body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I just took a stab at creating a library for something I'm dubbing semi-synchronous programming (async + dependencies). It's rather dense, but I'd really appreciate a quick code review to ensure I'm not introducing any race conditions. Feedback on best practices, general improvements is also welcome.</p> <pre><co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-07-20T07:42:30.650", "Id": "178259", "Score": "0", "body": "You should check out the new 3.5 keywords." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-07-20T20:55:16.607", "Id": "178402", "Score": "1", ...
[ { "body": "<p><a href=\"https://www.python.org/dev/peps/pep-0008/#indentation\" rel=\"nofollow\">PEP0008</a> says to use 4 spaces per indentation level. Using just 2 can make it harder to see what is and isn't a full indentation.</p>\n\n<p>You should use <a href=\"https://www.python.org/dev/peps/pep-0257/\" rel...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-15T17:09:05.763", "Id": "39315", "Score": "6", "Tags": [ "python", "asynchronous" ], "Title": "Semi-synchronous programming in Python" }
39315
<p>The first thing I would like to say is that I do have a fully functioning script, but the script is ugly, and I am wondering if there is a way to optimize it.</p> <p>The script looks to see if I have at least 6 news articles in my database.</p> <ul> <li>If I have at least 6 news articles, it branches into a nested...
[]
[ { "body": "<p>First, putting all HTML into <code>echo</code> does not necessarily make things cleaner. More typically, it makes them full of escaped quotes and difficult to edit in an IDE. I personally only use <code>echo</code> for output that will span less than a full line. I use php tags and heredocs for...
{ "AcceptedAnswerId": "39434", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-15T20:07:14.780", "Id": "39323", "Score": "3", "Tags": [ "php", "optimization", "mysql", "pagination" ], "Title": "Searching for news articles in database" }
39323
<p>I need to find the end of a loop or the length of the object. Some context on the code:</p> <p>I obtain the <code>txt</code> var from the DOM (that's the only way I've got by now and can't change it) and it's a formatted JSON. Here's an example of the expected JSON output:</p> <blockquote> <p>{"SE DIO AVISO A C...
[]
[ { "body": "<p>You can do this with <a href=\"http://api.jquery.com/jquery.map/\" rel=\"nofollow\"><code>jQuery.map</code></a> extremely elegantly as the function allows you to do a filtered map (<code>.map</code> excludes any item when you return <code>null</code> or <code>undefined</code>). As <code>$.map</cod...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-15T20:13:28.003", "Id": "39326", "Score": "3", "Tags": [ "javascript", "jquery", "json" ], "Title": "Find end of $.each() loop" }
39326
<p>I'm kind of new to Python. So, I wonder which method is better to use in a function to find an element in a list.</p> <p>First:</p> <pre><code>def search_binary(xs,target): count = 0 for i in xs: if i == target: return count count = count +1 else: count =...
[]
[ { "body": "<p>If your list is sorted you can use binary search (your second code), and it will be faster for large lists, but if it's unsorted you'll have to keep to linear search. The Python library provides fast implementation of both methods, so you really don't need to roll your own:</p>\n\n<pre><code>&gt;&...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-15T20:52:29.913", "Id": "39329", "Score": "7", "Tags": [ "python", "beginner", "binary-search" ], "Title": "Finding an element in a list" }
39329
<p>This compiler, implemented in C++, takes brainfuck code and produces a valid (but still obfuscated) C program, which in turn can be compiled to a native binary.</p> <p>Expected usage is as follows:</p> <ol> <li><p>Build the compiler</p> <pre><code>$ c++ -o bfc bfc.cpp </code></pre></li> <li><p>Compile a brainfuck...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T09:38:05.880", "Id": "65882", "Score": "0", "body": "I might be missing something, but why are you methods all return a `std::ostream` reference? I guess it could facilitate method chaining but it's not really used as far as I can s...
[ { "body": "<p>As far as I can understand</p>\n\n<pre><code>default: comment.replace(i, 0, \"\\\\\");\n</code></pre>\n\n<p>makes</p>\n\n<pre><code>case '\\\\': comment.replace(i, 0, \"\\\\\"); break;\n</code></pre>\n\n<p>useless.</p>\n\n<p>Edit to add another comment :</p>\n\n<p>Please activate all warnings ...
{ "AcceptedAnswerId": "40264", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-15T20:57:14.837", "Id": "39330", "Score": "16", "Tags": [ "c++", "c", "error-handling", "brainfuck", "portability" ], "Title": "Brainfuck-to-C compiler written in C++" }
39330
<p>I'm just getting into testing and wanted to see if someone can tell me if I'm writing tests correctly. I'm using C#, NUnit, &amp; Should.</p> <p>This is the class I'm testing:</p> <pre><code> using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflec...
[]
[ { "body": "<p>My first observations is: use injection! </p>\n\n<p>for example: Instead of passing in<code>AddressType addtype, string addressName, string streetAddress, string city, string state, string zip, string country</code> into <code>AddLocation</code>, expect an <code>Address</code> instance. This sim...
{ "AcceptedAnswerId": "39344", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-15T21:52:45.757", "Id": "39336", "Score": "8", "Tags": [ "c#", "unit-testing", "nunit" ], "Title": "Testing classes" }
39336
<p>I am learning Java as my first programming language and have written a bit of code. I would love to read expert reviews on this code and suggestions to improve right from naming conventions to logic. Please let me know if there is any kind of mistake.</p> <pre><code>public class Sudoku { public static void mai...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-15T22:26:36.920", "Id": "65846", "Score": "1", "body": "Your noConflict is a waste of processor. You should be looking only for the number you try to set, so instead of: add to list every number in row and column, check if num is in th...
[ { "body": "<p>Overall, this is pretty good code for a beginner's solution to a relatively complex problem.</p>\n\n<p>But your code <em>does</em> have me a little lost. For one, I'm not quite sure why you're using recursion here. It seems like that will be a <em>lot</em> more memory intensive than it needs to ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-15T22:01:11.553", "Id": "39337", "Score": "7", "Tags": [ "java", "beginner", "recursion", "sudoku" ], "Title": "Alternative methods of solving Sudoku" }
39337
<p>I have a Backbone.Collection which has some models in it. Each model has a boolean property called 'special.' Only one model should be special at any given time.</p> <p>I've got the following to enforce this, but I'm wondering if it could be clearer or if there is a more appropriate way to enforce such behavior:</p...
[]
[ { "body": "<p>That seems wrong on a few levels. </p>\n\n<ul>\n<li>Slows down every update call</li>\n<li>This is pretty much 'magic happens here'</li>\n<li>I feel this should be enforced in the UI, is it not too late for this in Backbone?</li>\n</ul>\n\n<p>I would modify the setter to accomplish what you need :...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-15T22:20:37.797", "Id": "39338", "Score": "2", "Tags": [ "javascript", "backbone.js" ], "Title": "Backbone.Collection - Ensure that at most one model has property set to true" }
39338
<p>I would appreciate it if someone experienced in F# and/or functional programming to look over my code. This is practically the first thing I wrote in the language so I'm sure it's filled with non-idiomatic stuff and unoptimized code.</p> <p>I'm not interested in implementing a more efficient algorithm. Just impleme...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T15:38:04.287", "Id": "65923", "Score": "1", "body": "Others have answered this well enough, but one other little improvement: `Seq.sortBy` + `Seq.head` can be replaced with `Seq.maxBy`." } ]
[ { "body": "<p>A few comments:</p>\n\n<pre><code> let intervalIntersect : double -&gt; double -&gt; double -&gt; double -&gt; bool = \n fun start1 end1 start2 end2 -&gt; min (end1 - start2) (end2 - start1) &gt; 0.0;\n</code></pre>\n\n<p>could be</p>\n\n<pre><code>let intervalIntersect = fun start1 end...
{ "AcceptedAnswerId": "39375", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T00:52:41.160", "Id": "39347", "Score": "4", "Tags": [ "algorithm", "f#" ], "Title": "F# rectangle packing algorithm" }
39347
<p><a href="http://projecteuler.net/problem=12" rel="nofollow">Project Euler Problem 12</a> asks (paraphrased):</p> <blockquote> <p>Considering triangular numbers <em>T</em><sub><em>n</em></sub> = 1 + 2 + 3 + … + <em>n</em>, what is the first <em>T</em><sub><em>n</em></sub> with over 500 divisors? (For example, <em...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T00:40:49.647", "Id": "66023", "Score": "0", "body": "Is prime is checking *every* number from 2 to sqrt(n). Half of those are even numbers." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T15:28:23.760...
[ { "body": "<p>Here is one possible improvement:</p>\n\n<p>Don't check whether <code>currNum</code> is prime, instead simply search factors until <code>currNum</code> becomes <code>1</code>. Checking for prime takes <code>O(sqrt(n))</code> time, but the rest of the loop checking for factors takes approximately <...
{ "AcceptedAnswerId": "39351", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T01:15:29.247", "Id": "39348", "Score": "5", "Tags": [ "python", "optimization", "project-euler", "mathematics", "lookup" ], "Title": "Project Euler Problem 12 - Highly ...
39348
<p>I am writing a program that is based on the Travelling Salesman Problem. There are four cities in which the user determines its x and y coordinates. The salesman always starts at city1 and ends up at city1, so there are 6 possible routes. However, each route has an equivalent route, i.e <code>route1</code> has the s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T04:19:23.587", "Id": "65869", "Score": "2", "body": "Welcome back! Please add a bit more context, so that people that didn't see your [previous migrated post](http://stackoverflow.com/questions/21152873/travelling-salesman-based-que...
[ { "body": "<p>The biggest high-level comment I have is that you need to learn about <a href=\"http://en.wikipedia.org/wiki/Modular_programming\">modularity</a>; that is, how to divide your code into separate components that act independently, so that you can reuse those components instead of copy-pasting and ed...
{ "AcceptedAnswerId": "39354", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T04:10:50.403", "Id": "39353", "Score": "12", "Tags": [ "java", "traveling-salesman" ], "Title": "Travelling salesman with four cities" }
39353
<p>I want to see if I can make any improvements to the rendering methods that are currently written. I've noticed when profiling this project that the CPU was allocating a fair percentage of the time towards rendering and was wondering if there were any improvements that I can make towards it.</p> <p>Note: Below is my...
[]
[ { "body": "<p>I'm not sure if these would be optimized out by the compiler but</p>\n\n<pre><code>Tile.TILESIZE * SCALE\nTile.TILESIZE * Game.SCALE\n</code></pre>\n\n<p>are done more than once, why not just keep them as variables and...</p>\n\n<pre><code>for (int y = startY; y &lt; finishY; y++) {\n for (int x =...
{ "AcceptedAnswerId": "39369", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T06:33:24.990", "Id": "39355", "Score": "3", "Tags": [ "java", "performance", "image" ], "Title": "Improving rendering performance of 2D Tile Game" }
39355
<p>I am working on a CoderByte problem in JavaScript. I have solved the problem below. Although I am trying to figure out if there is an easier way to do it? I am guessing RegEx will come up, although I don't have experience with that yet. </p> <p>From CoderByte: </p> <blockquote> <p>Using the JavaScript language, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T20:32:15.447", "Id": "65989", "Score": "0", "body": "regex can be very messy for anything more complicated than this. better to learn how to do things without it first, then try to do the regex version, because regex is very useful...
[ { "body": "<p>First off, my solution was way more convoluted ;)</p>\n\n<p>Other than that, 2 minor points</p>\n\n<ul>\n<li>It is good practice to have a shortcut to [].length in general</li>\n<li>Since 'a' is larger than '+' and '=' ( in the ASCII table ) you can drop a part of the logic</li>\n</ul>\n\n<p>So yo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T06:39:19.850", "Id": "39356", "Score": "7", "Tags": [ "javascript", "strings", "parsing", "programming-challenge" ], "Title": "Coderbyte SimpleSymbols challenge in Javascript"...
39356
<p>I have this class which is used as part of a game. It needs to generate Random Even values, which is done by generating random numbers until the result is even.</p> <p>Is there a better way to do this?</p> <p>Also, I currently have the methods implemented as private instance methods, but should I declare <code>gen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T02:35:36.563", "Id": "66038", "Score": "17", "body": "Just wondering, why not just multiply whatever number you receive from the RNG by 2?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T06:20:31.373"...
[ { "body": "<p>Declaring such methods <code>static</code> can increase the readability of your code. For the reader it will be obvious that the method does not depend on the internal state of an instance of the class. </p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationD...
{ "AcceptedAnswerId": "39372", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T07:34:23.097", "Id": "39359", "Score": "34", "Tags": [ "java", "random", "static" ], "Title": "Generating Even Random Numbers" }
39359
<p>I want to implement a Type system for different representations of an angle value. Motivation to implement this as a type system comes from <a href="https://stackoverflow.com/questions/2945471/extending-the-net-type-system-so-the-compiler-enforces-semantic-meaning-of-prim/2945498">this question</a>.</p> <p>Angle c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T08:35:59.907", "Id": "65878", "Score": "1", "body": "Are you asking _us_ what _your_ system should be able to do?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T08:51:43.027", "Id": "65879", ...
[ { "body": "<p>I don't think you should treat the units as disjoint entities between which you convert. You have started your post by saying </p>\n\n<blockquote>\n <p>Angle can be represented using following types</p>\n</blockquote>\n\n<p>But actually what you meant is \"units\".</p>\n\n<p>So the entity you are...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T07:36:00.757", "Id": "39360", "Score": "12", "Tags": [ "c#", "mathematics", "converting", "type-safety" ], "Title": "Type system for different representations of angle value" ...
39360
<p>Please review the code for code cleanup, smart optimizations and best practices. Also verify my complexity: \$O(n^2)\$, where \$n\$ is the number of nodes.</p> <pre><code>/** * This class traverses the tree and returns in-order representation. * This class does not recursion and does not use stack. * This code i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T11:13:38.557", "Id": "65894", "Score": "0", "body": "there would be no need to unbalance the tree if you have a parent pointer in TreeNode" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T11:48:59.767"...
[ { "body": "<p>I have a few comments on your code and algorithm.</p>\n\n<p>First, I don't understand why you cannot use recursion or a stack. You have not elaborated on this. If it is because this is a learning exercise then perhaps I can understand, but it is a poor example of any normal data-structure manipula...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T08:21:30.860", "Id": "39364", "Score": "3", "Tags": [ "java", "algorithm", "tree" ], "Title": "Inorder traversal of a tree without recursion or stack" }
39364
<p>Please review the code quality of this l33t Speak translator. Improvement suggestions are welcome. Here it is - <a href="http://jsbin.com/IHoFuQE/1" rel="nofollow">http://jsbin.com/IHoFuQE/1</a></p> <pre><code>(function() { "use strict"; // http://en.wikipedia.org/wiki/Leet // http://www.catb.org/jargon/html...
[]
[ { "body": "<p>To start with, I'd like to give you credit for using <code>\"use strict\"</code> and limiting the scope of variables using functions.</p>\n\n<p>Your <code>tol33t()</code> function is weird to me. If the <code>randomcase</code> button is checked, you call <code>randomizeCase()</code> with no argum...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T08:38:16.327", "Id": "39365", "Score": "6", "Tags": [ "javascript", "strings" ], "Title": "l33t Speak translator" }
39365
<p>As an exercise, I wanted to rewrite this toy Python code in Haskell:</p> <pre><code>def f(x): return abs(42-x)**2 def improve(x): newX = x + 0.1 return newX, f(newX) def optimize(f, goal): x = 0 err = f(x) while not err &lt; goal: x, err = improve(x) return x, err print(optimi...
[]
[ { "body": "<p>The guys at #haskell pointed me to <a href=\"http://zvon.org/other/haskell/Outputprelude/until_f.html\" rel=\"nofollow\">until</a>. This makes it satisfactory to me.</p>\n\n<pre><code>f :: Num a =&gt; a -&gt; a\nf x = abs(42-x)^2\n\nimprove :: Fractional b =&gt; (b -&gt; c) -&gt; (b, a) -&gt; (b, ...
{ "AcceptedAnswerId": "39378", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T09:58:22.740", "Id": "39370", "Score": "0", "Tags": [ "haskell", "recursion" ], "Title": "Naïve optimization by stepping until the error falls below a threshold" }
39370
<p>The following is a solution to <a href="https://projecteuler.net/problem=12" rel="nofollow noreferrer">Project Euler problem number 12</a>: which is to find the first <a href="http://en.wikipedia.org/wiki/Triangular_number" rel="nofollow noreferrer">triangular number</a> with more than 500 divisors.</p> <p>The code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T10:52:55.193", "Id": "65892", "Score": "1", "body": "you only need to factor `n` and `n+1` (first divide the even one by 2); they are coprime and thus have mutually exclusive factors so `nd(n*(n+1))=nd(n)*nd(n+1)`" }, { "Con...
[ { "body": "<p>Project Euler problems typically don't benefit from micro-optimizations such as inlining functions or flushing standard output. The biggest speed gains often come from <strong>algorithmic improvements</strong>. Here there are two key mathematical facts that can make this computation tractable:</p>...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T10:33:04.183", "Id": "39373", "Score": "6", "Tags": [ "c++", "optimization", "algorithm", "c++11", "programming-challenge" ], "Title": "Project Euler #12 - highly divisibl...
39373
<p>I needed smth that could send (scp/rsync) many files in parallel <em>but that would not overload machine, firewalls on the way by starting e.g. 600 simultaneous uploads</em>, so upload should be done in batches. </p> <p>Most of the utilities like <code>aria2c</code> are <em>download</em> managers and I needed somet...
[]
[ { "body": "<p>The best code would be no code at all.</p>\n\n<p>Using <a href=\"http://www.openbsd.org/cgi-bin/man.cgi?query=sftp&amp;sektion=1\" rel=\"nofollow\"><code>sftp(1)</code></a> with the <code>-R</code> <em>num_requests</em> option (and/or <code>-l</code> <em>bandwidth_limit</em>), you can do a <code>p...
{ "AcceptedAnswerId": "39383", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T11:48:06.323", "Id": "39377", "Score": "4", "Tags": [ "bash", "shell" ], "Title": "Parallelizing upload" }
39377
<p>The following code works and does what I want, but I'd like to confirm I'm using this OOP concept correctly. I'm using the following class to get and set some configuration parameters for my program. It used $GLOBALS for this before, but I'm trying to use a singleton pattern for this instead.</p> <p>Below is the Co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T20:39:19.657", "Id": "65994", "Score": "1", "body": "The question you really need to ask is: Would a second Config cause the death of the app? Not just confusion... would the app fall apart if a second instance ever existed, even i...
[ { "body": "<p>There should be something about a Singleton class that <em>requires</em> that it allow and present a <em>single</em>, <em>globally available</em>, <em>instance</em>. Otherwise, the pattern is being misused.</p>\n\n<p>The way your class is built, there's not really such a reason. You could have a...
{ "AcceptedAnswerId": "39426", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T13:18:50.937", "Id": "39382", "Score": "4", "Tags": [ "php", "object-oriented", "singleton" ], "Title": "Using a singleton class to get and set program wide settings" }
39382
<p>I need your help in OpenCV. I'm a student and am working on a project in which involves a little autonomous car. I use Python for the main programming language.</p> <p>I have some problem with my meanshift. When I run the program, I want the camera fixed on an area on the floor and stay on this area. I would like...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-22T08:59:48.483", "Id": "66746", "Score": "2", "body": "Hello, and welcome to Code Review! What do you mean by \"not optimally for the floor\"? We focus on improving working code: code reviews will not change the behaviour, only do the...
[ { "body": "<p>Whitespace. Use it. It makes code <em>much</em> clearer. Here's a list of places where you can add whitespace to make your code clearer.</p>\n\n<ol>\n<li><code>(frame1,frame2,trackWindow) :</code> \\$\\rightarrow\\$ <code>(frame1, frame2, trackWindow):</code></li>\n<li><code>trackWindow1=[x0,y0,w,...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T13:52:32.360", "Id": "39386", "Score": "1", "Tags": [ "python", "opencv" ], "Title": "Track a fix area with meanshift -OpenCV" }
39386
<p>I create a binary tree, now I want to remove a node. I hope that you can provide me some input. The nodes are composed of characters instead of numbers.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BinaryTree { publ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T14:29:14.413", "Id": "65908", "Score": "0", "body": "When you find the node you want to delete, your code saves either the left or right subtree below it. You'll need to do a little more work to save both subtrees." }, { "Co...
[ { "body": "<p>A few points:</p>\n\n<ol>\n<li><p>Your code for both searching for the node to be removed and for removing it is broken. @HABO pointed out the second part of this. You need to check both halves of the tree for the node. Then, if you find it and delete it, you have to combine both its child subtree...
{ "AcceptedAnswerId": "39396", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T14:20:58.383", "Id": "39388", "Score": "2", "Tags": [ "c#", "algorithm" ], "Title": "Delete a node from a binary tree" }
39388
<p>This is a continuation of this: <a href="https://codereview.stackexchange.com/questions/39197/performance-of-biginteger-square-root-and-cube-root-functions-in-java">Performance of BigInteger square root and cube root functions in Java</a></p> <p>I've made most of the changes suggested, but since I'm loading litera...
[]
[ { "body": "<p>This is only a form/style review and not algorithm review, as I don't really know what some of your algorithms are supposed to do.\nThere are some changes that I would do in your code.</p>\n\n<p>The first one would be replace the <code>while</code> loops for <code>do while</code> loops, and get ri...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-01-16T17:19:22.047", "Id": "39398", "Score": "5", "Tags": [ "java", "array" ], "Title": "Performance of Large BigInteger square root and cube root functions, and excessively large array" }
39398
<p>This seems like a pretty basic question, so bear with me...Say I have two (or many) methods in the same class that need a LINQ to SQL DataContext. Additionally, I am needing the DataContext in other classes as well. Does it make sense to create the new DataContext every time? </p> <p>Should I be creating this DataC...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T18:44:26.327", "Id": "65968", "Score": "2", "body": "You should wrap your context instance inside a `using` block, or manually call `Dispose()` when you're done with it... or are you wiring up your UI directly to your database? ..."...
[ { "body": "<p>I can't make a thorough review <em>right now</em>, but here's a quick fix that should help you structure things up.</p>\n\n<p>What you have is probably working, but you're mixing-up presentation with data concerns. I don't think these methods should be returning <code>void</code>. Picture this:</p...
{ "AcceptedAnswerId": "39406", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T18:42:10.167", "Id": "39404", "Score": "7", "Tags": [ "c#", "linq-to-sql" ], "Title": "Redundant DataContext ? - LINQ to SQL" }
39404
<p>My application uses a simple Model-View-Presenter architecture and uses the following classes and interface:</p> <p><strong>Presenter:</strong></p> <pre><code>public abstract class Presenter&lt;V&gt; { private V view; public final void setView(V view) { this.view = view; } protected fina...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T19:15:58.503", "Id": "65977", "Score": "0", "body": "I'm sure it's possible. We're not here to write code for you. We're just here to review your already existing code." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>I tried it in an IDE and have some addition to the last comment. I agree that you should try </p>\n\n<pre><code>Presenter&lt;V extends View&gt;\n</code></pre>\n\n<p>plus I would add that you need to switch the signature to </p>\n\n<pre><code>public abstract class View&lt;V, P extends Presenter&gt;...
{ "AcceptedAnswerId": "46456", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T18:56:14.737", "Id": "39405", "Score": "5", "Tags": [ "java" ], "Title": "Refactoring my simple model-view-presenter architecture" }
39405
<p>In MATLAB I have a set of 5393280 points in the form of a decimal-valued vector (x,y,z). How do I represent them in a way that I can quickly collect all the points within some rectangular x-y domain?</p> <p>Right now I'm representing them as a 3-column matrix, sorted by x-values, and using the following code to ext...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-08T21:01:03.200", "Id": "81625", "Score": "1", "body": "The keyword you are looking for is quadtree." } ]
[ { "body": "<p>if you only need to select once then there is no need to sort at all; filtering can happen in \\$ O \\left( n \\right) \\$ while the sort needs \\$ O \\left( n \\log n \\right) \\$</p>\n\n<p>if you need to select multiple times then put them in a \\$ n \\times n \\$ grid structure, where each grid...
{ "AcceptedAnswerId": "40075", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T20:12:20.057", "Id": "39409", "Score": "4", "Tags": [ "performance", "matlab" ], "Title": "What's the fastest way to get the points I want out of a huge blob?" }
39409
<p>Being curious to see which tags on this site get the most attention, I developed a <a href="http://data.stackexchange.com/codereview/revision/160176/204146" rel="nofollow">Stack Exchange Data Explorer query</a>:</p> <pre><code>WITH CanonicalTags AS ( SELECT Id, TagName, Id AS AliasId, TagName AS Alias F...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T20:23:40.503", "Id": "65987", "Score": "1", "body": "I know, I'm blurring the lines with http://meta.codereview.stackexchange.com/ a bit." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T20:33:20.140",...
[ { "body": "<ol>\n<li>I think that the rounding behaviour is a bug. The output looks just fine if you tick the \"Text-only results\" checkbox.</li>\n<li><p><a href=\"http://data.stackexchange.com/code%20review%20stack%20exchange/revision/160176/204311\" rel=\"nofollow\">Simplified tag\ncanonicalization</a>:</p>...
{ "AcceptedAnswerId": "39437", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T20:22:03.747", "Id": "39410", "Score": "10", "Tags": [ "sql", "sql-server", "floating-point", "stackexchange" ], "Title": "SE Data Explorer Query: Average score for questio...
39410
<p>SEDE (<a href="https://data.stackexchange.com" rel="nofollow noreferrer">Stack Exchange Data Explorer</a>) now includes all public beta sites, and allows querying a recent snapshot of the sites' data, including questions, answers, comments, users, etc.</p> <p>This tool can be used to fetch data that can help assess...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-01-16T20:22:41.110", "Id": "39411", "Score": "0", "Tags": null, "Title": null }
39411
Questions about Stack Exchange APIs, Stack Exchange Data Explorer (SEDE), or any hacks to work with Stack Exchange sites.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T20:22:41.110", "Id": "39412", "Score": "0", "Tags": null, "Title": null }
39412
<p>For many programming languages, a namespace is a context for their identifiers. In a filesystem, an example of a namespace is a directory. Each name in a directory uniquely identifies one file or subdirectory, but one file may have the same name multiple times.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-01-16T20:52:13.490", "Id": "39416", "Score": "0", "Tags": null, "Title": null }
39416
For many programming languages, namespace is a context for their identifiers. Use this tag to indicate concerns about appropriate usage of namespaces.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T20:52:13.490", "Id": "39417", "Score": "0", "Tags": null, "Title": null }
39417
<p>This was our old site that I am redesigning.</p> <p><img src="https://i.stack.imgur.com/mjEYm.png" alt="old"></p> <p>Someone else hardcoded with inline CSS and javascript in tables. </p> <p>I wanted to make it dynamic, so I added Mustache and made this template:</p> <pre><code>{{#labs}} &lt;div class="lab"&gt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T00:48:26.150", "Id": "66026", "Score": "2", "body": "We're talking about a total savings of `66 + (19*labs)` characters at the expense of intuitive reading. I would argue that it's not worth it as it will have virtually no (maybe sa...
[ { "body": "<p>By using excessive markup for presentational purposes, the template is the exact opposite of clean.</p>\n\n<pre><code>&lt;span&gt;&lt;i class=\"fa fa-phone\"&gt;&lt;/i&gt;&lt;/span&gt;&lt;span&gt;{{{telefon}}}&lt;/span&gt;&lt;br /&gt;\n</code></pre>\n\n<p>vs.</p>\n\n<pre><code>&lt;span class=\"fa ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T23:22:21.790", "Id": "39425", "Score": "4", "Tags": [ "javascript", "css", "json", "template", "mustache" ], "Title": "How clean is this mustache template for a listing pa...
39425
<p>Preface: I'm starting to learn C# and I don't want to port any of my bad habits from other languages, so I'm following convention wherever possible.</p> <p>Using the default Visual Studio code formatting, this relatively simple function requires 14 lines of code.</p> <pre><code>public void add(int[] values, Func&l...
[]
[ { "body": "<p>There are at least two answers.\nThe short one:</p>\n\n<pre><code>public void add(int[] values, Func&lt;int, int&gt; transform = null)\n{\n foreach (int v in values)\n add( (transform != null) ? transform(v) : v);\n}\n</code></pre>\n\n<p>The efficient one:</p>\n\n<pre><code>public void a...
{ "AcceptedAnswerId": "39428", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T22:11:34.457", "Id": "39427", "Score": "3", "Tags": [ "c#", "beginner" ], "Title": "Is there a more concise and/or readable way to write the following method?" }
39427
<p>I have the following code to log changes using Entity Framework 6.</p> <p>At the moment it only logs changes to a particular table - but I intend to expand it to cope with any table. I'm not sure of the best way to extract the table name.</p> <p>I call this code before <code>Db.SaveChanges</code>. Db is the DBCo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T23:56:13.507", "Id": "66017", "Score": "0", "body": "I'm not an entity framework guru but I would have thought you might inherit the context and override `SaveChanges()` ?" }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>Not a big deal, but this:</p>\n\n<blockquote>\n<pre><code>var currentVal = property.CurrentValue == null ? \"\" : property.CurrentValue.ToString();\nvar originalVal = property.OriginalValue == null ? \"\" : property.OriginalValue.ToString();\n</code></pre>\n</blockquote>\n\n<p>Can be shortened to ...
{ "AcceptedAnswerId": "39858", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T23:47:07.353", "Id": "39430", "Score": "10", "Tags": [ "c#", "performance", "entity-framework" ], "Title": "Logging Entity Framework Changes - improve performance" }
39430
<p><a href="http://esolangs.org/wiki/Fishstacks">Fishstacks</a> is a <a href="http://esolangs.org/wiki/Deadfish">deadfish</a> derivative based on a stack the stack can only hold four elements when a fifth element is pushed the bottom element is kicked out and eventually printed out to the screen.</p> <p>I've come up w...
[]
[ { "body": "<p>Beyond the bad names that you are already aware of, I see a few things that could be improved.</p>\n\n<p><code>str1</code> and <code>str2</code> are bad variable names as well. They should be <code>str</code> and <code>chr</code> respectively. Those names would properly represent the data and make...
{ "AcceptedAnswerId": "73858", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T00:55:56.233", "Id": "39431", "Score": "23", "Tags": [ "ti-basic", "interpreter" ], "Title": "TI-BASIC interpreter for Fishstacks" }
39431
<p>I have an array that I want to enumerate using blocks concurrently. However, I'm having trouble making this thread safe. I am new to using blocks and locks, so I am hoping someone may be able to push me in the right direction for preventing this from crashing.</p> <p>The point of this function is to loop over a nu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T17:39:41.700", "Id": "74775", "Score": "0", "body": "Use Xcode Menu Product > Profile then Instruments with \"Time Profiler\" to see where most time is spent. And @synchronized is the easiest way to protect access to mutable objects...
[ { "body": "<ol>\n<li><p>The bottleneck of your code might not be where you think it is. I recommend reading the <a href=\"https://developer.apple.com/library/mac/documentation/Performance/Conceptual/PerformanceOverview/Introduction/Introduction.html#//apple_ref/doc/uid/TP40001410-CH202-SW1\" rel=\"nofollow\">Pe...
{ "AcceptedAnswerId": "42166", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T01:32:47.347", "Id": "39435", "Score": "6", "Tags": [ "array", "objective-c", "thread-safety", "file-system", "concurrency" ], "Title": "Concurrently enumerating an arr...
39435
<p>I am hoping to make this method run a little faster. I typically need to run this on a list with more than 100000 entries. Note that at the start and end of the list, I wish to weight the average so that it is closer to the start or end value, hence the smaller framesize.</p> <pre><code>public PointPairList GetMovi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T03:00:17.417", "Id": "66040", "Score": "1", "body": "Just a note relating to your original post: *make your titles more descriptive to what your code does*. You can request what you would like specifically reviewed in your post." ...
[ { "body": "<p><code>Skip()</code> is not optimized for <code>IList&lt;T&gt;</code>, it always enumerates the skipped elements. This means that your algorithm is O(<em>n</em><sup>2</sup>) for no good reason. What you should do instead is to manually iterate just the required part of the input in each iteration u...
{ "AcceptedAnswerId": "39481", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T02:33:34.243", "Id": "39439", "Score": "9", "Tags": [ "c#", "performance", "linq", "statistics" ], "Title": "Moving average calculation" }
39439
<p>Code review for best practices, optimizations, code cleanup etc. Also requesting verification of the complexity: O(row*row*col).</p> <pre><code>/** * Contains coordinates of the * topMost left, of matrix, obtained by getRowOne and colRowOne * bottomMost right, of matrix, obtained by getRowTwo and getColTwo * ...
[]
[ { "body": "<p>The begin returned by <code>maxSubArraySub</code> can be wrong as we update <code>start</code> after we've found a good candidate for the maximal sum. This can lead to potential bugs (I am way too lazy to find an actual case where it makes a difference but that should be possible). The solution fr...
{ "AcceptedAnswerId": "39460", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T06:28:19.577", "Id": "39443", "Score": "1", "Tags": [ "java", "matrix", "dynamic-programming" ], "Title": "MaxSum sub matrix within a matrix" }
39443
<p>Which of these names is better: <code>time.getHours()</code> or <code>time.hours()</code>? And why?</p> <pre><code>public class Time implements Serializable { private final int hours; private final int minutes; public static Time from(Calendar calendar) { int hoursIn24HourFormat = calendar.get(...
[]
[ { "body": "<p>It is a matter of taste, so there is no 'better'. But more common seams to be <code>time.getHours();</code> because often the conventions of <a href=\"http://en.wikipedia.org/wiki/JavaBeans#JavaBean_conventions\" rel=\"nofollow\">JavaBean</a> are used.</p>\n\n<p>If you work in a team, I would disc...
{ "AcceptedAnswerId": "39446", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T06:52:47.167", "Id": "39444", "Score": "4", "Tags": [ "java", "datetime" ], "Title": "Proper naming for a Time class" }
39444
<p>I have the following code:</p> <pre><code>static void TimerElapsed(object sender, ElapsedEventArgs e) { foreach (BIGService bigService in runningServices) { if (!bigService.ExecutedToday) { int executionResult = bigService.Execute(); string serviceName = bigService.To...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T11:52:55.800", "Id": "66083", "Score": "1", "body": "Why not just set up a Scheduled Task on the machine this needs to run under?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T09:59:57.987", "Id...
[ { "body": "<p>As your code stands now it looks to me as if the timer has some responsibilities it shouldent have.</p>\n\n<p>My suggestion would be to either move all the timer information to your timer, including bigService.ExecutedToday and SetAsExecuted OR you move all that logic inside the service. I would g...
{ "AcceptedAnswerId": "39449", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T09:06:06.313", "Id": "39447", "Score": "2", "Tags": [ "c#" ], "Title": "How should I set a daily method as executed, from inside or from outside?" }
39447
<p>I have client's methods that processes a large SQL query. I wouldn't like to do that through getting whole query result to memory, but process it in batches. It entails with exposing JDBC API to client's code. I think that this code could be refactored much better.</p> <pre><code> //client's method m_jdbcMa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T12:32:16.170", "Id": "66093", "Score": "0", "body": "You should update your question and tell us which JDBC Client/server you are using...." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T15:23:34.787...
[ { "body": "<p>Your assumption that the entire dataset is read in to memory is not necessarily accurate. The JDBC clients I have worked with (DB2, MS-SQLServer, Sybase, Oracle, etc.) each default to, or have an option to limit the size of the client-side buffer. You only have a small amount of data on the actual...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T09:12:14.323", "Id": "39448", "Score": "2", "Tags": [ "java", "jdbc" ], "Title": "How to hide implementation of JDBC while processing large query in client's code?" }
39448
<p>I have written a singleton module which is to be used for some future modifications on <code>.chart</code> elements. Modification functions, such as <code>colorArgumentButtons()</code> are called recursively so that I don't have to iterate over all <code>.chart</code> elements in all functions.</p> <p>Is my use of ...
[]
[ { "body": "<p>I think you are overdoing the underscores, you will find that conflicts will be rare.</p>\n\n<p>Furthermore, I can understand that you want to centralize the iteration over the chart elements, but why would you want to do that recursively, it does not make much sense to me. </p>\n\n<p>If you drop ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T09:55:15.950", "Id": "39451", "Score": "0", "Tags": [ "javascript", "revealing-module-pattern" ], "Title": "Singleton model for modifying future .chart elements" }
39451
<p>In a payment application a day before and at the same time with some payments some messages(email) needs to be sent. I have a DTO (called <code>EscrowPayment</code>, projected from some entity) from which I generate and send two similar `messages.</p> <p>I look for advice specifically on the following issues with t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T13:18:47.397", "Id": "66100", "Score": "0", "body": "There's not much I can see, is using a template system like [StringTemplate](http://www.stringtemplate.org/) an option?" }, { "ContentLicense": "CC BY-SA 3.0", "Creati...
[ { "body": "<p>This strikes me as an occasion where a custom method with positional format indexing may help <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html\" rel=\"nofollow\">(Formatter <code>argument_index</code>)</a>. It is a little-known feature of Java's String.format / Formatter...
{ "AcceptedAnswerId": "39587", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T10:18:50.263", "Id": "39453", "Score": "3", "Tags": [ "java" ], "Title": "Code duplication when converting DTO to String messages" }
39453
<p>PHP's <code>eval()</code> is general considered insecure with any user input.</p> <p>However, with filtering of input (i.e. <code>[-+/*0-9]</code>) you can make <code>eval()</code> secure for a small subset of PHP; mathematical expressions.</p> <p>I've tried to think of a way to extend that by allowing a limited s...
[]
[ { "body": "<p>It looks pretty reasonable to me. A couple of points:</p>\n\n<ol>\n<li><p>You seem to be assuming that a function start with a letter. Functions CAN start with an underscore. Are you sure there is no such function that can be exploited?</p></li>\n<li><p>The regex in the section 'Invalid function c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T10:32:20.897", "Id": "39454", "Score": "5", "Tags": [ "php", "security" ], "Title": "Secure math expressions using PHP eval()" }
39454
<p>I have the following contact form, using PHP, JS and a bit of Ajax. I want to make sure that it is secure.</p> <pre><code>&lt;?php session_start(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { ob_start(); if(isset($_POST['name']) &amp;&amp; isset($_POST['email']) &amp;&amp; isset($_POST['message']) &amp;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-23T20:21:56.800", "Id": "66977", "Score": "0", "body": "Why do you have quotes around your integers?" } ]
[ { "body": "<p>The form seems to be OK, but mixing all of the code in one file is not a best-practice.</p>\n\n<p><strong>UPDATE</strong></p>\n\n<p>Some tips on code separation:</p>\n\n<ul>\n<li>I would suggest using any template system for html/php code\nseparation. For example Smarty. </li>\n<li>Also, it would ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T10:34:38.360", "Id": "39455", "Score": "4", "Tags": [ "php", "security", "ajax", "form" ], "Title": "Is this contact form secure?" }
39455
<p>I've started writing a small CSV parser class as I needed a method to group a CSV file by a given column.</p> <pre><code>class CSVParser { private $FileName; private $FileHandle; private $HasHeaderRow = false; private $RowsToIgnore = array(); public function __construct ($FileName, $Mode = "...
[]
[ { "body": "<p>Ok, before I set of, there are 3 things to keep in mind here: Code review has to be tough, to be good, so if this hurts your feelings - sorry, but I'm trying to help.<br>\nThe second thing is: Please, please, please try to adhere to the coding standards as defined by PHP-FIG (google them). Most, i...
{ "AcceptedAnswerId": "39474", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T10:42:41.330", "Id": "39457", "Score": "2", "Tags": [ "php", "array", "csv" ], "Title": "Grouping a CSV by column" }
39457
<p>I began the journey to be a self-taught programmer about a month ago and my biggest fear about teaching myself is developing bad habits and not realizing it.</p> <p>I'm looking for criticism on this "Guess a Number" game. It's my first real "project" that I've invested serious time into so I feel like this is my fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T19:30:50.590", "Id": "66215", "Score": "2", "body": "I like the humility with which you are approaching programming. You'll learn faster than, and be easier to get along with, me when I started out." } ]
[ { "body": "<p>Overall it looks pretty good. A few pointers though...</p>\n\n<ul>\n<li><p>Try to indent your code properly. Most of it looks good but on a few places you have missed an indentation. e.g.,</p>\n\n<pre><code>do {\nsetMax();\nsetObjective();\nuserGuess();\nplayAgain();\n} while (playAgain == true);\...
{ "AcceptedAnswerId": "39463", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T11:19:22.910", "Id": "39459", "Score": "30", "Tags": [ "java", "beginner", "game", "formatting", "number-guessing-game" ], "Title": "\"Guess a number\" game" }
39459
<p>I am setting different <code>RadioGroup</code> like this:</p> <pre><code>fragment.setT1RadioGroup((RadioGroup)fragView.findViewById(rowids[0]).findViewById(R.id.t1_radiogroup)); fragment.setT2RadioGroup((RadioGroup)fragView.findViewById(rowids[1]).findViewById(R.id.t1_radiogroup)); fragment.setT3RadioGroup((RadioGr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T13:03:16.707", "Id": "66098", "Score": "0", "body": "Show us your code for whatever the `fragment` object is. In what way is the `fragment.setT1RadioGroup` different from `fragment.setT2RadioGroup`?" } ]
[ { "body": "<p>Assuming that <code>setT5RadioGroup</code> only sets a variable within the fragment:</p>\n\n<p>In your fragment, use <code>RadioGroup[] radioGroups = new RadioGroup[10];</code></p>\n\n<pre><code>setTRadioGroup(int number, RadioGroup grp) {\n this.radioGroups[number] = grp;\n}\n</code></pre>\n\n<...
{ "AcceptedAnswerId": "39469", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T12:58:13.627", "Id": "39468", "Score": "3", "Tags": [ "java", "android" ], "Title": "Refactoring RadioGroup setter code?" }
39468
<p>I've implemented just as Ryan Bates suggested in his <a href="http://railscasts.com/episodes/217-multistep-forms" rel="nofollow">railscast episode</a>, I've got everything working just right, so here is his approach in the controller :</p> <pre><code>def new session[:order_params] ||= {} @order = Order.new(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-27T20:40:30.010", "Id": "74116", "Score": "0", "body": "If you found @BroiSatse's answer helpful, please checkmark it." } ]
[ { "body": "<p>I would advise you to look at wicked gem: <a href=\"https://github.com/schneems/wicked\">https://github.com/schneems/wicked</a>.</p>\n\n<p>Using this gem you could write:</p>\n\n<pre><code>include Wicked::Wizard\nsteps &lt;list_of_your_steps&gt;\n\ndef new\n session[:order_id] ||= Order.create.id...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T13:11:05.047", "Id": "39470", "Score": "4", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Refactoring multistep form rails" }
39470
<p>I would prefer if more experienced users could give pointers on how I can optimize and think better when writing code.</p> <p>If you are unfamiliar with unity3d, ignore the use of UnityEngine, the heritage from <code>MonoBehaviour</code> as well as the <code>Debug.Log();</code>, <code>Debug.LogWarning();</code>, an...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T14:51:18.570", "Id": "66120", "Score": "0", "body": "could you please provide class item as well?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T15:38:13.313", "Id": "66136", "Score": "0", ...
[ { "body": "<p>First things first. I don't see a reason for why you didn't include a quantity property in your <code>Item</code> class. Depending on this you could also treat <code>Item</code> as the same as <code>ItemSlot</code> so you could get rid of one of those classes. That being said I will review the cod...
{ "AcceptedAnswerId": "39483", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T14:16:13.180", "Id": "39475", "Score": "0", "Tags": [ "c#", "unity3d" ], "Title": "Inventory Script (RPG) in C#" }
39475
<p>I've been working on an html5 canvas video player with a lot of fun little extras and ui toys, the main one being a chroma key (green screen) effect that allows the user to key out different colors or ranges of color while the video is playing. </p> <p>I seem to have hit a snag in the recommended chroma key method....
[]
[ { "body": "<p>Most of your code is API calls. I'm surprised that Javascript is fast enough to run at all (it isn't, on my old laptop, using Chrome browser).</p>\n\n<p>I'll assume that using completely different APIs, and for example writing a plug-in in a different, compiled language (if that's even possible) i...
{ "AcceptedAnswerId": "39667", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T14:32:02.290", "Id": "39476", "Score": "7", "Tags": [ "javascript", "performance", "html5", "canvas", "video" ], "Title": "Optimizing the performance of html5 video man...
39476
<p>I came across an issue the other day where I really just could not think of a functional solution. So I fell back on my imperative programming skills. Since a functional solution still eludes me, I figured I'd shout out for some help here.</p> <h2>Use Case</h2> <p>I have a List of Strings with arbitrary lengths. T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T16:13:16.853", "Id": "66149", "Score": "0", "body": "Can you give an example of input and result?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T22:54:56.457", "Id": "66247", "Score": "0", ...
[ { "body": "<p>This is much more \"Functional\" than my first attempt:</p>\n\n<pre><code> def combineStrings(strs: List[String], maxLen: Int)\n : List[String] = {\n import scala.collection.mutable.StringBuilder\n\n strs.map(_.trim).filter(_.nonEmpty)\n .aggregate(List[StringBuilder]())({ (lbs, s) =&...
{ "AcceptedAnswerId": "39708", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T14:37:15.903", "Id": "39477", "Score": "2", "Tags": [ "functional-programming", "scala" ], "Title": "Functional Re-Write in Scala: Rows of Strings with a Max Width" }
39477
<p>Just looking for some feedback on a hangman script. It works perfectly fine; I'm just trying to master the Python language, and the best place way to get better is to ask the <em>true</em> masters!</p> <pre><code>import random UNKNOWN_CHARACTER = "*" GUESS_LIMIT = 7 words = [] def load_words(): global words...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T17:00:50.367", "Id": "66157", "Score": "1", "body": "Can you provide an example of dictionnary.txt ?" } ]
[ { "body": "<p><strong>List comprehension</strong> is a very neat way to construct lists in Python. For instance :</p>\n\n<pre><code>stripped = []\nfor word in words:\n stripped.append(word.strip())\n</code></pre>\n\n<p>becomes</p>\n\n<pre><code>stripped = [word.strip() for words in word]\n</code></pre>\n\n<p...
{ "AcceptedAnswerId": "39496", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T16:17:12.930", "Id": "39484", "Score": "2", "Tags": [ "python", "game", "python-3.x", "hangman" ], "Title": "Python Hangman feedback" }
39484
<p>I make some ui custom controls. Typically my controls have themes to them so it can be changed. I dont use css files for each themes. What I do instead is hava a javascript file that contains the different themes for that particular control. Example of my button control (Note i took the rest of the css off the ot...
[]
[ { "body": "<p>Yes! This looks like a maintenance head ache ( nightmare ).</p>\n\n<p>CSS belongs to CSS files ( you can apply csslint to CSS files, CSS files also have syntax highlighting, plus most developers rightfully dislike maintaining CSS in JavaScript ).</p>\n\n<p>If you must support different styles at r...
{ "AcceptedAnswerId": "39663", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T17:22:41.933", "Id": "39489", "Score": "2", "Tags": [ "javascript", "css" ], "Title": "Performance Issue on css and javascript styling" }
39489
<p>I would like to get some feedback on my code. I am starting to program after doing a few online Python courses.</p> <p>Would you be able to help me by following my track of thinking and then pinpointing where I could be more efficient? (I have seen other answers but they seem to be more complicated than they need t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T05:22:01.037", "Id": "66169", "Score": "0", "body": "`append()` isn't on the list of efficient ways to populate a list. [Comprehensions](http://www.diveintopython3.net/comprehensions.html) are a means of accomplishing the same thing...
[ { "body": "<p>The Fibonacci sequence is a problem that's very well suited for a recursive solution. If you haven't yet learned about recursion, I would highly recommend it, as it provide a whole new way of looking at problems. </p>\n\n<p>To find the nth Fibonacci number, you could use something like the follo...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T04:31:13.450", "Id": "39493", "Score": "7", "Tags": [ "python", "project-euler", "fibonacci-sequence" ], "Title": "More efficient solution for Project Euler #2 (sum of Fibonacci n...
39493
<p>I need a little help with improving my first Java program. I have programmed for about a month, so my code is quite messy. The program is a "Musiclist" program, with which you can add songs, edit songs, and remove songs from the list.</p> <p>The program uses 2 <code>ArrayList</code>s, to store the information about...
[]
[ { "body": "<p>UI code is usually kinda \"messy\" you could separate out the ActionListeners to new files if you want. Also I'd probably put Artist and Song Title into a class like </p>\n\n<pre><code>public class SongData {\n private String artist;\n private String title;\n public SongData( String title...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T18:13:56.370", "Id": "39498", "Score": "4", "Tags": [ "java", "beginner", "database" ], "Title": "Music list program" }
39498
<p>I found a function online that tests if a tree is a binary search tree:</p> <pre><code>private boolean isBST(Node node) { if (node==null) return(true); // do the subtrees contain values that do not // agree with the node? if (node.left!=null &amp;&amp; maxValue(node.left) &gt; node.data) return(false); ...
[]
[ { "body": "<p>Here's a simple tree that can demonstrate a couple things:</p>\n\n<pre><code> 5\n / \\\n 3 7\n / \\ \\\n1 6 8\n</code></pre>\n\n<p>minValue and maxValue are written so that the algorithm can catch the 6 that is out of place. And it seems like even the original versions of those funct...
{ "AcceptedAnswerId": "39509", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T18:26:11.973", "Id": "39500", "Score": "4", "Tags": [ "java", "tree", "binary-search" ], "Title": "Testing to see if tree is BST" }
39500
<p>This is a follow up review of question '<a href="https://codereview.stackexchange.com/questions/39186/a-custom-undo-manager">a custom Undo Manager</a>'.</p> <p>After reviewing all the comments and answers, my code has been revised (completely rewritten) based on the review. </p> <p><strong>Summary</strong></p> <p...
[]
[ { "body": "<p>I think you should not clear <code>_redoCommands</code> stack when you are re-doing command. Actually you should be able to continue re-doing command until you will restore state when you called first undo command. You should clear redo-commands when completely new command arrives:</p>\n\n<pre><co...
{ "AcceptedAnswerId": "39513", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T19:17:23.660", "Id": "39503", "Score": "3", "Tags": [ "c#", "delegates" ], "Title": "follow-up review of a custom Undo Manager" }
39503
<p>I am working on a browser strategy game as a hobby and came up with a decision to use a tile-based map for the world map. </p> <p>I have several questions so far:</p> <ul> <li><p>I am using double-cache (file and apc) for performance issues. Isn't it too much? Or should I consider using Redis or anything similar?<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-21T08:56:50.223", "Id": "66638", "Score": "0", "body": "Given they are tiles, is it possible to pre-render all the tiles including the variations, sand-to-sea, sand-to-forest etc, then just return the correct url of the tile? This way ...
[ { "body": "<p>I had a look through the code, if it runs slow then it is most likely a network issue from what I can tell.</p>\n\n<p>I think you are caching the wrong thing. </p>\n\n<p>A better solution might be to change the design of the tiles and remove the coordinates from them.</p>\n\n<p>You have 6 types of...
{ "AcceptedAnswerId": "39849", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T19:35:41.320", "Id": "39505", "Score": "2", "Tags": [ "php", "game", "image" ], "Title": "Game map tiles generation with php" }
39505
<p>So I've got this module called risar, which draws. But that's not really of importance. I wrote this code which sets 20 flowers on the background.</p> <p>Now they need to move downwards by 5 units. The code works fine but it looks horribly awkward to me. I'd like it to look more "fancy" or maybe that less loops wou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T21:19:28.093", "Id": "66225", "Score": "0", "body": "So moving is supposed to animate the drawing by moving flowers every frame?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T23:49:58.687", "Id"...
[ { "body": "<p>Let's start with your naming. <code>flower</code> is supposed to be a list, right? Let's make it plural, then.</p>\n\n<pre><code>def moving(flowers):\n for i in range(len(flowers)):\n while flowers[i].y() &lt; risar.maxY:\n for p in flowers: #p is position\n p...
{ "AcceptedAnswerId": "39522", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T19:39:08.267", "Id": "39506", "Score": "3", "Tags": [ "python", "beginner", "iteration" ], "Title": "Drawing and moving flowers" }
39506
<p>I am trying to make a 3D application with OpenGL/LWJGL at the moment, but I am now already hitting some limits on the JVM, most likely due to a configuration that needs to be done.</p> <p>I have the following code in the render loop:</p> <pre><code>@Override protected void render(final double msDelta) { glClea...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T21:30:10.217", "Id": "66230", "Score": "0", "body": "Your render method should not compile given the class Matrix4f you have shown. Could you show a compilable example?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>Not that may be your issue but I would do your multiply algorithm with a loop:</p>\n\n<pre><code>public Matrix4f multiply(final Matrix4f other) {\n float[] a = getElements();\n float[] b = other.getElements();\n float[] result = new float[a.length];\n //assume a.length == b.length and...
{ "AcceptedAnswerId": "39516", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T19:53:53.347", "Id": "39508", "Score": "5", "Tags": [ "java", "matrix", "floating-point", "opengl", "garbage-collection" ], "Title": "Optimizing garbage collection for ...
39508
<p>I would prefer if more experienced users could give pointers on how I can optimize and think better when writing code.</p> <p>If you are unfamiliar with Unity3d, ignore the use of <code>UnityEngine</code>, the heritage from <code>MonoBehaviour</code> as well as the <code>Debug.Log()</code>, <code>Debug.LogWarning()...
[]
[ { "body": "<p>Here is a bug:</p>\n\n<pre><code>int tRemain = q;\n\nfor (...)\n if (...)\n tRemain = inventory[i].Add(q);\n</code></pre>\n\n<p>I think the above should be <code>tRemain = inventory[i].Add(tRemain);</code>.</p>\n\n<p>I don't see why you have <code>tRemain</code> as an extra/new variable,...
{ "AcceptedAnswerId": "39520", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T20:05:50.183", "Id": "39510", "Score": "2", "Tags": [ "c#", "unity3d" ], "Title": "Follow Up Inventory Script (RPG) in C#" }
39510
<p>I have a click event that calls a function (below, txtResize) which makes some CSS changes to html text. (Acts on Text of 3 unique elements).</p> <p>Q: What is the best way to refactor this code to limit excessive if/else usage, AND restore the original state of ALL text elements once the user clicks away from this...
[]
[ { "body": "<p>This is actually a pretty classic problem and I've addressed it in my code on numerous occasions. One of the simplest ways to do what you're doing is to just reset the state for all the elements and then correct it.</p>\n\n<pre><code>function txtResize() {\n var clicked = this.id;\n\n if ( c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T20:52:18.277", "Id": "39512", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Changing html element with click event: how to restore default state of element using jQuery ...
39512
<p>Are there any improvements to these two classes which implement <a href="http://www.isthe.com/chongo/tech/comp/fnv/index.html" rel="nofollow">FNV-1a</a> for hashing? Particularly, I'm looking for any reuse opportunities (possibly via a common abstract superclass derived from <code>HashAlgorithm</code>?).</p> <p><a ...
[]
[ { "body": "<p>If you were being completely asinine you could move the <code>Initialize</code> method to a new common ancestor class. The amount of code you would write for that common class would exceed the amount of code you would save from duplication though, in other words, not worth it. Alternatively, you c...
{ "AcceptedAnswerId": "39527", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T21:30:39.530", "Id": "39515", "Score": "8", "Tags": [ "c#", "performance", "algorithm", ".net", "hashcode" ], "Title": "Implementation of the FNV-1a hash algorithm for ...
39515
<p><strong>Please note there are newer revisions of this code, <a href="https://codereview.stackexchange.com/q/47840/27623">one here</a>, and <a href="https://codereview.stackexchange.com/q/84536/27623">one here for continuous audio recording</a>.</strong></p> <p>This is a program I wrote as a .wav audio recording lib...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T01:03:48.183", "Id": "66356", "Score": "0", "body": "Apparently, Rasberry Pi is little-endian by default; but can be big-endian." } ]
[ { "body": "<p>A few things jump out at me immediately:</p>\n\n<ol>\n<li><p>Use <code>sizeof()</code> whenever you need the size of something with non-dynamic allocation. In other words, all of your <code>write</code> calls on the <code>WaveHeader</code> struct members should be using <code>sizeof</code>, not ha...
{ "AcceptedAnswerId": "39524", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T23:23:52.020", "Id": "39521", "Score": "33", "Tags": [ "performance", "c", "linux", "audio", "raspberry-pi" ], "Title": "Recording audio in C" }
39521
<p>I'm currently writing a script and I decided to run cane over it to look for some issues, and the following method was highlighted. I've done my best to cut it back, and at this point I'm inclined to leave it as-is, however cane is still giving it a pretty high rating of 23 (15 is the point it starts complaining) so...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T20:27:16.630", "Id": "66323", "Score": "3", "body": "I did an edit based on your \"final code\", though I confess I'm not familiar with that term." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T04:50...
[ { "body": "<p>Matthew, it appears to me that you are only making use of the two elements of <code>data</code> whose keys are the top two in the sort. Please correct me if I am wrong. If that is the case, I believe your code (after \"edit\") can be simplified to this:</p>\n\n<pre><code> def self.fetch_data(co...
{ "AcceptedAnswerId": "39535", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T23:50:49.243", "Id": "39523", "Score": "3", "Tags": [ "ruby", "cyclomatic-complexity" ], "Title": "Ruby function to fetch, filter, and generate data" }
39523
<p>I am trying to emulate a basic CPU (Z80) as close as possible. It currently does not read real assembly code, but that will be implemented. If you have any views on how that could be implemented, I'd really appreciate it. Instead of reading real assembly code, I made up a simpler version with the knowledge I had a...
[]
[ { "body": "<blockquote>\n <p>It currently does not read real assembly code, but that will be implemented.</p>\n</blockquote>\n\n<p>Real assembly code might look like <a href=\"http://sgate.emt.bme.hu/patai/publications/z80guide/part4.html#shift\" rel=\"nofollow\">this</a>:</p>\n\n<pre><code>ld a,%11010011 ...
{ "AcceptedAnswerId": "39545", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T00:31:14.837", "Id": "39526", "Score": "8", "Tags": [ "c", "beginner", "assembly", "simulation" ], "Title": "Improvements/suggestions for my CPU emulator" }
39526
<p>I saw this problem posted as an interview question asked at Bloomberg:</p> <blockquote> <p>Given an integer N, print numbers from 1 to N in lexicographic order. Restriction. One cannot use strings or characters.</p> </blockquote> <p>Below is my solution to this problem. Can the algorithm be improved?</p> <pre...
[]
[ { "body": "<p>Okay, let me point out some stylistic things first:</p>\n\n<ul>\n<li>Doing <code>traceback.print_exc()</code> in an except block feels somewhat odd. Either you hide the stack trace by printing your own error message—which is actually helpful to the end user—or you leave the exception as it is.</li...
{ "AcceptedAnswerId": "39600", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T02:33:15.590", "Id": "39529", "Score": "1", "Tags": [ "python", "interview-questions" ], "Title": "Printing numbers in lexicographic order" }
39529
<p>I recently got started with Elixir. I'm used to F#'s pipes, and <code>Seq.map</code> and LINQ's <code>.Select</code> statements. Things are different in Elixir, and the code I have seems very ugly. Anon functions in anon functions.</p> <pre><code>defrecord FileData, name: "", date: nil def filedetails() do ...
[]
[ { "body": "<p>I'm not sure why you'd need to pipe three different streams - one for every manipulation. I'd probably use one Stream to do all the manipulations together, something like:</p>\n\n<pre><code>filedates = files |&gt; Stream.map &amp;((&amp;1 |&gt; File.stat!).ctime |&gt; datastr.())\n</code></pre>\n\...
{ "AcceptedAnswerId": "60017", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T03:56:26.670", "Id": "39532", "Score": "7", "Tags": [ "functional-programming", "lambda", "elixir" ], "Title": "Elixir pipes and anonymous functions" }
39532
Elixer is a functional programming language that runs on the Erlang VM. It is closely related to Erlang and Ruby.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T03:58:40.803", "Id": "39534", "Score": "0", "Tags": null, "Title": null }
39534
<p><a href="http://elixir-lang.org/" rel="nofollow"><strong>Elixir</strong></a> is a functional meta-programming aware language built on top of the Erlang VM. It is a dynamic language with flexible syntax with macros support that leverages Erlang's abilities to build concurrent, distributed, fault-tolerant applications...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T04:21:22.083", "Id": "39536", "Score": "0", "Tags": null, "Title": null }
39536
Elixir is a functional meta-programming aware language built on top of the Erlang VM. It is a dynamic language with flexible syntax with macros support that leverages Erlang's abilities to build concurrent, distributed, fault-tolerant applications with hot code upgrades.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T04:21:22.083", "Id": "39537", "Score": "0", "Tags": null, "Title": null }
39537
<p>I need a review of the following code for finding all permutations of a string in C++:</p> <pre><code>List Permute(const String&amp; string) { if (string.length == 0) return EmptyStrings(1); List prevList = Permute(SubString(string,1,string.length)); List nextList = EmptyStrings(string.length*pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T18:17:46.580", "Id": "66311", "Score": "1", "body": "This is cheating, but I thought it would be nice to mention that [<algorithm>](http://www.cplusplus.com/reference/algorithm/) has useful functions for this such as [next_permutati...
[ { "body": "<p>You may need to remove duplicates. Consider what your output will be if, for example, your input string is <code>\"aaa\"</code>.</p>\n\n<hr>\n\n<p>Code like this is unusual:</p>\n\n<pre><code>// nextList contains an array of empty strings\nnextList[i*string.length+j] += SubString(prevList[i],0,j);...
{ "AcceptedAnswerId": "39544", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T10:35:04.047", "Id": "39543", "Score": "3", "Tags": [ "c++", "strings", "combinatorics" ], "Title": "Find all permutations of a string in C++" }
39543
<p>I request you to provide insightful suggestions to improve the following code as well as an alternative algorithm to solve it.</p> <p><strong>Problem Specification:</strong></p> <blockquote> <p>We'll say that a &quot;mirror&quot; section in an array is a group of contiguous elements such that somewhere in the array,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T17:07:51.743", "Id": "66305", "Score": "2", "body": "By your interpretation, what should `maxMirror({1, 2, 1, 2, 1})` return?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T17:13:02.937", "Id": "...
[ { "body": "<p>My approach is to have two indexes. The <code>i</code> index starts at the left and the <code>j</code> index starts at the right of the array. For a length of 4, we would do these comparisons in this order.\n<code>(0, 3), (0, 2), (0, 1)</code>, then <code>(1, 3), (1, 2)</code>, then, <code>(2, 3)<...
{ "AcceptedAnswerId": "39559", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T16:48:55.150", "Id": "39551", "Score": "9", "Tags": [ "java", "beginner", "algorithm", "programming-challenge" ], "Title": "Codingbat maxMirror challenge" }
39551
<p>To add line numbers to a file (via <code>stdin</code> to <code>stdout</code>) we can use <code>cat -n</code> or <code>nl</code>.</p> <p>Given the file test.txt with:</p> <blockquote> <pre><code>hello hello bye </code></pre> </blockquote> <p>We can do:</p> <pre><code>$ cat -n &lt; test.txt 1 hello 2 h...
[]
[ { "body": "<p>It seems you need <code>through</code> and <code>split</code> to do the piping right. You do not need <code>sprintf</code> as you could build the number formatting yourself. You also do not need <code>fs</code>, you do not use it anywhere.</p>\n\n<p>Something like</p>\n\n<pre><code>var through = r...
{ "AcceptedAnswerId": "40155", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T18:44:47.573", "Id": "39554", "Score": "7", "Tags": [ "javascript", "strings", "node.js", "io" ], "Title": "Node.js equivalent of cat -n or nl" }
39554
<p>I came up with the following solution to find the number of prime numbers from 1 to <em>n</em>.</p> <p>I'm wondering if there is a more optimal way.</p> <pre><code>var max = 10; var compositeNumbers = {}; mainLoop: for (var i=2; i&lt;= max;i++) { smallLoop: for (var j=2; j&lt;=Math.ceil(Math.sqrt(i));j++) ...
[]
[ { "body": "<p>I've created the following performance tests to test the changes: <a href=\"http://jsbin.com/EqiKini/3\" rel=\"nofollow noreferrer\">http://jsbin.com/EqiKini/3</a></p>\n\n<p><img src=\"https://i.imgur.com/Cr6XmxK.png\" alt=\"enter image description here\"></p>\n\n<p>I'm going to start out this rev...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T20:19:40.283", "Id": "39557", "Score": "7", "Tags": [ "javascript", "algorithm", "primes" ], "Title": "Number of prime numbers between 1 and n" }
39557
<p>In the process of learning F#, I wrote this code that reads lines of input from the console and stores them in a list.</p> <p>As far as I can tell the code works correctly, but since I'm new to functional programming, I'm not sure if it is written as well as it could have been.</p> <ol> <li>Should I have read char...
[]
[ { "body": "<p>Some small comments</p>\n\n<pre><code> let tuple = handleChar c lines builder\n let newLines = fst tuple\n let newbuilder = snd tuple\n getLines newLines newbuilder\n</code></pre>\n\n<p>can become</p>\n\n<pre><code> let newlines,newbuilder = handleChar c lines builder\n getLines ...
{ "AcceptedAnswerId": "39562", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T20:51:23.560", "Id": "39558", "Score": "9", "Tags": [ "functional-programming", "f#" ], "Title": "Reading input from the console in F#" }
39558
<p>I've been solving problems on checkio (and trying to digest other's code) in order to improve my Python.</p> <p>My main goals are to learn to write more idiomatic Python and to explore the language more fully ("batteries included" is no joke!). I'd like critiques on the following (working) code in terms of pythoni...
[]
[ { "body": "<p>The efficiency of this check must surely be suffering because of the final check.... <em>create a String for each four-some, and compare it against a reference String</em>. In general this will be slow, but, in particular, there can only be 9 reference strings, so why do you have to calculate it e...
{ "AcceptedAnswerId": "39791", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T20:58:42.157", "Id": "39561", "Score": "3", "Tags": [ "python", "matrix", "generator" ], "Title": "Searching a 2D matrix for a consecutive sequence" }
39561
<p>This question is really to help me decide on something. I have started development of my own <em>programming language</em> that I am calling DeliciousWaffle (or maybe samscript).</p> <p>So far it looks pretty cool. I built a compiler in Python, and associated <code>.dw</code> files with it. These files are like ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-04-05T05:16:19.370", "Id": "232744", "Score": "0", "body": "`compiler to interpret` - Umm... compilers don't interpret stuff. Please correct such core terminology issues. [This](http://www.c4learn.com/c-programming/compiler-vs-interpreter...
[ { "body": "<p>It is a beginning. But currently your code is just a thin wrapper around Python function calls. And of course, there is a security problem with \"eval\", because someone could format your harddisk with the right line, if you execute scripts from untrusted sources.</p>\n\n<p>Maybe you should invent...
{ "AcceptedAnswerId": "39575", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T21:43:17.437", "Id": "39565", "Score": "18", "Tags": [ "python", "interpreter", "language-design" ], "Title": "Making my own programming language" }
39565
<p>I'm simple looking for what the general preference is between the below options:</p> <ol> <li><p>anon function directly to variable</p> <pre><code>middleware.customer = function(req, res, next){ req.customer = function(){ var customer = false; if(req.method == "POST") customer = req.body; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T22:06:44.860", "Id": "66334", "Score": "2", "body": "Second version looks best IMO." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T22:17:17.087", "Id": "66340", "Score": "0", "body": "Tha...
[ { "body": "<p>I think B is the best of the three, but here's another alternative using a simple lookup:</p>\n\n<pre><code>middleware.customer = function(req, res, next){\n var methods = {POST: req.body, GET: req.query};\n req.customer = methods[req.method] || false;\n return next();\n}\n</code></pre>\n", ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T22:05:09.777", "Id": "39568", "Score": "6", "Tags": [ "javascript" ], "Title": "Functions that return a variable" }
39568
<p>I need your help to see if the following binary search code is correct. I did my best to cover the corner cases. I wonder if I missed anything.</p> <p>The code as it is with tests (you can play with it online <a href="http://www.typescriptlang.org/Playground/" rel="nofollow">here</a>):</p> <pre><code>function bin...
[]
[ { "body": "<p>That looks jolly complicated. If you haven't read it, look for Jon Bentley's <em>Programming Pearls</em> article on binary search. Here's my version:</p>\n\n<pre><code>var bSearch = &lt;T&gt;(xs: T[], x: T, cmp: (p: T, q: T) =&gt; number): number =&gt; {\n var bot = 0;\n var top = xs.lengt...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T23:37:03.753", "Id": "39573", "Score": "2", "Tags": [ "algorithm", "binary-search", "typescript" ], "Title": "Is this binary search in TypeScript correct?" }
39573
<p>The comprehensive description of the problem can be found <a href="http://www.geeksforgeeks.org/median-of-two-sorted-arrays/" rel="nofollow noreferrer">here</a>. I'm looking for code review, clever optimizations, adherence to best practices. etc.</p> <p>This code is also a correction of code previously posted <a h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T00:51:38.773", "Id": "66353", "Score": "2", "body": "+1 for clear functional specification, and for updating your suite of test cases." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T18:07:43.330", ...
[ { "body": "<h2>Short Review</h2>\n\n<p>I have spent some hours trying to understand what you do, and why. Given the mess I made of the previous posting of this question, I thought I should spend extra effort to get this one right.</p>\n\n<p>I have failed. I cannot understand the full intent of your code, and, e...
{ "AcceptedAnswerId": "39616", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T00:33:32.923", "Id": "39574", "Score": "3", "Tags": [ "java", "array", "binary-search" ], "Title": "Median of two sorted equal sized arrays on combination" }
39574
<p>I'm writing a utility that validates fields. I decided to try my hand at <a href="http://en.wikipedia.org/wiki/Behavior-driven_development" rel="nofollow">Behaviour Driven Development (BDD)</a>. The validator utilises "rules" to determine if field is valid.</p> <p>Three different types of rules exist:</p> <ol> <li...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T06:59:09.860", "Id": "66375", "Score": "0", "body": "What assertion & test running framework are you using? I don't know if I need to know or not yet, but I would hate to be like \"yeah, everything looks great!\" and miss a really ...
[ { "body": "<p>Let me say up front that I'm far more familiar with <em>unit</em> testing than <em>behavior</em> testing, but this looks an awful like you wrote the tests after the code. When I think of \"behavior\", I don't think of neatly mapping it to method names. Instead I would write use cases that may requ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T01:57:41.617", "Id": "39576", "Score": "7", "Tags": [ "javascript", "unit-testing", "validation", "bdd", "mocha" ], "Title": "Am I implementing BDD correctly?" }
39576
<p>I created a rubber ball by extending instance of b2Body prototype of Box2D.js. I get the instance from factory method <code>b2World#CreateBody</code>.</p> <pre><code>var ball = world.CreateBody(bodyDef); </code></pre> <p>I extended the instance in the constructor of my RubberBall prototype. In result, I made the c...
[]
[ { "body": "<h1>Prototypal Inheritance</h1>\n<p>Now, the very first problem you'll face in your implementation is memory usage. Each <code>RubberBall</code> instance will be creating an internal function - that's a bad thing:</p>\n<pre><code>function RubberBall(){\n this.someFn = function(){...}\n}\n</code></pr...
{ "AcceptedAnswerId": "39582", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T03:51:21.070", "Id": "39578", "Score": "3", "Tags": [ "javascript", "prototypal-class-design", "factory-method" ], "Title": "Extending prototype of given instance from factory ...
39578
<p>Critiques (even pedantic ones) are welcome.</p> <pre><code>bool unique_chars(std::string &amp;s) { if (s.length()&gt;256) return false; std::bitset&lt;256&gt; bs; for (auto &amp;c:s) { if (bs.test(c)) return false; bs.set(c); } return true; } </code></pre> <p><strong>EDIT 1:</st...
[]
[ { "body": "<p>That's pretty good. It's short. The early returns communicate intent well, and since the function is short, they don't get lost. Formatting is good, and the variable names, although very short, are common abbreveviations that work well here.</p>\n\n<p>I'd consider making the argument <code>cons...
{ "AcceptedAnswerId": "39583", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T05:19:03.220", "Id": "39579", "Score": "18", "Tags": [ "c++", "algorithm", "strings", "c++11" ], "Title": "Testing whether characters of a string are unique" }
39579
<p>In this program, I understood everything except <code>power(x1,y1-1)</code>. I want to know how the <code>power(x1,y1-1)</code> function exactly works.</p> <pre><code> #include&lt;iostream.h&gt; #include&lt;conio.h&gt; int power(int,int); void main() { int x,y,p; clrscr(); cout&lt;&lt;"\n\n\t calcula...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T13:29:59.233", "Id": "66389", "Score": "0", "body": "Please fix indentations of your program. It is very hard to read code without proper indentations." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T...
[ { "body": "<p>The laws of recursion are:</p>\n\n<ol>\n<li>Change at least one argument while recurring. The arguments must be changed to be closer to termination</li>\n<li>The changing argument must be tested in the termination condition</li>\n</ol>\n\n<p>(from <a href=\"http://rads.stackoverflow.com/amzn/clic...
{ "AcceptedAnswerId": "39594", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T13:05:32.357", "Id": "39591", "Score": "-2", "Tags": [ "c++", "recursion" ], "Title": "Recursively calculating powers of numbers" }
39591
<p>My program uses graphics convolution, an algorithm that processes pixels to make them round, soft and blurred. This particular algorithm is well-known, but its slowing down the operation of the whole program.</p> <p>Can you suggest any improvements of this algorithm? I tried following from <a href="https://stackove...
[]
[ { "body": "<p><strong>Naming naming naming</strong></p>\n\n<p>Your code is very intimidating - it is filled with single letter variable and members (<code>s,h,e,d</code>...). Those which are not single letter are generic and unhelpful (<code>temp</code>, <code>buffer</code>, <code>notamount</code>...). This mak...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T13:36:52.383", "Id": "39592", "Score": "5", "Tags": [ "java", "performance", "algorithm", "image", "bitwise" ], "Title": "Gaussian blur - convolution algorithm" }
39592
<p>I am working on a simple quiz-type game in which the user basically is asked a series of questions and needs to provide an answer.</p> <p>I'm trying to find a solid/robust way of recording how long it takes for the user to answer each question. This is a web-based game so I am using JavaScript and PHP. I am very in...
[]
[ { "body": "<p>Matt.</p>\n\n<p>Basically, the idea is correct - start the timer on the server side before the question is send to the user and calculate the duration on the response received. Using <code>DateTime</code> for that is also a great idea, in my opinion.</p>\n\n<p>An alternative solution for you would...
{ "AcceptedAnswerId": "39728", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T14:08:10.517", "Id": "39593", "Score": "6", "Tags": [ "php", "ajax", "quiz" ], "Title": "Recording user response times for a quiz" }
39593
<p>I wanted to see the site's <em>top sponsors</em> - users that have paid bounties on questions that they didn't own.</p> <p>I started off with a bounty-related existing query, selected the details into a subquery, and then grouped by sponsor and ended up with <a href="http://data.stackexchange.com/code%20review%20st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T22:59:20.520", "Id": "66441", "Score": "0", "body": "Returns 10 rows in < 1 ms." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T23:26:29.347", "Id": "66448", "Score": "3", "body": "10 rows...
[ { "body": "<p>I would change some things.</p>\n\n<p>This:</p>\n\n<pre><code>inner join Votes bo on q.Id = bo.PostId \n and q.PostTypeId = 1 -- Questions\n and bo.VoteTypeId = 8 -- BountyOpen\n</code></pre>\n\n<p>kind of stuff needs to go in the where statement. The join ...
{ "AcceptedAnswerId": "39670", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T19:10:37.550", "Id": "39602", "Score": "13", "Tags": [ "sql", "sql-server", "t-sql", "stackexchange" ], "Title": "SEDE Top Sponsors" }
39602
<p>I'm trying to implement a left leaning red black tree as described <a href="http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf" rel="nofollow">here</a>. This is their snippet for insert</p> <pre><code>private Node insert(Node h, Key key, Value value) { if (h == null) return new Node(key, value); if (isRed...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-22T19:53:49.560", "Id": "66825", "Score": "1", "body": "Could you please make the code snippet [self-contained](http://sscce.org/), add the data type definition etc., so that it can be readily compiled? It'd help analyzing and perhaps ...
[ { "body": "<p>The code looks much better after refactoring!</p>\n\n<p>Additionally I'd strongly suggest to keep line lengths within some limit. Usual choices are something between 72 and 80. There are two reasons for it:</p>\n\n<ul>\n<li>People with smaller screens aren't able to see a piece code at once and ha...
{ "AcceptedAnswerId": "39943", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T20:55:30.817", "Id": "39607", "Score": "10", "Tags": [ "haskell", "functional-programming" ], "Title": "(How) should I avoid writing procedural code in Haskell?" }
39607
<p><sup>Please note that all credit for code goes to humanoid24 and I have only helped the bare minimum required to be able to post it here.</sup></p> <p>I am working with some friends to replicate a server for the game LEGO® Universe which was shut down two years ago. This code is included in the LUNIServer v3 <a hre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T21:36:59.610", "Id": "66432", "Score": "0", "body": "This question appears to be off-topic because it is about reviewing code that the OP has not written. Please see our [help/on-topic]." }, { "ContentLicense": "CC BY-SA 3.0...
[ { "body": "<p>I've only skimmed a little bit of your code, but here's what I found so far:</p>\n\n<p>Always make sure <code>std::string</code> methods do not return <code>std::string::npos</code>.</p>\n\n<pre><code>size_t pos = temp.find(\"redirect_ip=\", 0)+strlen(\"redirect_ip=\");\n</code></pre>\n\n<p>This c...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T21:07:16.167", "Id": "39608", "Score": "5", "Tags": [ "c++", "optimization", "server", "authentication", "raknet" ], "Title": "LEGO® Universe Authentication Server" }
39608
<p>I am just starting to program in C#, so I am a beginner. I've been practicing some coding and I would like your opinion on something. </p> <p>I have a flying direction for a plane, e.g. ''London - Berlin'' (direction). I want to create a method that will return the first and the last consonant of the plane's start...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T03:46:23.990", "Id": "66480", "Score": "1", "body": "Your code doesn't appear to address surrounding the `-` with spaces like in your example. Is this a bug, or did you just make a mistake when you wrote the example value?" } ]
[ { "body": "<p>Your code is working but repeating all those <code>Replace</code> seems to be unnecessary. Firstly, you repeat them five times for single word and then once again two times because of processing two words. Code becomes long and unclear. Always, when we repeat code, it is good time to think about i...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T21:57:48.923", "Id": "39611", "Score": "12", "Tags": [ "c#", "beginner" ], "Title": "Returning consonants of a plane's starting and ending points" }
39611
<p>I've found a peace of code I've wrote not long ago. It is used to fetch some dictinary from DB table only once and then return it to requestors. Seems like I tryed to implement double-checked locking here. Is it correct? If not, what are the mistakes?</p> <pre><code>package a.b.c.service.orders; import java.util.L...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T00:05:14.977", "Id": "66457", "Score": "1", "body": "See this video: http://www.youtube.com/watch?v=pi_I7oD_uGI#t=2228" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T19:12:12.327", "Id": "66553",...
[ { "body": "<p>There are a few reasons why double-checked locking does not always work in Java. There are a number of blogs with more detail, but I quite like <a href=\"http://www.javaworld.com/article/2074979/java-concurrency/double-checked-locking--clever--but-broken.html\">this one</a> and <a href=\"http://ww...
{ "AcceptedAnswerId": "39625", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T23:13:14.030", "Id": "39617", "Score": "6", "Tags": [ "java", "multithreading", "concurrency" ], "Title": "Double checked locking 101" }
39617
<p>Looking for general feedback and praise. This is for learning an not implementation as I would expect the built is sort algos to be much faster.</p> <p>Addressed issues here:</p> <p><a href="https://codereview.stackexchange.com/questions/38651/a-package-for-sort-algorithms">A package for sort algorithms</a></p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T16:37:08.477", "Id": "66523", "Score": "0", "body": "Is your code faster than the built-in `sort()`, and if not, what is the purpose of this library ?" } ]
[ { "body": "<p>What is the reason for performing internal initialization inside the <code>manageGlobal</code> function? You're already inside a function, and you're operating on its local variables.</p>\n\n<p>Here are some thoughts on the insertion sort (chosen at random):</p>\n\n<ul>\n<li><p>You can start <code...
{ "AcceptedAnswerId": "39623", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-19T23:44:26.230", "Id": "39619", "Score": "2", "Tags": [ "javascript", "sorting" ], "Title": "A package for sort algorithms - v2" }
39619
<p>This is basically the registry pattern and a pub/sub event system.</p> <p>Very simple and minimalist. Looking for general feedback.</p> <pre><code>/*************************************************************************************************** **COMMS - provides registry and event system - reduces dependenc...
[]
[ { "body": "<p>It looks good overall IMO. I won't comment on the bootstrap code as I'm not familiar with your library, but I would change a few things. Inside the closures that you create you could simply return the public object, without defining <code>publik</code>, it looks a bit cleaner. Then I added some an...
{ "AcceptedAnswerId": "39630", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T00:22:53.177", "Id": "39621", "Score": "1", "Tags": [ "javascript", "sorting" ], "Title": "A package for communications between packages - v2" }
39621
<p>This Scala code snippet is supposed to encode a SHA1 hash in base 62.</p> <p>Can you find any issues? I'm asking since I might not be able to change the algorithm and, for example, fix issues in the future.</p> <p>I'd like to be able to also implement it in JavaScript in the future.</p> <pre><code>def mdSha1() = ...
[]
[ { "body": "<p>It is 'standard' to have <code>0-9</code> at the beginning of the 'alphabet' for numbers....</p>\n\n<p>I would have suggested that you use the native functionality in BigInteger to convert the value to a <a href=\"http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#toString%28int%29...
{ "AcceptedAnswerId": "39629", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T02:56:52.933", "Id": "39627", "Score": "3", "Tags": [ "scala", "converting" ], "Title": "Is this base 62 encoding algorithm okay?" }
39627
<p>I'm working on the following interview practice problem, and got the following solution, which runs in worst case <code>n!</code> time (best case constant), and I'm trying to optimize it.</p> <p>Can you offer any suggestions to go about this? I think it should be able to be reduced down to <code>quadratic</code>, i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T03:30:43.243", "Id": "66474", "Score": "0", "body": "First think I would do is, check total of number from array that is less than the given number (in your above case, `6`). If total number is less than `3`, then return `false`" ...
[ { "body": "<p>First, make the array constant. There is no need to change this array or use any other data structure.</p>\n\n<p>You want an outer loop that does something like <code>for (int i : array)</code>.</p>\n\n<p>Inside that outer loop, have another loop like <code>for( (int j = i + 1; j &lt; max; j++)</c...
{ "AcceptedAnswerId": "39636", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T03:13:44.200", "Id": "39628", "Score": "11", "Tags": [ "java", "optimization", "interview-questions", "complexity" ], "Title": "Checking if three numbers sum to a given num...
39628
<p>RakNet is a C++ class library that provides UDP and reliable TCP transport. It contains several core systems that rely on the transport layer: object replication; Remote procedure call in C++ using Boost C++ Libraries; VoIP supporting FMOD, DirectSound, and PortAudio; NAT traversal; and Patch.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T05:19:50.910", "Id": "39638", "Score": "0", "Tags": null, "Title": null }
39638
RakNet is a cross platform, open source, C++ networking engine for game programmers by Jenkins Software
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T05:19:50.910", "Id": "39639", "Score": "0", "Tags": null, "Title": null }
39639