body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Any ideas to simplify this beauty; I would prefer a LinQ expression if possible:</p> <pre><code>private object[] array; public abstract bool Condition(object o); //... private object FindStuff() { for (int i = 0; i &lt; array.Length; i++) { if (Condition(array[i])) { return i == ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T21:28:40.547", "Id": "89725", "Score": "0", "body": "Using the assumption, that there is an `object foo;` as a non-valid data-placeholder, I have a new approach but I hate it even more:\n\n `return array.Select((t, i) => Conditio...
[ { "body": "<p>This code would benefit from a <code>previous</code> variable...... and it would also benefit from being <em>real</em> code, not this hypothetical example..... This code is also really short, so it's hard to simplify more.</p>\n\n<p>Still, using a foreach is better than the indexed iterator, and t...
{ "AcceptedAnswerId": "51866", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T20:37:44.217", "Id": "51860", "Score": "9", "Tags": [ "c#", ".net", "linq" ], "Title": "Take previous element from array if condition on current element matches" }
51860
<p>This program calculates the \$n\$th fibonacci number, in \$O(\log n)\$ time. I'm looking for code review, optimizations, and best practices.</p> <pre><code>public final class Fibo { private Fibo() { } public static int getNthfibo(int n) { if (n &lt; 0) { throw new IllegalArgumentExcept...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T21:30:00.907", "Id": "89726", "Score": "0", "body": "Small nitpick: `n = n / 2;` can just be `n /= 2;`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T23:20:40.073", "Id": "90104", "Score": "...
[ { "body": "<p>Your code seems to be working properly so there is not much to say on this.</p>\n\n<p>The only changes I would perform would be to make things easier to understand through different little steps.</p>\n\n<ul>\n<li><p>Multiplication could return a result</p>\n\n<p>At the moment, your multiplication ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T21:26:03.760", "Id": "51864", "Score": "7", "Tags": [ "java", "matrix", "fibonacci-sequence" ], "Title": "Calculate fibonacci in O(log n)" }
51864
<p>I am working on a simple "to do list" app in Django (two models: <code>List</code> and <code>Item</code>). I'm trying to learn and make use of class-based generic views. I have the following three display views working, but am requesting a quick code review to see if there's anything I can do to improve my usage/un...
[]
[ { "body": "<p>This looks pretty good -- views should generally be pretty minimal. These seem pretty short, and most of what you've done so far seems appropriate. </p>\n\n<p>One pattern you might think about is using a mixin to dry things out a touch more. Eg, you have all your <code>dispatch</code> methods deco...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T21:27:10.317", "Id": "51865", "Score": "3", "Tags": [ "python", "django" ], "Title": "Django class-based generic views - am I doing it right?" }
51865
Cocoa Touch is a UI framework for building software programs to run on the iOS operating system from Apple, Inc. It is based on the Mac OSX Cocoa API toolset.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T22:35:55.997", "Id": "51870", "Score": "0", "Tags": null, "Title": null }
51870
<p>I decided on making a small notepad editor in Java using Swing and I think it functions pretty well. Unfortunately, my skills in making my project tidy and organized has abandoned me; it looks like spaghetti code, which many renowned programmers discourage from doing.</p> <p>What can I do to make my code simpler?</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T04:37:07.843", "Id": "89752", "Score": "1", "body": "You import javax.swing.JCheckBoxMenuItem and then import javax.swing.* which makes the first import redundant. Also you should refrain from creating 'utilities' classes unless you...
[ { "body": "<h2>General</h2>\n\n<ul>\n<li><p>Java puts the <code>{</code> opening brace on the same line as the control-block, not the next line:</p>\n\n<blockquote>\n<pre><code> if (overWrite)\n {\n try\n {\n ....\n</code></pre>\n</blockquote>\n\n<p>should be:</p>\n\n<pre><code> ...
{ "AcceptedAnswerId": "51872", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T22:56:38.003", "Id": "51871", "Score": "5", "Tags": [ "java", "optimization", "swing", "gui" ], "Title": "Small notepad editor" }
51871
<p>I recently wrote a DSN class for use with the Access flavor of VBA. I'm preparing to refactor and would appreciate feedback.</p> <p>I am aware of two issues.</p> <ol> <li>I added the <code>findSectionKey()</code> function to the Registry class (which is separate and out of scope for this question) that I call, but...
[]
[ { "body": "<p>This constant is not needed, and if you decided to rename the class to <code>DomainNameService</code>, it would be telling a lie:</p>\n\n<blockquote>\n<pre><code>Private Const CLASS_NAME As String = \"DSN\" 'for error handling\n</code></pre>\n</blockquote>\n\n<p>Instead, use <code>TypeName(Me)</co...
{ "AcceptedAnswerId": "51882", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T00:14:41.167", "Id": "51873", "Score": "9", "Tags": [ "vba" ], "Title": "Domain Name Service Class" }
51873
<p>Would someone tell how I can improve this piece of code?</p> <pre><code>&lt;?php include_once './Core/Database/Db_connection.php'; class Post extends Db_connection { private $totalPage; private $per_page; private $page; function __construct() { parent::__construct(); } function...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T00:50:42.887", "Id": "89741", "Score": "2", "body": "Welcome to Code Review! It's usually better to provide reviewers with a bit of context; tell us what your code is doing, what aspects of it you're concerned with. This will help y...
[ { "body": "<p>If the code will be distributed, read or maintained by others, you might want to look at your naming conventions as they're a bit inconsistent, for example sometimes you use underscore separated names such as <code>get_per_page()</code>, but other times you use sulkingCamelCase such as <code>postB...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T00:41:05.157", "Id": "51875", "Score": "4", "Tags": [ "php", "beginner", "classes", "mysqli" ], "Title": "Blog engine or somesuch" }
51875
<p>For a given file name path, I need to get the folder one level before it. This can be accomplished in ruby with the following code:</p> <pre><code>File.dirname(File.dirname("/a/b/c.txt")) =&gt; "/a" </code></pre> <p>Independently from this exact case, how can I DRY two method calls in sequence?</p>
[]
[ { "body": "<p>You should consider any DRYing efforts in terms of its effects on code clarity. I don't think that trying to reduce <code>foo(foo(bar))</code> is worth the reduced clarity. Now, if we're trying to reduce <code>foo(foo(foo(foo(foo(bar)))))</code>, that's something else. One way you can do that is u...
{ "AcceptedAnswerId": "51881", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T01:57:33.450", "Id": "51878", "Score": "2", "Tags": [ "ruby" ], "Title": "Avoid calling nested method two times" }
51878
<p>Using .net 3.5, implementation of the repository pattern along with enterprise library 5 and stored procedures. Did not use EF, stored procedures already available and VS2008 is limited to EF 3/4.</p> <p>Looking at the following code, what are your recommendations for each section:</p> <h2>Domain/Repositories/IRep...
[]
[ { "body": "<p>Both of these return a variable that you define within the block itself, so you should just return what you need instead of creating a variable</p>\n\n<pre><code> public static IEnumerable&lt;Request&gt; GetRequests(){\n SqlDatabase db = new SqlDatabase(_connectionString);\n var r...
{ "AcceptedAnswerId": "51921", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T02:13:16.750", "Id": "51879", "Score": "7", "Tags": [ "c#", "stored-procedure", "repository" ], "Title": "Implementing repository pattern and DAL with stored procedures" }
51879
<p>I find myself frequently converting between formats, so I have come up with the following conversion framework. The converter interface surfaces a method to convert from a source type to a target type.</p> <pre><code>public interface IConverter&lt;in TSource, out TTarget&gt; { TTarget Convert(TSource source); }...
[]
[ { "body": "<p>I only scan read the very well written question (sorry it was late!) but:</p>\n\n<blockquote>\n <p>Am I reinventing the wheel? I couldn't find anything like it in the .NET framework but I also did not look very hard.</p>\n</blockquote>\n\n<p>As I understand it, yes. </p>\n\n<p>I believe all you'r...
{ "AcceptedAnswerId": "51942", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T06:00:54.697", "Id": "51889", "Score": "13", "Tags": [ "c#", "design-patterns", ".net", "converting", "framework" ], "Title": "Generic Converter framework" }
51889
<p>I've written a program for calculating the future date after certain number of business days.</p> <pre><code>function add_business_days($startdate,$businessdays,$holidays,$dateformat){ $i=1; $dayx = strtotime($startdate); while($i &lt; $businessdays){ $day = date('N',$dayx); $date = dat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-04-10T14:18:23.843", "Id": "155976", "Score": "0", "body": "Oh, I believe the DateTime::modify function does the job straight away: $startdate = new \\DateTime(\"2014-05-28\"); $my_date->modify(\"+ 7 weekday\"); Ok, we still have to deal ...
[ { "body": "<p>I propose a class, <code>BusinessDayCalculator</code>, which would handle all this logic in one place. Here's an example:</p>\n\n<pre><code>&lt;?php\n\nclass BusinessDaysCalculator {\n\n const MONDAY = 1;\n const TUESDAY = 2;\n const WEDNESDAY = 3;\n const THURSDAY = 4;\n cons...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T10:44:37.957", "Id": "51895", "Score": "20", "Tags": [ "php", "datetime" ], "Title": "Calculate future date based on business days" }
51895
<p>I'm new to C# and OOP and am struggling to move away from the procedural way of doing things. I understand the tutorials I have looked at but find it more difficult when actually doing something a little more involved. </p> <p>The code works out the number of presses and time taken for the supplied message.</p> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T12:32:19.533", "Id": "89954", "Score": "0", "body": "For posterity sake will you please rollback your last 2 edits, and instead post your new code either as a new post, or as a new section in your original question. (You shouldn't c...
[ { "body": "<p>Give your form a meaningful class name instead of <code>Form1</code></p>\n\n<hr>\n\n<p>Remove the <code>Form1_Load</code> method, and be sure to remove the event handler in the GUI designer from your main form.</p>\n\n<hr>\n\n<p>use <code>foreach</code> iterator instead of <code>for</code>, I also...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T11:50:00.060", "Id": "51898", "Score": "6", "Tags": [ "c#", "beginner", "object-oriented", "winforms" ], "Title": "Message estimator" }
51898
<p>I'm trying to set up a very lightweight permission system using Google App Engine and Flask.</p> <p>The end result I am hoping for is that each individual view is its own permission, and in an admin panel you can assign the views each user is allowed to see.</p> <p>How would I set this up better? It works fine, bu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T15:31:09.067", "Id": "90006", "Score": "0", "body": "Just a nit-pick, near the end of `user_authorized`, you could simply `return rule in user_info.permissions` instead of the `if-else`" }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>The first thing that comes to mind is just to cache user permissions in memcache, but that might or might not be necessary. I'd try this way first and see if you run into issues. </p>\n\n<p>A simpler approach would be to define each user's key to be their username, then use get_by_id(). That has t...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T12:55:45.970", "Id": "51901", "Score": "7", "Tags": [ "python", "google-app-engine", "flask" ], "Title": "Subclassing Flask for Permissions with Google App Engine" }
51901
<p>I am new to programming and entirely self-taught. Below is a program I wrote to retrieve text content via an API and scan the text for important words. If the word is found URI is returned. The API returns data in JSON. The important words and URIs are linked via a dictionary. It works. I'm at a point in my programm...
[]
[ { "body": "<p>I have a few pointers, a lot of them coming from <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">Python's offical style guide</a>:</p>\n\n<ol>\n<li><p>ALWAYS use <code>with</code> syntax when dealing with files:</p>\n\n<pre><code>with open('some_file.txt', 'r') as file:\n ...
{ "AcceptedAnswerId": "51916", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T14:13:26.003", "Id": "51908", "Score": "6", "Tags": [ "python", "beginner", "json", "api" ], "Title": "Clean and tidy Python code for dictionary look up and API interaction...
51908
<p>A friend of mine has a spreadsheet where she coded a classroom video for various teaching events, which I needed to help her plot. For each recording, she used several video cassettes, and her time codes were relative to each video cassette (ie. they always start on 0). To be able to plot these on a timeline, I need...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T14:27:01.447", "Id": "89808", "Score": "0", "body": "One quick fix would probably be to apply this to the data from each instructor, thus obviating the need for tracking instructor and checking when it changes, etc. However, this is...
[ { "body": "<p>R encourages vector-based operations instead of loops. But in this case, I don't think there's a good way around tracking the state of <code>delta</code>. </p>\n\n<p>This might be a slightly better way to create a vector <code>delta</code>:</p>\n\n<pre><code>delta &lt;- 0\nvdelta &lt;- c(0)\nfor (...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T14:21:02.180", "Id": "51910", "Score": "4", "Tags": [ "r" ], "Title": "Imperative code in R keeping track of state" }
51910
<h1>Description</h1> <p>To make it simple, this code is the Controller Packet corresponding to a View with multiple tabs. All but one of these tabs are showing a list of dependent entries. This Construction was once a single class, that did <strong>everything</strong> and I thought "Why not refactor that thing?"</p> ...
[]
[ { "body": "<h2>Scoping :</h2>\n\n<p>In your controllers are all your services default scoped.<br/>\nIn mine humble oppinion make them private, if you wish to have the default scope make getters and setters default scope.<br/>\n<b>Why:</b> You easily can forget the private before a global variable but getters/se...
{ "AcceptedAnswerId": "52248", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T14:36:16.363", "Id": "51911", "Score": "9", "Tags": [ "java", "jsf-2" ], "Title": "Show Details of an Object while allowing interactions with it and dependent objects" }
51911
<p>I am using a script to open a bunch of Excel files, copying two or more sheets into a new file and saving this new file. It sure beats doing it manually, but I think it could be faster.</p> <p>Here's my script:</p> <pre><code>Sub Flujo() Const FilePath = "A path..." Const Destination = "Another path..." Dim app ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T17:43:20.823", "Id": "89813", "Score": "2", "body": "Is WrkBook large? Which part of the code you feel is slower? The open, the moving of the sheets, the saving?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>The biggest bottle neck here is <code>Dim app As New Excel.Application</code>. Opening up a brand new excel instance is costly even if you do it once. Instead you can grab an existing instance of Excel (if there is one) if not then you can create a new one still. The rest of your code is pretty si...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T17:37:49.553", "Id": "51912", "Score": "6", "Tags": [ "performance", "vba", "excel" ], "Title": "Improving performance of VBA batch scripts?" }
51912
<p>No, this question has no roosting construction workers.</p> <p>I'm not sure if what I'm doing is a good use of the builder pattern or whether its a bastardization of what its intended purpose was. I'm trying to set up mocks in my tests and find myself repeating myself often to set up the mocks, so I've tried to sim...
[]
[ { "body": "<h2>Factory Method vs Constructor</h2>\n\n<p>In your builder classes you have opted to use factory methods instead of constructors. While this is not necessarily wrong, exposing a factory method generally implies a semantically different operation than constructor invocation. From the <a href=\"http:...
{ "AcceptedAnswerId": "51980", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T15:24:28.430", "Id": "51917", "Score": "5", "Tags": [ "c#", "design-patterns", "unit-testing", "moq" ], "Title": "Using the builder pattern to build mock objects and nested...
51917
<p>I tried to create a class which downloads the HTML source from a link and saves it. I'm a newbie to all this Android stuff, even new to Java, but this is what I have so far.</p> <p>It seems to work at least, although I cannot see the file since it is hidden.</p> <pre><code>package com.example.test; import java.io...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T16:25:13.087", "Id": "89849", "Score": "1", "body": "Welcome to Code Review! If you use a file manager app such as [Total Commander for Android](https://play.google.com/store/apps/details?id=com.ghisler.android.TotalCommander), you ...
[ { "body": "<h3>Don't leak <code>Context</code></h3>\n\n<p>It's not good to leak <code>Context</code> out of an Activity/Service. Your class needs just the output of <code>context.getFilesDir()</code>, so store just that:</p>\n\n<pre><code>private final File parentDir;\n\npublic PageDownloader(Context context) {...
{ "AcceptedAnswerId": "52025", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T16:12:05.390", "Id": "51919", "Score": "5", "Tags": [ "java", "beginner", "android" ], "Title": "Downloading a page in Android" }
51919
<p>I've written ordinary least squares fitting of market data for learning purposes, so performance is <em>not</em> an issue. I'd like a reviewer to look at correctness and programming flaws, if any, in the code:</p> <pre><code>#!/usr/bin/env python import math import sys import csv import traceback import ipdb de...
[]
[ { "body": "<p>Here are a few pointers:</p>\n\n<ol>\n<li>Start function/method names with a verb. So I would change <code>mean</code> and <code>variance</code> to <code>get_mean</code> and <code>get_variance</code> respectively.</li>\n<li><p>Your return statements in <code>mean</code> and <code>variance</code> c...
{ "AcceptedAnswerId": "51926", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T16:19:47.170", "Id": "51920", "Score": "2", "Tags": [ "python", "statistics" ], "Title": "Check ordinary least squares calculation for correctness" }
51920
<p>I'm trying to extend bootstrap 3 modal window with ability to disable closing it.</p> <p>I've built this code:</p> <pre><code>(function ($, window, document, undefined) { var oldHide = $.fn.modal.Constructor.prototype.hide; $.fn.modal.Constructor.prototype.hide = function (_relatedTarget) { if (th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T02:21:21.103", "Id": "89909", "Score": "0", "body": "I get passing in `this` in case someone overwrite `window`, but what pass in `window` and `document` only to assign them to function arguments with the same name? Does that have *...
[ { "body": "<p>Looks fine to me, except that you failed declare the <code>e</code> variable in the <code>lock</code>/<code>unlock</code> functions. So it's an automatic global, which isn't good.</p>\n\n<p>With a little bit of cleanup:</p>\n\n<pre><code>(function ($) {\n var _original = $.fn.modal.Constructor.pr...
{ "AcceptedAnswerId": "51931", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T17:22:40.587", "Id": "51925", "Score": "7", "Tags": [ "javascript", "jquery", "twitter-bootstrap" ], "Title": "Correct way to extend Bootstrap Modal - lock, unlock" }
51925
<p>So I wrote this class to handle my ajax calls simply:</p> <p><strong>ajaxCon.php:</strong></p> <pre><code>class ajaxCon{ private $init = false; private $functionArray = array(); private $Message = false; private $function = null; private $arguments = null; private $post = null; public ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T20:42:47.867", "Id": "89887", "Score": "0", "body": "Take a look at how [swagger](https://github.com/wordnik/swagger-js) does it. It's basically a contract for publishing metadata about restful services, sort of like SOAP's WSDL. Mi...
[ { "body": "<p>A review of the JavaScript part:</p>\n\n<ul>\n<li><code>ajaxCon</code> is a class/constructor, so you should call it <code>AjaxCon</code>, though really I would think about finding an even better name :)</li>\n<li><code>ajaxFailure</code> -> You have a number of functions that have <code>ajax</cod...
{ "AcceptedAnswerId": "51955", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T17:45:12.007", "Id": "51928", "Score": "2", "Tags": [ "javascript", "php", "jquery", "object-oriented", "ajax" ], "Title": "Ajax Class Efficiency" }
51928
<p>Is there a more efficient way to write this? This script will be used heavily and I want to make sure I do not have any memory leaks or speed issues.</p> <p>This script gets an input from a form and searches the database for that record.</p> <pre><code>&lt;?php date_default_timezone_set('America/Los_Angeles'); $h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T21:55:03.180", "Id": "89901", "Score": "0", "body": "Deleted previous comment. SQL injection is not so much a concern here, however I feel that hard-coding auto-commit SQL into a script such as PHP that is often visible to the end-u...
[ { "body": "<h1>Efficiency</h1>\n\n<p>Nothing to worry about. It's only a linear script, there are no loops anywhere. You don't need to worry about efficiency.</p>\n\n<h1>Security and <s>best-practices</s> <em>horrible practices</em></h1>\n\n<p>I should really have you write down this sentence 100 times on a pie...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T18:02:48.950", "Id": "51930", "Score": "15", "Tags": [ "php", "optimization", "performance", "mysql" ], "Title": "Search script code efficiency" }
51930
<p>I know something about pointers, but I'm trying to check my knowledge on a sample. Can somebody check if my code is good? I don't think that I should use pointers in these <code>struct</code>s.</p> <p>The second question is: Can I use a <code>for</code> loop like this?</p> <pre><code>for(DLList* i=first; i!=0; i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T19:43:21.153", "Id": "89876", "Score": "0", "body": "Hello there, and welcome to Code Review! We actually can't do reviews on psuedo/sample code, CR is for reviewing actual working code that you want to have reviewed. See more on wh...
[ { "body": "<p>I'm assuming that this is basically a pointer exercise rather than a real piece of code that you're planning to use. If it's the latter, please reconsider -- there are STL containers that do this better and safer. As to your question about the <code>for</code> loop, there's nothing wrong with th...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T19:05:57.300", "Id": "51935", "Score": "2", "Tags": [ "c++", "linked-list", "pointers" ], "Title": "Pointers for struct and `for`" }
51935
<pre><code>&lt;?php $page = 'Login'; session_start(); include 'header.php'; $user_error = ''; $pass_error = ''; $login_error = ''; if(isset($_SESSION['username'])){ header('location: control-painel.php'); } if(isset($_POST['login'])){ $username = $_POST['username']; $password = $_POST['password']; $cost = '11'; $salt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T19:22:36.860", "Id": "89870", "Score": "1", "body": "Not strictly an answer but it could do some accurate indenting!" } ]
[ { "body": "<p>The first thing I spotted was this: <code>control-painel.php</code>. I'm not sure if that's an error with your page name or code, but whichever it is needs to be fixed.</p>\n\n<blockquote>\n <p>Can it be optimized?</p>\n</blockquote>\n\n<p>The best optimisation is only doing what's necessary. Whe...
{ "AcceptedAnswerId": "51957", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T19:10:11.067", "Id": "51937", "Score": "3", "Tags": [ "php", "security", "authentication" ], "Title": "Is this login page safe and can it be optimized?" }
51937
<p>The below code returns all distinct combinations based on the logic that 1,2,3 = 3,2,1 = 2,3,1, so it only returns 1 instance of that set of numbers. </p> <pre><code>public void GetPowersets() { List&lt;int&gt; ints = new List&lt;int&gt;() { 1,2,2,3,3 }; var results = GetPowerSet(ints); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T20:03:56.080", "Id": "89880", "Score": "0", "body": "Hello SED, and welcome to Code Review! Where we review working code. Your current question seems to imply that you would like reviewers to write new code for you based on your exi...
[ { "body": "<p>Pasting your code exactly as is into my IDE, ReSharper gives the following warnings and suggestions:</p>\n\n<blockquote>\n<pre><code>List&lt;List&lt;int&gt;&gt; returnResult = new List&lt;List&lt;int&gt;&gt;();\n</code></pre>\n \n <p><em>Use implicitly typed local variable declaration</em></p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T19:11:55.033", "Id": "51938", "Score": "7", "Tags": [ "c#", "performance", "linq", "memory-management", "combinatorics" ], "Title": "Get distinct combinations of numbers" ...
51938
<p>What would be the best way to refactor this :</p> <pre><code>@busy.each do |b| title = b.title @events &lt;&lt; { :id =&gt; b.id, :title =&gt; title, :start =&gt; b.busy_start_time(b.start_date,b.start_time), :end =&gt; b.busy_end_time(b.end_date,b.end_time), :allDay =&gt; false, :recur...
[]
[ { "body": "<p>I think this is where you are trying to get to:</p>\n\n<pre><code>class Busy\n def event_info\n {\n :id =&gt; id,\n :title =&gt; title,\n :start =&gt; busy_start_time(start_date, start_time),\n :end =&gt; busy_end_time(end_date, end_time),\n :allDay =&gt; false,\n ...
{ "AcceptedAnswerId": "51947", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T19:26:30.700", "Id": "51939", "Score": "5", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Refactor .each where each is redirected into a hash" }
51939
<p>Please review this small program I wrote to create a World Cup Group Table. You feed the program match info, and it builds a table based on that info.</p> <pre><code> def table_for(matches) # Defaults that each team in the table should have defaults = { goals_for: 0, points: 0 } # Using the matches, l...
[]
[ { "body": "<p>Note that <code>uniq</code> is not in-place, <code>uniq!</code> is. Otherwise, I guess your code is pretty good if you like imperative style (maybe some unnecessary comments could be removed, though). Personally, I prefer a functional approach: less statements, more expressions. If you open a cons...
{ "AcceptedAnswerId": "51954", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T21:12:11.183", "Id": "51950", "Score": "4", "Tags": [ "ruby" ], "Title": "Small football table builder in Ruby" }
51950
<p>In one finance application I'm working on, the requirements call that I truncate a decimal value at certain number of places and not round.</p> <p>Example: 11.685 truncated to 2 decimal places should be 11.68</p> <p>I wrote this extension method, but was wondering if someone knew of an easier way.</p> <pre><code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T21:50:51.607", "Id": "89900", "Score": "0", "body": "Following [Hans' advice](http://stackoverflow.com/questions/3143657/truncate-two-decimal-places-without-rounding): `Math.Truncate(100 * value) / 100;` where `100` can be substitut...
[ { "body": "<p>My solution multiplies the value by 10<sup>places</sup>, truncates, and finally divides by the same power of ten. If the places are negative, the decimals before the decimal point are truncated; i.e., <code>1234.TruncateDecimalPlaces(-2) ==&gt; 1200</code>.</p>\n\n<p>Since <code>Math.Pow</code> is...
{ "AcceptedAnswerId": "51975", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T21:12:27.187", "Id": "51951", "Score": "9", "Tags": [ "c#", "floating-point" ], "Title": "Truncate decimal places" }
51951
<p><strong>What I want to do:</strong></p> <ol> <li><p>Let users add data to an array through an input field and add button. </p> <p><strong>HTML:</strong></p> <pre><code>&lt;body&gt; &lt;input type="text" id="input"&gt; &lt;button type="button" id="btnAdd"&gt;Add Number&lt;/button&gt; &lt;div id="outputBox"&gt;&lt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T00:33:46.623", "Id": "90109", "Score": "0", "body": "Took the liberty of editing your question a little to avoid breaking up the second code block (it made it hard to read the code)" } ]
[ { "body": "<blockquote>\n <p>Any potential pitfalls with this way of modifying an array?</p>\n</blockquote>\n\n<p>There certainly are for the user! Your code is not really confirming deletion: The number gets removed even if you press No/Cancel. You need to actually check the return value of the <code>confirm(...
{ "AcceptedAnswerId": "52060", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T00:25:50.537", "Id": "51958", "Score": "4", "Tags": [ "javascript", "jquery", "array" ], "Title": "Making an array editable by user" }
51958
<p><strong>Background</strong><br> We have to cater to large screens. So I created this portion of a grid system which is shown to users with screens larger than 1800px.</p> <p><strong>Solution</strong><br> This grid is 1800px wide but can shrink down to 1200px, has 8 columns. I wanted 10px margin around the sides of ...
[]
[ { "body": "<p>I want to suggest that you use LESS/SASS to build your library </p>\n\n<p>You have a lot of math. One problem here is that if you want to change your sizes, you'd be facing a calculator, calculate and change values for each. One decimal place wrong and it could ruin your pixel-perfect calculations...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T02:01:49.193", "Id": "51960", "Score": "2", "Tags": [ "html", "css" ], "Title": "New CSS grid at 1800px" }
51960
<p>There are a number of things wrong with the code here:</p> <pre><code> @cust = Customer.find_by_id(params[:customer_id]) upd = @cust.update_attributes({:city_id =&gt; params[:city], :zip_code =&gt; params[:zip], :first_name =&gt; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T14:17:15.873", "Id": "89977", "Score": "0", "body": "it's weird, when you use Rails helpers, attributes in form have the same name, what did you use? also, it's \"phone\" an array? why is it singular?" }, { "ContentLicense":...
[ { "body": "<pre><code>class Customer\n def update_customer params\n update_attributes(:city_id =&gt; params[:city],\n :zip_code =&gt; params[:zip],\n :first_name =&gt; params[:first_name],\n :last_name =&gt; params[:last_name],\n ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T03:41:07.087", "Id": "51963", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Move update_attributes into class and check for non-nil params to update only" }
51963
<p>I am working on some problems on Hackerrank.</p> <blockquote> <p>John has discovered various rocks. Each rock is composed of various elements, and each element is represented by a lowercase Latin letter from 'a' to 'z'. An element can be present multiple times in a rock. An element is called a 'gem-element' if i...
[]
[ { "body": "<p>Your solution looks pretty good. However, a few details can be changed to make your code more pythonic :</p>\n\n<p><strong>Unused variable</strong></p>\n\n<p>You can use <code>_</code> to name a variable whose value is not used. In your case, it applies to the first loop variable <code>x</code>.</...
{ "AcceptedAnswerId": "51973", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T04:32:11.407", "Id": "51964", "Score": "5", "Tags": [ "python", "optimization", "performance", "memory-management", "programming-challenge" ], "Title": "Hackerrank Gem ...
51964
<p>For a game, there is some WebGLRenderer object that wraps around canvas element. There is need to update it's size when browser window size changes. Here goes my current code written using BaconJS. What do you think about it ? Would you improve it in any way or maybe do it other way? I have read that listening to <c...
[]
[ { "body": "<p>I think your code style is fine. If you are happy with this method, I think you've written it pretty well.</p>\n\n<p>As potential upgrades, here are two alternative methods that better obey the <a href=\"http://www.faqs.org/docs/artu/ch01s06.html\" rel=\"nofollow\">Rules of Clarity and Simplicity<...
{ "AcceptedAnswerId": "52043", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T05:26:44.933", "Id": "51967", "Score": "4", "Tags": [ "functional-programming", "coffeescript", "bacon.js" ], "Title": "Resize renderer on browser window size change" }
51967
<p>While practicing at codinbat.com on the <a href="http://codingbat.com/prob/p196640" rel="nofollow">assignment</a>:</p> <blockquote> <p>Given an array length 1 or more of <code>int</code>s, return the difference between the largest and smallest values in the array. Note: the built-in <code>Math.min(v1, v2)</code> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T08:08:46.747", "Id": "89924", "Score": "3", "body": "Before doing any benchmark, I reckon you should retrieve `nums[i]` only once. Also, if you want to perform tiny optimisations, you can keep in mind the fact that if a value is sma...
[ { "body": "<p>Unnecessary assignments are extra instructions when the code is executed. So <em>in theory</em>, the second solution should be generally slower. In practice this difference may not even be measurable.</p>\n\n<p>More importantly, <a href=\"https://codereview.stackexchange.com/users/9452/josay\">@Jo...
{ "AcceptedAnswerId": "51981", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T07:44:36.287", "Id": "51974", "Score": "2", "Tags": [ "java", "performance", "array", "integer", "comparative-review" ], "Title": "Two solutions with min max values - w...
51974
<p>I have a jQuery dialog that is opened when the content of a div is clicked.</p> <p>When the dialog is opened, I am binding a <a href="http://benalman.com/projects/jquery-outside-events-plugin/" rel="nofollow">jQuery outside event</a> so when the user clicks anywhere outside of the dialog the dialog is closed. </p> ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T08:24:20.633", "Id": "51978", "Score": "1", "Tags": [ "javascript", "jquery", "jquery-ui" ], "Title": "Bind and unbind clickoutside event" }
51978
<p>I'm fairly new to C++ and to game programming itself. Today I decided to build a multiplayer Tic Tac Toe program using only elemental C++ syntax/data structures. I also implemented a text interface for the game instead of real graphics.</p> <p>Any suggestions or tips for the code?</p> <pre><code>#include &lt;iostr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T13:30:55.920", "Id": "90153", "Score": "1", "body": "if (isP2) {\n cout << \"Player 2 turn...\" << endl << \"Insert to slot > \";\n } else {\n cout << \"Player 1 turn...\" << endl << \"Insert to slot > \...
[ { "body": "<p>Overall, I think it is a pretty good program.</p>\n\n<p>I think I see one bug. You don't check that the user's input for <code>slotChoice</code> is valid. If the input is outside the range 0..8, the program overruns the array.</p>\n\n<p>Some style and refactoring suggestions, in no particular or...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T11:02:30.983", "Id": "51987", "Score": "25", "Tags": [ "c++", "beginner", "game", "console", "tic-tac-toe" ], "Title": "Non-AI Tic-Tac-Toe program" }
51987
<p>I have written the following Perl script to monitor the hardrive performance of the particular process (say, for example, Chrome).</p> <pre><code>use strict; use warnings; use Spreadsheet::WriteExcel; #@usage example perl script.pl 5 5 if($#ARGV!=1); my $login = (getpwuid $&gt;); die "must run as root" if $login...
[]
[ { "body": "<p>in general this script seems to be straight forward.</p>\n\n<p>But here are some suggestions for improvements:</p>\n\n<p>First check for needed command line arguments and <code>die</code> early with a usage message if they are missing/incomplete. Alternatively you could supply defaults for time in...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T11:10:35.187", "Id": "51988", "Score": "2", "Tags": [ "perl" ], "Title": "Check the hardrive performance of the particular process using a Perl script" }
51988
<p>This function checks if the <code>EndDate</code> of my grid is valid or not. If it is not valid, it turns the bgcolor of the cell to red color with <code>cell-error</code> class.</p> <p>I need some help in optimizing this block of code. It looks dirty right now.</p> <pre><code>function onAccrualEndDateChange(curre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T12:03:27.313", "Id": "89949", "Score": "0", "body": "remove most of the `else` that do the same thing" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T12:14:40.357", "Id": "89951", "Score": "0"...
[ { "body": "<p>This isn't \"optimized\", I just tried to make it more readable.<br>\nAs I cant test it (really wish people would make jsbin examples to test with, buggered if Im going to do it) I have no idea if it works ;) </p>\n\n<pre><code>function onAccrualEndDateChange(current) {\n var endDate = $(current...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T11:59:28.387", "Id": "51990", "Score": "4", "Tags": [ "javascript", "performance", "jquery", "datetime", "validation" ], "Title": "Validating a date in a grid" }
51990
<p>Here's a function I wrote - am I getting DRY about right? I could add another argument to <code>paramFilter</code> maybe, for even less reuse. Or have I gone too overboard as it is?</p> <pre><code>function goMageHack() { var ampFilter = function (str) { var amps = ["&amp;amp;", "amp%3B"]; for (v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T03:48:46.707", "Id": "90125", "Score": "0", "body": "Could you post a demo at http://jsfiddle.net to show how it works? It would help find a better way to do this DRYer." }, { "ContentLicense": "CC BY-SA 3.0", "CreationD...
[ { "body": "<p>I found something in your <code>fullReplace</code> function,</p>\n\n<blockquote>\n<pre><code>function fullReplace(needle, haystack, str) {\n str = String(str);\n var newStr;\n while ((newStr = str.replace(needle, haystack)) !== str) {\n str = newStr;\n }\n return newStr;\n}\n...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T13:00:07.893", "Id": "51993", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Filter functions" }
51993
<p>I have been trying to solve <a href="http://www.spoj.com/problems/TWOSQRS/" rel="nofollow">this</a> problem, and after a bit of googling, I realised a \$O(\sqrt{n})\$ time complexity works fine (though the algorithm suggested is different from that I have used). My algorithm is as follows (pseudo code):</p> <pre><c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T18:05:47.993", "Id": "90052", "Score": "2", "body": "For a bruteforcing, I'd recommend to set up a table of perfect squares. It is not that large: MAX is 10^8, so you only need 10^4 entries." }, { "ContentLicense": "CC BY-SA...
[ { "body": "<ol>\n<li><p><code>llu root = sqrtl(n);</code> is not safe. The precision of a long double is not specified by C to give the exact correct answer for all <code>unsigned long long</code>.</p></li>\n<li><p>Not sure yet why you get TLE (Time Limit Exceeded). As the page you point to only has 10 small ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T14:51:39.067", "Id": "52002", "Score": "2", "Tags": [ "algorithm", "c", "programming-challenge", "complexity" ], "Title": "Two squares or not two squares - constant time optim...
52002
<p>I need some help in working "Video Rental Store" application design optimization. The application describes the following tasks:</p> <ul> <li>Inventory stores videos. Inventory can add/delete/change and receive all videos. Inventory has 3 types of films: Old, New, Regular.</li> <li>Videos have a title, type (descr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T18:55:20.213", "Id": "90065", "Score": "0", "body": "I like your code's architecture" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T19:15:04.043", "Id": "90068", "Score": "0", "body": "Un...
[ { "body": "<p>I think you are getting lost in a bunch of methods you are implementing before you have a real justification for them. So let's just ignore those for the moment, and concentrate on the bits that you have a handle on (in the expectation that things will become clearer).</p>\n\n<pre><code>private d...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T15:36:04.090", "Id": "52007", "Score": "6", "Tags": [ "java" ], "Title": "Video rental store application design" }
52007
<p>I have a problem with parsing RSS from a PHP page because the app is too slow.</p> <p>This is my parsing code:</p> <pre><code>public void getdataparse(String url) { Log.d("Do in Background","Start Call Void"); String dbtitle = ""; String dbDesc = ""; String dbimgicon = ""; String dbimg = ""; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T15:45:19.967", "Id": "90188", "Score": "0", "body": "If you want a review of your PHP code, you should ask a new question about that and include that code in the post itself." }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>none of those Variables need to be set to <code>\"\"</code> inside the for loop, they have already been set.</p>\n\n<hr>\n\n<p>This can be set early and outside of the if block and the for loop:</p>\n\n<pre><code> dbimg = \"http://s14.postimg.org/cs10sq11d/whitemega.png\";\n</code></pre>\n\n<p>Oth...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T15:46:38.183", "Id": "52008", "Score": "4", "Tags": [ "java", "performance", "parsing", "android", "rss" ], "Title": "How can I speed up my RSS feed Android App?" }
52008
<p><a href="http://en.wikibooks.org/wiki/Vedic_Mathematics/Techniques/Multiplication" rel="nofollow">This</a> is vedic method multiplication. This code takes time on a very long numeric string, and I want to optimize it. I also apply recursion on <code>multIndices</code> (this function is multiplying two given indice...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T16:14:15.613", "Id": "90018", "Score": "0", "body": "I want to apply recursion on multIndices function instead on this loop." } ]
[ { "body": "<ul>\n<li><p><strong>Code organization</strong>: <code>main</code> does too much. Actual calculations, that is everything between <code>gets</code> and <code>puts</code> shall be a standalone function (<code>multiply</code>). Zero-filling loop shall be factored out into a function (see below). <code>...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T16:01:56.280", "Id": "52009", "Score": "2", "Tags": [ "optimization", "c", "strings", "recursion" ], "Title": "Multiplying a numeric string with the \"vedic method\"" }
52009
<p><strong>Intro</strong></p> <p>I am trying to populate a Multi-column Combo-box with a large amount of records.Depending on the selection the user has taken there can be 1 - 50000 items in the Combo-box (I may not display all these items at once, but i still have to process them all). </p> <p>I am using entity fram...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T16:32:17.290", "Id": "90026", "Score": "0", "body": "This comment is going to be more fitting on UX.StackExchange, but ....what use is a ComboBox with 50K items in it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDat...
[ { "body": "<p>One of the reasons behind <code>var</code> appearing in the C# language at the same time as LINQ, was specifically to avoid this:</p>\n\n<blockquote>\n<pre><code>IOrderedQueryable&lt;Models.Establishment&gt; establishments = entity.Establishments\n .Where(establishment =&gt;\n establishment....
{ "AcceptedAnswerId": "52024", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T16:14:35.293", "Id": "52011", "Score": "1", "Tags": [ "c#", "performance", "multithreading", "asp.net", "entity-framework" ], "Title": "Multi threading in ASP.Net to in...
52011
<p>I’ve been experimenting with the Twitter Streaming API and would like some critical feedback on my latest project. Specifically code correctness, code smells, overall structure, and my usage of collections. The application identifies the current top trending hashtags for the supplied hashtag, or string.</p> <h2>Abs...
[]
[ { "body": "<p>Recommendation: use an ExecutorService instead of managing the threads yourself.</p>\n\n<p>You should inject Dependencies, like TwitterClient, into the classes that need them, rather than doing the instantiation locally. If you feel like to absolutely need to hide the implementation detail that i...
{ "AcceptedAnswerId": "52049", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T16:32:44.450", "Id": "52014", "Score": "7", "Tags": [ "java", "twitter" ], "Title": "Twitter Streaming API Client: Identifying the top trending hashtags for a specific term" }
52014
<p>Suppose the following model:</p> <pre class="lang-c# prettyprint-override"><code>public class ViewBookModel { public string Title { get; set; } public string Subtitle { get; set; } } </code></pre> <p>I'm currently rendering it like this in my Razor view:</p> <pre class="lang-html prettyprint-override"><co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2018-03-13T08:28:04.207", "Id": "362174", "Score": "0", "body": "Have a look at [templated delegates](https://haacked.com/archive/2011/04/14/a-better-razor-foreach-loop.aspx/), so you can keep markup at the relevant places and move the logic t...
[ { "body": "<p><code>Subtitle</code> being a <code>string</code>, a <em>more elegant</em> way of testing whether it's <code>null</code> would be to use <code>string.IsNullOrEmpty(Model.Subtitle)</code>, like this:</p>\n\n<pre><code>&lt;h1&gt;@Model.Title&lt;/h1&gt;\n@if (!string.IsNullOrEmpty(Model.Subtitle))\n{...
{ "AcceptedAnswerId": "56268", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T16:38:53.593", "Id": "52016", "Score": "24", "Tags": [ "c#", "asp.net-mvc" ], "Title": "How to write elegant conditional bits of markup in Razor views?" }
52016
<p>I'm looking for some code review of my usage of async. Mainly why this does not work without the <code>done = this.async()</code> method and why I don't have to invoke 'done()' on every request to download a file. This is working now but it is a bit of magic to me. Hoping to understand why it's working and if I'm ab...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T22:49:46.123", "Id": "90101", "Score": "0", "body": "i'm also working on using the path module to remove platform specific separators." } ]
[ { "body": "<p><code>this.async()</code> tells grunt that you're doing something async and that it should wait until you call the <code>done</code> method. Usually it just goes to the next grunt task when the execution is done. Since you're using the <code>async</code> module you can call the <code>done</code> m...
{ "AcceptedAnswerId": "52053", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T18:09:49.303", "Id": "52027", "Score": "2", "Tags": [ "javascript", "node.js", "asynchronous", "grunt.js" ], "Title": "nodejs grunt plugin using async module" }
52027
<p><a href="https://oj.leetcode.com/problems/pascals-triangle-ii/">Question</a>:</p> <blockquote> <p>Given an index \$k\$, return the \$k^{th}\$ row of the Pascal's triangle.</p> <p>For example, given \$k = 3\$, return \$[1,3,3,1]\$. Bonus points for using \$O(k)\$ space.</p> </blockquote> <p>Can it be furthe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T18:32:52.460", "Id": "90056", "Score": "14", "body": "If this is for an interview I would make it understandable at a glance. This means writing in such a way that the code is very nicely formatted and there are comments explaining ...
[ { "body": "<p>For one thing, the inconsistency with whitespace use and curly brace placing may demonstrate a lack of attention to detail. Before you attack the actual problem, make sure your code is written cleanly.</p>\n\n<p>This:</p>\n\n<blockquote>\n<pre><code>for(int i=0;i&lt;=rowIndex;i++)\n</code></pre>\...
{ "AcceptedAnswerId": "52041", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T18:18:32.063", "Id": "52028", "Score": "24", "Tags": [ "c++", "performance", "interview-questions", "combinatorics" ], "Title": "Solution for kth row of Pascal's triangle ...
52028
<p>The following code uses scikit-learn to carry out K-means clustering where \$K = 4\$, on an example related to wine marketing from the book <a href="http://www.wiley.com/WileyCDA/WileyTitle/productCd-111866146X.html">DataSmart</a>. That book uses excel but I wanted to learn Python (including numPy and sciPy) so I im...
[]
[ { "body": "<p>One obvious improvement would be to break the code up a bit more - identify standalone pieces of functionality and put them into functions, e.g.:</p>\n\n<pre><code>def read_data(filename):\n csvf = open(filename,'rU')\n rows = csv.reader(csvf)\n data = [row for row in rows]\n csvf.clos...
{ "AcceptedAnswerId": "52042", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T18:25:27.630", "Id": "52029", "Score": "8", "Tags": [ "python", "beginner", "python-2.x", "numpy", "clustering" ], "Title": "K-means clustering in Python" }
52029
<p>I'm starting to figure out this jquery stuff, but as you can see there's a long ways to go. How would I approach refining and simplifying this snippet. Its purpose is to show a fieldset<code>[data-content]</code> with inputs inside when you click a "show" link, and to hide said fieldset and remove all "required" att...
[]
[ { "body": "<ol>\n<li>Store selections in variables; don't call <code>$(...)</code> again and again for elements you've already selected</li>\n<li>You start out by hiding the fieldset, but it'd be simpler to just hide it with CSS, so it starts out hidden by default. Conversely, if it's visible by default, then a...
{ "AcceptedAnswerId": "52040", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T18:50:16.730", "Id": "52034", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Refining/simplifying jquery for hiding and showing fieldsets" }
52034
<p>In preparation for a job interview I decided to try and implement the classic find all anagrams of a given string solution. I wanted to see if I could translate a javascript solution into python. This was my attempt:</p> <pre><code>def anagrams(word): if len(word) &lt; 2: return word else: t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T20:07:36.997", "Id": "90076", "Score": "4", "body": "It probably makes the exercise less interesting but you could have a look at itertools.permutations" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30...
[ { "body": "<p>Your python code is neat, simple and easy to understand (so generally it's good); and yet, something in me doesn't like the use of so many temporary arrays. How about using a generator? </p>\n\n<pre><code>def anagrams(word):\n \"\"\" Generate all of the anagrams of a word. \"\"\" \n if len...
{ "AcceptedAnswerId": "52048", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T19:10:15.313", "Id": "52038", "Score": "6", "Tags": [ "python", "beginner", "interview-questions" ], "Title": "Simple anagram or permutation generator in Python" }
52038
<p>I'm trying to post a little tutorial on the new <code>Spliterator</code> class. There are many tutorials these days on using stream starting from a standard Java collection, but I want to explore the creation of a stream using data coming from the web (so no stream fully backed by a collection).</p> <p>I decided to...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T18:39:12.513", "Id": "91427", "Score": "0", "body": "This is a really nice question and I'm happy to see others using Java 8 as well. Unfortunately I cannot answer this (yet), but I'll make sure to revisit it once I understand the `...
[ { "body": "<p>From my reading of the <a href=\"http://docs.oracle.com/javase/8/docs/api/java/util/Spliterator.html#ORDERED\" rel=\"nofollow\"><code>Spliterator</code> documentation</a>, your code looks like it should handle parallel usage. Each list of URLs is owned by exactly one spliterator while they all sha...
{ "AcceptedAnswerId": "52234", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T21:49:24.223", "Id": "52050", "Score": "21", "Tags": [ "java", "stream", "url", "web-scraping" ], "Title": "Spliterator implementation" }
52050
<p>I would love some feedback on this. I use it to validate web-form objects before persisting them in the dangerously-lazy MongoDb. I have a class and many validators for each of my collections. Is there a better way to write or go about this?</p> <pre><code>class ValidationError(Exception): pass class Us...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T00:49:58.813", "Id": "90110", "Score": "1", "body": "You probably already know this, but `def int(val):` ... `return int(val)` is recursive." } ]
[ { "body": "<p><code>lambda</code> is redundant here as you can use <code>_id</code> directly as well:</p>\n\n<pre><code> map_keys = dict(\n _id=_id\n )\n</code></pre>\n\n<p>Other than that, your approach seems ok. You are reinventing the wheel though and it might be a good idea to research existing...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T00:26:03.097", "Id": "52056", "Score": "1", "Tags": [ "python", "validation", "hash-map", "lambda" ], "Title": "Validate fields in Python dictionary using dictionary of lambda...
52056
<p>I've implemented a simple thread-safe circular queue. I'm looking for code review, optimizations and best practices.</p> <pre><code>public class CircularQueue { int[] queue; int front; int rear; int currentSize; int size; public CircularQueue(int size) { this.queue = new int[size...
[]
[ { "body": "<p>Some random notes:</p>\n\n<ul>\n<li><p>I'd rename <code>add</code> and <code>poll</code> to <code>push</code> and <code>pull</code>.</p></li>\n<li><p><code>front</code> shall be wrapped around when it reaches <code>size</code>, just like <code>rear</code>. I hope it is just a typo.</p></li>\n<li><...
{ "AcceptedAnswerId": "52063", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T00:32:14.257", "Id": "52057", "Score": "5", "Tags": [ "java", "multithreading", "queue", "circular-list" ], "Title": "Circular queue implementation" }
52057
<p>This code review expands on <a href="https://codereview.stackexchange.com/questions/51950/small-football-table-builder-in-ruby">an earlier one</a> that deals with generating a football table from match data. This review deals with ordering said table based on several criteria.</p> <p>Your opinions/refactorings are ...
[]
[ { "body": "<p><em>This answer's been through some revisions. See note at the end.</em></p>\n\n<p>From a cursory it glance it looks OK, except that I feel there too much going on in <code>Sorter#sort</code>.</p>\n\n<p>Also, with a name like <code>Sorter</code>, I almost expect the class to be state-less. Because...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T02:31:20.337", "Id": "52062", "Score": "7", "Tags": [ "ruby", "sorting" ], "Title": "A Ruby sorting program for multiple criteria" }
52062
<p>I have a model that consists of a 100 'agents' that change their x and y coordinates randomly. I use JFreeChart scatter chart to represent agents' locations.</p> <pre><code>package jfreecharttest; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util....
[]
[ { "body": "<p>The <code>locationTaken</code> is a big performance bottleneck as it iterates through all points whenever you're adding a new one. Depending on the size of the fields (currently 0-100, 0-100), it is also very low probability for any collision.</p>\n\n<p>I believe the probability for <em>no</em> co...
{ "AcceptedAnswerId": "52096", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T06:25:10.627", "Id": "52069", "Score": "4", "Tags": [ "java", "graph" ], "Title": "JFreeChart Dynamic Scatter Chart" }
52069
<p>Is there anything wrong with this?</p> <pre><code> namespace WindowsFormsApplication1 { public interface ICarfactory { ICar getCar(CarType carType); } public interface ICar { } public class Sedan: ICar { } public class Hatchback : ICar ...
[]
[ { "body": "<p>First thing that pops in my head is that <em>camelCase</em> for methods (<code>getCar</code>) is not actually usable in <a href=\"/questions/tagged/c%23\" class=\"post-tag\" title=\"show questions tagged &#39;c#&#39;\" rel=\"tag\">c#</a>, in my opinion it looks really ugly and makes it look like <...
{ "AcceptedAnswerId": "52074", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T06:26:43.000", "Id": "52070", "Score": "5", "Tags": [ "c#", "design-patterns" ], "Title": "Abstract factory design for different cars" }
52070
<p>I've implemented a stack using a queue.</p> <p>Time complexity:</p> <p>\$O(n)\$ - <code>push()</code>, where <em>n</em> is the number of elements in the queue</p> <p>\$O(1)\$ - <code>pop()</code> </p> <p>Space complexity:</p> <p>\$O(n)\$ - <em>n</em> is the number of elements in the queue.</p> <p>I'm looking f...
[]
[ { "body": "<h3>Implementation:</h3>\n<p>If you are implementing a Stack, why not implement it? (<em>bad phrasing</em>).</p>\n<blockquote>\n<pre><code>public class StackUsingQueue&lt;T&gt; {\n</code></pre>\n</blockquote>\n<p>Instead of that class signature I'd rather really explicitly implement Stack:</p>\n<pre>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T06:43:53.367", "Id": "52071", "Score": "1", "Tags": [ "java", "queue", "stack" ], "Title": "Stack implementation using a queue" }
52071
<p>How can I simplify and optimize this code?</p> <pre><code>if type(variant_list) == dict: style_color_if(variant_list[style_colors_main], variant_list) else: for variant in variant_list: if type(variant[style_colors_main]) == dict: json_key_getter(variant[style_colors_main], variant) ...
[]
[ { "body": "<p>Recursion here is going to be your friend:</p>\n\n<pre><code>def recurse_json(property, variant):\n # This is our exit condition\n if isinstance(property, dict):\n json_key_getter(property, variant)\n else:\n # Otherwise, WE NEED TO GO DEEPER!\n for item in property:\...
{ "AcceptedAnswerId": "52081", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T10:01:00.747", "Id": "52075", "Score": "3", "Tags": [ "python", "optimization" ], "Title": "Simplifying if else statements in Python code snippet" }
52075
<p>I have a threaded pipeline with single producers and (possible) multiple consumers. A producer might wait or not, depending on the policy provided. A problem here is valgrind (helgrind) is reporting a race condition where no race condition should be possible (If so, my code is wrong). </p> <pre><code>#include &lt;a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T19:57:59.147", "Id": "90257", "Score": "0", "body": "Did valgrind report any more details that you didn't include in the question? Can you explain in a sentence or two why you think \"no race condition should be possible\"?" }, ...
[ { "body": "<p>I haven't taken time to understand all the code so I won't offer a firm answer to your problem. But I'll suggest where to start thinking about the problem.</p>\n\n<p>Consider these code fragments:</p>\n\n<pre><code>state_write = set_pipeline_state_write() // fragment 1, thread 1\n\nif(state...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T12:49:48.027", "Id": "52079", "Score": "4", "Tags": [ "c++", "multithreading", "c++11" ], "Title": "Threaded pipeline" }
52079
<p>I have the following <code>LINQ</code> query that should return a result for each <code>Request</code>. I'd prefer to have the query translated to <code>SQL</code> by <code>EntityFramework</code>.</p> <pre><code>private static Expression&lt;Func&lt;Request, RequestResultModel&gt;&gt; requestResultExpression = reque...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T14:20:53.463", "Id": "90171", "Score": "1", "body": "Have you tried [`.DefaultIfEmpty()`](http://stackoverflow.com/a/5538637/1188513) to make a LEFT JOIN instead of the INNER JOIN you're getting with your current code?" }, { ...
[ { "body": "<p>Your current code generates an INNER JOIN, which as you've noticed, excludes any <code>Applicant</code> without an <code>ApplicantAddress</code>.</p>\n\n<p>You want to select from <code>Applicant</code> and generate a LEFT JOIN on <code>ApplicantAddress</code>, <a href=\"https://stackoverflow.com/...
{ "AcceptedAnswerId": "52095", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T12:58:24.693", "Id": "52080", "Score": "6", "Tags": [ "c#", "linq", "entity-framework" ], "Title": "Refactoring a LINQ query that (sometimes) returns null" }
52080
<p>How could I improve or make this program more user friendly? I have not been programming very long, so please don't give me a task that is too complicated.</p> <pre><code>from random import randint import time global word word = "a" shield = 5 #The main function def main(): #This will trigger the introduction ...
[]
[ { "body": "<p>Welcome to programming and Python. I have a few suggestions. There are a lot of suggestions here in this answer. To improve the style of your code beyond the things I have spoken to here, have a look at <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">the official Python st...
{ "AcceptedAnswerId": "52091", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T13:18:56.003", "Id": "52083", "Score": "6", "Tags": [ "python", "beginner", "game" ], "Title": "Can my Python maze game be better in any way?" }
52083
<p>I've written an algorithm which can multiply two hex values and return a hex as a result. What do you think about the below solution?</p> <pre><code>package com.datastructute.arraystring; public class hexadecimal { public static void main(String[] args) { System.out.println(multiplyHex("AE08FE21111111...
[]
[ { "body": "<p>Your <code>getInt</code> and <code>getChar</code> methods are very long and cumbersome, they can be replaced by this:</p>\n\n<p>Using arrays:</p>\n\n<pre><code>private char[] values = new char[]{ '0', '1', '2', '3', '4', '5', '6', '7',\n '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };\n\nchar getIn...
{ "AcceptedAnswerId": "52086", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T13:23:17.827", "Id": "52084", "Score": "7", "Tags": [ "java", "algorithm", "reinventing-the-wheel" ], "Title": "Multiply two hexadecimal values" }
52084
<p>I wanted just to right align one column in WPF and I found out that the syntax is not exactly syntetic... Is there a way to make it more syntetic? </p> <p>Consider that this one colum, but I have 20 columns which share the same identical structure, changing only the displayed property.</p> <pre><code>&lt;GridViewC...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T13:44:21.253", "Id": "90158", "Score": "0", "body": "strange.. the markup was invisible :D" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T13:46:12.277", "Id": "90159", "Score": "1", "body...
[ { "body": "<p>XAML is XAML - I'm not sure what the meaning of \"syntetic\" is in this context, but the only thing I can see that could improve, is the closing tags for <code>&lt;Binding&gt;</code> - the empty elements can be collapsed:</p>\n\n<pre><code>&lt;MultiBinding StringFormat=\"{}{0:N} {1}\"&gt;\n &lt;B...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T13:34:19.003", "Id": "52085", "Score": "2", "Tags": [ "wpf", "xaml" ], "Title": "Rewriting WPF GridViewColumn alignment in a less verbose way" }
52085
<p>We have an action merge for two projects. In the projects we have different modules like Feed, Files, Post etc....</p> <pre><code>modules Convert class Merge attr_accessor :source_ids, :destination_id, :sources, :destination def initialize(source_ids, destination_id) @source_ids = source_ids.class ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T18:40:14.580", "Id": "95183", "Score": "0", "body": "krunal, you could write `@source_ids = source_ids.class == Array ? source_ids : [source_ids]` as `@source_ids = [*source_ids]`. For example, `[*[1,2,3]] => [1, 2, 3]`, `[*2] => [...
[ { "body": "<p>This is nowhere near the full answer, but I just want to touch on the initialize method of Merge real quick since it was the first thing to jump out to me. </p>\n\n<pre><code>def initialize(destination_id, *source_ids)\n @source_ids = source_ids\n @destination_id = destination_id\n @sources = M...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T14:49:13.587", "Id": "52093", "Score": "4", "Tags": [ "ruby", "classes", "inheritance", "modules" ], "Title": "Merging with different modules" }
52093
<p>I'm learning SSE for the first time and trying to optimise some code. Using <a href="http://oprofile.sourceforge.net/news/" rel="nofollow"><code>oprofile</code></a> shows that the CPU usage in this function went down from 2.5% to 0.9% using the code I created. As I've only been reading up on SSE today, I'm sure my c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-07-09T20:21:59.663", "Id": "176159", "Score": "0", "body": "similar Q from the same asker on http://stackoverflow.com/questions/23948232/can-you-tell-me-whats-wrong-with-this-sse-code-and-how-to-do-it-better, where I made an attempt at an...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T14:50:48.843", "Id": "52094", "Score": "4", "Tags": [ "performance", "c", "audio", "sse", "simd" ], "Title": "SSE optimisation for audio resampling" }
52094
<p>I'd like to get a general review on the following code, and I'll highlight an extra point below:</p> <pre><code>public interface PlayerAction { boolean isActionAllowed(final Player player); void performAction(final Player player) throws PlayerActionNotAllowedException; } </code></pre> <hr> <pre><code>pub...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T16:06:43.323", "Id": "90193", "Score": "0", "body": "Did you really test that Exception gets correctly implemented? Talk about paranoid..." } ]
[ { "body": "<p>I just want to make a few minor remarks, IMO these are more \"preference\" than \"convention\", so take 'em with a grain of salt</p>\n\n<h3>Test \"sectioning\"</h3>\n\n<blockquote>\n<pre><code>@Test\npublic void testPerformAction() {\n PlayerAction playerAction = new AbstractPlayerActionImpl();...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T15:45:54.887", "Id": "52099", "Score": "7", "Tags": [ "java", "game", "unit-testing", "community-challenge" ], "Title": "FuseMonsterAction implementation and unit tests" }
52099
<p>I am writing a management application to replace an existing application. Depending on certain criteria, people are interviewed either quarterly or annually based on certain criteria. The date of the interviews are determined by their birthday. I want a dialog that will display all upcoming interviews, one month ...
[]
[ { "body": "<p>At first glance,</p>\n<ul>\n<li><code>o</code> is a terrible variable name</li>\n<li><code>getIsActive</code> boolean properties typically don't use <code>get</code>. I know some source code generators will throw it on there and that is probably what happened in this case.</li>\n</ul>\n<h1>Encapsu...
{ "AcceptedAnswerId": "52113", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T16:43:47.123", "Id": "52101", "Score": "3", "Tags": [ "java" ], "Title": "Find upcoming annual and quarterly interviews" }
52101
<p>This is perfectly readable code to me, but I'm afraid it may be too confusing to others. What do you think?</p> <p>Note that I'm not interested in validation of the input here (validation will happen long before we get to this line in the code), so assume it is blank or a valid non-negative integer.</p> <p>It's m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T17:16:16.523", "Id": "90206", "Score": "0", "body": "If that's confusing to the people you work with, time to find new people to work with. It's perfectly idiomatic JS." } ]
[ { "body": "<p>This seems a pretty standard syntax pattern in scripting languages. I am not an expert in JS but I can even read it without any issues — Take the ‘number-to-add’ (not sure what that is but I assuem some DOM object) value and then parse it to an Int, if that fails, then take the 500 as a default. A...
{ "AcceptedAnswerId": "52106", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T16:50:15.007", "Id": "52102", "Score": "6", "Tags": [ "javascript", "converting" ], "Title": "Readability of JavaScript shorthand for converting strings to numbers with default val...
52102
<p>I have been thinking quite some time and asked an StackOverflow question about extending abstract test classes, but I haven't been able to do it until now.</p> <p>I'll list my approach and then discuss some pros and cons and am asking you for a review of the code.</p> <p>Consider the <code>PlayerAction</code> inte...
[]
[ { "body": "<p>You are not doing your tests 'appropriately', and this is part of your issue.</p>\n\n<p>There is no need for the 'supplier'. The supplier is an instance field, and it's an extra level of abstraction that is unnecessary. JUnit has concepts at play that allows it to run tests in parallel. Having ins...
{ "AcceptedAnswerId": "52118", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T18:04:16.903", "Id": "52108", "Score": "11", "Tags": [ "java", "unit-testing", "junit" ], "Title": "JUnit extending abstract test class" }
52108
<p>Recently, I have get familiar with Command Pattern implementation. I have a problem where I need to get a choice for user to select what kind of method to execute typing method name or number, which concerns to this concrete method execution. Everything will be OK if I don't need to create separate class for each me...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T18:59:35.890", "Id": "90245", "Score": "0", "body": "I believe you haven't understood the purpose of this StackExchange site. We are here to review **your** working code. While it is okay to ask specific focus points in your questio...
[ { "body": "<p>I may not be able to review the point you specifically ask for, but I'll go for a general review:</p>\n\n<ol>\n<li><p>Omit <code>public</code> and <code>abstract</code> keyword from interfaces, it is implicit.</p></li>\n<li><p>Be consistent with spacing out your syntax. You for example have <code>...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T18:35:41.290", "Id": "52110", "Score": "0", "Tags": [ "java" ], "Title": "Command pattern implementation" }
52110
<p>I'm using code adapted from <a href="https://stackoverflow.com/questions/4331092/finding-all-combinations-of-javascript-array-values">this Stack Overflow question</a> to calculate all possible combinations from an array, which may contains strings.</p> <p>For example:</p> <blockquote> <pre class="lang-none prett...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T19:47:40.413", "Id": "90256", "Score": "4", "body": "On second thoughts I guess I could check if it's a string one for each and if it is, just wrap it in an array." } ]
[ { "body": "<ol>\n<li><p>You don't need the <code>else if/else</code> blocks at the top; it can just be <code>if</code> blocks, since they return and thus exit the function anyway.</p>\n\n<pre><code>if (arr.length === 0) {\n return []; // stop here\n} \n\nif (arr.length === 1){\n return arr[0]; // or here\n}\n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T19:41:02.843", "Id": "52119", "Score": "8", "Tags": [ "javascript", "strings", "array", "node.js", "combinatorics" ], "Title": "Calculate all possible combinations of an a...
52119
<p>This function is part of a the <code>Registry</code> class that can be found <a href="https://drive.google.com/file/d/0By73nGP34fPoQjYyU1Izc2FRSWs/edit?usp=sharing" rel="nofollow">on Google Drive</a>. The class was originally written by <a href="http://www.vbaccelerator.com/codelib/inireg/registry.htm" rel="nofollow...
[]
[ { "body": "<p>This is probably a typo:</p>\n\n<blockquote>\n<pre><code>On Error GoTo ErrHandler:\n</code></pre>\n</blockquote>\n\n<p>It should read as:</p>\n\n<pre><code>On Error GoTo ErrHandler\n</code></pre>\n\n<p>The <code>:</code> denotes a <em>label</em>, or separates multiple instructions on a single line...
{ "AcceptedAnswerId": "52137", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T21:29:25.460", "Id": "52122", "Score": "5", "Tags": [ "recursion", "vba", "windows", "vb6" ], "Title": "Recursively searching the Windows Registry" }
52122
<p>I've thrown everything I can at this, and I can't get it to lock or crash. My hope is that I have applied the principles correctly. I write client apps in JavaScript, and this is only the 3rd .NET class I've ever written (using JScript), so a topic as advanced as this really needs a once-over by some experienced dev...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T22:04:55.927", "Id": "90273", "Score": "0", "body": "Welcome to Code Review! Verbose indeed, but I guess there can never really be *too much context* given ;) I hope you enjoy the ride, feel free to browse around while waiting for a...
[ { "body": "<p>Don't right align your comments that way. It makes it near impossible to read the code and the comment at the same time. They're useless out there. I personally don't mind end of line comments, but <em>right aligned</em>... no. Others may disagree with me though.</p>\n\n<p>To clarify, this is hard...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T21:50:40.320", "Id": "52124", "Score": "11", "Tags": [ "c#", "beginner", "multithreading", ".net", "thread-safety" ], "Title": "Multithreading class for asynchronous usage...
52124
<p>I have created a custom <code>HtmlHelper</code> to render a <code>Grid</code>, and it's working fine, but I know for sure that it isn't written really nicely.</p> <p>I'll provide you with the code that's most important for the grid.</p> <p>First of all, the model which I pass to my grid is an <code>IEnumerable&lt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-12-30T04:09:01.640", "Id": "136690", "Score": "0", "body": "Please do not modify the original code after receiving answers." } ]
[ { "body": "<p>I like the fluent API. Nitpicks first:</p>\n\n<ul>\n<li>Drop the <code>#region</code> blocks. They only add clutter, for example <code>#region IHtmlString Members</code> is only confusing, since it's not immediately apparent that <code>GridBuilder</code> implements <code>IHtmlString</code> (perhap...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T22:02:30.350", "Id": "52125", "Score": "3", "Tags": [ "c#", "asp.net-mvc", "helper" ], "Title": "Custom HtmlHelper to render a Grid" }
52125
<p>This is my Java implementation (\$O(n)\$) about how to calculate infix expression with no parenthesis.</p> <p>For example, when we input "3 + 4 * 4 / 8", we will get a double type answer is 5.0. Here to make the algorithm simple, we don't consider any parenthesis in the expression.</p> <p>I think my implementation...
[]
[ { "body": "<p>It is common, when processing things like this, to use a <a href=\"http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern\" rel=\"nofollow\">chain-of-responsibility pattern.</a></p>\n\n<p>In this case, you can create an operator interface, or abstract class:</p>\n\n<pre><code>public interfac...
{ "AcceptedAnswerId": "52132", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T23:24:19.343", "Id": "52130", "Score": "10", "Tags": [ "java", "algorithm" ], "Title": "Calculating infix expression with no parenthesis" }
52130
<p>So my project was to make an algorithm that finds a path out the maze using "backtracking" to help. This is my first time attempting to solve anything with backtracking so I want to be sure if what I did is actually backtracking and if it is an efficient way to apply it to my problem. Bellow is the main logic:</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T10:26:53.887", "Id": "90313", "Score": "0", "body": "Could you provide your main method and the `mazeData.txt` so that we can try out your code ourselves?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-...
[ { "body": "<p>It is <em>almost</em> backtracking.</p>\n\n<p>There are two very different reasons for <code>solve</code> to return: either it got stuck, or it reached the goal. The (recursive) caller should react accordingly: inspect another neighbor or return happily. Your code disregards the reason, and forces...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T00:54:08.903", "Id": "52138", "Score": "1", "Tags": [ "java", "algorithm", "backtracking" ], "Title": "Is this a true backtracking algorithm?" }
52138
<p><strong>Problem</strong></p> <p>I am learning about HPC and code optimization. I attempt to replicate the results in <a href="http://www.cs.utexas.edu/users/pingali/CS378/2008sp/papers/gotoPaper.pdf" rel="nofollow noreferrer">Goto's seminal matrix multiplication paper</a>. Despite my best efforts, I cannot get over...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T21:53:43.767", "Id": "91336", "Score": "0", "body": "What is your physical hardware...? 4-core with HT?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T03:20:07.317", "Id": "91364", "Score": "...
[ { "body": "<p>Without addressing performance concerns, some trivial observations:</p>\n\n<ul>\n<li><code>#include &lt;omp.h&gt;</code> is unnecessary. (You use OpenMP, but don't call any OpenMP functions.)</li>\n<li>The <a href=\"https://stackoverflow.com/q/204476/1157100\">return type of <code>main()</code></...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T01:08:40.893", "Id": "52140", "Score": "6", "Tags": [ "optimization", "c", "matrix", "sse", "openmp" ], "Title": "Optimizing multiplication of square matrices for full CPU...
52140
<p>I'm working on class for a hash table where collisions are corrected using cuckoo hashing, I had difficulty writing the insert function, the function is supposed to insert the key if the <code>h(key)</code> is available, if not it is supposed to find the shortest "path" for moving other keys in order to find a place...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T06:55:22.427", "Id": "90307", "Score": "0", "body": "You keep saying *\"supposed to\"* - have you tested it? Does it actually work?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T07:07:29.683", "...
[ { "body": "<p>For one thing, I would suggest using a better name for your helper-function, that describes what it does:</p>\n\n<pre><code>def _find_insert_path(...):\n</code></pre>\n\n<p>Note the leading underscore - this is Python convention for \"don't call this directly from outside the class\". Users should...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T06:47:39.033", "Id": "52146", "Score": "2", "Tags": [ "python", "optimization", "classes", "hash-map" ], "Title": "How can I optimize my insert function for the cuckoo hash ta...
52146
<p>Next version of <a href="https://codereview.stackexchange.com/questions/51624/adding-a-duplicate-entry-randomly-into-a-list-in-haskell-using-random-monad">Adding a duplicate entry randomly into a list in haskell using random monad</a></p> <p>I wrote this trying to set up a Haskell testcase. The aim is to take a lis...
[]
[ { "body": "<p>I'd again advise against using monadic computations that produce lazy infinite lists. For most monads (including <code>State</code>) <a href=\"https://stackoverflow.com/q/14494648/1333025\"><strong>this does not work</strong></a>. For <code>MonadRandom</code> it works only very special cases, when...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T08:07:33.600", "Id": "52149", "Score": "3", "Tags": [ "haskell", "linked-list", "random", "monads" ], "Title": "v2 - Adding a duplicate entry randomly into a list in haskell u...
52149
<p>I have a bottleneck in my program at the point where I calculate the digit sum and product of a number. I am using GMP because I have to work with numbers that follow \$1e8 &lt; n &lt; 1e80\$. </p> <p>To calculate the sum/product of a number, I initially used strings, thinking the division/modulo method would resul...
[]
[ { "body": "<p>There are a few ways to speed up your division. First, note that because <code>rem</code> is declared within the <code>while</code> loop, it's both constructed and destroyed every loop iteration. That's not really necessary, so you could instead declare it outside the loop and simply assign a ne...
{ "AcceptedAnswerId": "52156", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T10:57:03.687", "Id": "52151", "Score": "5", "Tags": [ "c++", "performance", "comparative-review", "gmp" ], "Title": "Optimizing digit sum and product with GMP" }
52151
<p>I have an application in Ruby on Rails (3.2) and I want all the requests to take into account the currently logged in user's time zone. Also, I want to have a helper that will let me display date time fields using user's time zone.</p> <p>I follow this approach:</p> <ol> <li><p>Inside <code>ApplicationController</...
[]
[ { "body": "<p>If your usecase is displaying localized time in views then please handle it in frontend, i.e. using <a href=\"http://timeago.yarp.com/\" rel=\"nofollow\">http://timeago.yarp.com/</a> </p>\n\n<p>Handling timezone in backend will be big pain when you try to add caching (you will need to cache same p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T14:54:12.180", "Id": "52154", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "datetime" ], "Title": "Processing requests using the user's time zone" }
52154
<p>I am trying to provide a fluent API for authorization <a href="http://profsandhu.com/journals/computer/i94rbac%28org%29.pdf">based on roles</a>. As you will see I separated my implementation in two related Interfaces the Session and the Query. The session provides all roles, permissions and user information, so one ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T20:49:01.633", "Id": "91781", "Score": "0", "body": "Have you taken a look at the asp.net identity claims stuff? It seems capable of achieving a lot of these things and is fairly simple and standardized." }, { "ContentLicens...
[ { "body": "<blockquote>\n<pre><code>public delegate IEnumerable&lt;string&gt; GetUserPermissions(IPrincipal user, object resource);\npublic delegate IEnumerable&lt;string&gt; GetUserRoles(IPrincipal user, object resource);\npublic delegate bool IsUserInRole(IPrincipal user, object resource);\n</code></pre>\n</b...
{ "AcceptedAnswerId": "52404", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T15:26:32.263", "Id": "52155", "Score": "12", "Tags": [ "c#", "security", "authorization" ], "Title": "Fluent API of a Role based access control implementation" }
52155
<p>Input is a file containing numbers in this format:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>1.2 3 5.1 2 7 4 6 5 2 9.22 1 0.0 4 3 </code></pre> </blockquote> <p>I am doing the sorting in the simplest way, using <code>Collections.sort</code> method. The running code is as follows:</p> ...
[]
[ { "body": "<p>There are a few improvements I can see, but not really related to performance (though it may run a bit faster anyway).</p>\n\n<p>If the files are small (less than 10Megabytes or so), then the relative performance of different approaches are slight (obviously, you can bork your code, but the IO par...
{ "AcceptedAnswerId": "52159", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T18:30:07.360", "Id": "52158", "Score": "10", "Tags": [ "java", "performance", "sorting", "collections" ], "Title": "Sorting numbers using Java Collections.sort()" }
52158
<p>I'm working on writing code which gets several pieces of an image, and reconstructs them to one whole picture. The images are represented by matrices, and two pieces should be "glued" if the right column of one matrix is the same as the left column in the other one.</p> <pre><code>from images import * def reconst...
[]
[ { "body": "<p>First - some minor comments regarding your code:</p>\n\n<ul>\n<li><p>you are saying that all pieces of equal size, then it doesn't make sense to do <code>rows,cols=candidate.dim()</code> in a loop</p></li>\n<li><p>I never worked with <code>Matrix</code> class, but I assume that <code>[0:rows,0:1]<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T19:15:35.577", "Id": "52161", "Score": "2", "Tags": [ "python", "optimization", "matrix", "image" ], "Title": "How can I enhance my jigsaw puzzle solver function?" }
52161
<p>I've written these two command-line tools to be used to facilitate forestry surveys.</p> <p>For a little background, the idea here is that often a landowner needs to know precisely how much wood is coming out of his dirt. Not only that, but he has to account for the fact that you can't turn a cylinder (trees) into ...
[]
[ { "body": "<pre><code>def load_trees():\n trees=dict()\n</code></pre>\n\n<p>You only use this variable in the case that you successfully opened the file. I'd move it after the open.</p>\n\n<pre><code> try:\n with open(\"trees.txt\",\"r\") as treefil:\n</code></pre>\n\n<p>I recommend not shortening ...
{ "AcceptedAnswerId": "52163", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T19:22:56.717", "Id": "52162", "Score": "7", "Tags": [ "python", "python-3.x" ], "Title": "Tapes, Trees, Trunks & Tallies" }
52162
<p>Please do not mix Authorization with Authentication. As stated authorization is concerned about managing user access to the application resources whilst authentication is concerned about identifying a user of an application.</p> <p>In authorization there are three different actors: Actions, Users and Resources. Th...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-05-31T21:22:24.797", "Id": "52164", "Score": "0", "Tags": null, "Title": null }
52164
Authorization is the module of an application that is responsible to manage user access to the application resources.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T21:22:24.797", "Id": "52165", "Score": "0", "Tags": null, "Title": null }
52165
<p>I use these in a windows form with fun buttons, I wanted to see what the world thinks of my coding.</p> <p>This is something that I coded about 2-3 years ago, I did change some of the coding when I looked at it and thought "this could be better written like this"</p> <p>Let me know what you think and what I could ...
[]
[ { "body": "<h2>Simpler Methods.</h2>\n\n<p>the code:</p>\n\n<blockquote>\n<pre><code>public string removeSpaces(string plainIn)\n{\n plainIn = plainIn.Replace(\" \", string.Empty);\n return plainIn;\n}\n</code></pre>\n</blockquote>\n\n<p>Could be:</p>\n\n<pre><code>public string removeSpaces(string plainI...
{ "AcceptedAnswerId": "52170", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T21:49:51.543", "Id": "52166", "Score": "6", "Tags": [ "c#", "cryptography", "caesar-cipher" ], "Title": "Simple Caesar shifter in C#" }
52166
<p>I've written this code keeping the following cases in mind and I think I've covered them all. I'd really appreciate if someone could help me determine if I've covered all of them.</p> <p>Cases I considered:</p> <ol> <li>No comments at all </li> <li><code>Text /* Text */ Text</code> </li> <li><code>Text /* Text */...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T23:13:08.100", "Id": "91344", "Score": "0", "body": "There seem to be (at least) a few cases you haven't considered. For example, (at least if memory serves), a `/*` inside a string literal does not start a comment." }, { "C...
[ { "body": "<p>You didn't specify whether or not nested comments are allowed, but your code trims only the shorter comment. For example, case 4 would yield <code>Text Text</code> with nesting but <code>Text */ Text</code> without. It would be helpful to include some unit tests to demonstrate the intent.</p>\n\...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T22:44:07.527", "Id": "52173", "Score": "4", "Tags": [ "java", "strings", "parsing" ], "Title": "Stripping out all /* */ comments from a paragraph" }
52173
<p>Using Python/Cython, I am trying to construct an efficient way to index boolean values. I have been trying to use the <a href="https://pypi.python.org/pypi/bitarray/0.8.1" rel="nofollow noreferrer">bitarray</a> and/or <a href="https://pypi.python.org/pypi/bitstring/3.1.3" rel="nofollow noreferrer">bitstring</a> pack...
[]
[ { "body": "<p>What exactly do you want to do with your array of booleans? If you used numpy, you could instantiate your boolean array as an array of <code>uint8</code> one eighth the size of the boolean array, e.g.</p>\n\n<pre><code>In [38]: a = np.random.randint(256, size=(1000000//8,)).astype(np.uint8)\n</cod...
{ "AcceptedAnswerId": "52187", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T04:59:12.917", "Id": "52182", "Score": "2", "Tags": [ "python", "memory-management", "bitwise", "cython" ], "Title": "Fastest / most efficient random bit indexing in Python...
52182
<p>A friend helped me put the following code together, which is made up of a series of repetitive <code>loadContent()</code> functions. I've just shown the first two functions but they're all the same.</p> <p>The code works fine but I'm wondering if anyone could give me a tip as to how I could reduce the bloat in this...
[]
[ { "body": "<p>You could simplify like so:</p>\n\n<p>For the HTML, you could embed specifics as <code>data-*</code> attributes, which you can fetch in JS later on.</p>\n\n<pre><code>&lt;div class=\"content\" data-source=\"//cgi-bin/mggsn_ssr21.cgi\" data-refreshtext=\"#refresh1text'&gt;\n ...\n&lt;/div&gt;\n\n&...
{ "AcceptedAnswerId": "52184", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T05:01:44.343", "Id": "52183", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Series of repetitive content-loading functions" }
52183
<p>I got bored with opening and closing files whenever I need to write to one, so I wrote a <code>FileWriter</code> class that's used like this:</p> <pre><code>Public Sub TestWriter() On Error GoTo ErrHandler Dim writer As New FileWriter If writer.OpenFile("c:\test.txt") Then writer.WriteLine "foo...
[]
[ { "body": "<p>Using <code>Catch:</code> as a label for <code>On Error GoTo</code> is a bad, misleading idea. Error handling in <a href=\"/questions/tagged/vb6\" class=\"post-tag\" title=\"show questions tagged &#39;vb6&#39;\" rel=\"tag\">vb6</a>/<a href=\"/questions/tagged/vba\" class=\"post-tag\" title=\"show ...
{ "AcceptedAnswerId": "52231", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T06:37:27.530", "Id": "52185", "Score": "9", "Tags": [ "vba", "error-handling", "io", "vb6" ], "Title": "FileWriter supporting writing to multiple files" }
52185
<p>I have this table (<code>inradar_ad</code>) with almost 300k entries. I want to know why my query takes 160 secs to run. </p> <p>I tried limiting with <code>LIMIT 10</code> to see if I get a speed boost, I but didn't. Does <code>LIMIT</code> speed anything up? I don't think so in this case, since it has to calcula...
[]
[ { "body": "<p>I see no index on the <code>latitude</code> and <code>longitude</code> columns of the <code>location</code> table. Try</p>\n\n<pre><code>CREATE INDEX location_latlng ON `location` (`latitude`, `longitude`);\n</code></pre>\n\n<p>If it's still slow, then add the output of <code>EXPLAIN SELECT</code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T12:53:45.167", "Id": "52193", "Score": "11", "Tags": [ "performance", "sql", "mysql", "geospatial", "join" ], "Title": "Geographic search" }
52193
<p>Please review my servlet.</p> <pre><code>public class Controller extends HttpServlet { private static final long serialVersionUID = 1L; static List &lt; MRTBean &gt; stop1 = new ArrayList &lt; &gt; (); static List &lt; MRTBean &gt; stop2 = new ArrayList &lt; &gt; (); static List &lt; MRTBean &gt; st...
[]
[ { "body": "<p>I'm not very familiar with JSP and EL (which isn't very good considering I have an exam on it in a few days), but in general Java terms you can simplify it a lot by moving the separate lists to a <code>Map&lt;String, List&lt;MRTBean&gt;&gt;</code> which will do the mapping for you so you won't nee...
{ "AcceptedAnswerId": "52199", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T13:14:56.910", "Id": "52194", "Score": "9", "Tags": [ "java", "mvc", "servlets", "jsp" ], "Title": "MVC controller code" }
52194
<p>I would like a review on my <code>Console</code> class I made in JavaFX 8. It features the following:</p> <ul> <li>A text field where you can enter input, the input gets copied into the text area.</li> <li>A text area where you can observe output and see the input.</li> <li>When you press enter, you send the messag...
[]
[ { "body": "<p>As someone who's been working with your project and your Console Gui here's my 2 cents:</p>\n\n<blockquote>\n<pre><code>protected final TextArea textArea = new TextArea();\nprotected final TextField textField = new TextField();\n</code></pre>\n</blockquote>\n\n<p>these could use a rename. The name...
{ "AcceptedAnswerId": "55338", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T15:05:17.437", "Id": "52197", "Score": "11", "Tags": [ "java", "gui", "javafx" ], "Title": "Console component in JavaFX" }
52197
<p>I wanted to do some statistics over the history of a Git repository. At first I tried using GitPython, but it wasn't as trivial as I imagined it to be. In the end, I just call the necessary git commands with the submodule module.</p> <p>Can this code be considered clean and readable or does it have some style issue...
[]
[ { "body": "<p>A few small comments:</p>\n\n<ul>\n<li>I would suggest to use exit codes (<code>sys.exit()</code>), it will help you if you are planning to you your script together with other scripts (chaining it, or use from shell scripts)</li>\n<li>I would consider that <code>subprocess.check_output([\"git\", ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T16:21:23.723", "Id": "52198", "Score": "5", "Tags": [ "python", "git" ], "Title": "Base for iterating over git history" }
52198
<p>I am writing a text classifier, and in order to do so, I need TF/IDF values per every word of my single text.</p> <p>Then I need to use the cosine similarity:</p> <p>$$similarity = cos(\theta) = \dfrac{A \cdot B}{\lVert A \lVert \lVert B \lVert} = \dfrac{\overset{n}{\underset{i=1}{\LARGE\Sigma}}A_i \times B_i}{\...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T19:50:32.220", "Id": "91436", "Score": "2", "body": "\"the main method seems very very unoptimized\"... ***which main method?***" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T20:16:27.040", "Id"...
[ { "body": "<p><strong>Edit in response to OP comment above:</strong></p>\n\n<p><code>CreateCategoryClasses</code> may appear to be slow because of the <code>WaitOne</code> calls. You're essentially waiting waiting on either <code>ParseCategories</code> or <code>AddIDF</code> to complete before moving on. It wo...
{ "AcceptedAnswerId": "52219", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T16:56:42.210", "Id": "52202", "Score": "4", "Tags": [ "c#", "multithreading", ".net", "memory-management" ], "Title": "Slow data-processing and inefficient memory usage in ...
52202
<p>The program is running fine but I was just wondering whether there was anything I could do to make it more user friendly or efficient.</p> <pre><code>from random import randint import time word = "a" shield = 5 #The main function def main(): #This will trigger the introduction intro() while True: ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T19:20:32.507", "Id": "91433", "Score": "4", "body": "You could make the improvement [I already suggested](http://stackoverflow.com/a/23978761/3001761)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T...
[ { "body": "<p>You have a huge number of <code>if-else</code> constructions. This is fine, but in many cases can be clarified using a dictionary or other mapping from the conditions to the things you do in the branch.</p>\n\n<p>For example:</p>\n\n<pre><code> if chest == 1:\n print (\"You have ...
{ "AcceptedAnswerId": "52292", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T17:58:27.613", "Id": "52208", "Score": "6", "Tags": [ "python", "beginner", "python-3.x", "adventure-game" ], "Title": "Simple Python maze game" }
52208