body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I'm having some issues understanding why PDO is 6X slower executing a query than the depreciated MySQL query function. Here's my code:</p>
<pre><code>$conn = new PDO('mysql:host=localhost;dbname=work', 'root', 'Montreal');
protected function query_s($table, $col = '*', $where_col , $where, $return_col)
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T19:26:09.550",
"Id": "41192",
"Score": "0",
"body": "Take a look at the Database class here: http://codereview.stackexchange.com/questions/26507/generic-method-for-database-calls"
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>Change your connection string from host=localhost to host=127.0.0.1, for some reason PDO is slow at resolving the host name, just when using PDO always use the IP address of the server.</p>\n\n<p>Also why are you fetching one row at a time when you need 50?</p>\n",
"comments": [],
"meta_da... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T18:01:20.003",
"Id": "26581",
"Score": "2",
"Tags": [
"php",
"mysql",
"pdo"
],
"Title": "MySQL vs PDO execution time"
} | 26581 |
<p>I have the <code>List</code> method that takes sorting parameter to sort results. The sorting parameter value is the same as the column name.</p>
<pre><code>public ActionResult List(string sorting = "Name", string sortingMethod = "ASC")
{
var productList = productRepository.Get();
if(!String.IsNullOrEmpty... | [] | [
{
"body": "<p>What about seperating your sorting from your criteria? I'm like you, I'm sure there is another way so am interested to see other opinions. I'm not exactly sure if this would scale for multiple orderBys either but I think it might (NOTE: this code is untested and some types are not defined)</p>\n... | {
"AcceptedAnswerId": "26586",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T19:03:41.460",
"Id": "26584",
"Score": "1",
"Tags": [
"c#",
"asp.net",
"sorting"
],
"Title": "Lamba sorting for results"
} | 26584 |
<p>I implemented sleepsort in Go. I am new to channels, and I'd like to get some advice on them, especially on how to close channels after N messages have been sent on them. Currently I use a counter and an if statement (see the second for loop in <code>Sleepsort</code>), but maybe this can be done in a nicer way?</p>
... | [] | [
{
"body": "<p>I'm self-answering since I found a nicer way to do this.</p>\n\n<p>In this case, you can loop from 0 to N and receive from the channel manually, rather than using <code>range</code>.</p>\n\n<pre><code>for i := 0; i < len(xs); i++ {\n result[i] = <-channel\n}\nclose(channel)\n</code></pre>... | {
"AcceptedAnswerId": "26588",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T21:10:08.660",
"Id": "26587",
"Score": "4",
"Tags": [
"go",
"concurrency"
],
"Title": "Sleepsort in Go"
} | 26587 |
<p>I got this class in C# which works fine. But I was wondering if there was a more elegant solution to what I am trying to do. It looks rather clumsy and inefficient for a Logging functionality.</p>
<p>The code should be fairly self-explanatory.</p>
<pre><code>public static class Log
{
public static string Engin... | [] | [
{
"body": "<p>C# is not my main language, so I apologize for any mistakes that may exist in the following code.</p>\n\n<hr>\n\n<p>There is quite a bit of duplication in this class. It seems like <code>LogMessage()</code>, <code>EngineMessage()</code> and <code>ExceptionMessage()</code> could all delegate to <co... | {
"AcceptedAnswerId": "26593",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T22:55:25.390",
"Id": "26590",
"Score": "4",
"Tags": [
"c#",
"logging"
],
"Title": "More Elegant Solution to Logging Class"
} | 26590 |
<p>I am writing a game like Pong. Therefore I am using an entity system approach, so I use a Component-based design.</p>
<p>The hardest part until now was to write the collision system. As I just began with the component based design I am sometimes very unsure how to do something with this approach. With a "normal" OO... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T23:00:10.563",
"Id": "26591",
"Score": "4",
"Tags": [
"performance",
"collision",
"graphics",
"entity-component-system",
"basic-lang"
],
"Title": "Collision system in Pong... | 26591 |
<p>I am trying to calculate work progress in percentage. I have multiple batches, and each batch contains a set of tasks and each task also contains a set of sub tasks. Below code is the best I could do. Is there any more efficient way to do this?</p>
<p>I just edited the code using the Math static method to do hel... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T12:03:28.533",
"Id": "41269",
"Score": "2",
"body": "What if different batches have a different number of tasks? What if different tasks have a different number of subtasks? Or is that not an issue for what you're looking for?"
}
... | [
{
"body": "<ol>\n<li><pre><code>System.out.println(\"\\t\\tSub Task \" + k + \" from \" + Math.floor(fromSubTaskWeight) + \"% to \"\n + Math.floor(toSubTaskWeight) + \"%\");\n</code></pre>\n\n<p>I'd use <code>System.out.format</code> here, it's easier to read than string concatenation:</p>\n\n<pre><code>Syst... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T23:43:19.263",
"Id": "26592",
"Score": "4",
"Tags": [
"java",
"performance"
],
"Title": "Calculate work progress in percentage of batches that contain tasks and task contain sub tasks... | 26592 |
<p>I've been developing a simple console application in C++ using the <a href="http://www.grinninglizard.com/tinyxml2/">TinyXML2</a> library, and I honestly can't help but feel what I'm doing is not very robust. Maybe that's just the nature of parsing XML (this is my first foray into the topic, so I've no idea.)</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T14:11:43.537",
"Id": "41237",
"Score": "2",
"body": "I'm not familiar with TinyXML2, but have you considered [pugixml](http://pugixml.org/)?\nFrom its tutorial it doesn't seem to use a lot of pointers (and thus seems significantly l... | [
{
"body": "<p>In your code I do agree there more redundancy than I like to see. I would suggest writing some helper functions, and perhaps leveraging exceptions instead of return codes (I won't show that here).</p>\n\n<pre><code>const char* FirstChildElementText(tinyxml2::XMLElement *parent, const char *child_n... | {
"AcceptedAnswerId": "35507",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T07:34:23.190",
"Id": "26598",
"Score": "7",
"Tags": [
"c++",
"c++11",
"parsing",
"xml",
"console"
],
"Title": "Rigidness and verbose nature of XML parsing"
} | 26598 |
<p>This is a simple but complete console application where I experiment with genetic algorithm to try to figure out the best way to construct a battle mech that would win in a simple turn-based combat. </p>
<p>I welcome your criticism and pointers about what I could improve in the code above: architecture-wise, techni... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T13:36:29.473",
"Id": "41232",
"Score": "0",
"body": "Instead of coded return values, I'd consider using an enumeration for clarity: http://en.cppreference.com/w/cpp/language/enum\n\n// A good rule of thumb is that if you have to doc... | [
{
"body": "<p>Here's a summary of my comments in the answer format:</p>\n\n<ul>\n<li><p>Instead of coded return values, I'd consider using an enumeration for clarity: <a href=\"http://en.cppreference.com/w/cpp/language/enum\" rel=\"nofollow noreferrer\">http://en.cppreference.com/w/cpp/language/enum</a><br>\n//... | {
"AcceptedAnswerId": "26610",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T10:42:25.253",
"Id": "26600",
"Score": "5",
"Tags": [
"c++"
],
"Title": "'Genetic algorithm' implementation for constructing a battle mech"
} | 26600 |
<p>I have three tables for a blog system.</p>
<p>The blog</p>
<pre><code>CREATE TABLE IF NOT EXISTS lm_blog(
blog_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(80) NOT NULL UNIQUE,
action VARCHAR(80) NOT NULL UNIQUE INDEX,
url VARCHAR(80) NOT NULL UNIQUE,
summary VARCH... | [] | [
{
"body": "<p>Using a like with a leading wild card will likely be very slow as no indexes can be used. As such they should be avoided, which should be easy to do when the string you are checking it a concatenation of values from a table.</p>\n\n<p>I would suggest you do another join from the blog table to the ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T11:33:57.897",
"Id": "26601",
"Score": "2",
"Tags": [
"sql",
"mysql"
],
"Title": "Blog & Blog Tags SQL Statements"
} | 26601 |
<p>I have this version of John Conway's Game Of Life in Java:</p>
<p><code>Frame</code> class:</p>
<pre><code>import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JBut... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T07:47:22.710",
"Id": "41266",
"Score": "1",
"body": "That's a good start. To bump up performance a bit, rather than creating a new board for every time you create the next generation, you should instead create two boards. One will r... | [
{
"body": "<p>I am not a Java pro, so not everything I say now must be correct, but here is my review:</p>\n\n<p>First of all: \nYou did a good job when it comes to encapsulating. Nearly all of your methods are just a few lines, so every method really only does what it is supposed to do.\nFurthermore, your code... | {
"AcceptedAnswerId": "26623",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T13:39:10.760",
"Id": "26602",
"Score": "2",
"Tags": [
"java",
"swing",
"game-of-life",
"awt"
],
"Title": "Game Of Life 3 in Java"
} | 26602 |
<p>I have been playing with event driven javascript lately, and have wondered if it's a good/bad thing for objects listening for their own events as a way of abstracting and simplifying internal logic.</p>
<p>Consider the following:</p>
<pre><code>function MyModule(options) {
this.options = options;
this.data... | [] | [
{
"body": "<p>You could do this, but it's not really useful.</p>\n\n<p>This code is just easier to read:</p>\n\n<pre><code>MyModule.prototype.updateBasket = function() {\n var self = this,\n url = this.options.url;\n\n $.ajax(url)\n .done(this.done)\n .fail(this.fail)\n .compl... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T13:58:56.497",
"Id": "26603",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Javascript objects listening to their own events"
} | 26603 |
<p>I want to separate the code inside my <code>Add button click event</code> from the code in order to make my code looks more arranged.
this is my code before these changes (i am using BackgroundWorker in order to avoid my GUI to freeze because every file that I am choosing need to open process and check if this is fi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T21:07:50.817",
"Id": "41254",
"Score": "0",
"body": "show us `Editcap.isLibpcapFormat`. Also looks like you might want to make it static."
}
] | [
{
"body": "<p>well in part it helps, but you need to keep taking it a bit further. Think of it as a building blocks. Button_Click is the top most level and should be readable like a book. have the method state its intent. maybe this might have been a better idea</p>\n\n<pre><code>private void btnaddfiles_click(... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T17:08:29.003",
"Id": "26607",
"Score": "0",
"Tags": [
"c#",
"winforms"
],
"Title": "Is it necessary to move OpenFileDialog code for opening the files and put it into a separate method... | 26607 |
<p>I'll keep this short. I've never actually done professional C++. I don't really know any of the 'best practices'. I'd like to get some review on a simple class that I've made.</p>
<p>My Vector2d.h file:</p>
<pre><code>#ifndef VECTOR2D_H
#define VECTOR2D_H
#include <cfloat>
#include <climits>
/*The Ve... | [] | [
{
"body": "<h2>Disclaimer</h2>\n\n<p>I will mostly not critique what your class is doing, but mainly suggest how to make your interface as natural as possible (<strong>do as the ints do</strong>) by <a href=\"https://stackoverflow.com/questions/4421706/operator-overloading\">operator overloading best practices<... | {
"AcceptedAnswerId": "27112",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T17:34:20.963",
"Id": "26608",
"Score": "8",
"Tags": [
"c++",
"classes",
"interface",
"operator-overloading"
],
"Title": "Review of 2d Vector class"
} | 26608 |
<p>In my Rails 4 app i used to have every view contain a content_for :nav tag which included all of the links for the nav bar in my layout. This was getting annoying because if i wanted to add a button i would have to go through every view and add that link. I decide to make a partial view in layouts/_nav.haml which co... | [] | [
{
"body": "<p>You could create another helper to create your navigation links:</p>\n\n<pre><code>def navigation_link_to(text, path)\n link_to text, path, class: \"btn #{active_page(path)}\"\nend \n</code></pre>\n\n<p>Then in your view:</p>\n\n<pre><code>= navigation_link_to 'Home', root_path\n= navigation_link... | {
"AcceptedAnswerId": "26614",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-25T19:04:18.097",
"Id": "26612",
"Score": "3",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "DRY up Rails Navigation Code"
} | 26612 |
<p>I'm reading on design patterns for a software engineering class. I am doing small implementations of some I find the most interesting / applicable to better understand them.</p>
<p>I'd like a code review on my design, more particularly on the degree of coupling between my Observer and Publisher classes. I feel that... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T04:28:05.030",
"Id": "41262",
"Score": "0",
"body": "Don't have time to go into a lot of detail at the moment, but both your classes should have `virtual` destructors. Also, ownership semantics are somewhat unclear here."
}
] | [
{
"body": "<p>Don't pass by pointer. There is no ownership associated with it (and it can be NULL and thus you need to test for that).</p>\n\n<pre><code>class Publisher {\n\n // Is the publisher taking ownership of the observer?\n void add_observer(Observer*);\n</code></pre>\n\n<p>Is your class taking own... | {
"AcceptedAnswerId": "26677",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T02:58:46.213",
"Id": "26617",
"Score": "3",
"Tags": [
"c++",
"design-patterns"
],
"Title": "Very simple implementation of observer pattern in C++"
} | 26617 |
<p>I know this dining philosophers problem has been researched a lot and there are resources everywhere. But I wrote simple code to solve this problem with C and then turned to the Internet to see if it's correct. I wrote this with mutexes only and almost all implementations on the Internet use a semaphore. Now I'm not... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T08:45:11.077",
"Id": "79535",
"Score": "0",
"body": "casting an int `(int i;)` to a void pointer (`(void*)i` ) is undefined behaviour. Either pass `(void *) &i` or simply `&i`"
}
] | [
{
"body": "<p>In the problem as I have seen it, the philosophers only take one fork at a time and can hang on to it (but they only eat when they have 2 forks). You have simplified it by having them take both or none.</p>\n\n<p>There shouldn't be any deadlocks as the philosopher only has 0 or 2 forks, but there ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T05:06:17.420",
"Id": "26618",
"Score": "8",
"Tags": [
"c",
"concurrency",
"locking",
"pthreads",
"dining-philosophers"
],
"Title": "Dining philosophers problem with mutexe... | 26618 |
<p>Please assume I've exhaustively tried to come up with a set-based solution to my T-SQL problem, and that I need to use a cursor. The following is the typical<sup>1</sup> boilerplate for a T-SQL cursor:</p>
<pre class="lang-sql prettyprint-override"><code>DECLARE @myId AS INT;
DECLARE myCursor CURSOR FAST_FORWARD... | [] | [
{
"body": "<p>The infinite loop idiom in languages that have boolean literals is <code>while ( true )</code> but it seems the boolean type and its literals (e.g., <code>TRUE</code>/<code>FALSE</code>) have gone the way of the <code>DO ... WHILE</code> as far as T-SQL is concerned. This means you're stuck with t... | {
"AcceptedAnswerId": "26663",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T08:42:45.270",
"Id": "26620",
"Score": "3",
"Tags": [
"sql",
"sql-server",
"cursor"
],
"Title": "DRY cursors: preventing T-SQL's FETCH statement from being repeated"
} | 26620 |
<p>I'm looking for the best and fastest way to do a determinant, for determinants until 15x15.</p>
<pre><code>int Determinant(const vector<vector<int> > &a,int n)
{
int i,j,j1,j2;
int det = 0;
vector<vector<int> > m(n, vector<int>(n));
if (n == 1) { /* Shouldn't get used... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T21:21:53.490",
"Id": "42554",
"Score": "0",
"body": "Could you indicate whether my answer was helpful, or if not, how it could be improved?"
}
] | [
{
"body": "<p>Unless this is a homework assignment, you should probably not be writing your own linear algebra routines, but rely on libraries instead. Not only is it very hard to write <strong>correct and efficient</strong> general-purpose algorithms, for numerical algorithms there is an added requirement of <... | {
"AcceptedAnswerId": "27082",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T13:27:34.827",
"Id": "26625",
"Score": "2",
"Tags": [
"c++",
"performance",
"algorithm",
"matrix"
],
"Title": "Determinant of a binary matrix"
} | 26625 |
<p>I have made a mini image gallery which consists of one large div which has a background image of one of the galleries images. Underneath that are five thumbnail images, that when clicked, change the background image of the large div above. </p>
<p>All code works as expected but it looks like it could be improved. H... | [] | [
{
"body": "<p>You're using <code>$(\".main-image\")</code> a lot. It would be better to make a variable for that.\nAll the id's start with \"thumb\", so it might be better to use one click event handler on a selector that looks like this: <code>$(\"[id^='thumb']\")</code>. You can then, in the body of the click... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T13:45:44.197",
"Id": "26626",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"image"
],
"Title": "Mini image gallery"
} | 26626 |
<p>I'm solving Project Euler problems and uploading <a href="https://github.com/nicoekkart/python/tree/master/Project%20Euler" rel="nofollow">my solutions</a> to GitHub. Some of my solutions are just based on math and are thanks to that very fast, but #14 is way too slow, and I have no idea how to optimize it.</p>
<pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T14:53:58.650",
"Id": "41278",
"Score": "0",
"body": "Is it that slow? It takes 3.6s on my computer. One optimization is to use a list for indices less than eg. tn million, and use a dictionary otherwise. Initialize that list before ... | [
{
"body": "<p>I can not say something about optimizing the python code.\nBut wouldn't it be much faster if you cache partial chains of numbers?\nFrom my understanding of the problem it should not be impossible that sometimes collatz series overlap, so that you know that from element X in the series, the number ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T13:46:42.543",
"Id": "26627",
"Score": "2",
"Tags": [
"python",
"optimization",
"programming-challenge"
],
"Title": "Increasing speed of Project Euler #14 - Longest Collatz Sequen... | 26627 |
<p>Code reviews and suggestions to improve coding style are welcome.</p>
<pre><code>using ExpressionEvaluatorLibrary;
namespace ExpressionEvaluator
{
class Program
{
static void Main(string[] args)
{
ConsoleKeyInfo cki = new ConsoleKeyInfo();
Console.WriteLine(" Mathematical Expression Eval... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-05T18:23:26.697",
"Id": "43992",
"Score": "0",
"body": "Generally, if I were to write such thing, I'd look into [Polish notation](http://en.wikipedia.org/wiki/Polish_notation) which would make it easier to parse the expression and then... | [
{
"body": "<ol>\n<li><p>If I'm not mistaken your acceptable input expressions are in infix notation and look like this:</p>\n\n<pre><code>number [+-*/] number [+-*/] number ....\n</code></pre>\n\n<p>In that case you can greatly simplify you validation check with a single regular expression:</p>\n\n<pre><code>^\... | {
"AcceptedAnswerId": "36405",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T15:38:06.057",
"Id": "26631",
"Score": "3",
"Tags": [
"c#",
"regex",
"console"
],
"Title": "Mathematical expression evaluator."
} | 26631 |
<p>This is a continuation from here:<br/>
<a href="https://stackoverflow.com/questions/16761207/java-theory-classes-design-for-currency-futures-and-metals-analysis">https://stackoverflow.com/questions/16761207/java-theory-classes-design-for-currency-futures-and-metals-analysis</a>
<br/></p>
<p>I have created 2 classes... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T10:56:30.463",
"Id": "41320",
"Score": "0",
"body": "@Bobby as per your very useful comments I have updated my code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T11:08:09.030",
"Id": "41324",
... | [
{
"body": "<p>First, your indentation, brace-style and white-space usage is all mixed/messed up, fix that (hit \"Format Code\" in your favorite IDE if available).</p>\n\n<hr>\n\n<pre><code>// reads in a esfutures file and stores it as esfuturesdataobject \n</code></pre>\n\n<p><a href=\"http://www.oracle.com/tec... | {
"AcceptedAnswerId": "26655",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T20:24:31.700",
"Id": "26637",
"Score": "1",
"Tags": [
"java",
"object-oriented"
],
"Title": "Java Theory: Classes Design for Currency, Futures and Metals Analysis 1"
} | 26637 |
<p>Is this code good for checking if the variable <code>texto</code> is empty or not? How would it be done with try and catch?</p>
<pre><code>public class RedProfesionalException extends Exception {
public RedProfesionalException(String message) {
super(message);
}
}
public class Comentari extends Obj... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T20:49:16.823",
"Id": "41290",
"Score": "2",
"body": "There is nothing wrong with your current code..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T07:33:09.010",
"Id": "41310",
"Score": "2"... | [
{
"body": "<p>The current way of throwing your exception is absolutely fine from what I can see, I'm not quite sure what your question is supposed to be as since you want to throw an exception, you do not actually want to use try/catch. That part is left for the client code.</p>\n\n<p>Point is, the code you hav... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T20:46:32.623",
"Id": "26638",
"Score": "-1",
"Tags": [
"java",
"validation",
"constructor",
"exception"
],
"Title": "Checking whether a comment contains text"
} | 26638 |
<p>There are a few common jQuery call I find my self calling when creating my app. I need some help and maybe a better way to do all this or rewrite it.</p>
<h3>1) Singleton Selector</h3>
<p>If I want to select only one class I would do it like this:</p>
<pre><code>$("#tempo").on("click", ".ent... | [] | [
{
"body": "<p>I'd say you're on the right track with all your code. The trick is probably to abstract some of the oft-repeated code into functions/plugins.</p>\n\n<p>For the \"singleton selector\", wrapping your code in a plugin would seem the way to go. But note that your current code might need tweaking. You ... | {
"AcceptedAnswerId": "26646",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T21:00:05.190",
"Id": "26640",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"html",
"html5",
"jquery-ui"
],
"Title": "Replacing simple jQuery methods for better use"
... | 26640 |
<p>I am breaking my head with how to get rid of semantic duplication(Code that is syntactically the same but does different things).</p>
<p>I can't find anywhere a post or something that mentions a bit how to refactor this kind of duplication. All I found was this:<br>
<a href="https://blogs.agilefaqs.com/2011/07/21/d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T22:04:03.063",
"Id": "41297",
"Score": "0",
"body": "BTW, I think the second method is wrong. If the second new joiner is the last item in the collection, the method will incorrectly return `false`."
},
{
"ContentLicense": "... | [
{
"body": "<p>Well for a start, choose a style: Use the enhanced for loop, or use explicit iterators. Don't use one in one place and another in another. Other than that, I'm not seeing enough similar in the loops to justify spending any time on it as opposed to, say, actually getting something else done. :-)</p... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-05-26T21:13:57.423",
"Id": "26642",
"Score": "9",
"Tags": [
"java"
],
"Title": "Computing predicates of multiple items avoiding duplication of iteration code"
} | 26642 |
<p>I made my first Brainfuck program today, which prints the numbers 0-255 and the corresponding character.</p>
<p>I was wondering if I could improve my program, as I'm repeating myself a lot (e.g. 3 x copy & paste "comparer" function):</p>
<pre><code>max == 255
LF == 10
space == 32
'0' == 48
'9' == 57
'... | [] | [
{
"body": "<p>I think this would be a more efficient way of doing it (at least for the printable ASCII characters):</p>\n\n<pre><code>++++[->++++++++<] Use cell 0 for loop and cell 1 for ASCII codes\n++++[->>++++++++<<]>>> Use cell 2 for the sp... | {
"AcceptedAnswerId": "39252",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T23:27:25.057",
"Id": "26648",
"Score": "47",
"Tags": [
"brainfuck"
],
"Title": "ASCII table in Brainfuck"
} | 26648 |
<p>I'm making a comparing section, which I've just started typing, trying to get something working. It's working now, but as you can see its pretty messy. I feel this could be done in one or two less queries, or I should break it apart into smaller methods.</p>
<pre><code>foreach (XMLObject source in Sources)
{
v... | [] | [
{
"body": "<p>I'd like to suggest the following:</p>\n\n<pre><code> foreach (XMLObject source in Sources)\n {\n if (destList.Exists(s.ElementName == source.ElementName))\n continue;\n // perform a lightweight check\n if (lstAlteration.Exists(a => ... | {
"AcceptedAnswerId": "26653",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T02:52:19.530",
"Id": "26650",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Comparison application"
} | 26650 |
<p>I have never been entirely comfortable using <code>malloc()</code> and <code>free()</code> directly. For one thing, 99% of the time that I would like to call <code>malloc</code>, I would prefer it to take two arguments like <code>calloc</code> and do the multiplication itself, instead of taking one argument. Beyond ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T01:22:26.900",
"Id": "41499",
"Score": "1",
"body": "Is there any particular reason you've chosen not to also wrap `memmove()`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T01:25:26.687",
"Id":... | [
{
"body": "<p>Your code looks good, but your library doesn't seem to do much. The thing that bothers you (from my understanding), is that you can't call <code>malloc</code> like <code>calloc</code> and that the pointer given to <code>free</code> doesn't get set to <code>NULL</code>.</p>\n\n<p>IMHO, that doesn't... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T07:58:06.577",
"Id": "26656",
"Score": "5",
"Tags": [
"c",
"memory-management"
],
"Title": "Are these memory-allocation wrapper functions kosher with all C compilers?"
} | 26656 |
<p>I'm trying to join two tables based on one to one mapping without any common column. </p>
<p>For example, I have 3 records in the first table and 2 records in the second table.</p>
<p>The mapping should be as follows:</p>
<p><img src="https://i.stack.imgur.com/3Jrx9.png" alt="enter image description here"></p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T13:02:13.190",
"Id": "41336",
"Score": "0",
"body": "Even if you can get a query to line up the rows in some manner (using a calculated row ID), it may not be stable or survive backup/restore. Why can't you add the PK from one of th... | [
{
"body": "<p>Even if your solution is (almost) correct, the actual problem is in a wrong formulation of the problem.</p>\n\n<p>The main issue in your question is the assumption of a certain order of records within a table. In reality SQL Server <strong>cannot</strong> guarantee original order of records when y... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T10:05:42.287",
"Id": "26661",
"Score": "2",
"Tags": [
"sql"
],
"Title": "One to one record mapping without any common column between two tables in SQL server"
} | 26661 |
<p>This is a "answer" to my own question over at stackoverflow, head over there to see what I am trying to accomplish. <a href="https://stackoverflow.com/questions/16744109/deleting-the-proper-ccsprite-from-an-array-in-a-schedule">https://stackoverflow.com/questions/16744109/deleting-the-proper-ccsprite-from-an-array-i... | [] | [
{
"body": "<p>I don't know if this is the kind of answer you're looking for, but as this is code review, I'm going to at least review some aspects of your code.</p>\n\n<p>First thing I notice is <code>explosionLenght</code>. It's misspelled. You transposed the last two characters. It should be <code>explosio... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T11:52:30.377",
"Id": "26664",
"Score": "1",
"Tags": [
"objective-c",
"ios"
],
"Title": "Is this proper code for removing a CCSprite under certain conditions?"
} | 26664 |
<p>Is there a way to write this code block cleaner and more readable?</p>
<pre><code> var shareNavigate = function () {
scope.sharingActions.shareOnFacebook().done(function () {
app.router.navigateToStories();
});
},
sharePublishNavigate = function () {
scope.sharingActions.sh... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T12:10:07.603",
"Id": "41331",
"Score": "5",
"body": "First thing: use correct indentation!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T12:22:42.020",
"Id": "41333",
"Score": "0",
"body... | [
{
"body": "<p>I'd prefer to rewrite this</p>\n\n<pre><code> if (!noViews && hasEditPermissions) {\n shareNavigate();\n } else if (noViews) {\n if (hasEditPermissions) {\n sharePublishNavigate();\n } else if (!isLoggeedIn) {\n loginSharePublishNavigate();\n } else {\n ... | {
"AcceptedAnswerId": "26680",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T11:53:17.687",
"Id": "26665",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"facebook"
],
"Title": "Support for sharing stories on Facebook"
} | 26665 |
<p>I figured something like this:</p>
<pre><code>a= [1, 2, 3, 2, 2, 2, 3, 1, 1, 1, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
a.inject({}) { |h, el| h[el] = a.count(el) if h[el].nil? ; h }.sort_by {|k,v| v}.reverse.inject({}) { |h, el| h[el[0]] = el[1] ; h}
</code></pre>
<p>This outputs:</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T08:14:10.773",
"Id": "41435",
"Score": "0",
"body": "I think you need a longer array for a more representative benchmark. I don't know the big O for all of these, but there might be significant differences with a tougher dataset. Wh... | [
{
"body": "<p>Not sure which viewpoint this would be, but this is what I came up with:</p>\n\n<pre><code>Hash[a.group_by {|e| e}.map {|k,v| [k, v.length]}]\n</code></pre>\n\n<p>Update: I'm not thrilled with this, but this one sorts by the occurrence count, descending.</p>\n\n<pre><code>Hash[a.group_by {|e| e}.m... | {
"AcceptedAnswerId": "26674",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T15:38:17.953",
"Id": "26672",
"Score": "4",
"Tags": [
"ruby"
],
"Title": "Creating a sorted hash counting the occurrences of a number in an array"
} | 26672 |
<p>I am trying out a small piece of code that would generate HMAC-SHA1. I have been asked to code the HMAC implementation myself using the OpenSSL libs for SHA1 calculation.</p>
<p>After 'wiki'ing for the algorithm, here is what I have below. I have used input with RFC 2104 specified test values:</p>
<blockquote>
... | [] | [
{
"body": "<p>Might I suggest using OpenSSL's built in <a href=\"http://www.openssl.org/docs/crypto/HMAC.html\" rel=\"nofollow noreferrer\"><code>HMAC_*</code></a> methods, instead of re-rolling?</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T17:03:48.540",
"Id": "26673",
"Score": "5",
"Tags": [
"c",
"reinventing-the-wheel",
"cryptography",
"openssl"
],
"Title": "HMAC-SHA1 implementation"
} | 26673 |
<p>This is from an older question of mine that I decided to revisit:</p>
<p><a href="https://codereview.stackexchange.com/questions/24399/simple-and-efficient-code-for-finding-factors-and-prime-factorization">Simplifying and optimizing factors and prime factorization generator</a></p>
<p>In that question, someone sug... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T11:35:58.327",
"Id": "41382",
"Score": "0",
"body": "Few things for others to cover: either make these functions static or put them in a namespace, for C++ 11 you can consider std::unordered_map, using auto for everything you can, r... | [
{
"body": "<p>Looks generally ok. You can actually shorten iteration even more if your compiler supports range-based for loops:</p>\n\n<pre><code>for (auto iter = factors.begin(); iter != factors.end(); ++iter)\n{\n std::cout << \" \" << iter->first << \" x \" << iter->seco... | {
"AcceptedAnswerId": "26687",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-27T20:04:14.993",
"Id": "26678",
"Score": "4",
"Tags": [
"c++",
"c++11",
"primes",
"stl"
],
"Title": "First use of std::map in factors and prime factorization program"
} | 26678 |
<p>I'm reading Robert C. Martin's "Clean Code" and for the past few days I've been fiddling with its function writing guidelines. At first I thought the idea of functions being two/three lines long to be ludicrous, but I'm slowly getting the hang of it. The problem is, I'm pretty sure I'm overdoing it now.</p>
<p>Thes... | [] | [
{
"body": "<p>I think you have definitely taken it in the right direction. Excellent work!</p>\n\n<p>I don't see any compelling reason to break <code>AssembleDailySheetName()</code> down any further.</p>\n\n<p>My only complaint is that I don't really like the separation of adding and naming the sheets. I see bo... | {
"AcceptedAnswerId": "26704",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T00:08:50.553",
"Id": "26682",
"Score": "6",
"Tags": [
"vba"
],
"Title": "Are these good examples of functions that do one thing only or am I getting a little carried away?"
} | 26682 |
<p>I was trying out the <a href="http://beej.us/guide/bgnet/" rel="nofollow">Beej's guide to socket Programming</a> and wrote this. Is there anything that I am obviously doing wrong? Any potential for buffer overflows? Segmentation faults? Any possible errors that I am not checking for?</p>
<p>Or anything that I am ov... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T00:47:36.583",
"Id": "41420",
"Score": "0",
"body": "Next code you write think about the poor reader. Code is read much more often than it is written and so you should make the reader's job more pleasant."
}
] | [
{
"body": "<p>In other C like languages, it is customary to use more whitespace for readability, but maybe C is an exception; I will refrain from editing your example. I like to put spaces around infix operators and after commas, and use blank lines before function definitions.</p>\n\n<p>I think</p>\n\n<pre><co... | {
"AcceptedAnswerId": "26711",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T00:46:29.993",
"Id": "26683",
"Score": "2",
"Tags": [
"c",
"networking",
"socket"
],
"Title": "How is this for a \"Hello World\" of socket programming?"
} | 26683 |
<p>I have a method that returns either true or false based on a value contained by a <code>java.util.List</code>.</p>
<pre><code>List<Long>list=new ArrayList<Long>(){{
add(1L);
add(2L);
add(3L);
}};
public boolean checkId(Long id)
{
return list.contains(id);
}
</code></pre>
<p>Based on th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T09:47:33.353",
"Id": "41378",
"Score": "1",
"body": "What is the code _after_ that `if` condition?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T19:39:30.623",
"Id": "41413",
"Score": "0",
... | [
{
"body": "<p>Why don't you just write it like this? It should be logically equivalent.</p>\n\n<pre><code>if (id != null && id > 0 && test.checkId(id) && (isIdChanged || !isAjaxRequest))\n{\n // do stuff\n}\n</code></pre>\n\n<hr>\n\n<p>On a side note, I would move the null and pos... | {
"AcceptedAnswerId": "26688",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T04:12:24.880",
"Id": "26686",
"Score": "4",
"Tags": [
"java"
],
"Title": "Avoid duplicate conditional checks in multiple boolean conditions"
} | 26686 |
<p>I wrote this code to find the smallest possible integer ratio between two numbers:</p>
<pre><code>void ratio(int a, int b) {
int min = Math.min(a, b);
int max = Math.max(a, b);
if(max % min == 0) {
System.out.println("1" + " " + max / min);
return;
}
for (int i ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T11:27:06.130",
"Id": "41386",
"Score": "5",
"body": "are you referring to GCD (Greatest Common Divisor)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T11:28:44.050",
"Id": "41387",
"Score": ... | [
{
"body": "<p>You need to find the <a href=\"http://en.wikipedia.org/wiki/Greatest_common_divisor\">GCD</a> and then divide both numbers by that.</p>\n\n<p><a href=\"http://en.wikipedia.org/wiki/Euclidean_algorithm#Background_.E2.80.94_Greatest_common_divisor\">Euclid's algorithm</a> is the classic way to do th... | {
"AcceptedAnswerId": "26698",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T11:25:45.597",
"Id": "26697",
"Score": "2",
"Tags": [
"java"
],
"Title": "Getting the smallest possible integer ratio between two numbers"
} | 26697 |
<p>Please, review my implementation of the F# pipeline operator in Scala</p>
<pre><code>class PipelineContainer[F](value: F) {
def |>[G] (f: F => G) = f(value)
}
implicit def pipelineEnrichment[T](xs: T) = new PipelineContainer(xs)
test("Find the last but one element in the list") {
// example: penulti... | [] | [
{
"body": "<p>There isn't much that can be reviewed. If you use Scala 2.10 then you should use an <a href=\"http://docs.scala-lang.org/sips/pending/implicit-classes.html\">implicit class</a> instead of an implicit conversion. Even better: use an implicit <a href=\"http://docs.scala-lang.org/sips/pending/value-c... | {
"AcceptedAnswerId": "26710",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T14:15:47.277",
"Id": "26707",
"Score": "1",
"Tags": [
"scala"
],
"Title": "Pipeline operator in scala"
} | 26707 |
<p>Here's a test from a Rails app I'm working on. I want to know if I'm using <code>describe</code>, <code>let</code>, <code>before</code>, <code>expect</code>, etc in the proper way.</p>
<p>It is an integration test using <code>capybara</code> and <code>FactoryGirl</code>:</p>
<pre><code>require 'spec_helper'
descr... | [] | [
{
"body": "<ol>\n<li>Use contexts rather than describe on context.</li>\n<li>make sure to keep the same depth with same contexts (story -> login_state -> page -> user_action)</li>\n<li><p>dry your \"let, subject, before\"s</p>\n\n<pre><code>subject { page }\nlet (:other_user) { FactoryGirl.create(:user) }\nlet ... | {
"AcceptedAnswerId": "27425",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T15:25:50.380",
"Id": "26712",
"Score": "2",
"Tags": [
"ruby",
"unit-testing",
"ruby-on-rails",
"rspec",
"bdd"
],
"Title": "Test for a Rails app"
} | 26712 |
<p>I'm currently learning JAVA in a class and we're using the <a href="http://jtf.acm.org/javadoc/student/index.html" rel="nofollow">ACM Graphics package</a>. I wanted some pointers on my code. To provide some context here is the assignment:</p>
<blockquote>
<p>Write a program that creates an array of 5 custom objec... | [] | [
{
"body": "<p>Overall, it looks pretty straightforward.</p>\n\n<p>One thing I would recommend is breaking some of the functions down to smaller functions. Several of the comments in the code scream \"move me into a separate function\"! Take <code>displayWinner()</code> for example. This function does two things... | {
"AcceptedAnswerId": "26721",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T16:26:38.507",
"Id": "26714",
"Score": "3",
"Tags": [
"java",
"optimization"
],
"Title": "Java Array Traversal Optimization"
} | 26714 |
<p>I have had to do a crash course in JSP, Servlets, and JDBC. I decided to attempt a Login System. I'm unsure if my use of try/catch is appropriate and if I am closing database connections correctly. There is one major flaw in the program which is if a user registering enters an ID that is not unique, then it causes a... | [] | [
{
"body": "<p>Most of the functions in <code>LoginService</code> take unnecessary parameters. For example, <code>getConnection()</code> takes a <code>connection</code> parameter, but never uses it. It just reassigns and returns it. It could be written like this instead:</p>\n\n<pre><code>public Connection getCo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T17:43:55.013",
"Id": "26717",
"Score": "2",
"Tags": [
"java",
"authentication",
"jdbc",
"servlets",
"jsp"
],
"Title": "Am I using appropriate methods in this login system?... | 26717 |
<p>I was fiddling with animation in Java and wrote this:</p>
<pre><code>import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
class Main e... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T10:36:38.750",
"Id": "41442",
"Score": "0",
"body": "You might have a look at double-buffering or page-flipping: http://docs.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html"
}
] | [
{
"body": "<p>Two recommendations:</p>\n\n<ul>\n<li>It is better that you don't \"do any action\" in the constructor; create, say, a <code>.start()</code> method and do <code>new Main().start()</code> in <code>main()</code>;</li>\n<li><p>rather than testing on <code>count</code> in animation, use this, where <c... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T18:27:43.113",
"Id": "26720",
"Score": "4",
"Tags": [
"java",
"animation"
],
"Title": "Is this the correct approach to animation in Java?"
} | 26720 |
<p>I have written this code to be able to suspend (or to cancel) a worker executed in a separate thread in Qt.</p>
<p>To do it, I have used an instance <code>QWaitCondition</code> and <code>QMutex</code>.</p>
<pre class="lang-cpp prettyprint-override"><code>#ifndef MYWORKER_H
#define MYWORKER_H
#include <QObject&... | [] | [
{
"body": "<p>It's not at all clear why you've declared/defined this:</p>\n\n<pre><code>MyWorker::~MyWorker()\n{\n}\n</code></pre>\n\n<p>Unless there's something specific that this accomplishes (which I don't see) you're better off without it.</p>\n\n<pre><code>void MyWorker::restart()\n{\n this -> m_paus... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T19:48:08.223",
"Id": "26724",
"Score": "11",
"Tags": [
"c++",
"multithreading",
"qt"
],
"Title": "Thread pausing/resuming/canceling with Qt"
} | 26724 |
<p>I've written a modulus-type program (using <code>std::vector</code>). The user inputs a number, and the program displays a modulus grid pertaining to that number.</p>
<p>This is what it looks like (example program output with 12):</p>
<blockquote>
<pre><code>(0) 12 24 36 48 60 72 84 96 108 120
(1) 13 2... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T13:41:01.847",
"Id": "41456",
"Score": "0",
"body": "How about using a range-based for loop?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T14:00:25.930",
"Id": "41460",
"Score": "0",
"bo... | [
{
"body": "<p>After looking through my code output and thinking about the comments, I've decided that a map of arrays isn't best. I can see how a map can still display it in order (first column numbers as the keys), but that's about it. It does make more sense to use a vector of vectors, after deciding that i... | {
"AcceptedAnswerId": "26951",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-28T23:36:02.330",
"Id": "26728",
"Score": "3",
"Tags": [
"c++",
"c++11",
"matrix",
"stl"
],
"Title": "Utilizing std::map and std::array for displaying a modulus grid"
} | 26728 |
<p>You can <a href="https://sourceforge.net/projects/dangerworld/" rel="nofollow">download the Dangerworld game in pre-alpha version</a> and review the code. The particular issues I have are</p>
<ol>
<li>making the character walk over steps instead of sliding</li>
<li>NPC AI how to make the enemy <a href="http://www.r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-02T01:01:28.600",
"Id": "41645",
"Score": "5",
"body": "Is that all one huge god class?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-02T05:16:54.040",
"Id": "41652",
"Score": "0",
"body": "@H... | [
{
"body": "<p>Overall, your code looks quite good. There is something however which you can simplify <strong>a lot</strong>.</p>\n\n<p>Consider these two code-parts:</p>\n\n<pre><code>if (!ninjaControl.isOnGround()) {\n airTime = airTime + tpf;\n} else {\n airTime = 0;\n}\n\nif (binding.equals(\"CharLeft\... | {
"AcceptedAnswerId": "36310",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T00:48:02.673",
"Id": "26729",
"Score": "6",
"Tags": [
"java",
"game",
"ai"
],
"Title": "Dangerworld game"
} | 26729 |
<p>I have a handful of objects that don't have references to each-other that all need to receive an update. </p>
<p>From what I've read, it seems like a Publish-Subscribe Messaging Channel is an appropriate pattern. Searching for an existing solution mainly turned up messaging libraries for application integration (be... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T11:53:14.583",
"Id": "41449",
"Score": "0",
"body": "\" I presume I need to Unsubscribe in the subscriber's finalizer.\" If not unsubscribing will prevent the subscriber from being GCed, who would call the finalizer? Maybe you want ... | [
{
"body": "<p>Don't think it's a good approach.</p>\n\n<ul>\n<li><a href=\"http://blogs.msdn.com/b/scottdensmore/archive/2004/05/25/140827.aspx\" rel=\"nofollow\">Singletons are evil</a> by themselves </li>\n<li>Subscribers are likely to expect a specific type of message on specific channel</li>\n<li>Magic str... | {
"AcceptedAnswerId": "26737",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T02:30:13.193",
"Id": "26730",
"Score": "2",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Local (In-Process) Publish/Subscribe"
} | 26730 |
<p>This is sort of a follow-up to a post I created about 10 days ago, but I have completed the implementation: <a href="https://codereview.stackexchange.com/questions/26331/designing-function-prototypes-for-a-singly-linked-list-api-in-c">Designing function prototypes for a singly-linked list API in C</a>.</p>
<p>As I ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T16:59:43.117",
"Id": "41479",
"Score": "0",
"body": "I don't see a problem with _sllist_destroy_. Do you have a minimal program that uses your library to elicit the Valgrind complaint? If you do, could you please attach it?"
},
... | [
{
"body": "<p>This is a clean and well documented API: There is little reason to have to read to the code to know how to use it. The only thing I see missing from the comment is any mention of what happens to the cursor (<em>sllist.current</em>) when the list is modified.</p>\n\n<p>The memory error is because ... | {
"AcceptedAnswerId": "26758",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T03:58:38.080",
"Id": "26732",
"Score": "4",
"Tags": [
"c",
"unit-testing",
"linked-list",
"memory-management",
"library"
],
"Title": "Singly-linked list library"
} | 26732 |
<p>Here I have two <code>DataTable</code>s:</p>
<ul>
<li>dtTotalDateRangeExcludeSundays </li>
<li>dtAbsentsLeavesHolidaysWorks</li>
</ul>
<p>Each has 10k+ values, and I need to delete matched rows.</p>
<pre><code>foreach (DataRow rw in dtTotalDateRangeExcludeSundays.Select())
{
DateTime dateFromRange=Convert.T... | [] | [
{
"body": "<p>Assuming that you load the data into your <code>DataTable</code> instances from database, it's better to issue a direct <code>DELETE FROM ...</code> query over database rather than iterate on a client.</p>\n\n<p>As a side note - it is an awful practice to compare dates by comparing strings. If you... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T07:38:55.977",
"Id": "26736",
"Score": "1",
"Tags": [
"c#",
"performance",
"asp.net",
".net-datatable"
],
"Title": "Remove matched Rows from two Datatable"
} | 26736 |
<p>There is a function that converts region code strings (1 to 4 characters and null terminator) to 32 bit integers codes to be used in maps as keys or values.</p>
<p>Blindly casting char* to int* is bad as it can be less than 4 bytes including null terminator.</p>
<p>Currently the code is like this</p>
<pre><code>u... | [] | [
{
"body": "<p>Even if the <code>char</code> array is not aligned, your <code>*((uint32_t *)buf)</code> will be correct: the compiler will ensure the necessary operations are performed.</p>\n\n<p>Note that I used <code>unit32_t</code>: the C standard does not guarantee the size of an <code>int</code>.</p>\n\n<p>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T08:26:24.580",
"Id": "26739",
"Score": "6",
"Tags": [
"c",
"casting"
],
"Title": "Converting a region code (short string up to 4 characters) to a 32-bit integer"
} | 26739 |
<p>I want to provide, in the the spirit of C++11/boost make_shared and C++14 make_unique, a production-ready make_auto for C++03 compilers.</p>
<p>So, inspired boost's make_shared implementation for C++03 compilers, I provide N overloads (0 to 10, currently) of the same make_auto function.</p>
<pre><code>template <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-08T14:42:57.367",
"Id": "42185",
"Score": "0",
"body": "Can’t you use Boost.PP to generate that code for you rather than writing it manually? Additionally: why are the Boost smart pointers unsuitable?"
},
{
"ContentLicense": "C... | [
{
"body": "<p><strong>Disclaimer</strong>: this is not an attempt to answer your technical question, but suggesting alternatives to reach some compromise of your stated goals. It wouldn't fit in a comment :-)</p>\n\n<p>I am not sure it is a good idea to actually write a <code>make_auto</code>. It is akin to <a ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T09:03:49.953",
"Id": "26742",
"Score": "11",
"Tags": [
"c++",
"c++11",
"smart-pointers",
"c++03"
],
"Title": "make_auto implementation for C++03 compilers"
} | 26742 |
<p>My main goal is to perform the conversion on a list of strings. Is this a sensible approach or should I refactor?</p>
<p>Please note that I cannot use Boost in my work.</p>
<pre><code>#include <iostream>
#include <list>
#include <string>
#include <algorithm>
char fix_delim(char ch) {
... | [] | [
{
"body": "<p>With C++11 you can use lambda, otherwise make the helper function static. </p>\n\n<p>If you're tied to std::string and no stock solution, this one is about as good as it gets. I suggest naming it properly like fix_path_separators or along the lines describing its <em>purpose</em>.</p>\n",
"com... | {
"AcceptedAnswerId": "26745",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T09:22:02.723",
"Id": "26743",
"Score": "2",
"Tags": [
"c++",
"strings"
],
"Title": "Replace all instances of \\ with /"
} | 26743 |
<p>I am making a web app that will have a "my files" area and to do so I am writing my own html and jQuery to control the opening and closing of each folder (or <code>ul li</code>). I want to make sure that this web app is as efficient as I can make it as it may have to deal with a large amount of hierarchy.</p>
<p><a... | [] | [
{
"body": "<p>Step 1: Fix your markup. You have the \"plants\"-list nested inside the link, which is invalid</p>\n\n<p>Step 2: Fix your JS. You correctly add the click handler after the document's ready, but you set the <code>folderToggle</code> variable when the script's run, regardless of whether the document... | {
"AcceptedAnswerId": "26749",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T09:24:41.283",
"Id": "26744",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html",
"css"
],
"Title": "jQuery File Tree Toggle"
} | 26744 |
<p>Here is a function that checks whether an alement <code>a</code> is a member of every set in list <code>l-set</code>.</p>
<p>I don't like the fact that it returns <code>#t</code> for an empty list of sets. What would be a clean fix to this problem?</p>
<pre><code>(define memberall
(lambda (a l-set)
(co... | [] | [
{
"body": "<p>so this is not a question about code, but about conventions. Usually to say \"a condition holds for all elements of a set\" is the same as \"there's no such element in the set that the condition doesn't hold for it\". Which there clearly is no such element, in an <em>empty</em> set. So by conventi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T12:11:51.813",
"Id": "26748",
"Score": "1",
"Tags": [
"scheme"
],
"Title": "Check if element is a member of all sets in Scheme"
} | 26748 |
<p>I found this old color fading function in my snippets folder and would like to implement it to one of my projects. It can be used to fade one color to another. It's a very long one-liner:</p>
<pre><code>D3DCOLOR GetFadedColor(D3DCOLOR from, D3DCOLOR to, float factor)
{
return (factor<0.0f)?from:((factor>1... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T14:14:43.130",
"Id": "41465",
"Score": "0",
"body": "Since we don't deal with code errors, you can post about them on Stack Overflow. After getting them fixed, you could make those changes here and we'll help with the readability."... | [
{
"body": "<p>This is the reason why some people want ternary operators removed from the language. It's not quite the worst abuse I've seen, but it's pretty close. This took quite a while to disentangle. I'm going to go through it in steps:</p>\n\n<p>First step: make it slightly more readable. Break up everythi... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T13:05:25.153",
"Id": "26750",
"Score": "2",
"Tags": [
"c",
"bitwise"
],
"Title": "Color fading function"
} | 26750 |
<p>I have written some sort routines for PROGRESS 4GL/ABL and wanting to get some input whether these sorts can be improved. And whether my sorts are true to name. And I would also be very interested in any suggestions how to change the Quick sort to do a proper numeric sort as well.
The combsort was easy enough to wr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T19:55:16.853",
"Id": "41603",
"Score": "0",
"body": "Why not use a temp-table?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-05T07:16:09.873",
"Id": "41886",
"Score": "0",
"body": "Because ... | [
{
"body": "<p>Depending on how long strings you have to work with I really would consider sorting via TEMP-TABLE instead. On longer strings (lets say 1000 integers or more) the TEMP-TABLE sort is around twice as quick. For short strings (10 integers) quicksort is faster. Also the difference between the largest ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T13:06:50.353",
"Id": "26751",
"Score": "1",
"Tags": [
"sorting",
"quick-sort",
"progress-4gl"
],
"Title": "Suggestions on improving Sorting Algorithm (Progress ABL/4GL)"
} | 26751 |
<p>I have this method that reads a file into a hashmap. I feel like there are too many levels in this code with all these tries, ifs and so on. How do you think this can be improved?</p>
<pre><code>public static ExchangeHistory loadHistory(String path){
Map<Integer, Date> rtcHistory = new HashMap<Integer,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T13:32:15.300",
"Id": "41454",
"Score": "0",
"body": "Ok, I guess I need to remove the file creation part as it makes no sense here."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T13:48:43.400",
"... | [
{
"body": "<p>You can reduce the inner try/catch block in your while loop. For instance:</p>\n\n<pre><code>int id;\nlong timeInMillis;\n\nwhile (...) {\n // ...\n\n try {\n id = Integer.parseInt(tokens[1]); \n timeInMillis = Long.parseLong(tokens[2]);\n } catch (NumberFormatException e) {... | {
"AcceptedAnswerId": "26772",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T13:16:49.867",
"Id": "26752",
"Score": "3",
"Tags": [
"java",
"parsing",
"logging"
],
"Title": "Parsing a tabular log file into a hashmap"
} | 26752 |
<p>I came across the following code in our code base:</p>
<pre><code>public interface ICloneable<T>
{
T Clone();
}
public class MyObject : ICloneable<MyObject>
{
public Stuff SomeStuff { get; set; }
T Clone()
{
return new MyObject { SomeStuff = this.SomeStuff };
}
}
</code></p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T14:39:00.367",
"Id": "41469",
"Score": "3",
"body": "Implementation of the `Clone` should return `MyObject` not `T`."
}
] | [
{
"body": "<p>This pattern is called a <a href=\"http://en.wikipedia.org/wiki/Prototype_pattern\" rel=\"nofollow\">Prototype object creation pattern</a>. Usually it is used to do a deep cloning of objects (that is if <code>Stuff</code> is a reference type then it should also be cloned).</p>\n",
"comments": ... | {
"AcceptedAnswerId": "26802",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T13:47:09.983",
"Id": "26754",
"Score": "2",
"Tags": [
"c#",
"design-patterns",
"generics"
],
"Title": "Generically typed interface"
} | 26754 |
<p>ABAP is the programming language of the SAP R/3 system. It is a proprietary language that is used to write both the fundamental SAP R/3 system itself and the standardized business applications that run on top of this system. It can be used for customer extensions of the system or entirely new software applications a... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T17:30:56.597",
"Id": "26760",
"Score": "0",
"Tags": null,
"Title": null
} | 26760 |
ABAP is the programming language of the SAP R/3 system. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T17:30:56.597",
"Id": "26761",
"Score": "0",
"Tags": null,
"Title": null
} | 26761 |
<p>I've written this snippet to extract a review request status from review-board in python. It works well but i'm very new to python and i would like to know if i could write this any better.<br>
Should i put <code>conn.close</code> in it's own try statement ?</p>
<p>This script is supposed to run as part of a post-c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T09:45:54.560",
"Id": "41520",
"Score": "1",
"body": "is this a standalone script? if so I'd let it blow on errors, don't catch any exceptions (specially don't *silently* catch *all* exceptions)"
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>Looks pretty good to me. Regarding <code>conn.close()</code>, definitely don't put this in its own <code>try</code> statement, because if there's a problem with the earlier code, the connection might not get closed. I know you're not using Python 3, but ss an alternative, you might consider using ... | {
"AcceptedAnswerId": "26814",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T18:04:10.567",
"Id": "26762",
"Score": "2",
"Tags": [
"python"
],
"Title": "python httplib snippet"
} | 26762 |
<p>My code already works 100%, just trying to figure out if there is an easier, better or speedier way to do this. Outputs to an HTML table to display results.</p>
<p>Something that took me a while to figure out was how to select the correct parts of the following arrays ($name, $business, $email, $orderstatus) becaus... | [] | [
{
"body": "<p>You should look at how your accessing the data from both <code>orders</code> and <code>customers</code>. Your code is currently looping through the result of <code>SELECT * FROM orders</code> to retreive additional data from <code>customers</code> by <code>SELECT fname,lname,business FROM customer... | {
"AcceptedAnswerId": "26767",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T19:13:55.900",
"Id": "26765",
"Score": "-1",
"Tags": [
"php",
"mysql",
"pdo",
"session"
],
"Title": "Can this code be improved upon?"
} | 26765 |
<p>Here's the <a href="https://github.com/bevacqua/ponyfoo/blob/master/src/frontend/js/plugin/jquery.readingTime.js" rel="nofollow"><strong>full source</strong></a> to a plugin I'm developing, the relevant code I want to refactor is:</p>
<pre><code>function measure($element, $bubble){
var scrollTop = $window.scrol... | [] | [
{
"body": "<p>Strictly in terms of code readability, you want to break down a function like this into it's core parts. Additionally, to reduce repetitive behavior you could make it more of a prototype and use some object oriented style to get to your result without a block of math.</p>\n\n<p><strong>Things to C... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T19:30:13.297",
"Id": "26766",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Math calculation refactoring in JavaScript"
} | 26766 |
<pre><code>#!/usr/bin/env ruby
require 'pivotal-tracker'
require 'yaml'
TEMP_DIR = "#{ENV['HOME']}/.pivotal/"
TEMP_FILE = TEMP_DIR + "temp.yml"
CONFIG_FILE = TEMP_DIR + "config.yml"
unless File.directory? TEMP_DIR
Dir::mkdir TEMP_DIR
end
unless File.file? TEMP_FILE
f = File.open(TEMP_FILE, 'w')
f.write("id: ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T21:40:30.747",
"Id": "41494",
"Score": "2",
"body": "wants code to be \"nicer before I throw it up for the world to see\" - posts code on the internet anyway :) But in all seriousness, I'd probably start by removing the hard coded ... | [
{
"body": "<p>I haven't used Pivotal Tracker, so I can't really say what's \"right\" to do, purpose-wise. However, skimming through your code, I have a few ideas:</p>\n\n<h3>1. Extend PivotalTracker's classes for fun and profit</h3>\n\n<p>Instead of a global method like <code>story_info</code> (which I'd prefer... | {
"AcceptedAnswerId": "26776",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T20:04:46.203",
"Id": "26768",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Quick and dirty command line application in Ruby. Now it's time to refactor, where should I start?"
} | 26768 |
<p>I am developing a large .NET app. The previous developer used Martin Fowlers Transaction script design pattern. Please see the code below:</p>
<pre><code>Public Class TypeStudent
Private _Name As String
Private _Type As String 'Undergraduate or postgraduate
Public Property Name() As String
Get... | [] | [
{
"body": "<p>I don't think that there is inherently anything \"wrong\" with having multiple patterns like this in a single application, especially during a refactoring exercise. I would strongly suggest documenting the patterns that you are changing from and to and the reason for the modification so that futur... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T20:09:28.550",
"Id": "26769",
"Score": "1",
"Tags": [
"design-patterns",
"vb.net"
],
"Title": "Mixing Fowlers patterns"
} | 26769 |
<p>Can I make any further improvements to simplify / speed up this code? My reason for creating new arrays for the variables <code>$name</code>, <code>$business</code>, <code>$email</code>, <code>$orderstatus</code> is because when displaying results there will be identical order ID numbers stored in $orderid.</p>
<p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T08:04:05.650",
"Id": "41570",
"Score": "1",
"body": "You set the location to _login.php_ but then you don't `exit`. So you send the data to the unauthorized user and hope the browser redirects quick enough before he sees it? I hope ... | [
{
"body": "<p>First, since you're only going to print one HTML table row per order, make sure your query only returns one database row per order. That way there's no need for extra complexity and throwing away bandwidth and memory. This <em>should</em> be doable by adding a simple <code>DISTINCT</code> after th... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T20:56:59.733",
"Id": "26771",
"Score": "1",
"Tags": [
"php",
"mysql",
"pdo"
],
"Title": "Displaying orders and customers in a table, filtering out duplicates"
} | 26771 |
<p>This function counts the number of times each letter appears in a string, then display the one that appears the most, and the number of times it appears. If there's a tie, it shows all of them, like "bz,5".</p>
<p>I've got the feeling this could be done much better. Suggestions?</p>
<pre><code>private static void ... | [] | [
{
"body": "<p>The trick is to group by the character, as you are doing, then do a <em>second</em> grouping by the count:</p>\n\n<pre><code>var testString = \"abbsabwertbfacsfgggdfgasc\";\n\nvar characterCounts =\n from character in testString\n group character by character into characterGroup\n group c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-29T21:58:58.107",
"Id": "26775",
"Score": "4",
"Tags": [
"c#",
"strings",
"linq"
],
"Title": "Counting the occurrence of each letter in a string"
} | 26775 |
<p>I have to make project for school in C# which has to use database and web service. I have made a program which starts a web service and gets a function from there which is used for connecting to a website. I am using HTML Agility Pack for parsing info from that website. Website info is then written in textbox and st... | [] | [
{
"body": "<p>One comment I'd have is that there is a LOT going on in that method... but for the most part \neach section is the same... </p>\n\n<ul>\n<li>GetNodeCollection</li>\n<li>Loop Through it</li>\n<li>Add it to a list</li>\n</ul>\n\n<p>You could probably pull that out into a method to shorten your code.... | {
"AcceptedAnswerId": "26791",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T08:31:10.093",
"Id": "26787",
"Score": "4",
"Tags": [
"c#",
"parsing"
],
"Title": "Parsing website info with a database and web service"
} | 26787 |
<p><a href="http://projecteuler.net/problem=37" rel="nofollow">Project Euler problem 37</a> says:</p>
<blockquote>
<p>The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we ca... | [] | [
{
"body": "<p>I would suggest returning the truncations in order of increasing lengths for truncation from the left (checking the shorter tails for primality is faster, so if the number is not a left-truncatable prime, that should be detected faster on average when the tails are yielded in that order),</p>\n\n<... | {
"AcceptedAnswerId": "26795",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T09:19:24.500",
"Id": "26788",
"Score": "4",
"Tags": [
"c#",
"performance",
"programming-challenge",
"mathematics"
],
"Title": "Truncating an integer from left to right and ... | 26788 |
<p>How can I improve the following two views? Should the action listeners stay in the views?</p>
<p><strong>StudentView.java</strong></p>
<pre><code>package com.studentenverwaltung.view;
import com.studentenverwaltung.controller.StudentController;
import com.studentenverwaltung.helpers.MyTableCellRenderer;
import c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T11:10:32.243",
"Id": "41524",
"Score": "0",
"body": "While I am not fluent with graphics programming, I am not sure it is a good idea to add listeners in the constructors..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creat... | [
{
"body": "<p>Both of these classes have <code>ChangePasswordListener</code> and <code>LogoutListener</code> inner classes, each of which are almost identical. Both call the same functions in the corresponding controller classes, so there may be duplication there as well. See if there is a way you can eliminate... | {
"AcceptedAnswerId": "26834",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T09:35:08.673",
"Id": "26789",
"Score": "1",
"Tags": [
"java",
"swing"
],
"Title": "Student and Lecturer views"
} | 26789 |
<p>I have an xml file from which I want to extract the value of attribute <code>custName</code> from the very first child. The code below works where I am using the dom parser. Is there a third-party library with which I can do the same with less code and more neatly?</p>
<pre><code>import javax.xml.parsers.DocumentBu... | [] | [
{
"body": "<p>I think you should look into using a different parser for this particular situation. <a href=\"https://stackoverflow.com/questions/373833/best-xml-parser-for-java\">this page</a>\ncontains good comparisons between java xml parsers. Maybe SAX or StAX is more suitable here?</p>\n",
"comments": [... | {
"AcceptedAnswerId": "26801",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T09:40:31.673",
"Id": "26790",
"Score": "3",
"Tags": [
"java",
"parsing",
"xml"
],
"Title": "Better way to get the XML attribute value?"
} | 26790 |
<p><a href="http://plugins.trac.wordpress.org/browser/seo-content-helper/tags/1.1/get-data.php" rel="nofollow">Entire Code Here</a></p>
<p><strong>Don't repeat yourself</strong></p>
<p>I know of the "Don't repeat yourself". Still it's getting messy in some places. The code below contains three blocks of code.</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T17:36:57.037",
"Id": "41549",
"Score": "0",
"body": "I haven't done enough Wordpress plugin development to recommend the _best_ way of implementing this, but trying to follow the MVC pattern would probably help here. A quick google ... | [
{
"body": "<p>There's duplication between <code>$message</code> and <code>$array['content_editor']['count_h2']['status']</code> in the first block and its counterpoints in the other blocks - <em>they both convey the same information</em>. Instead of using <code>$message</code> you can use <code>$array['content_... | {
"AcceptedAnswerId": "27347",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T14:37:58.607",
"Id": "26803",
"Score": "4",
"Tags": [
"php",
"design-patterns",
"array"
],
"Title": "Creating an array that loops out on the frontend - Don't Repeat Yourself?"
... | 26803 |
<p>This is a project about a domotics control system based on arduino. Nothing great; it's only for testing myself and making stuff.</p>
<p>Before I started coding this, I searched on the net for some useful tips to use in my code, but I still remain a novice in programming.</p>
<p>The project is about 1600 lines lo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T11:12:06.197",
"Id": "45310",
"Score": "1",
"body": "You are very unlikely to get a good review unless you pick out the relevant parts you want reviewed and add them to the post."
}
] | [
{
"body": "<p>I am not familiar with Arduino, but as a general C++ developer, I've noticed the following issues (looking only at the code in the question, not the one behind links):</p>\n\n<ul>\n<li><p>No const-correctness.</p>\n\n<p>The biggest problem in the code, one which would cause me to return it back to... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T16:17:42.147",
"Id": "26811",
"Score": "6",
"Tags": [
"c++",
"beginner",
"arduino"
],
"Title": "Domotics control system"
} | 26811 |
<p>The program basically takes a polynomial and does some simple calculations with it.</p>
<p>With a couple of hours of work I managed to get my first console application to work (aside from the obligatory "Hello, World!", of course). However, I'm in total doubt that the style and habits I've used are even close to be... | [] | [
{
"body": "<p>First, your program has no need for these Libraries:</p>\n\n<pre><code>#include <fstream>\n#include <algorithm>\n#include <math.h>\n</code></pre>\n\n<p>The <<strong>math.h</strong>> is redundant due to the use of <<strong>cmath</strong>>. <<strong>cmath</strong>> is the ... | {
"AcceptedAnswerId": "26908",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T19:17:41.890",
"Id": "26817",
"Score": "10",
"Tags": [
"c++",
"performance",
"beginner",
"mathematics"
],
"Title": "Polynomial program"
} | 26817 |
<p>I'm writing unit tests for a library which parses colors from user input (example: the user input “#f00” gives a red color; the user input “60,100%,100%” gives a yellow color, etc.)</p>
<p>One of the conditions is that the method <code>Parse</code> returns <code>null</code> when there is actually nothing to parse, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T21:06:04.283",
"Id": "41557",
"Score": "3",
"body": "I guess a potential problem with this is if one of the items fail you won't easily know which one is the culprit"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>What you need is passing parameters to common test method and supplying it with informative error message.</p>\n\n<pre><code> [TestMethod]\n public void SubmitShortText()\n {\n var colorCodes = new[] { \"#\", \"#f\", \"#ff\" };\n DoAssertion(colorCodes);\n }\n\n privat... | {
"AcceptedAnswerId": "26976",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T20:49:58.667",
"Id": "26820",
"Score": "4",
"Tags": [
"c#",
"linq",
"functional-programming",
"unit-testing"
],
"Title": "Is a unit test which uses LINQ to check multiple v... | 26820 |
<p>I've read most of the posts I could find on optimizing SQLite3 performance, such as:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/1711631/how-do-i-improve-the-performance-of-sqlite">How do I improve the performance of SQLite?</a>, </li>
<li><a href="https://stackoverflow.com/questions/1609637/is-it-pos... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T21:29:25.890",
"Id": "41610",
"Score": "0",
"body": "@JanneKarila : Synthetic data generator added in code in lines 48-62 :-)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-02T17:43:32.683",
"Id": "... | [
{
"body": "<p>I have just had a similar experience using <a href=\"http://code.google.com/p/apsw/\">Another Python SQLite Wrapper (APSW)</a>, which is an alternative to pysqlite that tends to be a bit faster. The PRAGMA options make practically no difference on a database of ~2 million rows (6 columns, also doi... | {
"AcceptedAnswerId": "28112",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-30T21:40:56.247",
"Id": "26822",
"Score": "17",
"Tags": [
"python",
"optimization",
"sqlite"
],
"Title": "Myth-busting SQLite3 performance w. pysqlite"
} | 26822 |
<p>I made myself this code to read CSV files as I want to delve into machine learning. I do think that my code design is poor but I can't quite see why. The syntax of it does not feel right. I want to be able to iterate both over rows and columns but I'd rather not make two different kinds of iterators. </p>
<p>I'm so... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-02T17:56:28.920",
"Id": "41671",
"Score": "0",
"body": "Looks familiar."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-02T17:57:21.347",
"Id": "41672",
"Score": "0",
"body": "Don't use ALL CAPS... | [
{
"body": "<p>Your design seems rather confused. You generally want iterators to be retrievable only from member functions of a class - the user shouldn't have to manually \"create\" an iterator. Secondly, you don't really need to create your own iterator types here. Your classes are fairly simple wrappers arou... | {
"AcceptedAnswerId": "26827",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T02:06:09.693",
"Id": "26825",
"Score": "1",
"Tags": [
"c++",
"csv"
],
"Title": "Custom template iterator on CSV reading class"
} | 26825 |
<p>So far, the below code appears to work well. It operates pretty fast, but I was wondering if it's possible to make it faster. I'm also looking for general tips on what I might be doing wrong and what I could do better. I have added in comments to explain certain decisions.</p>
<p><strong>b64.h</strong>
</p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T02:38:46.890",
"Id": "41561",
"Score": "0",
"body": "I thought we have abundance of stock base64 implementations and no one recreates the wheel. Do you have a reason to think those are too slow or that yours needs actual speed optim... | [
{
"body": "<p>I only really looked at <code>ascii_to_base64</code>.</p>\n\n<p>Firstly, you say that the code is \"pretty fast\", but why is that a\nconsideration? Don't assume that execution speed is necessarily important.\nReadability and correctness are more so.</p>\n\n<p>On correctness, your code does not h... | {
"AcceptedAnswerId": "26860",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T02:21:12.077",
"Id": "26826",
"Score": "4",
"Tags": [
"optimization",
"c",
"base64"
],
"Title": "Speed optimisation and general tips for base64 encoding/decoding functions in C... | 26826 |
<p>I'm implementing a "tags" features to an already working solution. </p>
<p>Final users need to be able to add tags to three separate sections of the solution:</p>
<ul>
<li><code>Posts</code></li>
<li><code>Accounts</code></li>
<li><code>Groups</code></li>
</ul>
<p>Each section has its corresponding table in the d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T08:29:36.217",
"Id": "41572",
"Score": "1",
"body": "You have to split your `tagmap` table to `tag_post`, `tag_group` and `tag_account`.\n\nThis is also evident from: \"_Final users need to be able to add tags to three different sec... | [
{
"body": "<p>As @abuzittingillifirca said, this isn't very normalized. Summarizing my own opinion and what I've generally gathered from the net, you'll want to normalize it completely, test it with real data, then optimize the heck out of your configuration and queries before thinking about denormalization. Wi... | {
"AcceptedAnswerId": "26856",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T02:54:25.820",
"Id": "26828",
"Score": "4",
"Tags": [
"sql",
"mysql"
],
"Title": "Schema for allowing adding tags to entities in unrelated tables"
} | 26828 |
<p>Is there a better way to do this? If I ever have to worry about earlier images not being loaded before the later images, i.e. image[3] being loaded after image[21]. I have to load about 100 images at the start.</p>
<pre><code>for (var i = 0; i < 22; i++) {
images[i] = new Image();
images[i].src = whatever... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T08:06:30.803",
"Id": "41571",
"Score": "1",
"body": "Are you sure this works? Can we see a demo?"
}
] | [
{
"body": "<h1>Sprite!</h1>\n\n<p>I suggest you place the images in a single image, like a \"sprite sheet\". This means that you need to pre-assemble the images into one image, load that single image and draw it on the canvas. </p>\n\n<p>That way:</p>\n\n<ul>\n<li>You only load one image, thus reducing your htt... | {
"AcceptedAnswerId": "26835",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T06:11:20.867",
"Id": "26833",
"Score": "2",
"Tags": [
"javascript",
"image",
"html5"
],
"Title": "Using a single for loop to load multiple images in a canvas"
} | 26833 |
<p>For a session implementation I needed a <em>property</em> that caches its getter (since it involves a database lookup) but still allows modifications (e.g. assigning a new user and storing that user's id in the session). To make this as comfortable as possibly I subclassed <code>property</code> and added the caching... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-12T05:32:15.703",
"Id": "46858",
"Score": "0",
"body": "Not sure if this'll be used in a multi-threaded context, but if so you may want to a) lock around the cache accesses and b) invalidate the cache before setting/deleting, instead o... | [
{
"body": "<p>If you can afford to make your class <code>hash</code>able, and you read more often than you need to update the values inside (because an update to any property will invalidate the cache for all the other ones, and for this reason I set the <code>maxsize</code> to 1), it's probably much simpler to... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T09:44:26.980",
"Id": "26836",
"Score": "8",
"Tags": [
"python",
"lookup"
],
"Title": "Python property() implementation that caches getter while still allowing a setter"
} | 26836 |
<p>I have this working code that selects which method to call based on values in
the parameter:</p>
<pre><code>@Override
public Iterator<DBObject> __find(DBObject ref, DBObject fields,
int numToSkip , int batchSize , int limit, int options){
Preconditions.checkNotNull(ref, "Reference object can't b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T21:02:42.987",
"Id": "41608",
"Score": "0",
"body": "The `it` variable you declare all along, in each branch, doesn't really have a use... What is more, there is no need to `else` if you `return`."
}
] | [
{
"body": "<p>One possibility is to create a method that accepts all possible parameters, and have that method gracefully handle <code>null</code> values, or use the <a href=\"http://en.wikipedia.org/wiki/Null_Object_pattern\" rel=\"nofollow\"><em>Null Object</em> pattern</a> for those parameters. <code>getSort... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T09:49:26.770",
"Id": "26837",
"Score": "4",
"Tags": [
"java"
],
"Title": "Method Selection Engine"
} | 26837 |
<p>I was working on a sorting algorithm for my linked list implementation and wanted to get other people's input/comments/critique. What do you think of it in all aspects, including style?</p>
<p>I was told that it is preferred to use a bool type for the <code>changeFlag</code> instead of using an int as it makes it m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-01T20:51:06.310",
"Id": "41640",
"Score": "0",
"body": "If you asked me, sorting a linked list is rather pointless. If you needed to sort a list, you wouldn't use a linked list. There are other list types better suited for sorting and ... | [
{
"body": "<p>Giant problem that I see: your for loop is completely redundant. You go through the entire list in the inner while loop and then just continue checking the condition N times before you finish the outer for loop.</p>\n\n<p>I think that you're taking an approach which is overly complicated for the g... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T10:26:16.150",
"Id": "26839",
"Score": "5",
"Tags": [
"c++",
"sorting",
"linked-list"
],
"Title": "Linked List Sorting Algorithm"
} | 26839 |
<p>The general idea of this function is to load a different sound file depending on current time position of the video. I have the following information about audio files:</p>
<pre><code>var samples: [
['00:00:05', 'audio/1.mp3'],
['00:01:00', 'audio/2.mp3']
]
</code></pre>
<p>The first element contains the end time... | [] | [
{
"body": "<p>You want to play a certain audio at a certain time? Well, you're in luck. I recently did this in a demo. It wasn't playing audio with video though. It was triggering animations at certain points of the audio, but it should be the same idea.</p>\n\n<p><code><audio></code> and <code><video&... | {
"AcceptedAnswerId": "26849",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T14:17:53.027",
"Id": "26844",
"Score": "4",
"Tags": [
"javascript",
"html5",
"audio"
],
"Title": "Playing different audio files based on video keyframe"
} | 26844 |
<p>I would like to see if the working code below can be written more elegantly. I am assuming there is a way to parse out the "r" and "h" to condense it down into a function. Any help is much appreciated for learning purposes. There are no parent/sibling relationships in the ID's.</p>
<pre><code> $('#r1_1').hoverIn... | [] | [
{
"body": "<p>A basic function for running it could be</p>\n\n<pre><code>function hi(n1, n2) {\n var r = '#r'+n1+'_'+n2;\n var h = '#h'+n1+'_'+n2;\n $(r).hoverIntent(function() {\n $(h).toggleClass('vis');\n });\n}\n</code></pre>\n\n<p>However, it's possible to trim this down more by creating an ar... | {
"AcceptedAnswerId": "26852",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T15:43:03.933",
"Id": "26847",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "JQuery hover with multiple ID's"
} | 26847 |
<p>I'm building a website that is used to search our system. The users can search on a lot of critera at once. As I try to do this though, I can't figure out how to simplify this horrible action.</p>
<pre><code>public ActionResult Search(SearchViewModel model)
{
Expression<Func<Parcel, bool>> filtere... | [] | [
{
"body": "<p>I imagine you want to get rid of repetitive <code>if/And</code> blocks. To do that, you may start by generalizing the following pattern (note: I'm using <code>object</code> since you haven't specified the precise types you use; in your case, <code>object</code> will be replaced by something more s... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T16:46:43.690",
"Id": "26850",
"Score": "4",
"Tags": [
"c#",
"mvc"
],
"Title": "How can I refactor my Controller Action to not be so complex?"
} | 26850 |
<p>Can someone explain me how this code works or if it is possible to be written in another way? I tried it with just ArrayList but cannot figure it out.</p>
<pre><code>public static Set<Set<Integer>> combinations(List<Integer> groupSize, int k) {
Set<Set<Integer>> allCombos = new Ha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T17:46:59.223",
"Id": "41597",
"Score": "0",
"body": "What is the showTeam() method?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T17:50:18.320",
"Id": "41598",
"Score": "0",
"body": "My ... | [
{
"body": "<p>Basically the algorithm returns all subsets of <code>groupSize</code> (which should really be renamed to <code>group</code>), that have <code>k</code> elements.</p>\n\n<p>The method works recursively. To do so it needs two things : establish primitive cases that end the recursion, and a way of for... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T17:40:51.027",
"Id": "26854",
"Score": "0",
"Tags": [
"java",
"recursion"
],
"Title": "Recursive method to return a set of all combinations"
} | 26854 |
<p>It's a (simple) guesser for game where you need to find words of a given length only using given letters. I'd like to know if there's a more pythonic way to do things here.</p>
<pre><code>#!/usr/bin/env python3
import sys
if len(sys.argv) < 3:
sys.exit("Usage: " + sys.argv[0] + " letters number_of_letters [... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-06T10:08:26.137",
"Id": "41988",
"Score": "1",
"body": "checkout [argparse](http://docs.python.org/3.3/library/argparse.html). It's awesome! Also, it's worth avoiding making the wordlist upfront and instead iterating over the file obje... | [
{
"body": "<p>The following code shows I would have done what you asked in Python 2.7. Other readers will tell you the ways in which it is a) not Pythonic and b) wrong.</p>\n\n<ul>\n<li><p>Start with a module comment describing what the code is intended to do. (This is available to the code as <code>__doc__</co... | {
"AcceptedAnswerId": "26864",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T20:54:36.020",
"Id": "26857",
"Score": "5",
"Tags": [
"python",
"python-3.x"
],
"Title": "Finding words of a given length only using given letters"
} | 26857 |
<p>I am working on a project that involves XML parsing, and for the job I am using xml.dom.minidom. During development I identified several patterns of processing that I refactored into discrete methods. The code shown in the snippet below shows my definition of an <code>Article</code> class that is instantiated during... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-01T00:12:55.770",
"Id": "41611",
"Score": "2",
"body": "Maybe you should use composition? OK, as a rule, I despise monkey patching, but composition is a good way to \"hide\" what is wrong with older/crappy implementations."
}
] | [
{
"body": "<p>The problem here is the minidom API is a well known API. Someone new to the code needs to know that you monkey patched it and why you did it. Otherwise they would be scouring the minidom docs looking for your methods. This is generally why monkey patching is a bad idea because it can be confusing ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-31T21:10:10.193",
"Id": "26859",
"Score": "5",
"Tags": [
"python",
"xml",
"python-3.x"
],
"Title": "Using a monkey-patched XML parser to convert journal articles to ePub format"
} | 26859 |
<p>I have been doing some Code School classes on jQuery, and I needed a image slider for my site. Right now, there are only two responsive states, but that will most likely change (and/or become fluid later).</p>
<p>I was just wondering if there are any best practices or general clean up I can do to the code. I'm sti... | [] | [
{
"body": "<ul>\n<li><p>For variable and function names, use <code>camelCase</code>. For constants, or at least variables that are used as constants, use <code>ALLCAPS_AND_UNDERSCORES</code>. For constructor functions, use <code>TitleCaps</code> (I forgot how they called this). This is a convention which is com... | {
"AcceptedAnswerId": "26866",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-01T00:15:13.937",
"Id": "26863",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"datetime",
"image",
"mobile"
],
"Title": "Responsive image slider"
} | 26863 |
<p>I wrote a small script to analyse spam messages that are spam <em>false negative</em>; meaning that they are spam messages in nature but that happened to be in your <em>INBOX</em> folder because your spam filter failed to detect it correctly (I personally use SpamAssassin and unfortunately it rarely happens).</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-07T06:52:32.823",
"Id": "42094",
"Score": "0",
"body": "Interesting script, but it's a bit of a tall order to do all of these things. If you focus on either a single language (and show us the code if it's not PHP), you probably have a ... | [
{
"body": "<p>Here's an <em>untested</em> Bash version:</p>\n\n<pre><code>#!/usr/bin/env bash\nset -o errexit -o noclobber -o nounset\n\nwhile IFS= read -r -u 9 path\ndo\n /usr/bin/sa-learn --spam \"$path\" \\\n > \"/home/domainexample.ru/.spamassassin/logs/$(date +%d.%m.%Y-%G:%S)_analyzer.log\" \\... | {
"AcceptedAnswerId": "27165",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-01T10:09:25.920",
"Id": "26871",
"Score": "1",
"Tags": [
"php",
"bash",
"perl"
],
"Title": "SpamAssassin spam analyzer script in PHP based on sa-learn command"
} | 26871 |
<p>I have two tables (<code>a</code> and <code>b</code>) which have both one <code>date</code> field of type <code>TIMESTAMP</code>. They represent two different type of actions (records): table <code>a</code>'s actions are $200 worth each, while table <code>b</code>'s ones worth $500. </p>
<p>I want to calculate the ... | [] | [
{
"body": "<p>You might try this:</p>\n\n<pre><code>select\n sum(amount) amount\nfrom(\n select\n least(sum(amount),10000) amount\n from (\n select date,\n 200 amount\n from a\n union all\n select date,\n 500 amount\n from b) list_of_all\n group by\n date(date)) ... | {
"AcceptedAnswerId": "26875",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-01T12:40:19.777",
"Id": "26872",
"Score": "2",
"Tags": [
"sql",
"postgresql"
],
"Title": "Summing different tables values limiting the results"
} | 26872 |
<p>This is a utility class I have in one of my projects and I seek feedback on it. I have read the <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Locale.html" rel="nofollow">javadoc for <code>Locale</code></a> quite a few times while developing this code. I think I have it right, but maybe there are holes... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-02T18:22:52.687",
"Id": "41678",
"Score": "2",
"body": "That's some neat code and good documentation, very nice job! The only thing I can see is your declaration of `len`, which you use only one time and happily not use it the next tim... | [
{
"body": "<p>In general, your code is well structured, and well documented.</p>\n\n<p>As for the <code>-1</code> requirement for <code>split</code>, Java has done <em>the right thing</em> by keeping the behaviour consistent with the <a href=\"http://perldoc.perl.org/functions/split.html\" rel=\"nofollow\">Perl... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-01T19:06:41.840",
"Id": "26877",
"Score": "8",
"Tags": [
"java",
"parsing",
"i18n"
],
"Title": "Locale-related code -- are there corner cases I didn't see?"
} | 26877 |
<p>I wrote this program for sorting an array of type <code>String</code> alphabetical without using <code>compareTo()</code> method so I am saying that if you can find errors in my program please tell me I will try to fix it.</p>
<pre><code>class some{
public static void main(String[] args) {
String array[]={"name... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-02T06:50:42.133",
"Id": "41654",
"Score": "0",
"body": "Currently it's incorrect, given an initial array of `{\"dds\", \"dda\"}`, it fails to sort them properly."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013... | [
{
"body": "<p>First off, your use of whitespace is a mess, fix it. Press \"Format Code\" in your favorite IDE or do it manually.</p>\n\n<hr>\n\n<pre><code>class some{\n</code></pre>\n\n<ul>\n<li><a href=\"http://www.oracle.com/technetwork/java/codeconv-138413.html\" rel=\"nofollow\">The Java Naming Conventions<... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-01T21:12:50.650",
"Id": "26880",
"Score": "2",
"Tags": [
"java",
"array",
"sorting"
],
"Title": "Sorting an array"
} | 26880 |
<p>I am trying to learn how to animate with tkinter. The code below is an example I was able to build. It creates a small 5x5 map of cubes, then one of them randomly moves around the screen (preferably on the map, but it can wander off).</p>
<p>Is this a good way to do it? Is there a more pythonic, or more efficient ... | [] | [
{
"body": "<p>Here is anoted version of your code</p>\n\n<pre><code>from tkinter import *\nfrom time import sleep\nfrom random import randrange\n\n# lowercase tkinter suggest you are using python3, in this case\n# inheriting (object) is not needed anymore to create newstyle\n# class\nclass alien(object):\n d... | {
"AcceptedAnswerId": "26893",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-02T04:47:23.233",
"Id": "26885",
"Score": "2",
"Tags": [
"python",
"optimization",
"animation",
"tkinter",
"tk"
],
"Title": "Animation with 5x5 map of cubes"
} | 26885 |
<p>I have the following code in Java:</p>
<p><code>HangmanFunctions</code> class:</p>
<pre><code>import java.util.ArrayList;
import java.util.Random;
public class HangmanFunctions {
private static final String[] WORDS = {"jazz", "buzz", "hajj", "fuzz", "jinx",
"jazzy", ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-03T01:31:35.247",
"Id": "41696",
"Score": "0",
"body": "I started to work on the changes needed, but it's too much work. Basically, separate your one JPanel into two JPanels. One JPanel for the left side of your game, and another JPa... | [
{
"body": "<h1>Overview</h1>\n\n<p>Separate the game's entry point, model, the view, and the controller into different classes:</p>\n\n<ul>\n<li>HangmanGame - The main entry point to the application.</li>\n<li>HangmanModel - Contains information about the word being guessed.</li>\n<li>HangmanView - Displays the... | {
"AcceptedAnswerId": "26907",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-02T19:06:36.110",
"Id": "26898",
"Score": "4",
"Tags": [
"java",
"game",
"swing",
"hangman"
],
"Title": "Hangman in Java"
} | 26898 |
<p>I have a function in the C++ program, which does simple computations and writes result to two arrays - <code>result[53]</code> and <code>var1_new[53]</code>. It contains two code blocks:</p>
<p>The first one -</p>
<pre><code>double result[53];
result[0] = ((var1[13] * 1) + (var2[7] * 2)) / var3[0];
result[1] = ((... | [] | [
{
"body": "<p>First, <strong>magic constants are bad</strong>, you should name them</p>\n\n<pre><code>int const N = 53;\ndouble result[N];\n</code></pre>\n\n<p>Second, <strong>magic patterns are even worse</strong>, you should also name them along with <strong>documentation comments</strong></p>\n\n<pre><code>/... | {
"AcceptedAnswerId": "27029",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-03T07:39:11.133",
"Id": "26909",
"Score": "2",
"Tags": [
"c++",
"array"
],
"Title": "Making complex array initializations more readable"
} | 26909 |
<p>How to optimize below code to reduce code with better performance? </p>
<pre><code>import java.util.Scanner;
public class ConsoleCalculatorImproved
{
static boolean ERROR = true;
public static void main(String[] m)
{
String arg ;
ConsoleCalculatorImproved cC = new ConsoleCalculatorImpr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-03T11:15:03.333",
"Id": "41718",
"Score": "1",
"body": "Maybe you should tell us what this code does, how it works and why it works the way it works?"
}
] | [
{
"body": "<p>You need to compile and interpret a programming language, even though your language is rather simple expression language. Write <a href=\"http://en.wikipedia.org/wiki/Recursive_descent_parser\" rel=\"nofollow\">recursive descent parser</a> or use <a href=\"http://www.antlr.org/wiki/display/ANTLR3/... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-03T08:23:47.317",
"Id": "26911",
"Score": "2",
"Tags": [
"java"
],
"Title": "How to write this program efficiently and much shorter?"
} | 26911 |
<p>I wrote a web spider that I would like to download and parse pages concurrently. Here is what I am trying to achieve:</p>
<ol>
<li>instantiate a new instance of the class with the $startURL as the constructor</li>
<li>spider $startURL with the public concurrentSpider() function</li>
<li>foreach of the links found a... | [] | [
{
"body": "<p>It look like the first link on every page of the site is the same (e.g. the link on a logo) and the children processes are simply printing this (correctly) so it looks like incorrect behavior, but isn't.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicens... | {
"AcceptedAnswerId": "26985",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-03T09:54:10.260",
"Id": "26913",
"Score": "1",
"Tags": [
"php",
"multithreading",
"concurrency"
],
"Title": "Review of concurrent php logic for a web spider class"
} | 26913 |
<p>What is the best practice to output a list of prime numbers between two numbers?
How can I achieve a better running time? This is a solution to a <a href="http://www.spoj.com/problems/PRIME1/" rel="nofollow">SPOJ problem</a> which is getting Time Limit Exceeded.</p>
<pre><code>import java.io.BufferedReader;
import ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-03T12:58:02.073",
"Id": "41723",
"Score": "3",
"body": "The best practice is to take your problem and break it into many tiny steps. I can't guarantee it will run faster. I can guarantee it will be easier for mere mortals to understa... | [
{
"body": "<p>I followed my own advice, and broke the <a href=\"http://www.spoj.com/problems/PRIME1/\" rel=\"nofollow\">SPOJ problem</a> into many tiny steps.</p>\n\n<p>The first thing I did was create a class to hold the prime ranges that are given as input. The <code>PrimeRange</code> class is a basic getter... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-03T11:32:10.303",
"Id": "26916",
"Score": "4",
"Tags": [
"java",
"programming-challenge",
"primes",
"time-limit-exceeded"
],
"Title": "Outputting prime numbers between two number... | 26916 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.