body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>My bootstrap file contained procedural code, but after stumbling upon <a href="https://codereview.stackexchange.com/a/7918/39625">this answer</a> I tried to make my bootstrap object oriented.</p> <p>This is my attempt so far, and I have a feeling that I'm failing at it. I also know that some parts are not really wo...
[]
[ { "body": "<p><code>configArray()</code> and <code>functions()</code> do the same thing, create just <code>includeDir()</code>.</p>\n\n<p>If files in configs directory create arrays, they are not global, so are discarded once out of scope.</p>\n\n<p>Redefine <code>config()</code> as <code>config(&amp;$config)</...
{ "AcceptedAnswerId": "53868", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T19:54:02.020", "Id": "52543", "Score": "5", "Tags": [ "php", "object-oriented" ], "Title": "Converting bootstrap file from procedural code to OOP" }
52543
<p>Mind the code below:</p> <pre><code>var deltaArray = function(a,b){ var deltaPtrs = []; var deltaVals = []; for (var i=0, l=a.length; i&lt;l; ++i) if (a[i] !== b[i]) deltaPtrs[deltaPtrs.length] = i, deltaVals[deltaVals.length] = b[i]; return [deltaPtrs,deltaVals]; }; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T21:06:43.160", "Id": "92121", "Score": "0", "body": "Do you realize that your `if` statement needs braces so that it encompasses both of the statements after it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>The simplest answer is to remove <code>deltaArray</code> and use <code>deltaHash</code> for everything. As long as your arrays don't have any extra properties, the results will be identical, except the keys are stored as strings instead of numbers.</p>\n\n<hr>\n\n<p>I'm not sure it's useful to sto...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T20:24:09.030", "Id": "52544", "Score": "4", "Tags": [ "javascript", "performance", "array", "hash-map" ], "Title": "Listing the differences between corresponding elements of t...
52544
<p>I'm looking to take my JS skills to the next level - please be harsh...</p> <pre><code>define(["serviceApp", 'appConfig', "services/vehicleService"], function (serviceApp, appConfig) { serviceApp.directive('vehicleSelector', [ '$compile', 'vehicleService', function ($compile, vehicleService) { ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T20:35:43.167", "Id": "52546", "Score": "1", "Tags": [ "javascript", "angular.js" ], "Title": "Angular.js directive for a vehicle model selector" }
52546
<p>There has got to be a better way to do this. I have a method which returns either your standard "01/01/2014" Date or "January 1st, 2014" Date of the assembly file write time. Any suggestions on streamlining would be much appreciated.</p> <pre><code>// Grab the last date of revision of the assembly file write time...
[]
[ { "body": "<p>I'll preface this with \"I'm just learning C# too and I might have gotten some of the syntax wrong, but the principals are sound.\"</p>\n\n<p>First, fix your indenting.</p>\n\n<pre><code>if (Root.ToString().Length - 1 != ('/'))\n {\nPath = Root.ToString() + \"\\\\bin\\\\\" + Title + \".dll\";\n...
{ "AcceptedAnswerId": "52554", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T21:00:34.413", "Id": "52547", "Score": "3", "Tags": [ "c#", "beginner", "strings", ".net", "datetime" ], "Title": "Beautifying Dates" }
52547
<p>I've been working a strategy game for iOS for a little while, and each time I add functionality to the game model I'm finding myself building a lot of UI code to sync up with it. I believe that my latest creation could use some code review.</p> <p>The basic idea is that each worker can have certain job permissions...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T22:50:19.523", "Id": "92139", "Score": "0", "body": "Forgive my ignorance, as I'm not completely familiar with SpriteKit, but can you not use stuff from UIKit within SpriteKit? And can you not build interfaces with SpriteKit using ...
[ { "body": "<p>First, I'll start by emphatically stating that this method is far too large and tries to accomplish far too much. When your method grows this large, it should definitely be tasked out into smaller methods and functions.</p>\n\n<p>It's okay to write a method or function even if it's only ever call...
{ "AcceptedAnswerId": "52562", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T22:11:35.307", "Id": "52552", "Score": "6", "Tags": [ "game", "objective-c", "ios", "user-interface", "sprite-kit" ], "Title": "User Interface for Strategy Game" }
52552
<p>I have a Java game development framework. Certain classes, such as <code>Texture</code>, need to be disposed as soon as you don't need them - we cannot depend on the Garbage Collector.</p> <p>For this, I have decided to enforce reference counting like Objective-C. You call <code>retain()</code> when you want to own...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T23:25:40.430", "Id": "92152", "Score": "0", "body": "There's two potential forces at play here, and I'm wondering which (or both) you are going after. In particular, there's deterministic release of resources (\"Ok, I'm done with th...
[ { "body": "<p>You should not be manually counting references. Instead, you should be letting the garbage collector do the reference management for you, and then hook in to the garbage collection framework when the reference is cleared in Java.</p>\n<p>The right tool for the job is <a href=\"http://docs.oracle.c...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T22:35:40.883", "Id": "52553", "Score": "6", "Tags": [ "java", "memory-management" ], "Title": "Java Manual-Reference-Counting" }
52553
<p>This code is based off the <code>Queue</code> implementation in Chapter 3 of <em><a href="http://www.crackingthecodinginterview.com/" rel="nofollow">Cracking The Coding Interview</a></em>. I modified the code to make it compile and give me the correct output. I'd appreciate any feedback on code style and correctness...
[]
[ { "body": "<p>You don't have a parameterless constructor which forces each queue to be instantiated with 2 elements. This isn't userfriendly since I might very wel want to construct it first and then add 5 bazillion elements to it.</p>\n\n<p>Your code already allows it though: technically <code>first</code> can...
{ "AcceptedAnswerId": "52557", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T23:03:29.907", "Id": "52556", "Score": "7", "Tags": [ "java", "interview-questions" ], "Title": "Implementing a queue in Java for a technical interview" }
52556
<p>This code is based off the Stack implementation in Chapter 3 of <em>Cracking The Coding Interview</em>. I modified the code to make it compile and give me the correct output. I'd appreciate any feedback on code style and correctness, assuming that I write this code in a technical interview.</p> <p>The pseudocode fr...
[]
[ { "body": "<p>A stack should not know about the first element. A stack only know about the last element that was pushed, so the <code>Stack</code> object itself should only have one <code>Node</code> called <code>last</code>. <s>Because of this, the constructor should be changed as well to only take one <code>N...
{ "AcceptedAnswerId": "52563", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T00:00:23.447", "Id": "52558", "Score": "16", "Tags": [ "java", "interview-questions", "linked-list", "stack" ], "Title": "Implementing a Stack in Java for a technical inter...
52558
<p>I've been experimenting with the Twitter Streaming API and would like some critical feedback. Specifically code correctness, code smells, overall structure, and my usage of collections and queues.</p> <p>The application leverages the Twitter Streaming API to identify the top trending hashtags for the supplied hasht...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-23T19:18:43.177", "Id": "116420", "Score": "0", "body": "It smells of race condition (I might be wrong) of `messageCount++;`. Just because it's volatile doesn't mean it wont be tried to be updated in two threads simultaneously; Espec...
[ { "body": "<p>This implementation looks better than the one in the original question. As I said in my previous answer, your design looks a bit too complex.</p>\n\n<p>I'd go for a more reactive, event based solution. I'd structure your client and your message processor in the following way.</p>\n\n<pre><code>int...
{ "AcceptedAnswerId": "63830", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T00:04:35.490", "Id": "52560", "Score": "10", "Tags": [ "java", "queue", "collections", "twitter", "guava" ], "Title": "Twitter Streaming Client - Round#2" }
52560
<p>This project was completed as part of an interview challenge.</p> <p>The feedback I received was:</p> <ol> <li><p>The code is neither optimized nor does it follow generally accepted paradigms, naming conventions or best practices </p></li> <li><p>There are a lot of nested loops and if/else clauses that could be si...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2019-09-04T09:18:21.050", "Id": "442771", "Score": "1", "body": "@TobySpeight I think this question is OK; it's just that the description is _hidden_ under the `cleaner` method. (I fixed the title)" } ]
[ { "body": "<p><strong>Making your code run</strong></p>\n\n<p>Here's the result of my first run :</p>\n\n<pre><code> File \"cleaner.py\", line 305\n likes)\n ^\nSyntaxError: invalid syntax\n</code></pre>\n\n<p>This is quite easy to fix : just comment this part of the line or put it with the part of ...
{ "AcceptedAnswerId": "52583", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-06-06T03:21:55.170", "Id": "52569", "Score": "2", "Tags": [ "python", "python-2.x", "interview-questions", "api" ], "Title": "Reading, cleaning and parsing CSV" }
52569
<p>This is the third rewrite of the poker bot I am writing. The first one was such a mess of <code>if</code> / <code>else</code>s that I could not deal with it. The second version was cluttered, and I had trouble following what happened but did work. I decided to scrap it for a new clean module based / more functional ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-12T16:29:26.670", "Id": "114548", "Score": "0", "body": "See this link regarding scrapping a project and completely rewriting the code: http://www.joelonsoftware.com/articles/fog0000000069.html Hint: it's called Things You Should Neve...
[ { "body": "<p>All of these Nested if Statements can definitely be changed into one level if statements</p>\n\n<blockquote>\n<pre><code>if (commandList.indexOf('lockChat') !== -1) {\n if (lockChat === true) {\n bot.lockChat(room)\n }\n}\nif (commandList.indexOf('unlockChat') !== -1) {\n if (unloc...
{ "AcceptedAnswerId": "62761", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T04:03:37.977", "Id": "52570", "Score": "4", "Tags": [ "javascript", "beginner", "game", "node.js" ], "Title": "Cleaning if / else mess in Node.js poker game" }
52570
<p>I have this code working, but I'm not sure if it's the best way to write it. I was watching a JS talk on Maintainable JavaScript, and saw that I probably shouldn't be comparing my element to null, and instead should use <code>typeof</code>. However, regardless what is returned, it's still an object.</p> <p>What my...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T13:05:40.353", "Id": "92246", "Score": "0", "body": "I imagine the `[25]` is just an example index, right? You're not hard-coding that in your site's code, are you?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>Stuff I noticed:</p>\n\n<p>You're missing a semi-colon:</p>\n\n<pre><code>var elementText = element.innerText\n</code></pre>\n\n<p>The <code>elementClass</code> variable could have a slightly more descriptive variable name. \"targetClass\" for instance, to indicate that this is the class we're goi...
{ "AcceptedAnswerId": "52639", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T04:07:08.297", "Id": "52571", "Score": "2", "Tags": [ "javascript", "tree", "dom", "null" ], "Title": "Alternative to null check after DOM traversal?" }
52571
<p>I was going through a code snippet... </p> <pre><code>try { ... // Memory is allocated here... NmsMessage* pNmsMessage = new NmsMessage(NMS_MODEM_DIAL_NUMBER); ... { // pNmsMessage is passed to another thread. pThis-&gt;m_pDeviceThread-&gt;PostThreadMessage(WM_NMS_MESSAGE, 0,pNms...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T10:22:41.633", "Id": "92213", "Score": "1", "body": "Why don't you want to use smart pointers? You may as well be using C at that point." } ]
[ { "body": "<p>I could see passing the pointer to another thread, and <em>the other thread</em> deleting the object. (Gives me the willies, but it at least makes sense.) But if <code>PostThreadMessage</code> <em>itself</em> is doing the deletion, that feels wrong. I'm used to having a <code>delete</code> for ...
{ "AcceptedAnswerId": "52578", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T04:46:46.410", "Id": "52575", "Score": "4", "Tags": [ "c++", "memory-management" ], "Title": "Allocating memory and releasing the same" }
52575
<p>My project has a change on the database, so that every INSERT-UPDATE-DELETE action is logged with triggers on the DB.</p> <p>For that they have an extra table created:</p> <p>Table <code>T_USER</code> is new and have a PK, a discriminator field and some other fields, Table <code>T_APP_USER</code> contains an PK wi...
[]
[ { "body": "<p>Your code looks good. I've visited this question multiple times and I couldn't find anything. Design-wise there might be improvements, but the implementation looks very good. The only thing I found was this.</p>\n\n<pre><code>/**\n * Equals written on account -ignoring the case and trimming-.\n *\...
{ "AcceptedAnswerId": "67786", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T05:28:48.373", "Id": "52577", "Score": "7", "Tags": [ "java", "hibernate", "jpa" ], "Title": "Intern AuditSystem in DB and getting users from it" }
52577
<p>Here's my inline-assembly functions, which is used my x86 32bit kernel.</p> <pre><code>static inline uint8_t ckPortInByte(uint16_t port) { uint8_t ret; __asm__ __volatile__ ( "in %1, %0" : "=a"(ret) : "d"(port) ); return ret; } static inline void ckPortOutByte(uint16_t port, uint8_t data) { __asm__...
[]
[ { "body": "<p>Your use of <code>volatile</code> appears to be correct, but I think you should do a couple of things for safety:</p>\n\n<ul>\n<li>Add a clobber constraint for the flags (AKA \"condition codes\") to <code>ckAsmSetEFlag</code>. I believe this is \"cc\" for x86 machines.</li>\n<li>Add clobber constr...
{ "AcceptedAnswerId": "52597", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T07:03:36.887", "Id": "52582", "Score": "2", "Tags": [ "c", "assembly" ], "Title": "Inline assembly correctness (especially __volatile__)" }
52582
<p>I have built a delete button in Android, just like in Windows, which removes the string on the right hand side of the cursor (one by one). (Instead of the mainstream <kbd>Backspace</kbd> which removes the left side.)</p> <p>Tell me if you have any better ideas.</p> <pre><code>package com.example.app; import andro...
[]
[ { "body": "<ol>\n<li><p>Name your variables and fields meaningfully. I have no idea what <code>a</code>,<code>b</code>,<code>e</code>, etc are. </p></li>\n<li><p>Don't split your variable declaration and initalization. Instead of</p>\n\n<blockquote>\n<pre><code>final EditText ed;\n\nButton dlt;\n\ndlt = (Butto...
{ "AcceptedAnswerId": "52608", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T07:20:50.457", "Id": "52585", "Score": "6", "Tags": [ "java", "android" ], "Title": "Delete (Reverse Backspace) Button" }
52585
<p>I am using <code>if</code> <code>else</code> statements:</p> <pre><code>public ActionResult Process(int? inventoryCheck, int? POCheck, int? PromotionCheck) { //var result = db.ValidInventory(2); //1. When inventory is low: if (inventoryCheck != null &amp;&amp; POCheck == null &amp;&amp; PromotionChec...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T07:48:12.370", "Id": "92181", "Score": "1", "body": "Could you also post your `db.ValidInventory()` method?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T07:54:18.383", "Id": "92183", "Score...
[ { "body": "<p>You should have to split your function absolutely. \nYou should have to group commons conditions statements and instructions.</p>\n\n<p>However, I think there are deeper problem in your architecture which cause this piece of code. You have to rethink your problem at higher level.</p>\n\n<p>For the...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T07:39:32.673", "Id": "52587", "Score": "6", "Tags": [ "c#", "optimization", "null" ], "Title": "Inventory check with too many else-ifs" }
52587
<p>In this Stored procedure (called by <a href="https://codereview.stackexchange.com/q/52587/9357">this inventory-checking function</a>), many if else if statement are used. How can it be improved?</p> <pre><code> IF ( @count = 1 ) (SELECT skumaster.sku AS SKU, ( skumaster.minimumstoc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T08:30:43.970", "Id": "92195", "Score": "0", "body": "The last case (`ELSE IF (@count = 7)`) seems incomplete." } ]
[ { "body": "<p>I see seven independent queries. There is no reason to put them all in one stored procedure that dispatches based on the <code>@count</code> parameter. (Furthermore, it shouldn't be named \"count\". \"Mode\" would be more appropriate.)</p>\n\n<p>Once you treat them as independent queries, there...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T07:52:03.380", "Id": "52590", "Score": "3", "Tags": [ "sql", "sql-server", "stored-procedure" ], "Title": "Stored Procedure with many If Else if statement" }
52590
<p>My subclass extends the <code>Formatter</code> class, I wonder know is there any elegant way, to rewrite my code</p> <h2>Parent</h2> <pre><code>class Formatter(object): def resp_in_hash(self, resp): ... return rtn_hash </code></pre> <h2>Child</h2> <pre><code>from formatter import Formatter # ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T08:47:38.737", "Id": "92199", "Score": "0", "body": "That looks like an inappropriate application of inheritance, but I can't really tell since you've posted so little code." } ]
[ { "body": "<p>Two ways to rewrite it:</p>\n\n<p>When you know which version of the method you want to call you can name it directly, but in that case need to pass self as an argument:</p>\n\n<pre><code> return Formatter.resp_in_hash(self, content)\n</code></pre>\n\n<p>Not necessarily more elegant.</p>\n\n<hr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T08:38:28.797", "Id": "52594", "Score": "0", "Tags": [ "python" ], "Title": "more elegant way when call parent method with the same name" }
52594
<p>I am a beginner and I have made Snowfall in HTML for my mom. I'm pretty sure it will not look that awesome to any developer out there, but hey, that's why I've posted it.</p> <p>I'd like a general review of this. I'm especially concerned about the quality and enhancements of this HTML.</p> <pre><code>&lt;h1&gt;Hap...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T09:44:13.683", "Id": "92207", "Score": "13", "body": "I hope your mom isn't using IE 5/6." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T09:46:28.990", "Id": "92208", "Score": "7", "body"...
[ { "body": "<p>Instead of retriggering <code>setTimeout()</code> on every call to <code>movesnow()</code>, I suggest calling <a href=\"https://stackoverflow.com/q/729921/1157100\"><code>setInterval()</code></a> just once for the entire program.</p>\n\n<p>You have some duplicated code between <code>initsnow()</co...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T09:39:00.427", "Id": "52599", "Score": "32", "Tags": [ "javascript", "beginner", "html", "animation" ], "Title": "Snowfall in HTML" }
52599
<p>I have a program that makes operations on strings and this is the principal function of one of those operations. This works perfectly, but it is not efficient:</p> <pre><code>private void printString(ArrayList&lt;String&gt; operations, ArrayList&lt;String&gt; set) { int numerOfStrings = 0; int numberOflett...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T11:07:01.290", "Id": "92218", "Score": "0", "body": "what if you search for `oo` should he also give position n?(your code do but I suspect that may not be the case). Also your use case says number of letters of **each** string. Sho...
[ { "body": "<p>Let me first do a review without getting into the logic of the method.\nBefore I start making changes I've commented some <em>smelly</em> places in your original code:</p>\n\n<pre><code>//Try to use the most generic type in your arguments. You don't really need an ArrayList&lt;&gt;\n//a List&lt;&g...
{ "AcceptedAnswerId": "52606", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T10:10:12.083", "Id": "52603", "Score": "7", "Tags": [ "java", "algorithm", "strings" ], "Title": "Operations on strings in Java" }
52603
<p>I've had a bit of help but I'm still a bit unsure. I have an nginx webserver with SSH only required. I wrote this rule set based on information I found on the internet:</p> <pre><code>i=/sbin/iptables # Flush all rules $i -F $i -X # Setup default filter policy $i -P INPUT DROP $i -P OUTPUT DROP $i -P FORWARD DROP...
[]
[ { "body": "<p>Scripts should have a shebang line. If you happen to be running in a shell other than 'sh' or compoatible, then this script will fail. Add:</p>\n\n<pre><code>#!/bin/sh\n</code></pre>\n\n<p>as the very first line.</p>\n\n<p>The rest of the script looks fine enough.</p>\n\n<p>The script has a duplic...
{ "AcceptedAnswerId": "52615", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T10:26:06.583", "Id": "52605", "Score": "2", "Tags": [ "security", "bash", "linux", "iptables" ], "Title": "IPtables for webserver with SSH" }
52605
<p>I am aware JavaScript does not have the concept of constant variables, which in traditional languages, you would usually define as being static/class related since there's no point in having them defined in each object instance.</p> <p>So we have to make do with defining regular vars in uppercase, and just treating...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T18:19:39.427", "Id": "92305", "Score": "0", "body": "JavaScript does support the `const` keyword which can help you create constant (variables), unless I'm missing something obvious here?" }, { "ContentLicense": "CC BY-SA 3....
[ { "body": "<p>You could a least separate the variables declarations into constants and variables:</p>\n\n<pre><code>var URL_KEY = 'CurrentURL';\n\nvar appName = 'MyApp',\n directoryName = 'MyAppDir';\n</code></pre>\n\n<p>You could alternatively make a function that returns the constant.</p>\n\n<pre><code>fun...
{ "AcceptedAnswerId": "52610", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T10:58:41.613", "Id": "52607", "Score": "4", "Tags": [ "javascript", "constants" ], "Title": "Defining constants in JavaScript" }
52607
<p>I tried to create the PHP-framework, with no experience in the task like this:</p> <h3>Folders:</h3> <pre><code>www/ |-- protected/ | |-- controllers/ | | |-- Site.php | | | |-- core/ | | |-- App.php | | |-- Controller.php | | |-- Criteria.php ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T11:25:37.780", "Id": "92223", "Score": "1", "body": "Are you deliberately reinventing a web framework? That sounds unconventional, especially if you are working alone or if other developers are much less experienced.." }, { ...
[ { "body": "<p>Alright... here it goes! I'll section each part by the headings you gave.</p>\n\n<hr>\n\n<h2>Folders</h2>\n\n<p>This all looks fine and dandy. I haven't seen any rules or anything to prevent the public from accessing <code>protected</code> though. Maybe I missed it, but it should be obvious this n...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T11:19:06.947", "Id": "52611", "Score": "10", "Tags": [ "php", "mvc", "reinventing-the-wheel" ], "Title": "PHP-framework with MVC architecture and Active Record pattern for the DB ...
52611
<p>Last time I asked a question here, it was for my select function. In that question, another user stated the way I did it, might not have been safe. So here I am with the entire class. </p> <p>The class I'm about to show you is going to be used for a client's Homepage. My main concern is the safety of the PDO Class;...
[]
[ { "body": "<p>There's a few changes I'd suggest to insert, firstly as the second parameter has to be an array, you can use type hinting to indicate this:</p>\n\n<pre><code>public function insert($table, array $fields)\n</code></pre>\n\n<p>You can also generate the <code>$values</code> without using a <code>fore...
{ "AcceptedAnswerId": "52641", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T13:33:40.717", "Id": "52619", "Score": "4", "Tags": [ "php", "security", "pdo" ], "Title": "Entire PDO DB Class" }
52619
<p>I'm looking to achieve a time format that looks like this: <strong>2d 4h</strong> remaining; or <strong>1h 36m</strong> remaining; or <strong>35s</strong> remaining, etc. So that it only displays the two largest values of time (this is how Clash of Clans and some other mobile games format wait times.)</p> <p>Curren...
[]
[ { "body": "<p>What you want to do, is use early-returns (FTW). Also, let the formatter do the string work for you. Right tool for the job.</p>\n\n<p>Consider your code, <a href=\"http://ideone.com/NhIbfL\">rewritten in Ideone...</a>:</p>\n\n<pre><code>static string FormatRushTime (TimeSpan span)\n{\n if ( sp...
{ "AcceptedAnswerId": "52627", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-06-06T14:22:23.110", "Id": "52622", "Score": "8", "Tags": [ "c#", ".net", "datetime", "formatting" ], "Title": "Format a timespan with up to two fields" }
52622
<p>I designed this CUDA kernel to compute a function on a 3D domain:</p> <p><code>p</code> and <code>Ap</code> are 3D vectors that are actually implemented as a single long array:</p> <pre><code>__global__ void update(P_REAL* data, P_REAL* tmp, P_REAL* f, P_REAL* reduced, const unsigned int sizeX,const unsign...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T15:34:17.287", "Id": "92276", "Score": "1", "body": "Ummm... shouldn't the __syncthreads() in the for-loop, be outside the for-loop?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T15:44:06.640", ...
[ { "body": "<ul>\n<li><p>The indentation within <code>update()</code> is misleading. Most of all, everything inside of the function should be indented. Otherwise, it'll be hard to tell what exactly is inside of the function.</p>\n\n<p>I do, however, like that you've indented the (lengthy) parameter list by eig...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T14:46:24.800", "Id": "52623", "Score": "8", "Tags": [ "c++", "performance", "computational-geometry", "cuda" ], "Title": "3D vector CUDA kernel" }
52623
<p>This is the task I was given after completing my program. I don't have a clue what procedures and functions are to be honest. Therefore I have no clue on how to break down my program into different elements of it.</p> <pre><code>#paint calculator RoomWidth = 0 RoomHeight = 0 RoomTotal = 0 RoomPaint = 0 RoomWid...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T15:17:15.807", "Id": "92272", "Score": "0", "body": "Welcome to Code Review! You are actually not asking a question here. You say some facts about what you need to do and how you don't know how to do it. I would recommend rethinking...
[ { "body": "<p>Functions are described in <a href=\"https://docs.python.org/2/tutorial/controlflow.html#defining-functions\" rel=\"nofollow noreferrer\">the Python tutorial</a> - they are separate blocks of code which take defined inputs (argument values) and provide defined outputs (<code>return</code> values),...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T15:01:31.090", "Id": "52626", "Score": "6", "Tags": [ "python", "python-3.x" ], "Title": "Paint cost calculator" }
52626
<p>I have separated my application into two pieces. The first piece is my core functionality project. The other piece is the UI of the application. The core functionality should communicate with web services and interact with my SQLite databases.</p> <p>In the core application I have four layers. These layers are:</p>...
[]
[ { "body": "<p>This looks pretty over-engineered, I'd tend to agree with the comment to your SO post.</p>\n\n<p>The most pressing issue I'm seeing with your code is this one:</p>\n\n<ul>\n<li>Why isn't <code>AlbumManager</code> a <code>static class</code> if it only exposes <code>static</code> members?</li>\n<li...
{ "AcceptedAnswerId": "52652", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T15:44:46.707", "Id": "52629", "Score": "2", "Tags": [ "c#", "design-patterns" ], "Title": "Should my service access layer communicate with my data layer?" }
52629
<p>I've written this function that concats strings:</p> <pre><code>public void find(ArrayList&lt;String&gt; operations, ArrayList&lt;String&gt; set) { String toMerge = operations.get(1); String fromMerge = operations.get(2); outer: for (int i = 0; i &lt; set.size(); i++) { String[] toSet = set.get(i).split(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T16:30:23.633", "Id": "92287", "Score": "1", "body": "Looks like you've been changing your code back and forth, and the two versions are significantly different. If you're actively improving your code, perhaps wait until you're sure ...
[ { "body": "<p>Here is what it looks like you're trying to do:</p>\n\n<ol>\n<li>loop through <code>set</code>, loop through each individual word in <code>set</code>, until you find <code>toMerge</code>.</li>\n<li>When you find that, you then restart the loop through <code>set</code>, and each word in <code>set</...
{ "AcceptedAnswerId": "52653", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T15:51:26.377", "Id": "52632", "Score": "0", "Tags": [ "java", "optimization", "algorithm", "strings" ], "Title": "Concat strings in Java" }
52632
<p>I'm looking to achieve a time format that looks like this: <strong>2d 4h</strong> remaining; or <strong>1h 36m</strong> remaining; or <strong>35s</strong> remaining, etc. So that it only displays the two largest values of time (this is how Clash of Clans and some other mobile games format wait times.)</p> <p>I woul...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-08-29T16:13:55.553", "Id": "390740", "Score": "0", "body": "It is curious code did not employ the [good answer's](https://codereview.stackexchange.com/a/52627/29485) use of `!=`, rather than `>`. Here code relies on the span being positi...
[ { "body": "<p>If your goal is to reduce returns, you could use a single <code>string.Format</code> call and not make use of additional arguments in certain cases:</p>\n\n<pre><code>// Changed removeZeroes to includeZeroes since it read kind of like a double negative.\nstring format = includeZeros ? \"{0:d}d {1:...
{ "AcceptedAnswerId": "52643", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T16:27:17.123", "Id": "52635", "Score": "7", "Tags": [ "c#", ".net" ], "Title": "Function for formatting a timespan with optional trailing zero" }
52635
<p>I wrote a dirty and ugly code to show in console how many bugs are left until the release of <a href="http://elementaryos.org/" rel="nofollow">elementary</a> codename <em>Isis</em>. The code works but it's pretty inefficient. What it does is:</p> <ol> <li>downloads the entire <a href="https://launchpad.net/elementa...
[]
[ { "body": "<p>To start off, I will say what I say on every question dealing with files: always use <code>with</code> syntax.</p>\n\n<p>By using this syntax you lessen the change for bugs; especially the bug that happens when you forget to call <code>close()</code> on an open file pointer. Your code shows this b...
{ "AcceptedAnswerId": "52644", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T16:57:49.967", "Id": "52637", "Score": "2", "Tags": [ "python", "optimization", "url" ], "Title": "Getting information from URL efficiently" }
52637
<p>I am new to JavaScript programming and would like to get your comments/input or corrections on this chunk of code. I have tried to emulate patterns from recognized GitHub projects but I still don't have good feel for what "good" NodeJS code looks like.</p> <p>I have written a very simple HTTP routing framework that...
[]
[ { "body": "<p>I don't know what <code>workFlow</code> and <code>urlglob</code> are. So there might be wways to improve it that I don't know about.</p>\n\n<p><code>_sync</code>, <code>_async</code> and <code>_merg</code> are so similar that you should probably combine them in some way, instead of maintaining 3 n...
{ "AcceptedAnswerId": "52717", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T18:34:01.970", "Id": "52649", "Score": "3", "Tags": [ "javascript", "node.js", "http" ], "Title": "HTTP routing framework" }
52649
<p>The following ActionScript code just downloads and attempts to parse some JSON from an API service. Inside the method I have defined a <code>cleanUp()</code> function, just to remove 2 event listeners.</p> <p>I think these event listeners will be garbage collected anyway though, so is it worth it? I would prefer to...
[]
[ { "body": "<p>Quick answer:</p>\n\n<p>Maybe yes, maybe no. Yes, they'll be garbage collected now, but cleaning up after yourself is not a bad habit to get into. <strong>It doesn't hurt to do so.</strong></p>\n\n<p>What you do need to be careful of, however, is that you clean it up right.</p>\n\n<p>Compare:</p>\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T18:38:47.027", "Id": "52651", "Score": "3", "Tags": [ "actionscript-3" ], "Title": "Do I need to remove these event listeners?" }
52651
<p>I'm playing with unit-testing in Ruby. There is a situation that I don't know if is good enough or if I am doing the wrong abstraction.</p> <p>I have two classes: <code>Transaction</code> and <code>Account</code>. An <code>Account</code> could have 0..* <code>Transaction</code>s. The only constraint is shall not ha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T20:57:52.370", "Id": "92329", "Score": "0", "body": "What don't you like about the solution? What makes you feel like there should be a better way?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T21:1...
[ { "body": "<p>My first thought based on your comment (behavioral and state testing in same test) was that you should just make two different tests.</p>\n\n<p>However, then I took a step back. The specification says that:</p>\n\n<blockquote>\n <p>add[ing] a duplicated transaction will fail</p>\n</blockquote>\n\...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T20:49:17.417", "Id": "52658", "Score": "2", "Tags": [ "ruby", "unit-testing", "rspec" ], "Title": "Unit-testing account transaction code" }
52658
SpriteKit is a framework for making 2D games that comes built-in to iOS 7. It has sprite support, support for special effects like videos, filters, and masking, an integrated physics library, and a lot more.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T22:24:14.547", "Id": "52665", "Score": "0", "Tags": null, "Title": null }
52665
<p>I'm using Groovy to grab properties from a page and each of the properties are grouped into a specific type:</p> <p>Groovy:</p> <pre><code>String headerImage = null String sidebarImage = null String footerImage = null String mainVideo = null String sidebarVideo = null String overviewVideo = null //Images headerI...
[]
[ { "body": "<p>I don't quite understand why you are using individual variables for the various items since all you are doing is outputting them as a group. It would be much cleaner to collect them into a collection. Perhaps something like this:</p>\n\n<pre><code>//Images\nList images = [\n properties[\"headerIm...
{ "AcceptedAnswerId": "53967", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T22:52:24.200", "Id": "52667", "Score": "0", "Tags": [ "jquery", "groovy", "jstl" ], "Title": "Restructuring multiple variables into an array" }
52667
<p>I'm writing C# code to read and eventually parse VB6/VBA code modules. I have an interface like this:</p> <pre><code>/// &lt;summary&gt; /// An abstraction that represents an object /// that can read a code file and return its content. /// &lt;/summary&gt; public interface ICodeFileReader { /// &lt;summary&gt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T00:38:28.397", "Id": "92351", "Score": "3", "body": "Please take the simpler route, for the sanity of future code maintainers." } ]
[ { "body": "<p>The <code>FileHeaderValidatorCodeFileReader</code> rules are arbitrary, and a potential failure point. Hard-coding the validation rules into a bunch of conditions isn't very maintenance-friendly.</p>\n<p>Create an abstraction to represent a validation rule:</p>\n<pre><code>public interface IValida...
{ "AcceptedAnswerId": "53848", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T23:02:27.003", "Id": "52668", "Score": "10", "Tags": [ "c#", "object-oriented", "design-patterns" ], "Title": "Decoration Freak, or OCP in action?" }
52668
<p>I have never written a unit test and I am really new to C#. I am attempting to test a method, am I testing for the right things here?</p> <p><strong>The Method</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Reflection; using Orlean.Propert...
[]
[ { "body": "<p>I will give a general overview of things you should change but definitely take a look at some of my answers related to unit testing I will put at the bottom.</p>\n\n<h1>Naming</h1>\n\n<p>I very much advise to use a naming scheme like <code>[UnitOfWorkName]_[ScenarioUnderTest]_[ExpectedBehaviour]</...
{ "AcceptedAnswerId": "52673", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T23:53:39.193", "Id": "52670", "Score": "5", "Tags": [ "c#", "beginner", ".net", "unit-testing" ], "Title": "Unit Testing an AppInfo class" }
52670
<p>Given an undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent vertices of the graph are colored with same color. Here coloring of a graph means assignment of colors to all vertices. </p> <blockquote> <p>Special request to verify complexity:</p> ...
[]
[ { "body": "<p>The most blatant error is running time analysis is wrong.\nRunning time is T(E,V,M) with E,V, M as you said above.</p>\n\n<p>Since you call compute() recursively, in the best case scenario the number of nodes being colored is at most 1, the size of the input will be reduced by at best one. Speakin...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T00:22:10.273", "Id": "52671", "Score": "2", "Tags": [ "java", "algorithm", "graph" ], "Title": "M coloring problem" }
52671
<p>I have been using the pattern below for some time and it has worked well, but more than once I have almost bled my brain out of my ear trying to keep track of:</p> <ul> <li>the recursion depth</li> <li>the recursion path</li> </ul> <p>I commented the line of the code where the information I would like to retain is...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T01:38:08.733", "Id": "92353", "Score": "0", "body": "This 'scan and queue' concept is used by a breadth-first-search, and it closely resembles what you are doing here. Hmmm ... a [youtube video](https://www.youtube.com/watch?v=QRq6p...
[ { "body": "<p>This review is only going to focus on style, since one of your specific questions has been answered and the other one you've already worked out (for what it's worth I'm not entirely sure those questions were on-topic here to begin with, but there's plenty to review anyway).</p>\n\n<hr>\n\n<p>Your ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T01:25:55.383", "Id": "52676", "Score": "2", "Tags": [ "javascript", "recursion", "node.js", "pathfinding" ], "Title": "Retaining depth information and recursive traversals" }
52676
<p>After finishing up finals, I wasn't really working on coding for a while. I decided to write a card game to get back into the programming scene. I'm just wondering if there's anything that I missed or could be improved upon.</p> <pre><code>import random suit_choices = ("Diamonds", "Hearts", "Clubs", "Spades") sui...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T05:26:18.160", "Id": "92374", "Score": "1", "body": "correct -> correctly" } ]
[ { "body": "<blockquote>\n<pre><code> continue\n</code></pre>\n</blockquote>\n\n<p>Both your continue statements fall back to the end of the loop anyway, so they are redundant.</p>\n\n<hr>\n\n<blockquote>\n<pre><code> user_number = input('\\nNow pick a number card (2-9) ')\n</code></pre>\n</blockquote>...
{ "AcceptedAnswerId": "52693", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T02:14:36.327", "Id": "52677", "Score": "4", "Tags": [ "python", "game", "python-2.x", "playing-cards" ], "Title": "Simple Card Game in Python" }
52677
<p>I was interested to know which words of the English language, when spelled backwards, are still valid words (e.g. "drawer", which when spelled backwards is "reward"), so I wrote a small program to go through a dictionary text file to search for them.</p> <p>I don't know if there's a word to describe them, but becau...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T10:00:23.023", "Id": "92388", "Score": "3", "body": "So you are looking for [semordnilap](http://en.wiktionary.org/wiki/semordnilap)s?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T10:33:14.673", ...
[ { "body": "<ul>\n<li><p>For your headers:</p>\n\n<blockquote>\n<pre><code>#include&lt;iostream&gt;\n#include&lt;fstream&gt;\n#include&lt;vector&gt;\n#include&lt;algorithm&gt;\n</code></pre>\n</blockquote>\n\n<p>As @Jerry Coffin has mentioned, it's a little more readable to have a space after an <code>#include</...
{ "AcceptedAnswerId": "52683", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T02:40:14.117", "Id": "52678", "Score": "11", "Tags": [ "c++", "strings", "c++11", "palindrome" ], "Title": "Searching for pseudo-palindromes (\"semordnilaps\")" }
52678
<p>I'm writing a node.js application that involves handling clients based on their ID without any real way of confirming that the ID a client says it has is its actual ID. That is, it's possible for a client to tell the server it has an ID of <code>foo</code> even though it was assigned an ID of <code>bar</code>, thus ...
[]
[ { "body": "<pre><code>rand = crypto.randomBytes(32).toString(\"base64\");\nid = hashFct(rand).substr(0, 8);\n</code></pre>\n\n<p>If those random bytes are random, passing them through a hash function adds nothing. If they are only somewhat random, hash + truncation is better than just truncation. However, <code...
{ "AcceptedAnswerId": "52695", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T05:53:56.440", "Id": "52685", "Score": "2", "Tags": [ "javascript", "node.js", "random", "cryptography", "server" ], "Title": "Ensuring client IDs are unique" }
52685
<p>I have used jQuery AJAX for my development. Below I have added example code for AJAX request and response. </p> <p>ajax.php</p> <pre><code>$queView = array(); $queView['time'] = 40; $queView['name'] = "Level hard"; $queView ['noQuestions'] = 10; $queView['queDetails'] .= "&lt;h1&gt;Some html content&lt;/h1&gt;"; ...
[]
[ { "body": "<p>If you're passing information, pass only information, not markup. Alternatively completely generate the HTML markup on the server-side, and just apply it on the client side. There's no point in combining the two, and if done wrong you could cause double escaping issues.</p>\n\n<p>Second, don't use...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T06:15:59.230", "Id": "52687", "Score": "1", "Tags": [ "php", "jquery", "ajax" ], "Title": "Display AJAX response from PHP" }
52687
<p>I made a fairly simple template engine (if I could call it that). Basically my server returns something like</p> <pre><code>string "This text should be [color:red;font-weight:bold; red and bold]" </code></pre> <p>Then on the client side I have my parser, for HTML in this case</p> <pre><code>function parse(str){ ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T12:30:52.993", "Id": "92395", "Score": "0", "body": "You should definitely check out handlebars (http://handlebarsjs.com/), KnockoutJS (http://knockoutjs.com/) or Angular (https://angularjs.org/) instead of rolling your own. If clie...
[ { "body": "<p>There are several advantages to writing proper HTML and using semantic tags. Instead of asking yourself \"How should this look?\" Ask yourself \"What does this mean?\".</p>\n\n<p>What does it mean for a text to be red? Does it mean <code>&lt;em&gt;</code>phasized text? Maybe <code>&lt;strong&gt;</...
{ "AcceptedAnswerId": "52697", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T12:24:24.523", "Id": "52694", "Score": "1", "Tags": [ "html" ], "Title": "Do HTML tags make a difference?" }
52694
<p>I'm trying to make a simple proxy server in Python using the socket library, mostly to understand how it works. I'm a noob both at programming and networking, so please be nice if my questions are totally dumb.</p> <p>At the moment I've set up a proxy server which intercepts requests from the browser, prints them ...
[]
[ { "body": "<p>You don't get real multithreading in CPython (see more <a href=\"https://softwareengineering.stackexchange.com/a/186909\">here</a>).</p>\n\n<p>In your case it is mostly IO operations, so you can get good multithreading by using green threads. Something that is provided by Tulip (included in Python...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T14:31:50.260", "Id": "52701", "Score": "7", "Tags": [ "python", "multithreading", "socket", "proxy" ], "Title": "Proxy using socket, doubts on multithreading and connection cl...
52701
<p>I want to write my own program to search for a word in a sorted text file. In the text file each word is in one line. I want to write this myself because I did not find any simple program (without libraries such as boost) which can provide suggestion word which means a word with most similarity. Here is my code but ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T16:26:05.963", "Id": "92414", "Score": "1", "body": "I don't think you can seek to some spot in the file and expect to be right before a new word, and not in the middle of one" }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>It looks like what you are trying to do is a binary search on your dict, but you have a number of flaws:</p>\n\n<ol>\n<li><p>Your code has compile warnings: <code>found</code> is set, but never used</p></li>\n<li><p>You are doing a binary search on the file, but not identifying the <em>word</em>, ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T14:48:16.677", "Id": "52702", "Score": "3", "Tags": [ "c++", "search", "file", "binary-search" ], "Title": "How to search for a word in a sorted text file efficiently?" }
52702
<p>I am willing to switch to OOP concept, but before working on that I would like to know whether what I have working so far is OK, or if any major change is required?</p> <p>For every form I create 3 files:</p> <ol> <li>for front end html</li> <li>a js file as a mediator between client and server</li> <li>a server s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T18:13:50.430", "Id": "92426", "Score": "0", "body": "OOPing this is a bit of a feat, if you'd like I can try to give you some pointers in chat (you need 20 reputation to access [chat])" } ]
[ { "body": "<h1>HTML</h1>\n\n<ul>\n<li>Lack of consistent naming conventions and code style. Sometimes you see <code>&lt;script src= \"js/drivers.js\"&gt;</code> and sometimes <code>id = 'drivers_name'</code>. Pick one, and stick with it. It makes your code that much more readable.</li>\n<li>Your <code>&lt;form...
{ "AcceptedAnswerId": "52709", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T15:03:57.493", "Id": "52703", "Score": "4", "Tags": [ "javascript", "php", "jquery" ], "Title": "Driver License Input Form" }
52703
<p>I have implemented a quite long program in R and I have noticed that one block, concearning a backward model selection, is too slow and I would like to receive some suggestions in order to speed up all the program. Here is the code:</p> <pre><code>library(MASS) df.Cars &lt;- na.omit(Cars93[-57, -c(1,2,4,6,27)]) row...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-25T08:00:00.317", "Id": "96662", "Score": "0", "body": "Have you looked at `step`? e.g. `M <- step(glm(Origin ~ ., \"binomial\", df.Cars), dir='backward')`. Although you might need to drop some of those predictors to achieve convergenc...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T15:31:58.613", "Id": "52704", "Score": "2", "Tags": [ "performance", "r" ], "Title": "Speed up my backward model selection" }
52704
<p>I would like to ask for code review for my project related to sorting and search C# lists with <code>IComparer</code> on objects. I expect some design tips and how to make code more effective.</p> <p><strong><code>Job</code> class:</strong></p> <pre><code>class Job { public string Title { get; set; } publi...
[]
[ { "body": "<p><strong>OrderBy over sort</strong></p>\n\n<p>You can save yourself a lot of code here by using LINQ's <code>OrderBy</code> and <code>OrderByDescending</code>. These allow you to use a lambda to pull out a part of the object to order by, and the default <code>IComparer</code> for the type returned ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T15:41:51.017", "Id": "52705", "Score": "5", "Tags": [ "c#", "object-oriented", ".net" ], "Title": "Sorting and search List with Icomparer" }
52705
<p>as I was reading the Git Internals in the Pro Git book, I decided to see what objects I need to create to have the short hash say something funny. To do this, I have written the following code:</p> <pre><code>messages = ['badcafe','deaddad','badbeef','feedbac'] possible_letters = string.ascii_lowercase + string.asc...
[]
[ { "body": "<p>That's a brute force search of hashes for a particular prefix, meaning it's complexity is \\$O(2^n)\\$, where \\$n\\$ is the number of bits in the prefix. In your case that's \\$2^{28}\\$.</p>\n\n<p>You can't make it faster in terms of complexity or the hash would be broken, but you can increase t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T17:28:36.733", "Id": "52710", "Score": "2", "Tags": [ "python", "git" ], "Title": "BadCafe as a git object short hash" }
52710
<p>I'm just trying to master the art of using classes in PHP and have come across a concern.</p> <p>For security reasons, I sometimes use two database connections in my application; one with read-only privileges and one with full read/write. Unfortunately, I wasn't really thinking about this when I started to build a ...
[]
[ { "body": "<p>You want two classes. They <code>extends Database</code>. <code>PublicDatabase</code> and <code>PrivateDatabase</code>, you instantiate whichever you need, and inject whichever you need. That way you can even have the same signature in the constructor in both types.</p>\n\n<p>If you don't have a p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T18:01:46.083", "Id": "52712", "Score": "3", "Tags": [ "php" ], "Title": "PHP database class - Managing two connections with different privileges" }
52712
<p>This code is about finding Pythagorean triplets. I take a number as input, and find from 1 to that number, how many Pythagorean triplets exist.</p> <p>Are there ways this can be optimized? It takes a lot of time, but actually doesn't only provide the output for <code>no</code> > 10000</p> <pre><code>import java.u...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T19:00:34.930", "Id": "92437", "Score": "0", "body": "ohk see the code is about finding pythagorean triplets,so i take a no as input,and find from 1 to that no,how many pythagorean triplets exist.I am uploading the code,now,pls see,i...
[ { "body": "<p>I will not start about optimatization but I'll do first a review so you could write better code and can post it again in a new question.<br/></p>\n\n<p>Take <a href=\"https://codereview.stackexchange.com/q/49048/35389\">a look at this code in the question</a>.<br/>\nThat question is a vey nice exa...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T18:36:39.210", "Id": "52716", "Score": "-1", "Tags": [ "java", "optimization", "mathematics" ], "Title": "Pythagorean triplets" }
52716
<p>Nothing more to add than the title. Looking for code review, optimizations and best practices. </p> <pre><code>public final class BaseAdder { private BaseAdder() { } /** * Given two numbers and their bases, adds the number * and returns the result in the same base. * * This code suppo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T01:59:18.653", "Id": "93524", "Score": "0", "body": "You have an extra `}` at the very end (assuming everything already matches up)." } ]
[ { "body": "<p>Looks pretty good to me. I just have a few non-functional comments to add:</p>\n\n<ul>\n<li><p>The <code>add</code> JavaDoc is incomplete, as you state the upper-limit of <code>base</code> but not the lower-limit. Surely someone might wonder what the sum of 0<sub>1</sub> and 00<sub>1</sub> is.</p>...
{ "AcceptedAnswerId": "53760", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T22:26:02.787", "Id": "52722", "Score": "2", "Tags": [ "java", "algorithm" ], "Title": "Base adder, given base and two numbers of that base, it adds them" }
52722
<p>I've been playing around with functional programming for a while now and just started learning Clojure. So the problem I'm trying to solve is the following:</p> <p>I have a tree-like hashmap of tasks where each task can include a number of tasks and each of those can include other tasks. The toy one I'm using for s...
[]
[ { "body": "<p>I think your choice of using a nested map/vector structure is a good one, and I think it is pretty idiomatic to Clojure. It can be tricky to work with nested structures like this, but it's certainly doable. </p>\n\n<p>Your <code>find-in</code> function (and the private functions it depend on) is a...
{ "AcceptedAnswerId": "53838", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T01:18:03.203", "Id": "52727", "Score": "1", "Tags": [ "optimization", "design-patterns", "functional-programming", "clojure" ], "Title": "Finding an entry in a Hashmap" }
52727
<p>I'm working on quite complicated scientific project.</p> <p>I decided to use a configuration file for model description. However it was quite complicated to parse all strings after <code>ConfigParser</code> and convert every option to required objects, so I would like to avoid this long/boring code.</p> <p>I wrote...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T22:23:16.747", "Id": "93506", "Score": "1", "body": "it might be helpful to provide an example of how you actually intend to use this programme for model description. There might be easier ways than using a config file." }, { ...
[ { "body": "<p>Firstly, some general style comments:</p>\n\n<ol>\n<li>Take a look at <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a>, the official Python style guide. This gives some really nice pointers on how to style your code. </li>\n<li><p>Avoid multiple statements per line...
{ "AcceptedAnswerId": "53795", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T02:02:25.567", "Id": "52729", "Score": "12", "Tags": [ "python", "parsing" ], "Title": "Configuration file with Python functionality" }
52729
<p>How can I remove duplicated code?</p> <p>It's hard to me because I use different service class and model each code.</p> <pre><code>public class AcrAccessAreaController extends BaseController { @Autowired private AcrAccessAreaService acrA...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T04:19:29.370", "Id": "92456", "Score": "1", "body": "Mind adding which framework this is for? Anything else about the functionality?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-07-20T15:06:40.733", ...
[ { "body": "<p>I will give you an idea. You need to have a dummy class with the functionality that you want. As you haven't provided much details I will make the assumption that the all models are sibiling classes. Same assumption for other things.</p>\n\n<p>After you have the dummy class you can just sub-class ...
{ "AcceptedAnswerId": "52733", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T03:15:52.567", "Id": "52731", "Score": "-1", "Tags": [ "java" ], "Title": "Refactoring duplicated code" }
52731
<p>The original code: <a href="https://codereview.stackexchange.com/questions/52492/refactoring-conditional-statements-among-different-classes">Refactoring conditional statements among different classes</a></p> <p>I am now doing it continually. I fixed a few part as mentioned.</p> <pre><code>public abstract class Ba...
[]
[ { "body": "<p>Have you heard about the term <code>programming for interface not implementation</code>? If not, then look it up. That is the reason why there should be a abstract class/interface. It makes the things like what I suggested in the <a href=\"https://codereview.stackexchange.com/questions/52731/refac...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T05:30:50.933", "Id": "52735", "Score": "3", "Tags": [ "java" ], "Title": "Refactoring switch case statement in different classes" }
52735
<p>In a Windows forms payroll application employing <code>MVP</code> pattern (for a small scale client) I'm planing user permission handling as follows (permission based) as basically its implementation should be less complicated and straightforward.</p> <p><strong>NOTE:</strong> System could be simultaneously used by...
[]
[ { "body": "<blockquote>\n <p>Full disclosure: I haven't done much with windows forms applications, so I may be breaking some otherwise well known winforms programming patterns.</p>\n</blockquote>\n\n<p>Permissions are better handled by a service, so that you can more easily unit test that layer, plus the permi...
{ "AcceptedAnswerId": "53829", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T05:55:43.393", "Id": "52736", "Score": "1", "Tags": [ "c#", ".net", "security", "winforms", "mvp" ], "Title": "Controlling permissions in a MVP application" }
52736
<p>After years of criticizing others, I've finally found the time and worked up the courage to polish up one of my bits of code and solicit criticisms of my own.</p> <p>This is a simple dynamic-string library that I wrote for <a href="https://github.com/nibroc/UptimeMonitor">one of my old C projects</a> (don't judge t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T13:55:40.080", "Id": "92495", "Score": "3", "body": "A small string optimization can use up to `sizeof(StringBuffer)-1` bytes of the structure itself (via a union). I think I got this trick from libc++: The first bit indicates wheth...
[ { "body": "<p>Overall, I think this is very well done. There is one major thing I find wrong with it though:</p>\n<h1><a href=\"http://brikis98.blogspot.com/2014/05/you-are-what-you-document.html\" rel=\"noreferrer\">Where is the documentation?!?!?!</a></h1>\n<p>Sure, as a developer using this library I could ...
{ "AcceptedAnswerId": "53748", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T06:07:04.447", "Id": "52737", "Score": "12", "Tags": [ "c", "strings", "memory-management", "reinventing-the-wheel", "library" ], "Title": "Bare-bones string library" }
52737
<p>I am using Backbone Marionette - I would like to set the user name and password if that passes the model validation method.</p> <p>I am highly confused with that. Please show me a handy approach or correct me if I'm doing this wrong.</p> <pre><code>define(["backbone"], function(Backbone){ var LoginModel = Bac...
[]
[ { "body": "<p>I'm not very familiar with Backbone, however I do have a couple of comments:</p>\n\n<ul>\n<li><p>To simplify your life, check out <a href=\"https://github.com/not-only-code/marionette-forms\" rel=\"nofollow\">Marionette Forms</a>. It can handle quick validation of forms. This is an alternative to ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T07:22:13.760", "Id": "52738", "Score": "3", "Tags": [ "javascript", "jquery", "validation", "authentication", "backbone.js" ], "Title": "Validating a model and focus to th...
52738
<p>I have been playing with a new JavaScript module pattern to see what I can come up with. I think it's quite powerful and wanted to know if it is something people would find useful?</p> <p>I'm looking for some advice on optimisation, or possible missing features. </p> <p>Quick Example:</p> <pre><code>var a = funct...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T00:00:56.117", "Id": "93509", "Score": "0", "body": "Thanks. If this question is not appropriate for this site i am happy to break it down to more manageable parts." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T08:25:56.153", "Id": "52741", "Score": "3", "Tags": [ "javascript", "design-patterns", "inheritance", "modules", "prototypal-class-design" ], "Title": "Implement.js JavaSc...
52741
<ul> <li>I am working on a Python/Django project which has turned into a JavaScript/jQuery project due to the amount of asynchronous functionality that I thought to add. </li> <li>There is a <a href="https://github.com/anshbansal/Bookmarker/blob/master/static/BookMarker/js/bookmarker.js" rel="nofollow noreferrer">JavaS...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T09:28:41.890", "Id": "92476", "Score": "0", "body": "What are the values of `EV_ADD_CATEGORY` and `EV_ENTER_KEY`? I see those constants used in some places, but - I suspect - not _all_ the places they ought to be." }, { "Con...
[ { "body": "<p>Structurally, it doesn't look too bad, although it seems inconsistent.</p>\n\n<p>By convention, JavaScript uses <code>camelCase</code> naming - not <code>snake_case</code>. All your code is <code>snake_case</code>, but then you have things like <code>keyCode</code> and <code>charCodeAt</code> beca...
{ "AcceptedAnswerId": "52746", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T08:52:32.327", "Id": "52742", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Adding, deleting elements as per autocomplete results - updated" }
52742
<p>I just wanted to get an opinion on my dynamic-programming Haskell implementation of the solution to <a href="http://projecteuler.net/problem=18" rel="nofollow">Project Euler problem 18</a>.</p> <p>The Problem:</p> <blockquote> <p>By starting at the top of the triangle below and moving to adjacent numbers on th...
[]
[ { "body": "\n\n<p>Your code is correct, fast, and I'd like to emphasize that you thoroughly include types for your functions, which greatly helps readability.</p>\n\n<p>While arrays offer fast performance, I'd say that in this case operations with indexes and bounds of the arrays cloud the main idea considerabl...
{ "AcceptedAnswerId": "54245", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T10:01:07.817", "Id": "52745", "Score": "4", "Tags": [ "haskell", "programming-challenge", "dynamic-programming" ], "Title": "Dynamic programming with Project Euler #18" }
52745
<p>I need <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#ulp%28double%29" rel="nofollow">the <code>ulp</code> method</a> in Codename ONE, and since it isn't available there, I tried to come up with my own version. The code is completely written from scratch, based solely on the documentation of t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T16:39:47.717", "Id": "92503", "Score": "1", "body": "Never edit the code in the question in response to an answer, as that invalidates the answer. Here are some [options for follow-ups](http://meta.codereview.stackexchange.com/q/176...
[ { "body": "<p>The code looks neat enough, well formatted, etc. That's great. There is one common issue you have in your code, and that is the else-if for early-return blocks.</p>\n\n<p>The code:</p>\n\n<pre><code>if (conditionA) {\n ... do something\n return something;\n} else if (conditionB) {\n ... d...
{ "AcceptedAnswerId": "52752", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T11:52:50.347", "Id": "52747", "Score": "2", "Tags": [ "java", "floating-point" ], "Title": "Implementation of `ulp` and `nextAfter` for platforms where these are missing" }
52747
<p>In a WinForms application I'm doing the password validation as follows:</p> <p>When the user presses the <kbd>OK</kbd> button after entering username and password, an event will be fired and the listener in the presenter will then do the validation with the help of the Encryption class. It will basically compare th...
[]
[ { "body": "<p>For the GetHash() function you could go with <a href=\"http://en.wikipedia.org/wiki/PBKDF2\" rel=\"nofollow\">PBKDF2</a>. It was specifically created to address password hashing. It requires at least 8 bytes of salt, so the code below builds a SHA1 hash to \"stretch\" your salt to that minimum len...
{ "AcceptedAnswerId": "53796", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T14:51:19.793", "Id": "52751", "Score": "2", "Tags": [ "c#", ".net", "cryptography", "validation", "mvp" ], "Title": "User name and password validation in a MVP applicat...
52751
<p>I am currently trying to make a Walmart Scraper, where I have to scrape the title, link, image URL, price, category and subcategory of the product.</p> <p>Now my approach is that I will collect seed pages for each department, like a link of USB drives from computer from electronics departments. Likewise that there ...
[]
[ { "body": "<p>Some things I noticed, though I have to say I'm still a novice as well ;-)</p>\n\n<p>Iterating over a list doesn't require you to iterate over a counter:</p>\n\n<pre><code>for i in range(0,len(urllist)):\nfor url in urllist:\n</code></pre>\n\n<p>Try to follow <a href=\"https://www.python.org/dev/p...
{ "AcceptedAnswerId": "73924", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T18:38:16.410", "Id": "53749", "Score": "5", "Tags": [ "python", "xml", "web-scraping", "beautifulsoup" ], "Title": "Walmart scraping (crawling) code" }
53749
<p>I am porting an application from django 1.4.5 to django 1.6.1. I found that <code>commit_on_success</code> has been deprecated. Moreover I found specific incompatibilities when calling <code>get_or_create</code> from inside <code>commit_on_success</code>.</p> <p><code>atomic</code> is often mentioned as drop-in rep...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-25T07:31:35.467", "Id": "116681", "Score": "0", "body": "Thank your for the tests! Can you license your code to something else than the default cc by-sa 3.0?" } ]
[ { "body": "<ol>\n<li><p>Yes, this clever code solves your problem : you won't be able to nest <code>commit_on_success</code> or <code>atomic</code> under <code>commit_on_success</code>. You already know the caveats, but I'll repeat them anyway:</p>\n\n<ul>\n<li>If you do nest a block under a <code>commit_on_suc...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T19:17:00.670", "Id": "53751", "Score": "13", "Tags": [ "python", "database", "django", "atomic" ], "Title": "Replacement for commit_on_success" }
53751
<p>I'm implementing the backtracking solving algorithm for a Sudoku in F#. I'm wondering if I could make my code better respect the functional programming paradigm or even just making it simpler/better.</p> <pre><code>let solve originalSudoku = let sudoku = Array2D.copy originalSudoku let isValidNumber (x,y)...
[]
[ { "body": "<p>The function <code>isValidNumber</code> can take advantage of sequence expressions to make the code more readable. It may also be more efficient, as it will short-circuit the evaluation.</p>\n\n<pre><code>let square =\n let squareX = (x / 3) * 3\n let squareY = (y / 3) * 3\n seq { for i i...
{ "AcceptedAnswerId": "54098", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T19:28:23.937", "Id": "53752", "Score": "4", "Tags": [ "functional-programming", "f#", "sudoku" ], "Title": "Making backtracking Sudoku solver more functional" }
53752
<p>This is a script (function) to be added to a bashrc. The purpose is to not actually remove files, but rather to send them to a trash folder for safe keeping. I was tired of deleting important files. Because files may have the same name, I chose to create subdirectories with the date and file name on them, for easy a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T21:00:32.317", "Id": "93498", "Score": "0", "body": "Does this work if the file name has spaces in it? I suspect it doesn't, since `$PREFIX/$PLACE/$FILE` is not quoted. Also, why do you use `${foo}` instead of just `$foo`?" }, {...
[ { "body": "<p>You should realize that this is not a drop-in replacement for <code>/bin/rm</code>. For example, this function won't handle options such as <code>-f</code> correctly.</p>\n\n<p>You double-quoted several variable expansions, but you must make it a religious habit to always double-quote <em>all</em>...
{ "AcceptedAnswerId": "60410", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T19:58:01.940", "Id": "53753", "Score": "7", "Tags": [ "bash", "file-system", "cli" ], "Title": "Trash Filing System" }
53753
<p>I have to read a line of strings and split it for whitespace:</p> <pre><code>ArrayList&lt;HashSet&lt;String&gt;&gt; setOfStrings = new ArrayList&lt;HashSet&lt;String&gt;&gt;(); while ((currentLine = bufferedReader.readLine()) != null) { String[] tokens = currentLine.split(" "); for (int i = 0; i &lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T00:04:37.167", "Id": "93511", "Score": "0", "body": "Why not a List for the tokens?" } ]
[ { "body": "<p>Is the use of a <code>Set</code> for storing the tokens deliberate? That's because you can only have unique elements in the <code>Set</code>, and the output of the following code snippet will be 1, not 2:</p>\n\n<pre><code>System.out.println( new HashSet&lt;&gt;( Arrays.asList( \"a a\".split( \" \...
{ "AcceptedAnswerId": "53762", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T23:01:13.360", "Id": "53757", "Score": "2", "Tags": [ "java", "optimization", "strings" ], "Title": "Read a line from console in Java" }
53757
<p>Inspired by <a href="https://codereview.stackexchange.com/questions/41198">Tool for creating CodeReview questions</a>.</p> <p>This script generates a markdown document suitable for a CR question from a list of files. For each file it finds, it sends the following to stdout:</p> <ul> <li>The relative path to the fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T00:01:46.457", "Id": "93510", "Score": "1", "body": "Now who will make a `.bat` version of this? :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T00:10:26.510", "Id": "93512", "Score": "0", ...
[ { "body": "<p>I note three potential problems with your approach, both dealing with special characters in filenames, as well as one comment on the example usage.</p>\n\n<h1><code>for</code> with <code>find</code></h1>\n\n<p>Consider a directory structure where some paths have spaces in them, say:</p>\n\n\n\n<p...
{ "AcceptedAnswerId": "53759", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T23:05:31.020", "Id": "53758", "Score": "4", "Tags": [ "formatting", "shell", "stackexchange", "sh" ], "Title": "Shell script for creating CR questions" }
53758
<p>I'm trying to iterate through all the combinations of pairs of positive <code>long</code> integers in Java and testing the sum of their cubes to discover if it's a Fibonacci number. I'm currently doing this by using the value of the outer loop variable as the inner loop's upper limit, with the effect being that the ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T03:39:34.767", "Id": "93539", "Score": "0", "body": "cache the powers. fill an array with the cubes from 1 to your limit. and don't recalculate them in the nested cycle." }, { "ContentLicense": "CC BY-SA 3.0", "CreationD...
[ { "body": "<p>I don't think your code will ever finish executing. Just looping from 1 to Long.MAX_VALUE (Convenient way to get long's max value) will take a stupid amount of time, even if you do no calculation:2^63 - 1 iterations, lets assume 1 billion per second. = 9223372036 seconds = 292 years. And thats wit...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T03:21:49.700", "Id": "53764", "Score": "2", "Tags": [ "java", "time-limit-exceeded", "fibonacci-sequence" ], "Title": "Testing whether sums of cubes are Fibonacci numbers" }
53764
<p>This code is very long, and you need a separate method. How can I implement it?</p> <p>I have 6 (x2) imageview buttons and 6 edittext.</p> <pre><code>public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.imageViewPlusSubEdit1: if...
[]
[ { "body": "<p>Step #1: create a function for the body of each case in your switch statement</p>\n\n<pre><code>public void onClick(View v) {\n // TODO Auto-generated method stub\n switch (v.getId())\n {\n case R.id.imageViewPlusSubEdit1:\n handleImageViewPlusSubEdit1();\n br...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T04:02:23.007", "Id": "53766", "Score": "1", "Tags": [ "java", "android" ], "Title": "Reducing imageview buttons code" }
53766
<p>I have developed a generic HTTP functionality using Android Asynctask and Apache HTTP client. Please review the code and let me know if it is the right way of doing or there are other ways to achieve it.</p> <p><strong><code>Async</code> class</strong></p> <pre><code>public class HTTPAsyncTask extends AsyncTask&lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T12:33:01.097", "Id": "95069", "Score": "0", "body": "Hi I wanted to reuse this code but it looks like it doesn't work. Because I am getting an empty result in the Callback onResult()." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Use a <strong>code formatter</strong>, one is probably included in your editor. [ctrl+shift+f] in eclipse</p>\n\n<p><strong>Avoid setting variables to null.</strong> This turns off warnings and errors and allows you to make mistakes otherwise not possible!</p>\n\n<p>Declare <strong>variables</stro...
{ "AcceptedAnswerId": "54573", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T04:13:58.907", "Id": "53768", "Score": "4", "Tags": [ "java", "android", "asynchronous", "http" ], "Title": "Generic HTTP using Android Asynctask" }
53768
<p>I have just begun to work with OOP and I am converting my current project into OOP classes. I have a few questions about this <code>User</code> class.</p> <pre><code>class User { private $db; public function __construct($db, $utilities) { $this-&gt;db = $db; $this-&gt;utilities = $utilities...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T12:28:33.870", "Id": "93578", "Score": "0", "body": "Welcome to Code Review! Unfortunately, this code doesn't seem to be ready for review because it does not appear to be finished. Code Review is for making *completed and working* c...
[ { "body": "<p>If a <code>User</code> object represents a single User, you would want one <code>User</code> instance per actual user you are working with in the application. For example, say your user might have friends:</p>\n\n<pre><code>class User {\n private $friends;\n\n public function addFriend(User ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T05:16:12.033", "Id": "53770", "Score": "0", "Tags": [ "php", "object-oriented", "pdo" ], "Title": "Is this the right way to write OOP PDO classes?" }
53770
<p>I have written a logic part in my app. I'd like to learn best practices, so can you please check my class?</p> <p>This class is a little too big in my opinion, but I have no idea what I should do now. I've pasted only the main class, but if you'd like to see anything related, please tell me.</p> <p>This class is m...
[]
[ { "body": "<p>Your constructor has mixed concerns:</p>\n\n<blockquote>\n<pre><code>public FeedDataSource(string databaseName,\n string feedsLinkSettingNameInRoamingSettings)\n{\n this._dbConnection = InitializeDatabase(databaseName);\n this._unitOfWork = new UnitOfWork(this._dbConnection);\n this._f...
{ "AcceptedAnswerId": "53786", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T05:32:13.813", "Id": "53771", "Score": "2", "Tags": [ "c#", "mvvm" ], "Title": "RSS reader and model (logic) layer in practise" }
53771
<p>I need your help in reviewing the following code. My main concern is dead-lock, but there might also be other issues.</p> <p>The <code>EventGenerator</code> object is owned by a single thread that running the <code>ThreadTask</code>. Other threads might access <code>EventGenerator</code> public APIs to set/remove ...
[]
[ { "body": "<p>From your concerns:</p>\n\n<ol>\n<li><code>EventGenerator::{Add,Remove}Handler</code> should be safe to call from <code>EventDelegate::Invoke</code>, though any updates won't be reflected in the current loop iteration in <code>ThreadTask</code>.</li>\n<li>Your shared_ptrs are pointing to the same ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T08:34:22.280", "Id": "53776", "Score": "1", "Tags": [ "c++", "multithreading", "c++11" ], "Title": "Thread-safe callback registration and invocation in C++11" }
53776
<p>I've read a lot of stuff about mixins, inheritance and such, and in the end I came up with this solution for extending a class with multiple mixins. I haven't seen this anywhere else...</p> <pre><code>var Classes = {}; // I keep all classes inside this objects, so I can do new Classes[obj_name](); Classes.asA = fun...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T09:30:41.753", "Id": "93572", "Score": "1", "body": "Seems like it requires a lot of repetition in the constructor of the object and I think lines like Classes.asA.call(Classes.Obj.prototype); would be a bit confusing to see inside ...
[ { "body": "<p>The main things is that your system is much more verbose and harder to understand than simply hard-coding all the calls to superclass methods:</p>\n\n<pre><code>function A(a) {\n this.a = a;\n}\nA.prototype = {\n methodA: function () {\n console.log(\"a: \"+this.a);\n }\n};\n\nfunc...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T09:08:13.830", "Id": "53777", "Score": "0", "Tags": [ "javascript", "extension-methods", "mixins" ], "Title": "JavaScript mixins - extending and super methods" }
53777
<p>I wrote a basic binary tree in JS. Can anyone give me some feedback about my code?</p> <p>I just want to know if this is the right approach, and how I can improve the tree. I am new to JavaScript and data structures. </p> <pre><code>function bst() { this.root = null; } bst.prototype.insert = function( obj ){ ...
[]
[ { "body": "<p>I can see two obvious points:</p>\n\n<ul>\n<li>Constructor names are usually capitalized, to indicate that they should be invoked with <code>new</code></li>\n<li>You've got some code duplication between <code>bst::insert</code> and <code>node::insert</code>. This even leads to the bug that you don...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-08T16:16:28.763", "Id": "53782", "Score": "2", "Tags": [ "javascript", "beginner", "tree" ], "Title": "Basic binary Tree in JavaScript" }
53782
<p>I have to read a <code>String</code> from console, so I used the <code>tokenizer</code> to split it and add each token in a position on <code>arrayList</code>, is there a way to improve the operation of split?</p> <pre><code>while ((currentLine = bufferedReader.readLine()) != null ) { StringTokenizer st...
[]
[ { "body": "<p>This is probably not your bottleneck, but you could achieve the same result by:</p>\n<ul>\n<li>ditching the <code>StringTokenizer</code> in favour of <code>String.split()</code></li>\n<li>replacing the <code>while</code> loop with a call to <code>Collections.addAll(T...)</code></li>\n</ul>\n<p>Lik...
{ "AcceptedAnswerId": "53792", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T13:30:49.260", "Id": "53784", "Score": "2", "Tags": [ "java", "optimization" ], "Title": "Optimize the split of a String from console" }
53784
<pre><code>public class RunnableThreadPrimeNumber implements Runnable { private long startNum; private long endNum; private Thread t; RunnableThreadPrimeNumber(long start , long end ) { t = new Thread(this); this.startNum = start; this.endNum = end; t.start(); } public v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-08-05T03:35:22.917", "Id": "181589", "Score": "0", "body": "1/ yes. see about memoization, and go until sqrt(n), not n/2 2/ you are not using `counter` for anything else. replace `counter ++` by `return true` altogether. if you reach the ...
[ { "body": "<p>The algorithm will be a lot faster, if you write the loop as <code>for (int i = 3 ; i*i &lt;= n ; i += 2)</code> and you <code>return false</code> from inside the loop as soon as you know the number is not a prime. Then you don't need the <code>counter</code> variable. If you get to the point afte...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T13:43:03.430", "Id": "53785", "Score": "2", "Tags": [ "java", "optimization", "performance", "algorithm", "primes" ], "Title": "isPrime Number Algorithm" }
53785
<p>I want to simplify an <code>if: .. else: ..</code> construct:</p> <pre><code>def find_eulerian_tour(graph): available_edges, path = initial_state(graph) while incomplete(available_edges): edge = propose_extension_edge(available_edges, path) if extension_is_possible(edge): extend_...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-10T23:53:56.683", "Id": "93902", "Score": "1", "body": "I rarely use python. I do a course on algorithms with exercises in python. And I see this as chance to improve the readability of my python code by the way." } ]
[ { "body": "<pre><code>def find_eulerian_tour(graph):\n available_edges, path = initial_state(graph)\n while incomplete(available_edges):\n edge = propose_extension_edge(available_edges, path)\n if extension_is_possible(edge):\n extend_path(available_edges, path, edge)\n els...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T14:04:16.297", "Id": "53787", "Score": "4", "Tags": [ "python", "optimization", "graph" ], "Title": "Simplify an if else construct with assignment before if and else" }
53787
<p>I wrote a script that does the following:</p> <ol> <li>Run another script on the system</li> <li>Filter the output to find lines that contain ALL of the given patterns</li> <li>Pipe the output to a second script on the system</li> </ol> <p>I feel like the way I did it is a dirty hack. I use a control character to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-03-11T17:36:19.847", "Id": "228401", "Score": "0", "body": "A little late here, but did you consider `firstScript | fgrep -f searchTargFile | secondScript`. `fgrep -f searchTargFile inFile` searchs for string matches. I think more modern ...
[ { "body": "<p>Have you tried something simpler? I know that chaining greps together is not hugely scalable, but, it should accommodate as much as your commandline can. Including single-quotes as commandline expressions may be a problem though.</p>\n\n<pre><code>#!/bin/bash\n\nsource=\"/path/to/script1\"\ntarget...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T14:22:44.653", "Id": "53790", "Score": "4", "Tags": [ "bash", "awk" ], "Title": "Filter shell script to find lines that contain all specified patterns" }
53790
<p>I've previously posted a version of this code here:</p> <p><a href="https://codereview.stackexchange.com/questions/52511/ms-access-vba-code-to-compare-records-in-a-table-and-combine-data-where-necessar/52540#52540">MS Access VBA code to compare records in a table and combine data where necessary</a></p> <p>To repe...
[]
[ { "body": "<p>This is a huge improvement over the last version. I'll try to give you some pointers on how to improve this farther, but I am also going to tell you this. Your database is very poorly designed (if not downright broken) and nothing we do here will fix that. If you were using proper keys on your dat...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T14:40:04.043", "Id": "53793", "Score": "5", "Tags": [ "sql", "vba", "ms-access" ], "Title": "MS Access VBA code to compare records in a table and combine data - revised" }
53793
<p>I am attempting to break down a Rebol View into a Forth style 'divide and conquer' word set, to optimize readability and organization, and to segregate the business logic from the view layout inner workings.</p> <p><strong>Business intelligence</strong></p> <p>Field</p> <ul> <li>declaration</li> <li>initializatio...
[]
[ { "body": "\n\n<h3>Try to avoid mixed casing in new dialect designs</h3>\n\n<p>Rebol preserves the case of characters when they match the lexical rules to become a symbolic type in the <a href=\"http://en.wikipedia.org/wiki/Homoiconicity\">homoiconic</a> structure being produced:</p>\n\n<pre class=\"lang-none p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T14:44:27.320", "Id": "53794", "Score": "8", "Tags": [ "rebol" ], "Title": "Rebol View layout compose, seek minima notation" }
53794
<p>How can I improve this code with nested null check statements?</p> <pre><code>public class AcrCategoryService extends BaseActionService&lt;AcrCategoryModel&gt; { @SuppressWarnings({ "rawtypes", "unchecked" }) public Map getCategoryList(String categoryCd, String categoryNm, String rgstTrgt) throws Exception...
[]
[ { "body": "<p>Use rawtypes is even worse than null check!</p>\n\n<p>Your</p>\n\n<pre><code>Map model = new HashMap();\n</code></pre>\n\n<p>should be</p>\n\n<pre><code>Map&lt;String, List&lt;AcrCategoryModel&gt;&gt; model = new HashMap&lt;String, List&lt;AcrCategoryModel&gt;&gt;();\n</code></pre>\n\n<p>or if yo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T15:05:52.437", "Id": "53799", "Score": "3", "Tags": [ "java", "null" ], "Title": "Duplication with nested null checks" }
53799
<p>As part of a project I'm working on, I've implemented a class that encapsulates the syntax for a <a href="/questions/tagged/vb6" class="post-tag" title="show questions tagged &#39;vb6&#39;" rel="tag">vb6</a>/<a href="/questions/tagged/vba" class="post-tag" title="show questions tagged &#39;vba&#39;" rel="tag">vba</a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T16:43:35.200", "Id": "93622", "Score": "0", "body": "Just realized, [I had the wrong definition for both parser and lexer](http://stackoverflow.com/a/3614928/1188513)..." } ]
[ { "body": "<p>Finally, a question where we can use Roslyn!</p>\n\n<p>I won't review your own code but instead I whipped up this small showcase of how you might do it with the Roslyn compilers. Do note that it is rather ugly, not in the least because I am not entirely comfortable with it myself yet but also beca...
{ "AcceptedAnswerId": "54629", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T15:16:48.243", "Id": "53800", "Score": "7", "Tags": [ "c#", "parsing", "regex", "dependency-injection", "meta-programming" ], "Title": "VB6/VBA Declaration (Dim) Syntax...
53800
<p>The following method is used in a call center application to display an approximation of remaining time. The call center telephone operator would inform the caller that they could perform their desired action (like, for example, place another order) after <em>N</em> time has elapsed. You'll note some <em>arbitrary</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T18:35:44.337", "Id": "93645", "Score": "0", "body": "you should post a new question with the updated code. and Jamal changed the code in his answer, you should check it out." }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>Depending on how you are calling this piece of code, this if statement will almost never be evaluated as true. </p>\n\n<pre><code>if (interval == TimeSpan.Zero)\n{\n return \"now\";\n}\n</code></pre>\n\n<p>I don't think it is worth the time to type this out, it should be grouped into the else ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T16:22:23.087", "Id": "53803", "Score": "5", "Tags": [ "c#", "strings", "datetime", "converting" ], "Title": "Displaying TimeSpan as largest interval (with units)" }
53803
<pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;GPS Tracker&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css"&gt; &lt;link rel="stylesheet" type="text/css" href="view/style.css"&gt; &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=fa...
[]
[ { "body": "<p>You need 3 php files. One to render the map and fire a javascript function which returns the second php page containing the map data.</p>\n\n<p>Another javascript function runs every few seconds and compares a checksum of the map data against a checksum of a fresh database query returned by the th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T07:50:22.883", "Id": "53804", "Score": "0", "Tags": [ "javascript", "php", "mysql", "geospatial", "google-maps" ], "Title": "Refreshing Google map until new data has been ...
53804
<p>I'm looking for a code review for my JavaScript code that checks if there is any memory leaks in data structures. Please include constructive criticism, as well as details on what I can do to make this code more efficient.</p> <pre><code>// memoryleak.js // (C) 2014 Kyle Maune // checks for memory leaks in data str...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T17:11:54.083", "Id": "93627", "Score": "1", "body": "I don't understand how this works. Do you have an example program that triggers a memory leak warning?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06...
[ { "body": "<p>This code</p>\n\n<blockquote>\n<pre><code>if ((self._isArray(obj) || self._isObject(obj))) {\n if (self._isArray(obj)) {\n self._logTooBig(obj, obj.length)\n for (var i = 0; i &lt; obj.length; i++) {\n self._checkIfNeeded(obj[i])\n }\n }\n else if (self._isObject(obj)) {\n self...
{ "AcceptedAnswerId": "53818", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T16:33:20.390", "Id": "53809", "Score": "3", "Tags": [ "javascript", "memory-management" ], "Title": "Checking for memory leaks in data structures" }
53809
<p>Can you give me some idea how to optimize the <code>switch</code> statements, maybe a <code>for</code> or <code>do while</code> loop? Which is faster, <code>switch</code> or <code>for</code>/<code>while</code> loop?</p> <pre><code>public class CalculateTheValueOfE { static long start1 = System.currentTimeMilli...
[]
[ { "body": "<p>Your I/O is eccentric.</p>\n\n<p><code>args[0]</code>, <code>args[2]</code>, and <code>args[4]</code> are ignored. <code>args[5]</code> is also required, but the program never does anything with it.</p>\n\n<p>Code in <code>main()</code> should be kept to a minimum — just enough to process the arg...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T18:55:56.330", "Id": "53821", "Score": "6", "Tags": [ "java", "performance", "multithreading", "mathematics" ], "Title": "Calculation of e performance issue" }
53821
<p>My question is: Using C# and/or Linq, how can this existing code be improved to be more efficient? (My "Complex" example takes about 5 seconds to run, how to make it faster?)</p> <p>What the code is actually doing: I want to get all unique combinations from choosing 1 number from each group of numbers. </p> <p>Ho...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-10T04:20:04.400", "Id": "93704", "Score": "0", "body": "Use a `HashSet<List<int>>` instead of a list of lists; that makes adding and checking for a match much much faster." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>Use a cross join with LINQ to combine the lists of numbers and filter them.</p>\n\n<p>You don't want a list, you want a <a href=\"https://en.wikipedia.org/wiki/Multiset\" rel=\"nofollow\">Multiset</a>, best implemented as a <code>Dictionary&lt;int,int&gt;</code>.</p>\n\n<p>Use a helper class to pr...
{ "AcceptedAnswerId": "53912", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T19:17:12.353", "Id": "53822", "Score": "5", "Tags": [ "c#", "performance", "linq" ], "Title": "Efficient way to get every unique combination of \"Pick 1 number from each Group ...
53822
<p><sub>[This is a follow-up question to: <a href="https://codereview.stackexchange.com/questions/53803/">Displaying TimeSpan as largest interval (with units)</a>. The code listed here has been refactored since the original question was posed. Please note that the scope of this question is limited to the declaration an...
[]
[ { "body": "<p>Your code is looking good, but I find the control flow in this version a bit easier to follow:</p>\n\n<pre><code>// Defined per business rules.\nprivate static readonly TimeSpan MinimumIntervalDeemedOneDay = TimeSpan.FromHours(22);\nprivate static readonly TimeSpan MinimumIntervalDeemedOneHour = T...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T19:21:11.963", "Id": "53824", "Score": "3", "Tags": [ "c#", "strings", "datetime", "converting" ], "Title": "Displaying TimeSpan as largest interval (with units) - Part II" }
53824
<p>After playing around with Java 8 and Generics for some time, I came across an idea while reading some posts about Apple's new programming language Swift.</p> <p>Swift has AOP-like methods for properties (<code>willSet</code> and <code>didSet</code>) and I thought of creating something similar in Java with the help ...
[]
[ { "body": "<p>My first thought is: Interesting.</p>\n\n<h3>The <code>Property&lt;T&gt;</code> class as it is right now</h3>\n\n<p>First, some feature-requests or changes you can consider:</p>\n\n<ul>\n<li>You could combine <code>beforeSet</code> and <code>onSet</code> into a <code>BiFunction&lt;T, T, T&gt;</cod...
{ "AcceptedAnswerId": "53837", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T19:25:42.463", "Id": "53826", "Score": "5", "Tags": [ "java", "generics", "java-8" ], "Title": "Generic property with AOP-functionality in Java" }
53826
<p>I am trying to learn kTurtle (slightly different from Logo) so that I can help my daughter learn to write code. I have decided that I would write a program that would play Tic-Tac-Toe with a user. So far, all I have is the <code>Game</code> board, and I make it more than just a single board to add to the intensity...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-12T13:58:43.130", "Id": "94156", "Score": "1", "body": "Not worth an answer yet but : `$TwoThirdsX` does not seem to be used, your code could probably be easier to understand with more comments and more meaningful variables names. Also...
[ { "body": "<p>I'm not a kTurtle programmer, but there are some general things that could be improved:</p>\n\n<ul>\n<li>Use good, descriptive names for your variables. You might use <code>CanvasWidth</code> instead of <code>CanvasX</code>, and <code>left</code>, <code>bottom</code>, <code>right</code>, <code>top...
{ "AcceptedAnswerId": "54256", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T20:37:35.567", "Id": "53828", "Score": "19", "Tags": [ "beginner", "game", "logo-lang" ], "Title": "Four Tic-Tac-Toe boards using kTurtle" }
53828
<p>Logo was created in 1967 at Bolt, Beranek and Newman (BBN), a Cambridge, Massachusetts research firm, by Wally Feurzeig and Seymour Papert.</p> <p>Its intellectual roots are in artificial intelligence, mathematical logic and developmental psychology. The first four years of Logo research, development and teaching w...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T20:41:16.080", "Id": "53831", "Score": "0", "Tags": null, "Title": null }
53831
Logo is a computer programming language, famous for its turtle cursor, created mainly for the purposes of education.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T20:41:16.080", "Id": "53832", "Score": "0", "Tags": null, "Title": null }
53832
<p>See also <a href="/questions/tagged/logo" class="post-tag" title="show questions tagged &#39;logo&#39;" rel="tag">logo</a> for additional information.</p> <p>KTurtle syntax is slightly different from Logo syntax.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-09T20:46:02.260", "Id": "53834", "Score": "0", "Tags": null, "Title": null }
53834