body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Before I go too far, does this look right?</p> <p>This is mostly to have a "central" place that hold a "hierarchical/structured" errors message.</p> <pre><code>public static class ValidationError { static ValidationError() { Prefix = "VE"; Notice = new _Notice(); Exporter = new _Exp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T13:19:22.253", "Id": "80137", "Score": "4", "body": "It will help if you stated the objectives you are aiming to achieve with this code and give it some context so people can try and provide the most appropriate solution. In the mea...
[ { "body": "<h2>Naming</h2>\n<p>Class names in C#, whether they're for a static, non-static, internal, public, private, abstract, nested or on-its-own class, should be <em>PascalCase</em>.</p>\n<p>Find the intruder:</p>\n<pre><code>public class _Notice\npublic class _Exporter\npublic class _Importer\npublic clas...
{ "AcceptedAnswerId": "45944", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T12:10:14.847", "Id": "45937", "Score": "3", "Tags": [ "c#", "validation", "error-handling" ], "Title": "Simple structure that would contain validation errors messages" }
45937
<p>I was thinking about how to implement a GPS navigation for my quadcopter. I was writing some functions to calculate the angle between two positions (from home point to the target).</p> <p>I'd like a review of this code. I am not very sure whether I was calculating the geographic position right.</p> <pre><code>/*...
[]
[ { "body": "<p>You naming convention is a bit weird. My assumption is that <code>fLat</code> stands for \"float latitude\". Because it is quite easy to know the type of a variable, there's no need for having the <code>f</code> prefix.</p>\n\n<p>You don't need to cast to <code>float</code> in <code>m_fDestin_deg ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T12:47:13.067", "Id": "45939", "Score": "1", "Tags": [ "c++", "geospatial" ], "Title": "Working and calculating with geographic positions" }
45939
<p>This code connects to a mongodb database and returns collection objects. I am concerned about the exception handling, variable names and comments.</p> <pre><code> import config_files import tweepy import csv import warnings import importlib import sys from MongodbConnections impor...
[]
[ { "body": "<p>So some minor comments to kick things off:</p>\n\n<p>Your method names are not PEP8 compliant. Usually camel case is avoided in Python. Names like <code>checkArgumentsLength</code> should really be more along the lines of <code>check_arguments_length</code>.</p>\n\n<p>It is bad practice to put <co...
{ "AcceptedAnswerId": "46041", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T15:44:53.707", "Id": "45949", "Score": "0", "Tags": [ "python", "exception-handling", "mongodb" ], "Title": "Class for connecting to mongodb databases and return collection obj...
45949
<p>Is my approach good to naming variables and exception handling? I would like to make this code more robust and maintainable. I need advice on exception handling, var naming and comments.</p> <pre><code> import config_files import math """ Performs logistic regression on tweets object passed and retu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T17:49:46.017", "Id": "80181", "Score": "1", "body": "Your docstrings need to be below the `def` to be attached to the object properly." } ]
[ { "body": "<p>For a start : your naming convention does not follow <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a> which is the usually accepted style guide for python code.</p>\n\n<hr>\n\n<p><code>sigmoid()</code> does not need to operate on an instance.</p>\n\n<hr>\n\n<p>In ...
{ "AcceptedAnswerId": "45958", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T15:50:28.550", "Id": "45950", "Score": "2", "Tags": [ "python", "exception-handling", "statistics", "machine-learning" ], "Title": "Compute logistic regression on tweet obj...
45950
<pre><code>public class AnagramNumber { public static void checkAnagram(String[] str) { String[] sortedArray=new String[str.length]; for(int i=0;i&lt;str.length;i++) { char[] strToCharArray=str[i].toCharArray(); sortedArray[i]=new String(sortCharArray(strToCharArray))...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T08:22:17.150", "Id": "80275", "Score": "0", "body": "please provide a bit of background. Are you trying to implement your own sorting algorithm? Otherwise, trust `Arrays.sort` from `Java`. Your sorting algorithm is using bubble sort...
[ { "body": "<p><strong>Indentation</strong></p>\n\n<p>Your indentation seems consistent in your code, except for this part. It could be a problem in the question here on Code Review, but always pay attention to the indentation of your code. It's a major point for good readability.</p>\n\n<blockquote>\n<pre><code...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T16:02:30.423", "Id": "45954", "Score": "6", "Tags": [ "java", "optimization", "strings" ], "Title": "Anagram Checking" }
45954
<p>I have a form that posts (a,b) values into the following .php file, and displays an error message when the user tries to reach the .php file directly, instead via POST request.</p> <p>This code is probably pretty messy, for example, I'm not sure I can post <code>&lt;p&gt;</code> tags right away, instead of having t...
[]
[ { "body": "<p>A few suggestions.</p>\n\n<ol>\n<li>Instead of writing styles in same file use an external style sheet</li>\n<li><p>Also you can restructure it like:</p>\n\n<pre><code> &lt;!doctype html&gt;\n &lt;html&gt;\n &lt;head&gt;\n &lt;title&gt;test&lt;/title&gt;\n &lt;meta http-equiv=\"Content-Type\" cont...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T16:08:50.623", "Id": "45955", "Score": "2", "Tags": [ "php" ], "Title": "If/else that contains HTML blocks, which contain additional PHP functions" }
45955
<p>This class' function is to change a given array's data into an ID. The list is set by a configuration file. I have DI the outer array and objects into the class so that if there are any dependencies - it gets injected.</p> <p>The protected <code>$_api;</code> is an external API class that contains some API call to ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T16:40:13.510", "Id": "45957", "Score": "1", "Tags": [ "php", "design-patterns", "php5", "redis" ], "Title": "Data lookup table with Redis and API call" }
45957
<p>Is there anything horribly wrong with creating different representations of data behind the scenes when constructing a <code>std::vector&lt;T&gt;</code> from a <code>std::vector&lt;U&gt;</code>?</p> <pre><code>std::vector&lt;Color&gt; initialScene(Settings::HRes * Settings::VRes); std::vector&lt;Pixel&gt; finalSce...
[]
[ { "body": "<p>No problem with that at all, since it's not the <code>copy</code> which is doing the conversion (which would be strange) but the constructor. Since the <code>vector</code> templates you've mentioned are clearly of different types, the operation you describe would not at all be unexpected. It's l...
{ "AcceptedAnswerId": "45972", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T18:40:24.140", "Id": "45968", "Score": "4", "Tags": [ "c++", "c++11" ], "Title": "Trigger custom implicit conversion on \"copy\"" }
45968
<p>In my current project, I find myself using <code>Dispatcher.Invoke</code> a lot. Before each call I test if the current dispatcher is the right one. I want to write a wrapper class like so:</p> <pre><code>class SafeRunner { //From the thread we always need to run on public static System.Windows.Threading.Di...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T18:50:41.967", "Id": "80194", "Score": "0", "body": "Your invocation may be able to be written as `SafeRunner.Run(doSomething, \"Hello\", \"World\")`. The methodgroup/delegate should match the parameters already, after all. That mak...
[ { "body": "<p>A couple of things I notice, and they are both around the if statements</p>\n\n<p>I would flip the if statements around so that they are checking the positive test. I would also put the <code>disp</code> on the right side of the <code>==</code>. You can eliminate the else statement, all it reall...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T18:40:47.310", "Id": "45969", "Score": "4", "Tags": [ "c#", "multithreading", "wpf" ], "Title": "Same function, variable parameters and types with lambda" }
45969
<p>Please review my code for bearer token (JWT) authentication of Web API 2 (Self Hosted using OWIN)</p> <p>Are there any security issues in the implementation?</p> <p>Quick overview:</p> <ul> <li>Token creation and validation using JWT Handler</li> <li>Symmetric key encryption</li> <li>CORS support not yet checked ...
[]
[ { "body": "<p>Instead of keeping <code>KEY</code> in config, I would keep it with user records. A unique key for each user.</p>\n\n<p>I admit, I don't get why creating keys dynamically would break the load balancing scenario. We can have a key created at the back-end where we have a single service serving all ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T18:57:48.893", "Id": "45974", "Score": "14", "Tags": [ "c#", "authentication", "asp.net-web-api", "jwt" ], "Title": "Web API 2 authentication with JWT" }
45974
<p>I need to delete a file when an error occurs during loading it. It is not allowed to perform async operations in a catch block. </p> <p>This has lead me to writing the following code:</p> <pre><code> public async Task LoadFromStorageFile(string fileName) { StorageFile file = null; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T17:06:53.543", "Id": "81058", "Score": "1", "body": "“It is not allowed to perform async operations in a catch block.” Not yet, it's probably going to be allowed in C# 6.0." } ]
[ { "body": "<p>Couple random observations:</p>\n\n<p>This initialization is redundant:</p>\n\n<pre><code> StorageFile file = null; \n Exception ex1 = null;\n</code></pre>\n\n<p>Because all reference type default to <code>null</code>, this is rigorously equivalent:</p>\n\n<pre><code> StorageFi...
{ "AcceptedAnswerId": "46004", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T20:22:35.243", "Id": "45980", "Score": "6", "Tags": [ "c#", "error-handling", "async-await" ], "Title": "Async and error-handling" }
45980
<p>I have been developing a small application for a client which combines two arrays together and then creates a URL and then loads the images on the same page from the given URL.</p> <p>I'd like you to look at my code and give feedback on how to make it more maintainable and robust.</p> <pre><code>function displayCo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T23:09:22.673", "Id": "80245", "Score": "0", "body": "Could you explain better what your code does? Your first paragraph doesn't make any sense at all. \"Combining two arrays\" could mean anything. And what do two arrays (of what?) h...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>obfuscating urls from the javascript side will not stop any dedicated individual</li>\n<li><code>displayContent</code> is an unfortunate name for the function, it does not give away that all it does it setting a listener, consider <code>setFindCarListener</code><...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T22:11:48.430", "Id": "45985", "Score": "5", "Tags": [ "javascript", "array", "image", "url" ], "Title": "Loading car photo's" }
45985
<p>How can I get Monday and Friday from a date range (<strong>start</strong> and <strong>end</strong> date)?</p> <p>Example:</p> <p><strong>startdate</strong> - 03/24/2014 <br/> <strong>enddate</strong> - 04/01/2014</p> <p>Result should be:</p> <p><strong>Monday</strong> - 2 <br/> <strong>Friday</strong> - 2</p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-28T06:18:35.593", "Id": "80237", "Score": "1", "body": "I don't understand why you think increasing the time range would somehow increase the processing time. You're not iterating over anything." }, { "ContentLicense": "CC BY-S...
[ { "body": "<p>Your code is already good enough.</p>\n\n<pre><code>static int CountDays(DayOfWeek day, DateTime start, DateTime end)\n{\n start = start.Date.AddDays((7 + day - start.DayOfWeek) % 7);\n if (end &lt; start)\n return 0;\n else\n return ((int)(end - start).TotalDays) / 7 + 1;\n...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-28T06:14:40.870", "Id": "45986", "Score": "3", "Tags": [ "c#", "datetime" ], "Title": "Counting Monday and Friday from a Date Range" }
45986
<blockquote> <p>Given an expression string exp, write a program to examine whether the pairs and the orders of</p> <pre><code>"{","}","(",")","[","]" </code></pre> <p>are correct in exp.</p> <p>For example, the program should print true for</p> <pre><code>exp = "[()]{}{[()()]()}" </code></pre> <p>a...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-10-29T09:37:56.040", "Id": "398312", "Score": "0", "body": "add this check as the first validation, If the length of the expression is an odd number we can return false right away." }, { "ContentLicense": "CC BY-SA 4.0", "Crea...
[ { "body": "<p>This is almost all style suggestions; the code itself looks great.</p>\n\n<p>Personally, I prefer the brace-on-same-line style for everything in JS, and I prefer proper blocks instead of inlining expressions. But those are just preferences. I've also skipped the bitwise trick, added some strict co...
{ "AcceptedAnswerId": "46039", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-01T23:05:26.267", "Id": "45991", "Score": "42", "Tags": [ "javascript", "algorithm", "strings", "stack", "balanced-delimiters" ], "Title": "Balanced parentheses" }
45991
<p>For my own linked list implementation, I've decided to try something different: a linked list of groceries.</p> <p>The main differences between this implementation and a standard list are:</p> <ol> <li>more data fields (name, quantity, if item has been purchased)</li> <li>two size data members (different items and...
[]
[ { "body": "<p>Rather than having the user pass in name and quantity, have the user pass in a Grocery. You complete throw away any sense of encapsulation by having the user provide the components rather than the object.</p>\n\n<hr>\n\n<p>Rather than <code>displayGroceries</code>, I would overload <code>operator&...
{ "AcceptedAnswerId": "45996", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-01T23:12:28.423", "Id": "45992", "Score": "6", "Tags": [ "c++", "c++11", "linked-list" ], "Title": "Singly-linked grocery list" }
45992
<p><a href="http://crystalcleanhomes.com/slide/" rel="nofollow">http://crystalcleanhomes.com/slide/</a></p> <p>There are countless scripts that perform this simple slide-out navigation menu but they are all so bloated and the styles are so convoluted that I decided to make my own and it seems almost too simple and too...
[]
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li><p>You should put the closing brace at the level of <code>$</code> for readability:</p>\n\n<pre><code>$(function () {\n $('#menubutton').click(function (e) {\n e.preventDefault();\n e.stopPropagation();\n });\n\n function handler1() {\n ...
{ "AcceptedAnswerId": "46072", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T00:21:34.383", "Id": "45995", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "slide out navigation bar seems too simple but it works, is it?" }
45995
<p>I'm looking for a more cleaner and simpler solution to auto-format a text-box field intended only for the user to enter their college Grade Point Average (GPA). Here is my code:</p> <pre><code>&lt;label for="collegeGPA"&gt;GPA:&lt;/label&gt; &lt;input type="text" name="collegeGPA" id="collegeGPA" maxlength="4" styl...
[]
[ { "body": "<p>First of all, I'd be hesitant to use as-you-type correction to begin with. It doesn't take much for something like that to be an annoyance rather than a help. It's probably better to validate the input only when it loses focus, or when the form is about to be submitted, and then inform the user so...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T01:08:20.890", "Id": "45997", "Score": "7", "Tags": [ "javascript", "validation", "formatting" ], "Title": "Auto-Format GPA while typing" }
45997
<p>Here is another example of a moving ball. I would like to see how to make it more efficient and better. I think that moving the variables to the top of the function would be better but then I tried this and it would not work as good as it did.</p> <pre><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T06:58:30.820", "Id": "80268", "Score": "0", "body": "Please make sure your code works before having it reviewed. If it does not work, head over to [StackOverflow](http://stackoverflow.com/)" }, { "ContentLicense": "CC BY-SA ...
[ { "body": "<h1>Your Script</h1>\n\n<h3>Handlers</h3>\n\n<p>Unless your handlers are called somewhere else, you can just embed them</p>\n\n<pre><code>window.addEventListener('load', function () {\n canvasApp();\n});\n</code></pre>\n\n<h3>requestAnimationFrame</h3>\n\n<p>There's this timer function called <cod...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T01:13:23.760", "Id": "45998", "Score": "2", "Tags": [ "javascript", "optimization" ], "Title": "Efficiency of moving ball" }
45998
<p>Inspired by all of the lovely linked lists lately, I decided to implement one in assembly language. This code maintains two linked lists - one is a free store and the other is the active linked list. Rather than allocating memory whenever a new node is needed, the Node is pulled from the free list and all of the p...
[]
[ { "body": "<p>Just a few notes, mostly in micro-optimizations that even assembly language programmers probably ignore nowadays.</p>\n\n<pre><code> ; steal a node from the freenode list\n ; [rootnode] = [freenode]\n mov rbx, freenode ; rbx -&gt; freenode\n cmp qword [rbx], 0 ...
{ "AcceptedAnswerId": "48283", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T02:11:51.263", "Id": "45999", "Score": "14", "Tags": [ "linked-list", "linux", "assembly" ], "Title": "Linux NASM assembly linked list implementation" }
45999
<p>I wrote a stack implementation using a singly linked list in x86_64 assembly. This stack supports the usual <code>push</code>/<code>pop</code> operations as well as first/next for iterating over each element.</p> <p>I'm looking for general feedback.</p> <p>Here are the stack subroutines:</p> <pre><code>; Stack St...
[]
[ { "body": "<p>The code is generally well written and easy to understand, but I have a few comments on it that could help improve it.</p>\n\n<h2>Eliminate \"magic numbers\"</h2>\n\n<p>In the <code>StackCreate</code> routine, the first instruction is <code>mov rdi,24</code> but it's not clear what 24 signifies in...
{ "AcceptedAnswerId": "48951", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T02:22:52.170", "Id": "46000", "Score": "27", "Tags": [ "linked-list", "stack", "assembly" ], "Title": "Stack implemented using linked list in x86_64 assembly" }
46000
<blockquote> <p>Given <code>(</code> and <code>)</code> and length of 4, generate the following combinations - <code>()()</code> and <code>(())</code>.</p> </blockquote> <p>Looking for code review, optimizations and best practices. Also verifying complexity to be O(2<sup>(n+1)</sup> - 1), where n is half the 'inpu...
[]
[ { "body": "<p>Jus a few minor points:</p>\n\n<ol>\n<li><p>I guess you have a typo here:</p>\n\n<blockquote>\n<pre><code>if (length % 2 == 1) { \n throw new IllegalArgumentException(\"The length should be positive\");\n}\n</code></pre>\n</blockquote>\n\n<p>If <code>length</code> is <code>3</code> it prints th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T03:20:34.360", "Id": "46003", "Score": "2", "Tags": [ "java", "algorithm", "balanced-delimiters" ], "Title": "Print all combinations of balanced parentheses" }
46003
<p>I just wrote this pool to avoid calling <code>malloc</code> and <code>free</code> when I have some code that frequently allocates and deallocates chunks of same-sized memory. I would like to know if there are any bugs I didn't notice and what would be the best solution to achieve this goal.</p> <p>I'm using some sm...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T00:22:29.713", "Id": "85246", "Score": "0", "body": "Could you also post the contents of `\"dynamic_stack.h\"`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-02T09:00:34.697", "Id": "85609", "S...
[ { "body": "<p>You should always use curly braces around <code>if</code> statements and <code>for</code> loops. It's the safe thing to do, especially when you are dealing with memory-management. </p>\n\n<p>Something small like this:</p>\n\n<pre><code>if(temp == NULL)\n return NULL;\n</code></pre>\n\n<p>Can b...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T03:31:44.623", "Id": "46005", "Score": "8", "Tags": [ "c", "memory-management" ], "Title": "Does this simple memory pool use too much memory?" }
46005
<p>I wonder if there are some possible ways to simplify my code. <br/></p> <pre><code>startDate = '04/02/2014' endDate = '04/06/2014' mondayTag = 0 tuesdayTag = 0 wednesdayTag = 1 thursdayTag = 0 fridayTag = 1 saturdayTag = 0 sundayTag = 0 public int GetRemainingDays(DateTime startDate, DateTime endDate, bool monday...
[]
[ { "body": "<p>Since DayOfWeek is a an Enum with 0 = Sunday through 6 = Saturday.</p>\n\n<p>Instead of passing Boolean tags, you can pass an array of integers where index = 0 is for Sunday, with value 1 for true and 0 for false.</p>\n\n<pre><code> var dayOfWeeksTags = new int[7];\n</code></pre>\n\n<p>then...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T06:29:15.630", "Id": "46010", "Score": "5", "Tags": [ "c#", "datetime" ], "Title": "Get remaining days in date range" }
46010
<p>Here is the code as it stands right now:</p> <pre><code>import numpy as np from matplotlib import pyplot as plt from matplotlib import animation from random import randint arraySize = 50 Z = np.array([[randint(0, 1) for x in range(arraySize)] for y in range(arraySize)]) def computeNeighbours(Z): rows, cols =...
[]
[ { "body": "<p>I'll just be cheeky and post a slightly modified version of my SO answer here.</p>\n\n<p>So first things first, you want to get rid of the loops. They are slow to execute.</p>\n\n<p>The first loop:</p>\n\n<pre><code>for x in range(rows):\n for y in range(cols):\n if Z[x][y] == 1:...
{ "AcceptedAnswerId": "46020", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T06:36:34.753", "Id": "46011", "Score": "7", "Tags": [ "python", "numpy", "animation", "game-of-life", "matplotlib" ], "Title": "Optimizing very simple piece of “Game of...
46011
<p>Writing a MMORPG server in nodejs, I have to handle packets. These packets have a structure of </p> <pre><code>&lt;length&gt; &lt;id&gt; &lt;data&gt; </code></pre> <p>So what I did was use a node package called <a href="https://github.com/bigeasy/packet">packet</a></p> <p>And first get the packet id:</p> <pre><c...
[]
[ { "body": "<p>You should compartmentalize your \"handlers\" for each of the packets. Each handler should contain a <code>canHandle</code> method that determines whether it can process the packet and a <code>process</code> method that does the work. Example:</p>\n\n<pre><code>var packet300Handler = {\n canH...
{ "AcceptedAnswerId": "46057", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T07:29:52.133", "Id": "46013", "Score": "7", "Tags": [ "javascript", "node.js" ], "Title": "Handling packets in nodejs for MMORPG" }
46013
<p>I was asked to answer the following question before setting up a phone interview, but they said my code wasn't detailed enough.</p> <p>Question:</p> <blockquote> <p>Without using any of the .NET Collection or Linq libraries (i.e. without using List), implement a ListOfStrings object that contains a set of st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T08:17:28.783", "Id": "80274", "Score": "3", "body": "What did they mean by \"not detailed enough\"? They were expecting comments or something?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T10:51:51....
[ { "body": "<p>I don't have too much experience with C#, so just some notes about the algorithm/structure. (Maybe there are C#-related issues which I'm not aware of.)</p>\n\n<p>At first I was expecting some array manipulation logic here with extending the array if it's full. They might be expected the same but y...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T07:45:11.743", "Id": "46017", "Score": "12", "Tags": [ "c#", "interview-questions" ], "Title": "ToString() and AddString() method without using .Net Collections" }
46017
<p>Recursive version. The only interesting function:</p> <pre><code> List&amp; List::reverse() { if (empty()) { return *this; } int val = head(); // // The fun bit. // See if you can figure this bit out. re...
[]
[ { "body": "<blockquote>\n <p>See if you can figure this bit out.</p>\n</blockquote>\n\n<p>Is this meant to be a <a href=\"https://codegolf.stackexchange.com/\">Programming Puzzle</a>?</p>\n\n<p>You don't call <code>append</code> until after you finish calling <code>reverse</code>; <code>reverse</code> is recur...
{ "AcceptedAnswerId": "46184", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T07:49:46.297", "Id": "46019", "Score": "9", "Tags": [ "c++", "c++11", "recursion", "linked-list" ], "Title": "Linked List reversal" }
46019
<p>I implemented K-Nearest Neighbours algorithm, but my experience using MATLAB is lacking. I need you to check the small portion of code and tell me what can be improved or modified. I hope it is a correct implementation of the algorithm.</p> <pre><code>function test_data = knn(test_data, tr_data,k) numoftestdata =...
[]
[ { "body": "<ul>\n<li>Use consistent indentation.</li>\n<li>You switch from extremely verbose all lower case variable names like <code>numoftrainingdata</code> to single letter capitalized variable names like <code>A</code>. Make your variable names descriptive and no longer than necessary, and be consistent.</l...
{ "AcceptedAnswerId": "46068", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T10:23:54.483", "Id": "46027", "Score": "4", "Tags": [ "algorithm", "beginner", "matlab", "clustering" ], "Title": "K-nearest neighbours in MATLAB" }
46027
<p>I just read the Lib/argparse.py code (class FileType) on <a href="http://hg.python.org/cpython/file/default/Lib/argparse.py" rel="noreferrer">http://hg.python.org/cpython/file/default/Lib/argparse.py</a>. File objects are opened without the with statement. For safe file opening/closing, should I instead encapsulate ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T06:55:03.793", "Id": "80506", "Score": "2", "body": "See the discussion in http://bugs.python.org/issue13824" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-14T08:05:04.813", "Id": "87464", "Scor...
[ { "body": "<p>I've expanded on your example, and explored some alternatives.</p>\n\n<p>Observations:</p>\n\n<ul>\n<li><p>your <code>def argparse</code> shadowed the module; I changed its name.</p></li>\n<li><p>using <code>FileType</code> to process the argparse input results in <code>unclosed file</code> warnin...
{ "AcceptedAnswerId": "49768", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T11:22:09.617", "Id": "46031", "Score": "7", "Tags": [ "python", "python-3.x" ], "Title": "Should I put python3 argparse filetype objects in a contextlib stack?" }
46031
<p>I'm coding a little class hierarchy printing tool for easy show hierarchies of java classes.</p> <p>This is my current code:</p> <pre class="lang-java prettyprint-override"><code>import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.ArrayList; import java.uti...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T12:48:46.767", "Id": "80326", "Score": "0", "body": "`entries` and `moreToCome` are private instance variable which is looking fine to me since they look as being use in every method of the class. If they were global that would be a...
[ { "body": "<p><strong>Mutators vs. Selectors</strong><br>\nThe method <code>printHierarchy(final Class&lt;?&gt;...)</code> both populates the instance, and prints the result. It would be a lot more predictable if it would be responsible only for one or the other. Its name implies that it only prints, so I would...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T11:22:10.520", "Id": "46032", "Score": "8", "Tags": [ "java", "classes", "tree", "inheritance" ], "Title": "Class for printing class hierarchy as text" }
46032
<pre><code>public class SudokuChecker{ static int[][] sMatrix={ {5,3,4,6,7,8,9,1,2}, {6,7,2,1,9,5,3,4,8}, {1,9,8,3,4,2,5,6,7}, {8,5,9,7,6,1,4,2,3}, {4,2,6,8,5,3,7,9,1}, {7,1,3,9,2,4,8,5,6}, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T12:08:24.707", "Id": "80311", "Score": "3", "body": "Hint why checking for `sum == 45` is not sufficient: `(1+9)+(2+8)+(3+7)+(4+6)+5` is OK, but `(1+9)+(1+9)+(1+9)+(1+9)+5` also fulfills that constraint!" }, { "ContentLicens...
[ { "body": "<p>You have waaaay too many sums you are checking. <a href=\"http://en.wikipedia.org/wiki/Keep_it_simple_stupid\">KISS-Principle --> Keep it Simple {and} Stupid</a>:</p>\n\n<pre><code>private boolean checkSudokuStatus(int[][] grid) {\n for (int i = 0; i &lt; 9; i++) {\n\n int[] row = new in...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T11:32:46.243", "Id": "46033", "Score": "15", "Tags": [ "java", "validation", "sudoku" ], "Title": "Sudoku Checker in Java" }
46033
<p>I'm a beginner and I only know limited amounts such as <code>if</code>, <code>while</code>, <code>do while</code>. So I'm here to check if I'm coding with best practise and the most effective methods to my current knowledge.</p> <pre><code>import java.util.Scanner; public class SixtyTwo { public static void ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T05:12:57.403", "Id": "80489", "Score": "2", "body": "[collatz research/ graphs/ leads/ papers/ ruby code/ many se Q/As](http://vzn1.wordpress.com/code/collatz-conjecture-experiments/)" } ]
[ { "body": "<p>That is some overall quite good code you have there, but I have a couple of comments.</p>\n\n<ul>\n<li><p><code>Scanner</code> should be closed when you are done with the input. Simply call <code>keyboard.close();</code> when you have acquired the input that you need.</p></li>\n<li><p>Your class i...
{ "AcceptedAnswerId": "46036", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T11:38:13.017", "Id": "46034", "Score": "17", "Tags": [ "java", "beginner" ], "Title": "Collatz Sequence" }
46034
<p>I needed a script for working out billing dates over a period of time. The date should be the same day every month however if the billing date starts on a date that doesn't exist in another month, then it should be on the last day of that month. This rules out the <code>DateTimeInterval</code> Object, because that ...
[]
[ { "body": "<p>I think the best thing you could do (as in easiest, most reliable and least code) is to go back to the <code>DatePeriod</code> class. Yes, it doesn't correct itself in terms of <em>\"month-overflow\"</em> (yet), but that's an easy fix:</p>\n\n<p>Assume the data from your example:</p>\n\n<pre><code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T13:27:21.813", "Id": "46047", "Score": "8", "Tags": [ "php", "datetime" ], "Title": "Calculate a month later than current month (without rolling over to next month)" }
46047
<p>Please review my code and let me know how I can possibly improve it.</p> <pre><code>#include&lt;iostream&gt; using namespace std; class node { private: int data; public: node *next; node(int element) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T20:17:15.730", "Id": "80422", "Score": "6", "body": "Indenting seems very haphazard." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-11-01T13:18:39.913", "Id": "273840", "Score": "0", "body": "C...
[ { "body": "<p>First of all, I will start with one of the most common remarks: please, <a href=\"https://stackoverflow.com/q/1452721/1364752\">do not use <code>using namespace std;</code></a>. It is especially bad if you write it in a header file since it leads to namespace pollution and name clashes.</p>\n\n<hr...
{ "AcceptedAnswerId": "46051", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T13:48:08.260", "Id": "46048", "Score": "15", "Tags": [ "c++", "beginner", "stack", "collections", "pointers" ], "Title": "Implementation of stack using pointers" }
46048
<p>I'm in a beginner JavaScript class and I feel like I have a pretty good grasp on all the intro material. All of my homework assignments work but they seem longer than they have to be, especially my most recent one. I'm not asking for answers to my homework as it is already complete (you can see the code works below)...
[]
[ { "body": "<p>rather than query each radio to see if it is checked and then run the arithmetic based upon that, I would probably store the arithmetic as a closure in your obj, where the key is the value of the checked input and then run document.querySelector to find the checked input, something like this:</p>\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T14:26:44.297", "Id": "46053", "Score": "7", "Tags": [ "javascript", "beginner", "homework", "calculator" ], "Title": "Basic Calculator" }
46053
<p>I just got into Object Oriented Programming, and it made me think about certain code how I can make them as efficient as possible.</p> <p>Right now I am just including my header and footer like the following:</p> <p><strong>PHP</strong></p> <pre><code>require_once 'core/init.php'; require_once 'includes/header.p...
[]
[ { "body": "<p>If you are working in PHP use a framework that has MVC such as Laravel(up and coming and popular), Symphony, Yii, Codeigniter(defunct), etc.</p>\n\n<p>Each of them will enable you to use some reuse mechanism.</p>\n\n<p>Laravel itself uses a template PHP called blade. There are several other templa...
{ "AcceptedAnswerId": "46069", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T14:44:14.897", "Id": "46059", "Score": "5", "Tags": [ "php", "object-oriented" ], "Title": "Neatest way of including a header and footer on every page" }
46059
<p>The purpose of the below code is to update a column based on the name of the field name sent from the .NET code. This allows one piece of code to handle multiple rows when a user is only adding/updating one at a time.</p> <p>I have been using Stored Procedures for a while but normally just Add/Update but not using ...
[]
[ { "body": "<p>I think your stored procedure looks great!</p>\n<p>The only line that had me scratching my head is this one:</p>\n<pre><code>Execute ('UPDATE [TblActionsOldest] SET ' + @vFieldName + ' = ''' + @vValue + ''' WHERE RefID = ''' + @AlphaNumbericalRef+ '''')\n</code></pre>\n<p>I'm guessing those apostr...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T14:45:43.047", "Id": "46060", "Score": "7", "Tags": [ "sql", "sql-server", "stored-procedure" ], "Title": "Update column based on input variable in stored procedure" }
46060
<p>This is a form generator I created so users can input a URL, description and link. The output will eventually be a JavaScript news slider. The HTML the form generated is irrelevant for now but I'd like to see how I can improve the JavaScript code handing the processing. </p> <p>This is my first version/draft.</p> ...
[]
[ { "body": "<p>I will start with a snooty remark; please don't submit your first draft, but submit the best code you think you can write.</p>\n\n<p>From a once over:</p>\n\n<ul>\n<li>You should consider having your JavaScript in a separate file, JavaScript mixed in with your HTML is old skool</li>\n<li>Indentati...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T16:03:59.850", "Id": "46071", "Score": "6", "Tags": [ "javascript", "jquery", "css", "form" ], "Title": "Form generator for inputting URL, description and link" }
46071
<p>I've borrowed and written the following code to output the disconnect time. All works well but I'm curious as to how I could tighten/ shorten the code. If anyone feels like having some fun then I'd love to see what can be done. Be a learning lesson for me.</p> <p>Excerpt of input:</p> <pre><code>ftp&gt; !:--- FTP ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T17:55:25.500", "Id": "80380", "Score": "0", "body": "Is your first \"output\" actually the input in the context of this question? Could you explain what \"44.81117.00\" means, and why that translates to a desired output value of 122...
[ { "body": "<p>Assuming the \"Output\" section is stored in \"filename.txt\", and assuming you have GNU tools:</p>\n\n<pre><code>grep -oP '(?&lt;=\\.\\d\\d)\\d+\\.\\d\\d(?=disconnect)' filename.txt\n</code></pre>\n\n<p>That's a perl regex meaning: prececeded dot and two digits, find some digits, a dot and two di...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T16:49:23.693", "Id": "46074", "Score": "4", "Tags": [ "parsing", "datetime", "sed", "awk" ], "Title": "Extracting performance statistics from FTP session transcript" }
46074
<p>This is my code which receives a file to read and converts binary values to ASCII text.</p> <p>The code works fine, so I am looking for a review on what I have written, and suggestions on how I could do it better, perhaps without the use of a <code>StringBuffer</code>.</p> <pre><code>import java.io.File; import ja...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T18:02:22.587", "Id": "80381", "Score": "2", "body": "Why not use a `StringBuffer`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T18:02:34.523", "Id": "80382", "Score": "1", "body": "Your...
[ { "body": "<p>You should be using <code>StringBuilder</code> instead of <code>StringBuffer</code>, since <code>StringBuffer</code> has synchronization for thread safety that you don't need.</p>\n\n<p>To make the code more modular and reusable, consider writing it as a <code>FilterInputStream</code> instead.</p>...
{ "AcceptedAnswerId": "46082", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T17:59:43.603", "Id": "46080", "Score": "10", "Tags": [ "java", "strings" ], "Title": "Read and convert binary files to ASCII text" }
46080
<p>I was asked to create a test APK file by a company HR when I applied for an Android developers job,</p> <p>Specification:</p> <blockquote> <p>The goal is to develop a simple application which finds the local restaurants. The application will contain 2 screens:</p> <p>A list of nearby restaurants within 1 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T19:19:07.963", "Id": "80407", "Score": "0", "body": "I don't know much about API key, but you do know that they are now public, since they are in the code (just want to make if those key are suppose to be private, they should be rem...
[ { "body": "<ol>\n<li><p><code>GooglePlaces.search</code> could return empty list instead of <code>null</code>. It would save you a few <code>null</code> checks in clients. (<em>Effective Java, Second Edition</em>, <em>Item 43: Return empty arrays or collections, not nulls</em>)</p></li>\n<li><p>Be careful abou...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T18:50:25.997", "Id": "46086", "Score": "9", "Tags": [ "java", "android", "interview-questions", "geospatial", "google-maps" ], "Title": "Simple application for finding lo...
46086
<p>The following is some code I just wrote. I keep wondering as always what I can do to make this more efficient. Please help me make this code object oriented and if anyone could help me write automated or even non automated tests for my widget... </p> <p>Also is this considered a closure? I don't think it is but I ...
[]
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>Do not use <code>data-function~=\"exploded-state-1\"</code>, instead assign id's and search by id, this is the common ( and faster, better ) approach</li>\n<li>One single <code>var</code> statement with comma separated variables is considered better</li>\n<li>I w...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T18:54:52.210", "Id": "46087", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Object Oriented Modular Closure" }
46087
<p>I'm on chapter 7 of Chris Pine's book, trying to work on the last exercise in that chapter. This code works fine, but I'm wondering if there is a better way to do this...</p> <pre><code>toc_array = ['Table of Contents', 'Chapter 1: Numbers', 'page 1', 'Chapter 2: Letters', 'page 72', 'Chapter 3: Variables', 'p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T19:13:59.630", "Id": "80404", "Score": "2", "body": "What does this have to do with sorting (as indicated in the title)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T19:32:44.850", "Id": "80411...
[ { "body": "<p>Your code is very brittle and hard-coded. Code is supposed to be as generic and flexible as possible so you could re-use it. A new chapter, a different layout, anything would require you to change the whole code.</p>\n\n<p>Code is about doing work <em>for you</em>. Think generically - can this cod...
{ "AcceptedAnswerId": "46096", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T19:05:15.800", "Id": "46088", "Score": "-1", "Tags": [ "ruby", "formatting" ], "Title": "Efficient way to sort a formatted array (Chris Pine book, ch 7)" }
46088
<p>I would like to test reliability of system <code>flock</code> in a multi-threaded and concurrent environment as some <a href="https://stackoverflow.com/a/2921596/223226">suggest that they are not reliable</a> (in comments).</p> <p>Thus I wrote this code which requests non-blocking exclusive lock, with multiple thre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T14:32:40.820", "Id": "80783", "Score": "1", "body": "Sorry, no. 1st: the [comment you are referring to](https://stackoverflow.com/questions/2921469/php-mutual-exclusion-mutex/2921596#comment5291305_2921596) is simply wrong. File loc...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T19:14:21.227", "Id": "46092", "Score": "1", "Tags": [ "perl", "file-system", "locking", "concurrency" ], "Title": "Reliability of flock mutex (LOCK_EX|LOCK_NB)" }
46092
<p>I've currently got a MSSQL stored procedure that uses multiple SQL functions to achieve a number of returns. Now I've been told about using sets rather than functions as it creates &quot; bad code smell of a DBA who is not yet thinking in sets&quot; <a href="https://stackoverflow.com/questions/22808489/speeding-up-m...
[]
[ { "body": "<p>First goal in thinking in SQL (or thinking in sets) is to get rid of IF statements and Loops (or cursors). So for your 2nd function this is much better:</p>\n\n<pre><code>CREATE FUNCTION dbo.funcSellIdByPropId\n(\n@PropertyId AS INT\n)\nRETURNS INT\nAS\nBEGIN\n DECLARE @ID AS INT\n\n SELECT @ID...
{ "AcceptedAnswerId": "46099", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T19:46:49.880", "Id": "46094", "Score": "2", "Tags": [ "sql", "sql-server" ], "Title": "The use of database \"sets\" rather than \"functions\"" }
46094
<p>I have spent a few hours on this code, but think it could be improved a bit. It requires eSpeak to be installed to run the speech synthesis, but the voice can be toggled on or off using the <code>togglevoice</code> command. This was created for Python 2.7.3.</p> <p>My major concerns are the fluctuations of the use ...
[]
[ { "body": "<h1>Line by line analysis</h1>\n\n<pre><code>import os\n</code></pre>\n\n<p>You need 2 blank lines before each global function definition.</p>\n\n<pre><code>def talk(n):\n</code></pre>\n\n<p><code>n</code> is not descriptive and associated with a number. Don't use one letter variables unless it's rea...
{ "AcceptedAnswerId": "46145", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T20:08:44.510", "Id": "46097", "Score": "5", "Tags": [ "python", "python-2.x", "linux", "raspberry-pi" ], "Title": "Ping Pong Pi - A Ping Pong score and serving manager" }
46097
<p>I am a high school intern, and I am trying to parse my mentor's code so that he can read in an XML file and call simple methods to edit or get information from his XML file. </p> <p>I was hoping someone could provide me with some (any) feedback - ways to optimize the code perhaps?</p> <p>The XML file that my mento...
[]
[ { "body": "<p>Overall, it’s pretty good. I can follow what you’re doing fairly easily, and the docstrings make it easy to see what each function does (even though I’ve not used this module before). Here are some suggestions for how you could make your code more “Pythonic”, and more compact:</p>\n\n<ul>\n<li><p>...
{ "AcceptedAnswerId": "46117", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T20:28:29.513", "Id": "46098", "Score": "7", "Tags": [ "python", "parsing", "xml" ], "Title": "Parse XML using Python XML eTree" }
46098
<p>I'm trying to implement interfaces in my design but not sure if this is correct or if there is a better way to do it.</p> <p>What I need to do is </p> <ol> <li><p>open a text file</p></li> <li><p>keep searching blocks of text until I find a string that matches against one of the classes that defines that string pa...
[]
[ { "body": "<p>It's very easy: you shouldn't. An interface is used to indicate that a subset of classes present common behaviour or should be considered similar in some way.</p>\n<p>In your situation there simply is no reason to make this change because all you do is change a text value in a property, which coul...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T20:42:30.817", "Id": "46100", "Score": "3", "Tags": [ "c#", "design-patterns", "strings", ".net" ], "Title": "Searching text files for string patterns that are each defined in...
46100
<p>I've built this small jQuery plugin to work with HTML5 History State functions. It's my first jQuery plugin, so I'm not sure if it's up to the best practices, or what could be done better. Keeping it simple and small is my main concern.</p> <p>If you have any suggestions on how to improve it, I'd love to see them.<...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T21:11:18.197", "Id": "46102", "Score": "3", "Tags": [ "javascript", "jquery", "design-patterns", "html5", "state" ], "Title": "jQuery Plugin - HTML5 History State" }
46102
<p>I wrote this script for a code challenge on TreeHouse. I already submitted my code, but I am looking for an after the fact feedback.</p> <p>The challenge was to open a file of text, remove specific words (provided in another file) and do the following:</p> <blockquote> <p>Output to the screen in a readable fashi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T15:27:13.707", "Id": "80608", "Score": "0", "body": "Just curious, what is the problem with defining word boundaries by simple whitespace?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T16:07:32.000"...
[ { "body": "<p>The first thing I noticed is that you've defined methods such as <code>word_occurrences</code>, which do nothing but set instance variables (<code>@word_occurrences</code>, etc.). This is a bit redundant, and it would be better to do one of two things:</p>\n\n<ol>\n<li>Define all of your instance ...
{ "AcceptedAnswerId": "47515", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T22:14:18.303", "Id": "46105", "Score": "2", "Tags": [ "ruby" ], "Title": "A Ruby string analyser" }
46105
<p>I have a GUI that contains a Table Object (for displaying columns of data) and a Table Model. The Table Object contains the Table Model.</p> <p>Is it better to store the Table Model as a object in the User interface or de-reference it as needed? Is there any performance gain keeping it separate? If there is, is ...
[]
[ { "body": "<p>There will be no difference in performance whatsoever between the two approaches.</p>\n\n<p>I would suggest you don't break the responsibility principle and leave the handling of the tablemodel to the <code>Table</code> class.</p>\n\n<p>One remark though: if there are additional computations done ...
{ "AcceptedAnswerId": "46110", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T22:16:55.267", "Id": "46106", "Score": "1", "Tags": [ "java", "optimization" ], "Title": "Store object in memory or de-reference it for performance" }
46106
<p>Is there a better way to handle this ClassNotFoundException ?</p> <pre><code>private Class&lt;?&gt; getClass(String value) { Class&lt;?&gt; columnClass = null; try { columnClass = Class.forName(StringUtils.trim(value)); } catch (ClassNotFoundException ex) { if (value.contains...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T22:50:55.130", "Id": "80455", "Score": "0", "body": "Can you provide more context about how this code is called, and how often?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T13:56:49.000", "Id":...
[ { "body": "<p>You do not provide much context for this method, so I can only give you general advice.</p>\n<h2>Logic</h2>\n<ol>\n<li><p>never use exception handling as part of the routine/regular code path in you program. Most Java VM's require significant locking and processing to generate the actual exception...
{ "AcceptedAnswerId": "46113", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T22:22:20.960", "Id": "46107", "Score": "2", "Tags": [ "java", "exception-handling" ], "Title": "Java ClassNotFoundException Handling" }
46107
<p>I'm trying to build an app which crawls a website to find the emails that it has and prints them. I also want to allow the user to type "false" into the console when they want to skip the website (maybe the user has already found 2 emails and doesn't need any more).</p> <p>Is the way I'm approaching this the best ...
[]
[ { "body": "<p>As @tokland pointed out, the major thing that jumps out when reading your code is the indentation problems. In most Ruby code you see, the standard indentation is 2 spaces. It looks like you are using hard-tabs, which are generally a bad idea. You should explore the settings of your text editor --...
{ "AcceptedAnswerId": "46828", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T22:25:12.000", "Id": "46108", "Score": "3", "Tags": [ "ruby", "http", "email", "web-scraping" ], "Title": "Crawling for emails on websites given by Google API" }
46108
<p>This is my second jQuery script: a universal tooltip for my entire web page. It took me a couple of days to research and make it work.</p> <p>Now, I need help from the experts to optimize my newbie code.</p> <p>This is one of the ways I can show the tooltip:</p> <pre><code>&lt;a class="tooltip" data-tooltip="this...
[]
[ { "body": "<p>You don't really need a <code>tooltip</code> class on your target element. Since you already have a <code>data-tooltip</code> attribute, that's enough to find the relevant elements:</p>\n\n<pre><code>$(\"[data-tooltip]\") // find all elements with a data-tooltip attribute\n</code></pre>\n\n<p>This...
{ "AcceptedAnswerId": "46124", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T22:32:39.903", "Id": "46111", "Score": "3", "Tags": [ "javascript", "jquery", "beginner" ], "Title": "jQuery tooltip optimization" }
46111
<p>Two trees are called isomorphic if one of them can be obtained from other by a series of flips, i.e. by swapping left and right children of a number of nodes. Any number of nodes at any level can have their children swapped. </p> <ol> <li>Looking for code-review, optimizations and best practices</li> <li>This class...
[]
[ { "body": "<p>As a general comment, your code has improved significantly in the last few months. It is to your benefit for multiple reasons.... the 'easy' things to review have gone (code style, variable names, etc.) and the core logic is much more readable. Reviewing your work is harder now because the easy th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T22:53:19.660", "Id": "46114", "Score": "2", "Tags": [ "java", "algorithm", "tree" ], "Title": "Isomorphic trees verification" }
46114
<p>I just jumped to a new project, which uses the active record pattern. It's a subscription service website. </p> <p>I have the following <code>User</code> object that extends a framework specific <code>ORM</code> object:</p> <pre><code>class User extends ORM { public function isSubscriber() { $ac...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T19:58:59.413", "Id": "80643", "Score": "0", "body": "Unrelated, but I'm going to have nightmares now... but what hellish framework are you using? An ORM that is built around a singleton DB? ffs, that's just horrible. Oh, and as an a...
[ { "body": "<p>Avoid hacking the code, if possible. Instead, you should have a test environment with a testing database. <code>Database::getInstance()</code> should use a configuration file containing the database connection parameters. It should configure itself to use the testing database when running unit tes...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T23:23:07.453", "Id": "46119", "Score": "4", "Tags": [ "php", "unit-testing" ], "Title": "Active record pattern for a subscription service website" }
46119
<p>I have a class created for the sole purpose is to help handle files. The class holds a path (folder) that contains a single file at a time. Some extra properties to this class are: age of a file and max file size. I'm a very procedural style coder, and I'm trying to shift my work to a more OOP and eventually end up...
[]
[ { "body": "<p>The class in on itself seems fine to me, but the question you should be asking is <strong>what problem am I solving here?</strong>.</p>\n\n<p>OOP design works well on the big picture. Let's say you have a simple application where you want to CRUD a user's contacts. And let's say that you decided f...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-02T23:30:51.780", "Id": "46120", "Score": "7", "Tags": [ "php", "object-oriented", "design-patterns", "file-system" ], "Title": "Making a FileHandler more OOP-friendly using SOLI...
46120
<p>I'm using this code to bring my phone numbers in a consistent format.</p> <blockquote> <p>Desired: <code>+(country code)phone number</code></p> </blockquote> <p>Possible patterns:</p> <blockquote> <p><code>01721234567</code> -&gt; change to desired pattern</p> <p><code>00491234567</code> -&gt; change to desired patt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T01:40:20.217", "Id": "80468", "Score": "0", "body": "Is there a reason not to remove all `+` and all leading zeroes as step 1, and then just add the leading `+` at the end? No country code begins with 0." }, { "ContentLicen...
[ { "body": "<p>There are two aspects to this, the general design, and the implementation.</p>\n<h2>Implementation</h2>\n<p>The entire things should be extracted as a function. The first line of code:</p>\n<blockquote>\n<pre><code>String number = allContactNumbers.get(i).get(j);\n</code></pre>\n</blockquote>\n<p>...
{ "AcceptedAnswerId": "46130", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T01:18:17.517", "Id": "46125", "Score": "9", "Tags": [ "java", "regex" ], "Title": "Bring phone numbers in consistent format" }
46125
<p>Please be brutal and let me know what you think of the code below, if written at an interview.</p> <p>Problem:</p> <blockquote> <p>Given an index <em>k</em>, return the kth row of the Pascal's triangle.</p> <p>For example, given k = 3, return [1,3,3,1].</p> <p><strong>Time it took:</strong><br> 25 mi...
[]
[ { "body": "<h2>Types</h2>\n<p>Given the description, I would assume that the return value is supposed to be <code>int[]</code> instead of <code>List&lt;Integer&gt;</code>....</p>\n<p>... but, you are not using the more general <code>List&lt;Integer&gt;</code> value, but instead the <code>ArrayList&lt;Integer&gt...
{ "AcceptedAnswerId": "46137", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T02:07:59.487", "Id": "46131", "Score": "5", "Tags": [ "java", "algorithm", "interview-questions" ], "Title": "Pascal triangle produced for a particular integer K" }
46131
<p>I have previeous;y posted my php code with way to many nested blocks I hope I fixed it right. </p> <p>I'd also like some tips on my OOP, as this is new to me.</p> <pre><code>class event { //Builds the event in html public function renderEvent($Array) { echo "&lt;/p&gt;"; echo "&lt;p&gt;"; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T03:10:36.447", "Id": "80477", "Score": "0", "body": "Please state the goal of your class so that we can help you refactor it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T03:56:55.123", "Id": "...
[ { "body": "<p>Given that this is a follow-up question, and <a href=\"https://codereview.stackexchange.com/questions/45801/i-have-a-huge-function-filled-with-nested-blocks\">I've dealt with some issues here already</a>, I'm not going to be as verbose. I will, however, refer to a couple of my initial critiques, a...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T02:59:06.123", "Id": "46133", "Score": "1", "Tags": [ "php", "beginner", "html", "datetime" ], "Title": "Too many nested blocks fixed but not sure if this way is right" }
46133
<p>I have taken a look at several answered questions on Stack Overflow about jQuery's new (since 1.9.1 upgrade)</p> <pre><code>.on('click','',function(){} </code></pre> <p>and that you need to delegate. However, in each one, it just provides the solution to fix the issue, but I need a bit more finest or an explanatio...
[]
[ { "body": "<p>I'm not sure this question really fits into the site but I'm going to answer it anyway. </p>\n\n<ol>\n<li><p>Since the elements don't exist when the page is loaded you can't add a click event to it (yet). If you try to attach the event handler directly to the elements at this time it won't do an...
{ "AcceptedAnswerId": "46147", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T03:09:21.797", "Id": "46135", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Is there a way to avoid calling the document with jQuery on click?" }
46135
<p>I've been trying to expand my programming horizons, and have entered the world of grammars and parsing, which I'm brand new to. I have been improving a little implementation of Dijkstra's shunting yard algorithm that currently handles negatives and parentheses correctly (which took a bit of work). I'm well aware tha...
[]
[ { "body": "<p>A few tips:</p>\n\n<ul>\n<li>Your function <code>is_numeric</code> is rather useless. There is a function named <code>std::isdigit</code> in the standard header <code>&lt;cctype&gt;</code> which does exactly the same thing.</li>\n<li>Instead of <code>skip_space</code>, I would have named the funct...
{ "AcceptedAnswerId": "46161", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T03:36:00.283", "Id": "46136", "Score": "8", "Tags": [ "c++", "c++11", "parsing" ], "Title": "Infix-to-postfix parser using Dijkstra's shunting yard algorithm" }
46136
<p>I have code that is used for retrieving and storing conversation for a chat application. I found this from a tutorial and tweak it a little bit. This script works fine but my concern is if it's the standard way. Can somebody please check this for me if to see if it's deprecated or a bad practice? And is there any ot...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T04:28:26.937", "Id": "80482", "Score": "0", "body": "Can you show a complete example, including what `receiveReq` and `sendReq` are" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T04:32:41.723", "...
[ { "body": "<p>This is really odd. As I read the code, I was thinking you'd go all-native. Then, suddenly a <code>$.get</code> is found at the bottom. You had jQuery all along! Why not go ahead and use it for all the AJAX functions you have. Overhead is not really a concern here, but readability and maintainabil...
{ "AcceptedAnswerId": "46149", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T03:57:08.193", "Id": "46138", "Score": "1", "Tags": [ "javascript", "jquery", "ajax", "chat" ], "Title": "AJAX chat client" }
46138
<p>I have an <code>Account</code>, <code>User</code> and <code>Group</code> model. All <code>User</code> and <code>Group</code> records belong to an <code>Account</code>, so it is possible for both users and groups to be related to various accounts.</p> <p>Basically, I have some really hacky, pieced together SQL queri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-21T04:31:04.847", "Id": "88530", "Score": "0", "body": "Is the SQL tag properly used here? Was looking for SQL to review in your code but found only tiny snippets. No bad karma just seems a bit misleading." } ]
[ { "body": "<p>I would try to use as much as possible what is provided by <code>ActiveRecord</code>. I was thinking to something like:</p>\n\n<pre><code>class Account &lt; ActiveRecord::Base\n belongs_to :accountable, touch: true, polymorphic: true\n CLAUSE_FOR_RELATED = '\"accounts\".\"accountable_type\" = \\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T04:05:16.287", "Id": "46139", "Score": "5", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Querying multiple related records in Rails" }
46139
<p>I need to further simplify this solution to auto-format a text-box field intended only for the user to enter their college Grade Point Average (GPA). Here is my code:</p> <pre><code>&lt;label for="collegeGPA"&gt;GPA:&lt;/label&gt; &lt;input type="text" name="collegeGPA" id="collegeGPA" maxlength="4" style="width:45...
[]
[ { "body": "<p>I'd maybe try something like the following. What I've done is remove the string manipulation and concentrate on rounding the numbers.</p>\n\n<pre><code>function formatGPA(originalGPA) {\n\n var originalGPAVal = originalGPA.value;\n var gPAVal = parseFloat(originalGPAVal);\n\n if (gPAVal &...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T05:17:12.037", "Id": "46146", "Score": "2", "Tags": [ "javascript", "validation" ], "Title": "Auto-Format GPA while typing : REVISED" }
46146
<p>Given a complete binary tree returns the following format (Parent ( leftchild (leftchild, rightchild), rightchild(leftchild,rightchild) ). Looking for code review, optimizations and best practices. </p> <pre><code>public final class PreOrderList { private TreeNode root; /** * Constructs a binary tree...
[]
[ { "body": "<p>I haven't fully parsed your code, but I would definitely add a check before creating the root. This <code>get(0)</code> would break on an empty list, and would break on a null list. Or you could throw an <code>IllegalArgumentException</code> as well.</p>\n", "comments": [], "meta_data": { ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T06:15:23.013", "Id": "46151", "Score": "1", "Tags": [ "java", "algorithm", "tree" ], "Title": "Preorder traversal of binary tree to produce formatted string" }
46151
<p>I am trying to create a <em>library</em> of my own which contains (among others), a <code>class</code> called <strong>Point</strong>. As the name suggests, it is intended to encapsulate a <em>point</em> represented in 2D space. This is what I've come up with:</p> <pre><code>package geom; import static java.lang.Ma...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T22:30:47.950", "Id": "80657", "Score": "4", "body": "The hashing could be more effective but it's actually fine. The `equals` depending on `hashCode` is very bad. We would not expect `(1, 0)` and `(0, 1)` to be considered equal and ...
[ { "body": "<p>This will be an incomplete review because I don't really know Java.</p>\n\n<p>Instead of <code>State</code> maybe call it <code>SummaryType</code> or <code>FormatType</code>.</p>\n\n<p>In <code>distanceFrom</code> I don't see why you have a special case for <code>other.equals(Point.ORIGIN)</code>;...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T06:15:55.120", "Id": "46152", "Score": "25", "Tags": [ "java", "design-patterns", "library", "library-design" ], "Title": "A Library Class : Point" }
46152
<p>I have a method that finds 3 numbers in an array that add up to a desired number.</p> <pre><code>public static void threeSum(int[] arr, int sum) { quicksort(arr, 0, arr.length - 1); for (int i = 0; i &lt; arr.length - 2; i++) { for (int j = 1; j &lt; arr.length - 1; j++) { for (int k = a...
[]
[ { "body": "<p>Are you looking for three distinct numbers, or can <em>i</em>, <em>j</em>, and <em>k</em> be the same? The loop limits suggest that you expect the numbers to be distinct. However, you don't actually check that the results are distinct.</p>\n\n<p>To be consistent, you should either:</p>\n\n<ul>\n...
{ "AcceptedAnswerId": "46158", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T06:43:24.283", "Id": "46153", "Score": "6", "Tags": [ "java", "performance", "complexity" ], "Title": "Performance analysis of 3 digits sum" }
46153
<pre><code>import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class LargestPalindrome{ static ArrayList&lt;String&gt; palinList=new ArrayList&lt;String&gt;(); public static void splitString(){ String actualString="ABCBAHELLOHOWRACECARAREYOUILOVEUEVOLIIAMAIDOIN...
[]
[ { "body": "<p><strong>Re-organising the code</strong></p>\n\n<p>You've tried to split the logic into small functions and that was a good idea. Unfortunately, because of the way it plays with a class member <code>palinList</code>, the flow is quite hard to follow. In order to avoid this, the best is to define sm...
{ "AcceptedAnswerId": "46163", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T07:22:10.897", "Id": "46157", "Score": "3", "Tags": [ "java", "palindrome" ], "Title": "Largest Palindrome Checker" }
46157
<p>I have implemented a <code>ThreadPoolExecutor</code> that will run a <code>Consumer&lt;T&gt;</code> only on elements not already consumed. This code uses Java 8.</p> <p>The background behind this is that I scan a directory every x time units for which files are present, I must maintain a 100% accuracy on finding fi...
[]
[ { "body": "<h1>.equals</h1>\n\n<p>The last part of your <code>.equals</code> implementation can be simplified to:</p>\n\n<pre><code>return Objects.equals(this.path, other.path) &amp;&amp; Objects.equals(this.fileTime, other.fileTime);\n</code></pre>\n\n<h1>HashCode</h1>\n\n<pre><code>int hash = 3;\nreturn hash;...
{ "AcceptedAnswerId": "46166", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T08:03:38.467", "Id": "46159", "Score": "11", "Tags": [ "java", "multithreading" ], "Title": "Extending ThreadPoolExecutor" }
46159
<p>I have a model Collection which has a many to many relation to a model Item.</p> <p>I want to be able to add or remove items to this collection using Django Rest Framework.</p> <p>Option1 - make an action:</p> <pre><code>class CollectionViewSet(viewsets.ModelViewSet): queryset = Collection.objects.all() s...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2019-02-20T14:42:01.827", "Id": "413693", "Score": "0", "body": "What about actions https://www.django-rest-framework.org/api-guide/viewsets/#marking-extra-actions-for-routing" } ]
[ { "body": "<p>If the collection is at another model then you must setup the serializer with the 'many' kwarg.</p>\n\n<pre><code>class CollectionContainerViewSet(viewsets.ModelViewSet):\n queryset = CollectionContainer.objects.all()\n collection_ids = serializers.PrimaryKeyRelatedField(\n ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T08:29:33.303", "Id": "46160", "Score": "16", "Tags": [ "python", "django" ], "Title": "Django Rest Framework - add/remove to a list" }
46160
<p>How could I reduce the length of my functions restricting them to max 10 lines? Other comments are welcome on the code in general.</p> <pre><code>import config_files import math from datetime import datetime import importlib import sys from scan_twittosphere import * from tweets import * import nltk debugger = impo...
[]
[ { "body": "<p>There is nothing inherently wrong with having methods longer than 10 lines. If there are no reusable elements in those methods then the only reason to break them into more methods is aesthetic (and can also improve readability if you name your methods well).</p>\n\n<p>A couple of comments on the r...
{ "AcceptedAnswerId": "46164", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T08:48:35.693", "Id": "46162", "Score": "5", "Tags": [ "python" ], "Title": "Reducing lines in methods of Python class to manage tweets" }
46162
<pre><code>#!/usr/bin/env python from os import environ, path, name as os_name, getuid from sys import exit from fileinput import input update_environ = lambda: environ.update(dict(env.split('=') for env in open('/etc/environment', 'r')....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T10:21:58.940", "Id": "80536", "Score": "0", "body": "Can you give some context? What is the purpose of this code? What are you trying to achieve?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T10:27:...
[ { "body": "<p><code>env | grep '^NOM'</code> would more exactly align with the sed command.</p>\n\n<p>ensure you're exactly matching the variable name:</p>\n\n<pre><code>sudo sed -i \"/^$VAR=/d\" /etc/environment\n# .................^\n</code></pre>\n\n<p>Use %-formatters for printf:</p>\n\n<pre><code>printf '...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T09:41:28.493", "Id": "46165", "Score": "4", "Tags": [ "python", "bash" ], "Title": "Setting global environment vars from Python or Bash" }
46165
<p>I have a completed application which I'm trying to write unit tests for (Yeah I know, talk about bad practices)</p> <p>I have the following class here</p> <pre><code>public class UserManagementService : IUserManagementService { private static readonly IUserDao userDao = DataAccess.UserDao; private stat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T12:27:58.867", "Id": "80569", "Score": "0", "body": "FYI I prefer [automated system tests instead of automated unit tests](http://stackoverflow.com/q/856115/49942)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>Following on what Magnus said in comments can you not inject the necessary dependencies.</p>\n\n<p>For example:</p>\n\n<pre><code>public class UserManagementService : IUserManagementService\n{ \n private readonly IUserDao userDao ;\n private readonly ILog log;\n\n public UserManagement...
{ "AcceptedAnswerId": "46212", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T10:45:09.850", "Id": "46172", "Score": "8", "Tags": [ "c#", "unit-testing", "dependency-injection" ], "Title": "Refactoring method to make it unit testing friendly" }
46172
<p>I'm doing VBA macros and need to use Arrays of values extensively. After the below help from @TonyDallimore on Stack Overflow, I've decided to use nested variant arrays.</p> <p><a href="https://stackoverflow.com/questions/20971161/vba-chrashes-when-trying-to-execute-generated-sub/20973615#20973615">VBA chrashes whe...
[]
[ { "body": "<p>Regarding the not-listed <code>IsArrInitialized</code>, after investigating on StackOverflow, I ended up using this:</p>\n<pre><code>Private Declare Sub CopyMemory Lib &quot;kernel32&quot; Alias &quot;RtlMoveMemory&quot; _\n (pDst As Any, pSrc As Any, ByVal ByteLen As...
{ "AcceptedAnswerId": "46203", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T10:55:23.330", "Id": "46174", "Score": "6", "Tags": [ "array", "unit-testing", "vba" ], "Title": "Ranking a variant array with variable dimensions" }
46174
<p>I have the below enum. I need to get the description by code. It is working but can it be improved still? </p> <pre><code>public enum Maps { COLOR_RED("ABC", "abc description"); private final String code; private final String description; private static Map&lt;String, String&gt; mMap; private...
[]
[ { "body": "<p>Your code is very neat and clean, there is only one thing that I would change:</p>\n\n<pre><code>private static Map&lt;String, String&gt; mMap;\n</code></pre>\n\n<p>to</p>\n\n<pre><code>private static final Map&lt;String, String&gt; mMap = Collections.unmodifiableMap(initializeMapping());\n</code>...
{ "AcceptedAnswerId": "46178", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T11:17:33.700", "Id": "46175", "Score": "39", "Tags": [ "java", "enum", "hash-map" ], "Title": "Java enum containing a hash map for look up" }
46175
<p>I need to use SQL extensively in VBA macros that I write. Since the DB is from our enterprise application, I use vendor's library for this.</p> <p>I generate dynamic queries, sometimes with many <code>JOIN</code>s and <code>UNION</code>s, and the queries can be quite complex.</p> <p>The procedure that I coded scre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T18:47:35.310", "Id": "80856", "Score": "1", "body": "You can take a look at [this code](http://codereview.stackexchange.com/questions/46312/simplistic-naive-adodb-wrapper) that lets you easily create parameterized ADODB queries (wro...
[ { "body": "<h3>Error Handling / Execution Flow: Beware of Raptors</h3>\n<p>I realize you haven't implemented it yet, but you've set yourself up for some twisted execution flow:</p>\n<pre><code> Exit Function 'fixed indentation\nErrorHandler:\n EvaluateQuery = &quot;&quot;\nEnd Function\n</code></pre>\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T11:36:51.417", "Id": "46177", "Score": "5", "Tags": [ "vba", "sql-injection" ], "Title": "Making VBA generated dynamic SQL statements safe against injection" }
46177
<p>I got the point of PEP8 naming conventions, docstrings going inside methods, catching exceptions and printing them, not doing import *. will correct them. </p> <p>I need a bit of advice on the robustness and flexibility for the following code. Do you find the variable names descriptive and the flow of code optimal...
[]
[ { "body": "<ol>\n<li><p>Please wrap your code at column 80. Otherwise, we have to do a lot of sideways scrolling to read it. Besides, 79 byte lines is <a href=\"http://legacy.python.org/dev/peps/pep-0008/#maximum-line-length\" rel=\"nofollow\">what PEP8 recommends</a>.</p></li>\n<li><p>Your variable and method ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T12:17:14.173", "Id": "46182", "Score": "3", "Tags": [ "python" ], "Title": "Robustness and maintanability based on descriptiveness of variables and docstrings" }
46182
<p>So the two functions below both send emails via PHPMailer but both hold different messages (which use different data from the db). I was just wondering (as I plan to use PHPMailer more) a way to consolidate these functions into perhaps a <code>sendMail()</code> function which could handle different data variables an...
[]
[ { "body": "<p>You should pass the body of the mail as an argument and it will do what you need. The body part should have been on the outside and independent of the mailing function. This way if you decide to expand this - you wont need to copy paste a third version</p>\n", "comments": [ { "Co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T12:40:12.060", "Id": "46183", "Score": "1", "Tags": [ "php", "optimization", "php5", "email" ], "Title": "Optimising and consolidating multiple PHPMailer functions" }
46183
<h1>Problem Statement</h1> <blockquote> <p><strong>Input</strong></p> <p>The input begins with the number t of test cases in a single line (t&lt;=10). In each of the next t lines there are two numbers m and n (1 &lt;= m &lt;= n &lt;= 1000000000, n-m&lt;=100000) separated by a space.</p> <p><strong>Output</strong></p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T15:13:48.953", "Id": "80599", "Score": "0", "body": "The accepted answer to [your previous question](http://codereview.stackexchange.com/q/45857/10916) proposes a more efficient implementation of the sieve. Have you not tried it her...
[ { "body": "<p><strong>Re-organising the code</strong></p>\n\n<p>A quite easy thing to start with is to split the logic into a part collecting the input and a part performing computation from this input. This makes things clearer but also this might make testing easier and make some optimisations possible later ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T13:29:10.957", "Id": "46187", "Score": "5", "Tags": [ "python", "programming-challenge", "primes", "time-limit-exceeded" ], "Title": "Prime generator program SPOJ time limit e...
46187
<p>I have some concerns on my refactoring for the data layer in my current Project. Just for a small info, I am currently building a CRM as "training JEE application". But enough of talk, let's talk code!</p> <p><strong>IService.java:</strong> (7 lines, 160 bytes)</p> <pre><code>public interface IService&lt;T&gt; { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T15:09:28.173", "Id": "80596", "Score": "6", "body": "+1 simply for using my [question generator tool](http://codereview.stackexchange.com/questions/41225/follow-up-to-tool-for-posting-code-review-questions) :)" }, { "Content...
[ { "body": "<p>This answer will reflect the naming convention at my work. </p>\n\n<p><strong>Naming Convention</strong></p>\n\n<p>Prefixing <code>I</code> to all your interface seems superfluous, since we use a simple name like <code>ContractService</code>. The implementation class would have <code>Impl</code> s...
{ "AcceptedAnswerId": "46197", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T15:04:45.703", "Id": "46194", "Score": "12", "Tags": [ "java", "inheritance", "interface" ], "Title": "DataLayer Interfaces Genericized" }
46194
<p>I am implementing merge sort in Java and I have a performance problem in this method:</p> <pre><code> private static void marge(int[] source, int[] buffer, int startingIndex, int count) { int index1 = startingIndex; int index2 = startingIndex + count / 2; int maxIndex1 = index2; i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T15:31:00.227", "Id": "80609", "Score": "5", "body": "`System.arraycopy` calls native code, so it will always be *much* faster: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/System.java#System...
[ { "body": "<p>Some pointers:</p>\n\n<ul>\n<li><p>You keep adding 2 numbers here: <code>startingIndex + i</code>, that could probably be avoided if you went <code>for(int i = startIndex; i &lt; lastIndex; i++){</code> where <code>lastIndex</code> would be <code>startIndex + count</code></p></li>\n<li><p>Since <c...
{ "AcceptedAnswerId": "46200", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T15:24:36.340", "Id": "46198", "Score": "6", "Tags": [ "java", "performance", "sorting", "mergesort" ], "Title": "Merge sort could work 10 times faster" }
46198
<p>Let's say that I have a method that makes an HTTP request that will take a long time to finish. While that's happening the UI is not updating because I'm doing it in the UI's thread. </p> <p>One solution is to:</p> <ol> <li>Show the "Loading" animation.</li> <li>Start the HTTP request on a thread.</li> <li>On the ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T18:56:44.330", "Id": "80640", "Score": "0", "body": "“plus I need .NET 4.5” You don't, you can use `async`-`await` on .Net 4.0 using [Microsoft.Bcl.Async](http://nuget.org/packages/Microsoft.Bcl.Async). But you do need at least VS 2...
[ { "body": "<p>Good you have a <code>BackgroundWorker</code>. If I understood correctly, let's say you want to update a button, whether to enable it or not. you can use this:</p>\n\n<pre><code>delegate void EnableButton(Button b, bool enable);\npublic void ActuallyEnableButton(Button b, bool enable)\n{\n if (...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T15:25:53.873", "Id": "46199", "Score": "3", "Tags": [ "c#", "wpf" ], "Title": "Keep the sequential nature while updating the UI of the progress of the HTTP request" }
46199
<p>This tag is obsolete. Don't use it. See <a href="http://meta.codereview.stackexchange.com/q/1694/9357">Tag soup: [dijkstra]</a></p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T17:06:35.637", "Id": "46205", "Score": "0", "Tags": null, "Title": null }
46205
This tag is obsolete. Don't use it.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T17:06:35.637", "Id": "46206", "Score": "0", "Tags": null, "Title": null }
46206
<p>I usually take my school code as a playground to mess around with things. I was given a bunch of premade hash functions and had to test their output and find when they reach a specific lower range. Since the functions all have the same structure, I made a check function that uses a function pointer parameter(I think...
[]
[ { "body": "<p>Your code does seem open to some improvement. Right now, you're not really getting much good out of using a pointer to a function. You could just about as well invoke each hash function directly in <code>findLowHash</code> as call it via a pointer in <code>foundLow</code>.</p>\n\n<p>In this case, ...
{ "AcceptedAnswerId": "46232", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T19:57:22.700", "Id": "46214", "Score": "5", "Tags": [ "c++", "bitwise", "hashcode" ], "Title": "Eliminating repetitiveness in code to test hash functions" }
46214
<p>I have the following method in a web service class. I'm a little unhappy about the big block of <code>new JProperty(...)</code> calls in the for loop. Is there a way to simplify that?</p> <pre><code>public string UserCatalog(string numericSessionId, JObject incomingRequestJson) { JObject json = new JObjec...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T21:46:39.300", "Id": "80654", "Score": "2", "body": "why do you want to simplify it? it looks very simple. In other words, I'm curious about what you don't like about it.\n\nYou could 'Extract Method' on the line that initializes th...
[ { "body": "<p>If you want to remove the big block of new JProperties, then you need to abstract what varies and find a way in which you can loop over the list of properties you wish to serialise to JSON. You can do this using reflection, which won't be as fast as this code, but it would be more generic and reu...
{ "AcceptedAnswerId": "46227", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T21:06:08.880", "Id": "46217", "Score": "3", "Tags": [ "c#", "json" ], "Title": "Simplifying a web service method" }
46217
<p>I made a search method because I want to use binary data like PNG files. The point of this is to be able to find strings like <code>IEND</code> in a PNG file. I think it works properly. Any improvements/fixes would be appreciated.</p> <pre><code>public static int findString(byte[] in, byte[] find) { boolean...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T11:56:18.657", "Id": "80734", "Score": "0", "body": "Your edit invalidates advice that was already given in an existing answer, and is therefore not allowable. I've rolled Rev 3 back to Rev 2." } ]
[ { "body": "<ol>\n<li><p>I might have misunderstood something but both of these tests fail:</p>\n\n<pre><code>@Test\npublic void test3() {\n byte[] in = { 1, 2, 3, 4, 5, 6 };\n byte[] find = { 3, 4, 5 };\n assertEquals(2, findString(in, find)); // returns -1\n}\n\n@Test\npublic void test5() {\n byte[...
{ "AcceptedAnswerId": "46224", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T22:09:47.703", "Id": "46220", "Score": "11", "Tags": [ "java", "array", "search" ], "Title": "Find byte[] in byte[] with Java" }
46220
<ol> <li>What is the best method/practice to keep, let's say, over 3,000 lines of code organized for readability?</li> <li>What kind of NO-NOs in regards to coding habits should I get rid of before they become bad habits?</li> <li>Inversely what kind of good coding habits should I be picking up?</li> <li>Any glaringly ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T23:14:52.860", "Id": "80660", "Score": "2", "body": "Could you please explain the purpose of this code? Titles here should also reflect on that." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T00:22:...
[ { "body": "<p>As a piece of code for a “beginner” (reading from the tag), this is pretty good. I’ll start by offering some suggestions on your specific questions, and then make some comments on the code itself:</p>\n\n<ol>\n<li><p><strong>What is the best method/practice to keep, let's say, over 3,000 lines of ...
{ "AcceptedAnswerId": "46240", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T22:56:08.170", "Id": "46223", "Score": "11", "Tags": [ "python", "beginner", "gui" ], "Title": "wxPython Item Information Scraper" }
46223
<p>I wrote a small utility function that divides a total into <em>n</em> parts in the ratio given in <code>load_list</code>. Numbers in each part should be positive integers. It supports an optional <code>min_num</code> argument that, when specified, puts at least <code>min_num</code> in each of the <em>n</em> parts be...
[]
[ { "body": "<p>Because the problem is not quite formalised and is mostly defined by the way your code currently works, I must confess that I find it quite hard to make thinds more efficient/concise.</p>\n\n<p>A few point however:</p>\n\n<ul>\n<li>using <code>( len(num_loads) * min_num )</code> un-necessarly reli...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T01:17:47.510", "Id": "46226", "Score": "5", "Tags": [ "python" ], "Title": "Utility function to split a number into n parts in the given ratio" }
46226
<p>Here's a program to take a bitfield like 7 and decompose it into the flags [1,2,4]. Ignore that the algorithm for doing this doesn't use bit shifting/is stupid.</p> <p>Problems: it seems like I have to have the <code>bithelp</code> function for the sole purpose of calling the other ones, since <code>getFlags</code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T03:39:20.580", "Id": "80670", "Score": "1", "body": "`Is there any other way to do what they're doing without recursion? Is recursion like this the standard way to \"loop\" in FP?` Yes, recursion is the only way to loop in Pure FP l...
[ { "body": "<p>A more common way of \"initializing\" values on the first call is to define an inner worker function.</p>\n\n<pre><code>findPower :: Int -&gt; Int\nfindPower bitfield = go 0\n where go i = ... -- Note that the bitfield argument is still in scope\n</code></pre>\n\n<p>Recursion is the standard wa...
{ "AcceptedAnswerId": "46230", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T02:20:01.253", "Id": "46228", "Score": "6", "Tags": [ "haskell", "functional-programming", "bitwise" ], "Title": "Decomposing bitfield with Haskell: is recursion the only way t...
46228
<p>I'm looking for code-review, optimization and best practices. Also verifying complexity to be O(E) time and O(V+E) space complexity.</p> <pre><code>final class NodeClone&lt;T&gt; { private final T item; NodeClone(T item) { this.item = item; } public T getItem() { return item; }...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T16:09:34.080", "Id": "81162", "Score": "0", "body": "Can you describe in more detail what you are trying to do? It seems that you should not create any new classes, but just write a method to clone your original graph. But I'm not...
[ { "body": "<p>looking at it I came across what might be an issue. When you are cloning the graph you create new nodes, that is good. <strong>However</strong>, the edge objects stays the same so they are pointing to the old NodeClone objects. So this way they are actually pointing to the nodes in the \"old\" gra...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T06:54:19.043", "Id": "46237", "Score": "3", "Tags": [ "java", "algorithm", "graph" ], "Title": "Clone an undirected graph" }
46237
<p>I have been trying to get as close to SRP in my code as possible. I have a situation where I need to log leads when interactions happen for a contact. A lead may be created or updated. There are three different states that I would like to set leads to.</p> <ul> <li>Active - new interested interactions causes active...
[]
[ { "body": "<p>I'm not sure how you intend to use this class, but the <code>call</code> method is very fishy. This method seems to do one of three things: <code>convert_lead</code>, <code>activate_lead</code> or <code>stale_lead</code>. The choice of which of them should actually be executed is made in the <code...
{ "AcceptedAnswerId": "46241", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T06:57:57.843", "Id": "46238", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Logging leads when interactions happen for a contact" }
46238
<p>Here is my single parse code for splitting a <code>std::string</code> on a <code>char</code> into a <code>std::vector&lt;std::string&gt;</code>:</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; std::vector&lt;std::string&gt; split_uri(std::string, unsigned chr='/'); int main() { std::vector&lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T08:58:02.177", "Id": "80694", "Score": "0", "body": "Your edit is invalid: `case chr:` won't work since `chr` is not a constant expression." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T08:58:23.620...
[ { "body": "<p>First, consider passing potentially expensive-to-copy objects such as <code>std::string</code> as const reference rather than by-value. The obvious approach is to use <code>std::istringstream</code> and <code>std::getline</code>.</p>\n\n<pre><code>std::vector&lt;std::string&gt; split_uri(const std...
{ "AcceptedAnswerId": "46245", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T08:47:47.797", "Id": "46242", "Score": "2", "Tags": [ "c++", "performance", "memory-management", "vectors", "cyclomatic-complexity" ], "Title": "split string into conta...
46242
<p>I want to split a list using another list which contains the lengths of each split.</p> <p>E.g:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; print list(split_by_lengths(list('abcdefg'), [2,1])) ... [['a', 'b'], ['c'], ['d', 'e', 'f', 'g']] &gt;&gt;&gt; print list(split_by_lengths(list('abcdefg'...
[]
[ { "body": "<p>You can do it by just slicing the sequence &mdash; there's really no advantage to having a helper function like<code>take()</code>. I also added a keyword argument to make the returning of anything remaining optional.</p>\n\n<pre><code>def split_by_lengths(sequence, lengths, remainder=True):\n ...
{ "AcceptedAnswerId": "46249", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T09:39:54.243", "Id": "46246", "Score": "8", "Tags": [ "python" ], "Title": "Split a list using another list whose items are the split lengths" }
46246
<p>I am working on some code and I have come across the following:</p> <pre><code>private int getPosition() { List&lt;IDescriptor&gt; fragmentDescriptors = new ArrayList&lt;IDescriptor&gt;(mDescriptors); int position = -1; for (IDescriptor fragmentDescriptor : fragmentDescriptors) { if (fragm...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T12:10:34.730", "Id": "80740", "Score": "1", "body": "What kind of changes are you afraid of? If the name of the class changes, how do you think you will be able to identify this (or any other relevant) class?" }, { "ContentL...
[ { "body": "<p>Are you asking if you can find the first element in a list of a certain type without asking for its type? That's a strange question... What's wrong with <code>instanceof</code>?</p>\n\n<p>As for the code, being code-review, I've got some observations:</p>\n\n<p>This code actually finds the <em>las...
{ "AcceptedAnswerId": "46263", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T09:51:35.407", "Id": "46248", "Score": "2", "Tags": [ "java", "design-patterns" ], "Title": "Avoiding instanceOf when finding index of an interface within a list" }
46248
<p>I'm using an API which returns text in the following format:</p> <pre><code>#start #p 09060 20131010 #p 09180 AK #p 01001 19110212982 #end #start #p 09060 20131110 #p 09180 AB #p 01001 12110212982 #end </code></pre> <p>I'm converting this to a list of objects:</p> <pre><code>var result = data.match(/#start[\s\S]+...
[]
[ { "body": "<p>If you use regular expressions for parsing, then I would recommend using them for everything. Here's a solution that proceeds line by line, using capturing parentheses to see what the line contained.</p>\n\n<pre><code>function parse(data) {\n var re = /(#start)|(#end)|#p\\s+(\\S+)\\s+(\\S+)/ig...
{ "AcceptedAnswerId": "46259", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T10:32:28.727", "Id": "46250", "Score": "6", "Tags": [ "javascript", "performance", "jquery", "parsing", "regex" ], "Title": "Performance tuning on a text file to object...
46250
<p>I've been following along a blog post on <a href="http://www.2ality.com/2012/01/js-inheritance-by-example.html" rel="nofollow noreferrer">JavaScript inheritance</a>. I wanted to slightly adapt this and try to write something more like I've seen in Backbone (extend method). See I set about it, and run into problems. ...
[]
[ { "body": "<p>I think you cannot move parent constructor call out of child constructor. At least because you have different parameters, extend function cannot guess what kind of parameters it should pass.</p>\n\n<p>But even if you standardize all constructors, you will have to make a \"smart\" constructor in Ba...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T11:22:02.007", "Id": "46254", "Score": "4", "Tags": [ "javascript" ], "Title": "Good way to write extend method of a contructor?" }
46254
<pre><code>import java.util.Collections;//for frequency of words import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.ArrayList; import java.util.Scanner; import java.util.Arrays; /** Output--In phrase count duplicate substrings or strings or with space psuedo code--- 1.splt phrase...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-11T11:54:49.173", "Id": "82098", "Score": "0", "body": "Please see this meta-post about [appropriate ways to edit your post after it has been reviewed](http://meta.codereview.stackexchange.com/questions/1482/can-i-edit-my-own-question-...
[ { "body": "<h1>Spaces</h1>\n<p>I see many code segments like this:</p>\n<pre><code>splitleng&gt;0\nstring_to_test=1\nstring_to_test=sc.nextInt()\n</code></pre>\n<p>Put spaces between your two expressions to result in this:</p>\n<pre><code>splitleng &gt; 0\nstring_to_test = 1\nstring_to_test = sc.nextInt()\n</co...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T11:32:19.810", "Id": "46257", "Score": "4", "Tags": [ "java", "strings" ], "Title": "Word duplicate finder and counter" }
46257
<p>I made a command line Hacker News reader in Ruby that pulls the latest 10 stories from HN and allows the user to cycle through them or open them with Launchy. This was to play around with Ruby and APIs.</p> <p>The data that I pulled from HN was messy, like an array of hashes with arrays and hashes inside. I feel li...
[]
[ { "body": "<p><strong>Redundant operations</strong><br>\nAfter reading the data from the web service, you go over it a number of times, which seems redundant:</p>\n\n<blockquote>\n<pre><code>results = parsed.reject { |key, value| key != \"results\"}\n</code></pre>\n</blockquote>\n\n<p>Why is that important? You...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T11:40:21.613", "Id": "46258", "Score": "4", "Tags": [ "beginner", "ruby", "json" ], "Title": "Refactor Ruby code from Hacker News API. Trouble parsing the JSON data" }
46258