body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<h1>Enter risk!</h1>
<p>This program will roll dice for the game of Risk. The initial input is two numbers separated by a space and if the attackers wish to do a blitz they can add one more space and an "!" to get a positive attack modifier but are committed for an all or nothing fight.</p>
<pre><code>package... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T15:29:00.320",
"Id": "60170",
"Score": "4",
"body": "`\"Please enter the a\" + \"mount [...] separa\" + \"ted by a space.\"`?! I thought splitting the string on multiple lines was supposed to **improve** readability!"
},
{
"... | [
{
"body": "<pre><code>package riskdieroll;\n</code></pre>\n\n<p>Package names are used to associate developers/companies with the code. They normally look like this:</p>\n\n<pre><code>package com.company.yourpackage;\npackage com.gmail.username.yourpackage;\n</code></pre>\n\n<p>This is not a problem if this is ... | {
"AcceptedAnswerId": "36659",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T15:22:18.070",
"Id": "36643",
"Score": "21",
"Tags": [
"java",
"game",
"dice",
"battle-simulation"
],
"Title": "Possible improvements to Risk board game?"
} | 36643 |
<p>I'm trying out a new approach to SASS stylesheets, which I'm hoping will make them more organizined, maintainable, and readable. </p>
<p>I often feel like there is a thin line between code that is well structured and code that is entirely convoluted. I would appreciate any thoughts as to which side of the line this... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T16:12:15.740",
"Id": "60180",
"Score": "1",
"body": "There appears to be a CSS error in your icon-sprite class. You have `vertical-align: -3px`, but the vertical-align property only takes specific values like top/bottom/middle/text... | [
{
"body": "<p>Overall, your naming conventions are pretty good. I don't feel like I need to go look at mixins themselves to figure out what their purpose is. The extensive use of extends does concern me, since it can lead to larger CSS rather than smaller like you might expect (see: <a href=\"https://coderevi... | {
"AcceptedAnswerId": "36652",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T16:01:02.750",
"Id": "36647",
"Score": "3",
"Tags": [
"css",
"sass"
],
"Title": "SASS Code Structure / Readability"
} | 36647 |
<p>Though I have heard about the magic method <code>__autload</code>, I still prefer to use this code:</p>
<pre><code>function autoload($array)
{
foreach ($array as $value)
{
switch ($value)
{
case 'database' :
include ROOT_DIR.'/core/database.php';
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T23:03:16.800",
"Id": "60253",
"Score": "1",
"body": "For reference, this wouldn't be nearly as messy if you stuck to a naming convention. You could easily handle just the odd cases, and let everything else be handled by code that u... | [
{
"body": "<p>It depends if this is for OOP or procedural code. I am assuming OOP as you use class in some of your file names.</p>\n\n<h2>Procedural</h2>\n\n<p>If this is for procedural code then it should be renamed to <code>load</code> as there is nothing auto about it (see the OOP review).</p>\n\n<h2>OOP</h... | {
"AcceptedAnswerId": "36661",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T19:07:12.940",
"Id": "36654",
"Score": "1",
"Tags": [
"php5"
],
"Title": "Simple PHP Autoloader alternative"
} | 36654 |
<blockquote>
<p>You have to find a path through which the rat move from the starting
position (0,0) to the final position where cheese is (n,n). List the
total no of possible paths which the rat can take to reach the cheese.</p>
</blockquote>
<p>Sample Input:</p>
<pre><code>7
0 0 1 0 0 1 0
1 0 1 1 0 0 0
0 0 ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-07-19T19:05:06.860",
"Id": "253481",
"Score": "0",
"body": "There's no input about where the cheese is."
}
] | [
{
"body": "<p>There are not many things to criticize here ... the basic algorithm in general looks good.</p>\n\n<p>The three items I would caution you on are:</p>\n\n<ol>\n<li>you are keeping track of the path-count in the <code>paths</code> static variable. This is a pattern that, although works, is not very '... | {
"AcceptedAnswerId": "36658",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T19:07:49.777",
"Id": "36655",
"Score": "4",
"Tags": [
"java",
"recursion",
"pathfinding"
],
"Title": "Count possible paths through a maze"
} | 36655 |
<p>I have the input image <code>in</code>, and the mask image <code>lev</code> (which label each pixel as a number from 1 to <code>nlevels</code>, <code>nlevels</code>=4). I need to get image out, which from each region <code>in==lev</code> will be replaced by its average value.</p>
<p>Here is my brute force approach.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T04:55:23.437",
"Id": "60292",
"Score": "0",
"body": "I don't really follow your description, especially what average you are taking. Could you provide a simple input / lev / output example? Also if you could comment your code I gues... | [
{
"body": "<h1>Algorithm</h1>\n\n<p>You will benefit greatly from using OpenCV's built-in functionality rather than performing this operation yourself. OpenCV supports masked operations, which will only apply to pixels where the mask is nonzero.</p>\n\n<pre><code>cv::Mat global_average(const cv::Mat& input,... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T19:51:30.370",
"Id": "36656",
"Score": "6",
"Tags": [
"c++",
"algorithm",
"image",
"opencv"
],
"Title": "Replace subimage by its average value"
} | 36656 |
<p>I have previous revisions of my deck of cards project, but I may not need to link them here since the emphasis is on the use of templates.</p>
<p>I've never used them before until now, and I like how intuitive my implementation has become. However, I'm also aware that there are many pitfalls in C++ templates. Alt... | [] | [
{
"body": "<p>The usage of a template parameter named <code>T</code> is generally idiomatic when there are no restrictions on what you can use when instantiating the template; for example, when using container classes <code>T</code> is used as it could potentially be anything. If the parameter is more limited h... | {
"AcceptedAnswerId": "36677",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T19:54:26.297",
"Id": "36657",
"Score": "13",
"Tags": [
"c++",
"template",
"playing-cards"
],
"Title": "Use of templates with templated Deck class"
} | 36657 |
<p>Seeking code correctness and best practices. </p>
<p>I would like to re-allocate various amounts of memory (0 or more) such that on systems that may return <code>NULL</code> for an allocation of 0 does not falsely imply a memory allocation error.</p>
<p>Given:</p>
<ul>
<li><code>void *</code> (with a valid value ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T21:45:45.067",
"Id": "60239",
"Score": "0",
"body": "I already see I should be using `void *` rather than `char *`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T10:00:04.857",
"Id": "60711",
... | [
{
"body": "<p>With the variety of behaviors exhibited by different implementations, I think the only safe thing is to test for zero size before the <code>realloc</code> call and set a minimum allocation (eg 1 byte). </p>\n\n<p>Note that <code>realloc</code> will probably set <code>errno</code> to <code>ENOMEM</... | {
"AcceptedAnswerId": "36669",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T21:39:18.560",
"Id": "36662",
"Score": "6",
"Tags": [
"c",
"memory-management",
"wrapper"
],
"Title": "Critique of realloc() wrapper"
} | 36662 |
<pre><code>var romanArray = [];
var toRoman = {
analyze: function(number){
romanArray = [];
if (number >= 1000) {
return this.thousands(number);
}else if (number >= 100){
return this.hundreds(number);
}else if (number >= 10) {
return this... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T22:03:33.273",
"Id": "60243",
"Score": "0",
"body": "Your example confuses me. What would the variables `four`, `nine`, `five`, and `one` be? The names aren't very descriptive..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>You may be aware that there are simpler answers to this problem, such as:</p>\n\n<pre><code>function toRoman(n) {\n var r = '',\n decimals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],\n roman = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];\n... | {
"AcceptedAnswerId": "36675",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T21:50:15.400",
"Id": "36664",
"Score": "2",
"Tags": [
"javascript",
"converting",
"roman-numerals"
],
"Title": "Number to Roman Numeral"
} | 36664 |
<p>I've been learning Haskell for a few weeks after coming from a C# background. I've written a function to return a number of unique <code>Int</code>s from a specified range:</p>
<pre><code>module MrKWatkins.Random (
uniqueRandomInts
) where
import System.Random
import qualified Data.IntSet as I
uniqueRandomInt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T07:49:14.067",
"Id": "60294",
"Score": "2",
"body": "obligatory http://xkcd.com/221/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-03-20T19:12:17.420",
"Id": "230011",
"Score": "0",
"body": "O... | [
{
"body": "<p>Haskell is very different than other languages.</p>\n\n<p>Here is how I would solve the problem:</p>\n\n<pre><code>import Control.Arrow\nimport System.Random\n\nuniqueRandomInts :: (RandomGen g, Random a)\n => (a, a) -> Int -> g -> ([a], g)\nuniqueRandomInts range n = \n (map fst &... | {
"AcceptedAnswerId": "36678",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T23:36:37.923",
"Id": "36671",
"Score": "5",
"Tags": [
"haskell",
"recursion",
"random"
],
"Title": "Function to produce unique random numbers"
} | 36671 |
<p>I've been playing around with Clojure for a while now, and one of the tasks I occasionally find awkward is parsing input. For example, I took part in the facebook hacker cup recently, where part of the challenge was to read input like this:</p>
<pre><code>5
4
..##
..##
....
....
4
..##
..##
#...
....
4
####
#..#
#... | [] | [
{
"body": "<p>I think your main problem is that you're using <code>iterate</code> where partitioning and <code>map</code>ping would work just fine.</p>\n\n<p>I would create a simple helper function that splits the input line-seq into cases. Normally you could use <code>partition</code> for this, but since the n... | {
"AcceptedAnswerId": "45425",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T00:09:03.627",
"Id": "36672",
"Score": "3",
"Tags": [
"clojure"
],
"Title": "Idiomatic input parsing in clojure"
} | 36672 |
<p>I'm not a dedicated cryptographer, so I'm looking for someone to look over these functions I wrote and let me know if there are any implementation errors leading to security vulnerabilities or just anything I should improve. Any other comments about improving performance, etc. would be great too.</p>
<p>This is us... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T04:26:42.280",
"Id": "60287",
"Score": "1",
"body": "`mysqli_query()` input must be properly escaped. Can you guarantee this happens outside the `EncryptFile()` function?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<ol>\n<li><p><a href=\"http://hu1.php.net/fwrite\" rel=\"nofollow noreferrer\">fwrite</a> returns <code>FALSE</code> on error. You should handle that to avoid dangerous silent data corruption.</p></li>\n<li><p>If you're using PHP 5.5 I guess you could <a href=\"https://stackoverflow.com/q/3549344/843... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T03:00:47.350",
"Id": "36679",
"Score": "6",
"Tags": [
"php",
"ajax",
"cryptography"
],
"Title": "Cryptography implementation for a web-based file server"
} | 36679 |
<p>I have a number of text files (they are reports from a financial system) stored in a directory. Each report has a particular piece of text to search for (eg Report Total) and then a range of characters to extract for the value (e.g. position 78 for 10 characters).
There are a number of these reports - but no more th... | [] | [
{
"body": "<p>The point of filehandles is that it allows you to open more than one file simultaneously. So you could be reading the file list and the files you're searching through simultaneously.</p>\n\n<p>Also, this:</p>\n\n<pre><code>if (grep /$TextToFind[$i]/, $_)\n</code></pre>\n\n<p>Is a a really convolut... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-04T17:45:17.657",
"Id": "36681",
"Score": "5",
"Tags": [
"beginner",
"file",
"csv",
"perl",
"finance"
],
"Title": "Reading CSV files pertaining to financial recorts"
} | 36681 |
<p>Other people will be looking at this jquery code and i'm not an expert with jQuery so im asking. How can i make this jQuery code shorter, more efficient, and easier to read? </p>
<pre><code>/*
HEADER NAVIGATION
*/
/* navigation tabs click highlight */
$(".header-main-tabs").click(function() {
$(".header-main-tabs... | [] | [
{
"body": "<h2>Easier to Read</h2>\n\n<p>Make sure you use the same standard everywhere, indent nicely and be consistent. Then the code already looks a lot better:</p>\n\n<pre><code>/* \nHEADER NAVIGATION \n*/\n\n/* navigation tabs click highlight */\n$(\".header-main-tabs\").click(function() {\n $(\".header... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T07:50:19.267",
"Id": "36686",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "Window-size-dependent navigation menu with animation effects"
} | 36686 |
<p>What can be improved in my code:</p>
<pre><code> using (var oracleConnection = new OracleConnection(ConnectionString))
{
using (var oracleCommand = oracleConnection.CreateCommand())
{
oracleConnection.Open();
oracleCommand.CommandText =
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T08:45:46.463",
"Id": "60300",
"Score": "1",
"body": "You mean like having parametrized queries? Check the docs: http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oraclecommand.parameters%28v=vs.110%29.aspx"
},
{
... | [
{
"body": "<p>You're using <code>using</code> blocks to dispose your disposables, which is excellent. However these blocks increase the nesting of your code; since there's nothing between <code>using (var oracleConnection = new OracleConnection(ConnectionString))</code> and <code>using (var oracleCommand = orac... | {
"AcceptedAnswerId": "36711",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T07:52:22.750",
"Id": "36687",
"Score": "4",
"Tags": [
"c#",
"sql",
"oracle"
],
"Title": "Connecting to Oracle using ODP.NET"
} | 36687 |
<p>I have a program I am writing that calculates Algebra 2 functions and equations. The interface is all CLI, and I even made commands that are similar to shell commands. That's not the part I want review on, so in the interest of space I'm going to consolidate as much as possible. If you want to check out the full pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T09:10:14.410",
"Id": "60304",
"Score": "0",
"body": "Do you assume that a, b, and c are all positive integers?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T16:03:26.287",
"Id": "60369",
"Sc... | [
{
"body": "<h3>1. Bugs</h3>\n\n<ol>\n<li><p>The code fails to factorize \\$x^2 + 2x + 1\\$:</p>\n\n<pre class=\"lang-none prettyprint-override\"><code>>>> Factor().FactorQuad(1, 2, 1)\nError: The quadratic equation is not factorable\nFalse\n</code></pre>\n\n<p>It should print the factorization <code>(x... | {
"AcceptedAnswerId": "36695",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T08:57:51.250",
"Id": "36689",
"Score": "11",
"Tags": [
"python",
"algorithm",
"mathematics",
"symbolic-math"
],
"Title": "Factoring quadratic equation"
} | 36689 |
<p>Below is a code snippet of how I have been laying out my WPF control XAML. I do it mainly because I get intellisense in the editor and I can change the implementation of the viewmodel and push the layout into a resource file.</p>
<p>However, I am not sure whether you gurus have a better insight into why I should no... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T17:34:42.890",
"Id": "60382",
"Score": "0",
"body": "Could you explain how is this user control meant to be used?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T13:20:20.850",
"Id": "60820",
... | [
{
"body": "<p>There are 2 things that I could critisize on your code with the information you gave us:</p>\n\n<ol>\n<li>Don't load style resources inside the usercontrol. Let the application hold control over how to style a usercontrol</li>\n<li>Try not to use a grid in this context, because it prevents the con... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T09:46:07.543",
"Id": "36691",
"Score": "3",
"Tags": [
"c#",
"wpf",
"xaml"
],
"Title": "Is this a good user control layout for WPF?"
} | 36691 |
<p>I'm new to ASP.Net and up until now my code has worked but has been a mish mash all over the place with no real structure. I'm trying to teach myself how to keep the presentation/BLL/DAL separate so I have built a simple page to try and work with. </p>
<p>Page has 3 text boxes: clock number, first name and last nam... | [] | [
{
"body": "<p>Just a few suggestions:</p>\n\n<p>Probably advisable to use Int.TryParse instead of CInt(txtCLock.Text) for parsing user input so you don't get an invalid type exception.</p>\n\n<p>On general error handling you might at least put a try/catch around the logic in txtCLock_TextChanged to catch any er... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T11:01:10.843",
"Id": "36692",
"Score": "1",
"Tags": [
"asp.net",
"vb.net"
],
"Title": "Separating presentation/BLL/DAL"
} | 36692 |
<p>I have a folder called uploads in this folder is a folder for the year the file was uploaded(2013,2014,2015 etc...), inside the year folder are usernames(rick, dan, edward etc...), inside the usernames folder are folders 1-12 for the month that the file was uploaded.</p>
<p>I want to search through the folders and ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T15:58:39.307",
"Id": "60367",
"Score": "0",
"body": "Where do you initialize `$username` and `$userPath` ?"
}
] | [
{
"body": "<p>You might want to try using the <a href=\"http://php.net/manual/en/function.scandir.php\" rel=\"nofollow\">scandir</a> function to build your arrays of directories and files, makes it a bit more future proof.</p>\n\n<pre><code>$baseDir = ABSPATH.\"/uploads\";\n$calendarinfo = cal_info(0); //built-... | {
"AcceptedAnswerId": "36701",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T12:18:45.077",
"Id": "36694",
"Score": "2",
"Tags": [
"php",
"file-system"
],
"Title": "Search through server folders and display files that exist"
} | 36694 |
<p>I am working on using monad transformers in C#. I would like to know if the following code I present, shows that I have understood this. I am fairly new to this so any feedback / comments are really welcome. This example is just for wrapping a maybe monad in a validation monad.</p>
<pre><code>using System;
using NU... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-03T14:52:21.497",
"Id": "60339",
"Score": "0",
"body": "+1 for the effort, but I wonder if maybe the non-standard names will be confusing to people familiar with monads? For instance, it looks like your `Select` is often called `map` ... | [
{
"body": "<p>There isn't much to review here. However I did find this:</p>\n\n<blockquote>\n<pre><code>public class CustomerRepository : ICustomerRepository\n{\n public IValidation<Exception,Customer> GetById(int id)\n {\n if (id < 0)\n return new None<Customer>().ToValid... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-03T14:22:50.407",
"Id": "36699",
"Score": "10",
"Tags": [
"c#",
"functional-programming",
"validation",
"null",
"monads"
],
"Title": "Monad transformers in C# for use in vali... | 36699 |
<p>I wrote this code in Java without using any methods, just by using simple <code>for</code> loop and <code>if</code> statements.</p>
<p>When we input a number, it checks whether it's a prime or not. If it's a prime, then it prints "It's a prime". And if it's not a prime number, it says "It's not a prime" and prints ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T15:15:34.890",
"Id": "60351",
"Score": "0",
"body": "You wrote what code ?!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T15:18:01.860",
"Id": "60352",
"Score": "1",
"body": "Could you p... | [
{
"body": "<p>You don't have to iterate from 2 to y.</p>\n\n<p>It's enough to iterate from 2 to sqrt(y).</p>\n\n<p>This is not necessarily a Java optimization, it's an optimization of the algorithm applicable no matter the implementation.</p>\n\n<p><strong>LATER EDIT</strong></p>\n\n<p>And this is how you can s... | {
"AcceptedAnswerId": "36704",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T15:13:10.763",
"Id": "36703",
"Score": "2",
"Tags": [
"java",
"optimization",
"primes"
],
"Title": "Determining whether or not a number is prime"
} | 36703 |
<p>I have some code below that takes different detected users recognized by the Kinect and assigns them a specific random id range based on the player they are. I use this to grab the x,y coordinates of their left or right hand. I was trying to have the Kinect get at least 6 peoples coordinates with the code. Am I taki... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T16:47:08.053",
"Id": "60375",
"Score": "0",
"body": "Note: the full source is located here: http://kinectmultipoint.codeplex.com/releases/view/104786"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T16... | [
{
"body": "<p>I'm just going to review what's here:</p>\n\n<ol>\n<li>Your comments are excessive. Commented out code helps no one. If you remove code and want it later, that's what version control is for.</li>\n<li>Your method is too long. You should break it into smaller pieces.</li>\n<li><p>Use loops instead ... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T16:43:52.533",
"Id": "36707",
"Score": "2",
"Tags": [
"vb.net"
],
"Title": "Identifying specific players with the kinect?"
} | 36707 |
<p>I wrote the following Fizz Buzz program. How can I improve it or make it more efficient?</p>
<pre><code>public class FizzBuzz
{
public static void main(String[] args)
{
System.out.println("--------Fizz Buzz program-------------");
for(int num=1;num<=100;num++)
{
if(num%3==0)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T18:02:21.547",
"Id": "60393",
"Score": "10",
"body": "Advice to reviewers: This being Code Review, answers of the form \"This is how I would do it: _code_\" are insufficient. Your answer must bear some relationship to the code in th... | [
{
"body": "<p>You have some redundant code there .... there is no need for the code :</p>\n\n<pre><code> if(num%3==0) \n System.out.println(\"FizzBuzz\");\n else\n</code></pre>\n\n<p>in the <code>else if(num%5==0)</code> side of the program. This is because if the number was <code>% 3 ==0</code> it wo... | {
"AcceptedAnswerId": "36715",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T16:59:25.870",
"Id": "36708",
"Score": "11",
"Tags": [
"java",
"beginner",
"performance",
"fizzbuzz"
],
"Title": "Efficient FizzBuzz"
} | 36708 |
<p>The aim is to enumerate all possible sets of whole numbers whose sum is a given integer.</p>
<pre><code>class partition
{
public static void main(String[] ar)
{
part(66);
}
public static void part(int n)
{
part(n,1,"");
}
public static void part(int n, int st, String pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T19:38:25.577",
"Id": "60402",
"Score": "2",
"body": "Can you please describe what \"partition an integer\" means?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T20:41:40.690",
"Id": "60555",
... | [
{
"body": "<p>My first observation is that your variable names mean nothing. <code>n</code> and <code>st</code> should describe what they are supposed to represent. </p>\n\n<p>I don't like having the <code>println</code> in the <code>part</code> function. In my opinion, the value should be returned back up t... | {
"AcceptedAnswerId": "36724",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T19:32:48.880",
"Id": "36722",
"Score": "6",
"Tags": [
"java",
"combinatorics"
],
"Title": "Integer Partition"
} | 36722 |
<p>I would like the have a second opinion on my code I've written to calculate <code>e</code></p>
<p><code>e</code> is an integer that you wherefore the following counts <code>gcd(φ(n),e) = 1 with 1 < e < φ(n)</code></p>
<pre><code>public int calce()
{
do
{
e = priemgen.newKey(1, euler);
} w... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T21:11:24.837",
"Id": "60414",
"Score": "0",
"body": "Could you clarify this sentence please: `e is an integer that you wherefore the following counts`? I have trouble understanding what it should mean."
},
{
"ContentLicense"... | [
{
"body": "<p>There is not a huge amount of code to review here, just a few things:</p>\n\n<ol>\n<li><p>You have a method <code>NewPrime</code> which I assume provides a prime number between the two bounds provided. Yet you do not use it and call <code>priemgen.newKey</code> directly in <code>calce</code>. You ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T20:27:55.560",
"Id": "36726",
"Score": "3",
"Tags": [
"c#"
],
"Title": "RSA calculating e in C#"
} | 36726 |
<p>The game will be combination of text adventure (navigate through buttons), RPG, sandbox, strategy and turn-based game where the main task of player is to explore the game's world and survive (since I cannot classify my game with one genre just yet, I'm still experimenting).</p>
<p>The interaction between player and... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T22:11:49.900",
"Id": "60422",
"Score": "0",
"body": "One problem jumps out `if(true)` is a useless `if` statement that causes clutter. Remove it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T15:33... | [
{
"body": "<p>When reading your code, the <a href=\"http://altreus.github.io/qi-klaxon/?Strategy+Pattern\" rel=\"nofollow noreferrer\">Strategy Pattern alarm</a> goes off in my head. Before that however, I have some other remarks.</p>\n<ul>\n<li><p>Indentation. If you are using Eclipse, please select your code ... | {
"AcceptedAnswerId": "36742",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T21:24:34.460",
"Id": "36732",
"Score": "4",
"Tags": [
"java",
"performance",
"android"
],
"Title": "Adding buttons for a text adventure game"
} | 36732 |
<p>I've never done a FizzBuzz before, so I decided I would. Please let me know what I could have done better. This is ran via a .bat file in Windows.</p>
<pre><code> @echo off
set loopStart=1
set loopEnd=100
set /a i=%loopStart% - 1
:LoopStart
if %i% == %loopEnd% goto :LoopEnd
set /a i=%i% + 1
set /a... | [] | [
{
"body": "<p>Use FOR /L to iterate a range of numbers - much faster than SET /A with GOTO loop.</p>\n\n<p>Use SETLOCAL to localize variables so no need to undefine them. The EnableDelayedExpansion option does just that so that you can use <code>!var!</code> within a FOR loop.</p>\n\n<p>A minor optimization - i... | {
"AcceptedAnswerId": "36745",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T22:00:48.243",
"Id": "36735",
"Score": "9",
"Tags": [
"fizzbuzz",
"batch"
],
"Title": "Batch-File FizzBuzz"
} | 36735 |
<p>I created a quiz using the module pattern. My code is as follows:</p>
<pre><code>; (function ($) {
"use strict";
var s,
QuizDefaults = {
modalOverlay: $(".modal-overlay"),
modalWrap: $(".js-modal-container"),
timer: null, // setInterval var for timer
totalSeconds: 10... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T12:03:22.453",
"Id": "60482",
"Score": "0",
"body": "Can you add the html to go with this? Even better a [fiddle](http://jsfiddle.net/) also."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T19:05:22.8... | [
{
"body": "<ol>\n<li><p>Slight issue in your JavaScript. I can't find <code>s</code> declared. I assume it should have been <code>settings</code>.</p></li>\n<li><p>String concatenation inside a loop is not a good idea for performance. I'd also try to keep the addition to the DOM till after the loop.</p></li>\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T22:21:44.840",
"Id": "36736",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html",
"closure"
],
"Title": "Deeper abstracting of code into functions"
} | 36736 |
<pre><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<tit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T22:29:41.357",
"Id": "60423",
"Score": "5",
"body": "Explain what your code is doing, please."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T22:31:56.433",
"Id": "60425",
"Score": "0",
"b... | [
{
"body": "<p>Just a few things (not including the obvious suggestion to try an object-oriented implementation - though I prefer it, a script of this size won't hurt anyone this way):</p>\n\n<ol>\n<li>Your <code>switch()</code> statement doesn't have a <code>default:</code> case. What\nhappens if there's a pro... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T22:25:36.880",
"Id": "36737",
"Score": "0",
"Tags": [
"php",
"html"
],
"Title": "Car Rental Form"
} | 36737 |
<p>I have project where I need to use C# and Entity Framework.</p>
<p>After my question <a href="https://stackoverflow.com/questions/20277478/entity-framework-create-and-update-related-objects-in-wpf">here</a>, I have decided to use Unit of Work and Repository patterns. </p>
<p>This is the first time when I'm using t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T23:32:07.923",
"Id": "60439",
"Score": "0",
"body": "Group entity vs GroupId: choose one, stick to it. You can specify either, or both. I think you're getting an exception because your navigation property isn't `virtual`."
},
{... | [
{
"body": "<p>That looks pretty good but it depends on what your controller looks like. </p>\n\n<p>There is a valid argument that the Entity Framework implements the Repository Pattern for you and all you need to implement is the service layer. </p>\n\n<p>So you could put the service layer directly on top of t... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T23:15:37.317",
"Id": "36738",
"Score": "4",
"Tags": [
"c#",
"design-patterns",
"entity-framework"
],
"Title": "Is this correct usage of Repository + Unit of Work + Service Pattern... | 36738 |
<p>I'm creating a simple <a href="http://en.wikipedia.org/wiki/Syslog" rel="nofollow">syslog server</a> in Delphi XE2 using Indy's <code>TIdSyslogServer</code>. I've decided to make it dump into a <code>TClientDataSet</code> and display in a <code>TDBGrid</code>, but I'm skeptical about how well it would handle if the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T01:18:33.853",
"Id": "60451",
"Score": "0",
"body": "I'm kinda wondering if this type of question is better off on programmers SE?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T01:22:46.197",
"I... | [
{
"body": "<p><code>TClientDataset</code> will work fine for this purpose, except for the \"million of records\". I don´t believe that any dataset will have a good response for such an amount of data, so I think you will have to work some kind of paging system and keep in the dataset only some hundreds or thoud... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T01:00:07.670",
"Id": "36743",
"Score": "1",
"Tags": [
"performance",
"logging",
"delphi",
"server"
],
"Title": "Is it feasible to create a syslog server which writes to a clie... | 36743 |
<p>I have code that checks the range of a value and sets a variable accordingly. </p>
<pre><code>if ( 169 <= angle && angle < 191 ) {currentOrientation = "1";}
if ( 191 <= angle && angle < 214 ) {currentOrientation = "2";}
if ( 214 <= angle && angle < 236 ) {currentOrientation... | [] | [
{
"body": "<p>Use <code>else if</code> statements after the first <code>if</code> so that it breaks out of the comparisons when a match is found:</p>\n\n<pre><code>if ( 169 <= angle && angle < 191 ) {currentOrientation = \"1\";}\nelse if ( 191 <= angle && angle < 214 ) {currentOrient... | {
"AcceptedAnswerId": "36749",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T01:47:12.460",
"Id": "36744",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"optimization",
"mathematics"
],
"Title": "Find number matching range"
} | 36744 |
<p>Some recent discussions on this site involved the <strong>Fizz-Buzz</strong> game - I have never actually implemented this, but for the record this is what I put together:</p>
<pre><code>public class FizzBuzzConverter
{
private readonly int _fizz;
private readonly int _buzz;
public FizzBuzzConverter(in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T10:45:34.603",
"Id": "60474",
"Score": "1",
"body": "[According to Jeff, it is how you write FizzBuzz.](http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html)"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>I'd first create an <code>interface</code> that your <code>FizzBuzzConverter</code> class can implement:</p>\n\n<pre><code>public interface IConverter\n{\n string Convert(int value);\n}\n\npublic class FizzBuzzConverter : IConverter\n{\n // ...\n}\n</code></pre>\n\n<p>Then the <code>PseudoBr... | {
"AcceptedAnswerId": "36753",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T03:34:20.190",
"Id": "36750",
"Score": "5",
"Tags": [
"c#",
"fizzbuzz",
"ai"
],
"Title": "PseudoBrain FizzBuzz Thoughts"
} | 36750 |
<p>I've been reading about <code>WeakPointer</code> and <code>WeakPointer<T></code> today, and it looks very useful. Rather than just using it as-is though, I decided to write a wrapper around it that covers a common usage case for me.</p>
<p>Code as follows:</p>
<pre><code>public class Temporary<T> wher... | [] | [
{
"body": "<p>It's pretty good, clean and simple code. Not a lot to critique really. A few minor things:</p>\n\n<ol>\n<li><p>Some people (myself included) prefer to prefix private fields with <code>_</code>. This way it's easy to see that it's a field rather than a local variable (and gets rid of the <code>this... | {
"AcceptedAnswerId": "36757",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T04:55:30.787",
"Id": "36754",
"Score": "4",
"Tags": [
"c#",
"generics",
"weak-references"
],
"Title": "Generic 'temporary instance' class"
} | 36754 |
<p><strong>Disclaimer: The code already was graded - so I don't ask for a homework here -just for a code review. :)</strong></p>
<p>For a university course my colleagues and I had to implement a list without using any Arrays or any utilities from java collections. Only interfaces were allowed.</p>
<p>We received a sm... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T13:34:49.243",
"Id": "60487",
"Score": "0",
"body": "A comment about `Tuple.toString`, in this case you can concat Strings without StringBuilder: `\"(\" + this.xCoordinate+ \" ,\" + this.yCoordinate + \")\"`. The only situation wher... | [
{
"body": "<p>Just some comments on your code:</p>\n\n<ul>\n<li>Don't call your Iterator <code>ListIterator<T></code> - that is the name of an interface in <code>java.util</code> and it confused me for a moment.</li>\n<li>It is 'unconventional' to use positive/negative positions to insert values relative ... | {
"AcceptedAnswerId": "36781",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T08:41:25.103",
"Id": "36759",
"Score": "5",
"Tags": [
"java",
"linked-list",
"generics"
],
"Title": "Implementation of a double linked list with generics and inheritance"
} | 36759 |
<p>I wrote the following Caml light code to find prime factors of a number (part of an early <a href="http://projecteuler.net/problem=3" rel="nofollow">Project Euler question</a>).</p>
<blockquote>
<p><strong>Largest prime factor</strong></p>
<p>The prime factors of 13195 are 5, 7, 13 and 29.</p>
<p>What i... | [] | [
{
"body": "<p>I guess that I should not be giving you an answer, but guide you. So, one general remark that I have: stylistically, it would be preferable to see you start with</p>\n\n<pre><code>let largest_factor n =\n let rec aux_factor d n =\n ...\n in \n # some expression involving to aux... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T09:51:23.350",
"Id": "36762",
"Score": "2",
"Tags": [
"primes",
"project-euler",
"ocaml"
],
"Title": "Caml light and finding the prime factors"
} | 36762 |
<p>I have written this code for cookie parsing. Can anyone tell me what optimizations we can do in this or what can we do to make it more concise? </p>
<pre><code>function parseCookies(cookies) {
var cookie,
cookieParts,
parsedCookies = [];
if (!cookies || !cookies.length) {
return null;
}
// Rem... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T18:24:31.993",
"Id": "60533",
"Score": "0",
"body": "Could you add examples of input and output? As far as I can tell, this isn't so much a parser but rather a sanitizer, since it returns the same format, just with some stuff remove... | [
{
"body": "<p>This question is a great candidate for using Array.map and Array.filter. That is, if you are willing to return [] instead null if cookies is not provided.</p>\n\n<p>Basically you map cookies to a new array which has modified cookies, and you filter out the value from the cookie that you don't want... | {
"AcceptedAnswerId": "36817",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T11:35:56.543",
"Id": "36765",
"Score": "1",
"Tags": [
"javascript",
"optimization",
"parsing"
],
"Title": "How to optimize Cookie Parsing?"
} | 36765 |
<p>Which of these two alternatives is more readable?</p>
<pre><code>token = map.get(token_str)
if not token:
token = Course(token_str)
return token
</code></pre>
<p>or</p>
<pre><code>token = map.get(token_str)
token if token else Course(token_str)
</code></pre>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T12:07:27.687",
"Id": "60483",
"Score": "3",
"body": "How about `token = map.get(token_str) or Course(token_str)`? Or `token = map.get(token_str, Course(token_str))` if map is a dict?"
}
] | [
{
"body": "<p>In python, a common style is \"easier to ask for forgiveness than permission\" (<a href=\"http://docs.python.org/2/glossary.html#term-eafp\" rel=\"nofollow\">http://docs.python.org/2/glossary.html#term-eafp</a>). I.e.</p>\n\n<pre><code>try:\n return map[token_str]\nexcept KeyError:\n return ... | {
"AcceptedAnswerId": "36771",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T12:00:09.080",
"Id": "36766",
"Score": "1",
"Tags": [
"python"
],
"Title": "Python - ternary operator or if statement?"
} | 36766 |
<p>I made a small text adventure. I'm not trying to make it appealing to anyone, but rather just to practice my Python skills. I am fairly new to Python and this was my next step after making a console calculator and BMI calculator. I would like someone to tell me how this code could be better optimised, less work, et... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T12:49:11.960",
"Id": "60484",
"Score": "1",
"body": "See [this question and its answers](http://codereview.stackexchange.com/q/16126/11728)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T13:44:27.60... | [
{
"body": "<p>You have a lot of repetition in your code, which is something you should focus on reducing.\nFor example, this recurring pattern: </p>\n\n<pre><code>ch2 = str(input(\"Do you approach the object? [y/n]\"))\n\n# APPROACH SPIDER\nif ch2 in ['y', 'Y', 'Yes', 'YES', 'yes']:\n</code></pre>\n\n<p>... can... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T12:37:24.807",
"Id": "36768",
"Score": "14",
"Tags": [
"python",
"optimization",
"beginner",
"adventure-game"
],
"Title": "Tiny text adventure"
} | 36768 |
<p>I must read and extract some values from string. These values are coded like this:</p>
<pre><code>k="11,3,1" v="140.3"
</code></pre>
<p>I have defined the codes and created struct with all field as well as a temp one where I store k and v. In fillFields proc I transfer values from temp struct to the right one (wi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T19:26:12.787",
"Id": "60544",
"Score": "0",
"body": "This is a more applicable forum for http://stackoverflow.com/questions/20423447/how-can-i-do-it-smarter/20424944#20424944"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Crea... | [
{
"body": "<p>I am not sure, what you mean by 'smarter', but here is a possible speed improvement:</p>\n\n<p>If k is always ASK, BID or CLOSE, and nothing else, you can avoid calling <code>strcmp(..)</code> because looking at the 4th character shows which case it is</p>\n\n<pre><code>#define ASK ... | {
"AcceptedAnswerId": "36795",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T13:21:40.430",
"Id": "36774",
"Score": "5",
"Tags": [
"c",
"parsing"
],
"Title": "Parsing key-value pairs to fill a struct"
} | 36774 |
<p>Here are a couple of examples of one-liners that go way beyond 80 characters:</p>
<pre><code>scope = DepartmentRepository.includes(:location).by_account(@request.account_id).find(approved_department_ids)
departments = ActiveModel::ArraySerializer.new(scope, each_serializer: DepartmentWithLocationSerializer).as_json... | [] | [
{
"body": "<p>I don't really see any real trouble with those lines. But I know the feeling that a line just seems \"too long\" (especially if everything else in the file is nice and neat). It's often a good thing to notice, but in some cases it just doesn't make sense to worry.</p>\n\n<p>Are the lines readable?... | {
"AcceptedAnswerId": "36802",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T14:41:39.897",
"Id": "36782",
"Score": "5",
"Tags": [
"ruby"
],
"Title": "How do I refactor lines of Ruby code that run too long due to method chaining or object instantiation?"
} | 36782 |
<p>I have a Google Maps Geocoder and I am looking to refactor it. The user enters address details into a form where at the bottom there is the option to show on map. </p>
<ul>
<li>First the map is hidden</li>
<li>The user clicks <code>show_map</code> checkbox</li>
<li>Map-area is shown</li>
<li>Map is initialized</li... | [] | [
{
"body": "<p>The main change I would make is to reduce the responsibility of <code>codeAddress()</code> to do just the geocoding. If it successfully looks up the address, then it can pass the location to a callback.</p>\n\n<p>I don't have enough context to tell whether <code>geocoder</code>, <code>map</code>,... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T15:54:07.787",
"Id": "36785",
"Score": "3",
"Tags": [
"geospatial",
"google-apps-script",
"google-maps"
],
"Title": "Entering address details into Google Maps geocoder"
} | 36785 |
<p>I was asked to write a permutation algorithm to find the permutations of {a,b,c}. Since this is a famous question to which an answer is readily available online, I wanted to do it a little differently, so that it won't look like I copied off the Internet. It was evaluated as OK for the algorithm being correct, but s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T19:39:42.423",
"Id": "60659",
"Score": "1",
"body": "You know there is a standard function `std::next_permutation()` http://www.cplusplus.com/reference/algorithm/next_permutation/"
}
] | [
{
"body": "<p>you pre generate all permutations, this means that when you have 20 elements you have <code>20! = 2.432902e+18</code> possible permutations all needing to reside in memory when the algorithm finishes</p>\n\n<p>then you copy all vectors over and over, also not a good idea as that requires a lot of ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T16:03:01.787",
"Id": "36786",
"Score": "5",
"Tags": [
"c++",
"performance",
"algorithm",
"combinatorics"
],
"Title": "Permutation algorithm"
} | 36786 |
<p>I just wrote this simple code, but I have a problem. I get the factorial for small numbers, but if I enter number like 45 or above, I get 0 as the factorial. Why is that? Check and let me know what you think:</p>
<pre><code>import java.util.*;
public class Testing1 {
public static void main (String args[]){
Sc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T18:18:48.927",
"Id": "60532",
"Score": "0",
"body": "You don't need a loop to calculate the sum of the first `n` numbers."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T18:30:39.497",
"Id": "6053... | [
{
"body": "<p><code>45!</code> is a very large number. Your <code>fact</code> is a <code>long</code>, but <code>long</code> is not large enough to hold the value...</p>\n\n<pre><code>44! = 2673996885588443136\nLong.MAX_VALUE = 9223372036854775807\n</code></pre>\n\n<p>Multiplying <code>44!</code> by 4... | {
"AcceptedAnswerId": "36790",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T16:21:50.363",
"Id": "36788",
"Score": "-1",
"Tags": [
"java"
],
"Title": "Determining the factorial and the summation of numbers until that number"
} | 36788 |
<p>I'm curious about <code>Object.defineProperty</code>. It seems awfully verbose for not doing much more than what you can already do in the constructor. What's the point of it? Would it be 'bad code' to not use it? I know you have more control over read/write and enumerability with defineProperty, is that enough ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T16:34:41.833",
"Id": "60513",
"Score": "0",
"body": "You usually only use defineProperty in very specific cases. (let's say you wanted validation on age?) - in your case - I would not use it."
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<p>As requested by tomdemuyt. I'm posting my comments as an answeR:</p>\n\n<p>You usually only use <code>defineProperty</code> in very specific cases. (let's say you wanted validation on age?) - in your case - I would not use it.</p>\n\n<p>Op then asked:</p>\n\n<blockquote>\n <p>offhand can you thin... | {
"AcceptedAnswerId": "36797",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T16:32:32.367",
"Id": "36791",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "JavaScript Object.defineProperty"
} | 36791 |
<p>I am building an web application that is going to work in a similar way like photoshop or illustrator regarding layers. Here are my code that is searching the ".case" div for images, and then put these images id's to an array. When that is done we are looping the array to find out if the received image is the same a... | [] | [
{
"body": "<p>I'm not sure if I understand what you're doing correctly.</p>\n<p>So essentially each image has itself, and then some other element that should be before it as a buddy? Assuming they are all siblings, you should utilize some of jQuery's functions that support working with siblings.</p>\n<p>Here's ... | {
"AcceptedAnswerId": "36800",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T16:47:20.493",
"Id": "36793",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Optimize “layering” in jQuery"
} | 36793 |
<p>We have a binary tree, suppose like this:</p>
<pre><code> 8
/ \
6 10
/ \ / \
4 7 9 12
/ \
3 5
</code></pre>
<p>We have to print this binary tree in top-down manner - column wise. Note that, <code>8, 7 & 9</code> would be considered in same column. So the required output sho... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T21:03:52.157",
"Id": "60560",
"Score": "0",
"body": "The challenge seems ill formed. What if \"7\" has two complete levels under it? I think you would probably consider the left child of \"7\" to share the same column as \"5\". What... | [
{
"body": "<p>Using recursion in this instance helps a lot to reduce code duplication. Particularly, in this case, you have different code blocks depending on whether <code>left()</code> or <code>right()</code> are null.</p>\n\n<p>Using recursion you only need one null check, and this removes a big chunk of cod... | {
"AcceptedAnswerId": "36804",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T18:06:33.427",
"Id": "36799",
"Score": "14",
"Tags": [
"java",
"algorithm",
"interview-questions",
"tree"
],
"Title": "Printing a Binary Tree top-down (column wise)"
} | 36799 |
<p>I'm just starting to get along with threads in Java and I need some code review,
about interfaces, classes, managing threads, correct writing, secure threads, exposed objects etc.</p>
<p>Horse-Race Implementation:</p>
<pre><code>package HorseRace;
public interface FinishingLine {
public void arrive(Horse h);... | [] | [
{
"body": "<pre class=\"lang-java prettyprint-override\"><code>// package name should be lower case\npackage HorseRace;\n\npublic interface FinishingLine {\n\n public void arrive(Horse h);\n}\n\npackage HorseRace;\n\nimport java.util.Vector;\n\npublic class FinishingLineImpl implements FinishingLine {\n\n ... | {
"AcceptedAnswerId": "36809",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T18:55:10.970",
"Id": "36806",
"Score": "4",
"Tags": [
"java",
"thread-safety",
"simulation",
"multithreading"
],
"Title": "Multithreaded horse race simulation"
} | 36806 |
<p>Please review my code based off of a responsive Initializr template. It's functional and visually correct, but I know there's better ways to write the code. Let me know if I can layout the HTML5 better and/or best practices I'm not using for CSS selectors because I feel my stylesheet is all over the place.</p>
<p><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T20:15:02.737",
"Id": "60547",
"Score": "2",
"body": "I'd recommend trying to split the CSS section into separate parts since it's quite a large code block."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12... | [
{
"body": "<p>Since I don't have high enough rep to comment, I'll post this instead...</p>\n\n<p>fyi: @import vs <a href=\"https://stackoverflow.com/questions/7199364/import-vs-link\">https://stackoverflow.com/questions/7199364/import-vs-link</a>\nI'd keep the same master stylesheet if it were me.</p>\n\n<hr>\... | {
"AcceptedAnswerId": "41785",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T20:12:40.273",
"Id": "36812",
"Score": "7",
"Tags": [
"html",
"css"
],
"Title": "Web page code based off of a responsive Initializer template"
} | 36812 |
<p>I haven't had much experience with postgresql (none) and I am wondering/hoping that there is a better way for me to do this query.</p>
<pre><code>SELECT * FROM member_copy WHERE id = 17579 OR id = 17580 OR id = 17582 ect.
</code></pre>
<p>There are about 800 where clauses in total so this will take a while and I n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T22:56:12.023",
"Id": "60577",
"Score": "0",
"body": "If there are really 800 where clauses I think you should work on your application"
}
] | [
{
"body": "<p>The way to write that query is:</p>\n\n<pre><code>SELECT * FROM member_copy WHERE id IN (17579, 17580, 17582);\n</code></pre>\n\n<p>However, the real question is, where did that list of <code>id</code>s come from? If the list of <code>id</code>s is the result of another database query, then you s... | {
"AcceptedAnswerId": "36816",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T20:29:57.027",
"Id": "36814",
"Score": "8",
"Tags": [
"sql",
"postgresql"
],
"Title": "SQL query where id=… or id=… or id=… etc"
} | 36814 |
<p>I tried implementing <a href="/q/36722">Integer Partition</a> (enumerating all possible sets of whole numbers whose sum is a given integer).</p>
<p>Looking at <a href="/a/36725/9357">@rolfl's answer</a>, I reasoned that with a stack data structure, we shouldn't need to use recursion, since recursion implicitly stor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T22:05:44.247",
"Id": "60570",
"Score": "1",
"body": "Interesting to set it as an Iterator..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T22:13:33.023",
"Id": "60572",
"Score": "0",
"bo... | [
{
"body": "<p>I am not sure how to 'review' your code in this case.... I have a sense of 'competition' here, and the moment performance enters the equation, there are things I just know are going to be slower, but I cannot always explain why.....</p>\n\n<p>I think often times it simply comes down to primitives ... | {
"AcceptedAnswerId": "36827",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T20:40:12.560",
"Id": "36815",
"Score": "6",
"Tags": [
"java",
"combinatorics",
"iteration"
],
"Title": "Integer Partition using an iterator"
} | 36815 |
<p>I would like to execute a certain method at a given interval. The reason why I can't use a timer + its event handler right away is because I want to add an offset to each tick (100ms in my example below).</p>
<p>It seems to be working just as intented. The reason why I'm starting it manually is because if the <code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T02:01:02.157",
"Id": "60599",
"Score": "0",
"body": "My `IDisposable` (really my C#) is a little weaker than I like, but isn't that Dispose implementation open to a problem with a second call calling `_timer.Stop()` after `_timer.Di... | [
{
"body": "<p>Do <strong>not</strong> put the random number generator creation in the <code>TimerElapsed</code> method. This could wind up generating the same value if called in succession rapidly. Instead put it at the class level:</p>\n\n<pre><code>private readonly Random _rnd = new Random();\n</code></pre>\n... | {
"AcceptedAnswerId": "36826",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T23:01:10.363",
"Id": "36824",
"Score": "2",
"Tags": [
"c#",
"winforms",
"timer"
],
"Title": "Executing method on a certain interval + offset"
} | 36824 |
<p>I have not tried decorators yet or functions within functions, but this current un-pythonic method seems a little convoluted. I don't like how I need to repeat myself when I check the <code>return_type</code> 3 times.</p>
<p>Any suggestions are welcome, especially if the repetion can be dealt with in an elegant way... | [] | [
{
"body": "<p>I am disregarding some questionable code (such as the fact that <code>'3,,,4'</code> would be handled identically to <code>'34'</code>, and so forth), and as you mention, the fact that <a href=\"http://docs.python.org/dev/library/locale.html\" rel=\"nofollow\">locale</a>'s <code>atof</code> is pro... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T00:53:55.840",
"Id": "36828",
"Score": "1",
"Tags": [
"python"
],
"Title": "What is the best way to deal with multiple return types in Python's is_number?"
} | 36828 |
<p>I'm trying to port the following C loop to Python:</p>
<pre><code>for (int32_t i = 32; --i >= 0;) {
v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
sum -= delta;
v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum >> 11 & 3]);
}
</code></pre>
<p>The problem i... | [] | [
{
"body": "<p>Firstly, the expensive modulo operation <code>% 2**32</code> can be replaced by a cheap bitwise and: <code>& 2**32-1</code>. Make sure to familiarize yourself with operator precedence, because it's not intuitive when it comes to bitwise operators (if you haven't done that yet).</p>\n\n<p>As a ... | {
"AcceptedAnswerId": "36897",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T00:58:01.000",
"Id": "36830",
"Score": "4",
"Tags": [
"python"
],
"Title": "Wrapping every expression with % 2 ** 32 to get a C-like behavior"
} | 36830 |
<p>This code finds all the divisors of a given number. Can it be shortened?</p>
<pre><code>import java.util.Scanner;
public class PrimeNum2{
public static void main(String args[]){
Scanner x=new Scanner(System.in);
System.out.print("Enter the number : ");
long y=x.nextInt(),i;
Sy... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T06:01:37.663",
"Id": "60609",
"Score": "0",
"body": "Why do you start with i = 2? Why not change it to i = 1?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-11-08T06:40:19.063",
"Id": "275137",
"Sc... | [
{
"body": "<p>This code could do with some editing...</p>\n\n<p>First of all is the spacing. It is absolutely horrible (we will fix that after the edits).</p>\n\n<p>Also, the naming is horrible. <code>Scanner x</code> could be <code>scanner</code> and <code>y</code> could be <code>num</code>. As for z, it is co... | {
"AcceptedAnswerId": "58711",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T05:12:03.177",
"Id": "36837",
"Score": "18",
"Tags": [
"java",
"beginner",
"mathematics"
],
"Title": "Finding divisors of a number"
} | 36837 |
Template meta-programming is a meta-programming technique in which templates are used by a compiler to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T05:52:04.407",
"Id": "36839",
"Score": "0",
"Tags": null,
"Title": null
} | 36839 |
<p>This week's review challenge is a poker hand evaluator. I started by enumerating the possible hands:</p>
<pre><code>public enum PokerHands
{
Pair,
TwoPair,
ThreeOfKind,
Straight,
Flush,
FullHouse,
FourOfKind,
StraightFlush,
RoyalFlush
}
</code></pre>
<p>Then I thought I was goin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T08:54:37.900",
"Id": "60612",
"Score": "1",
"body": "What are you trying to do? Determine what hand a person has?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T09:46:38.843",
"Id": "60614",
... | [
{
"body": "<pre><code>public enum PokerHands\n</code></pre>\n\n<p>This type should be called in singular (<code>PokerHand</code>). When you have a variable of this type, it represents a single hand, not some collection of hands. Your other <code>enum</code>s are named correctly in this regard.</p>\n\n<pre><code... | {
"AcceptedAnswerId": "36851",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T06:49:31.033",
"Id": "36841",
"Score": "4",
"Tags": [
"c#",
"linq",
"weekend-challenge",
"playing-cards"
],
"Title": "Poker Hand Evaluator Challenge"
} | 36841 |
<p>I came across an interview question, which is like this:</p>
<blockquote>
<p>You have an array of integers, such that each integer is present an odd number of time, except 3 of them. Find the three numbers.</p>
</blockquote>
<p>I tried implementing it using a <code>HashMap<Integer, Integer></code>, by mapp... | [] | [
{
"body": "<p>Since your map values toggle between 0 and 1, you could just as well use a <code>Map<Integer, Boolean></code> instead.</p>\n\n<p>Usually, it is good practice not to mingle your output routines into your logic. In the absence of any specific instructions from your interviewer, it would have ... | {
"AcceptedAnswerId": "36852",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T07:40:21.033",
"Id": "36842",
"Score": "7",
"Tags": [
"java",
"algorithm",
"array",
"interview-questions"
],
"Title": "Find elements occurring even number of times in an in... | 36842 |
<p>In my first attempt, I have tried to load images from disk and load it to a <code>QTableView</code> using <code>QAbstractTableModel</code>. I'd like a general code review of this code.</p>
<pre><code>import sys
import os
from PyQt4 import QtGui, QtCore
class MyListModel(QtCore.QAbstractTableModel):
def __in... | [] | [
{
"body": "<h2>Abstract Model</h2>\n\n<p>There are a few improvements I could see in your table model class:</p>\n\n<ol>\n<li>In <code>data()</code> you could use <code>elif</code> for all of the if-statements past the first. This will save the need to evaluate each if-condition after the first condition that w... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T10:29:40.790",
"Id": "36843",
"Score": "4",
"Tags": [
"python",
"unit-testing",
"pyqt"
],
"Title": "Modelview programming in PyQt4"
} | 36843 |
<p>I am having a structure of 3 tables</p>
<pre><code>Table mintemp consist of matcode,min_qty,jo_no,mr_no
Table min_out_body consist of matcode,out_qty,jo_no,mr_no
Table eu_min_out_body consist of matcode,out_qty,jo_no,mr_no
</code></pre>
<p>And data as follow:</p>
<pre><code>[mintemp]
matcode min_qty ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T14:16:40.373",
"Id": "60630",
"Score": "0",
"body": "This code is not in working order. The query references min.min_no which does not exist. I vote to close... if you edit your question (to reopen it) I suggest that you change your... | [
{
"body": "<p>I have had a play with your query. I don't believe there is a way to do the query without the sub-selects in the select fields... but, you can use the <code>having</code> to avoid the duplication of the code (and processing effort) to limit your results to just those with a positive target. Additi... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T12:39:26.747",
"Id": "36847",
"Score": "3",
"Tags": [
"mysql",
"sql"
],
"Title": "Optimized Query"
} | 36847 |
<p>I have a nested array that returns objects which are then traversed to retrirve the <code>id</code>s, which are then used to retrieve another array, which is traversed and the values returned are echoed out.</p>
<p>The problem is this seems to take ages in the browser to work across. How do I go about speeding thi... | [] | [
{
"body": "<p>It takes \"ages\" because it's having to do requests out to the Internet itself, as can be seen here</p>\n\n<pre><code>$response = $this->CTCTRequest->makeRequest($url, 'GET');\n$parsedReturn = simplexml_load_string($response['xml']);\n</code></pre>\n\n<p>These requests will quickly dominate... | {
"AcceptedAnswerId": "36894",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T15:56:17.470",
"Id": "36860",
"Score": "0",
"Tags": [
"php"
],
"Title": "foreach loop too slow?"
} | 36860 |
<p>I have a bit of code that converts a Sql Like expression to a regex expression for the purposes of a Linq to objects <code>Like</code> extension method. For some time I have been using <a href="http://bytes.com/topic/c-sharp/answers/253519-using-regex-create-sqls-like-like-function" rel="nofollow">this conversion</a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T16:16:31.770",
"Id": "60642",
"Score": "0",
"body": "What if it starts with and endsWith? I don't understand the need for startsWith to check that it doesn't also endWith"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>I think you're overcomplicating this and your code still doesn't work correctly. The LIKE pattern <code>bcd</code> shouldn't match <code>abcde</code>, but it does with your code.</p>\n\n<p>What you should do is to <em>always</em> add <code>^</code> at the start and <code>$</code> at the end.</p>\n... | {
"AcceptedAnswerId": "36864",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T15:56:58.033",
"Id": "36861",
"Score": "3",
"Tags": [
"c#",
"sql",
"linq",
"regex",
"converting"
],
"Title": "Convert Sql LIKE to Regex"
} | 36861 |
<p>I have the following code that reads a .csv file that than outputs the result in the form of a HTML table:</p>
<pre><code>$fhdrop = fopen("ac.csv", "r");
while (!feof($fhdrop) ) {
$at[] = fgetcsv($fhdrop, 1024);
}
$fhdrop2 = fopen("rc.csv", "r");
while (!feof($fhdrop2) ) {
$at2[] = fgetcsv($fhdrop2, 1024);
}
... | [] | [
{
"body": "<p>Looping on feof is wrong. <code>feof</code> doesn't return return true until <em>after</em> you've hit the end of file. If the read pointer is sitting past the last character and you try to read, feof will return false, but the read will fail. At that point feof will return true.</p>\n\n<p>Example... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T17:08:57.080",
"Id": "36863",
"Score": "3",
"Tags": [
"php",
"optimization",
"csv"
],
"Title": "How to make this csv-reading PHP code more efficient?"
} | 36863 |
<p>I wrote this script as a proof of concept of reading a file from disk as variable-length quantities (ints encoded using 7 bits from as many bytes as required). I'm mostly making use of the file system ReadStream, for reading byte buffers from files and the <em>varint</em> package for decoding variable length values.... | [] | [
{
"body": "<p>It turns out it was possible to increase the speed about <strong>12 times</strong> by using the offset argument of <code>varint.decode</code> to traverse the buffer rather than slicing read bytes off of the buffer for each value.</p>\n\n<pre><code>rs.on('data', function(buffer) {\n var buffer, va... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T18:42:54.090",
"Id": "36868",
"Score": "2",
"Tags": [
"javascript",
"node.js",
"stream"
],
"Title": "Streaming variable length integers from a file"
} | 36868 |
<p>This is following up on my <a href="https://codereview.stackexchange.com/questions/36841/poker-hand-evaluator-challenge">previous attempt</a>, which was admittedly <em>done fast</em> and not-so-well. This code attempts to allow comparing two poker hands to determine a winner, not only evaluating a given set of cards... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T21:37:28.697",
"Id": "60670",
"Score": "0",
"body": "Looking at @radarbob's answer on the first post, I suspect upcoming [tag:weekend-challenge] posts will push it to *determining the winning hand out of two*..."
},
{
"Conte... | [
{
"body": "<ol>\n<li><p>The idiomatic way of creating <code>Tuple</code>s is to use the <a href=\"http://msdn.microsoft.com/en-us/library/system.tuple%28v=vs.110%29.aspx\"><code>Create</code></a> factory method. This should remove a fair amount of type clutter from the code.</p></li>\n<li><p>Tuples are great wh... | {
"AcceptedAnswerId": "36895",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T20:44:28.793",
"Id": "36873",
"Score": "11",
"Tags": [
"c#",
"linq",
"weekend-challenge",
"playing-cards"
],
"Title": "Poker Hand Evaluator, take 2"
} | 36873 |
<p>I am working with an encryption algorithm that looks like this</p>
<ol>
<li>The key is a number stored in 4 bytes.</li>
<li>For each byte in the message, XOR it with the corresponding byte in the key</li>
<li>When you reach the end of the key, multiply the key by 13, and then continue looping</li>
</ol>
<p>Transla... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T22:07:05.557",
"Id": "60677",
"Score": "1",
"body": "It should be an easy branch prediction, so I wouldn't expect it to influence actual performance. (But profile both ways to be certain.)"
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>Initialize the first byte, and then start the loop from 1.....</p>\n\n<p>You may also want to do a bit-check instead of modulo, but they may be equally fast...</p>\n\n<pre><code>if (dataSize > 0) {\n data[0] ^= key;\n}\nfor (int i = 1; i < dataSize; i++) {\n\n // Increase the key as per... | {
"AcceptedAnswerId": "36876",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T21:30:21.263",
"Id": "36875",
"Score": "6",
"Tags": [
"c#",
"optimization"
],
"Title": "Running a block of code on every interval except the first iteration"
} | 36875 |
<p>I'm developing an application that receives and manages e-mails from a server. I manage only XML files and organize, by sender, the e-mails that have XML attachments, while the others are deleted. I create a list of files and create them in the temporary folder. I have a feeling my JavaMail process is slow becaus... | [] | [
{
"body": "<p>I have a feeling your application is slow because it does a lot of network access ... ;-)</p>\n\n<p>The amount of time in your code will be a very small fraction of the actual 'latency'. So, the question is not \"How can we make your code faster?\" but rather it is \"How can we reduce the amount o... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-07T23:01:23.377",
"Id": "36878",
"Score": "5",
"Tags": [
"java",
"email"
],
"Title": "Is there any way to make this JavaMail code faster?"
} | 36878 |
<p>This is the most basic code to join two tables in a database. For tables it uses a simple list. Solved this using brute force, sorting and using hashtable.</p>
<pre><code>final class SportsMan {
private final String name;
private final int rank;
private final String sport;
public SportsMan (String... | [] | [
{
"body": "<p>Right now you aren't using <a href=\"http://docs.oracle.com/javase/1.5.0/docs/guide/language/generics.html\">generics</a>:</p>\n\n<pre><code>Map hashMap; // no generics :o\nMap<String, Object> hashMap; // generics :D\n</code></pre>\n\n<hr>\n\n<p>The variable <code>result</code> can only be <... | {
"AcceptedAnswerId": "36885",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T00:06:00.797",
"Id": "36879",
"Score": "2",
"Tags": [
"java",
"join"
],
"Title": "Join of two databases"
} | 36879 |
<p>I have an homework as follows:</p>
<blockquote>
<p>Write a program where you enter from the keyboard a number n. Then n
stars are drawn onto the screen, circling around the center of your
screen. You can assume that 1 < n < 20.</p>
</blockquote>
<p>The solution I came up with is below.</p>
<pre><code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T21:32:10.957",
"Id": "88164",
"Score": "0",
"body": "Circling around the screen? What does that actually mean? I would put them all at the same distance from the center (and thus, if there are a lot of stars, I'd guess they would ha... | [
{
"body": "<p>is using <code>turtle</code> a requirement? otherwise you could use plotting libraries such as <code>matplotlib</code>:</p>\n\n<pre><code>import numpy as np\nimport matplotlib.pyplot as plt\n\nplt.figure( figsize=(8, 8) ).patch.set_alpha( 0 )\n\ntheta = np.linspace( 0, 2 * np.pi, 16, endpoint=Fals... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T00:21:17.973",
"Id": "36880",
"Score": "4",
"Tags": [
"python",
"python-3.x"
],
"Title": "Drawing stars around the center of the screen"
} | 36880 |
<p>I'm working on a page using AJAX that will get an entire .php page when the navigation button is clicked. I have that set up and working right. But this is my first time using AJAX, so I'm not sure what the best practices are and what I can do to prevent failures and display error messages.</p>
<pre><code> $(docu... | [] | [
{
"body": "<p>There isn't too much wrong. Your containers (<code>#sidebar-container</code> and <code>#sidebar-content-container</code>) really shouldn't need to be accessed by Ids, but more-so classes. For those types of DOM elements, <a href=\"http://css-tricks.com/the-difference-between-id-and-class/\" rel=\"... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T03:08:19.280",
"Id": "36881",
"Score": "8",
"Tags": [
"javascript",
"jquery",
"beginner",
"ajax"
],
"Title": "Fail-proof AJAX"
} | 36881 |
<p>I'm working my way through <em>The Java Programming Language, Fourth Edition - The Java Series</em>. This is Exercise Exercise 20.3:</p>
<blockquote>
<p>Create a pair of Filter stream classes that encrypt bytes using any
algorithm you choose—such as XORing the bytes with some value—with your
DecryptInputSt... | [] | [
{
"body": "<p>It looks like you have covered the bases quite well. There are some things I would like to suggest, and the first one is the most important:</p>\n\n<blockquote>\n <p>The performance of Input/Output Streams that read/write 1 byte at a time is really, really bad. You should also override the <stron... | {
"AcceptedAnswerId": "36886",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T03:31:50.750",
"Id": "36884",
"Score": "2",
"Tags": [
"java",
"cryptography",
"stream"
],
"Title": "Critique of FilterInputStream and FilterOutputStream classes"
} | 36884 |
<p>In collision detection problems, the challenge is to determine when shapes intersect each other, especially when moving shapes first make contact.</p>
<p>Related tag: <a href="/questions/tagged/computational-geometry" class="post-tag" title="show questions tagged 'computational-geometry'" rel="tag">computat... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T07:55:49.900",
"Id": "36888",
"Score": "0",
"Tags": null,
"Title": null
} | 36888 |
In collision detection problems, the challenge is to determine when shapes intersect each other. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T07:55:49.900",
"Id": "36889",
"Score": "0",
"Tags": null,
"Title": null
} | 36889 |
<p>Is there a better algorithm for finding the common divisors of two numbers? Can this code be shortened?</p>
<pre><code>import java.util.*;
public class Testing1 {
public static void main (String args[]){
Scanner x=new Scanner(System.in);
System.out.print("Enter the 1st number(larger number) : ");
int... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T14:54:52.313",
"Id": "60720",
"Score": "4",
"body": "You have already accepted an answer, and I don't code in java, but as a mathematician, I would like to point out that there is a very nice recursive algorithm which is much shorte... | [
{
"body": "<p>There are few improvements you can do in your code:</p>\n\n<ul>\n<li><p>First choose better variable names. I would name the <code>Scanner</code> type variable as <code>scanner</code> rather than <code>x</code>. Really, <code>x</code>, <code>y</code>, <code>z</code> are the worst variable name, wh... | {
"AcceptedAnswerId": "36892",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T08:09:10.843",
"Id": "36890",
"Score": "7",
"Tags": [
"java",
"optimization",
"beginner",
"mathematics"
],
"Title": "Determining common divisors of two numbers"
} | 36890 |
<p>Testing on localhost, it takes a bit longer to get the results than I would like and gives me this PHP error:</p>
<blockquote>
<p>Fatal error: Maximum execution time of 30 seconds exceeded</p>
</blockquote>
<p>I am wondering if there is any way to stop that error from happening, as well as making my class faster... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T07:57:10.247",
"Id": "61156",
"Score": "0",
"body": "Have you consider use javascript ajax? If api.iamphoenix.me support CORS, it can be a good solution: you won't need php (at least, for these operations) and most important you can... | [
{
"body": "<p>I'd imagine your timeout is due to server lag, your code doesn't look to be something that should take anywhere near 30 seconds to execute. You might want to look at using set_time_limit() which has a pretty self explanatory name.</p>\n\n<p>A few other quick observations if i may:</p>\n\n<p>I'd se... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T08:19:50.487",
"Id": "36891",
"Score": "4",
"Tags": [
"php",
"optimization"
],
"Title": "Getting JSON from a remote API sometimes hangs. Can I make this any faster?"
} | 36891 |
<p>I'm currently reading a certain pixels color from a process window like this: </p>
<pre><code>[DllImport("gdi32.dll")]
private static extern int BitBlt(IntPtr srchDc, int srcX, int srcY, int srcW, int srcH,
IntPtr desthDc, int destX, int destY, int op);
public static Color GetPixe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T14:38:25.510",
"Id": "60718",
"Score": "0",
"body": "You're not disposing the `Bitmap`."
}
] | [
{
"body": "<p>You'll actually need to wrap the <code>Bitmap</code> in a <code>using</code> as well because its base class, <code>Image</code>, implements <code>IDisposable</code>:</p>\n\n<pre><code>public static Color GetPixel(IntPtr hwnd, int x, int y)\n{\n using (Bitmap screenPixel = new Bitmap(1, 1);\n ... | {
"AcceptedAnswerId": "36964",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T13:09:11.810",
"Id": "36899",
"Score": "5",
"Tags": [
"c#",
"winforms"
],
"Title": "Reading a certain pixels color from a window"
} | 36899 |
<p>first time visiting Code Review. I figured this was a more appropriate spot than SO for this question. Here goes...</p>
<p>Currently, I have a php function that converts bbcode format text in to HTML (among other things). A code snippet is as follows...</p>
<pre><code>function bbcode_format ($str) {
$simp... | [] | [
{
"body": "<p>You have two issues: how to represent all of the desired transformations as code, and how to perform the substitutions efficiently.</p>\n\n<p>To address the data representation issue — you want to use an <a href=\"http://php.net/array\" rel=\"nofollow\">associative array</a>.</p>\n\n<pre><code>$si... | {
"AcceptedAnswerId": "36914",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T15:01:55.300",
"Id": "36901",
"Score": "2",
"Tags": [
"php",
"optimization"
],
"Title": "Looking for a better way to handle this growing array used for preg_replace"
} | 36901 |
<p>While coding today, I came across the following loop in C#:</p>
<pre><code>for(int x = 0; x < max_x_index; x++){
for(int y = 0; y < max_y_index; y++, count++){
some2DarrayRepresentedBy1D[count] = ...;
}
}
</code></pre>
<p>Would this be consider bad practice? Would the following be a better w... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T17:43:50.347",
"Id": "60741",
"Score": "1",
"body": "I see this question has been tagged with both \"C\" and \"Java\". Idiomatic code in the two languages is different, so the best answer may well be different in different language... | [
{
"body": "<p>I would agree with the OP in that the second code block would be the best approach. </p>\n\n<p><strong>Reason</strong> - readability. In my opinion, the variable incremented in the for loop statement should only be used for keeping count of how many times we're looping. <code>count</code> mi... | {
"AcceptedAnswerId": "36906",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T15:28:56.333",
"Id": "36904",
"Score": "26",
"Tags": [
"c#"
],
"Title": "Is it bad practice to increment more than one variable in a for loop declaration?"
} | 36904 |
<p>I've written a very basic Python 3 script to search ThePirateBay. Since the tracker doesn't have an API, I had to parse the HTML using BeautifulSoup. I'd like to get some reviews, I'm pretty sure the code is crap, so fire away. I'm also interested in projects I could read to improve my Python.</p>
<pre><code>#!/usr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T17:05:23.577",
"Id": "60734",
"Score": "0",
"body": "@200_success I did post the code, what do you mean?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T17:10:02.533",
"Id": "60736",
"Score": ... | [
{
"body": "<p>By reading the code the only thing i could \nthought to improve your code is to change this </p>\n\n<pre><code>def search_engine():\n try:\n pattern = re.compile('\"(.+)\" \\-(.*) \\-(.*)')\n while True:\n kw, cat, order = get_query(pattern)\n</code></pre>\n\n<p>and... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T16:08:01.990",
"Id": "36909",
"Score": "5",
"Tags": [
"python",
"parsing",
"python-3.x"
],
"Title": "Python Script to Search PirateBay"
} | 36909 |
<p><strong>Weekend Challenge #2 - <a href="https://codereview.meta.stackexchange.com/questions/1218/proposals-for-weekly-challenge-topics/1220#1220">Poker Hand Evaluation</strong></a></p>
<p><strong>Finding a straight with wildcards</strong></p>
<p>Because of a size limit on Code Review I have to split my <a href="ht... | [] | [
{
"body": "<p>In this case bit-wise manipulation is your friend .... (as it often is...)....</p>\n\n<p>I believe the following solution makes the combination/permutation expense a 1-off setup problem, and using the <code>Integer.bitCount(...)</code> makes it almost trivial ...</p>\n\n<p>The code I hacked up app... | {
"AcceptedAnswerId": "36923",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T17:42:39.070",
"Id": "36915",
"Score": "10",
"Tags": [
"java",
"performance",
"playing-cards",
"community-challenge"
],
"Title": "Poker Hand Evaluation - Finding a straight... | 36915 |
<h1>Weekend Challenge #2 - <a href="https://codereview.meta.stackexchange.com/questions/1218/proposals-for-weekly-challenge-topics/1220#1220">Poker Hand Evaluation</a></h1>
<p>Very early I decided to support the usage of wild jokers, even though I knew that this was going to lead to <s>trouble</s> more work. I also wa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T20:31:46.850",
"Id": "60764",
"Score": "0",
"body": "And is it me or no \"kicker\" for a straight is assuming you're playing 5-cards (the rest of your code isn't...)? You couldn't tell the winner of a 7-card deal where the two playe... | [
{
"body": "<h2>AceValue</h2>\n\n<p>This class has me confused. I am not sure what the <code>ranks[]</code> is for.... and there are magic numbers, and no comments? </p>\n\n<h2>Suite</h2>\n\n<p>This has an <code>isBlack()</code> method, but that indicates that DIAMONDS are black... but they are red!</p>\n\n<p><c... | {
"AcceptedAnswerId": "36936",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T17:45:18.320",
"Id": "36916",
"Score": "35",
"Tags": [
"java",
"game",
"weekend-challenge",
"playing-cards"
],
"Title": "Weekend Challenge - Poker Hand Evaluation"
} | 36916 |
<p>I'm trying to teach myself Objective-C/Cocoa for eventual iPhone development but I figured I would start with a terminal app. It takes a user input, strips everything but numerics, then displays PI to the number that is left over.</p>
<p>Could anyone have a quick look over my code and see if there's any optimisatio... | [] | [
{
"body": "<p>BTW: I'm answering from a strong C perspective and weak Objective-C one</p>\n\n<p>To avoid unexpected input and avoid string overflow:</p>\n\n<pre><code>//scanf(\"%s\",userInput);\nif (1 != scanf(\"%9s\",userInput)) handle_error();\n</code></pre>\n\n<p>I'm sure you want:<br>\n<a href=\"https://sta... | {
"AcceptedAnswerId": "36937",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T18:20:33.127",
"Id": "36919",
"Score": "4",
"Tags": [
"beginner",
"objective-c",
"floating-point"
],
"Title": "Pi to the Nth Digit"
} | 36919 |
<p>I have a small module that gets the lemma of a word and its plural form. It then searches through sentences looking for a sentence that contains both words (singular or plural) in either order. I have it working but I was wondering if there is a <strong>more elegant</strong> way to build this expression.</p>
<p>Not... | [] | [
{
"body": "<p>Maybe, you will find this way of writing more easy to read:</p>\n\n<pre><code>words = (('cell',), ('wolf','wolves'))\n\nstring1 = \"|\".join(words[0]).join(('(?:',')'))\nprint string1\n\nstring2 = \"|\".join(words[1]).join(('(?:',')'))\nprint string2\n\npat = \"|\".join((\n \".+\".j... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T19:08:28.343",
"Id": "36922",
"Score": "3",
"Tags": [
"python",
"regex"
],
"Title": "Either or case in Python and Regex"
} | 36922 |
<p>I have created the following code:</p>
<pre><code>class Club(object):
def __init__(self, name, points=1000):
self.name = name
self.points = points
def __eq__(self, other):
return self.name == other.name
def __gt__(self, other):
return self.points > other.points
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T21:56:44.713",
"Id": "60772",
"Score": "0",
"body": "Watch out when implementing only some of `__eq__`, `__ne__`, `__lt__`, `__gt__`, etc., or `__eq__` and `__hash__`. It can make a class harder to use correctly."
}
] | [
{
"body": "<p>In <code>play_match</code>, the <code>Club</code> class should be responsible for updating its own score. You could define an <code>update_points</code> method taking the same parameter as the <code>computes_point</code> one (and calling it). Also, shouldn't <code>compute_points</code> be responsi... | {
"AcceptedAnswerId": "36928",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T20:18:56.953",
"Id": "36927",
"Score": "4",
"Tags": [
"python"
],
"Title": "Football Elo Rankings"
} | 36927 |
<p>This might be a basic question for C. I'm making a struct called <code>check_t</code> and I want to make an array whose elements are of type <code>check_t</code>. This array is called <code>enqueued</code>. The struct <code>check_t</code> contains an integer x and a lock (for multi-threading).</p>
<pre><code>typede... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T00:46:40.200",
"Id": "60783",
"Score": "0",
"body": "`check_t **enqueued;` is how you'd declare a pointer to a 2D array of `check_t`. Is that what you want?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-1... | [
{
"body": "<p>1D array:</p>\n\n<pre><code>check_t *enqueued = malloc(N * sizeof(*enqueued));\nenqueued[0].x = 5;\nenqueued[N - 1].x = 2;\n</code></pre>\n\n<p>2D array:</p>\n\n<pre><code>check_t **enqueued = malloc(N * sizeof(*enqueued));\nfor(int i = 0; i < N; i++)\n enqueued[i] = malloc(M * sizeof(**enqu... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-08T22:59:47.323",
"Id": "36929",
"Score": "4",
"Tags": [
"c",
"multithreading"
],
"Title": "Making an array whose elements are defined by a struct"
} | 36929 |
<p><strong>Question:</strong> Is having a master class bad practice? I am making a simple pong game, but I'm writing the code as if I were making for something that might be for something more complicated I want to create in the future. Also, am I not doing it in a good manner? </p>
<p><strong>What I am doing:</strong... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T03:57:17.550",
"Id": "60794",
"Score": "2",
"body": "Look up the [God Object](http://en.wikipedia.org/wiki/God_object)"
}
] | [
{
"body": "<p>A \"master class\" is a very close relative to a singleton or a global. It can easily be a design which violates the Dependency Injection principle, and leaves you with non-modular code. In this case your engine is also violating the Single Responsibility principle, as it's doing a lot of unrela... | {
"AcceptedAnswerId": "36941",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T02:41:05.060",
"Id": "36935",
"Score": "4",
"Tags": [
"c++",
"object-oriented",
"game",
"sfml"
],
"Title": "Master engine class for a Pong game"
} | 36935 |
<p>I have started some experiments with node.js.<br />
Any comment on style (especially the callbacks) and best practice is appreciated:</p>
<h3>PassportControl.js</h3>
<pre><code>/*
* Export single function that creates the passportControl object
*
* The passport control object is supposed to be a wrapper for
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T19:41:18.393",
"Id": "60899",
"Score": "0",
"body": "Also See: http://codereview.stackexchange.com/q/36940/507"
}
] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>Your indenting is a mix of 4 space and 8 space tabbing, please stick at all times to either 4 or 2 spaces. Looking at <code>deserializeUser</code> is aneurysm inducing.</li>\n<li>You have a ton of comments, which I like, authentication can always use tons of comm... | {
"AcceptedAnswerId": "39885",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T03:14:18.963",
"Id": "36938",
"Score": "11",
"Tags": [
"javascript",
"node.js",
"passport",
"authentication"
],
"Title": "node.js passport wrapper"
} | 36938 |
<p>More javascript (nodejs) to go with the passport wrapper I just posted:</p>
<h3>UserBook.js</h3>
<pre class="lang-js prettyprint-override"><code>/*
* A wrapper for user Registration for a web site.
* This is an MYSQL version of the client to provide persistent state.
*
* Exports a single function that returns ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T18:05:28.710",
"Id": "60880",
"Score": "0",
"body": "would you please include a link to the other questions that you posted, it seems that they might be relevant when reviewing the code"
},
{
"ContentLicense": "CC BY-SA 3.0"... | [
{
"body": "<p>I have never seen so relatively little code with so much indentation before. There are many acceptable style choices, but I think you'll regret this one.</p>\n\n<p>Personally I usually avoid inlining functions, I know it is what all the cool kids are doing, but I find that it makes it harder to sp... | {
"AcceptedAnswerId": "38504",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T03:49:20.597",
"Id": "36940",
"Score": "8",
"Tags": [
"javascript",
"mysql",
"sql",
"node.js"
],
"Title": "Local user registration"
} | 36940 |
<p>This program is compiling just fine, and the variables and such seem to be passing through. However, when I open the text file there is no data. Can anyone point me in the right direction or nudge my brain into the right process thought? </p>
<pre><code>package dvdlogger;
import java.util.*;
import java.io.*;
pu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T04:20:59.370",
"Id": "60795",
"Score": "0",
"body": "Your question is not suited to CodeReview, it is not working code. Still this is a really common mistake that java programmers make, and the answer is more than can fit in a comme... | [
{
"body": "<p>With any Java Writer or Stream... <strong>YOU MUST PROPERLY FLUSH AND CLOSE</strong> it.</p>\n\n<p>The documentation is not fantastically clear... but:</p>\n\n<p>when you exit the method, you must ensure that the file is flushed and closed. you are exiting your program before the data is written t... | {
"AcceptedAnswerId": "36943",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T04:11:25.367",
"Id": "36942",
"Score": "1",
"Tags": [
"java",
"file",
"io"
],
"Title": "Java PrintWriter not printing data to file"
} | 36942 |
<p>I wrote a Heap, but the judge system reports "time limit exceeded" in some tests. I use a <code>sift_down</code> to build, so I don't know why.</p>
<p>Maybe I can improve the build? Or do I have a bad <code>sift_down</code>?</p>
<blockquote>
<p><strong>Input:</strong></p>
<p><code>n</code> commands</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T08:07:42.413",
"Id": "60797",
"Score": "4",
"body": "It may be tough for others to read your code since you use many one-letter variable names. I'm also not sure why you're using a global variable."
},
{
"ContentLicense": "... | [
{
"body": "<p>Some generic comments about your code, not related to your problem.</p>\n\n<hr>\n\n<pre><code>using namespace std;\n</code></pre>\n\n<p>There are some developers which consider importing a whole namespace (overwriting some standard functions with imported ones) as very bad practice. I'm not qualif... | {
"AcceptedAnswerId": "36974",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T07:53:29.437",
"Id": "36947",
"Score": "4",
"Tags": [
"c++",
"programming-challenge",
"heap",
"time-limit-exceeded"
],
"Title": "Time limit exceeded in Heap"
} | 36947 |
<p>I am now working on a Node.js project, and on my ejs view page, I'm retrieving this array of objects, like:</p>
<pre><code>[{ name: 'Andy',
age: 20,
username: 'andygoodluck'},
{name: 'Terry',
age: 21,
username: 'terrygoodnight'}]
</code></pre>
<p>My objective is to make use of this data to dynamicall... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T13:16:02.367",
"Id": "60819",
"Score": "0",
"body": "Hello and welcome to Code Review! I'm not sure I understand what you're trying to do. Can you describe a bit more your goal here? What does insertUserBlock do? Can we see all the ... | [
{
"body": "<p>The most simple and probably what will save you some time in the future is to wrap every JSON object into a <code><div></code> and add all of your wrapper divs into another div (or whatever element that might be best for your purpose). Then just style it using CSS. </p>\n\n<p><a href=\"http:... | {
"AcceptedAnswerId": "37095",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T08:58:02.020",
"Id": "36948",
"Score": "5",
"Tags": [
"javascript",
"optimization",
"node.js"
],
"Title": "A more efficient approach to existing JavaScript coding"
} | 36948 |
<p>I've just created a small class to reverse date in PHP. I'd like to see whether or not it's good and can be improved.</p>
<pre><code><?php
/**
* Reverse date and hour
*/
class ReverseDate
{
var $date;
var $hour;
var $error;
/**
* Checks if the date has hours
*/
function exec($da... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T11:31:59.063",
"Id": "60804",
"Score": "0",
"body": "struggling to see the need for this at all since you can do exactly this with the built in php date functions which are much more powerful and allow you to change the format and l... | [
{
"body": "<p>If you want to do it this way, then:</p>\n\n<ol>\n<li><p>Change your <code>var</code> to <code>public</code> (I hope it is not PHP4 code):</p>\n\n<pre><code>public $date;\n</code></pre></li>\n<li><p>In the <code>exec()</code> function, I would first check <code>$data</code>:</p>\n\n<pre><code>// C... | {
"AcceptedAnswerId": "36957",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T10:27:53.037",
"Id": "36951",
"Score": "2",
"Tags": [
"php",
"datetime"
],
"Title": "Reverse date in PHP"
} | 36951 |
<p>I'm trying to use the good parts of Javascript and dont follow the classical inheritance.
I studied and created this example of compose in Javascript, <a href="https://gist.github.com/fernandoperigolo/7789866" rel="nofollow">https://gist.github.com/fernandoperigolo/7789866</a>.</p>
<p>My question is. You think this... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>from your comments inside the code you seem to not have written the code or have heavily borrowed from somebody else's code..</p>\n\n<p>From a high level I have only a few misgivings:</p>\n\n<ul>\n<li>Do not modify standard JS objects, so do not add <code>compose</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T15:33:36.023",
"Id": "36965",
"Score": "3",
"Tags": [
"javascript",
"design-patterns"
],
"Title": "Compose in Javascript - Go ahead with this example?"
} | 36965 |
<p>I'm writing a SDK for a NFC device in .NET so I don't have to import the SDK from C++. Right now I'm working on the ISO14443-3 part which is just simple Halt, Request, and Anticollision commands. The communication part between the device and computer is simple enough so I'm not going to post any of that. Just know t... | [] | [
{
"body": "<p>I've never been a fan of a global constants file. It's a good idea to keep enums defined close to where they are needed. Makes it a little more apparent how enum is used. This helps keep the code clean as you mentioned, and also helps improve maintainability, since there's not a long, master li... | {
"AcceptedAnswerId": "36969",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T15:35:42.467",
"Id": "36966",
"Score": "2",
"Tags": [
"c#",
"enum",
"constants"
],
"Title": "Enum or Constant"
} | 36966 |
<p>Sometimes, when you're doing something like displaying a bunch of elements, you can avoid running a function entirely if an object is <code>hidden</code>.</p>
<p>So you can either write the check from the loop:</p>
<pre><code>for( Displayable * d : displayables )
if( d->isShowing() )
d->draw() ;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T18:11:34.193",
"Id": "60882",
"Score": "0",
"body": "what language is this?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T18:11:57.957",
"Id": "60883",
"Score": "2",
"body": "The questio... | [
{
"body": "<p>You should focus on whatever methods avoid code duplication. </p>\n\n<pre><code>// Some code\nfor( Displayable * d : displayables )\n if( d->isShowing() )\n d->draw() ;\n\n// Some code elsewhere\nfor( Displayable * d : displayables )\n // Oops, we forgot to check if it's sh... | {
"AcceptedAnswerId": "36982",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T18:09:54.260",
"Id": "36978",
"Score": "8",
"Tags": [
"c++",
"object-oriented"
],
"Title": "Is `if( hidden ) return;` an antipattern?"
} | 36978 |
<p>I get the following correct results from this code, but it seems incredibly clunky to me. Is there anything I could be doing more elegantly? The results can be imprecise - as long as it's the right number of returned elements, and the selection is mostly right.</p>
<pre><code>$_5elements = array(1,2,3,4,5);
$_10ele... | [] | [
{
"body": "<h1><em>Ding!!</em></h1>\n<p><strong>I've got it!</strong></p>\n<p>So, I have been looking at this code for quite a while now, because <em>I knew</em> there had to be some ingenious way to do this. It seemed all to simple to need something of the opposite scale! And, after playing around, sure enough... | {
"AcceptedAnswerId": "56627",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T19:08:30.880",
"Id": "36983",
"Score": "5",
"Tags": [
"php",
"array"
],
"Title": "Take an array and return \"n\" elements, as evenly spaced as possible"
} | 36983 |
<p>A very simple cipher in which the letters of the alphabet are substituted by a different letter that have a fixed distance to the original letter.</p>
<p>Named after <a href="http://en.wikipedia.org/wiki/Caesar_cipher" rel="nofollow">Julius Caesar</a>, because he is said to have used it.</p>
<p>A special case of t... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T19:18:06.040",
"Id": "36984",
"Score": "0",
"Tags": null,
"Title": null
} | 36984 |
A Caesar cipher is a trivial method to obfuscate text by substituting each character with it successor (or nth successor). Use this tag for questions involving a Caesar cipher or toy-grade ciphers of similar design. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T19:18:06.040",
"Id": "36985",
"Score": "0",
"Tags": null,
"Title": null
} | 36985 |
<p>As I am new to bash scripting, and want to use apt-get in my university. I know that many people have issues when trying to do so. My focus is simplicity and ease of use, but still need to be somewhat robust. </p>
<pre><code>#!/bin/bash
string="install"
errormsg="\n\tInvalid input\n You should run this script wi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T20:52:37.403",
"Id": "60913",
"Score": "0",
"body": "Assuming that apt-get should always use the HTTP proxy, configure [`/etc/apt/apt.conf`](https://help.ubuntu.com/community/AptGet/Howto#Setting_up_apt-get_to_use_a_http-proxy) with... | [
{
"body": "<p><strong>NO!</strong></p>\n\n<p>Storing plaintext passwords in a world-readable file is not acceptable.</p>\n\n<p>Making an executable file world-writable is not acceptable.</p>\n\n<p>Asking for a password to be entered as a command-line parameter, where it would likely end up in ~/.bash_history, i... | {
"AcceptedAnswerId": "36993",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T19:18:12.320",
"Id": "36986",
"Score": "5",
"Tags": [
"beginner",
"bash",
"linux",
"shell"
],
"Title": "apt alternative for proxy environment with bash shell"
} | 36986 |
<p>Example Script is located in /home/insp/public_html/deploy/</p>
<p>I want to return the /home/insp/ section</p>
<pre><code>$path = realpath(__DIR__);
$parts = explode('/', $path);
$newPath = array(
$parts[0],
$parts[1],
$parts[2],
);
$realPath ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T21:09:57.387",
"Id": "60916",
"Score": "0",
"body": "So you want the home directory of the user?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T21:11:34.150",
"Id": "60918",
"Score": "0",
... | [
{
"body": "<p>A different way:</p>\n\n<pre><code>preg_match(':^/[^/]*/[^/]*/:', realpath(__DIR__), $matches);\n$realPath = $matches[0];\n</code></pre>\n\n<p>This matches the first and second files in path, and stores them in $matches.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": "37038",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T20:26:29.910",
"Id": "36991",
"Score": "1",
"Tags": [
"php",
"optimization",
"linux"
],
"Title": "Optimize this path location script?"
} | 36991 |
<p>I'm no pro in JavaScript. Please help me review this code. I would appreciate any suggestions!</p>
<p><strong>JavaScript:</strong></p>
<pre><code>var y_offset, /*current position of window*/
distance_from_current_position, /*different between current position and target*/
body_height, /*hight of body*/
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T23:04:52.707",
"Id": "60931",
"Score": "1",
"body": "What are you trying to solve exactly? It seems cleaner to use built in [`window.scrollTo()`](https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollTo) or even using `<a hr... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>This code does not work, you did not provide <code>$y_1</code>, I am assuming you meant <code>scroll_function</code></li>\n<li>I built a JsBin for this : <a href=\"http://jsbin.com/sihoj/1/edit\" rel=\"nofollow\">http://jsbin.com/sihoj/1/edit</a>, because you kee... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T22:11:54.193",
"Id": "36999",
"Score": "1",
"Tags": [
"javascript",
"optimization"
],
"Title": "Help me optimize this scrollTo"
} | 36999 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.