body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I'm working on the <a href="http://projecteuler.net/problem=3" rel="nofollow">third Euler problem</a> and I've written a simple little function that returns the list of <em>prime</em> factors of a given number.</p> <p>The number for which I have to get all the factors is over 6 billion, so building this huge freaki...
[]
[ { "body": "<p>Some advice about maths and algorithms which will be useful for this problem and for future problems:</p>\n\n<ul>\n<li><p>You are interested in <strong>prime</strong> factors.</p></li>\n<li><p>You don't care about the non-biggest factors (you might go through them but there is not much point in st...
{ "AcceptedAnswerId": "31909", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T00:08:14.950", "Id": "31661", "Score": "3", "Tags": [ "python", "programming-challenge", "primes", "io" ], "Title": "Attempting to efficiently compute the largest prime fac...
31661
<p>I want you to pick my code apart and give me some feedback on how I could make it better or simpler. For a full tree (all nodes with 0 or 2 children) it works deterministically:</p> <pre><code>public class Construct { private TreeNode root; private static class TreeNode { TreeNode left; Tr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T18:36:56.820", "Id": "50580", "Score": "0", "body": "Is the tree reconstruction necessarily deterministic? If the inorder array is `[8, 8, 8, 8]` and the preorder array is also `[8, 8, 8, 8]`, then what should the result look like?"...
[ { "body": "<p>The algorithm looks good to me. Regarding the code, here are a few points:</p>\n\n<ol>\n<li>You don't need to overload the function. Semantically it's a tree builder, and probably the <code>private</code> function can be termed as <code>buildTree</code>.</li>\n<li><p>The following condition should...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T00:55:33.080", "Id": "31664", "Score": "1", "Tags": [ "java", "algorithm", "recursion", "tree" ], "Title": "Construct a tree given pre and inorder or post and inorder" }
31664
<p>I wrote a small program which shows all possible permutations of choosing <em>m</em> integers from the set \${1, 2, ..., n}\$, as follows:</p> <pre><code>def perm(nlist, m): """ Find all possible permutations of choosing m integers from a len(n)-list. INPUT: @para nlist: a list of length n...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T02:40:59.590", "Id": "50528", "Score": "0", "body": "If `m == len(nlist)` then shouldn't it return `[nlist]` instead of `[[]]`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T03:15:19.437", "Id":...
[ { "body": "<p>As noted by 200_success in the comments, the <code>m == len(nlist)</code> check is a bug that can be fixed by simply removing the condition.</p>\n\n<p>Also, <code>if m &gt; len(nlist): return</code> is almost redundant because you would get an empty list as the result anyway in that case. (The dee...
{ "AcceptedAnswerId": "35778", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T01:42:09.743", "Id": "31665", "Score": "4", "Tags": [ "python", "combinatorics" ], "Title": "Showing all possible permutations from a set" }
31665
<p>This is my first program in java. I am wondering if there would be a better way to tackle this. I am only allowed to use one class. It's not quite finished, but I am thinking it doesn't look very elegant.</p> <pre><code>import java.io.*; public class CarHire { public static void main(String[] args) throws IOEx...
[]
[ { "body": "<ol>\n<li><p>Given the constraints, your code looks mostly good. Ideally I would collect the user input in a loop instead of repating code for each entry. This may be out of scope for you at this point.</p></li>\n<li><p>Your usage of <code>printf</code> is a bit contrived; again, it may be OK as prac...
{ "AcceptedAnswerId": "31682", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T02:21:10.670", "Id": "31666", "Score": "3", "Tags": [ "java", "beginner" ], "Title": "Prompting for values to plug into a formula — how to do it elegantly" }
31666
<p>Below is the current code which is used to update/insert records from Oracle view to SQL Server table using <a href="https://code.google.com/p/dapper-dot-net/">Dapper</a>. There is not a field to check last record updated date in the oracle view so I have added a method to get hashcode by using property values. Sinc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T07:29:29.500", "Id": "50541", "Score": "4", "body": "Consider creating a linked server to Oracle from your SQL Server. You can then perform your necessary work in T-SQL, in a set-based manner. Consider using the new MERGE syntax in ...
[ { "body": "<p>One thing I would say is that you don't need to create those connection string variables, you are only using them once in this program and you have them nicely hidden where they should be, so you can just call them when you use them, which in this case is once.</p>\n\n<p>so instead of this</p>\n\n...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T07:15:53.960", "Id": "31673", "Score": "9", "Tags": [ "c#", "sql-server", "oracle", "dapper" ], "Title": "Compare Oracle Table with SQL Server Table and Update/Insert" }
31673
<p>All of the class here share these same property</p> <p>Country, Total and Date.</p> <p>Total property are integer in some classes and decimal in some classed.</p> <p>The extension method below has a lot of duplication. i have tried to refactor it using interface but i can't find a way to refactor it at the last s...
[]
[ { "body": "<p>You can use an interface and a generic method to remove the code duplication:</p>\n\n<pre><code>public interface IStatistic\n{\n string Country {get; set;}\n DateTime Date {get; set;}\n Decimal Total {get; set;}\n}\n\npublic static class StatisticExtension\n{\n public static void Merge...
{ "AcceptedAnswerId": "31684", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T07:40:45.950", "Id": "31674", "Score": "4", "Tags": [ "c#", "linq" ], "Title": "Refactor Linq grouping" }
31674
<p>I'm trying to implement an inversion counting routine in Scala in a functional way (I don't want to port Java solution) but have real troubles with it. The sorting routine works fine but adding the code to count inversions leads to stack overflow error. Here's the code in question:</p> <pre><code> object FuncSort ...
[]
[ { "body": "<p>The recursive calls to <code>mergeAndCount</code> are not in tail position, so the Scala compiler can not use tail optimisation and the stack grows till it overflows its alloted space. The <code>lazy</code> modifier in <code>lazy val (i, s)</code> is doing you no good at all, by the way.</p>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T08:01:01.017", "Id": "31675", "Score": "1", "Tags": [ "scala", "sorting" ], "Title": "Counting inversions" }
31675
<p>This is a batch program to xcopy from host PC to remote destination with multi-processing.</p> <p>Kepler, Python-3.x are my environment.</p> <pre><code>#!/usr/bin/env python # -*- coding: utf-8 -*- # based on Carnival http://ask.python.kr/users/6970/carnival/ import os import os.path import csv import re from mu...
[]
[ { "body": "<p><strong>Technical issues:</strong></p>\n\n<ul>\n<li>You are reading whole files into memory at once. Consider what happens if the directory contains huge files.</li>\n<li>You use <code>multiprocessing</code>, apparently in an attempt to parallelize things, and use locks to synchronize.</li>\n<li>F...
{ "AcceptedAnswerId": "35105", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T11:14:49.977", "Id": "31678", "Score": "4", "Tags": [ "python", "optimization", "python-3.x", "csv", "multiprocessing" ], "Title": "Batch program to xcopy from host PC ...
31678
<p>Just looking for some help reviewing/refactoring. For example, could the classes random/vertical be refactored into 1 class instead of 2?</p> <h3>BouncingBalls.java</h3> <pre class="lang-java prettyprint-override"><code>import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Graphics; import jav...
[]
[ { "body": "<p>Your <code>VerticalBall</code> class and <code>RandomBall</code> have lots of duplicate code(should it?). So you can make an <code>abstract</code> <strong><code>Ball</code></strong> class and define the duplicate codes there. This way you can have a clear hierarchy of classes. </p>\n\n<p>See : <a ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T14:09:48.693", "Id": "31687", "Score": "3", "Tags": [ "java", "multithreading", "gui" ], "Title": "Java Bouncing Ball Review" }
31687
<p>I have implemented an <code>IDataContractSurrogate</code> to enable serialization of <code>ImmutableList&lt;T&gt;</code> (from the Microsoft Immutable Collections BCL) using the <code>DataContractSerialization</code> framework.</p> <p>The code is a bit wild using reflection and compiling of delegates. Are there an...
[]
[ { "body": "<p>This actually looks pretty nice and I am bookmarking it. :)</p>\n\n<p>Two tiny details, which are probably a waste of time:</p>\n\n<ol>\n<li><p>I would personally (probably) make the <code>ImmutableListListConverter&lt;T&gt;</code> a private class inside of the <code>ImmutableListListConverter</co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T14:14:09.153", "Id": "31688", "Score": "8", "Tags": [ "c#", "reflection", "serialization" ], "Title": "Improve this reflection bashing code" }
31688
<p>Kml uses an 8 digit HEX color format. The traditional Hex format for red looks like #FF0000. In Kml, red would look like this FFFF0000. The first 2 digits are for opacity (alpha). Color format is in AABBGGRR. I was looking for a way to set the color as well as the opacity and return it in a string to be placed in an...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T15:35:08.733", "Id": "50563", "Score": "2", "body": "“The traditional Hex format for black looks like #FF0000.” That's not black, that's red." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T21:18:07.2...
[ { "body": "<p>In the <code>System.Drawing</code> namespace lives the <code>ColorTranslator</code> class which has an <code>ToHtml()</code> method which can be used here. A good way would be to create extension methods for this task. The first extension method will be named <code>ToKMLColor</code> and will expec...
{ "AcceptedAnswerId": "60793", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T14:36:54.010", "Id": "31689", "Score": "5", "Tags": [ "c#" ], "Title": "Getting the KML color code from colordialog box more efficiently" }
31689
<p>I am coding a site where users submit sporting events.</p> <p>When submitting an event there are a lot of fields that need to be validated.</p> <p>This is the method I wrote to valid the fields:</p> <pre><code>class event{ private $dbh; private $post_data; public function __construct($p...
[]
[ { "body": "<p>Yeah that's ugly :) </p>\n\n<p>You do not have to nest the ifs because when you throw an error, the function will stop executing right there so you can safely do</p>\n\n<pre><code>try {\n if(!empty($this-&gt;post_data['event-name']) &amp;&amp; (strlen($this-&gt;post_data['event-name']) &lt; 1...
{ "AcceptedAnswerId": "31696", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T16:11:50.850", "Id": "31693", "Score": "1", "Tags": [ "php", "validation" ], "Title": "Form validation for sporting events" }
31693
<p>I have a method that returns a <code>List&lt;Object&gt;</code> from any given <code>Object</code> containing its values. It doesn't get the values of any <code>static</code> or <code>final</code> field in the class.</p> <pre><code>public List&lt;Object&gt; objectData(Object object) { Field[] fields = object.get...
[]
[ { "body": "<p>In principle, your code is correct (provided you really do not want to deal with fields in superclass). But it can be optimized: inside the first loop, you already have fields so there is no need to save their names in a collection and retrieve later - just use them in place.</p>\n", "comments...
{ "AcceptedAnswerId": "31702", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T17:27:02.467", "Id": "31697", "Score": "2", "Tags": [ "java", "reflection" ], "Title": "Is this the right way to retrieve all the fields from any Object?" }
31697
<p>I've written a piece of code. Would like to know is the below piece of code unit testable or does it need any kind of refactoring.</p> <p>MatchCilentUrls is the primary method for matching two urls. Based on my business logic i am matching the Urls.</p> <p>Appreciate your comments on this.</p> <pre><code> publ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T08:29:50.020", "Id": "50620", "Score": "2", "body": "I think it's `C#` not `Java`." } ]
[ { "body": "<p>Of course it is unit testable.</p>\n\n<p>All function/methods are.</p>\n\n<p>A unit test is to flex the function to breaking point. i.e. exercise the usual conditions and the boundary points.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-S...
{ "AcceptedAnswerId": "31701", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T05:50:34.217", "Id": "31698", "Score": "1", "Tags": [ "java", "unit-testing" ], "Title": "Is my code unit testable" }
31698
<p>I'm getting back into web development, and I'm creating a mobile-friendly web app. I'm trying to make it SPA-like in the sense that I don't load new pages for each action the user takes. As my index.cshtml page will show, I have a header, and then I have a bunch of <code>div</code>s. Those <code>div</code>s serve as...
[]
[ { "body": "<p>It's more of a personal preference thing, but I would recommend removing the onclicks in the following:</p>\n\n<pre><code>&lt;li onclick=\"showApps()\"&gt;&lt;a href=\"#\" class=\"ui-btn-active\"&gt;Apps&lt;/a&gt;&lt;/li&gt;\n&lt;li onclick=\"showServers()\"&gt;&lt;a href=\"#\"&gt;Servers&lt;/a&gt...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T18:34:03.940", "Id": "31703", "Score": "3", "Tags": [ "javascript", "jquery", "asp.net", "asp.net-mvc-4" ], "Title": "Navigating in ASP.NET MVC 4 in SPA-like App" }
31703
<p>I have been working on a character escaper for a production server that receives quite a few requests per second (sometimes in the range of 400).</p> <p>We forward some "query" requests to apache Lucent/SOLR, and I need to escape characters.</p> <p>Containing also feedback from <a href="https://softwareengineering...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T21:00:44.103", "Id": "50589", "Score": "0", "body": "I like your original version a lot better. If you need this to be faster, then I would suggest to just write it in C." }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>First I have to be honest and say that this code puts me into WTF-Mode very early on, but that must not be a bad thing. But what took me by surprise is the lack of comments, there are some edge-cases in there I can not make out why they're the way they're.</p>\n\n<p>On the latter, changing, sugges...
{ "AcceptedAnswerId": "31719", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T18:46:27.923", "Id": "31705", "Score": "2", "Tags": [ "java" ], "Title": "CharacterEscaper - further optimizable? Bugs?" }
31705
<p>I think that the following query is preventing against SQL injection, but what other measures do I need to take to ensure my queries are 100% safe from any malicious attacks?</p> <pre><code>$statement = $db-&gt;prepare( "INSERT INTO blogs (blogtitle, blogdesc, coverimage, userID, frontpage, tags) VALUES (:...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T23:36:05.933", "Id": "50598", "Score": "0", "body": "Which classes are you using (what is $db) ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T08:34:49.600", "Id": "50621", "Score": "0", ...
[ { "body": "<p>100% safe is not possible; I'm sure someone will break prepared statements if they haven't already. You have already take an big step in security by using prepared statements over escaping. </p>\n\n<p>One important step is to validate your POST variables. For instance let's say a valid buildtitl...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T19:11:39.397", "Id": "31706", "Score": "2", "Tags": [ "php", "sql", "security", "pdo" ], "Title": "Remove vulnerabilities from query on public website" }
31706
<p>Here's the query: </p> <pre><code> using (var db = CreateContext()) { // performing the check for HasBeenAdded inline here, is this only one db call? return db.Subjects.Select(s =&gt; new SubjectDto(s){HasBeenAdded = db.Interests.Any(x =&gt; x.SubjectId == s.SubjectId)}).ToList(); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T23:30:08.863", "Id": "50596", "Score": "1", "body": "Seems relatively simple to me. Some newline characters would spruce it up a bit." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T01:48:05.413", ...
[ { "body": "<p>I would normally suggest consistent usage. In the example you provide, you use both constructor parameters as well as property initialisation.</p>\n\n<p>Depending on you options to change etc. the <strong>SubjectDto</strong> I would add another construction parameter to it and pass in a hasBeenAdd...
{ "AcceptedAnswerId": "38653", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-23T22:19:21.990", "Id": "31710", "Score": "3", "Tags": [ "c#", "linq" ], "Title": "LINQ query to select subjects of interest" }
31710
<p>I'm learning C with K&amp;R 2nd Ed. I just completed <a href="//stackoverflow.com/questions/7178201/kr-exercise-1-20-need-some-clarification" rel="nofollow">exercise 1-20</a> (which is the <code>detab</code> program). I was hoping to get some feedback on my work. I want to make sure that I am taking a good C appr...
[]
[ { "body": "<p>I don't think this program is correct, according to my interpretation of tab stops. One problem is that the column count should reset to 0 after every carriage return or newline character encountered.</p>\n\n<p>Your program is vulnerable to buffer overflow. This may be acceptable for a beginner,...
{ "AcceptedAnswerId": "31718", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T01:19:10.047", "Id": "31712", "Score": "4", "Tags": [ "beginner", "c", "strings", "io", "formatting" ], "Title": "K&R 1-20 Converting tabs to spaces using idiomatic C" ...
31712
<p>I'm writing a <em>somewhat</em> secure voting system. I'm aware that it won't be really secure because it's on the internet so I'm looking for feedback on any logic errors or glaring mistakes in the security implementation.</p> <p>The backend is ExpressionEngine CMS.</p> <p>So, in this system user is allowed to vo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T17:05:46.760", "Id": "50659", "Score": "0", "body": "See the Electronic Voting Systems\nlisted at: https://bitbucket.org/djarvis/world-politics/wiki/Related%20Links" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>Don't use <a href=\"http://php.net/manual/en/function.mt-rand.php\" rel=\"nofollow\">mt_rand</a> as the \"random\" value can be predictable:</p>\n\n<blockquote>\n <p>This function does not generate cryptographically secure values, and should not be used for cryptographic purposes. If you need a c...
{ "AcceptedAnswerId": "31727", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T06:38:53.333", "Id": "31716", "Score": "2", "Tags": [ "php", "security" ], "Title": "Somewhat secure voting system" }
31716
<p>I want you to pick my code apart and give me some feedback on how I could make it better or more simple. This code will traverse peripheri (clock and anticlockwise) in \$O(n)\$ just traversing the tree once.</p> <pre><code>public class PeriPheri { private TreeNode root; private static class TreeNode { ...
[]
[ { "body": "<p>I think that <code>printChild()</code> would be better named <code>printDescendantLeaves()</code>. Also, <code>printChild()</code> always works left-to-right, which spoils your clockwise traversal.</p>\n\n<p>For flexibility, consider taking a <a href=\"http://en.wikipedia.org/wiki/Visitor_pattern...
{ "AcceptedAnswerId": "31722", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T07:58:14.903", "Id": "31717", "Score": "2", "Tags": [ "java", "algorithm", "tree" ], "Title": "Print periphery of a binary tree" }
31717
<p>I've written this code for a merge sort, which is meant to implement the pseudo-code from Cormen's <em>Introduction to Algorithms</em>:</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdlib&gt; using namespace std; const unsigned long long infinity = -1ULL; void merge(int* A,int p,const int q, const int ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T13:20:57.007", "Id": "50633", "Score": "0", "body": "Did you try to run this using `gdb` or another debugger and check whether the indeces used are correct?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-0...
[ { "body": "<p>Don't do this:</p>\n\n<pre><code>using namespace std;\n</code></pre>\n\n<p><a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">For a detailed explanation</a> on why not to use the usign clause.</p>\n\n<p>This is not used anywhere (also its not...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T10:19:30.627", "Id": "31726", "Score": "5", "Tags": [ "c++", "sorting", "mergesort" ], "Title": "Merge Sort in C++" }
31726
<p>I've been working on a website status checker.. However this array that I use has around 30 sites within it, I've noticed it's taking around 6-7 seconds to load it.</p> <p>I was wondering if there's any kind of way of doing below, but more efficiently.</p> <p>I have thought of doing the below in a cron, and fetchi...
[]
[ { "body": "<p>PHP is not suitable for multi-threading. Though there are some extensions that offer ways of multithreading, they all are, basically, hacks IMO. The best way forward in your case would be: to use a tool that is async by nature, and update the url's as you go along.<Br/>\nThankfully, such a thing e...
{ "AcceptedAnswerId": "31738", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T11:16:26.247", "Id": "31729", "Score": "3", "Tags": [ "javascript", "php", "optimization", "curl" ], "Title": "Service status checker... Is there a more efficient way?" }
31729
<p>I have this if statement</p> <pre><code>if (dt.Month &gt; 3 &amp;&amp; dt.Month &lt; 11) { if (hours == 23 || (hours &gt;= 0 &amp;&amp; hours &lt;= 6)) { session = String.Empty; } else if (hours == 7) { session = String.Empty; } else if (hours &gt;= 8 &amp;&amp; hours &lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T13:20:38.190", "Id": "50632", "Score": "1", "body": "Easy. `if (dt.Month > 3 && dt.Month < 11) { sesion = String.Empty; }`. I think you can fall through case statements in C# depending what you are trying to do, maybe post real code...
[ { "body": "<p>Shouldn't you replace the whole code with <code>session = String.Empty;</code> ?</p>\n\n<p>Let's assumme that this is just a placeholder for actual code. If you handle your different cases in order and if <code>hours</code> is an <code>int</code>, then you can make the logic a bit easier to follow...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T13:16:07.510", "Id": "31731", "Score": "4", "Tags": [ "c#" ], "Title": "Condensing if statement in C#" }
31731
<p>I'm working through a Java textbook by Paul and Harvey Deitel and I have come across a review question (Chapter 2 - Intro to Java, Exercise 2.18 for those that have the book) which asks the user to create the following diamond:</p> <pre><code> * * * * * * * * * * * * * * * *...
[]
[ { "body": "<p>You can do away with the <code>printStartEnd</code> method, as the <code>printOtherLines</code> can do the same job, if you send in the same value for <code>positionOne</code> and <code>positionTwo</code>.</p>\n\n<p>If you have a numeric value for direction instead of a boolean flag, you can use t...
{ "AcceptedAnswerId": "31754", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T13:44:10.503", "Id": "31734", "Score": "3", "Tags": [ "java", "console", "formatting" ], "Title": "Shortening and optimizing diamond-printing code" }
31734
<p>I've been trying to emulate MS Windows behavior on my OS X and close processes that do not have a window.</p> <p>What I'd really like to do is "quit" the process on clicking the red "x" button. Instead, I've managed to code this workaround, which constantly runs in the background.</p> <p>(see my question <a href=...
[]
[ { "body": "<p>Maybe a late response but I'm new to codereview but not to AppleScript. The problem with AppleScript and scripts that stays open is that they leak memory. Why? I just blame it on AppleEvents. It's a nice feature, it really is, but it does eats memory somehow. So the longer the script will run the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T15:47:10.027", "Id": "31742", "Score": "4", "Tags": [ "macros", "osx", "applescript" ], "Title": "AppleScript to close running processes" }
31742
<p>OS X consists of a Mach/BSD-based kernel, operating system interfaces primarily based on FreeBSD, and additional frameworks (written in C, C++ and Objective-C) providing user interface and application-level services.</p> <h3>More information:</h3> <ul> <li><a href="http://en.wikipedia.org/wiki/OS_X" rel="nofollow"...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T16:00:36.323", "Id": "31743", "Score": "0", "Tags": null, "Title": null }
31743
OS X, previously Mac OS X, is a series of Unix-based graphical interface operating systems developed, marketed, and sold by Apple Inc. It is designed to run exclusively on Mac computers, having been pre-loaded on all Macs since 2002. Use this tag for questions about OS X specific code.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T16:00:36.323", "Id": "31744", "Score": "0", "Tags": null, "Title": null }
31744
<p>AppleScript is a macOS inter-application scripting language, designed to control and exchange data between scriptable applications.</p> <p>From <a href="http://developer.apple.com/applescript/" rel="nofollow noreferrer">Apple Developer</a> page:</p> <blockquote> <p>AppleScript is Apple's powerful and versatile nativ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-09-24T16:14:08.797", "Id": "31745", "Score": "0", "Tags": null, "Title": null }
31745
AppleScript is an end user scripting language that has been available in Mac computers since System 7 Pro (7.1.1). It allows for automation of system tasks, communication between processes, and creation of workflows, amongst other functions.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T16:14:08.797", "Id": "31746", "Score": "0", "Tags": null, "Title": null }
31746
<p>I have attempted to write a method that checks that images being uploaded are valid.</p> <pre><code>public function checkValidImages(){ $errors = array(); $allowedImages = array('image/jpg','image/jpeg','image/png','img/gif'); $maxFileSize = 2097152; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T21:46:08.517", "Id": "54367", "Score": "0", "body": "You're not doing any check for exploits nor managing duplicates" } ]
[ { "body": "<p>There are 4 foreach loops for the same files, going for a little more complex but more\norganaized nested loop would be better, like this</p>\n\n<pre><code>foreach ($_FILES['event-images']['tmp_name'] as $tmp_name) {\n if (!empty($tmp_name)){\n $image = $_FILES[\"event-images\"][\"name\"...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T16:26:57.420", "Id": "31747", "Score": "1", "Tags": [ "php", "validation", "image" ], "Title": "Validating uploaded images" }
31747
<p>I got tired of doing (more or less) this in my rails controllers : </p> <pre><code>class ThingsController &lt; ApplicationController def index @category = Category.find( params[:category_id] ) if params[:category_id].present? scope = @category ? @category.things : Thing.scoped @things = scope.order( ...
[]
[ { "body": "<p>I'd try to keep it as simple as possible. Instead of multiple in-line conditionals or a weird abstraction, I think a single full-fledged indented conditional makes things very clear. There are two scenarios, write two branches:</p>\n\n<pre><code>class ThingsController &lt; ApplicationController\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T17:09:24.893", "Id": "31750", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "\"specific case\" object that stands for \"any object\" : is it a good idea ?" }
31750
<p>I just created a Hangman app (same game mechanics mostly) using Java. I did this mainly to test my knowledge in OOP design/coding. I'd like to know your thoughts on my code</p> <p>The whole <a href="https://github.com/zurcnay4/Hangman" rel="nofollow">project is on Github</a></p> <p>I would really appreciate the co...
[]
[ { "body": "<p>Please split your code into different smaller functions.\nThis is just impossible to understand. Here's my attempt, it probably doesn't compile but it does look much easier to understand :</p>\n\n<pre><code>public class Launcher {\n private static BufferedReader consoleReader;\n\n public sta...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T17:15:40.250", "Id": "31751", "Score": "7", "Tags": [ "java", "beginner", "object-oriented", "hangman" ], "Title": "Console based Hangman in Java" }
31751
<p>This is my first attempt at Clojure! Apart from all game related issues, how is my code? Is there anything I can do to make it more idiomatic?</p> <pre><code>(ns hangman.core (:import (java.net ServerSocket Socket SocketException)...
[]
[ { "body": "<p>A bunch of random observations</p>\n\n<ul>\n<li><p>avoid <code>def</code> as a non-top level form e.g. in <code>(def the-guess (atom \"\"))</code>, prefer <code>let</code> bindings</p></li>\n<li><p>there's no need to use a ref for the connection, as it never changes after creation. Prefer a simple...
{ "AcceptedAnswerId": "31787", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T17:21:43.203", "Id": "31752", "Score": "5", "Tags": [ "beginner", "clojure", "hangman" ], "Title": "Hangman - my first Clojure code" }
31752
<p>This is an assignment for an intro to Java course. It works with the test case given, but I would like to know if there is anything / a lot of things that should be different or could be better.</p> <p>Specification:</p> <blockquote> <p>Write a Java application that accepts 5 “valid” numbers from the user.</p> ...
[]
[ { "body": "<ul>\n<li><p>Comparisons of <code>boolean</code>s:</p>\n\n<p>Please use</p>\n\n<pre><code>if (validCheck)\n</code></pre>\n\n<p>or</p>\n\n<pre><code>if (!validCheck)\n</code></pre>\n\n<p>instead of</p>\n\n<pre><code>if (validCheck == true)\n</code></pre>\n\n<p>or</p>\n\n<pre><code>if (validCheck == fa...
{ "AcceptedAnswerId": "31760", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T17:36:46.913", "Id": "31753", "Score": "1", "Tags": [ "java", "homework" ], "Title": "Intro to Java - determine valid unique numbers" }
31753
<p><a href="http://projecteuler.net/problem=92" rel="nofollow">Link to problem</a>.</p> <blockquote> <p>A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before.</p> <p>For example,</p> <p>44 -> 32 -> 13 -> 10 -> 1 -> 1</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T20:52:33.237", "Id": "50666", "Score": "1", "body": "Memoization might help you" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T21:08:19.243", "Id": "50667", "Score": "0", "body": "There i...
[ { "body": "<h2>1. Bug</h2>\n\n<p>There's a bug in your program. This line</p>\n\n<pre><code>if pastChains[term] is not None:\n</code></pre>\n\n<p>should be</p>\n\n<pre><code>if pastChains[term] is None:\n</code></pre>\n\n<h2>2. Piecewise improvement</h2>\n\n<p>In this section I'm going to show how you can speed...
{ "AcceptedAnswerId": "31767", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T19:29:30.663", "Id": "31761", "Score": "4", "Tags": [ "python", "optimization", "project-euler" ], "Title": "Project Euler problem 92 - square digit chains" }
31761
<p><a href="http://mootools.net/" rel="nofollow noreferrer">MooTools</a> is a compact, modular, object-oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and <a href="http://mo...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T21:03:58.663", "Id": "31763", "Score": "0", "Tags": null, "Title": null }
31763
MooTools is a compact, modular, object-oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and coherent API.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T21:03:58.663", "Id": "31764", "Score": "0", "Tags": null, "Title": null }
31764
<p>I had to do this in a course a while back: make <code>{1,2,3,4,5,6,7,8,9}</code> into <code>{{1,2,3},{6,5,4},{7,8,9}}</code>. When doing it, I just made the inner for-loop do all the work. But most of my friends had a Boolean and an if-statement to chose between a forward or reverse loop. </p> <p>Which is more opt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T22:56:30.050", "Id": "50670", "Score": "0", "body": "Can you give more details on what is expected? Another example or an explanation would be much appreciated." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>I do prefer the solution with the boolean. Also, a third possible variant would be to fill every other from left to right and remaining rows from right to left</p>\n\n<p>In any case, they way you are supposed to handle arrays where size is not A*B might help you to pick the best solution for you.<...
{ "AcceptedAnswerId": "31788", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T21:06:59.377", "Id": "31765", "Score": "2", "Tags": [ "java", "array" ], "Title": "Switching directions in iterating 2D arrays" }
31765
<p>I've written a little command-line utility for filtering log files. It's like grep, except instead of operating on lines it operates on log4j-style messages, which may span multiple lines, with the first line always including the logging level (TRACE, DEBUG etc.).</p> <p>Example usage on a file short.log with conte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T22:45:46.867", "Id": "50669", "Score": "1", "body": "Shouldn't you consider the log level only if it is at the beginning of the line? A line could contain info without being the first line of an info log. (Also you should log on a s...
[ { "body": "<p>I see two problems with your loops.</p>\n\n<p>In terms of style, calling <code>file.next()</code> and catching <code>StopIteration</code> is highly unconventional. The normal way to iterate is:</p>\n\n<pre><code>for line in fileinput.input(options.file):\n …\n</code></pre>\n\n<p>In terms of fu...
{ "AcceptedAnswerId": "92630", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T22:33:12.010", "Id": "31768", "Score": "3", "Tags": [ "python", "logging" ], "Title": "Filtering file for command line tool" }
31768
<p>Kindly look at this code and point out design flaws or areas for improvement. I think I've done the last part right (the enum). I think the rest of the design is flawed but I am very new to object-oriented programming.</p> <p><strong>Game</strong></p> <pre><code>//Game class establishes rules and finds winner pub...
[]
[ { "body": "<p>If you like enums, this example has two of them. The code is untested but might give you an idea.</p>\n\n<pre><code>public class Game {\n private final Symbol[] gameState = new Symbol[9];\n private final Symbol player1;\n private final Symbol player2;\n private Symbol currentPlayer;\n\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T23:20:28.240", "Id": "31769", "Score": "7", "Tags": [ "java", "beginner", "object-oriented", "enum", "tic-tac-toe" ], "Title": "Tic-Tac-Toe design" }
31769
<p>So a page where I do a search based on a bunch of filters but all of them are optionals. I have my controller here:</p> <pre><code>def distribution begin @service_request = ServiceRequest.find(params[:id]) @claimed, @unclaimed = 0, 0 @conditions = ContractorSearchConditions.new() @condit...
[]
[ { "body": "<p>Many things here.</p>\n\n<h2>Style considerations</h2>\n\n<p>First, in ruby <a href=\"http://rubylearning.com/blog/2011/12/21/lets-talk-about-conditional-expressions/\" rel=\"nofollow\">conditionals are expressions</a>, so instead of :</p>\n\n<pre><code>self.lat.nil? ? self.lat = zip.latitude.to_f...
{ "AcceptedAnswerId": "31791", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-24T23:29:00.040", "Id": "31770", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Improve a list of if" }
31770
<p><strong>Background</strong></p> <p>In C++ unlike other OOP languages, we do not have a Base Class from where All Classes are derived. I understand in MFC and pre STL, some Compilers did had a similar model, so lets leave it out of the discussion and focus on what the standard provides. </p> <p>In C++11, <code>auto...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-02-06T13:22:29.410", "Id": "504585", "Score": "0", "body": "Does `std::optional` serve your purpose nowadays?" } ]
[ { "body": "<p>The first question is, why are you using pointers in the first place here? Allocation with <code>new</code> should only be used when required. Perhaps it is in this case, but I'd rethink your design. Are the errors polymorphic? If so, why? If not, why do you need to use pointers?</p>\n\n<p>Many ST...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T03:13:40.577", "Id": "31777", "Score": "3", "Tags": [ "c++" ], "Title": "Null Object Pattern for STL Types" }
31777
<pre><code>import bwi.prog.utils.TextIO; public class MinMidMax { public static void main(String[] args) { int a,b,c; int greatest, mid, smallest; TextIO.putln("Enter three numbers"); TextIO.put("a="); a = TextIO.getInt(); TextIO.p...
[]
[ { "body": "<p>This will achieve the same goal in much less code.</p>\n\n<pre><code>import bwi.prog.utils.TextIO;\nimport java.util.*;\n\npublic class MinMidMax {\n\n public static void main(String[] args) { \n Map&lt;Integer, Character&gt; vars = new TreeMap&lt;Integer, Character&gt;();\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T04:25:07.843", "Id": "31778", "Score": "0", "Tags": [ "java", "sorting" ], "Title": "Sorting three numbers" }
31778
<p>I have written a memory pool (<code>pool_allocator</code>) that was described in a book I am reading (<em>Game Engine Architecture</em>). The interface is pretty basic:</p> <ul> <li>The constructor: <code>pool_allocator(std::size_t count, std::size_t block_size, std::size_t alignment);</code>.</li> <li><code>void*...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-05T15:47:41.507", "Id": "106421", "Score": "0", "body": "Shouldn't you try to implement the allocator interface? http://en.wikipedia.org/wiki/Allocator_(C%2B%2B)" } ]
[ { "body": "<p>I think you have some fundamental misunderstandings about alignment (and you can simplify your code a lot):</p>\n\n<h3>3.11 Alignment</h3>\n\n<blockquote>\n <p>3: Alignments are represented as values of the type std::size_t. Valid alignments include only those values returned by an alignof expres...
{ "AcceptedAnswerId": "31879", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T04:37:54.593", "Id": "31779", "Score": "4", "Tags": [ "c++", "c++11", "memory-management" ], "Title": "Memory Pool and Block Alignment" }
31779
<p>I am learning java and browsing posts on CodeReview and StackOverflow.</p> <p>In my text <strong>Introduction to Java Programming- Y Daniel Liang</strong> it states: </p> <blockquote> <p>The wildcard import imports all classes in a package by using ...<br> The information for the classes in an imported pack...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T07:21:52.047", "Id": "50697", "Score": "5", "body": "I'm not sure, but I think this question would be better suited for Programmers." } ]
[ { "body": "<p>I prefer not to use star imports, because they can lead to ambiguities. Read more here: <a href=\"https://stackoverflow.com/a/147461/660143\">https://stackoverflow.com/a/147461/660143</a></p>\n\n<p>There is no consensus about whether star import are good or bad. My IDE organizes the imports for me...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T06:39:20.697", "Id": "31782", "Score": "3", "Tags": [ "java", "beginner" ], "Title": "Using the wildcard when importing packages" }
31782
<p>In our Rails 3.2.13 app (Ruby 2.0.0 + Postgres on Heroku), we are often retreiving a large amount of Order data from an API, and then we need to update or create each order in our database, as well as the associations. A single order creates/updates itself plus approx. 10-15 associcated objects, and we are importing...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T21:00:25.757", "Id": "50742", "Score": "0", "body": "It's hard to understand what you are actually doing there. Did you monitor what (and how many) database statement get executed when you import an order? That could give you a clue...
[ { "body": "<p>You can reduce the amount of queries by putting it into a transaction:</p>\n\n<pre><code>ActiveRecord::Base.transaction do\n ...\nend\n</code></pre>\n\n<p>This wont reduce the amount of queries but will do them all at once which will save it doing the commit step for each time it has to do the qu...
{ "AcceptedAnswerId": "32051", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T07:35:39.407", "Id": "31784", "Score": "7", "Tags": [ "performance", "ruby", "ruby-on-rails", "postgresql" ], "Title": "Faster way to update/create of a large amount of rec...
31784
<p>I have a function that processes a large amount of data. I call this function as part of a wider process via a command line script in which many similar but shorter jobs are conducted in sequence.</p> <p>I have something like this:</p> <pre><code>import time def initialise_foo(): """do something quickly""" ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T15:41:59.093", "Id": "50715", "Score": "1", "body": "Alternatively, you could pass in an object like a file or something and write progress to that, perhaps." } ]
[ { "body": "<p>I see three basic options you have, to structure progress feedback:</p>\n\n<ol>\n<li><code>yield</code></li>\n<li>a callback function</li>\n<li>inline, hard-coded feedback</li>\n</ol>\n\n<p>Using <code>yield</code>, as you've shown, is one approach. Ensure you are familiar with Python's implement...
{ "AcceptedAnswerId": "33746", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T10:22:22.480", "Id": "31789", "Score": "12", "Tags": [ "python", "console", "iteration" ], "Title": "Progress report for a long-running process using 'yield'" }
31789
<p>I am new in haskell and for start I choosed to write simple grep. Now I want to ask if there is some simplier/shorter way to write it. For example if there is any way to avoid recursion.</p> <pre><code>parseLines :: String -&gt; [String] -&gt; Int -&gt; IO () parseLines _ [] _ = return () parseLines pattern (x:xs) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T17:07:53.073", "Id": "50721", "Score": "0", "body": "Since you're actually not doing any regexps, I believe this can hardly be called a \"grep\". This is just some searching utility." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Here's the updated code. The notes are following after.</p>\n\n<pre><code>import Control.Monad\nimport Data.List\nimport System.Directory\nimport System.Environment\n\nsearch :: String -&gt; String -&gt; [(Int, String)]\nsearch searchString content = do\n (lineNumber, lineText) &lt;- zip [0..] $ ...
{ "AcceptedAnswerId": "31815", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T15:33:11.447", "Id": "31795", "Score": "3", "Tags": [ "haskell" ], "Title": "Haskell grep simplification" }
31795
<p>More information, documentation and samples are available at <a href="http://knockoutjs.com" rel="nofollow">http://knockoutjs.com</a></p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T16:18:49.947", "Id": "31801", "Score": "0", "Tags": null, "Title": null }
31801
<p><a href="http://coolwx.com/buoydata/data/curr/all.html" rel="nofollow">http://coolwx.com/buoydata/data/curr/all.html</a> provides weather data from ships (or maybe buoys) at sea, but the date is given as "25/18" (meaning the 18th hour of the 25th day of the month, all times GMT). </p> <p>I need to convert this to...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T06:53:08.643", "Id": "50754", "Score": "2", "body": "The link you gave as an example has month name in the first line (_Offshore Data at 06Z Sep 26_) - can you use it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDat...
[ { "body": "<p>There's a timestamp file available here: <a href=\"http://coolwx.com/buoydata/data/curr/timestamp\" rel=\"nofollow\">http://coolwx.com/buoydata/data/curr/timestamp</a>, so I think it'll be easier if you download and parse both data and timestamp files. </p>\n\n<p>You can parse the timestamp with t...
{ "AcceptedAnswerId": "31865", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T18:51:17.237", "Id": "31809", "Score": "1", "Tags": [ "perl", "datetime" ], "Title": "More elegant way to get timestamp from day/hour? (Perl)" }
31809
<p>I've started coding C++ again after a 6 month break to prepare for a class I'm taking this quarter. I found this idea and thought it would be fun to try and code.</p> <p>I originally started with input as a string, and wanted to split it into two <code>int</code>s at <code>.</code>, but this way seemed easier. The...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T19:13:13.683", "Id": "50731", "Score": "0", "body": "Where's `main()`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T19:30:24.427", "Id": "50732", "Score": "3", "body": "Why are you usin...
[ { "body": "<p>Stylistically:</p>\n\n<ul>\n<li>just write <code>std::</code> instead of <code>using namespace std;</code> (which you didn't show but was implicit)</li>\n<li>use a regular <code>if()</code> instead of the ternary operator <code>?</code> </li>\n<li>use compound assignment operators like <code>dolla...
{ "AcceptedAnswerId": "31823", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T19:04:07.297", "Id": "31811", "Score": "3", "Tags": [ "c++", "integer" ], "Title": "Breaking down a dollar amount into bill and coin denominations" }
31811
<p>I am new to C++ and with my basic knowledge of the language, I have attempted to create a simple console application filled with lots of useful functions involving math related stuff.</p> <p>The following is the only version of it that I have created thus far: (also available <a href="https://gist.github.com/NickKa...
[]
[ { "body": "<p>The command pattern is your friend.<br>\nYou can then use a std::map to convert a user input string to a command during execution.</p>\n\n<pre><code>#include &lt;map&gt;\n#include &lt;string&gt;\n#include &lt;functional&gt;\n#include &lt;cmath&gt;\n#include &lt;iostream&gt;\n\nint main(int argc, c...
{ "AcceptedAnswerId": "48539", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T19:51:38.210", "Id": "31813", "Score": "6", "Tags": [ "c++", "optimization", "beginner", "mathematics", "console" ], "Title": "Simple mathematical console application" ...
31813
<p>I have an element where the <a href="http://jscrollpane.kelvinluck.com/" rel="nofollow noreferrer"><code>jScrollPane</code></a> is being used to provide custom scrollbars for an extensive text. The idea behind the code is to change the image beside the text each time the user reaches a certain amount of scroll while...
[]
[ { "body": "<p>I'd like to address a couple of style concerns over simplification.</p>\n\n<ol>\n<li><p>Purely for debugging if you have function expressions then name them.</p>\n\n<p>eg. \n setInterval(function(){</p>\n\n<p>could become</p>\n\n<pre><code>setInterval(function _scrollDetectionInterval(){\n</cod...
{ "AcceptedAnswerId": "31830", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:07:44.840", "Id": "31816", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Custom function to scroll spy on the jScrollPane plugin" }
31816
<p>Here is my implementation of John Conway's Game of Life in Python:</p> <pre><code>from copy import deepcopy def countSurrounding(board, row, cell): SURROUNDING = ((row - 1, cell - 1), (row - 1, cell ), (row - 1, cell + 1), (row , cell - 1), ...
[]
[ { "body": "<p>Firstly read <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">http://www.python.org/dev/peps/pep-0008/</a> and be Pythonic.\nYou will be amazed how your code will get improve, write the new one as a new file and compare them.</p>\n\n<p>This is a huge brick of False bools on yo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:12:16.237", "Id": "31817", "Score": "4", "Tags": [ "python", "game-of-life" ], "Title": "Python - Game Of Life" }
31817
<p>Could someone help me shorten this code, please?</p> <pre><code>while cd == "monday": if cp == "0": for v in mon.values(): print(v) break break elif cp == "1": print(mon[1]) break elif cp == "2": print(mon[2]) break elif cp == "...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:20:29.057", "Id": "52111", "Score": "0", "body": "What are `cp`, `cd`, `mon`, and `tues`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:21:48.597", "Id": "52112", "Score": "0", "bo...
[ { "body": "<p>I'm considering the code only for \"monday\"</p>\n\n<pre><code>while cd == \"monday\": \n for i in range(0, 6):\n if cp == str(i):\n print(mon[i])\n break\nbreak\ncd = false\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:27:56.670", "Id": "31818", "Score": "3", "Tags": [ "python" ], "Title": "Repetitive days of the week code" }
31818
<h2>Problem Description</h2> <blockquote> <p>Write a program to find the maximum number of rectangles that can be formed both horizontal and vertical with the help of a given n number of coordinate(x,y) points. [x,y points will always be positive].</p> <p>The method getRectangleCount takes 1 input parameter...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:47:20.860", "Id": "50738", "Score": "0", "body": "`coOrdinates` should be `coordinates`; see: http://en.wikipedia.org/wiki/Coordinate_system" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:49:45...
[ { "body": "<p>On the whole it's not at all bad, I find it readable and I'm sure that it does the job (one caveat to this is how does it handle cases where you have multiple instances of the same point e.g. {{1,1},{1,1},{1,2},{2,1}}), a few things that you could do to improve it..</p>\n\n<ul>\n<li>For uniqueness...
{ "AcceptedAnswerId": "31845", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:37:02.877", "Id": "31819", "Score": "5", "Tags": [ "java", "optimization", "coordinate-system" ], "Title": "Get Rectangle Count from Given List of Co-ordinates" }
31819
<p>I am trying to write a <code>SynchronizationContext</code> in C# that represents a message queue, to be pumped from a main loop.</p> <p><em>Edit</em>: I see that I have forgotten to say - I need the message loop executions to be done a single, pre-determined thread. (In my case I want to push updates to an OpenGL c...
[]
[ { "body": "<ol>\n<li>You don't need to implement <code>Dispose</code> pattern if you have no unmanaged resources to dispose. Unless you get paid per line of code, that is :)</li>\n<li><p>You should not dispose objects you did not create (unless you implement a wrapper). In your case, you should not dispose rese...
{ "AcceptedAnswerId": "31843", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:42:18.790", "Id": "31820", "Score": "10", "Tags": [ "c#", ".net", "multithreading" ], "Title": "Basic, single-threaded implementation of SynchronizationContext" }
31820
<p><code>User</code> and <code>Role</code> are just examples; also, code is sparse on purpose (i.e. for demonstration purposes only).</p> <p>Thoughts? (e.g. good, bad, etc.)</p> <p><strong>Interfaces</strong></p> <pre><code>public interface IEntity { int Id { get; } } public interface IUser : IEntity { ...
[]
[ { "body": "<p>This seems about right.</p>\n\n<p>There is only one thing I'd like to point out.</p>\n\n<p>I'd change this:</p>\n\n<pre><code>public interface IEntity {\n int Id { get; }\n}\n\npublic class Entity : IEntity {\n public virtual int Id { get; set; }\n}\n</code></pre>\n\n<p><strong>All</strong> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T20:57:27.023", "Id": "31822", "Score": "4", "Tags": [ "c#", "design-patterns", "entity-framework" ], "Title": "Unit of Work and Repository Design Pattern Implementation" }
31822
<pre><code>def execute(parameterName : scala.Boolean = { /* compiled code */ }) </code></pre> <p>When calling this method, you can go with</p> <pre><code>someobject.execute(true) </code></pre> <p>or</p> <pre><code>someobject.execute(parameterName = true) </code></pre> <p>If you use the former, IntelliJ pops up a r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T21:53:19.597", "Id": "50832", "Score": "0", "body": "This is really a question for the Programmers affiliate site. You're asking about a concept, with single line examples, not for a review of some functioning code. You'd get more...
[ { "body": "<p>IDEA's Scala plugin has always been lacking quality compared to other products of Jetbrains. The company develops a direct competitor language to Scala named Kotlin, so I think it's simply an issue of their priorities. In a couple of years of posting dozens of bugs related to Scala plugin on their...
{ "AcceptedAnswerId": "31828", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-25T22:39:47.800", "Id": "31827", "Score": "7", "Tags": [ "scala" ], "Title": "Whether or not to name Boolean parameters in Scala" }
31827
<p>While responding to a SO question, I wrote the following method to convert a flat key structure to a hierarchical one as given below</p> <p>In</p> <pre><code>{ property1: 'value1', property2.property3: 'value2', property2.property7: 'value4', property4.property5.property6: 'value3', } </code></pre> <...
[]
[ { "body": "<p>The main complexity of this function arises from using a <strong>plain for-in loop</strong> to loop over object keys - this adds two extra indentation levels instead of just one level if one were to use a higher-level looping construct. So I would use some library function or create something like...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T03:04:48.480", "Id": "31831", "Score": "4", "Tags": [ "javascript" ], "Title": "Convert flat object keys to hierarchical one" }
31831
<p>I wrote a script that will eventually go onto a Raspberry Pi. It takes a picture then uploads it to Twitter every 15 minutes from 5:30-9:00pm. </p> <p>It works fine as is, but I feel I need to organize this as a class. I was wondering if someone could point me in the right direction on how to take my functions a...
[]
[ { "body": "<p>I think that defining a function inside of a function definition body is bad practice.\nFor example you can have a class called <code>Scheduler</code> and define each function inside that class.</p>\n\n<p>I will leave the rest for the more expirienced people.</p>\n", "comments": [], "meta_...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T03:41:47.097", "Id": "31832", "Score": "2", "Tags": [ "python", "twitter" ], "Title": "Uploading a picture to Twitter over a period of time" }
31832
<p>I attempted to write a read-only dictionary, containing primes:</p> <pre><code>#inspired by http://ceasarjames.wordpress.com/2011/07/10/the-quadratic-sieve/ class PrimeDict(dict): def __init__(self): super(PrimeDict,self).__setitem__(2,2) self.previous_max = 2 def __setitem__(self, key, val...
[]
[ { "body": "<h3>1. Comments on your code</h3>\n\n<ol>\n<li><p>No docstrings! What does your class do and how am I supposed to use it? Also, no <a href=\"http://docs.python.org/3/library/doctest.html\" rel=\"nofollow\">doctests</a>.</p></li>\n<li><p>Wouldn't it be more natural for this class to be a <em>set</em> ...
{ "AcceptedAnswerId": "31848", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T04:26:31.057", "Id": "31835", "Score": "3", "Tags": [ "python", "primes", "hash-map" ], "Title": "Prime number dictionary" }
31835
<p>I've taken all the advice from <a href="https://codereview.stackexchange.com/questions/31451/craps-game-rules-and-code">here</a> and have created a Craps class and gameplay. I just wanted to ask for more advice on how to optimize my code.</p> <pre><code>#include &lt;iostream&gt; #include &lt;cmath&gt; // atan()...
[]
[ { "body": "<ul>\n<li><p><a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">Try to refrain from using <code>using namespace std</code></a>, especially in a program like this. If you were to put it in the header, you could introduce bugs due to issues such ...
{ "AcceptedAnswerId": "31838", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T04:45:14.700", "Id": "31836", "Score": "2", "Tags": [ "c++", "optimization", "classes", "game" ], "Title": "Craps game rules and code: version 2" }
31836
<p>I want you to pick my code apart and give me some feedback on how I could make it better or simpler. This code converts a binary tree to a doubly linked list (in order).</p> <pre><code>public class BinaryTreeToLinkedList { private TreeNode root; private static class TreeNode { TreeNode left; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T16:50:17.860", "Id": "50797", "Score": "0", "body": "Your question says inorder, but your code says postorder." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T17:39:43.973", "Id": "50803", "Sc...
[ { "body": "<p>Your code certainly seems to do the job (assuming that the tree is only a root node with two branches; otherwise you will need to implement some recursion). It doesn't \"feel\" very Java-esque, but you've said in your previous questions/comments that you don't really want critique of method and v...
{ "AcceptedAnswerId": "31852", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T06:10:10.213", "Id": "31841", "Score": "4", "Tags": [ "java", "algorithm", "linked-list", "tree", "converting" ], "Title": "Convert tree to circular doubly linked list"...
31841
<p>The first line of the input stream contains integer n. The second line contains <code>n (1 &lt;= n &lt;= 1000)</code> integers <code>{ a[1], a[2], a[3], ... , a[n] }, abs(a[i]) &lt; 10^9</code>. </p> <p>Find the longest alternating subsequence <code>{ a[i1], a[i2].. , a[ik] }</code> of the sequence <code>a</code> t...
[]
[ { "body": "<p>Your approach is not very idiomatic. It is very hard to read, and reason-about. Spotting mistakes is not easy. I will not even attempt it, as I think some major rewriting should be your first priority. I think your current approach of trying to solve the entire problem in one big function is a big...
{ "AcceptedAnswerId": "31991", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T07:19:06.500", "Id": "31842", "Score": "7", "Tags": [ "c++", "algorithm" ], "Title": "The longest alternating sequence in C++" }
31842
<p>I am working on a small method that saves uploaded images and records the images in a database.</p> <pre><code>public function setEventImages($event_id){ foreach($_FILES['event-images']['tmp_name'] as $tmp_name){ $imgName = $this-&gt;imgPath . $this-&gt;random_name . $_FILES['event-imag...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T20:46:37.910", "Id": "83829", "Score": "0", "body": "Are you sure you want to store images in the database? I have always opted for storing the path to the image in the database, but left the images as flat files. There are plenty o...
[ { "body": "<p>I don't think your code will work as expected. This:</p>\n\n<pre><code> foreach($_FILES['event-images']['tmp_name'] as $tmp_name){\n</code></pre>\n\n<p>tells me that <code>$_FILES['event-images']['tmp_name']</code> is an array (i.e., you're handling multiple files upload). But, in that case...
{ "AcceptedAnswerId": "31855", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T13:26:51.180", "Id": "31853", "Score": "3", "Tags": [ "php", "pdo", "image" ], "Title": "Saving and uploading images in a database" }
31853
<p>I've been looking into empty abstract classes and from what I have read, they are generally bad practice. I intend to use them as the foundation for a small search application that I am writing. I would write the initial search provider and others would be allowed to create their own providers as well. My code's int...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T17:01:02.383", "Id": "50798", "Score": "2", "body": "Both your `abstract` `class`es listed could be `interface`s. And the second one could be a custom `[Attribute]`." } ]
[ { "body": "<p>To build on @Jesse C. Slicer's comment above: interfaces are for defining contracts, whereas abstract classes are meant to add some base implementation code. An abstract class without any implementation code does not add anything an interface does not already provide. Even worse, it blocks inher...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T14:50:03.870", "Id": "31856", "Score": "2", "Tags": [ "c#", "interface" ], "Title": "Empty abstract class enforce structure" }
31856
<p>I am currently using the following to convert <code>[url=][/url]</code> to an <a href="http://en.wikipedia.org/wiki/HTML" rel="nofollow">HTML</a> link:</p> <pre><code>s = message.replace(/\[url=([^\]]+)\]\s*(.*?)\s*\[\/url\]/gi, "&lt;a href='$1'&gt;$2&lt;/a&gt;") </code></pre> <p>That work's fine.</p> <p>I then a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T16:04:24.547", "Id": "50791", "Score": "0", "body": "No full review, but perhaps a useful pointer: [Do NOT try parsing with regular expressions](http://kore-nordmann.de/blog/do_NOT_parse_using_regexp.html) and [Q: Best way to parse ...
[ { "body": "<p>Like <em>ojdo</em> has pointed out, using plain regexes to parse something like BBCode is too complicated of a route to take.</p>\n\n<p>It would be too long of a task to educate you on building proper parsers, but here's a short simplified example, of how one would go on parsing something like BBC...
{ "AcceptedAnswerId": "31862", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T15:42:40.723", "Id": "31859", "Score": "2", "Tags": [ "javascript", "regex" ], "Title": "JavaScript HTTP regular expression" }
31859
<p>So I really want to have something similar to <a href="http://msdn.microsoft.com/en-us/library/dd233226.aspx">discriminated unions</a> in C#.</p> <p>One way to do it is to use a visitor pattern, but it takes half a life to write all broilerplate code by hands. There is another way that would allow me writing a bit ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T20:56:44.440", "Id": "50826", "Score": "1", "body": "Options don't have a message, this is more like `Choice<T, string>`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T21:00:40.973", "Id": "5082...
[ { "body": "<p>This looks very well crafted. I don't know <a href=\"/questions/tagged/f%23\" class=\"post-tag\" title=\"show questions tagged &#39;f#&#39;\" rel=\"tag\">f#</a> and I'm not really into <em>functional programming</em>, but I can enumerate everything I like about this code:</p>\n\n<ul>\n<li>Type par...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T19:07:51.550", "Id": "31864", "Score": "8", "Tags": [ "c#", "f#" ], "Title": "Discriminated-unions in C#" }
31864
<p>So I'm implementing a linked list in Java, and so far it looks like this:</p> <pre><code>public class List &lt;T&gt; { private class Node { T value; Node next; } private Node node_at(int n) { Node seeker = front; for (int i = 0; i &lt; n; i++) { seeker = see...
[]
[ { "body": "<p>Yes, in theory. That depends on when the garbage collector decides to run. (There are lots of great explanations about <a href=\"https://stackoverflow.com/a/18297597/1435657\">how finicky it is</a> on Stack Overflow.) But it will become <em>eligible</em> for garbage collection and is gone for a...
{ "AcceptedAnswerId": "31876", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T20:02:17.127", "Id": "31868", "Score": "4", "Tags": [ "java", "linked-list", "garbage-collection" ], "Title": "Linked List in Java (Garbage Collection)" }
31868
<blockquote> <p>A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.</p> <p>Find the largest palindrome made from the product of two 3-digit numbers.</p> </blockquote> <p>How would you improve the following code?</p> <p>I'm lo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T01:16:49.767", "Id": "51050", "Score": "1", "body": "whenever a `product` or `combination` or `permutation` is mentioned, i'd check `itertools` first" } ]
[ { "body": "<p>It looks good to me.</p>\n\n<p>You could break from the inner loop even if x*y == max to avoid 1) an additional useless iteration 2) checking if it is a palindrome. Also it would remove some code testing the value of the product.</p>\n\n<p>I think you could change the limits of the inner loop to c...
{ "AcceptedAnswerId": "31872", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-26T21:23:09.750", "Id": "31869", "Score": "2", "Tags": [ "python", "optimization", "project-euler" ], "Title": "Project Euler #4 - Largest Palindrome Product" }
31869
<p>I have the following code (it looks long but it's not too bad):</p> <pre><code>function evaluate_cards(hand){ var hand_length = hand.length; var num_of_sets = 0; var num_of_runs = 0; var cards_in_run = 0; var suit = ''; var buckets = { three_bucket: [], four_bucket: [], ...
[]
[ { "body": "<p>Your sorting of cards to buckets takes a lot of code, which is because the names of your buckets don't match with the names of cards. The cards have just numeric values (10, 11), while buckets are named with words (ten_bucket, j_bucket). I would represent the cards as such:</p>\n\n<pre><code>{kind...
{ "AcceptedAnswerId": "31890", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T02:20:39.230", "Id": "31878", "Score": "3", "Tags": [ "javascript", "playing-cards" ], "Title": "JavaScript card game and hand evaluation" }
31878
<p>This is a class I implemented that can be thought of as a highly specialized version of <code>std::list&lt;&gt;</code> for pointers. It provides the additional feature that the elements can be removed in constant time with the element alone. This is accomplished with an <code>std::unordered_map&lt;&gt;</code> to ass...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T13:53:18.213", "Id": "51072", "Score": "0", "body": "Have you tried [Boost.MultiIndex](http://www.boost.org/doc/libs/1_54_0/libs/multi_index/doc/index.html)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-...
[ { "body": "<p>I think this problem screams out for Boost.MultiIndex. It allows to add multiple indices to a container. In your case, you seem to want both a <code>std::list&lt;T&gt;</code> and a <code>std::unordered_set</code> interface. In Boost.MultiIndex, these index types are called <code>sequenced</code> a...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T06:51:17.380", "Id": "31886", "Score": "3", "Tags": [ "c++", "c++11", "pointers" ], "Title": "list class for pointers with constant time item removal" }
31886
<p>I want to know how I can improve this piece of JS with respect to best practices/performance.</p> <p><strong>JS</strong></p> <pre><code>var treeGroupTypes, treeType, leftLeafClass, rightLeafClass; treeGroupTypes = ["tree-group-small", "tree-group-avg", "tree-group-large", "tree-group-large", "tree-group-avg", "tre...
[]
[ { "body": "<p>I am using color codes for clarity of my explanation, not suggesting you use them in the code.</p>\n\n<p><img src=\"https://i.stack.imgur.com/sdd25.png\" alt=\"trees\"></p>\n\n<p>As the image is static. Just use a set code.</p>\n\n<p>You have 5 tree heights:<br>\nred, green, yellow, blue (=oran...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T08:30:40.853", "Id": "31892", "Score": "3", "Tags": [ "javascript", "jquery", "html" ], "Title": "Drawing a picture of some trees using JavaScript" }
31892
<p>Just want to know if this is safe way to clone arrays and plain objects avoiding infinite loops trigger by circular refrences:</p> <pre><code>// !(( function ( methodName, dfn ) { // add global 'clone' method identifier this[methodName] = dfn(); } ).call( self, "clone", function () { var _api = { ...
[]
[ { "body": "<p><strong>What the tin says</strong></p>\n\n<p>Your code seems to track all cloned objects, so that it will find circular references, so it should be bullet proof indeed.</p>\n\n<p><strong>The goggles!</strong></p>\n\n<pre><code>!(( function ( methodName, dfn ) {\n // add global 'clone' method id...
{ "AcceptedAnswerId": "39696", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T11:00:20.857", "Id": "31898", "Score": "3", "Tags": [ "javascript" ], "Title": "Bulletproof way to clone Objects & Arrays handling circular references?" }
31898
<p>I’m planning on creating a Mortal Kombat-inspired game in JavaScript. I’ve written a basic game engine that manages my game states and creates a game loop.</p> <p>I just wondered if it could be improved at all? As I’m a web developer by trade and this is my first foray into programming games.</p> <pre><code>/** *...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T14:32:44.357", "Id": "50918", "Score": "2", "body": "It's a little hard to code review something this simple it doesn't actually do anything at this moment." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-0...
[ { "body": "<p>Just a general tip in regard to the comments...</p>\n\n<p>It's not recommended to use <code>/* */</code> comment blocks in your code. The reason for that is because in Javascript, that character pair can occur in regular expression literals as well. Comment blocks are therefore not safe for commen...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T12:15:44.703", "Id": "31901", "Score": "6", "Tags": [ "javascript" ], "Title": "Simple Game Engine in JavaScript" }
31901
<p>I have navigation items that are created dynamically with PHP. I wrote this because I need to add individual classes and fire them individually. My code works, but I want a way of refining it no matter how many items are added to the navigation via the backend. Is there a way of doing this so I don't have to add 20 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T16:43:51.620", "Id": "53709", "Score": "1", "body": "Hi, welcome to CR! If [this post](http://codereview.stackexchange.com/questions/33522/saas-hierarchy-what-should-i-do) is meant as a comment to the accepted answer here, and you d...
[ { "body": "<p>I think that all you are looking for is:</p>\n\n<pre><code>//assumes sidr is top level container for menu\n//you should consider adding a generic class to menu items when page is assembled\njQuery('#sidr &gt; ul &gt; li').click(function() {\n $this = jQuery(this);\n $this.find('ul').slideT...
{ "AcceptedAnswerId": "31904", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T14:32:13.040", "Id": "31902", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Calling individual classes for navigation items" }
31902
<p>Edit: <a href="https://codereview.stackexchange.com/questions/32073/parallel-job-consumer-using-tpl">A second iteration of this problem here.</a></p> <p>I need to provide a service (either a Windows Service or an Azure Worker Role) which will handle the parallel execution of jobs. These jobs could be anything from...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T15:16:45.520", "Id": "50925", "Score": "0", "body": "I wrote similar code polling a serial port and used the same looping methods you've used. Except I added a timeout error count, which would reset every time it connected successfu...
[ { "body": "<ol>\n<li><p>The way you're using <code>TaskScheduler.Current</code> to try to synchronize access to <code>Tasks</code> won't work (unless this code runs under a very specific custom <code>TaskScheduler</code>).</p>\n\n<p>With the default scheduler, a <code>Task</code> can be executed on any <code>Th...
{ "AcceptedAnswerId": "31912", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T15:04:06.660", "Id": "31903", "Score": "3", "Tags": [ "c#", "design-patterns", ".net" ], "Title": "Parallel Job Consumer" }
31903
<p>I had an exercise to create two methods for simple queue class, first to delete last element and second to delete element at k position. Particularly I'm not asking for better implementation. Is it good enough and elegant ? What I should change ? I'll post only mentioned methods, rest should be simple enough.</p> <...
[]
[ { "body": "<p>Well, your code is correct and mostly ok. Except for two things:</p>\n\n<ul>\n<li><p>You have 1-based indexing? Follow the <em>principle of least suprise</em>, and use zero-based indexing like all other data structures as well.</p></li>\n<li><p>Your variable names could be more obvious.</p>\n\n<ul...
{ "AcceptedAnswerId": "31908", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T15:59:24.590", "Id": "31906", "Score": "1", "Tags": [ "java", "queue" ], "Title": "Removing nodes from queue" }
31906
<p>I was making a relatively large-scale project in Python as a learning experiment, and in the process I found that it would be useful to have a map (or, in Python, I guess they're called dictionaries) where a value could have multiple keys. I couldn't find much support for this out there, so this is the implementati...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T20:28:43.680", "Id": "50954", "Score": "1", "body": "It's hard to answer if the structure is optimal, because there is no data how many values there are? How many keys per value? How many unique values? Are ranges usual or an except...
[ { "body": "<p>My attempt, keep in my mind that I'm not close to any of pro's around here.</p>\n\n<pre><code>for i in range(1, 101):\n if i &lt; 15:\n my_coins[i] = None\n if 15 &lt;= i &lt; 30:\n my_coins[i] = '1d6x1000 cp'\n if 30 &lt;= i &lt; 53:\n my_coins[i] = '1d8x100 sp'\n ...
{ "AcceptedAnswerId": "31943", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T16:53:08.803", "Id": "31907", "Score": "11", "Tags": [ "python", "python-3.x", "hash-map" ], "Title": "\"Multi-key\" dictionary" }
31907
<p>I'm using using twitter4j to fetch usernames that retweeted me. I'm interested in any feedback that make the code more elegant, and also that might reduce the number of calls I'm making to the Twitter API.</p> <pre><code>import java.util.ArrayList; import twitone.structure.BaseTwitterClass; import twitone.structure...
[]
[ { "body": "<p><strong>General Notes</strong></p>\n\n<ol>\n<li>Follow Java naming conventions. Class names should have <code>EachWordCapitalized</code>, and variable and method names should be <code>inCamelCase</code>. Also, class names should be nouns, and method names should be verbs.</li>\n<li>For collectio...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T18:23:04.190", "Id": "31910", "Score": "2", "Tags": [ "java", "twitter" ], "Title": "Using twitter4j to fetch usernames that retweeted me" }
31910
<p>I want you to pick my code apart and give me some feedback on how I could make it better or more simple. This code finds inorder successor in a binary tree.</p> <pre><code>public class Successor { private TreeNode root; private class TreeNode { TreeNode left; TreeNode right; TreeNo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T18:01:49.590", "Id": "53826", "Score": "1", "body": "I assume that this is Java, given your Username? I added the tag." } ]
[ { "body": "<ul>\n<li>Please give clear meaningful name. Your class name is <code>Successor</code>... now who's successor? yours? king Luthar's? who's? See the concern. I think <code>BinarySearchTree</code> is the apt. name for the class.</li>\n<li>In <code>makeBinarySearchTree</code> you are creating a Binary T...
{ "AcceptedAnswerId": "33617", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T18:49:03.033", "Id": "31911", "Score": "2", "Tags": [ "java", "tree" ], "Title": "Finding inorder successor" }
31911
<p>I want you to pick my code apart and give me some feedback on how I could make it better or more simple.</p> <pre><code>class TreeNode { private TreeNode left; private TreeNode right; private TreeNode parent; int item; public TreeNode (TreeNode left, TreeNode right, TreeNode parent, int item) {...
[]
[ { "body": "<p>Your <code>TreeNode</code> class is mostly allright. But you have to be careful when handling trees with parent pointers, or the tree could go out of sync, and deteriorate to a weird class. A <code>setParent</code> on its own is silly. The <code>setLeft</code> and <code>setRight</code> should also...
{ "AcceptedAnswerId": "31921", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T21:53:54.570", "Id": "31916", "Score": "7", "Tags": [ "java", "tree" ], "Title": "Create a tree from a list of nodes with parent pointers only" }
31916
<p>Do you have an idea to "transfer" this CSS Code to Javascript (maybe jQuery)?</p> <pre><code>html { background-color: #B94FC1; } html:before, html:after { content: ""; height: 100%; width: 100%; position: fixed; z-index: -6; } html:before { background-image: linear-gradient(to bottom, #5856D6 0%, #C644FC 100%); ani...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T22:55:41.130", "Id": "50960", "Score": "0", "body": "CAn you pls put your relevant code into the question" } ]
[ { "body": "<p>using jquery:</p>\n\n<p><strong>html</strong></p>\n\n<pre><code>&lt;div class=\"gradient one\"&gt;&lt;/div&gt;\n&lt;div class=\"gradient two\"&gt;&lt;/div&gt;\n</code></pre>\n\n<p><strong>css</strong></p>\n\n<pre><code>html { background-color: #B94FC1; } \nbody { margin:0; }\n.gradient { content: ...
{ "AcceptedAnswerId": "31920", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T22:22:54.943", "Id": "31917", "Score": "1", "Tags": [ "javascript", "jquery", "css" ], "Title": "CSS gradient transition_in javascript" }
31917
<p>Here's my first HTML5 game: a really simple snake. I've never made a game before and haven't had too much experience with JavaScript.</p> <p><a href="http://jsfiddle.net/NjdWv/1/" rel="noreferrer">Fiddle</a></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div ...
[]
[ { "body": "<p>It's pretty good for a first game. There are a few things I would change:</p>\n\n<p><strong>1. Dependencies</strong></p>\n\n<p>You use jQuery for two purposes in your code: <code>$(document).ready</code> to trigger the game setup, and <code>$(document).keydown</code> to catch the keyboard events....
{ "AcceptedAnswerId": "32039", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-27T22:36:35.977", "Id": "31919", "Score": "16", "Tags": [ "javascript", "jquery", "game", "html5", "snake-game" ], "Title": "First HTML5 game: Snake" }
31919
<p>I want you to pick my code apart and give me some feedback on how I could make it better or more simple.</p> <pre><code>public class MaxSumPath { private TreeNode root; private static class TreeNode { TreeNode left; TreeNode right; int item; TreeNode (TreeNode left, TreeNo...
[]
[ { "body": "<p>You should have a constructor <code>MaxSumPath(TreeNode root)</code>. Otherwise, there's no way for any other class to call the code.</p>\n\n<p>The <code>TreeNode(left, right, item)</code> constructor is awkward. Consider rearranging the <code>TreeNode</code> constructor arguments to <code>TreeN...
{ "AcceptedAnswerId": "31931", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T00:36:23.193", "Id": "31922", "Score": "3", "Tags": [ "java", "algorithm", "tree" ], "Title": "Print path (leaf to root) with max sum in a binary tree" }
31922
<p>As far as I know (and I don't claim to know much about this!), direct binding to <code>ListView.SelectedItems</code> isn't possible in WPF. I've seen work-arounds involving code-behind which I'm not too crazy about, especially since I'm having a hard time with getting a <code>DelegateCommand</code> to work, and deci...
[]
[ { "body": "<p>Your approach looks fine to me. Except i would probably use prefix-casting, to get cast exceptions straigt away if something goes wrong, instead of using <code>as</code>.</p>\n\n<p>This can be achieved without modifying code-behind tho. You can bind container's IsSelected property to appropriate i...
{ "AcceptedAnswerId": "32017", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T01:49:54.823", "Id": "31926", "Score": "4", "Tags": [ "c#", "wpf", "mvvm" ], "Title": "ListView MultiSelect, MVVM and RoutedCommands" }
31926
<pre><code>from string import punctuation, ascii_lowercase def is_palindrome(string): """Return True if string is a palindrome, ignoring whitespaces and punctuation. """ new = "" for char in string: lc = char.lower() for x in lc: if x in ascii_lowercase: ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T09:59:03.743", "Id": "51010", "Score": "0", "body": "What should `is_palindrome('èÈ')` be? I mean, you are considering only *ascii* letters, but should we remove from the string any non-ascii letter before the comparison or unicode ...
[ { "body": "<ul>\n<li>You are unnecessarily importing <code>punctuation</code></li>\n<li>Avoid reassigning module names such as <code>string</code> in your code</li>\n<li>A list comprehension would be a simpler way of filtering out the data you don't want</li>\n</ul>\n\n<hr>\n\n<pre><code>from string import asci...
{ "AcceptedAnswerId": "31929", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T02:57:46.253", "Id": "31928", "Score": "6", "Tags": [ "python", "strings", "palindrome" ], "Title": "is_palindrome function that ignores whitespace and punctuation" }
31928
<p>I'm building a text search system for a web application in PHP. I wrote this function that gets the sentences of the text which contains the keywords used by the user and also highlight them (well, surround them with any tags anyway).</p> <p>I'm measuring an average of 23ms if only the first matches is retrieved, a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T05:37:54.553", "Id": "51002", "Score": "0", "body": "Why complicate the wrapping so much? Can't you just use something like this? https://gist.github.com/elclanrs/6738783" }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T04:05:11.877", "Id": "31932", "Score": "2", "Tags": [ "php", "strings", "search" ], "Title": "How to increase concision and performance in a function to retrieve sentences where k...
31932
<p>I'm not a Javascript expert, so please review this function for me. Also, it could be that there is something in any of the library we're using in our project that can do something similar for me (angular, foundation, jquery, underscore), but I'm not too familiar yet with most of them.</p> <pre><code>// helper fun...
[]
[ { "body": "<p>I think it's a bit too much code. If you are already using a regular expression, why not using it to do all the parsing for you?</p>\n\n<pre><code>function parseNumeric(number) {\n var num = number.trim();\n var reOut = /^([-+]?(\\d+\\.?\\d*|\\d*\\.?\\d+))\\s*%?$/.exec(num);\n return reOu...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T07:29:30.677", "Id": "31934", "Score": "2", "Tags": [ "javascript", "parsing" ], "Title": "Function to parse floats optionally followed by %, more strict than parseFloat in javascript...
31934
<pre><code>var appname = " - simple notepad", textarea = document.getElementById("textarea"), untitled = "untitled.txt" + appname, filename = "*.txt", isModified; document.title = untitled; textarea.onpaste = textarea.onkeypress = function() { isModified = true; }; function confirmNav() { // Conf...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T07:55:55.007", "Id": "51004", "Score": "0", "body": "Do you have a question, or any specific part of your code you want looked at? Or just anything and everything?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": ...
[ { "body": "<p>You can optimize some queries.</p>\n\n<pre><code>var selected_file = document.getElementById(\"selected_file\")\n</code></pre>\n\n<p>Unless your HTML changes considerably (replacing nodes periodically), every call to getElementById() will return the same node. You can access the node more efficien...
{ "AcceptedAnswerId": "31942", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T07:36:31.037", "Id": "31935", "Score": "1", "Tags": [ "javascript" ], "Title": "Web-based text editor (#2)" }
31935
<p>I want you to give me some feedback on how I could make it better or simpler.</p> <pre><code>public class NonRecursiveTraversal { private TreeNode root; private static class TreeNode { TreeNode left; TreeNode right; int item; TreeNode (TreeNode left, TreeNode right, int it...
[]
[ { "body": "<p>I would not throw <code>NullPointerException</code>; it indicate that you are trying to use a variable which is null. Throw <code>IllegalArgumentException</code> instead; it indicated that arguments provided are not in a legal state.</p>\n\n<p>And I personally don't like nesting too much loops and...
{ "AcceptedAnswerId": "32121", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T07:51:10.937", "Id": "31936", "Score": "3", "Tags": [ "java", "algorithm", "tree" ], "Title": "Non-recursive tree traversal" }
31936
<p>I just wrote my first Java class, and I wanted to share it with you and maybe get some quick check from more experiences coders than I am.</p> <p>I want to learn OOP, and Java is just the tool I thought was the best to start with (it's very similar to C in syntax, which I'm used to, and it's spreading more and more...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T23:37:41.897", "Id": "51049", "Score": "3", "body": "From a security perspective, I hope you're not going to use Random for real passwords. It produces low-quality random numbers. You should use SecureRandom instead for actual app...
[ { "body": "<p>Your code does have its share of C-isms, but we will be able to fix that.</p>\n\n<p>But first, if you are learning Java in order to understand Object Oriented Programming, pick a better language. Java's OO primitives are classes, abstract classes, interfaces and single inheritance. Since Java was ...
{ "AcceptedAnswerId": "31941", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T08:40:42.417", "Id": "31937", "Score": "8", "Tags": [ "java", "object-oriented", "classes", "random" ], "Title": "Random password generator" }
31937
<p>Since the resources I found to learn are generally out-of-date, I'm having to read a lot of documentation, which makes the learning process somewhat haphazard. The module makes a simple character stack which can be read and written to by multiple processes.</p> <pre><code>#include&lt;linux/init.h&gt; #include&lt;li...
[]
[ { "body": "<p>So, this isn't a full answer to your question, but maybe still relevant.</p>\n\n<p>Included with the Linux sources is scripts/checkpatch.pl - which checks for things like coding style compliance, but also warns on use of outdated interfaces.</p>\n\n<p>If you have a checked out (clean) git reposito...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T09:56:17.340", "Id": "31938", "Score": "3", "Tags": [ "c", "linux", "kernel" ], "Title": "Simple Linux char driver" }
31938
<blockquote> <p>There is a char array of n length. The array can have elements only from any order of R, B, W. You need to sort the array so that order should R,B,W (i.e. all R will come first followed by B and then W).</p> <p>Constraints: Time complexity is O(n) and space complexity should be O(1).</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T18:03:36.837", "Id": "51025", "Score": "0", "body": "Does this work? Running it in my head with `\"WRB\"` gives `\"RWB\"`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T18:05:55.267", "Id": "510...
[ { "body": "<p>One quick improvement to your solution would be to use <code>switch(arr[i])</code> instead of the <code>if-else</code> chain.</p>\n\n<p>The only real problem I see <strike>beyond the complexity and non-obviousness of the algorithm</strike> is that it can end up doing a lot of unnecessary swaps<str...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T15:57:45.190", "Id": "31944", "Score": "6", "Tags": [ "java", "algorithm", "sorting" ], "Title": "A character array of arbitary length with 'R', 'B', 'W' is needed to be sorted in...
31944
<p>I need some feedback for this set of value-test functions (are they doing what they say they do). Also ways to improve some of them, suggestions to add more test functions, etc.</p> <pre><code>// Object.test.isnumeric('0x12') -&gt; true, etc. !(( function ( field, define ) { this[field] = define(); } ).call( O...
[]
[ { "body": "<p>Did you run this through a minifier and then prettified it again?</p>\n\n<p>Stuff like <code>(foo) &amp;&amp; (bar || (x = y()))</code> looks like google closure compiler and <strong>has no place in actual source code</strong>. It makes your code hard to read and letting closure compiler do this l...
{ "AcceptedAnswerId": "32033", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T17:30:10.960", "Id": "31946", "Score": "2", "Tags": [ "javascript" ], "Title": "Criticize my JavaScript value tester suite" }
31946
<p>Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple.</p> <pre><code>public class PrintAllPath { private TreeNode root; private class TreeNode { TreeNode left; int item; TreeNode right; TreeNode (TreeN...
[]
[ { "body": "<p>It looks good overall.</p>\n\n<p>I see you have taken my <a href=\"https://codereview.stackexchange.com/a/31931/9357\">previous suggestion</a> to rearrange the <code>TreeNode</code> constructor arguments. Now you have to readjust your calling convention accordingly.</p>\n\n<p>Your <code>create()<...
{ "AcceptedAnswerId": "31973", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T18:22:38.837", "Id": "31949", "Score": "2", "Tags": [ "java", "algorithm", "tree" ], "Title": "Print all path from root to leaves - code review request" }
31949
<p>I'm starting out and need feedback in order to discover the things I'm doing wrong.</p> <p>This is supposed to behave like <code>strcmp()</code>:</p> <pre><code>int compare(char *str1, char *str2) { while(*str1 || *str2) { if(*str1 != *str2) { break; } ++str1; ...
[]
[ { "body": "<p>You can skip the check for the end of one of the strings. If the other string ends before the one that you check the length for, the comparison of the characters will catch the difference:</p>\n\n<pre><code>int compare(char *str1, char *str2) {\n while (*str1 &amp;&amp; *str1 == *str2) {\n str...
{ "AcceptedAnswerId": "31954", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T21:12:03.397", "Id": "31953", "Score": "3", "Tags": [ "c", "strings", "reinventing-the-wheel", "comparative-review" ], "Title": "Function equivalent to strcmp()" }
31953
<p>I'm working my way through <em>The Java Programming Language, Fourth Edition - The Java Series</em>. This is Exercise 6.4:</p> <blockquote> <p>Expand your traffic light color enum from Exercise 6.1 on page 152 so that each enum constant has a suitable Color object that can be retrieved with getColor.</p> </block...
[]
[ { "body": "<p>Certainly, that seems adequate. You may want to make the <code>color</code> field <code>private</code>, though. Otherwise having a getter is pretty irrelevant. Also, I would make the field <code>final</code> so that the associated color can never be modified.</p>\n\n<p>Were you told to code you...
{ "AcceptedAnswerId": "31959", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T22:52:03.750", "Id": "31958", "Score": "3", "Tags": [ "java", "enum" ], "Title": "Critique of enum" }
31958