body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have written a deliberately pretty simple class that wraps a <code>std::vector</code> to basically make it capable of self-populate itself with random generated numbers, simply to be able to test the result of some sorting algorithms that I'm working on. </p> <p><em>This is only a hobby project</em>, it is not p...
[]
[ { "body": "<ul>\n<li><p>In addition to having <code>begin()</code> and <code>end()</code>, you should also have <code>cbegin()</code> and <code>cend()</code> for <code>const</code> iterators. These also are provided by <code>std::vector</code>.</p></li>\n<li><p>If you have <code>at()</code>, you should also ov...
{ "AcceptedAnswerId": "52242", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T19:11:29.737", "Id": "52213", "Score": "8", "Tags": [ "c++", "c++11", "random", "vectors" ], "Title": "std::vector composition with self populating super-powers" }
52213
<p>I finished a program to do connected component analysis using union - find algorithm. Is it true that the complexity of the code is \$O(N logN)\$, where \$N\$ is the total number of pixels (512x512 by example, not 512).</p> <p>Is there any way to improve the performance?</p> <pre><code>import cv2 import numpy as n...
[]
[ { "body": "<blockquote>\n <p>Is it true that the complexity of the code is O(NlogN), where N is the total number of pixels (512x512 by example, not 512).</p>\n</blockquote>\n\n<p>You main loop in <code>bwlabel</code>is:</p>\n\n<pre><code>for i in range(M - 1):\n for j in range(N - 1):\n if (im[i][j] ...
{ "AcceptedAnswerId": "52592", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-06-01T19:34:08.503", "Id": "52216", "Score": "5", "Tags": [ "python", "performance", "opencv" ], "Title": "Connected component analysis" }
52216
<p>I need to do a few hundred million euclidean distance calculations every day in a Python project.</p> <p>Here is what I started out with:</p> <pre><code>#!/usr/bin/python import numpy as np def euclidean_dist_square(x, y): diff = np.array(x) - np.array(y) return np.dot(diff, diff) </code></pre> <p>This i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T20:09:38.160", "Id": "91440", "Score": "0", "body": "Welcome to Code Review! This will likely get you a [tag:performance] review - if you want your complete code peer reviewed, feel free to embed it into your question as well." },...
[ { "body": "<p>You can decrease Python's overhead by parsing the <code>args</code> tuple and creating the return value manually.</p>\n\n<p>Try changing these portions of your code:</p>\n\n<pre><code>/* Parse the input tuple */\nif (!PyArg_ParseTuple(args, \"OO\", &amp;x_obj, &amp;y_obj))\n return NULL;\n\n&lt...
{ "AcceptedAnswerId": "52221", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T20:00:46.290", "Id": "52218", "Score": "14", "Tags": [ "python", "performance", "c", "numpy", "clustering" ], "Title": "Possible optimizations for calculating squared e...
52218
<p>I've posted <a href="https://codereview.stackexchange.com/questions/51272/first-try-at-a-python-game">this</a> some time ago. Here is the new version that I made based on all the comments that were made. Another look would be much appreciated, especially on:</p> <ul> <li><p>Getting rid of the <code>global</code> st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T16:49:12.387", "Id": "91536", "Score": "0", "body": "Function names should be `lowercase_with_underscores` ([PEP 8](http://legacy.python.org/dev/peps/pep-0008/)). And spell out the name of `addbp` as `add_body_parts`, to match `remo...
[ { "body": "<p>Quick answer but the part in the <code>with open(loadfile, 'rt') as file:</code> block \ndefinitly looks wrong to me. Here are a few suggestions.</p>\n\n<hr>\n\n<p>You shouldn't use the same variable for different purposes :</p>\n\n<pre><code>newitem = ''\nnewitem = newitem.join(line)\nsome_functi...
{ "AcceptedAnswerId": "52268", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T23:03:01.053", "Id": "52228", "Score": "6", "Tags": [ "python", "game", "python-3.x", "dice" ], "Title": "Spin-the-bottle-like game, follow-up" }
52228
<p>To learn the language of JavaScript, I did a dojo exercise by Roy Osherove. Is there a better way to organize this so that the only method exported is <code>add</code> while keeping it in one single module?</p> <pre><code>module.exports = { add: function (string) { this._checkForError(string); this._check...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T03:26:33.480", "Id": "91467", "Score": "0", "body": "Yes, don't export it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T03:27:24.850", "Id": "91468", "Score": "0", "body": "I see what y...
[ { "body": "<p><code>module.exports</code> is just an object. Set properties on it that you want to expose.</p>\n\n\n\n<pre class=\"lang-js prettyprint-override\"><code>exports.add = add\n</code></pre>\n\n<p>This is also equivalent in this case.</p>\n\n<pre class=\"lang-js prettyprint-override\"><code>module.exp...
{ "AcceptedAnswerId": "52285", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T03:07:17.430", "Id": "52236", "Score": "4", "Tags": [ "javascript", "node.js", "modules" ], "Title": "Module to validate and sum a string containing no negative numbers" }
52236
<p>One of my first ever <a href="http://jython.org" rel="nofollow">Jython</a> scripts lets me get comma-separated values out of an RDBMS:</p> <pre><code>from java.lang import System from java.sql import DriverManager, ResultSet import csv import cStringIO as StringIO import sys def doIt(): if System.getProperty("j...
[]
[ { "body": "<p>Some JDBC-related notes:</p>\n\n<ul>\n<li><p>use <a href=\"http://docs.oracle.com/javase/8/docs/api/java/sql/ResultSetMetaData.html#getColumnLabel-int-\" rel=\"nofollow\"><code>getColumnLabel()</code></a> instead of <code>getColumnName()</code></p></li>\n<li><p>using <a href=\"http://docs.oracle.c...
{ "AcceptedAnswerId": "52240", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T03:33:15.620", "Id": "52239", "Score": "4", "Tags": [ "csv", "jdbc", "jython" ], "Title": "Converting JDBC to CSV" }
52239
<p>I have converted this code from Java to Scala, and I need reviews. This works fine, but I am sure that something is wrong with this coding pattern.</p> <pre><code>package models import org.apache.log4j.ConsoleAppender import org.apache.log4j.Level import org.apache.log4j.Logger import org.apache.log4j.PatternLayo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-28T20:45:46.833", "Id": "97429", "Score": "0", "body": "This feels like it's configuring Log4j more than it's doing logging. XML files or a `.properties` file are meant to be used for configuring Log4j. I would say that there is indeed...
[ { "body": "<p>I'm not exactly sure what you mean with coding pattern, but there are some things that strike me as odd:</p>\n\n<ol>\n<li><p>you only log empty messages ... in some of the cases encoding the message in the logger name. This certainly isn't the way log4j is intended to be used.</p></li>\n<li><p>Whe...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T05:02:48.067", "Id": "52241", "Score": "3", "Tags": [ "scala", "logging" ], "Title": "Apache log4j in play framework" }
52241
<p>Please review my short 65 lines of code:</p> <ul> <li>Is there a way to avoid <code>eval</code> (security)?</li> <li>Is there a better way or place to use <code>shopt -s nullglob</code>?</li> <li>Does <code>shopt -u nullglob</code> always need to be unset through each iteration?</li> <li>Is there a smarter way to d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T08:43:01.190", "Id": "92384", "Score": "0", "body": "I don't think your edit added much value, and I see no problem with the way I posted my question." } ]
[ { "body": "<p>Your questions:</p>\n\n<ol>\n<li>Yes. Use double quotes and then drop the eval (this will also cause the script to show <code>/path/to/prod/home</code> instead of <code>$PROD_HOME</code>)</li>\n<li>Yes, just do it once at the start of the script.</li>\n<li>No. </li>\n<li>Depends on your requiremen...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T06:44:47.753", "Id": "52243", "Score": "2", "Tags": [ "bash" ], "Title": "Grep to search for array of location targets" }
52243
<p>This question is related to this <a href="https://codereview.stackexchange.com/questions/51298/implement-operation-and-simulation-mode-in-an-interface">topic</a>.</p> <p>Context:</p> <pre><code>class OperationDevice(Device): def __init__(self): super(OperationDevice, self).__init__() def operation...
[]
[ { "body": "<blockquote>\n <p>I am wondering wether is it possible to define automatically all method from SimulationDevice linked with mode = \"simulation\" (same for OperationDevice with \"operation\") without having to specify for each method (self._start_map for example) in constructor (init) of DualModeDev...
{ "AcceptedAnswerId": "52283", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T07:07:13.440", "Id": "52246", "Score": "2", "Tags": [ "python", "inheritance" ], "Title": "Call method of specific parent class" }
52246
<p>In an interview I was asked to solve the following problem:</p> <blockquote> <p>find a subarray with max sum</p> </blockquote> <p>I have written a piece of code for the same. I need your help in reviewing this code.</p> <pre><code>package com.ankit.rnd; public class MaxSubArrSum { int largestSum=0; i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T13:19:10.147", "Id": "91507", "Score": "3", "body": "This a well-known problem with a very efficient solution. Check out: [Maximum Subarray Problem](http://en.wikipedia.org/wiki/Maximum_subarray_problem)" }, { "ContentLicens...
[ { "body": "<p>It can be done a lot more simpler. What reason do you split array for? I think, you should change global approach. It is a very simple task for 2 nested loops: </p>\n\n<p>You should use something like this in pseudocode:</p>\n\n<pre><code>for (int i = 0; i &lt; array.length; ++i) {\n for (int j...
{ "AcceptedAnswerId": "52262", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T08:58:01.417", "Id": "52249", "Score": "8", "Tags": [ "java", "array", "interview-questions" ], "Title": "Find the subarray with the max sum" }
52249
<p>I have this code which works for uploading multiple files (images). However, it seems inefficient due to having to a function for every single file upload (for 2 uploads, but there will be about 12 in total).</p> <pre><code>function readURL1(input) { if (input.files &amp;&amp; input.files[0]) { var read...
[]
[ { "body": "<p>No need for a loop. The only difference between the functions is the target image (I assume it's an image, since DIVs don't have a <code>src</code>attribute), so change the function to get the target from an data attribute of the input field:</p>\n\n<pre><code>function readURL(input) {\n if (in...
{ "AcceptedAnswerId": "52258", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T09:02:39.353", "Id": "52250", "Score": "5", "Tags": [ "javascript", "jquery" ], "Title": "Uploading multiple images" }
52250
<p>In Model View Presenter (<code>MVP</code>) pattern, it is said that our <code>DAL</code> always should returns business models. </p> <ol> <li><p>If I want to get a list of business objects from my <code>DAL</code>, is it acceptable to do it as follows or better to get a <code>DataTable</code> from <code>DAL</code> ...
[]
[ { "body": "<h3>Your Question</h3>\n<p><code>System.Data.DataTable</code> lives under the <code>System.Data</code> namespace; one good way to start mixing concerns in your BLL is to reference <code>System.Data</code>, and then you don't even need a DAL any more and can have your BLL directly access the database....
{ "AcceptedAnswerId": "52274", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T09:11:36.747", "Id": "52251", "Score": "4", "Tags": [ "c#", "object-oriented", ".net", "mvp", "ado.net" ], "Title": "DAL Returns a collection of business objects in MVP...
52251
<p>I've two similar functions and I want to use one generic function with two params, <code>dialog</code> and <code>buttons</code>. How do I do it?</p> <p>My functions:</p> <pre><code>LanguageLogosView.showConfirmRemoveDialog = function () { var def = $.Deferred(); var buttons = { buttons: { ...
[]
[ { "body": "<p>First of all, always return <code>def.promise()</code> - not <code>def</code> itself. If you return the Deferred object itself, other code can call <code>resolve/reject</code> on it. So keep <code>def</code> to yourself, and only return its promise.</p>\n\n<p>Also, why not use <code>reject()</code...
{ "AcceptedAnswerId": "52264", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T10:24:08.057", "Id": "52252", "Score": "3", "Tags": [ "javascript", "jquery", "promise" ], "Title": "Two dialog boxes using Deferreds?" }
52252
<p>I'm looking for some JavaScript code improvement and optimization. Is it possible to optimize this block of code (for example, remove double array loop)?</p> <pre><code>replace: function(ex, str) { var arr = str.match(/{add_([A-Z]+)}/gi); if (arr &amp;&amp; arr.length) { arr.each(function(e){ ...
[]
[ { "body": "<p>You should be using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace\" rel=\"nofollow\"><code>String.prototype.replace()</code></a> with a function as the second argument. Example:</p>\n\n<pre><code>str = str.replace(/{add_([A-Z]+)}/gi, func...
{ "AcceptedAnswerId": "52255", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T10:28:20.927", "Id": "52253", "Score": "1", "Tags": [ "javascript", "array" ], "Title": "Find-and-replace optimization" }
52253
<p>I have written simple code which loops through a list object and create groups in <code>ListView</code> depending on the data in the list. I have a list object of type <code>List&lt;Assignment&gt;</code> where <code>Assignment</code> is a class as follows.</p> <pre><code>public class Assignment { public TimeSpa...
[]
[ { "body": "<p>It's possible with the help of LINQ to reduce your code to this (assuming, of course, the version of .NET you're using will allow it):</p>\n\n<pre><code>private void FeedDataToPane(IEnumerable&lt;Assignment&gt; assignmentList)\n{\n MonitorPane.BeginUpdate();\n MonitorPane.Groups.Clear();\n ...
{ "AcceptedAnswerId": "52269", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T11:48:42.087", "Id": "52261", "Score": "5", "Tags": [ "c#", ".net", "wpf" ], "Title": "Adding groups to ListView depending on the data in a list" }
52261
<p>I've just written my first full batch of RSpec tests and wondered if anyone can comment at a glance on how they might be written easier, more readable, faster etc. There are some pending specs so excuse those. It should describe what they will test when I finish. I've given examples of models, controllers and featu...
[]
[ { "body": "<p>For the model tests, you can get by with less. By testing all the validations in such detail, you're partly checking whether <em>Rails</em> works - and you can usually assume that Rails works just fine. If not, well, Rails already has tests you can run.</p>\n\n<p>So rather than checking for specif...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T11:55:05.157", "Id": "52263", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "rspec" ], "Title": "Various RSpec tests" }
52263
<p>I'm aiming to get this program right as I might show it at a job interview. The code below runs fine but I would like to know if there's anything that can be improved in terms of readability, good practices and/or standards. The program asks a user to take money from a checking account and move it to a savings accou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T18:35:32.663", "Id": "91545", "Score": "1", "body": "Guys, I just wanted to say THANKS for all your suggestions. I'll spend some quality time going through each one, hopefully the code will look neat after the changes." }, { ...
[ { "body": "<p>I don't like 2 points:</p>\n\n<ol>\n<li><p>Your static connection variables:</p>\n\n<pre><code>// Connection variables\nstatic Connection conn = null;\n</code></pre>\n\n<p>If you want to access the connection from everywhere, create a singleton class <code>ConnectionManager</code>.</p></li>\n<li><...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T12:47:23.957", "Id": "52265", "Score": "15", "Tags": [ "java", "sql", "mysql", "finance" ], "Title": "Asking a user to take money from a checking account and move it to a savi...
52265
<p>This is the code I ended up with that implements the approach I described in a <a href="https://codereview.stackexchange.com/a/52262/31562">recent answer to another question about the same problem</a></p> <p>The basic idea here is to not loop through more things than necessary.</p> <p>I have also added a parameter...
[]
[ { "body": "<p>The code appears to be sane, and reasonable.</p>\n\n<h2>Logic Duplication</h2>\n\n<p>There are a couple of logic duplications. For example:</p>\n\n<blockquote>\n<pre><code> // If this value is below zero, there's no need in starting to loop here,\n // it's better to start looping o...
{ "AcceptedAnswerId": "52276", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T14:15:27.727", "Id": "52270", "Score": "21", "Tags": [ "java", "performance", "array", "interview-questions" ], "Title": "Finding the sub-array with the maximum sum - my ap...
52270
<p>I could really use another set of eyes on this. No one else in the office has a lot of experience working with Android, so I'm on my own with this one.</p> <p>The goal of this class is to encapsulate an image which can be sourced from a camera or file so that it can be uploaded to one of our servers using a POST re...
[]
[ { "body": "<pre><code>static String filePathFromUri(Context context, Uri uri) {\nUri getUri() {\nvoid invalidate() {\nString getFilepath(Uri uri) {\n</code></pre>\n\n<p>Missing access modifier. Is that intentional?</p>\n\n<pre><code> if (cursor != null) {\n // Here you will get a NPE if cursor...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T14:37:43.687", "Id": "52271", "Score": "4", "Tags": [ "java", "android", "image", "stream" ], "Title": "Parcelable Bitmap with the intention of uploading the bitmap" }
52271
<p>I have written a simple (read: incomplete) tuple implementation that, AFAICT, does not violate the standard layout requirements. It's largely based on <a href="http://voidnish.wordpress.com/2013/07/13/tuple-implementation-via-variadic-templates/" rel="nofollow noreferrer">Nish's implementation</a>, but I use a recur...
[]
[ { "body": "<p>Minor issues:</p>\n\n<ul>\n<li>You need to include <code>&lt;utility&gt;</code> for <code>std::forward</code>.</li>\n<li><p>You don't support empty tuples. It's obviously not a huge problem, but adding one line </p>\n\n<pre><code>template &lt;&gt; struct tuple&lt;&gt; {};\n</code></pre>\n\n<p>is n...
{ "AcceptedAnswerId": "52279", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T14:41:55.273", "Id": "52272", "Score": "9", "Tags": [ "c++", "c++11" ], "Title": "Standard-layout tuple implementation" }
52272
<p>When playing Killer Sudoku I find myself repeatedly writing stuff like this:</p> <pre><code>12/3 921 831 741 732 651 642 543 </code></pre> <p>and then crossing out the combinations that include say 9, 7, and 6 </p> <p>IE I need a list of any 3 digits between 1 and 9 that add up to 12, excluding 9, 7, and 6 becau...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T17:48:50.217", "Id": "91540", "Score": "0", "body": "TIL `Console.Write` works in LinqPad, thanks" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T18:53:28.307", "Id": "91552", "Score": "0", ...
[ { "body": "<h2>Naming</h2>\n\n<p>Use <code>camelCase</code> for local variable names. And, use a meaningful name if <em>possible</em>.</p>\n\n<pre><code>//var List1 = new List&lt;int&gt;{1,2,3,4,5,6,7,8,9};\nvar validNumbers = new List&lt;int&gt;{1,2,3,4,5,6,7,8,9};\n</code></pre>\n\n<p>Use pluralized noun for ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T16:57:30.453", "Id": "52284", "Score": "4", "Tags": [ "c#", "linq", "sudoku" ], "Title": "Create a LINQ Killer Sudoku Cage Solver" }
52284
<p>Performance benchmarking small functions in Java is notoriously difficult, and there are a number of tools out there to help (caliper, others). Those other tools require a fair amount of setup and installation to get them working.</p> <p>This code is <a href="https://codereview.stackexchange.com/q/42473/31503">adap...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T11:44:53.273", "Id": "91849", "Score": "1", "body": "What is going on with double warm up: one with the `warmups` the other two calls to `process()` with a `println(\"\\n\\nWarmup Complete\\n\\n\")` in between?" } ]
[ { "body": "<h1>Framework</h1>\n<pre><code> /* **********************************\n * ADD YOUR PROBLEMS HERE!\n * ***********************************/\n</code></pre>\n<p>I'm sorry, did you just call this <strong>a framework</strong>? Never in my life have I seen a framework where I had to <em>edit the...
{ "AcceptedAnswerId": "52298", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T18:10:08.083", "Id": "52289", "Score": "11", "Tags": [ "java", "benchmarking" ], "Title": "Micro-Benchmark framework" }
52289
<p>I am reading this article about how you can organize JavaScript code for large projects.</p> <p>I am attempting to write a simple events calendar as a way to play with some of these design patterns.</p> <p>Using the module pattern I started to create a calendar module, but I have some questions:</p> <pre><code>va...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T19:03:29.880", "Id": "91553", "Score": "0", "body": "how are you planning on using this module? do you plan to use many instances of it in one application?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06...
[ { "body": "<p>In terms of the module pattern as used in JavaScript- </p>\n\n<p>There are plenty of times that a getter is used to access a variable that is otherwise managed internally. This would mean that you would have no need for a setter; in fact a setter in that case would be a no-no.</p>\n\n<p>Using a ge...
{ "AcceptedAnswerId": "52302", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T18:52:16.053", "Id": "52294", "Score": "2", "Tags": [ "javascript", "design-patterns", "modules", "revealing-module-pattern" ], "Title": "Am I using the JavaScript \"module...
52294
<p>I'm looking to improve the efficiency of my code. Although my current method works, I feel it can be improved.</p> <pre><code>if ouroraddrlen == (4,): ouropip = struct.unpack("&gt;bbbb", payload[6:10]) # Need to change this to accept ipv6 as well print "Our I.P : ", ouropip notheirip = str...
[]
[ { "body": "<p>Your question was a little confusing. But I will try and summarize it before I go into my solution:</p>\n\n<ul>\n<li>You have a struct that you are unpacking and during that process you get the number of IPs 'they' have and the length of those IPs (either 4 or 16)</li>\n<li>You want to get all of ...
{ "AcceptedAnswerId": "52299", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T19:09:31.987", "Id": "52295", "Score": "3", "Tags": [ "python" ], "Title": "Dynamically assign values" }
52295
<pre><code>function min_strpos_array($haystack, $needles) { $min = null; for ($i = 0; $i &lt; count($needles); $i++) { $strpos = strpos($haystack, $needles[$i]); if ($strpos !== FALSE) { $min = $strpos; for ($i = $i + 1; $i &lt; count($needles); $i++) { $s...
[]
[ { "body": "<p>Well, any time you have nested for loops, you should cringe a little because it means you're running in O(n^2) time. Sometimes it's unavoidable, but often you can do something to bring it down significantly. <strong>Edit:</strong> this algorithm is actually O(n).</p>\n\n<p>In your case, you can re...
{ "AcceptedAnswerId": "52309", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T19:13:13.753", "Id": "52296", "Score": "2", "Tags": [ "php" ], "Title": "Most optimized way to get minimum strpos from multiple needles" }
52296
<p>So here we have a little game of Tic Tac Toe I've made. It runs well on TI-83/84 calculators and it doesn't seem to have any problems. However, I'd like to eliminate some of the code that seems bulky and repetitive as well as possibly add some checks so you can't overwrite a square that's already been played and to ...
[]
[ { "body": "\n\n<p><em><strong>Disclaimer:</strong> I only have a <a href=\"http://education.ti.com/en/us/guidebook/details/en/8D7A30C057FB4063B9F7BF0C15194A14/85\" rel=\"nofollow\">TI-85</a>, whose commands are slightly different from the <a href=\"http://education.ti.com/en/us/products/calculators/graphing-cal...
{ "AcceptedAnswerId": "55654", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T19:27:39.763", "Id": "52297", "Score": "8", "Tags": [ "game", "tic-tac-toe", "ti-basic" ], "Title": "Tic Tac Toe (2 players)" }
52297
<p>I've just recently started C# and I was wondering if there's anything I can improve on.</p> <p>My project is a pizza form, where people can order pizza and the price gets updated, depending on whether they want delivery or not.</p> <p>Here's a picture of the GUI:</p> <p><img src="https://i.stack.imgur.com/OqmgX.p...
[]
[ { "body": "<p>Your <code>btnAdd_Click</code> routine could use some clean up. Instead of hardcoding all of the values, set yourself up an <a href=\"http://msdn.microsoft.com/en-us/library/sbbt4032.aspx\" rel=\"nofollow noreferrer\">enumeration</a> to use. It will make your code easier to read, and the values th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T19:44:38.843", "Id": "52300", "Score": "12", "Tags": [ "c#", "beginner", "winforms" ], "Title": "Pizza form project" }
52300
<p>I have found <em>Scripting.FileSystemObject</em> to be slow and unstable. Calling <code>file_object.Name</code> repeatedly has caused my code to crash excel on multiple instances. Therefore I made a module where all of my file System helper functions reside. I called it <code>os</code> after python's <code>os</co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T04:09:31.203", "Id": "91639", "Score": "0", "body": "You might be interested in reviewing [this somewhat related code](http://codereview.stackexchange.com/q/52306/23788)" } ]
[ { "body": "<p>Just one quick little comment, about this function... which turns out being applicable to the whole:</p>\n\n<blockquote>\n<pre><code>Function Remove(file_path As String) As Boolean\n\n Remove = FileExists(file_path)\n\n If Remove Then Kill file_path\n\nEnd Function\n</code></pre>\n</blockquo...
{ "AcceptedAnswerId": "52328", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T19:59:51.890", "Id": "52301", "Score": "8", "Tags": [ "file-system", "vba" ], "Title": "\"Scripting.FileSystemObject\" Replacement module in VBA" }
52301
<p>I am currently working on a project that requires users to input text that may or may not be formatted (if it helps, just think of it as a Stack Exchange clone, even though that's not quite accurate). Instead of opting for some sort of BB Code or other markup language to allow users to format their text, I figure it...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T22:53:49.593", "Id": "91593", "Score": "0", "body": "`strip_tags` may be a little too much. You get questions on Stack Overflow like \"I tried (newline) it didn't work\", where it makes no sense because the HTML example is hidden." ...
[ { "body": "<p><a href=\"http://www.php.net//manual/en/function.strip-tags.php\" rel=\"nofollow\">PHP strip_tags Documentation</a> </p>\n\n<p>you should check out the documentation and what people are saying about the function as well so that you know exactly what is happening with the code you are using.</p>\n\...
{ "AcceptedAnswerId": null, "CommentCount": "18", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T20:09:42.757", "Id": "52303", "Score": "21", "Tags": [ "php", "html", "security", "validation" ], "Title": "Allowing users to input a safe subset of HTML" }
52303
<p>Following-up on <a href="https://codereview.stackexchange.com/q/52185/23788">this post</a>, I wanted to be able to use my <code>FileWriter</code> with a syntax reminiscent of .net's <code>using</code> blocks, which ensure proper disposal of resources (i.e. closing the file/stream).</p> <p>I'm looking for general fe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T18:28:28.643", "Id": "91760", "Score": "3", "body": "Just a readability preference, but your code window has a horizontal scroll bar. I would insert some `_`s. I know they are ugly but so is a 176 character line." }, { "Con...
[ { "body": "<p><strong>Error Handling</strong></p>\n\n<p>Your error handlers look much cleaner (and ultimately safer) than before. I also like your GetErrorSoure() routine and the \"CleanExit:\" name of the labels. Very concise. (&lt;-Read as, \"I'll be 'borrowing' more of your code'). I see a small issue in you...
{ "AcceptedAnswerId": "52326", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T20:24:03.963", "Id": "52306", "Score": "15", "Tags": [ "vba", "error-handling", "io", "vb6" ], "Title": "File reader/writer (text)" }
52306
<blockquote> <p>Given two strings string <code>X</code> of length <code>x1</code> and string <code>Y</code> of length <code>y1</code>, find the longest sequence of characters that appear left to right (but not necessarily in contiguous block) in both strings.</p> <p>e.g. if <code>X = ABCBDAB</code> and <code>Y =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T21:31:59.487", "Id": "91572", "Score": "0", "body": "I don't have the time to write a full out answer, but you should use `memset(LCS, 0, sizeof(LCS[0][0]) * x1 * y1);` instead of those 2 `for` loops at the beginning in order to zer...
[ { "body": "<p>The algorithm is correct, but the implementation is sort of naive; it definitely doesn't scale to 50000-long strings. Even for the 1024-long strings it is very cache-unfriendly; most likely you spend most of the time in cache misses.</p>\n\n<p>The <a href=\"http://en.wikipedia.org/wiki/Longest_com...
{ "AcceptedAnswerId": "52325", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T20:36:04.643", "Id": "52308", "Score": "5", "Tags": [ "c++", "optimization", "programming-challenge", "dynamic-programming", "time-limit-exceeded" ], "Title": "Optimizi...
52308
<p>I am using <a href="http://www.numpy.org" rel="nofollow noreferrer">numpy</a> and <a href="http://matplotlib.org" rel="nofollow noreferrer">matplotlib</a> to do a statistical simulation. The simulation itself is pretty fast thanks to numPy vectorizatio, however the plotting is slow since I still use a <code>for</c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T13:50:39.210", "Id": "91693", "Score": "2", "body": "Wouldn't `plt.fill(myPath[..., ..., 0], myPath[..., ..., 1])` without a loop do the trick?" } ]
[ { "body": "<p>Try using matplotlib's <code>LineCollection</code> class. <a href=\"http://matplotlib.org/examples/pylab_examples/line_collection2.html\" rel=\"nofollow\">Here's an example</a>.</p>\n\n<p>In your case, you might do:</p>\n\n<pre><code>from matplotlib import pyplot as plt\nfrom matplotlib.collection...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T21:32:09.193", "Id": "52311", "Score": "3", "Tags": [ "python", "numpy", "matplotlib" ], "Title": "Plotting many images at once in matplotlib" }
52311
<p>I am refactoring a user search that just feels dirty. (Users#search)</p> <p>I need to allow a blank param to search on partial or only a first or last, but don't want to return all the records in the database (which is what seems to be happening when I search with one value nil). </p> <p>That said, what's the best...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T23:42:05.790", "Id": "91607", "Score": "1", "body": "If an HTML form has both an `fname` and an `lname` field, then `params[:fname] && params[:lname]` will always be true, even if either field (or both fields) is empty." }, { ...
[ { "body": "<p><em>These are just some ideas based on some assumptions, so I may be way off.</em></p>\n\n<blockquote>\n <p>Looking for a first_name in the last_name column sounds kind of silly hackery. Unless I'm looking at this the wrong way.</p>\n</blockquote>\n\n<p>The \"hacky\" feeling is maybe not so much ...
{ "AcceptedAnswerId": "52385", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T21:32:23.643", "Id": "52312", "Score": "5", "Tags": [ "ruby", "mysql", "ruby-on-rails", "active-record" ], "Title": "Search for User by first and/or last name, efficiently"...
52312
<p>First some background - I am developing a Python program which has thousands of lines spread across many files. I have intermediate programming skills - and no commercial OOP experience, and have taught myself Python recently. I have come across a problem which I can solve, in a number of different ways, but I'm not...
[]
[ { "body": "<p>First, to answer your question on passing by value/reference, Python <em>doesn't</em> pass mutable (e.g. <code>list</code>, <code>dict</code>) and immutable (e.g. <code>str</code>, <code>tuple</code>) objects any differently - the difference appears <em>because</em> they are[n't] mutable, i.e. can...
{ "AcceptedAnswerId": "52355", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T21:36:10.907", "Id": "52313", "Score": "4", "Tags": [ "python", "object-oriented", "tkinter" ], "Title": "Changing attributes in different objects" }
52313
<p>I'm making an Android app where users can create posts. This process of creating a new post can potentially be a few activities/screens, so I need a way to save and pass the data between the activities. My first (bad) solution was just to pass the data with the intent in a <code>Bundle</code>, but this soon got ver...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T00:00:50.613", "Id": "91613", "Score": "0", "body": "I have voted to close this question because of the following reasons: 1) You're essentially asking about fixing a problem that your current code does not handle well. Because of t...
[ { "body": "<p>Fixing a <code>NullPointerException</code> is not under the scope of Code Review, but you should be able to solve that problem by looking at a previous answer of mine where I'm describing <a href=\"https://codereview.stackexchange.com/questions/45751/sound-manager-for-android/45772#45772\">How to ...
{ "AcceptedAnswerId": "52320", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T21:42:44.467", "Id": "52314", "Score": "1", "Tags": [ "java", "android" ], "Title": "Retaining and passing data between Activities" }
52314
<p>I'm looking for code review, best practices and optimizations.</p> <pre><code>public final class DivThreeEfficiently { private DivThreeEfficiently() {} /** * Returns true if the input number is divisible by three. * Else returns false. * * @param n the input number * @return...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T21:50:45.087", "Id": "91576", "Score": "88", "body": "I suppose `n % 3 == 0` is cheating?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T22:27:07.130", "Id": "91589", "Score": "11", "body...
[ { "body": "<p>Given how fast it should be I'd tend toward advocating a brute-force test, something like:</p>\n\n<pre><code>for (int i=-100000; i&lt;100000; i++)\n assertEquals(DivThreeEfficiently.isMultipleOfThree(i), i%3==0);\n</code></pre>\n\n<p>This makes the intent more apparent, reduces the amount of co...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T21:48:46.560", "Id": "52315", "Score": "56", "Tags": [ "java", "bitwise" ], "Title": "Efficiently checking if a number is divisible by 3" }
52315
<p>Secure Shell (SSH) is a cryptographic network protocol for secure data communication, remote shell services or command execution and other secure network services between two networked computers that it connects via a secure channel over an insecure network: a server and a client (running SSH server and SSH client p...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T23:38:35.687", "Id": "52321", "Score": "0", "Tags": null, "Title": null }
52321
Secure Shell - a network protocol for exchanging data throughout secure channel with most common uses of remote command execution (remote shell/console) and file transfer. Use this tag for programs and scripts using the SSH protocol, including the associated SCP and SFTP file-transfer mechanisms.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-02T23:38:35.687", "Id": "52322", "Score": "0", "Tags": null, "Title": null }
52322
<p>I have a pricing list that I can make sense of as both a table and as a description list. Using a table feels hackish. I thought a dl might be appropriate because description lists "are useful for displaying metadata as a list of key-value pairs" according to the docs at <a href="https://developer.mozilla.org/en-U...
[]
[ { "body": "<p>I'd say stick with the table.</p>\n\n<p>Yes, tables are frowned upon - <em>if you use them for purely visual purposes</em>. But this isn't \"just\" layout; it's information structure. And these <em>are</em> tabular data sets so semantically speaking tables are the right choice. There's nothing hac...
{ "AcceptedAnswerId": "52396", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T03:10:17.093", "Id": "52329", "Score": "4", "Tags": [ "html", "html5" ], "Title": "Is there a more semantic way to markup Price Lists? Example as Table and as Description List" }
52329
<p>This class retrieves JSON data from a PHP script and uses the data to populate a ListView using AsyncTasks. Any ideas on how to improve it?</p> <pre><code>public class MainActivity extends ActionBarActivity { ArrayList&lt;Location&gt; arrayOfLocations; LocationAdapter adapter; @Override protected ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-10T17:52:51.770", "Id": "100902", "Score": "0", "body": "You mention php in the title, in your post and in the code comments. It would probably be clearer if you did not talk about php at all and just wrote about retrieving json data....
[ { "body": "<p>Well, depending on what SDK level you need to support, you could use HttpUrlConnection instead of the deprecated DefaultHttpClient.</p>\n\n<p>Quoting from a post in the Android blog:</p>\n\n<p>\"Apache HTTP client has fewer bugs on Eclair and Froyo. It is the best choice for these releases.</p>\n\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T04:39:00.867", "Id": "52332", "Score": "2", "Tags": [ "java", "android" ], "Title": "Populating a ListView via a php script in Android app using AsyncTask" }
52332
<p>I decided to give the maximum sub-array sum problem an interesting go, however I will assure you that it doesn't perform well, and that I would never put this in production.</p> <p>I'd like a review on this, if possible, it would be cool to see the running time, I'm sure it's upper bounded by at most \$O(n^3)\$, bu...
[]
[ { "body": "<p>You code :</p>\n\n<blockquote>\n<pre><code>private static int[] buildRandom(int size, int min, int max) {\n return new Random().ints(size, min, max).toArray();\n}\n</code></pre>\n</blockquote>\n\n<p>I think that doing <code>new Random</code> several times, will reduce the \"randomness\" of the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T07:48:01.330", "Id": "52335", "Score": "6", "Tags": [ "java", "array", "interview-questions" ], "Title": "Finding the sub-array with maximum sum - my slow approach" }
52335
<p><em>This is the smallest <strong>SSCCE</strong> of my project. I get flickering on the screen with this code.</em></p> <p><strong>Main class (on which I start the application)</strong></p> <pre><code>import javax.swing.JFrame; public class MainFrame { public static void main(String[] args) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T09:50:29.627", "Id": "91672", "Score": "0", "body": "Do you think it's possible to show us a video on youtube or another platform on what exactly is happening" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014...
[ { "body": "<h1>Java</h1>\n\n<p>You tabbing, makes your code less readable, after every </p>\n\n<pre><code>bracket {\n you should be indenting the following lines \n}\n</code></pre>\n\n<hr>\n\n<pre><code>break;\n} else {\nbreak;\n</code></pre>\n\n<p>looks like you're going to break either way, how bout doing ...
{ "AcceptedAnswerId": "52358", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T09:31:56.843", "Id": "52341", "Score": "4", "Tags": [ "java", "performance", "object-oriented", "graphics" ], "Title": "Avoid flickering on game screen" }
52341
<p>I'm very new to <code>NHibernate</code> and DB. I have three tables which are connected with many to many relationship.</p> <p>Here are the tables creation Script:</p> <pre><code>create table PATIENT_INFO(patient_Code int not null identity(1,1) PRIMARY KEY, PATIENT_NAME VARCHAR(30), PATIENT_ADRESS VARCHAR(30), ...
[]
[ { "body": "<p>There's not much to say about mappings. These things either work or they don't, and since they're posted here I presume they work. </p>\n\n<p>I'd comment on the <em>formatting</em> of the fluent API code, for example in this snippet:</p>\n\n<pre><code> HasManyToMany(x =&gt; x.PatientDoctor)...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T11:29:03.883", "Id": "52345", "Score": "8", "Tags": [ "c#", ".net", "sql", "mvc", "sql-server" ], "Title": "Fluent Nhibernate" }
52345
<p>I am using an <code>AlertDialog</code> in Android, asking the user for some input. I would like do run some code when the user has finished entering her input.</p> <p>Since an <code>AlertDialog</code> is asynchronous, my code is not waiting for it. Therefore, I decided to use a callback, as in the following sample ...
[]
[ { "body": "<p>Your pattern is close to what is recommended <a href=\"http://developer.android.com/guide/topics/ui/dialogs.html#PassingEvents\" rel=\"nofollow\">on the official Android dev network.</a>.</p>\n\n<p>Formalizing your callback as an interface is the right choice, and passing an implementation of the ...
{ "AcceptedAnswerId": "52361", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T13:36:42.230", "Id": "52351", "Score": "7", "Tags": [ "java", "android", "callback" ], "Title": "Callback on AlertDialog" }
52351
<p>I was wondering if I did this in a remotely acceptable way:</p> <pre><code>var fib = function(params) { var iterations = params; var output = [0]; for(var i = 1, j = 1; j &lt; iterations; j++){ //i is the fibonacci sequence //j counts iterations output.push(i); i = parse...
[]
[ { "body": "<pre><code>var fib = function(params) {\n var iterations = params;\n</code></pre>\n\n<p>Why are you copying params into iterations, rather than just naming your parameter iterations?</p>\n\n<pre><code> var output = [0];\n</code></pre>\n\n<p>That's not really your output is it? Perhaps there is ...
{ "AcceptedAnswerId": "52356", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T14:26:04.010", "Id": "52354", "Score": "4", "Tags": [ "javascript", "fibonacci-sequence" ], "Title": "How would you count in the Fibonacci Sequence?" }
52354
<p>I've got this own made grid system made in SASS:</p> <pre><code>@import "../mixins/cross-browser-elements/box"; $columns: 12 !default; $gutter-width-px: 20px !default; @function calculate-column-width($index) { @return percentage($index / $columns); } .row { overflow: hidden; max-width: 100%; .column { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-07T00:16:16.667", "Id": "92350", "Score": "0", "body": "To answer your question no, using percentages alone will usually make your grid responsive for the most part. However you may want to look into breakpoints. I have a [sass grid ...
[ { "body": "<p>I'm unsure of your SCSS, because it doesn't seem to use media-queries, and isn't small-screen-first: but here are my HTML suggestions:</p>\n\n<p>The columns would likely stack on small screens, and aren't really columns semantically in general. You can note that they are smaller pieces inside a co...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T15:16:37.657", "Id": "52360", "Score": "5", "Tags": [ "css", "sass" ], "Title": "SASS grid system improvements" }
52360
<p>To protect my web site against XSS injection, I am using <a href="https://www.owasp.org/index.php/Category%3aOWASP_Encoding_Project" rel="nofollow">OWASP Encoding Project</a>.</p> <p>Is it a good idea to protect all data retrieved in my DB to avoid XSS by going throuh all the data just returned by the query like th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T15:36:03.747", "Id": "91713", "Score": "3", "body": "Just follow the rule \"Filter input, escape output\". Be paranoid :-)" } ]
[ { "body": "<p>One might forget HTML encoding, but how about doing it automatically:</p>\n\n<pre><code>class HtmlEncode {\n private $obj;\n\n public __construct($obj) {\n $thos-&gt;obj = $obj;\n }\n\n public __call($method, $args) {\n $ret = call_user_func_array($this-&gt;obj, $args);\n ...
{ "AcceptedAnswerId": "52366", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T15:30:08.667", "Id": "52362", "Score": "1", "Tags": [ "php", "database", "sql-injection" ], "Title": "Where to protect DB data against XSS injections?" }
52362
<p>I'm new to OOP and PHP. I've made an attempt at a PHP library file that handles account creations, logins, and file uploads with image resizing on the fly. It works so far. I'd like some help with the Obj Oriented part, namely making the code more efficient/succinct.</p> <p>User class:</p> <pre><code>&lt;?php de...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T20:33:25.610", "Id": "91779", "Score": "1", "body": "`createNewUser` and `findUser` should be abstracted from the database class" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T15:29:37.127", "Id"...
[ { "body": "<h1>Executive summary:</h1>\n\n<ul>\n<li>Pick a naming standard and stick to it (img != image for instance)</li>\n<li>Learn how to write comment blocks ( /* description <em>/ /*</em> @var */ is kinda weird)</li>\n<li>SOLID is a good place to start (google it)</li>\n<li>PSR-1 and PSR-2</li>\n<li>Don't...
{ "AcceptedAnswerId": "52386", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T15:37:02.283", "Id": "52363", "Score": "7", "Tags": [ "php", "object-oriented", "image", "library", "authentication" ], "Title": "PHP library for handling account creat...
52363
<p>The Microsoft Visual Basic for Applications Extensibility library let's us meta-program VBA, but the way it handles (or rather, doesn't handle) getting to the actual subs and functions is clunky at best. I decided to write a few class modules to make it easier.</p> <p>Considering this can be kind of dangerous to do...
[]
[ { "body": "<p>The only coupling I can see with MSAccess-specific <a href=\"/questions/tagged/vba\" class=\"post-tag\" title=\"show questions tagged &#39;vba&#39;\" rel=\"tag\">vba</a> is in your <code>exampleCall</code> (why is it <code>Private</code> anyway?):</p>\n\n<pre><code>Dim prj As vbProject\nSet prj = ...
{ "AcceptedAnswerId": "52539", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T15:44:23.443", "Id": "52364", "Score": "11", "Tags": [ "object-oriented", "vba", "error-handling", "vb6", "meta-programming" ], "Title": "Extending the VBA Extensibilit...
52364
<p>I made a few changes to this:</p> <p><a href="https://codereview.stackexchange.com/questions/52265/asking-a-user-to-take-money-from-a-checking-account-and-move-it-to-a-savings-acc">Asking a user to take money from a checking account and move it to a savings account</a></p> <p>The changes I made were:</p> <ul> <li...
[]
[ { "body": "<p>General suggestions</p>\n\n<ul>\n<li>Find ways to shorten your methods.</li>\n<li>DRY (don't repeat yourself).</li>\n</ul>\n\n<p>Specific points</p>\n\n<ul>\n<li>Combining the above points: extract your series of <code>println</code>s to a new <code>BankAccount.displayBalances()</code> method. Th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T15:57:52.593", "Id": "52367", "Score": "3", "Tags": [ "java", "sql", "mysql", "finance" ], "Title": "Asking a user to take money from a checking account and move it to a savin...
52367
<p>I have a bit of code to insert some values in a table. It seems a bit clunky - is there a neater way?</p> <p>words is a list of dictionaries, and the entries contain other fields which I don't want to insert.</p> <pre><code># add the list of words to the words table time_stamp = datetime.datetime.now().isoformat()...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T16:26:44.403", "Id": "91726", "Score": "0", "body": "If `user_id` and `game_id` came from the user/UI, would you assemble the `sql` string that way?" } ]
[ { "body": "<p>There is a neater, more Pythonic way of doing this using the <code>str.format</code> function. However, it is not the way you <strong>should</strong> do it. </p>\n\n<p>Currently, the way you are building your query, you are vulnerable to <a href=\"http://en.wikipedia.org/wiki/SQL_injection\" rel=\...
{ "AcceptedAnswerId": "52374", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T16:17:57.880", "Id": "52370", "Score": "6", "Tags": [ "python", "sql" ], "Title": "Idiomatic way to construct a SQL INSERT query in Python" }
52370
<p>I have a django app with search powered by haystack. The general search goes very quickly, but I need to filter the results by their model type. It works but is very slow. I've never really worked on optimizing code so I don't necessarily know the tools to use.</p> <pre><code>def search(request): if 'q' in r...
[]
[ { "body": "<p>I suggest collecting all the <code>item_model_name</code>s from the search results, counting them, and forming an index.</p>\n\n<p>Then during the for loop, instead of querying the database, just look up the count.</p>\n\n<p>This solution has the benefit that it removes about 10 database calls, at...
{ "AcceptedAnswerId": "52469", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T16:20:45.603", "Id": "52371", "Score": "10", "Tags": [ "python", "performance", "search", "django" ], "Title": "Speed up my search" }
52371
<p>I'm trying to make a reusable data layer that is mostly generated from a database via T4 templates. On top of this data layer, I'd like to have WebAPI endpoints for each repository, with most of the basic CRUD operations generated/from a base class. The generics are somewhat getting out of hand, and I don't know if ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T16:54:17.057", "Id": "91736", "Score": "4", "body": "Are you using an ORM? It would be nice to see some implementations, and the truncated bits too (including the class bodies)." } ]
[ { "body": "<p>It looks like you're basically writing Entity Framework. If so...why not use Entity Framework?</p>\n\n<p>It also looks like in addition to your rewriting of Entity Framework, you're writing the whole generic repository pattern + unit of work pattern that people like to add on top of it. I would st...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T16:35:10.010", "Id": "52372", "Score": "2", "Tags": [ "c#", "design-patterns", "generics" ], "Title": "Auto-generated generic data layer" }
52372
<p>Entity Framework 6 fails to handle the maintenance of LocalDB's global list of databases. That is noted here: <a href="https://entityframework.codeplex.com/workitem/1748" rel="nofollow">Application fails when attached mdf and ldf files are deleted</a></p> <p>Here is my code to work around the issue. I'm open to sug...
[]
[ { "body": "<p>there is a little piece of code that can be shortened a little bit</p>\n\n<pre><code> if (!string.IsNullOrEmpty(filename))\n {\n var filesExist = File.Exists(filename);\n if (!filesExist)\n DropAndCreateLocalDatabase(filename, builder.InitialCatalog, b...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T17:02:45.693", "Id": "52373", "Score": "5", "Tags": [ "c#", "entity-framework" ], "Title": "Work around for EF6 bug 1748 in the Entity Framework" }
52373
<p>I was solving this question on an <a href="http://www.spoj.com/problems/TIPTOP/">online judge</a>.</p> <p>The problem boils down to the following:</p> <blockquote> <p>Given a number \$n\$, where \$1 \le n \le 10^{18}\$, we need to check if it contains odd number of divisors.</p> </blockquote> <p>I have used fol...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T17:38:52.630", "Id": "91749", "Score": "1", "body": "`It gives the correct answer for small values` Have you tried to debug it with bigger values ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T17:5...
[ { "body": "<p>Your code works, as specified, but your specification is wrong.</p>\n\n<p>Sometimes doing a code review involves fact-checking. In this case, your facts are wrong. What looked fishy to me, is the statement that:</p>\n\n<blockquote>\n <p>the recursive sum of digits of perfect squares is always 1,4...
{ "AcceptedAnswerId": "52378", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T17:17:22.173", "Id": "52375", "Score": "7", "Tags": [ "c++", "mathematics", "programming-challenge" ], "Title": "Checking if a number is a perfect square by recursive sum of it...
52375
<p>I am teaching myself React.js from Facebook with small projects. For this one, I want to know if this was the cleanest, most React-ish way I could have done this.</p> <p>The basic structure is as follows:</p> <pre><code>Page &lt;h2&gt; &lt;h2&gt; Form Adaptive_Input &lt;input&gt;&lt...
[]
[ { "body": "<p>The only think that I can see right off the bat is your <code>input</code> tags and your <code>label</code> tags</p>\n\n<pre><code> &lt;input \n className=\"adaptive_input\"\n type=\"text\" \n required=\"required\" \n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T19:50:55.290", "Id": "52380", "Score": "5", "Tags": [ "javascript", "form", "react.js" ], "Title": "Live updating headers from form input with React.JS" }
52380
<p>This code detects cycle in acyclic graph. The assumption of this approach is that there are no parallel edges between any two vertices. Looking for code review, best practices and optimizations.</p> <p>Also verify the complexity is O(E) and not O(V+E).</p> <pre><code>class AcyclicGraphCycleDetection&lt;T&gt; impl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T23:16:34.477", "Id": "91797", "Score": "5", "body": "Terminology comment... you cannot detect cycles in acyclic graphs, because, by definition, there are none. You should be saying \"detect cycles in an undirected graph\", or \"prov...
[ { "body": "<p>I'm not keen on <code>AcyclicGraphCycleDetection</code>, which is trying to be too many different things at once.</p>\n\n<ol>\n<li>It is acting as a definition of your Graph abstraction</li>\n<li>It is acting as an implementation of your Graph abstraction</li>\n<li>It is acting as a <code>builder<...
{ "AcceptedAnswerId": "52395", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T20:39:04.770", "Id": "52383", "Score": "0", "Tags": [ "java", "graph" ], "Title": "Detect cycle in an undirected graph" }
52383
<p>How can I improve this code, without to return async Task?</p> <pre><code>[WebMethod] public string Login(string login, string password, string deviceId, string appVersion, string xuid) { var authTask = _SSOFrontendService.GetSSOTokenAsync(login, password, deviceId, appVersion); var tokenTimesta...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T22:05:57.667", "Id": "91787", "Score": "2", "body": "It's good form to give a little back ground about what your code does. Welcome to CodeReview! =)" } ]
[ { "body": "<blockquote>\n <p>How can I improve this code, without to return async Task?</p>\n</blockquote>\n\n<p>Doing this doesn't make much sense. If the whole method is going to be synchronous, then you're not gaining much by using asynchronous methods in it, because the synchronous method still needs to bl...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T21:50:42.443", "Id": "52388", "Score": "2", "Tags": [ "c#", "asp.net", "api", "web-services" ], "Title": "Async operations in WebMethod" }
52388
<p>How do I simplify this method? Is handling an exception in this method a good idea?</p> <pre><code>[WebMethod] public string GetMDSToken(string xuid) { var tokenTask = _mapTokenService.GetMappedSSOTokenAsync(xuid); var tokenTimestampTask = _SSOFrontendService.GetSSOTokenTimestampAsync(); Task.WhenAll(...
[]
[ { "body": "<p><strike>I can't speak for the language you a using specifically, but I have always been lead to believe that declaring variables within <code>if</code> and <code>try</code> statements is bad form. Can't say I've ever seen one in a <code>catch</code> statement, but I believe the same principle migh...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T21:59:49.970", "Id": "52389", "Score": "1", "Tags": [ "c#", "web-services" ], "Title": "WebService async WebMethod" }
52389
<p>This a little pagination script that I am writing "Object Oriented" and I have no idea how to set the current page equal to total page, if the current page is greater. I also would really like it if anyone can tell me how to improve my code.</p> <pre><code>class pagination extends Db_connection { public $per_...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T18:30:25.860", "Id": "95181", "Score": "0", "body": "The tiny amount of SQL you have in there looks fine, for all that it's worth. I don't know much about PHP but I'll try to tag someone who does." } ]
[ { "body": "<p>If you have to identify the main objects here, we could conclude that you have at least 3</p>\n\n<p>-- The connection to the DataBase</p>\n\n<p>-- The pagination object that knows how to paginate a query</p>\n\n<p>-- The query it self</p>\n\n<p>so ie this is a possible solution:\n \n\n<pre><cod...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T22:34:38.670", "Id": "52392", "Score": "3", "Tags": [ "php", "object-oriented", "mysqli", "pagination" ], "Title": "Pagination object oriented" }
52392
<p>I forked the <a href="https://github.com/VerbalExpressions/ScalaVerbalExpressions" rel="nofollow">original implementation</a> of <a href="https://github.com/VerbalExpressions/JSVerbalExpressions" rel="nofollow">VerbalExpressions</a> in Scala here: <a href="https://github.com/pathikrit/ScalaVerbalExpressions" rel="no...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T22:56:29.687", "Id": "52393", "Score": "4", "Tags": [ "regex", "scala" ], "Title": "VerbalExpressions in Scala" }
52393
<p>When I'm throwing together prototype code, I don't want to spend extra time setting up parameters, or chasing down problems from entering parameters wrongly. So this is a general purpose, fairly easy to use, GUI data input helper, that hopefully takes care of most of the data entry whoopsies that frustrate just gett...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-10T00:15:18.053", "Id": "113878", "Score": "1", "body": "You use MyLabelEntry (with camel case) as the name of one class, and GUI_inputs (with snake case) as the other. I know the PEP8-prescribed \"GUIInputs\" is ugly as sin, so you mi...
[ { "body": "<p>Adding the following to the top is all you need to make this code bacwards compatible to Python 2.</p>\n\n<pre><code>import sys\nif sys.version == 2:\n import Tkinter as tki\n import tkMessageBox as tkm\nelse:\n import tkinter as tki\n import tkinter.messagebox as tkm\n</code></pre>\n"...
{ "AcceptedAnswerId": "73778", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T23:23:39.170", "Id": "52397", "Score": "11", "Tags": [ "python", "validation", "gui", "tkinter" ], "Title": "A general purpose GUI data input, with validation, but unclear ...
52397
<p>I'm writing a bash script that has these goals: </p> <ul> <li>to build a node program from sources</li> <li>to install the built program on Ubuntu Linux</li> <li>to allow the user to rebuilt from most recent sources</li> <li>to add a small CLI (it has none)</li> <li>to add a small GUI for support (like report-bug,f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T00:50:02.367", "Id": "91807", "Score": "2", "body": "I have to ask, why are you using a bash script to duplicate the functionality of dpkg? Just build a deb and be done with it. I would think three, maybe four times before running a...
[ { "body": "<h2>Working with the ecosystem</h2>\n\n<p>It important to know when <em>not</em> to write code. If you're going to work in the APT ecosystem, then you should work <em>with</em> other package management tools, rather than invent your own approach. There are at least two tools you should be leveragin...
{ "AcceptedAnswerId": "52423", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T23:44:43.333", "Id": "52398", "Score": "6", "Tags": [ "bash", "installer" ], "Title": "Building/installing bash script" }
52398
<p>My objective is to swap every element of a string array with a random element.</p> <pre><code>for (int i = 0; i &lt; array.length; i++) { // scanning the deck int abc = rm.nextInt(77); // random object range String temp = array[i]; // swapping cards at random places array[i] = array[abc]; array[abc]...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T04:58:29.140", "Id": "91816", "Score": "3", "body": "\"I checked and the code is working [...] so my question is , is my code working\" <- what?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T04:59:5...
[ { "body": "<p>I see <em>some</em> problems with it:</p>\n\n<ol>\n<li><p>You are reinventing the wheel. Use <code>Collections.shuffle();</code></p></li>\n<li><p>The code only shuffles an array of 77 elements. What would you do if the array had 2 elements? What would you do if the deck contains more than 77 eleme...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T04:56:08.390", "Id": "52407", "Score": "15", "Tags": [ "java", "shuffle" ], "Title": "Shuffling a deck" }
52407
<p>I made a simple database class and I wanted to know if there are any improvements I could work on as far as readability, efficiency, methods and making it modular goes.</p> <p>Any other suggestions are also welcome!</p> <p><strong>Database.php</strong></p> <pre><code>class Database { private $config; priv...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T15:20:47.410", "Id": "91890", "Score": "0", "body": "What you did here is take a pretty good class (PDO) and only allow one method to be called, the query(); ieuk" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>I see several things up for improvements:</p>\n\n<ul>\n<li><p>What problem are you solving? PDO on itself is an abstraction. Your abstraction over it is, on most cases, redundant.</p>\n\n<ul>\n<li>A abstraction is a Mapper for example, which uses the PDO connection to map an object to the database...
{ "AcceptedAnswerId": "53894", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T08:17:21.767", "Id": "52414", "Score": "4", "Tags": [ "php", "object-oriented", "classes", "database", "pdo" ], "Title": "My simple PDO wrapper class" }
52414
<p>I have a table called <code>tblDelegates</code> in my database which I need to populate with some data. I have created a class called Delegates which has various properties to hold the bulk of the information. </p> <p>I am fairly new to C#, so I wanted to get the answers to a few questions as to why you should be...
[]
[ { "body": "<p>If I understand your code (and I'm not 100% certain I do), your <code>Delegates</code> class only returns one object (as opposed to a collection or array of objects) and should thus be named <code>Delegate</code>, but as @Mat'sMug pointed out, it conflicts with the <code>System.Delegate</code> nam...
{ "AcceptedAnswerId": "52467", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T08:22:21.523", "Id": "52415", "Score": "5", "Tags": [ "c#", "beginner", "sql", "asp.net", "linq" ], "Title": "Adding object to database, using linq or sql connection" }
52415
<p><strong>Problem Statement</strong></p> <blockquote> <p>Prompt the user for the order </p> <p><code>statistic n: 1, 2, 3,</code> etc. </p> <p>Read a file of tokens, building a map </p> <pre><code>(Map[List[Stringn]] -&gt; List[String*]) </code></pre> <p>from a list of n words to a list of the words...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T10:50:50.547", "Id": "91840", "Score": "0", "body": "You suggest the problem is simple to read, but I am struggling to understand the problem. Two things.... this sounds suspiciously like [NGrams](http://en.wikipedia.org/wiki/Ngram)...
[ { "body": "<p>Let's go through a couple of things. Concept, then missing functionality (.... you have some).</p>\n<h1>Concept</h1>\n<p>An N-Gram is a sequence of N words that have been found in a span of text. You can have 1-grams, 2-grams, 3-grams, .... n-grams. You identify these n-grams by finding all possib...
{ "AcceptedAnswerId": "52448", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T08:43:28.503", "Id": "52417", "Score": "4", "Tags": [ "java", "algorithm", "strings" ], "Title": "Wordgenerator algorithm using Java collection" }
52417
<p>I wrote a anonymous event creator. I would like to ask if anyone can tell me if I did it the "right" or "best" way, or how I could make it better.</p> <p>Here is what I did:</p> <p>Declaration:</p> <pre><code> TAnonymousEvents&lt;TTEventPointer,TTEventReference&gt;=class public class function Create(AEvent...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-03-18T11:54:11.437", "Id": "151785", "Score": "1", "body": "I don't see the declaration of TTEventPointer and TTEventReference" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-03-19T13:51:37.993", "Id": "15205...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T08:49:52.397", "Id": "52418", "Score": "4", "Tags": [ "event-handling", "delphi" ], "Title": "Anonymous Events in Delphi" }
52418
<p>I'm trying to figure out what is the best way to create some objects in my application. The application is already running, but I want to structure things well and clean.</p> <p>These objects represents paths and they are complicated (they receive various parameters in their constructors).</p> <p>There are four ty...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T11:14:38.453", "Id": "91844", "Score": "2", "body": "I'm a bit sad to see the (wasted) time to create localized documentation. It is a good thing that you document, but they should really be in English." }, { "ContentLicense...
[ { "body": "<p>You should not pass the Context to those classes (separation of concerns/ single responsibility principle). You could add the Context as a constructor parameter to the AsyncTask's; or maybe it would be better to define the AsyncTask's where the computation is launched (and the Context accessible)...
{ "AcceptedAnswerId": "52475", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T09:59:07.797", "Id": "52422", "Score": "6", "Tags": [ "java", "design-patterns", "android" ], "Title": "Create and organize some classes (hierarchy)" }
52422
<p>This morning, being in urgent need of an effective subject code solution, I have had to write a "quick &amp; dirty" custom one:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace MyTestConsole { /// &lt;summary&gt; /// Handles System.Window...
[]
[ { "body": "<blockquote>\n<pre><code>public static EventInfo GetEventInfo(Type controlType, string targetEventName)\n{\n foreach (var eventInfo in controlType.GetEvents())\n {\n if (string.Compare(eventInfo.Name, targetEventName, true) == 0) return eventInfo;\n }\n return null;\n} \n</code></...
{ "AcceptedAnswerId": "109238", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T10:39:22.010", "Id": "52424", "Score": "2", "Tags": [ "c#", "winforms", "event-handling" ], "Title": "Keeping WebBrowser control's DocumentCompleted event handlers" }
52424
<p>I wrote this a while back when my fiance was taking a Number Theory class. I wrote about it <a href="http://christopherjmcclellan.wordpress.com/2014/02/15/how-many-numbers-less-than-ten-thousand-contain-a-five/">here</a> and it recently came back to my attention. Anytime I write a <code>for</code> loop in Ruby I fee...
[]
[ { "body": "<p>I would use recurence in place of the loop - it is easier to understand the logic behind it then:</p>\n\n<pre><code>def number_containing_5(pwr)\n return 0 if pwr == 0\n number_containing_5(pwr-1) * 9 + 10**(pwr-1)\nend\n</code></pre>\n", "comments": [ { "ContentLicense": "CC B...
{ "AcceptedAnswerId": "52463", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T12:37:20.920", "Id": "52426", "Score": "8", "Tags": [ "algorithm", "ruby", "mathematics" ], "Title": "Ruby-ize for loop - counting all the n-digit numbers that contain the digi...
52426
<p>How can I make this code more compact?</p> <p>It is a ASP.net WebForms project</p> <p>It is a SinglePageApplication for searching in list mode and map mode.</p> <p>I have many paths for a page. </p> <ul> <li>/Denmark</li> <li>/Denmark/Copenhagen</li> <li>/Denmark/Copenhagen/Christiansborg</li> <li>Map/Denmark </...
[]
[ { "body": "<p>This code doesn't look like much fun at all</p>\n\n<pre><code>if (!string.IsNullOrWhiteSpace(parameters))\n{\n var parameterArray = parameters.Split('/');\n var i = 0;\n while (i &lt; parameterArray.Length)\n {\n if (i == 3)\n param4 = parameterArray[3];\n\n if...
{ "AcceptedAnswerId": "52435", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T12:46:59.590", "Id": "52428", "Score": "5", "Tags": [ "c#", "strings" ], "Title": "Shorten code to perform search based on four slash-delimited parameters" }
52428
<p>Here is a <a href="http://jsfiddle.net/nF9Cu/" rel="nofollow">JSFiddle</a> of my problem.</p> <p>I have one <code>&lt;select&gt;</code> on the page that lets you choose a brand:</p> <pre><code>&lt;select class="form-control" name="website_brand"&gt; &lt;option value="" disabled selected&gt;Please Select&lt;/op...
[]
[ { "body": "<p>A bit short on time, so hopefully you (or someone else) can fill in the blanks here:</p>\n\n<ul>\n<li>Instead of just doing this all in a JQuery selector/event function, put this logic in its own method and give it a meaningful name. Something like: <code>toggleBannerTypeVisibility(brandName)</cod...
{ "AcceptedAnswerId": "52461", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T13:06:40.970", "Id": "52429", "Score": "3", "Tags": [ "javascript", "jquery", "html" ], "Title": "Is it possible to condense and/or tidy these jQuery functions?" }
52429
<p>I have a snap SVG animation which animates a bunch of circles, and draws a line between them if they are within a certain proximity of each other. However, I realize that there is a lot of optimizing I can do, but I'm not exactly sure how to do it. I feel like it would be useful to</p> <ol> <li>have a good example ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T17:08:36.137", "Id": "98682", "Score": "0", "body": "Am now running everything in a single loop - not using snap's animation function at all;\n[check this](http://jsfiddle.net/heaversm/fJ6fj/)." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T13:09:50.623", "Id": "52430", "Score": "2", "Tags": [ "javascript", "animation", "collision", "svg" ], "Title": "Optimizing snap SVG animation with collision detection" }
52430
<p>I've recently read <a href="https://zschoche.org/make-c-smart-pointers-a-bit-smarter/" rel="nofollow">an interesting blog post by Philipp Zschoche</a>: it explains how it's possible to avoid unnecessary allocations/deallocations by keeping track of previously allocated memory in a stack.</p> <p>It's very easy to co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T14:08:18.573", "Id": "91867", "Score": "0", "body": "Allocating via malloc/new is possibly not lock free, and it is definitely thread safe. If you add a lock to make this thread safe, how does it compare? Either way, in an ideal wor...
[ { "body": "<p>My main complaint is the use of the <code>std::vector</code> in such a low level interface. I think that is totally a waste of resources.</p>\n\n<p>Would be interested to know how this performs in comparison to you vector based version.</p>\n\n<p>I basically swapped the <code>std::vector&lt;TBase&...
{ "AcceptedAnswerId": "52465", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T13:40:24.060", "Id": "52433", "Score": "3", "Tags": [ "c++", "c++11", "memory-management", "pointers", "smart-pointers" ], "Title": "Auto-recycling C++11 polymorphic sm...
52433
<p>Is this a good usage of Decorator pattern? I'm trying to use Interfaces instead of Abstract classes.</p> <p>(Component) Interface</p> <pre><code>public interface IBake { string Name { get; } double Price { get; } } </code></pre> <p>(Concrete Component)</p> <pre><code> public class BakeBas...
[]
[ { "body": "<p>As I'm a more java programmer than C# but I try to answer you as good as I can.</p>\n\n<p>The decorater pattern should be able to decorate multiple times.</p>\n\n<p>Example : I must be able to decorate with cream and cherry and cream again.</p>\n\n<p>In your implementation you can only decorate on...
{ "AcceptedAnswerId": "52439", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T14:08:20.710", "Id": "52436", "Score": "8", "Tags": [ "c#", "design-patterns" ], "Title": "Usage of Decorator pattern in baking program" }
52436
<p>after profiling my application, it turns out that a single method is taking 3 minutes to run, which is about a third of the total runtime.</p> <p>The method deletes approx. 400.000 rows from each table (<code>PROCESSED_CVA</code> and <code>PROCESSED_DVA</code>).</p> <p>The code executing the queries :</p> <pre><c...
[]
[ { "body": "<p>Oracle uses the following strategy when deleting data. It:</p>\n\n<ul>\n<li>identifies the rows that need to be deleted (it does use your PRIMARY KEY index to check the RUN_ID value, but because the RUN_ID is not the first column in the index it needs to 'skip' values in the index).</li>\n<li>it d...
{ "AcceptedAnswerId": "52451", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T14:46:59.590", "Id": "52441", "Score": "1", "Tags": [ "java", "performance", "sql", "oracle" ], "Title": "Slow delete query on table with composite index" }
52441
<p>For fun, I implemented a version of Python's <code>range</code> function in JavaScript. I found that underscore.js implements it as well, but with notable differences. I'm hoping others can comment on the differences. I assume that underscore's implementation is, if not more optimal, at least more idiomatic. And I'd...
[]
[ { "body": "<p>The reason underscore defines the length of the results array from the beginning is because constantly having to change the length of an <code>Array</code> (using <code>push</code>) is more costly than defining its length beforehand and simply updating its elements.</p>\n\n<p>As for having the par...
{ "AcceptedAnswerId": "52447", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T14:52:42.773", "Id": "52442", "Score": "5", "Tags": [ "javascript" ], "Title": "Implementing range() in JavaScript" }
52442
<p>I've written a Binary Search Tree Monad in Scala. I would like to hear your thoughts on how to improve it (e.g. making insertion/deletion/search faster and more scalable). Also, is there a better way to implement this kind of data structure the Scala way?</p> <p><a href="https://github.com/melvic-ybanez/scala-bst/b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-14T17:14:55.017", "Id": "94586", "Score": "1", "body": "I remember seeing some academic paper about an efficient algorithm to implement an immutable binary tree. I know it was referenced in some way by Martin Odersky. Sorry, but it's...
[ { "body": "<p>I have not treated Scala, but Haskell. I like some competitive programming and I thought about Tree Problems deeply. I'm sorry for the Japanese site, a tree problem and my solution are:</p>\n<p><a href=\"https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_1_B&amp;lang=en\" rel=\"nofollo...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T16:42:07.887", "Id": "52449", "Score": "15", "Tags": [ "tree", "scala", "monads" ], "Title": "Binary Search Tree Monad Implementation" }
52449
<p>I have a site where there are lots of "jobs" that a user creates. The user has the option to <kbd>Close</kbd> any given job. I want a pop up warning dialog whenever the user clicks the <kbd>Close</kbd> button, and verify that they actually want to close the job. </p> <p>There are many ways to do this, and I've impl...
[]
[ { "body": "<p>Looks OK to me. jQueryUI will take care of most of the low-level stuff like not letting you open several dialogs and such (by simply not letting you click \"behind\" the modal).</p>\n\n<p>The code could be cleaned up though:</p>\n\n<ul>\n<li>Store <code>$(item)</code> in a variable (same with the ...
{ "AcceptedAnswerId": "54453", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T17:39:18.117", "Id": "52453", "Score": "6", "Tags": [ "javascript", "jquery", "jquery-ui" ], "Title": "Dialog multiple instantiations" }
52453
<p>Edit: Just to clarify, this isn't my original code, I've simplified it to make it smaller/easier to understand what I'm trying to do.</p> <p>It's my first time working with threads in Java, and I was wondering if I'm synchronizing correctly. I did some quick research on locks, synchronized and volatile, but I'm sti...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T19:22:38.833", "Id": "91938", "Score": "0", "body": "You have `return null` after waiting for the process which won't compile. This should be `return false` instead." } ]
[ { "body": "<p>Find a copy of <a href=\"http://rads.stackoverflow.com/amzn/click/B004V9OA84\" rel=\"nofollow\">Java Concurrency in Practice</a>, it's got very good chapter on <em>Cancellation and Shutdown</em>.</p>\n\n<p>You've made <code>cancelProcess()</code> private, so your outside threads aren't going to do...
{ "AcceptedAnswerId": "52458", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T17:56:40.423", "Id": "52454", "Score": "10", "Tags": [ "java", "multithreading", "synchronization" ], "Title": "Using synchronized blocks and volatile variables to ask a Java t...
52454
<p>I'm currently building a text editor using contenteditable and RoR back end. As the editor is WYSIWYG and trying to follow DRY, I used only one file to 3 actions: Show, Edit and New. </p> <p>Edit and new will pretty much be the same, however, show won't be editable and won't show the Subtitle if it's empty. I was d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T08:05:59.913", "Id": "92004", "Score": "2", "body": "Why not use existing text editors? I highly recommend ckeditor: https://github.com/galetahub/ckeditor" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-...
[ { "body": "<p>There's two things I usually consider in this kind of situation:</p>\n\n<p><strong>Use custom helpers and partials</strong></p>\n\n<p>The idea here is to break down your view in small components, and have one helper to build each component. Most of the time those helpers will just dispatch and ren...
{ "AcceptedAnswerId": "82497", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T20:22:07.033", "Id": "52466", "Score": "4", "Tags": [ "ruby", "coffeescript", "haml" ], "Title": "Ruby on Rails text editor" }
52466
<p>Allowing wraparound, the sequence <code>[2, 3, 5, 7, 11]</code> contains the sequence <code>[7, 11, 2]</code>.</p> <p>I'm looking for compact/pythonic way to code this, rather than an optimally-efficient way. (Unless I need the efficiency, I usually gravitate to the path of least ASCII).</p> <p>An obvious method w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T21:26:30.360", "Id": "91953", "Score": "2", "body": "What is `b` ? Does your code work at all ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T21:40:26.137", "Id": "91955", "Score": "1", ...
[ { "body": "<p>As you said in your comments above, the first is the cleanest way you came up with. </p>\n\n<p>Instead of writing your own logic, Python has a built-in library <code>difflib</code> that contains the <a href=\"https://docs.python.org/2/library/difflib.html#sequencematcher-objects\" rel=\"nofollow\"...
{ "AcceptedAnswerId": "52508", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T20:46:41.983", "Id": "52470", "Score": "3", "Tags": [ "python" ], "Title": "Determine whether a list contains a particular sequence" }
52470
<p>Is this code correct? Is there any major improvement I can ad in terms of number of operations?</p> <pre><code>#include &lt;stdio.h&gt; /* function that yields 1 when run on a machine that uses arithmetic right shifts for int's and 0 otherwise */ /* use only &lt;&lt; &gt;&gt; ! &amp; ~ ^ and constants between 0x0...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T21:43:20.380", "Id": "91956", "Score": "1", "body": "Does the code what you expect to do? The question of you \"Is this correct\" should be answered by you. If the answer is yes => change question to can you review mine code, if ans...
[ { "body": "<p>Replace <code>24</code> with <code>(sizeof(int) - 1) * CHAR_BIT</code>. Otherwise the code would fail on a non-32-bit integer machines. Also, using <code>-1</code> as a probe makes you independent of the bitness of a system:</p>\n\n<pre><code>return ((-1) &gt;&gt; 1) == (-1);\n</code></pre>\n\n<p>...
{ "AcceptedAnswerId": "52474", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T21:02:36.027", "Id": "52472", "Score": "0", "Tags": [ "c", "bitwise" ], "Title": "Arithmetic or logical right shifts" }
52472
<p>The script is for rotating 5 different coloured gears (tandwiel) on my site.</p> <p>I think the code can be improved and improved performance. 5x var paper isn't that smart for speed?</p> <p>Getting the current code working faster in the normal state is the primary concern, but there are two smaller issues I know ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T01:24:46.823", "Id": "91982", "Score": "0", "body": "I only just realized what you were saying in the first list point about the animation speeding up, then re-acclimating. This is caused by the animate subroutine, and if you check ...
[ { "body": "<p>Ok, now that I have a firm grasp on what you're doing, I think I have what you're looking for. The below still applies in terms of optimizing what you posted, but I think what you want is more along the lines of the following:</p>\n\n<p><a href=\"http://jsfiddle.net/SJsuJ/\" rel=\"nofollow\">fiddl...
{ "AcceptedAnswerId": "52476", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T21:11:30.953", "Id": "52473", "Score": "5", "Tags": [ "javascript", "performance", "animation", "raphael.js" ], "Title": "Animating Coloured Cogs" }
52473
<p>I am making an app and I want somebody to check my code to maybe make it shorter, fix bugs, or add some things.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Simple Calculator&lt;/title&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt; &lt;style...
[]
[ { "body": "<p>You have some layout bugs:</p>\n\n<ul>\n<li><p>The labels for the \"4\" and \"5\" keys are misaligned due to careless use of whitespace. I recommend omitting the spaces altogether, e.g.:</p>\n\n<pre><code>&lt;input id=\"btn7\" type=\"Button\" value=\"7\" …\n</code></pre></li>\n<li><p>You used a <...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T21:48:42.557", "Id": "52478", "Score": "8", "Tags": [ "javascript", "html", "css", "calculator" ], "Title": "A simple HTML / JavaScript calculator" }
52478
<p>I recently wrote a concurrent, mutex-less (but not lockfree) queue and wanted to know if it is actually correct, and if there are any particular improvements I could make:</p> <pre><code>template &lt;typename T&gt; class concurrent_queue { protected: T *storage; std::size_t s; std::atomic&lt;T*&gt; cons...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T09:03:41.743", "Id": "92009", "Score": "0", "body": "`\"It's platform specific to GCC on x86_64 [...]\"`\nOk, but can we move away from that?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T12:01:38.4...
[ { "body": "<p>Regarding the conditional return types in <code>push()</code> and <code>pop()</code>, it may be clearer to use a different type of infinite loop, such as a <code>for(;;)</code>. This will better focus the attention to the loop contents.</p>\n\n<p>You could also use curly braces for the single-lin...
{ "AcceptedAnswerId": "74309", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T22:31:27.483", "Id": "52481", "Score": "7", "Tags": [ "c++", "multithreading", "queue", "concurrency", "atomic" ], "Title": "Concurrent queue" }
52481
<p>I am a Java programmer, and I just recently started learning Scala for fun. I found a group of projects <a href="http://www.cplusplus.com/forum/articles/12974/">here</a>, and I tried to do the graduation excercise. The problem is, my code looks a lot like java, and I want to make this code more styled to fit scala, ...
[]
[ { "body": "<p>Let me start with some suggestions to improve your code a little bit in regards of scala/functional style. I will start with by class with the points that catched my eyes first and i might edit my post later on and add additional points.</p>\n\n<h3>Class structure and constructors</h3>\n\n<p>Inste...
{ "AcceptedAnswerId": "52485", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T23:45:03.290", "Id": "52483", "Score": "5", "Tags": [ "beginner", "functional-programming", "scala" ], "Title": "Beginner Project: Bunny City" }
52483
<p>I have an object, having key and values. I'd like to pick the object and call the appropriate function from the key:</p> <pre><code>var requireViews = { "breadCrumbView": true, "headerView": false, "footerView": false }; var that = this; _.each(requireViews, functi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T06:18:03.503", "Id": "92000", "Score": "0", "body": "What else is `requireViews` used for? Could you add more context to your question?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T08:24:39.190", ...
[ { "body": "<p>To be honest, I'd skip underscore for this, and just do</p>\n\n<pre><code>for(var func in requireViews) {\n if(requireViews[func] &amp;&amp; typeof this[func] === 'function') {\n this[func]();\n }\n}\n</code></pre>\n\n<p>Otherwise, there are many different ways to go about it.</p>\n\n<p>Here'...
{ "AcceptedAnswerId": "52512", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T04:38:37.843", "Id": "52490", "Score": "0", "Tags": [ "javascript", "underscore.js" ], "Title": "Is there a simple way to use Underscorejs to achieve this?" }
52490
<p>I wonder there is any method of refactoring nested condition. It's just the same content with different contents and different classes which looks bad. I really want to reform this code which looks bad.</p> <p>My sample code consists of the same conditions with different classes and contents.</p> <pre><code>publ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T05:32:55.413", "Id": "91994", "Score": "1", "body": "Do you know your submited code can't compile?" } ]
[ { "body": "<p>Time to review, while I think your second line just have a typ fault I will not consider that.</p>\n\n<h2>Implement abstract method with use of generics.</h2>\n\n<p>All your Service extends <code>BaseService</code>.<br/>\nI see the method <code>public Map action(AModel aModel) throws Exception{</c...
{ "AcceptedAnswerId": "52494", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T05:16:29.890", "Id": "52492", "Score": "1", "Tags": [ "java", "design-patterns" ], "Title": "Refactoring conditional statements among different classes" }
52492
<p>The following program is a demonstration of variant and double visitation used to obtain double dispatch between the elements of two inhomogeneous containers. Most of the work is done at compile time. What do you think about it compared to <a href="http://en.wikipedia.org/wiki/Double_dispatch#Double_dispatch_in_C.2B...
[]
[ { "body": "<p>It's a good example of multimethods in C++. But you should be aware that <code>variant</code> takes at least as much space as the biggest of its argument. It's done so to minimize overhead of walking an additional pointer. Probably, you need a variant with another allocation policy, as asteroids a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T07:30:39.633", "Id": "52495", "Score": "11", "Tags": [ "c++", "c++11", "template", "boost", "variant-type" ], "Title": "Multiple dispatch with variant and multi visitation...
52495
<p>This is my first validator I have created myself and I was wondering if there is anything about it that I could improve as far as:</p> <ul> <li>Code readability</li> <li>Code efficiency</li> </ul> <p>Note: The reason why I put an underscore before each validation method name is so that non-validation methods canno...
[]
[ { "body": "<p>Although you used a <code>Validator</code> class, this is not really object orientated. Actually I'm missing a <code>Rule</code> class. Your rules are applied by comparing strings right now, which is error prone and really ugly if you need to refactor it. Extending your code with new rules also re...
{ "AcceptedAnswerId": "52501", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T10:01:02.083", "Id": "52499", "Score": "4", "Tags": [ "php", "optimization", "object-oriented" ], "Title": "Validator Readability and Efficiency" }
52499
<p>I recently went through this <a href="http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours" rel="noreferrer">Haskell tutorial</a>. I'd be interested in any thoughts or comments at all, in terms of improving the structure, order, haskell conventions, or that long, kind of ugly eval function. </p> <pre><...
[]
[ { "body": "<h2>Bike shedding</h2>\n\n<p>to get the bike shedding out of the way: i prefer <a href=\"https://github.com/tibbe/haskell-style-guide/blob/master/haskell-style.md\" rel=\"noreferrer\">tibbe's style guide</a>. in that spirit, have blank lines between instance declarations, use a newline after an inst...
{ "AcceptedAnswerId": "55105", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T10:46:17.977", "Id": "52500", "Score": "7", "Tags": [ "haskell", "parsing", "scheme" ], "Title": "Code from \"Write Yourself a Scheme in 48 Hours\" tutorial" }
52500
<p>I've just created an implementation of array to train myself in copy constructors, assignment operators, and exception safety. Please look at this code and tell me what is wrong here.</p> <pre><code>class DumbArray { public: DumbArray(size_t sz) : _size(sz), _buf(new int[_size]) { memset(_buf, 0, _size...
[]
[ { "body": "<p>This is reasonably clean and reasonably complete code but I see some things that might improve your code.</p>\n\n<h1>Consider making this a template</h1>\n\n<p>There is no reason that this data structure should be limited to just storing <code>int</code> values. Consider reworking it as a templat...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T11:44:05.307", "Id": "52505", "Score": "4", "Tags": [ "c++", "c++11", "reinventing-the-wheel", "constructor" ], "Title": "Exercising in copy constructors and assignment operat...
52505
<p>I have made some composited container <code>Range</code> which accepts either a min/max range as a <code>std::pair</code> or a set of integers as a <code>std::set</code>.</p> <p><em>internally it saves a copy of the input by as <code>void *</code></em></p> <p>This container supports <code>iterators</code> which is...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T18:00:00.203", "Id": "92073", "Score": "0", "body": "can you show us a few lines of `main()` that demonstrates your intended use case of `Range`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T19:43:...
[ { "body": "<p>You should use template specialization rather than casting to void* here</p>\n\n<pre><code>// Pair or set depends on m_which.\n// Very easy to get that screwed up.\n// Especially since it is not const.\n\nRange(const Pair &amp; pair){\n m_ptr = static_cast&lt;void * &gt;( new Pair(pair) );\n ...
{ "AcceptedAnswerId": "52600", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T12:21:17.663", "Id": "52507", "Score": "4", "Tags": [ "c++", "c++11", "stl", "iterator" ], "Title": "Container which iterates a range or a list" }
52507
<p>I need to process some data which is the output from a CAD system, namely a Bill of Materials.</p> <p>I've constructed database and written some VBA code to achieve this. An explanation of what this code does is included as comments at the top of the code block below.</p> <p>This is my first project in Access/VBA ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T20:46:40.900", "Id": "92119", "Score": "1", "body": "On a personal note, I commend you for coming here and asking for feedback. In my experience, very few VBA programmers are actually interested in \"which are considered bad practic...
[ { "body": "<p>I think you should change a couple of your loops so they look cleaner</p>\n\n<pre><code>Do While Not RS_tmpTblDocsOutList.EOF ' loop through output docs\n</code></pre>\n\n<p>should be a <code>Do Until</code> loop</p>\n\n<pre><code>Do Until RS_tmpTblDocsOutList.EOF ' loop through output docs\n</cod...
{ "AcceptedAnswerId": "52545", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T14:05:14.757", "Id": "52511", "Score": "5", "Tags": [ "sql", "vba", "ms-access" ], "Title": "MS Access VBA code to compare records in a table and combine data where necessary" ...
52511
<blockquote> <p>I am writing a <code>ServerArbiter</code>, the job of which is to make a decision about which server to "choose" given a set of rules. The aim is to be able to add / remove rules at will - for ease of future maintenance. My language of choice is <a href="/questions/tagged/php" class="post-tag" title="...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T11:53:34.473", "Id": "92229", "Score": "0", "body": "I think you should allow for hard rules, and preference. Return true or false if server must be or must not be used, respectively, integer to increase or decrease the preference."...
[ { "body": "<ol>\n<li>Why does the <code>decide()</code> method do more work? It's the problem of the object constructing your Rules, which is not necessarily the <code>ServerArbiter</code>.</li>\n<li>Isn't that already a part of the <code>Server</code> entity? Why do you need to inject yet another dependency. I...
{ "AcceptedAnswerId": "53791", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T14:31:41.123", "Id": "52515", "Score": "5", "Tags": [ "php", "object-oriented" ], "Title": "OOP Decision Maker Class - ServerArbiter" }
52515
<p>I have a custom attribute in my assembly called SemverAttribute, and I have a helper class called AppInfo that has a function to return a number called the Semver number. It accepts an id of null-6. Is this the most efficient way to do this or should I break all this up into separate strings instead of one inline fu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T15:27:29.370", "Id": "92044", "Score": "1", "body": "Why are you using `dynamic` instead of `var` or `string[]`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T15:30:40.167", "Id": "92046", "...
[ { "body": "<p>You have a lot of comments saying what you are doing (almost one for every line of code). Code is good at saying what is happing, comments are better at saying why something is happening. If it is not clear to a reader what the code does, this is an indication that you might need better variable n...
{ "AcceptedAnswerId": "52524", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T15:25:43.163", "Id": "52519", "Score": "2", "Tags": [ "c#", "beginner", "strings", "classes", "asp.net-mvc-3" ], "Title": "Return custom assembly attribute variables" ...
52519
<p>I know that stringstreams are the C++ recommended way to create formatted text. However, they can often become quite verbose, especially when compared to the succinct format strings of <code>printf</code> and family. However, the <code>printf</code> family can lead to its own issues, with buffer overflow issues, a...
[]
[ { "body": "<p>Beware that <code>vsnprintf</code> <a href=\"http://msdn.microsoft.com/en-us/library/1kt27hek.aspx\">may</a> return -1. It is a non-compliant implementation, yet widely used.</p>\n\n<p>I honestly don't see a need to pass a format parameter as <code>std::string</code>. It is only used as <code>c_st...
{ "AcceptedAnswerId": "52572", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T15:35:28.403", "Id": "52522", "Score": "14", "Tags": [ "c++", "strings" ], "Title": "Mimic sprintf with std::string output" }
52522
<p>I'm currently working on my portfolio site and it's all great, but I'm unsure how to DRY my jQuery. I'm repeating myself a lot in the jQuery and it's just messy.</p> <p><strong>HTML:</strong></p> <pre><code> &lt;div id="footer-start" class="row"&gt; &lt;div class="col-sm-12 col-md-12"&gt; &lt;ul cla...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-06T11:46:04.647", "Id": "92227", "Score": "0", "body": "This would be *so* much easier using a library like Knockout JS. Check it out, you'll never code using jQuery .on selectors again." } ]
[ { "body": "<p>You can move all of the <code>click</code> functionality into one function:</p>\n\n<pre><code>function myClick(obj)\n{\n event.preventDefault();\n $loadHide.slideUp(500);\n obj.slideToggle(500);\n}\n</code></pre>\n\n<p>Then call that function inside each of your click mappings:</p>\n\n<pr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T18:03:42.247", "Id": "52529", "Score": "6", "Tags": [ "javascript", "jquery", "html" ], "Title": "DRY-ing jQuery code for portfolio site" }
52529