body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Consider this class:</p>
<pre><code>using Ninject;
using Ninject.Syntax;
using Ninject.Parameters;
namespace MyApp.Dependencies.Factories
{
public abstract class FactoryBase<T> where T : class
{
private IResolutionRoot _resolutionRoot;
protected FactoryBase(IResolutionRoot resolutionR... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-12T15:17:46.963",
"Id": "38724",
"Score": "0",
"body": "Couldn't create a 'ninject' tag. Or does this question belong in StackOverflow?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-12T16:38:43.263",
... | [
{
"body": "<p>Line-by-line I had exactly the same factory code. It smells, isn't it?</p>\n\n<p>The correct solution would be to use <a href=\"http://www.planetgeek.ch/2011/12/31/ninject-extensions-factory-introduction/\" rel=\"nofollow\">Ninject Factory extension</a>. I am happy since.</p>\n",
"comments": [... | {
"AcceptedAnswerId": "29203",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-12T15:17:06.020",
"Id": "25038",
"Score": "4",
"Tags": [
"c#",
"dependency-injection",
"factory-method"
],
"Title": "Are there side-effects to having a generic Ninject factory?"
} | 25038 |
<p>The <code>struct</code> and the prototypes of the functions were given in the question. I am unfortunately aware that this is more C code and less C++ code. </p>
<p>I am looking to compact my functions (specifically <code>ordered_insert</code> and <code>find_remove</code>) without removing functionality. For exampl... | [] | [
{
"body": "<p>The <code>tail_insert()</code> function could be improved a bit:</p>\n\n<pre><code>node_ll* tmp = new node_ll;\n...\nwhile(*list)\n list = &(*list)->next;\n*list = tmp;\n</code></pre>\n\n<p>In any case, you should separate the code for setting up the new node and inserting it a bit, then... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-12T18:20:10.607",
"Id": "25043",
"Score": "5",
"Tags": [
"c++",
"linked-list"
],
"Title": "Singly linked list"
} | 25043 |
<p>This script updates a MySQL database with golf scores and calculates how many strokes under the player is in real time and is working. I'm just looking for a better way to make it cleaner and compact.</p>
<pre><code><?php
// Get values from form
$uid=$_POST['uid'];
$name=$_POST['name'];
$course=$_POST['course']... | [] | [
{
"body": "<p>There are a number of ways to improve this code:</p>\n\n<ol>\n<li>You really need to use arrays for this.</li>\n<li><code>$d</code> and <code>$n</code> are identical so I don't see any need for the <code>if ($course = 'Augusta')</code> condition.</li>\n<li>Use <code>msqli</code> methods instead of... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-12T19:20:30.427",
"Id": "25045",
"Score": "3",
"Tags": [
"php",
"mysql"
],
"Title": "Populating a database with golf scores and stroke calculations"
} | 25045 |
<p>This is a security question.</p>
<p>I'm quite new to PHP and just a beginner in SQLite.</p>
<p>For practical, and educational reasons, I'm writing a small PHP site that will serve as one-threaded discussion (meaning, only one topic / no topics) between me and my friends.</p>
<p>The site will be open to the Intern... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T09:06:33.257",
"Id": "39625",
"Score": "0",
"body": "1. Doesn't `$query->bindValue()` escape `$message`? 2. You should call `htmlspecialchars()` in your view code, not before you store it in the DB."
},
{
"ContentLicense": "... | [
{
"body": "<p>Your sample <code>$message</code> is, frankly, kind of boring. Make it use accented vowels and the Chinese glyph 气 (\"life\"). Put an ASCII NUL in the middle. Ensure that SQLite3::escapeString() will insert at least two escapes, and that htmlspecialchars() will change one of them. You might want t... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-12T21:33:06.677",
"Id": "25049",
"Score": "3",
"Tags": [
"php",
"security",
"sqlite"
],
"Title": "how secure is this way of writing and reading with PHP and SQLite?"
} | 25049 |
<p>I am writing a method to find me a price range for special price as well as the retail price. Such as in example below I have price range for retail from 129 to 329 where as special price range is 89 to 199</p>
<pre><code>array
0 =>
array
'id' => 83739000038374
'special-price' =>... | [] | [
{
"body": "<pre><code>if($originalArraySingle['original-price'] < $priceRange['original-price']['min']){\n $priceRange['original-price']['min'] = is_int($originalArraySingle['original-price']) ? number_format((float)$originalArraySingle['original-price'], 2, '.', '') : $originalArraySingle['original-price... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-12T23:54:59.357",
"Id": "25051",
"Score": "1",
"Tags": [
"php",
"php5"
],
"Title": "array to return on conditions"
} | 25051 |
<p>The exercise is as follows:</p>
<blockquote>
<p>Create a class called Fraction that can be used to represent the ratio of two integers.
Include appropriate constructors, properties, and methods. If the denominator becomes
zero, throw and handle an exception. Create an application class to test the Fraction cl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-13T19:24:37.620",
"Id": "38762",
"Score": "0",
"body": "Would he allow unit testing to be considered a class to \"test\" your class?"
}
] | [
{
"body": "<p>I think your class is pretty much useless. If you have a class that represents a fraction, you should be able to do operations with it that you can do with a fraction, like addition, subtraction, multiplication and division (possibly using operator overloading). Another possible operation is fract... | {
"AcceptedAnswerId": "25055",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-13T10:07:50.933",
"Id": "25054",
"Score": "5",
"Tags": [
"c#",
"homework",
"rational-numbers"
],
"Title": "Creating and testing a Fraction class"
} | 25054 |
<p>I have some code that allows me to enumerate over months in a year. This code is used both in a Web application as well as a standalone exe. Although it doesn't have to be efficient it is used a lot so if there are any improvements that would be great (I haven't done any profiling). It also needs to be thread-saf... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-13T21:12:21.883",
"Id": "38766",
"Score": "0",
"body": "Is there a reason why `Undefined` is required? Couldn't you just use `January = 1`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-13T21:26:26.770",
... | [
{
"body": "<p>Here's my take - note the <code>ReadOnlyCollection</code> creations to keep the callers from being able to modify the members of the static collection:</p>\n\n<pre><code>public enum Month\n{\n /// <summary>\n /// Required here even though it's not a valid month.\n /// </summary&g... | {
"AcceptedAnswerId": "25063",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-13T20:07:42.457",
"Id": "25059",
"Score": "0",
"Tags": [
"c#"
],
"Title": "Enumerating over a enum that defines months in the year"
} | 25059 |
<p>When a user is created, deleted and update the system will give feed back. e.g. User Deleted/Updated/Create success or unsuccessfully, but I'm sure there is a better way to do it than what I have done because I repeat the same code in all functions within my class.</p>
<p>Code to create user</p>
<pre><code>$userOn... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T11:40:24.087",
"Id": "38796",
"Score": "0",
"body": "You could make them static functions. echo userActions::create($database, 'Greg', '324b2643243'); If you don't use them for something else."
}
] | [
{
"body": "<p>I recommend splitting your model (the database operation) from your view (the localization of your message).</p>\n\n<p>Depending if you prefer a return code or a exception flow your code could look like:</p>\n\n<pre><code>public function create()\n{\n if($this->user_exists) return \"\"; //do... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T01:19:51.580",
"Id": "25066",
"Score": "2",
"Tags": [
"php",
"mysql",
"user-interface"
],
"Title": "Better way to have output code?"
} | 25066 |
<p>I am working out a bit of Clojure code that will take a ref to a map and increment a key value pair in the map. I think I am using ref correctly, but Im not sure about atom. Do I need to use swap! to be more idiomatic? I am new to STM and Clojure, does this look thread-safe / sane? What am I missing?</p>
<pre><... | [] | [
{
"body": "<p><strong>Don't always create new atoms</strong></p>\n\n<p>My first comment is that your use of <code>atom</code> seems quite wrong to me: atoms are mutable entities which you're supposed to mutate via e.g. <code>swap!</code> or <code>reset!</code>, which alter the value the atom points to without c... | {
"AcceptedAnswerId": "25130",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T02:52:06.527",
"Id": "25067",
"Score": "3",
"Tags": [
"thread-safety",
"clojure"
],
"Title": "Atomically incrementing a value in a map in Clojure"
} | 25067 |
<p>I am doing exercises for the <em>Art and Science of Java</em> textbook. I had an exercise that required me to program the simulation of flipping a coin until 3 consecutive "Heads" result appeared.</p>
<p>I did it, but I'm not sure if my code is simple enough - since I used an instance variable to count the heads an... | [] | [
{
"body": "<p>The one thing that really stands out to me: you don't need to convert the boolean result of <code>nextBoolean()</code> to a human-readable string, then test the string. Just test the result directly, <em>then</em> convert it to a human-readable string. </p>\n\n<pre><code>private void flipCoin () {... | {
"AcceptedAnswerId": "25069",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T03:02:04.343",
"Id": "25068",
"Score": "5",
"Tags": [
"java",
"performance"
],
"Title": "Coin flipping code"
} | 25068 |
<p>I'm writing a program that downloads stuff from the internet. While the program is working fine, I want to get one critical part reviewed. I use System.Diagnostics.StopWatch object to measure the time taken for the ns (NetworkStream) object to read the bytes in buffer. I then divide the number of elapsed seconds in ... | [] | [
{
"body": "<blockquote>\n <p>I then divide the number of elapsed seconds in stopwatch by number of\n bytes received to calculate the speed of my download in KBPS.</p>\n</blockquote>\n\n<p>Just an idea: NetworkStream.Read returns the number of bytes received. If you divide this with the number of seconds, you'... | {
"AcceptedAnswerId": "25085",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T07:14:05.773",
"Id": "25070",
"Score": "6",
"Tags": [
"c#",
"networking"
],
"Title": "Better way to code download speed calcuation"
} | 25070 |
<p>For a WordPress login form I have written a small plugin. It adds a checkbox with a unique name to the form and if that name is not present in the login POST request it just dies.</p>
<p>The idea is preventing <a href="http://www.metasploit.com/modules/auxiliary/scanner/http/wordpress_login_enum" rel="nofollow nore... | [] | [
{
"body": "<p>This is not meant to be a comprehensive answer:</p>\n\n<p>If you do not want a bug that happens only in some browsers and only some of the time, use a <a href=\"https://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html\">safe, conservative format as an id</a></p>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T07:32:58.293",
"Id": "25071",
"Score": "2",
"Tags": [
"javascript",
"optimization",
"form"
],
"Title": "Add checkbox with label to a form"
} | 25071 |
<p>with below query i'm getting the results that i want but it's quite slow taking nearly 0.2 seconds (on an i5 machine). Is there a more optimized way to get the same results.</p>
<p>Basically this query fetches the last 20 rows in the table and shows only one row per yzr.name and orders by yzr.favorite_count </p>
<... | [] | [
{
"body": "<p>As you have no range specific functions applied in the <code>SELECT</code> clause I don't understand why you need the <code>GROUP BY</code> clause.</p>\n\n<p>The expression is way to simple to be optimized (its hard to see how you can go wrong). </p>\n\n<p>For any optimization advice you will nee... | {
"AcceptedAnswerId": "25075",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T10:06:56.170",
"Id": "25074",
"Score": "2",
"Tags": [
"optimization",
"mysql",
"sql"
],
"Title": "Is there a more optimized way for this MySql Query"
} | 25074 |
<p>I have to write this program in java.</p>
<blockquote>
<p>Write a program name sorting.java that will use an array to store 10,000 randomly generated numbers (ranging from 1 to 10,000 no repeat number).</p>
</blockquote>
<p>Here is what I have so far:</p>
<pre><code>public class Sort
{
public static void ma... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T21:50:25.620",
"Id": "38818",
"Score": "0",
"body": "I would like to thank everyone as all your post have been excellent."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-13T05:31:44.280",
"Id": "8239... | [
{
"body": "<p>Nearly right. </p>\n\n<p>List item</p>\n\n<p>You want:</p>\n\n<pre><code>for (int i=0; i<nums.length; i++) {\n nums[i] = i + 1;\n}\n</code></pre>\n\n<p>or you'll get 0-9,999, the question says 1-10,000</p>\n\n<p>Also, the print loop is missing a closing <code>}</code></p>\n",
"comments"... | {
"AcceptedAnswerId": "25081",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T16:25:48.203",
"Id": "25077",
"Score": "15",
"Tags": [
"java",
"sorting",
"random"
],
"Title": "Sorting 10,000 unique randomly-generated numbers"
} | 25077 |
<p>I've found two ways of writing the same program (one that only uses local variables, but no methods other than the main one) and other that uses one instance variable that is used in two methods.</p>
<p>This program aims to simulate the radioactive decay of atoms and uses a random number generator.</p>
<p>Here are... | [] | [
{
"body": "<p>Firstly, some minor nitpicks on your code: </p>\n\n<pre><code> for (int i = remainingAtoms; i > 0; i--) {\n</code></pre>\n\n<p>Why are you counting down instead of up? I can see why after careful inspection, but a comment would be useful.</p>\n\n<pre><code> println (\"There are \" ... | {
"AcceptedAnswerId": "25088",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T19:24:21.870",
"Id": "25083",
"Score": "1",
"Tags": [
"java",
"random"
],
"Title": "Simulating the radioactive decay of atoms using a random number generator"
} | 25083 |
<p>Basically, I'm performing an <code>if</code> statement on an array based on the returned value</p>
<pre><code><?php
if($array[1]>10000 AND $array[1]<50000){
$selling = $array[1] - 250;
}
elseif($array[1]>50000 AND $array[1]<100000){
$selling = $array[1] - 500;
}
else{
... | [] | [
{
"body": "<p>First of all, replace <code>$array</code> with a descriptive name, and copy <code>$array[1]</code> into some other descriptive name.</p>\n\n<p>Next, create a new array that describes those price ranges, in $10k increments, along with 1000, 750, 500, whatever. Give them a descriptive name, too, per... | {
"AcceptedAnswerId": "25105",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T19:45:53.313",
"Id": "25084",
"Score": "0",
"Tags": [
"php"
],
"Title": "Cleaner method of doing IF"
} | 25084 |
<p>Here's my code. Please review it for correctness, readability and efficiency. If you think it can be improved also let me know. This code works fine for positive numbers but doesn't for negative. How can I change it ? Any comments for improvement will be appreciated. </p>
<pre><code>int sum(int a, int b)
{
... | [] | [
{
"body": "<p>Nice.</p>\n\n<p>Start by following Java <a href=\"http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-139411.html#16712\" rel=\"nofollow\">Code Conventions</a>; 8.2 asks for spaces around binary operators.</p>\n\n<p>Add a unit test with nested loops that compares your resul... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T20:44:51.690",
"Id": "25089",
"Score": "1",
"Tags": [
"java"
],
"Title": "Code Review for Adding two numbers without using the + operator"
} | 25089 |
<p>I feel this is deeply inelegant, but I really want the option of classical inheritance in the future. How could this be written better. FYI animation here is from <a href="http://www.greensock.com/gsap-js/" rel="nofollow">GSAP</a> if you are curious.</p>
<pre><code>class Modal
angular.element(document).ready =... | [] | [
{
"body": "<p>Honestly, I'd recommend against creating a class. You <em>may</em> want classical inheritance in the future, but right now it's not necessary. Premature optimization rarely benefits anyone. Besides, if you do want classical inheritance later, it's pretty trivial to convert the code.</p>\n\n<p>I'd ... | {
"AcceptedAnswerId": "25106",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T23:54:01.093",
"Id": "25092",
"Score": "0",
"Tags": [
"coffeescript",
"angular.js"
],
"Title": "coffeescript and angular directive"
} | 25092 |
<p>How can I optimize this code to have fewer loops and return values for unit testing?</p>
<pre><code> public class Diamond {
public void DiamondShape(int num) {
for(int ucount=num;ucount>0;ucount--) {
//Loop to print blank space
for(int count_sp=1;count_sp<ucount;count_sp++)
System.out.printf(... | [] | [
{
"body": "<p>First of all: Use a StringBuilder instead of System.out.println so you can easily compare the result of your method with an expected output.</p>\n\n<p>Your test could look like: (I renamed you method to draw and moved the size to the instance.)</p>\n\n<pre><code>@Test\npublic void test4()\n{\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-15T08:25:26.263",
"Id": "25099",
"Score": "4",
"Tags": [
"java",
"unit-testing",
"formatting",
"junit"
],
"Title": "Printing a diamond-shaped figure"
} | 25099 |
<p>I wrote a Connect Four game including a AI in Clojure and since I'm rather new to Clojure, some review would be highly appreciated. It can include everything, coding style, simplifications, etc.
But keep in mind the AI is not finished yet, other heuristics will be added in the near future. Currently it only cares ... | [] | [
{
"body": "\n\n<p><em>This is two and a half years old, but for the sake of future viewers:</em></p>\n\n<p>Overall your coding style looks pretty good, especially for someone new to Clojure. I don't have any comments on the AI engine itself, but here are a few structural notes:</p>\n\n<p><code>not-nil?</code> a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-15T09:07:35.817",
"Id": "25101",
"Score": "49",
"Tags": [
"beginner",
"functional-programming",
"lisp",
"clojure",
"ai"
],
"Title": "Connect Four AI (Minimax) in Clojure"
} | 25101 |
<p>I have a user model, a task model, and a junction model user_task that saves the data joining the two:</p>
<pre><code>class Task < ActiveRecord::Base
attr_accessor :completed_on
has_many :user_tasks
class UserTask < ActiveRecord::Base
attr_accessible :task_id, :user_id, :completed_on
belongs_to :user... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-15T18:40:26.057",
"Id": "38855",
"Score": "0",
"body": "Why do you have the `UserTask` model and table? Since you're not using a `has_and_belongs_to_many` relationship anywhere, and `UserTask` isn't adding any new information, there's ... | [
{
"body": "<p>The problem is that the data to render does not match the modelling. You call it \"task\", but if it includes a <code>completed_on</code> it's not a task, it's something more of a <code>user_task</code>. I definitely wouldn't use an accessor to accomplish this, that's messing with <code>Task</code... | {
"AcceptedAnswerId": "25140",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-15T18:08:46.983",
"Id": "25108",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Rails: Setting a transient attribute on a set of objects from one model based on informat... | 25108 |
<p>I was writing a calendar a long time ago and, coming back to the code, I've realized that it's not the best. I was fairly mediocre at programming back then.</p>
<p>I'm using jQuery, Mousetrap, and Hammer.js. Here is <a href="http://8b51d1abd8.test-url.ws/" rel="nofollow">a working example</a> and the <a href="http:... | [] | [
{
"body": "<p>Actually posting your code here should not require any additional comments. Everywhere you have the feeling for the need of the comment, you should check the method and variable names. Maybe even splitting a method might help to make the code more readable. (You obviously have a feeling for this a... | {
"AcceptedAnswerId": "25122",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-15T18:32:23.647",
"Id": "25110",
"Score": "1",
"Tags": [
"javascript",
"performance"
],
"Title": "What could I have done better with this code from a calendar?"
} | 25110 |
<p>I was hoping I might get some feedback and ideas for improvement on this, particularly the <code>WebRouter</code> class.</p>
<pre><code>#include <native/native.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
#include <cppconn/driver.h>
#include <cppconn/connection.h&g... | [] | [
{
"body": "<p>I know this is a small app, but I would move the direct SQL calls into it's own class:</p>\n\n<p>From this:</p>\n\n<pre><code>sql::ResultSet *result;\nresult = stmt->executeQuery(\"select * from daily_history where symbol_id = 'AA';\");\n</code></pre>\n\n<p>To this:</p>\n\n<pre><code>DailyHisto... | {
"AcceptedAnswerId": "25115",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-15T22:24:38.247",
"Id": "25113",
"Score": "0",
"Tags": [
"c++",
"mysql",
"json",
"connection-pool"
],
"Title": "JSON API in C++ with Node.native, RapidJSON, and MySQL"
} | 25113 |
<p>I have a 100page long .docx format document. I'm using a macro written in VBS to extract some information and then just generate a table from them. I iterate through the paragraphs and store the found strings in 3 separate arrays.</p>
<p>However, the loop is unreasonably slow. It takes 3 min to complete on a relat... | [] | [
{
"body": "<p>Maybe I'm deeply wrong, but please test:</p>\n\n<p>-- Almost all your variables are of type Variant, even the ones which could be Long, like counter. Define each variable with the correct type (it will be faster), in the form: </p>\n\n<pre><code> Option Explicit\n Dim counter as Long\n Dim Colu... | {
"AcceptedAnswerId": "25126",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T07:05:20.093",
"Id": "25123",
"Score": "7",
"Tags": [
"performance",
"vba",
"vbscript",
"ms-word"
],
"Title": "Extracting data from a Word document is too slow"
} | 25123 |
<p>I've created simple try/catch macros that now I'd like to promote to wider use in my projects.
I would have really liked to be able to do without global variables but I have not found any way to do it.</p>
<p>Any suggestion for improvement? Any issue that I may have overlooked?</p>
<pre><code> #include <std... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T19:57:35.257",
"Id": "38909",
"Score": "2",
"body": "Why not use C++ instead of building your own?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T20:31:38.000",
"Id": "38912",
"Score": "0",
... | [
{
"body": "<p>One problem with this is resource leaks. It is not that your macros leak, but that when you use them, you'll leak. For example, suppose you call your <code>utlTry</code> in function <code>a()</code> that then calls function <code>b()</code> that allocates a resource (opens a file for example) an... | {
"AcceptedAnswerId": "25187",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T08:07:55.093",
"Id": "25124",
"Score": "3",
"Tags": [
"c",
"macros"
],
"Title": "C try/catch macros"
} | 25124 |
<p>I was writing an answer in another thread and came across this challenge. I'm trying to have a generic class so that I can delegate the routine (and tiring) <code>Equals</code> and <code>GetHashCode</code> implementation to it (which should handle all that). With the code things will be clearer.</p>
<p>Please note ... | [] | [
{
"body": "<p>You can reach maximum performance by generating specialized code at runtime using <code>Expression</code> trees. Instead of injecting <code>Func</code>s, inject <code>Expression<Func<...>></code> s into your <code>Equater</code> class. Analyze what field they point to and build up the ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-15T22:44:31.577",
"Id": "25131",
"Score": "6",
"Tags": [
"c#",
"performance",
"generics"
],
"Title": "Generic wrapper for equality and hash implementation"
} | 25131 |
<p>I want to extend an app object with a widget that initializes itself immediately.</p>
<p><em>Immediately-Invoked Function Expression:</em></p>
<pre><code>var app = {};
(function() {
app.widget = {
init: function() {
return true;
}
};
app.widget.init();
}());
</code></pre>
<p><em>Immediately-... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T11:55:33.300",
"Id": "38890",
"Score": "3",
"body": "It's better if you actually put the code here. If jsPerf was down, this question won't have any future value."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | [
{
"body": "<p>Code is not just about performance. You have to check for maintainability, scalability and readability as well.</p>\n\n<p>With regards to the way code is written, I'd favor the first method because it's the module pattern and is a common convention. The second one is too full of brackets and the o... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T11:53:22.463",
"Id": "25133",
"Score": "1",
"Tags": [
"javascript",
"performance"
],
"Title": "Performance Test and Idea: Initialize a widget"
} | 25133 |
<p>I started this question to get people to grasp a little bit more on how to develop analog controls for android devices. But my code is a little outdated so if anyone knows how to implement it better please post your answer, as there are a lots of bugs in the code below as you'll see.</p>
<p>Note: this is only if yo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T11:56:13.840",
"Id": "38891",
"Score": "0",
"body": "thanks, i did not even know about that site"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T12:25:27.597",
"Id": "38892",
"Score": "0",
... | [
{
"body": "<h3>Initial refactoring</h3>\n\n<p>Your code was hard to follow, so I applied a few mechanical transformations to clean it up first.</p>\n\n<p>Let's start by renaming a few variables.</p>\n\n<pre><code>void init() {\n DisplayMetrics screen = new DisplayMetrics();\n getWindowManager().getDefault... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T11:52:31.700",
"Id": "25135",
"Score": "3",
"Tags": [
"java",
"android"
],
"Title": "Dual Analog Stick Controls"
} | 25135 |
<p>I'm using OpenGL to draw about 20 circles. Each circle has 2 lines, ~10 segments, and all of them have different colors and lengths. Frames per Second are around 4.</p>
<p>How can I optimize this to run faster, with higher frame-rates? I am using Python 3 on Ubuntu.</p>
<pre><code>class ScreenOpenGL(Screen):
def _... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T13:43:29.247",
"Id": "38962",
"Score": "1",
"body": "First, we're a code review...not here to fix code. Having said that, your code does not follow *any* style-rules. Sometimes there are spaces between operators, sometimes there are... | [
{
"body": "<p>Not really sure why this line is neccesary.</p>\n\n<pre><code>print(\"Fuck\")\n</code></pre>\n\n<p>Unless <code>\"Fuck\"</code> is Russian for something, this should be removed.</p>\n\n<p>In addition, using <code>%</code> for string formatting is deprecated. One should be using <a href=\"https://d... | {
"AcceptedAnswerId": "97067",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T13:37:05.810",
"Id": "25138",
"Score": "5",
"Tags": [
"python",
"performance",
"python-3.x",
"linux",
"opengl"
],
"Title": "Accelerate OpenGL 2D on Python3"
} | 25138 |
<p>In a new project I am creating for my work, I am creating a fairly large ASP.NET web API. The API will be in a separate Visual Studio solution that also contains all of my business logic, database interactions, and <code>Model</code> classes.</p>
<p>In the test application I am creating (which is ASP.NET MVC4), I w... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-06T15:48:02.030",
"Id": "60531",
"Score": "0",
"body": "This method will probably help your cause: http://i-skool.co.uk/net/re-usable-webapi-request-wrapper/ Let's you call an API route and return the delegated object."
}
] | [
{
"body": "<p>All the controlers are regular classes with methods.</p>\n\n<p>Assuming your API controller <code>StudentDashboard</code> has a <code>Get(string name)</code> verb method, you can do this:</p>\n\n<pre><code>public ActionResult Index() //This view is strongly typed against User\n{\n //testing aga... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T14:45:36.390",
"Id": "25141",
"Score": "18",
"Tags": [
"c#",
"performance",
"asp.net",
"web-services"
],
"Title": "Consuming an ASP.NET Web API call in an MVC controller"
} | 25141 |
<p>I am brand new to dictionaries and coding and am hoping to get some suggestions on how I should structure my dictionary. </p>
<p>I have a collector number which has meters connected to them. Each of the meters have a meter number and a ert number and would like to store both the meter and ert number. There will be... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T17:30:39.950",
"Id": "38900",
"Score": "5",
"body": "Dictionaries are fast (O(1)) but not handy if you need to find items by more than one 'key'. If the lists will not be large you'd be better of just using a list of objects (classe... | [
{
"body": "<p>If you have a collection of <code>Meter</code>s and you want to be able to find the ONE based on a property, this is how I would do it:</p>\n\n<p>Create a <code>List</code> of <code>Meter</code>s, say <code>l</code>..</p>\n\n<pre><code>List<Meter> l = new List<Meter>();\n</code></pre>\... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T16:44:58.397",
"Id": "25143",
"Score": "0",
"Tags": [
"c#",
"hash-map"
],
"Title": "Dictionary Structure"
} | 25143 |
<p>I'm working on a piece of code for calculating all the possible combinations of numbers that sum to <em>n</em>. For example:</p>
<pre><code>sum_combination(3) = [
[1,1,1],
[1,2],
[3]
]
</code></pre>
<p>So my ruby code is this:</p>
<pre><code>class Integer
SUM_COMBINATION = {
1 => [[1]],
2 =>... | [] | [
{
"body": "<p>Unless you need the entire set of combinations immediately, you could use <a href=\"http://ruby-doc.org/core-2.0/Enumerable.html#method-i-lazy\" rel=\"nofollow\">a <code>lazy</code> enumerator</a>, which just gets the next item in the set when asked.</p>\n\n<p>This requires using Ruby 2.0, as it w... | {
"AcceptedAnswerId": "25203",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T18:45:55.793",
"Id": "25148",
"Score": "5",
"Tags": [
"ruby",
"combinatorics"
],
"Title": "Optimizing sum_combination_for(n) code"
} | 25148 |
<p>I've got this method, and it's quite a big method. I look at it, and I feel... dirty. I feel that it's doing too much, and that there might be a better way to accomplish what I'm trying to.</p>
<pre><code>/// <summary>
/// Calculates daily project drilling hours
/// </summary>
/// <param name="daily"... | [] | [
{
"body": "<p>Without going too far I've simplified your method. I'll leave the bigger stuff to someone who is more familiar with the content. I haven't touched correctness and/or functionality.\nYou should also have some try/catch around the query stuff and the conversions.</p>\n\n<pre><code>/// <summary>... | {
"AcceptedAnswerId": "25158",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-16T21:42:18.350",
"Id": "25155",
"Score": "6",
"Tags": [
"c#"
],
"Title": "Calculating daily project drilling hours"
} | 25155 |
<p>Thanks for looking it over. I'm still pretty new to programming. I thought this would be a good exercise in addition to making the Project Euler fraction problems easier</p>
<pre><code>import java.math.BigInteger;
final class BigFraction extends Number{
private BigInteger numerator;
private BigInteger de... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T07:10:01.737",
"Id": "38934",
"Score": "4",
"body": "Can you specify what is slow? All operations?"
}
] | [
{
"body": "<p>You should use <code>BigInteger.gcd()</code> instead of <code>GCF()</code>, also in <code>isReduced()</code>. Don't use <code>compareTo</code> in <code>equals</code>: If your fractions are <em>always</em> in reduced form, you can just compare numerators and denominators. In <code>compareTo</code>,... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T06:34:50.403",
"Id": "25160",
"Score": "3",
"Tags": [
"java"
],
"Title": "I made a BigFraction class in Java. It's a bit slow"
} | 25160 |
<p>I have read some articles discussing about why static is bad, some of them refering static as not-testable, non-mockable, has state (non-stateless) and everything else.</p>
<p>However I have encountered some cases where I am forced to use static implementation, such as:</p>
<ul>
<li>During using HttpContext.Curren... | [] | [
{
"body": "<p>I see no problem in such wrappers except they are kinda cumbersome to write. They provide a good way to decouple your code not only from static objects, but from the all the objects you cannot mock too (for example, sealed classes from 3rd party libraries). I use that kind of adapters myself and h... | {
"AcceptedAnswerId": "25167",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T07:13:20.580",
"Id": "25161",
"Score": "6",
"Tags": [
"c#",
"design-patterns",
"static"
],
"Title": "Handle static objects using custom adapter"
} | 25161 |
<p>I have the following CRC 16 code. Is it possible to improve the performance of the code with unsafe constructs? My knowledge about pointer arithmetic is rather limited.</p>
<pre><code>public enum Crc16Mode : ushort { Standard = 0xA001, CcittKermit = 0x8408 }
public class Crc16Ccitt
{
static ushort[] table = ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T14:20:10.557",
"Id": "38963",
"Score": "3",
"body": "Is the performance of this code problematic? `ComputeChecksum` looks rock-solid as you can get. The only other improvement I can see is to remove the constructor and replace with ... | [
{
"body": "<p>Your code looks pretty good except for the <code>static table</code>. More about that later.</p>\n\n<p>Unsafe code has a few things that can make code go faster, like pointers to arrays and arrays on the stack.</p>\n\n<p>A pointer to array would make code only faster if the code is iterating throu... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T09:02:39.447",
"Id": "25165",
"Score": "2",
"Tags": [
"c#",
"performance"
],
"Title": "CRC 16 code with \"unsafe features\""
} | 25165 |
<p>I have to create a modularized program that can find out the diameter, circumference, and area of a circle's radius. I'm sure many of you can notice I kind of winged this from a example given from my teacher. Instead of people pointing out the fact that I coded this wrong, could you please give me reasons for what I... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T12:02:30.047",
"Id": "38945",
"Score": "0",
"body": "Have you learned about Classes? This would be a great example in using one."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T07:51:11.587",
"Id"... | [
{
"body": "<p>Many little comments here to make things simpler,shorter,more pythonic :</p>\n\n<ul>\n<li><p><a href=\"http://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables\" rel=\"nofollow\">PEP 0008</a> gives some coding guidelines for python. Among other things, it gives a naming convent... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T09:30:14.287",
"Id": "25166",
"Score": "2",
"Tags": [
"python"
],
"Title": "Modularized program to find circumference, diameter, and area from a circle's radius"
} | 25166 |
<p>I'm using the following pattern to pool D3D objects globally in my application. Is it a good idea (alternatives)? Is it thread-safe?</p>
<pre><code>CComPtr<ID3D11Texture2D> create_texture(const D3D11_TEXTURE2D_DESC& desc)
{
static concurrent_unordered_map<D3D11_TEXTURE2D_DESC,
... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T12:06:26.980",
"Id": "25169",
"Score": "2",
"Tags": [
"c++",
"c++11",
"thread-safety",
"memory-management",
"com"
],
"Title": "D3D COM Object Pooling"
} | 25169 |
<p>I have written the below code which generates all possible permutations with repetitions of a string.</p>
<p>I want to make this program shorter and much faster, but I don't know how to do that.</p>
<pre><code>Imports System.Text
Public Class Form1
Private blkRpt As Integer
Private perm As Double
Pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T08:56:54.583",
"Id": "38946",
"Score": "1",
"body": "Please use Option Strict....implicit conversions (like `Dim rtb As Double = TextBox2.Text`) are dangerous. What is `TextBox2.Text` has \"The first and the last\" in it?"
},
... | [
{
"body": "<p>I'm not going to rewrite this code right now, but I can highlight a few points:</p>\n\n<ol>\n<li>Naming. \n<ul>\n<li>Identifiers should have a <strong>meaningful</strong> name.</li>\n<li><strong>Disemvoweling</strong> is evil.</li>\n<li>Adding a <code>1</code> after an identically-named variable i... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-14T08:48:27.413",
"Id": "25170",
"Score": "2",
"Tags": [
"vb.net",
"combinatorics",
"performance"
],
"Title": "Generating permutations with repetitions of string"
} | 25170 |
<p>I have several calculus to do in my ruby app.
My code is currently working but I find it very ugly.</p>
<pre><code>@guestreviews = GuestReview.where(:reviewed_id => @user.id)
@hostreviews = HostReview.where(:reviewed_id => @user.id)
@hospitalityrate = 0
@foodrate = 0
@placerate = 0
@hostreviews.try(:each) do ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T16:39:02.403",
"Id": "38968",
"Score": "0",
"body": "why are all of these instance variables? why not use some local variables?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T03:59:09.960",
"Id":... | [
{
"body": "<p>It's actually easier to do this in the database layer. It's exceedingly good at these kinds of things.</p>\n\n<pre><code>@guest_reviews = GuestReview.where(:reviewed_id => @user.id)\n@host_reviews = HostReview.where(:reviewed_id => @user.id)\n\n@hospitality_rate = @guest_reviews.average('pe... | {
"AcceptedAnswerId": "25174",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T13:41:07.730",
"Id": "25172",
"Score": "3",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Math Calculus in ruby"
} | 25172 |
<pre><code>/**
* takes a list of componentIDs to load, relative to componentRoot
* returns a promise to the map of (ComponentID -> componentCfg)
*/
function asyncLoadComponents (componentRoot, components) {
var componentCfgs = {};
function asyncLoadComponentCfg(component) {
var url = _.sprintf("... | [] | [
{
"body": "<p>Here's <a href=\"http://jsfiddle.net/UgdNA/1/\" rel=\"nofollow\">a sample in jsFiddle</a>, with some values and functions mocked-up to use jsFiddle API.</p>\n\n<p>Here's the actual code, with notes in the comments:</p>\n\n<pre><code>//personally, I like comma separated variables preferrably the \n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T14:53:29.787",
"Id": "25173",
"Score": "1",
"Tags": [
"javascript",
"functional-programming",
"asynchronous",
"underscore.js",
"monads"
],
"Title": "functional javascript ... | 25173 |
<p>Could this be better factored as a reduce?</p>
<pre><code>/**
* recursively build a nested Backbone.Model or Backbone.Collection
* from a deep JSON structure.
*
* undefined for regex values
*/
exports.modelify = function modelify (data) {
if (_.isArray(data)) {
return new Backbone.Collection(_.map... | [] | [
{
"body": "<p>Looks quite nice to me, the only thing I would change is the flow, you do not need the <code>else if</code> and <code>else</code> after a <code>return</code>. I think the function is easier on the eyes and shorter if you take <code>return</code> into account.</p>\n\n<pre><code>exports.modelify = f... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T15:02:53.763",
"Id": "25175",
"Score": "5",
"Tags": [
"javascript",
"functional-programming",
"recursion",
"underscore.js"
],
"Title": "Recursively walking a tree to build up ... | 25175 |
<p>I wonder if someone could give me some pointers to my PHPmailer Process file and see if they find any misstakes or things that I have missed in the validation/sanitation of the data.
Any input would be most wellcome! </p>
<pre><code><?php
//includes
require_once('func/mail/mailcon/config-info.php');
require_once... | [] | [
{
"body": "<p>and welcome to CodeReview!</p>\n\n<p>Here's a few things:</p>\n\n<ul>\n<li>You have a lot of pointless comments \n<ul>\n<li>(\"includes\": The includes are the next line. We see them; no need to tell us.)</li>\n</ul></li>\n<li>Indent block content.\n<ul>\n<li>Whenever you enter an if block, indent... | {
"AcceptedAnswerId": "25191",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T13:19:49.777",
"Id": "25182",
"Score": "4",
"Tags": [
"php"
],
"Title": "PHPmailer sanitazion/validation a second oppinion."
} | 25182 |
<p>I'm trying to teach myself javascript and HTML5, (just beginning), and for some practice with canvas I am trying to turn <a href="http://www.stefan.gr/dhammachart-bigger.gif" rel="nofollow">this chart</a> into an interactive chart on canvas, whereby clicking on a word opens up some of the tree below, and so on. I ca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T18:56:34.597",
"Id": "38979",
"Score": "0",
"body": "I highly suggest you use a framework rather than tackling this head on with raw JS."
}
] | [
{
"body": "<p><a href=\"http://canvasquery.com/\" rel=\"nofollow\">Canvas Query</a> will be very helpful. Once you load it you will be able to chain methods as follows:</p>\n\n<pre><code>ctx.font = \"bold 40px Arial\";\nctx.fillStyle = \"#0C0\";\nctx.textAlign = \"center\";\nctx.fillText(\"Fully Enlightened\", ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T17:55:03.617",
"Id": "25185",
"Score": "2",
"Tags": [
"javascript",
"html5",
"canvas"
],
"Title": "Javascript canvas interactive chart - how to make my code shorter"
} | 25185 |
<p>How can I improve this code?</p>
<p>Also available from git://github.com/edescourtis/actor.git .</p>
<p>Actor.java</p>
<pre><code>package com.benbria.actor;
public interface Actor<T> extends Runnable {
public abstract void send(T msg) throws InterruptedException;
public abstract void stop() throws... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T21:56:49.697",
"Id": "39001",
"Score": "0",
"body": "Very nice! What about an factory to create the actor?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T21:57:51.483",
"Id": "39002",
"Score"... | [
{
"body": "<ol>\n<li><p>No need for Actor to extend Runnable</p></li>\n<li><p>NullActorListener is redundant: MultiplexedActorListener with empty list of listeners behaves the same way. Having MultiplexedActorListener as a default listener, no need for the ThreadActor constructors with ActorListener parameters ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T18:41:49.907",
"Id": "25188",
"Score": "5",
"Tags": [
"java",
"design-patterns",
"multithreading",
"thread-safety",
"actor"
],
"Title": "Review of simple Java Actor librar... | 25188 |
<p>I wrote a small ducktaped VBA script which pings servers every 15 mins or so. If a server's status is anything other than "Alive", the server and timestamp is written to another worksheet called "Log". </p>
<pre><code>Sub Countup()
Dim CountDown As Date
CountDown = Now + TimeValue("00:00:01")
Applicati... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T08:53:54.247",
"Id": "39019",
"Score": "1",
"body": "And what was your question again?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T15:27:47.813",
"Id": "39057",
"Score": "0",
"body": "... | [
{
"body": "<p>Using <code>Application.OnTime</code> is a <strong>very neat</strong> way of implementing your timer, but I have a hard time figuring out how \"<em>pings servers every 15 mins or so</em>\" translates to <code>Now + TimeValue(\"00:00:01\")</code>. Note that since VBA is single-threaded, <em>OnTime<... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T19:07:00.597",
"Id": "25189",
"Score": "7",
"Tags": [
"optimization",
"vba",
"timer",
"excel"
],
"Title": "How to make this ping test with timer more efficient?"
} | 25189 |
<p>I have a C# program that I would like to have reviewed. I am new to programming and want to know how it could be improved. It is a Windows Forms project that generates a PDF using the iTextSharp dll. I have tried to leave off the repetitive parts (multiple textboxes, etc) as well as the part that uses iTextSharp.... | [] | [
{
"body": "<ol>\n<li>Moving the states list to some sort of data store (could be a text / xml file, or database) is preferable; this way you won't have to re-compile if you want to use your application in countries other than the US. </li>\n<li>(A positive point) I see that <code>IsFileLocked</code> is copied ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T19:10:56.187",
"Id": "25190",
"Score": "3",
"Tags": [
"c#",
"beginner",
"winforms"
],
"Title": "Windows form that generates invoices"
} | 25190 |
<p>I have written an algorithm to find the largest palindrome under a given number, but I am sure my code loses efficiency by creating new arrays in every pass. I am currently learning about efficiency so I have the following question: Can anyone suggest a more efficient (faster) approach and explain why this approach ... | [] | [
{
"body": "<p>I'm sure there are other ways to improve it but here are a few quick points: </p>\n\n<ol>\n<li>Start from the end and work your way back, that way once you've found one palindrome you're done!</li>\n<li>You only have to check half of the digits for equality.</li>\n<li>We can shave off some time by... | {
"AcceptedAnswerId": "25196",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T20:34:16.463",
"Id": "25193",
"Score": "6",
"Tags": [
"c#",
"performance",
"palindrome"
],
"Title": "Largest Palindrome efficiency"
} | 25193 |
<p>This is my first attempt with a basic text adventure game, and I was wondering if there was a way to make it more efficient (or any other things I could add to make the game better). It isn't totally finished yet, but if there is a way to make it better, please post in the comments.</p>
<pre><code>#lets me use the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T22:07:47.220",
"Id": "39003",
"Score": "0",
"body": "`while True: ready = raw_input('y/n ')` : if I'm not wrong and if the indentation is not wrong, this would loop forever."
}
] | [
{
"body": "<p>A couple things. First of all, you should abstract the function that exits the game:</p>\n\n<pre><code>def exitGame():\n print 'That\\'s a shame...'\n print 'Exiting program in 5 seconds:'\n for i in range(5):\n time.sleep(1)\n print(i+1)\n sys.exit('Exiting Game...')\n</... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T20:46:55.353",
"Id": "25194",
"Score": "3",
"Tags": [
"python"
],
"Title": "Is there a better way to code this text adventure game?"
} | 25194 |
<p>**Note: I might put this on Code Golf too, but first I'd like to get this code reviewed.</p>
<p>So there's this programming contest my school will be holding soon, which is about solving problems in the shortest (writing) time possible. I want to participate, but I discovered that I suck with puzzles. So today I be... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T17:48:28.887",
"Id": "61237",
"Score": "1",
"body": "This question appears to be off-topic because it is about code golfing, that is not what we do here on code review."
}
] | [
{
"body": "<p>The book programming perls has one of the most clever implemenations to find the longest repeated substring. He sorts an array of pointers to the substrings. This would be the place that I would start for an implementation.</p>\n\n<pre><code>/* From 'Programming Pearls' by Jon Bentley */\n/* lon... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T20:58:13.120",
"Id": "25197",
"Score": "2",
"Tags": [
"c++",
"contest-problem"
],
"Title": "Largest sequence found in all strings"
} | 25197 |
<p>I'm currently working my way through the questions on Project Euler and I am on question 5. Is this the best possible solution? Any suggestions welcomed!</p>
<pre><code> List<int> divisors = new List<int>{ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
int n = 1;
while (true)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T21:32:18.423",
"Id": "38992",
"Score": "0",
"body": "Thanks for the suggestion. Do you know order would that would give?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T21:32:56.753",
"Id": "38994... | [
{
"body": "<p>The most optimal solution would be to calculate the <a href=\"http://en.wikipedia.org/wiki/Least_common_multiple\">LCM</a> of 1 to 20 directly using the standard <a href=\"http://en.wikipedia.org/wiki/Euclidean_algorithm\">Euclidean algorithm</a>.</p>\n\n<pre><code>// calculate GCD using Euclidean... | {
"AcceptedAnswerId": "25204",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T21:09:29.127",
"Id": "25200",
"Score": "5",
"Tags": [
"c#",
"project-euler"
],
"Title": "smallest number divisible by all numbers from 1 to 20? Project Euler question 5"
} | 25200 |
<p>The requirements:</p>
<ul>
<li>Work inside <strong>.htaccess</strong> (preferably via <code>mod_rewrite</code>)</li>
<li><strong>Redirect</strong> requests from <code>/any/directory/index.php</code> to <code>/any/directory/</code></li>
<li>Make sure that <code>/index.php-with-stupid-stuff-here</code> <strong>does n... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2020-04-30T16:32:38.433",
"Id": "473953",
"Score": "0",
"body": "Looking for nearly the exact same thing. Any success?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2020-05-11T20:21:37.170",
"Id": "475099",
"Scor... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-17T22:50:14.230",
"Id": "25205",
"Score": "3",
"Tags": [
"regex",
"file-system",
".htaccess"
],
"Title": "Automatically redirect /index.php files to their URL directory with .htacces... | 25205 |
<p>I've coded following two methods to combine images that are HTTP POSTed to the server:</p>
<pre><code>// Crops two squares out of two separate images
// And then combines them into single image that's returned as byte[]
private byte[] combineImages(HttpPostedFileBase[] itemPayload)
{
try
{
using (va... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T13:40:18.017",
"Id": "39044",
"Score": "2",
"body": "Instead of `return new byte[0]`, I'd have a class-level field `private static readonly byte[] emptyImage = new byte[0]` and then just `return emptyImage`. You may also want to do ... | [
{
"body": "<p>Expanding on my comment above, I'd also follow Microsoft's naming guidelines and have the method names be <code>PascalCase</code>d. Plus, I'm not a huge fan of mutable <code>structs</code>, preferring to initialize them via provided constructors. So I came up with the following:</p>\n\n<pre><code>... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T05:46:12.520",
"Id": "25211",
"Score": "2",
"Tags": [
"c#",
"asp.net",
"asp.net-mvc-4"
],
"Title": "Cropping and combining two images on server"
} | 25211 |
<p>Sometimes, I need to read two integer parameters in a single input line, separated by a whitespace.</p>
<p>I have these two functions that seem to do the job just fine:</p>
<pre><code>#include <iostream>
#include <sstream>
#include <deque>
// Splits a string by its whitespaces and returns a dequ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T09:03:57.387",
"Id": "39021",
"Score": "0",
"body": "If you're always reading two values from a line, consider using `std::pair` instead of `std::deque`. In fact, why do you even use `std::deque`? Use just `std::vector`, it's genera... | [
{
"body": "<p>I can think of two more ways of doing it.</p>\n\n<p><strong>1. Using iostream iterators</strong>. (Following code is from <a href=\"http://www.cplusplus.com/reference/iterator/istream_iterator/\" rel=\"nofollow\">here</a>)</p>\n\n<pre><code>#include <iostream>\n#include <iterator>\nusi... | {
"AcceptedAnswerId": "25216",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T07:13:57.050",
"Id": "25212",
"Score": "2",
"Tags": [
"c++"
],
"Title": "Input reading: two values (separated by whitespace) per line"
} | 25212 |
<p>I made a reference-counting smart pointer class. My aim is to make a "minimal" but "general purpose" smart pointer class with proper documentation. This is basically for educational purposes.</p>
<p>I would like to have comments regarding exception handling, code clarity, comments, ease of use of API, etc. And, als... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T08:40:45.383",
"Id": "39012",
"Score": "1",
"body": "I'm not sure... but it seems your copy operators don't handle self assignment (cf. Effective C++ item 11)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013... | [
{
"body": "<p>A few non-expert comments: </p>\n\n<ul>\n<li><p>I would prefer the private vars to be at the top of the class - to avoid the immediate need to scroll to the bottom.</p></li>\n<li><p>Is there and advantage in making <code>m_pRefCount</code> a pointer to <code>int</code> instead of a simple <code>in... | {
"AcceptedAnswerId": null,
"CommentCount": "15",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T08:21:23.893",
"Id": "25214",
"Score": "3",
"Tags": [
"c++",
"pointers"
],
"Title": "Reference-counting smart pointer class"
} | 25214 |
<p>I'm implementing a simple <a href="http://msdn.microsoft.com/en-us/library/65zzykke%28v=vs.80%29.aspx" rel="nofollow">iterator in C#</a> over an xml document, in order to process an xml document in as much a streaming manner as possible. For this reason, I'm using an <a href="http://msdn.microsoft.com/en-us/library/... | [] | [
{
"body": "<p>Could you do it with a boolean and short circuiting your while loop condition?</p>\n\n<pre><code>...\n var isElement = false;\n while (isElement || reader_.Read())\n {\n isElement = false;\n switch (reader_.NodeType)\n {\n case XmlNodeType.Element:\n ... | {
"AcceptedAnswerId": "25220",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T09:48:57.100",
"Id": "25217",
"Score": "2",
"Tags": [
"c#",
"iterator"
],
"Title": "How to remove goto statement from iterator"
} | 25217 |
<p>I've been writing a node.js web crawler, to get it running, I've found myself having to string together really rather a lot of different NPM modules.</p>
<p>I've done my best to keep the code DRY and well designed, but unfortunately, it's turned into a bit of a tangled mess, and in places I feel like I'm forced to ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T10:20:10.303",
"Id": "39025",
"Score": "2",
"body": "It seems to me there could be at least 3 different files: a data store, an analytics tester, and a crawler. I'm pretty sure the socket handling could be in another file too."
}
... | [
{
"body": "<p>Isaacs, node.js current maintainer, recently wrote node.js' philosophy in this blog post: <a href=\"http://blog.izs.me/post/48281998870/unix-philosophy-and-node-js\" rel=\"nofollow\">http://blog.izs.me/post/48281998870/unix-philosophy-and-node-js</a></p>\n\n<blockquote>\n <p>In Node, the basic bu... | {
"AcceptedAnswerId": "25265",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T10:09:42.550",
"Id": "25218",
"Score": "3",
"Tags": [
"javascript",
"node.js",
"web-scraping"
],
"Title": "Node.js web crawler"
} | 25218 |
<p>I wrote the following to create an animation which collapses a navigation bar, load new content for it and expands it again. Meanwhile, the rest of the page content fades out, loads and fades in again.</p>
<p>It works and looks good, and is even timed well. But my code is one hell of a mess. How could I have done b... | [] | [
{
"body": "<p>Here are some quite general pointers on your code. If you put up a fiddle with everything working, I might be able to play around and re-write this for you. But anyways, I've included my comments directly into the code to provide some context:</p>\n\n<pre><code>$(function() {//Is this what wraps y... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T12:40:23.277",
"Id": "25224",
"Score": "2",
"Tags": [
"javascript",
"performance",
"jquery",
"animation"
],
"Title": "Animation for collapsing/expanding a navigation bar"
} | 25224 |
<p>I have been attempting the questions at Project Euler and I am trying to find the sum of Primes under two million (question 10)</p>
<blockquote>
<p>The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.</p>
<p>Find the sum of all the primes below two million.</p>
</blockquote>
<p>Here is my attempt which does work, b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T14:37:49.160",
"Id": "39051",
"Score": "1",
"body": "just want to let you know - after you solve your project euler question . you can see the problem list and a PDF document in general a link to PDF document explains the best way t... | [
{
"body": "<p>One slight improvement you can do is </p>\n\n<p>All Prime numbers could be represented this format</p>\n\n<p>2,3,4,5 and</p>\n\n<p>6,7,8,9,10,11 or 12,13,14,15,16,17 or 18,19,20,21,22,23</p>\n\n<p>6k,6K+1 ,6k+2,6K+3,6k+4,6k+5</p>\n\n<p>so only prime number possible is </p>\n\n<p>6k+1 and 6k+5 </p>... | {
"AcceptedAnswerId": "25256",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T13:46:25.233",
"Id": "25225",
"Score": "4",
"Tags": [
"c#",
"primes",
"project-euler"
],
"Title": "Sum of primes less than 2,000,000"
} | 25225 |
<p>This is one of the slightly trickier Project Euler Questions I have seen (Question 27)</p>
<pre><code>Considering quadratics of the form:
n² + an + b, where |a| < 1000 and |b| < 1000
where |n| is the modulus/absolute value of n
e.g. |11| = 11 and |−4| = 4
Find the product of the coefficients, a and b, for ... | [] | [
{
"body": "<p>Pre-computing a large list containing numbers you may or may not use isn't always a good idea. I tested it and it turns out to be much slower. </p>\n\n<hr>\n\n<p>Things I would change about your code:</p>\n\n<ol>\n<li><p>I'd remove the classes, this is a trivial problem that can be solved with a f... | {
"AcceptedAnswerId": "25245",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T14:19:49.940",
"Id": "25227",
"Score": "4",
"Tags": [
"c#",
"primes",
"project-euler"
],
"Title": "Quadratic Primes"
} | 25227 |
<p>I'm totally hooked on CodeEval, and one of the problems on there caught my attention. Here it is, copied from <a href="https://www.codeeval.com/open_challenges/75/" rel="nofollow">here</a>:</p>
<p>Challenge Description:</p>
<p>Flavius Josephus was a famous Jewish historian of the first century, at the time of the ... | [] | [
{
"body": "<ol>\n<li><p>You can easily find the next death-index with the modulus operation: <code>next = (current + space) % totalStillAlive</code> . No need for fancy loops (see end of answer).</p></li>\n<li><p>Instead of making an array of arrays (btw, don't create js arrays with <code>new Array</code>, use ... | {
"AcceptedAnswerId": "25232",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T14:40:51.117",
"Id": "25230",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "The Josephus problem in JavaScript"
} | 25230 |
<p>I've developed my own class in ASP.NET project to access MySQL and make queries and scalars, and read the results from it.</p>
<p>I want you to review my class and tell me where I've made a mistake.</p>
<p>Here are some questions that are important for me:</p>
<ul>
<li>Do I use a reference correctly for the conne... | [] | [
{
"body": "<h2>Question #1</h2>\n\n<p>No. You do not need to ref the connection object in your methods' parameters - think object oriented way not class oriented.</p>\n\n<h2>Question #2</h2>\n\n<p>The only way is to make this as a non static class. Avoid always statics when the current problem contains some kin... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T15:04:16.617",
"Id": "25231",
"Score": "3",
"Tags": [
"c#",
"mysql",
"asp.net",
"classes"
],
"Title": "Accessing MySQL to make queries and scalars"
} | 25231 |
<p>I am trying to get a tuple of <code>date</code> (or <code>datetime</code>) objects over the last <code>N</code> months.</p>
<p>My thought was to use the <code>dateutil</code> package with something like this:</p>
<pre><code>def last_n_months(n=12, ending=None):
"""Return a list of tuples of the first/last day ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-09-20T01:50:57.113",
"Id": "119705",
"Score": "0",
"body": "Unless I'm missing something, you can probably adapt the itermonthdates() function from the calendar module in the python standard library:\nhttps://docs.python.org/2/library/cal... | [
{
"body": "<pre><code>def last_n_months(n=12, ending=None):\n \"\"\"Return a list of tuples of the first/last day of the month\n for the last N months \n \"\"\"\n from datetime import date\n from dateutil.rrule import rrule, MONTHLY\n from dateutil.relativedelta import relativedelta\n</code... | {
"AcceptedAnswerId": "25239",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T15:09:12.853",
"Id": "25233",
"Score": "2",
"Tags": [
"python",
"datetime"
],
"Title": "Get tuple of the first and last days of the last N months"
} | 25233 |
<p>I have a selector that pulls in all anchor tags that start with the <code>#</code> symbol. I am trying to add a <code>:not</code> selector of some form for elements that have a <code>data</code> attribute. I know I could do the following...</p>
<pre><code>$('a[href^="#"]:not([data-known])')
</code></pre>
<p>But th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T22:46:56.107",
"Id": "62780",
"Score": "0",
"body": "I think your best approach would be using [jQuery.hasData()](http://api.jquery.com/jQuery.hasData/) (even though you will still use an if statement)."
},
{
"ContentLicense... | [
{
"body": "<p>Very good question. I'm pretty sure this can't be done within the selector.</p>\n\n<p>However, instead of checking the <code>data</code> every time it's clicked, <code>filter</code> the collection before applying the event listener:</p>\n\n<pre class=\"lang-js prettyprint-override\"><code>$('a[hre... | {
"AcceptedAnswerId": "25243",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T21:42:16.057",
"Id": "25241",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"html5"
],
"Title": "Do not select elements that contain data attributes"
} | 25241 |
<p>I need to add quotes to each word in a string. Here is something that works but it looks ugly to me; </p>
<pre><code>"this is a test".split.to_s.delete("[],")
</code></pre>
<p>produces</p>
<pre><code>"\"this\" \"is\" \"a\" \"test\""
</code></pre>
<p>split adds the quotes, to_s turns the array back to a string, ... | [] | [
{
"body": "<p>Here's the \"naïve\" way to go</p>\n\n<pre><code>\"this is a test\".split.map { |word| \"\\\"#{word}\\\"\" }.join(\" \")\n</code></pre>\n\n<p>But a better way is to use a regular expression, since those are made specifically for string manipulation/substitution</p>\n\n<pre><code>\"this is a test\"... | {
"AcceptedAnswerId": "25246",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T22:41:52.697",
"Id": "25242",
"Score": "0",
"Tags": [
"ruby"
],
"Title": "Suggestions for Ruby string parsing"
} | 25242 |
<p>I wanted to store some dictionary data (key/value pairs of strings) in C, and decided to use a trie.</p>
<p>I found what looks like a good implementation <a href="http://simplestcodings.blogspot.com/2012/11/trie-implementation-in-c.html" rel="nofollow">here</a>, along with some nice notes.</p>
<p>In this implement... | [] | [
{
"body": "<p>If I look at the Wikipedia page on Trie, <a href=\"https://en.wikipedia.org/wiki/Trie\" rel=\"nofollow\">https://en.wikipedia.org/wiki/Trie</a> I see that each node has one parent and an arbitrary number of children; if the key is a char the limit would be 255 children (or maybe less if you restri... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T01:34:07.963",
"Id": "25248",
"Score": "1",
"Tags": [
"c",
"linked-list",
"hash-map",
"trie"
],
"Title": "Sorted trie implementation in C"
} | 25248 |
<p>It would be a huge help if you could tell me ways to make my code run smoother and if I could add more code to my program to make my program more unique.</p>
<p>Panelball class: </p>
<pre><code>import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class Panelball extends JPanel impleme... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T10:08:42.273",
"Id": "39171",
"Score": "1",
"body": "Especially on a site like *.stackexchange.com, where we're not reviewing code in a desktop IDE, I'd suggest removing extra newlines from your code, and indenting with a limited nu... | [
{
"body": "<p>\"Uniqueness\" should not be your goal (except you copied it completely from somebody else ;) ) In general you should aim for removing stuff and still let it work as expected and not adding unnecessary stuff. Do you have test, that is something you should add always?</p>\n\n<p>Some hints:</p>\n\n<... | {
"AcceptedAnswerId": "25255",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-04-19T02:42:20.520",
"Id": "25249",
"Score": "2",
"Tags": [
"java",
"strings",
"array",
"game",
"homework"
],
"Title": "High School Java Class: Pong Project External Reviewer... | 25249 |
<p>I have a repository abstract class that encapsulates pretty much all of the CRUD functionality:</p>
<pre><code>public abstract class DataRepository<T> : IRepository<T>
where T : class
{
public DataContext Context { get; private set; }
public TransactionScope Transaction { get; private set; }
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T19:38:23.513",
"Id": "39195",
"Score": "0",
"body": "Made `Delete(IEnumerable<T> items)` a virtual method in `RepositoryBase`, just like `Save(IEnumerable<T> items)` is."
}
] | [
{
"body": "<h2>Repositories for</h2>\n\n<ul>\n<li>Add objects</li>\n<li>Remove objects</li>\n<li>Query objects (no named queries like GetById)</li>\n</ul>\n\n<p>Repositories may not know about anything their context or transaction scope (and they can't be saved directly) these are different story which can be t... | {
"AcceptedAnswerId": "25252",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T02:57:38.547",
"Id": "25250",
"Score": "4",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Abstract repository implementation"
} | 25250 |
<p>I'm working on an algorithm to solve the <a href="http://en.wikipedia.org/wiki/24_Game" rel="nofollow">24-challenge game</a>. The basic idea is to combine positive integers using arithmetic operators to produce an expression that evaluates to exactly 24. For instance, <code>(9 - 3) * (2 + 2) = 24</code>. My current ... | [] | [
{
"body": "<pre><code> @SOLUTION = 24.0\n @MAX_SOLUTIONS = 10\n @TOLERANCE = 0.000001\n</code></pre>\n\n<p>I guess those uppercase names are used to denote constants, you can also use class constants for that.</p>\n\n<pre><code> # iterate over all unique permutations of given numbers\n @nums.perm... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T03:31:23.457",
"Id": "25251",
"Score": "2",
"Tags": [
"algorithm",
"ruby"
],
"Title": "General case of the 24-challenge problem"
} | 25251 |
<p>I have created a proof of concept jQuery based flow diagram based upon kayen's answer to <a href="https://stackoverflow.com/questions/7540149/click-through-yes-no-questions-from-opml-one-at-a-time">this post</a>.</p>
<p>This diagram shows the flow diagram that I am seeking to create in jQuery:</p>
<p><a href="http... | [] | [
{
"body": "<p>You can simplify the javascript to be something as given below by adding some properties to the markup.</p>\n\n<pre><code>jQuery(function () {\n\n jQuery('input:radio[name^=\"question\"]').change(function(){\n var $this = $(this);\n\n $this.closest('.question-container').hide();\n... | {
"AcceptedAnswerId": "25263",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-18T12:34:08.230",
"Id": "25262",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "jQuery-based flow diagram"
} | 25262 |
<p>My definition of monkey testing is basically playing with a program in as if I was a monkey (press every button, unplug things, go in the wrong order..etc etc)</p>
<p>So I made a rather simple SmartCard library that when I "enable" it it just polls the smart card reader for a card, and reports back information. see... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T21:21:39.807",
"Id": "39147",
"Score": "0",
"body": "I think I found the answer. It appears to be work. On the Disable instead of `readerThread.Suspend()` I change it to `readertThread.Join()`. Then I just check for the Unstarted fl... | [
{
"body": "<p>As requested by Ryan Gates I should post my results. I don't remember the entire scope of what i did, but I do know where the code is :)</p>\n\n<p>So the basics are that I want the thread to be able to exit without causing any strange hicups if the user decides to use my library incorrectly. So I ... | {
"AcceptedAnswerId": "27405",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T14:22:26.507",
"Id": "25266",
"Score": "5",
"Tags": [
"c#",
"multithreading",
"state"
],
"Title": "Monkey testing a SmartCard library"
} | 25266 |
<p>I'm writing a multithreaded game engine, and I'm wondering about best practices around waiting for threads. It occurs to me that there could be much better options out there than what I've implemented, so I'm wondering what you think.</p>
<ol>
<li><p><code>wait()</code> method gets called at the top of every other ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T18:14:59.207",
"Id": "63444",
"Score": "0",
"body": "Just use `std::future::get` if you really wanna wait."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-20T11:13:59.230",
"Id": "66510",
"Score"... | [
{
"body": "<blockquote>\n <p>I'm wondering about best practices around waiting for threads.</p>\n</blockquote>\n\n<p>That's too big a question. Instead I'll just review your existing code.</p>\n\n<blockquote>\n <p>This is my current implementation, and I'm realizing it's not ideal.</p>\n</blockquote>\n\n<p>Yo... | {
"AcceptedAnswerId": "39622",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T17:33:38.237",
"Id": "25269",
"Score": "10",
"Tags": [
"c++",
"multithreading"
],
"Title": "Thread-safe game engine: multi-threading best practices?"
} | 25269 |
<p>I am using a recursive algorithm to find all of the file-paths in a given directory: it returns a dictionary like this: <code>{'Tkinter.py': 'C:\Python27\Lib\lib-tk\Tkinter.py', ...}</code>.</p>
<p>I am using this in a script to open modules by solely given the name. Currently, the whole process (for everything in ... | [] | [
{
"body": "<pre><code>import os, os.path\ndef getDirs(path):\n</code></pre>\n\n<p>Python convention is to use <code>lowercase_with_underscores</code> for function names</p>\n\n<pre><code> sub = os.listdir(path)\n</code></pre>\n\n<p>Don't needlessly abbreviate, and at least have it be a plural name.</p>\n\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T20:52:06.053",
"Id": "25272",
"Score": "1",
"Tags": [
"python",
"optimization",
"recursion"
],
"Title": "Improve file-path finding method"
} | 25272 |
<p>I am working on an application that will use an N-Tiered approach. I would appreciate any feedback and advice on my architecture before I proceed any further.</p>
<p><strong>DataLayer (Class Library Project)</strong></p>
<p>Context.cs</p>
<pre><code>namespace TimeTracker.DataLayer
{
public class Context : Db... | [] | [
{
"body": "<p>I like your effort, there is a separation of responsibilities in what you present </p>\n\n<p>Here are my remarks:</p>\n\n<blockquote>\n <p>I am working on an application that will use an N-Tiered approach.</p>\n</blockquote>\n\n<p>While many people use the terms N-Tiered and N-Layered interchange... | {
"AcceptedAnswerId": "25668",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T21:27:26.083",
"Id": "25274",
"Score": "1",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Feedback and Advice on my N-Tier Application Architecture"
} | 25274 |
<p>I want to see if one of two values (a, b) are in an array. Here's my current thought:</p>
<pre><code>$match_array = array('a','b');
$array_under_test = array('b', 'd', 'f');
if (array_intersect($match_array, $array_under_test)) {
// Success!
}
</code></pre>
<p>Any better implementations?</p>
| [] | [
{
"body": "<p>If you want to verify that <em>either</em> value is in the <code>$array_under_test</code>, <code>array_intersect</code> may not be the best option. It will continue to test for collisions even after it finds a match. </p>\n\n<p>For two search strings you can just do:</p>\n\n<pre><code>if (in_array... | {
"AcceptedAnswerId": "25280",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T21:42:58.130",
"Id": "25276",
"Score": "3",
"Tags": [
"php",
"array"
],
"Title": "Best way to check for one of two values in an array in PHP"
} | 25276 |
<p>I have a list of plans and a list of contacts, and I have to check whether <code>contact.ProviderId</code> matches <code>plan.ProviderId</code>. If they match I need to store in a <code>contactUI</code> the <code>plan.Name</code>.</p>
<p>Provider to plan is a 0..1-to-many relationship, and that's why I couldn't use... | [] | [
{
"body": "<p>Once you've gotten your code into a <code>ILookup</code> you can just call <a href=\"http://msdn.microsoft.com/en-us/library/bb549314.aspx\" rel=\"nofollow\"><code>Item</code></a> property (which in C# is called with <code>[...]</code>) to get all values with a given key. So the <code>Check</code>... | {
"AcceptedAnswerId": "25278",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T21:47:41.310",
"Id": "25277",
"Score": "3",
"Tags": [
"c#",
"lookup"
],
"Title": "Tuple/Lookup conundrum"
} | 25277 |
<p>I had a code for a layout library which looked like :</p>
<pre><code>$this->layout->setLayout($layout)->setTitle($title)->render()
etc.
</code></pre>
<p>Today I started writing a new code, simpler and smaller :</p>
<pre><code>$this->layout->data(array(
'view_name' => 'layout_admin',
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T23:48:01.780",
"Id": "39154",
"Score": "0",
"body": "You should add more details, especially code of your layout class."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T00:21:45.237",
"Id": "39155"... | [
{
"body": "<p>The core of your question is whether or not you should use setters ($tpl->setSomeParam()) or a simple array to bind template parameters. While using an array my not seem very OO, it's actually a pretty effective way of decoupling your data from your templates. As you've discovered, having to add a... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T22:59:18.750",
"Id": "25281",
"Score": "4",
"Tags": [
"php",
"object-oriented"
],
"Title": "Best OOP method for a layout library"
} | 25281 |
<p><strong>Introduction</strong></p>
<p>I'm learning C++ (Coming from Haskell, C, and Assembly - and other languages sparsely) and this was my practice with classes and templates. It's a linked list that you can call in this fashion:</p>
<pre><code>#include "list.hpp"
int main(void){
linked_list<char> test;... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T10:43:54.937",
"Id": "39177",
"Score": "1",
"body": "In addition to Morwenn's answer, one suggestion is to keep the preprocessor *guards* named consistent with the class (`#ifndef LIST_H`). I'd recommend `#ifndef LINKED_LIST_H` if ... | [
{
"body": "<p>This won't be as complete an answer as you often see on Code Review, but here are a few pointers to improve your code:</p>\n\n<pre><code>template <typename T>\nT& linked_list<T>::operator[](int i){\n return (get_add(i)->data);\n}\n</code></pre>\n\n<p>First of all, you should ... | {
"AcceptedAnswerId": "25290",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T01:41:31.040",
"Id": "25283",
"Score": "7",
"Tags": [
"c++",
"object-oriented",
"c++11",
"linked-list",
"template"
],
"Title": "General advice on a practice linked_list... | 25283 |
<p><em>The Art and Science of Java</em>, a course book that uses the ACM library, has an exercise that reads like this:</p>
<blockquote>
<p>Implement a new class called Card that includes the following entries:</p>
<p>• Named constants for the four suits (CLUBS, DIAMONDS, HEARTS, SPADES)
and the four ranks th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T03:52:03.150",
"Id": "39158",
"Score": "1",
"body": "I would think that you did not do it right. I believe they are hinting at using a enum. Because your method accepts 2 integers you could put a suit into a rank and a rank into a s... | [
{
"body": "<h2>Enums</h2>\n\n<p>Java enums have been around for a long time, so it's really a waste <strong>not</strong> to be using them at this point.</p>\n\n<p><em>However</em>, I understand that this may simply be an <em>exercise</em>, to test and build your understanding of Java, one step at a time. If th... | {
"AcceptedAnswerId": "25291",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T02:15:42.947",
"Id": "25285",
"Score": "6",
"Tags": [
"java",
"optimization",
"classes",
"playing-cards"
],
"Title": "Playing Card Class - is this right?"
} | 25285 |
<p>I have <a href="http://bl.ocks.org/nkhine/3150901" rel="nofollow">this code</a> and would like to have it reviewed:</p>
<pre><code>function thisClient() {
"use strict"
var self = this
var width = 960,
height = 500,
centered, data
this.init = function () {
//now.receiveLocation = function(m... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>Because you have <code>use strict</code> on top in <code>function thisClient() {</code>, you do not need it within functions declared within <code>thisClient</code> like <code>this.fileExists</code></li>\n<li>I am all for Spartan coding but variable like <code>d<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T07:00:50.300",
"Id": "25289",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"svg",
"d3.js"
],
"Title": "D3.js zoomable map"
} | 25289 |
<p>I've written a simple numeric menu which displays in the console. When the user types in '1', something happens. When the user hits ENTER, I clear the whole output except for the menu itself. When the user types in '5', the program ends.</p>
<p>However, the code got ugly. It's full of <code>cin.get()</code>s, <cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T19:05:17.497",
"Id": "39188",
"Score": "0",
"body": "Have you compiled this code yourself before? I'm doing it now, and it already says that node is undeclared (obvious when just looking at it, too). Also, why is `using namespace ... | [
{
"body": "<ul>\n<li><p><strong><a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\"><code>Using namespace std</code></a></strong>: I've already mentioned this in the comments. Although it's not a huge deal for small programs such as this, it's still not a ... | {
"AcceptedAnswerId": "25294",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T18:39:24.157",
"Id": "25293",
"Score": "4",
"Tags": [
"c++",
"console"
],
"Title": "Input stream for console menu"
} | 25293 |
<p>This is my first COBOL program, and I'd like to get a critique as I am unfamiliar with best practices.</p>
<p>Particularly, I'd like to know how to get the input and output to be more elegant and less dependent on how the file fields are structured.</p>
<p>Some type of analogy to C's <code>scanf()</code>, <code>ge... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T21:27:45.780",
"Id": "39200",
"Score": "3",
"body": "Might be nice for privileged user to create a COBOL tag."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T21:06:17.377",
"Id": "58466",
"Sco... | [
{
"body": "<p>While the code is crisp and clean (COBOL always is .... ;-) ) I see some logic flaws in your computations.</p>\n\n<p>Specifically, consider the current time <code>14450000</code> (2:45pm) and the user enters <code>15</code> for [HH] and <code>15</code> for [MM] as his ETA (3:15pm)</p>\n\n<p>Your s... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T20:08:11.767",
"Id": "25295",
"Score": "22",
"Tags": [
"beginner",
"datetime",
"cobol"
],
"Title": "Current and estimated arrival times"
} | 25295 |
<p>I have a block of code that pulls the current menu position and compares it to what users selected, if the selection is different the database is updated with the new selection. As I am still new with EF I was hoping for a general code review for suggestions on a possible better, more efficient, and/or easier way to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T23:12:44.703",
"Id": "39206",
"Score": "2",
"body": "Let me throw something at you: why only save if there is a difference? Why not just save anyway? Unless you have database congestion (table locking etc) then a database access is ... | [
{
"body": "<p>As @dreza mentioned, you might want to move the code around your LINQ-Statements to a method.</p>\n\n<pre><code>public void changeCategoryTo(String newCategory){\n var record = (from n in db.Navigation where n.Category == newCategory\n && n.SectionId == SectionID select... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-19T23:01:44.260",
"Id": "25299",
"Score": "5",
"Tags": [
"c#",
"asp.net"
],
"Title": "Sugestion on a better way to code this EF update?"
} | 25299 |
<p>I just finished a program that is a simple Swing GUI. It takes in user info, such as password and username, turns them into strings, and puts them in a text file called nuserInfo.txt.</p>
<p>I just want corrections on how the code works and what I can do to improve my saving, GUI, and code in general. I'll post all... | [] | [
{
"body": "<ul>\n<li><p>I put your Swing components on the Event Dispatch thread (EDT) in the main method.</p></li>\n<li><p>I rearranged your Swing component definitions in the go method to group like things together. I made sure that the JFrame setVisible method was the last method called in the go method. I... | {
"AcceptedAnswerId": "25383",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T01:44:04.407",
"Id": "25300",
"Score": "3",
"Tags": [
"java",
"swing",
"gui",
"user-interface"
],
"Title": "Account-creation program"
} | 25300 |
<p>Which version is more efficient in calculating the square root ? </p>
<p>There are 2 versions I have written to calculate square root programatically. Note reqs strictly state not using library functions ? </p>
<p>This is puzzling, the first method takes one extra iteration over the 2nd one but returns the more ac... | [] | [
{
"body": "<p>In version 1, you are testing the difference of the square is within 0.001. </p>\n\n<p>The square root of 9.001 is 3.000167 </p>\n\n<p>In version 2, you are testing the difference of the square root part. When you square it, the error becomes bigger.</p>\n\n<p>The square of 3.001 is 9.006001</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T03:37:42.653",
"Id": "25301",
"Score": "3",
"Tags": [
"java",
"comparative-review",
"numerical-methods"
],
"Title": "Square root approximations, implemented two ways"
} | 25301 |
<p>I want to move this to a class that will open an sqlite connection that can be re-used, rather than disposing of it every time I write to the database. Furthermore I am more than happy for any best practices from sqlite users! I am aware of a similar thread and am trying to absorb it:</p>
<p><a href="https://codere... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T20:02:41.897",
"Id": "39227",
"Score": "0",
"body": "First suggestion is for `public int fileExists` you are returning an int that has meaning to it. It would be better to make a enum with those values so that there is a name attach... | [
{
"body": "<p>Just a few comments:</p>\n\n<ol>\n<li>Try to use the 'using' construct for SQLiteTransaction, SQLiteCommand and SQLConnection objects everywhere, not just in selected places. Get rid of explicit calls to Dispose() method. Also there is a connection string parameter 'Pooling=true', which tells driv... | {
"AcceptedAnswerId": "25311",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T06:50:28.883",
"Id": "25304",
"Score": "2",
"Tags": [
"c#",
"beginner",
"sqlite"
],
"Title": "Working with sqlite and moving functions to class"
} | 25304 |
<p>The code below is equivalent. I can see pros and cons for both versions. Which is better: the short, clever way, or the long, <kbd>ctrl</kbd>+<kbd>c</kbd> way?</p>
<p>Short version:</p>
<pre><code>character.on("key",function(key){
var action = ({
"a":{axis:"x",direction:-1},
"d":{axis:"... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T17:09:58.663",
"Id": "39212",
"Score": "0",
"body": "I don't see how the long version is better."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T17:26:43.297",
"Id": "39213",
"Score": "0",
... | [
{
"body": "<p>The short code wins hands down. I understood it <em>immediately</em>, and more importantly, I can trivially verify that the code is reasonably error free. This is <em>much</em> harder with the longer code.</p>\n\n<p>You say that the longer code is easier to understand but I claim that this is <em>... | {
"AcceptedAnswerId": "25309",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T17:03:39.890",
"Id": "25308",
"Score": "5",
"Tags": [
"javascript",
"game",
"comparative-review",
"event-handling"
],
"Title": "Two keyboard handlers for a video game char... | 25308 |
<p>I would like to re-write this C# code so it is easier to understand. Should I create a separate function to configure a menu item? Is there is some kind of <code>using</code> statement so I only need to mention the menu name once?</p>
<pre><code>private void initializeContextMenuRightClick()
{
try
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T20:42:54.230",
"Id": "39228",
"Score": "2",
"body": "Do you need the intermediate tool menu variables? Could you not just use ctxMenuStripRightClick.Items.Add(new ToolStripMenuItem(\"Add\", null, AddMenuItem_Click)) etc"
},
{
... | [
{
"body": "<blockquote>\n <p>Is there a way I can avoid repeatedly mentioning\n ctxMenuStripRightClick.</p>\n</blockquote>\n\n<p>Yes, I guess you could do something like:</p>\n\n<pre><code>ctxMenuStripRightClick = new ContextMenuStrip();\nctxMenuStripRightClick.Opening += ctxMenuStrip_Opening;\nctxMenuStripRi... | {
"AcceptedAnswerId": "25317",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T20:31:18.310",
"Id": "25310",
"Score": "1",
"Tags": [
"c#",
"winforms",
"crud"
],
"Title": "CRUD menu creation"
} | 25310 |
<p>I've found a <a href="https://stackoverflow.com/a/5158227/435460">good example of how to do this in Java</a> and <a href="https://stackoverflow.com/a/838985/435460">how you can get the same behavior in c#</a>, so I've made made an attempt at it:</p>
<pre><code>public class CircularReferenceOne
{
public int Iden... | [] | [
{
"body": "<p>You should never use hash codes like this, because they are not unique. Two different objects can have the same hash code and when that happens, your algorithm breaks down. Instead you should use <a href=\"https://stackoverflow.com/a/1890230/41071\">an implementation of <code>IEqualityComparer</co... | {
"AcceptedAnswerId": "25316",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T23:20:50.673",
"Id": "25314",
"Score": "0",
"Tags": [
"c#",
"algorithm"
],
"Title": "Deep copying objects with circular references"
} | 25314 |
<p>Given two integers, <code>X</code> and <code>Y</code>, you must create all possible integer sequences of length <code>Y</code> using the numbers from 1 to <code>X</code>.</p>
<p>For certain reasons, the function must return a <code>deque<deque<int> ></code> representing such (the primary <code>deque</co... | [] | [
{
"body": "<p>I don't have time to do a style review at the moment, so until I can expand on this later, I'll just suggest a different algorithm.</p>\n\n<hr>\n\n<p>Rather than depending on string manipulation and generating more items than you need, just take an arithmetic approach.</p>\n\n<p>In particular, you... | {
"AcceptedAnswerId": "25320",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-21T23:43:58.627",
"Id": "25315",
"Score": "5",
"Tags": [
"c++"
],
"Title": "All integer sequences given amount of integers and length of sequence"
} | 25315 |
<p>I really hate messy code, but I seem to be rolling in it. I just want to see if anyone has some helpful advice on how to tidy this up.</p>
<pre><code><table>
<tbody>
<tr>
<th>Zona</th>
<th>Baptismos Mulheres</th>
<th>Conf. Mulheres</th>
<th>Batismos Homems... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T05:34:09.207",
"Id": "39242",
"Score": "0",
"body": "I'm not familiar with PDO but can't you divide your PHP code into functions and put them in one file. You can then call them as necessary. It would also be a good idea to use temp... | [
{
"body": "<p>WKS is right, first of all you should split your layout from your logic and your logic from your database query. (see Model-View-Controller-Pattern)</p>\n\n<p>Lets start with your model (Model.php): (actually you could split it in a model for each entity/database table)</p>\n\n<pre><code><?php\... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T01:12:00.973",
"Id": "25318",
"Score": "1",
"Tags": [
"php",
"mysql",
"html",
"pdo"
],
"Title": "Assist cleaning up messy HTML/PHP code"
} | 25318 |
<p>Sometimes I need an <code>NSDictionary</code>-like object that maps a few integers (non-negative) to objects. At first glance, <code>NSMutableArray</code> is great for this, provided that the indexes aren't too high so I came up with <a href="http://cutecoder.org/programming/behold-holy-array/" rel="nofollow">a quic... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T04:59:12.520",
"Id": "39239",
"Score": "0",
"body": "Can you clarify what your motivation is? Are you wanting to optimize for lookup speed, at the expense of memory usage? Something else?"
},
{
"ContentLicense": "CC BY-SA ... | [
{
"body": "<p>I would write a custom class that uses an <code>NSMutableDictionary</code> internally, boxing the indexes into <code>NSNumber</code> keys.</p>\n\n<p>Depending on your particular use case it’s probably going to be both faster and more memory efficient than stuffing the unused array items with <code... | {
"AcceptedAnswerId": "25348",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T02:29:03.213",
"Id": "25321",
"Score": "4",
"Tags": [
"objective-c",
"category"
],
"Title": "Simple yet efficient integer-to-object dictionaries?"
} | 25321 |
<p>I am creating a web application for an enterprise and I would like to improve my way of coding, know what I do wrong and what I do well. I'll leave the main class' code here:</p>
<pre><code>package com.puntobile;
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntax... | [] | [
{
"body": "<p>Some comments: (I bet other reviewers can find more)</p>\n\n<p><strong>Private and final</strong></p>\n\n<p>As much as possible, fields should be marked with <code>private</code> and <code>final</code>. One of these fields is <code>signs</code>. There are several others that have the \"default\" v... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T07:28:13.250",
"Id": "25326",
"Score": "2",
"Tags": [
"java"
],
"Title": "Vaadin web application"
} | 25326 |
<p>I have a Drupal site with roughly the following in my template.php <a href="http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_init/7" rel="nofollow">hook_init</a> block:</p>
<pre><code>function mytemplate_init() {
if (request_path() == "widgets_json") {
drupal_json_output(_get... | [] | [
{
"body": "<p>From what I see, you could use two different methods: Ternaries and <code>switch</code>es:</p>\n\n<hr>\n\n<p>From a <code>switch</code> point of view, you could use the following to proceed:</p>\n\n<pre><code>function mytemplate_init() {\n switch(request_path()) {\n case \"widgets_json\":... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T08:09:00.103",
"Id": "25328",
"Score": "3",
"Tags": [
"php",
"drupal"
],
"Title": "Dumping output from template_init()"
} | 25328 |
<p>I have a few big arrays stored in separate files that are included into PHP as and when they are required:</p>
<p>Array File:</p>
<pre><code><?php
$cty_arr["af"] = "Afghanistan";
$cty_arr["ax"] = "Åland Islands";
$cty_arr["al"] = "Albania";
$cty_arr["dz"] = "Algeria";
$cty_arr["as"] = "American Samoa";
...... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T09:53:17.853",
"Id": "39259",
"Score": "0",
"body": "Slightly related to [PHP parse_ini_file() performance?](http://stackoverflow.com/questions/2120401/php-parse-ini-file-performance)"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>I thought about this again. My comments are still valid, so <a href=\"https://stackoverflow.com/questions/2120401/php-parse-ini-file-performance\">including it in a php file</a> is the cheapest way to get the array into your system and without a <a href=\"http://php.net/manual/en/book.memcache.php... | {
"AcceptedAnswerId": "25331",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T09:36:57.087",
"Id": "25330",
"Score": "3",
"Tags": [
"php",
"memory-management"
],
"Title": "What is the most memory efficient way to load big arrays into PHP script?"
} | 25330 |
<p>Here's the problem statement:</p>
<blockquote>
<p>Given an integer value, print out Pascal's Triangle to the
corresponding depth in row-major format:</p>
<p><strong>Input Sample:</strong></p>
<pre><code>6
</code></pre>
<p><strong>Output Sample:</strong></p>
<pre><code>1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T14:16:51.447",
"Id": "39270",
"Score": "0",
"body": "Typically, recursive functions should not have side effects. This means you should not be mutating a variable getting passed down through the stack. It should be returned instea... | [
{
"body": "<p>I have <a href=\"http://jsfiddle.net/N3bfw/1/\" rel=\"nofollow\">this implementation</a> right off the top of my head and it doesn't use recursion. It's a plain loop that creates the current row with the previous row.</p>\n\n<p>Here's the <a href=\"http://jsperf.com/pascal-s-triangle#run\" rel=\"n... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T13:36:58.650",
"Id": "25333",
"Score": "4",
"Tags": [
"javascript",
"recursion"
],
"Title": "Printing out Pascal's Triangle in row-major format"
} | 25333 |
<p>Within our project we've used a lot of <code>boolean setOutputValue(char pinNumber, boolean pinValue)</code> kind of functions.</p>
<p>Within those functions we do the following (for example):</p>
<p>hardware_layer:</p>
<pre><code>#define L9823_HIGH 0
#define L9823_LOW 1
void hardware_L9823_setOutput(U8BIT pin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T14:01:32.207",
"Id": "39269",
"Score": "0",
"body": "`void aModuleSetValue(boolean lowHigh) { setOutputValue(PINBELONGINGTOTHISMODULE, lowHigh); }` would be a starting point."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Crea... | [
{
"body": "<p>This would be better if you could post a real extract of the four layers and the real proposed C replacement code rather than pseudocode. </p>\n\n<p>But you might also consider why software four levels up from the hardware even knows about the names of registers and the polarity of signals at pin... | {
"AcceptedAnswerId": "25339",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T13:39:44.487",
"Id": "25334",
"Score": "2",
"Tags": [
"c"
],
"Title": "One function two functionalities or two functions each with one functionality"
} | 25334 |
<p>I was given a simple requirement for reversing a string. The requirement is as follows: </p>
<p>In any programming language, create an input that accepts "My name is Albert McDonald." and outputs the reversed value "Ym eman si Trebla DlAnodcm."</p>
<p>I got it to work like this:</p>
<pre><code>string expectedInpu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T14:38:45.860",
"Id": "39276",
"Score": "1",
"body": "So, each word is reversed separately? How exactly is a ”word” defined? For example, should `123` considered as a word? What about `?!`?"
}
] | [
{
"body": "<p>If you aim for fewer lines of code, you could of course put everything into a single line, but that would not helpful at all. </p>\n\n<p>However, you could shorten your code a bit by using a simple regular expression and some linq-fu, something like:</p>\n\n<pre><code>var s = yourInputString;\n\n/... | {
"AcceptedAnswerId": "25338",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T14:14:25.173",
"Id": "25335",
"Score": "6",
"Tags": [
"c#",
"performance",
"strings"
],
"Title": "Reversing each word of a string while keeping the case index"
} | 25335 |
<p>I'm writing a multi-threaded queue implemented with pthreads. Since I came up with the code based on several tutorials from Internet, I would like to make sure there are no logic errors in my code:</p>
<pre><code>template <typename T>
class ThreadQueue {
public:
ThreadQueue() {
pthread_mutex_init(... | [] | [
{
"body": "<p>The <code>pthread_cond_signal</code> should be done with the mutex locked. And a broadcast might be preferable to a signal.</p>\n\n<p>I'd put the private variables at the start of the class and braces on the <code>if</code> statements, even though they are of only one line.</p>\n",
"comments":... | {
"AcceptedAnswerId": "25482",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T16:03:02.150",
"Id": "25342",
"Score": "2",
"Tags": [
"c++",
"queue",
"pthreads"
],
"Title": "Concurrent queue with pthread implementation"
} | 25342 |
<p>Is there a design pattern I can use for a situation like below. This is an example I made up to try and explain the situation I'm dealing with currently. I keep having to add new DeviceScript classes to my DeviceAnalyzer as situation come up and adding logic about when to return the new type in the 'GetScriptForDe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T17:31:14.790",
"Id": "39284",
"Score": "0",
"body": "Use indirection like an XML config file (such as app settings) that can store mapping between a key and a class name. Ultimately I see no logic (e.g. code that does something) in ... | [
{
"body": "<p>I would suggest something like that</p>\n\n<pre><code>public interface IDeviceScript\n{\n string Name { get; }\n string SecurityScriptName { get; }\n string BusinessScriptName { get; }\n bool IsScriptApply(IDevice device);\n}\n\npublic interface IDevice\n{\n Locations Location { get... | {
"AcceptedAnswerId": "25352",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T17:03:57.597",
"Id": "25345",
"Score": "3",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Design Pattern Question/Violating OCP"
} | 25345 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.