body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I have the following task:</p>
<blockquote>
<p>The Shallow Alto city council has organized a special committee to
review the traffic situation in the city. Despite the fact that there
is nothing whatsoever to do in the city, citizens still write
complaints about the amount of time it takes them to get from ... | [] | [
{
"body": "<h1>Naming</h1>\n\n<p>I strongly recommend you read through the official <a href=\"http://msdn.microsoft.com/en-us/library/vstudio/ms229002%28v=vs.100%29.aspx\" rel=\"nofollow noreferrer\">C# naming conventions</a>. Here are a few rules to keep in mind:</p>\n\n<ul>\n<li>Properties are UpperCamelCase<... | {
"AcceptedAnswerId": "50923",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T14:33:24.313",
"Id": "50918",
"Score": "11",
"Tags": [
"c#",
"object-oriented",
"design-patterns"
],
"Title": "Problem: Traffic Flow"
} | 50918 |
<p>I wrote this script a few days ago to find all files which were taking up over a certain threshold of memory on the hard drive. A hard drive on one of my computers had just 6 GB left, so I needed to clean some space up. I used this to identify bulky folders to find out where the problem was.</p>
<p>Is there anyth... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:05:25.610",
"Id": "87855",
"Score": "1",
"body": "For lisibility purposes, I'd rather read `BYTES_IN_GIGABYTE = 2**30`."
}
] | [
{
"body": "<p><code>ACCESS_ERROR_CODE</code> is <code>errno.EACCES</code>.</p>\n\n<p><code>BYTES_IN_GIGABYTE</code> is clearer as <code>2**30</code>. That's transparent enough that the constant and <code>convert_bytes_to_gigabytes</code> aren't needed, so I'd just write <code>folder[1] / 2**30</code>.</p>\n\n<p... | {
"AcceptedAnswerId": "50926",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T14:35:07.140",
"Id": "50919",
"Score": "4",
"Tags": [
"python",
"recursion",
"python-3.x",
"exception-handling",
"file-system"
],
"Title": "Python script to find large ... | 50919 |
<p>The code should be relatively self-explanatory. I was wondering how much rep the Top Voters on sites did "generate" on a site, in comparison to how much rep they "own".</p>
<p>Therefore I created a little SEDE-Query and I am now wondering, if I follow good SQL-Practices and how the performance of the query could po... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:33:33.367",
"Id": "87871",
"Score": "0",
"body": "I think the ratio column name could be better, is lower better or higher better. Since I have the lowest score, does that make me a vampire on CR, or more like a blood donor ? :)"... | [
{
"body": "<p>First of all, when you are selecting and want to perform mathematics on it you should directly specify what you want done</p>\n\n<p>instead of </p>\n\n<pre><code>Voters.Upvotes * 8 as [EstimatedAddedRep], \n</code></pre>\n\n<p>it should be </p>\n\n<pre><code>(Voters.Upvotes * 8) AS [EstimatedAdded... | {
"AcceptedAnswerId": "50921",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T14:49:12.213",
"Id": "50920",
"Score": "10",
"Tags": [
"performance",
"sql",
"sql-server",
"stackexchange"
],
"Title": "SEDE-Query for Rep-Trivia"
} | 50920 |
<p>This is my first User model I created.</p>
<p>And I wanted to know if there are any good ways I can improve my code? It works with sessions, database and cookies.</p>
<p>I feel like some parts are somewhat written in a weird way, like in my constructor.</p>
<p>I would like to have my code as modular as possible, ... | [] | [
{
"body": "<p>There are a couple of things that I would personally change about the code, at the moment the model is doing far too much. It's pulling in cookies, request parameters and accessing the database. That's not the responsibility of the model, any domain logic should be separated from the models themse... | {
"AcceptedAnswerId": "50948",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:23:49.453",
"Id": "50925",
"Score": "2",
"Tags": [
"php"
],
"Title": "Making my User model class code more modular, and correct"
} | 50925 |
<p>This is based on a very similar question I asked, found <a href="https://codereview.stackexchange.com/questions/49780/change-random-list-of-numbers-into-all-5s-using-simple-evolution-simulation">here</a>.</p>
<p>The intent of this program is to start with a set number of random strings of zeros and ones, and eventu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:31:02.743",
"Id": "87869",
"Score": "0",
"body": "*\"I believe it fulfills [sic] its purpose\"* - have you tested it?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:34:05.713",
"Id": "87872... | [
{
"body": "<p>One thing that immediately jumped out:</p>\n\n<pre><code>def KillOld(strings):\n for _ in strings:\n if _.age > 2:\n strings.remove(_)\n</code></pre>\n\n<p><code>_</code> is used by convention to indicate \"I won't be using this variable\", e.g.:</p>\n\n<pre><code>for _ in ... | {
"AcceptedAnswerId": "50929",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:28:04.107",
"Id": "50927",
"Score": "3",
"Tags": [
"python",
"strings",
"random"
],
"Title": "Simple evolutionary string matching"
} | 50927 |
<p>Let's say we've got some SQL queries and want to display the results. Processing takes some time, so I do it multi-threaded.
The following works quite well for me. I reduced the code to the important parts and would be glad to get some comments on it:</p>
<p>Queries and results are stored in thread safe collections... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:48:13.747",
"Id": "87876",
"Score": "0",
"body": "What is still not clear: Is it getting the answer or processing the answer what takes longer and so requires multiple threads?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p><code>Thread.sleep</code> is usually a red flag in code, especially when used to emulate a blocking call. If you choose a different approach, such as using <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CompletionService.html\" rel=\"nofollow\">CompletionService</a>, you ... | {
"AcceptedAnswerId": "50977",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:46:34.883",
"Id": "50928",
"Score": "0",
"Tags": [
"java",
"multithreading",
"concurrency"
],
"Title": "Continually process results of multi-thread worker"
} | 50928 |
<p>If you can't afford the extra level of indirection, that comes with PIMPL, use the <code>implstore</code>! Improvements?</p>
<pre><code>#ifndef IMPLSTORE_HPP
# define IMPLSTORE_HPP
# pragma once
#include <cstddef>
#include <new>
#include <type_traits>
#include <utility>
template <cla... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T16:12:27.697",
"Id": "87885",
"Score": "0",
"body": "Maybe it would help if you explained what you're trying to do..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T19:15:02.667",
"Id": "87928",
... | [
{
"body": "<pre><code>new (store_) U;\n</code></pre>\n\n<p>You should explicitly cast to a <code>void*</code> to avoid calling any user-defined allocation functions instead of placement-new.</p>\n\n<pre><code>void (*deleter_)(implstore&){};\n</code></pre>\n\n<p>To my eyes, this is quite ugly. It almost look... | {
"AcceptedAnswerId": "50970",
"CommentCount": "22",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:54:16.460",
"Id": "50931",
"Score": "4",
"Tags": [
"c++",
"c++11"
],
"Title": "instead of PIMPL, use the implstore"
} | 50931 |
<p>I have written a piece of MATLAB code that (hopefully) calculates <a href="http://www.nature.com/npp/journal/v39/n2/full/npp2013224a.html" rel="nofollow">CECT</a>. I have two matrices of psychophysiological measures - one for brain data, one for heart rate; both are of the format epochs * times (i.e., multiple epoch... | [] | [
{
"body": "<p>With this random data and a few tweeks I got the time reduced about 30 times. The inner loop can be taken outside which is the biggest difference.</p>\n\n<pre><code>clear all\n\nn=800;\ndata = randn(2,n,30);\ntimes=linspace(-1900,8600,n);\n\ntic;\n\nsamplingrate = 200;\nscalefac = 1000/samplingrat... | {
"AcceptedAnswerId": "51082",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:54:32.633",
"Id": "50932",
"Score": "2",
"Tags": [
"performance",
"matrix",
"matlab"
],
"Title": "Less For, more MATLABesque?"
} | 50932 |
<p><strong>The Issue</strong> </p>
<ol>
<li><p>I added SSL to a previously static and non-SSL website because some new features will require it. I'm using rails 4.0.5, ruby 1.9.3, and the site is deployed on heroku (it's at www dot palleylaw com).</p></li>
<li><p>The newly SSL site included content from my non-SSL blo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-12-03T22:05:30.237",
"Id": "130843",
"Score": "0",
"body": "1) Example XML please? 2) How is the origin of your XML maintained? Is there any way for your app to find out when it changes?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T16:05:07.837",
"Id": "50934",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails",
"xml",
"https",
"rss"
],
"Title": "Displaying blog posts from non-SSL site in SSL site"
} | 50934 |
<p>I'm new to Haskell, and I'm wondering why my programs are so slow compared to other languages.</p>
<p>Haskell, 6 seconds (x64, -O2):</p>
<pre class="lang-haskell prettyprint-override"><code>nextCollatz :: Int -> Int
nextCollatz x = if even x
then quot x 2
else 3 * x + 1
collatzLength :: Int -> Int
c... | [] | [
{
"body": "<p>Your initial version - 6.834 seconds.</p>\n\n<p>Version with <code>quot</code> and <code>even</code> operations replaced with bitwise - 6.651 seconds.</p>\n\n<p>This version - 0.928 seconds:</p>\n\n<pre><code>import Data.Bits\n\ntOdd sum 1 = sum\ntOdd sum x = tEven (sum + (tEven2 0 x)) (x - 1)\n\n... | {
"AcceptedAnswerId": "50958",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T16:51:43.623",
"Id": "50939",
"Score": "3",
"Tags": [
"optimization",
"performance",
"beginner",
"haskell",
"comparative-review"
],
"Title": "Efficient Collatz sequence... | 50939 |
<p>I'm working on a libcurl binding for NodeJS, and to get info from a curl handler, using <code>curl_easy_getinfo</code>, I've created a template function, the issue, is that the result of the call can be a null pointer.</p>
<p>To make sure this was correctly addressed, I've created a template specialization that han... | [] | [
{
"body": "<p>The check is better factored into a specialization on a traits class. This allows you to have one implementation of the overall logic flow, and just specialize the part that changes. I haven't fully researched the implications of this approach, but I expect that due to the always true/false nature... | {
"AcceptedAnswerId": "50994",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T17:38:32.900",
"Id": "50943",
"Score": "5",
"Tags": [
"c++",
"beginner",
"node.js",
"template-meta-programming"
],
"Title": "Template function specialization with code dupl... | 50943 |
<p>I have created this little dropdown directive in Angular. The idea is that you create a nav element with a ul inside. The directive prepends a chevron and toggles <code>scope.visible</code> when you click it. Two functions watch <code>scope.visible</code>, the first folds the dropdown, and the second reverses the ch... | [] | [
{
"body": "<p>The <a href=\"http://www.faqs.org/docs/artu/ch01s06.html\" rel=\"nofollow\">Rule of Simplicity</a> is getting neglected a bit, but broadly, this code\nisn't bad.</p>\n\n<p>You're doing a fairly simple thing here, so the code would me clearer with less\nindirection. You don't need to abstract away ... | {
"AcceptedAnswerId": "51583",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T17:44:53.160",
"Id": "50944",
"Score": "8",
"Tags": [
"javascript",
"jquery",
"angular.js"
],
"Title": "Angular dropdown"
} | 50944 |
<p>I have a solution for pretty printing physical values with the correct suffix (kilo, mega etc.).</p>
<p>I'd like to discuss my solution with you.</p>
<pre><code># -*- coding: utf-8 -*-
import math
def eng_format(x, unit=''):
e =(math.floor(math.log10(x))//3)*3
sL = ['f', 'p', 'n', 'u', 'm', '', 'k', 'M', ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T22:23:06.313",
"Id": "87947",
"Score": "0",
"body": "In this day and age, you should really use `str.format` e.g. `'*10^{0} '.format(e)` rather than `'*10^%d '%e`"
}
] | [
{
"body": "<h3>Unit testing</h3>\n\n<p>When developing a utility function like this it's good to create unit tests so you can refactor safely, knowing when you break something. Let's say your code above is in a file called <code>prettyprint.py</code>, you could create a file with unit tests in <code>prettyprint... | {
"AcceptedAnswerId": "50971",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T18:00:30.803",
"Id": "50945",
"Score": "6",
"Tags": [
"python"
],
"Title": "Pretty print with unit and physical suffix"
} | 50945 |
<p>I am trying to write a spellchecker and I wanted to use difflib to implement it. Basically I have a list of technical terms that I added to the standard Unix dictionary (<code>/usr/share/dict/words</code>) that I'm storing in a file I call dictionaryFile.py.</p>
<p>I have another script just called stringSim.py whe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-11-12T19:32:13.987",
"Id": "127202",
"Score": "0",
"body": "I had a similar issue with efficiency and used the Levenshtein module on pypi: http://stackoverflow.com/a/26894959/4085463"
}
] | [
{
"body": "<p>Using <code>difflib</code> is probably the best choice. So the problem comes down to the size of your word list. If we can pare down the number of words <code>difflib</code> needs to compare, then we could get a faster time.</p>\n\n<p>One idea to implement, is take only words that are <em>near-eno... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T18:04:45.353",
"Id": "50947",
"Score": "4",
"Tags": [
"python",
"python-2.x"
],
"Title": "Searching a dictionary of words using difflib"
} | 50947 |
<p>I'm writing a financial app that has to get data over a set of dates.</p>
<p>The user specifies the start date, end date, and frequency from a list of choices. (daily, weekly, monthly, quarterly, semi, annually).</p>
<p>There's also a preference option that allows the user to choose whether each period should be t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T19:06:06.977",
"Id": "87926",
"Score": "0",
"body": "oh yeah, I know I should use LINQ to build up the list, but business reasons require .NET 2.0."
}
] | [
{
"body": "<h1>Naming</h1>\n\n<p>I highly recommend you read through the <a href=\"http://msdn.microsoft.com/en-us/library/vstudio/ms229002%28v=vs.100%29.aspx\">C# naming conventions</a>. Highlights are:</p>\n\n<ul>\n<li>Private fields are lowerCamelCase, sometimes prepended with an underscore</li>\n<li>Propert... | {
"AcceptedAnswerId": "50959",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T18:53:41.587",
"Id": "50951",
"Score": "5",
"Tags": [
"c#",
".net",
"finance",
"delegates"
],
"Title": "Financial app for retrieving data over a set of dates"
} | 50951 |
<p>I am trying to make the CommandTimeout value more configurable. I'm wondering if this is best practice to do so?</p>
<p>I add the following to my <code><appsettings></code> node in my Web.config file:</p>
<pre><code><add key="commandTimeValue" value ="60"/>
</code></pre>
<p>The I added the following ... | [] | [
{
"body": "<p>I do not like the name <code>myDAL</code> as a class name. It is very cryptic and does not follow C# naming conventions. I would prefer <code>DataAccessLayer</code> or <code><entity>DataAccessLayer</code> where <code><entity></code> is the name of the class the DAL is for.</p>\n\n<p>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T18:55:32.913",
"Id": "50952",
"Score": "2",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Making the objectContext.CommandTimeout configurable?"
} | 50952 |
<p>I'm using the following function to index ebook data with Lucene. I'm looking to improve the structure and organization of this function.</p>
<pre><code>public string BuildIndex(int pageNum, int pageSize)
{
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
var version = Lucene.Net.Util.Ver... | [] | [
{
"body": "<p>I'm glad you are using <code>using</code> for your iwriter.</p>\n\n<p>I also like the one comment you have included. It states why the next line of code does what it does, not what it is doing.</p>\n\n<p>The return value should be a <code>long</code> rather than a <code>string</code>. I think th... | {
"AcceptedAnswerId": "50985",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T19:24:18.250",
"Id": "50957",
"Score": "4",
"Tags": [
"c#",
"lucene"
],
"Title": "Indexing data with Lucene.net"
} | 50957 |
<p>I have a table <code>Bill</code> containing <code>Bills</code> with 0...n relationships to <code>Material</code> and <code>Activity</code> (line items on the bill).</p>
<p>My SQL query is essentially bill left join material left join activity. </p>
<p>I have the following insanely tangled code to transform the re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-02T02:56:10.393",
"Id": "91464",
"Score": "1",
"body": "I don't know Scala, I think your SQL looks fine. I would really like to see someone with Scala knowledge answer this."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>I was hoping someone would review your <a href=\"/questions/tagged/scala\" class=\"post-tag\" title=\"show questions tagged 'scala'\" rel=\"tag\">scala</a> but I don't think it's going to happen. So I thought I would at least say something about <a href=\"/questions/tagged/sql\" class=\"po... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T19:43:40.543",
"Id": "50961",
"Score": "4",
"Tags": [
"sql",
"functional-programming",
"scala"
],
"Title": "Neatly Transforming Anorm ResultSet Into Map[Parent , (Set[Child1], Se... | 50961 |
<h2>The Program</h2>
<p>I wrote this program as an answer to a question I thought of for <a href="https://codegolf.stackexchange.com/questions/27054/optimally-solve-the-flux-puzzle">Programming Puzzles and Code Golf</a>. To avoid cross-posting, I will only summarize the requirements:</p>
<ul>
<li>Solve a game in a 3x... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T20:42:16.467",
"Id": "87935",
"Score": "8",
"body": "I totally agree with your commenting philosophy! ;)"
}
] | [
{
"body": "<p>Why do you need to create a Variable here?</p>\n\n<pre><code>@Override\npublic void run() {\n computeAllBoards(template);\n solveAllBoards();\n\n Scanner c = new Scanner(System.in);\n while (c.hasNext()) {\n String input = c.nextLine(); // <----\n printSolution(input)... | {
"AcceptedAnswerId": "51445",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T20:24:20.497",
"Id": "50962",
"Score": "10",
"Tags": [
"java",
"game",
"guava"
],
"Title": "Solve the game \"Flux\""
} | 50962 |
<blockquote>
<p>The number, 1406357289, is a 0 to 9 pandigital number because it is
made up of each of the digits 0 to 9 in some order, but it also has a
rather interesting sub-string divisibility property.</p>
<p>Let <em>d<sub>1</sub></em> be the 1<sup>st</sup> digit, <em>d<sub>2</sub></em> be the 2<sup>nd<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T22:01:09.800",
"Id": "87941",
"Score": "0",
"body": "Can the first digit in a number be `0`, i.e., is every nine-digit number consisting of the digits `1` through `9` a base-10 pandigital number because you can stick `0` on the fron... | [
{
"body": "<p>Instead of brute-forcing 10! permutations, I'd recommend going other way around: construct the necessary ones.</p>\n\n<p>You know already that the last 3 digits must form a multiple of 17 - there's just 50 or so such numbers, provided that all 3 digits shall be different. Then prepend each of them... | {
"AcceptedAnswerId": "50969",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T21:15:23.553",
"Id": "50965",
"Score": "4",
"Tags": [
"python",
"optimization",
"performance",
"strings",
"programming-challenge"
],
"Title": "Speeding up Project Euler... | 50965 |
<p>I'm new to C++ and am doing the C++ 4th Edition Stroustrup book. I expanded on one of the examples, and have a few questions to ask (embedded within the code: ////QUESTION 1-9).</p>
<p>Please provide any critiques, I'd like to bang in safe practice as early as possible. The Vector.h file simply declares these funct... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T00:11:51.737",
"Id": "87960",
"Score": "1",
"body": "Could you please move the questions outside of the code? Having them commented in makes it a little harder to read the code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>I'll go ahead and answer most of the questions. I'll also add some additional notes.</p>\n\n<ol>\n<li><blockquote>\n <p>How would it differ if I set <code>elem</code> & <code>sz</code> in the body of the constructor? As of now, they are being declared after the method declaration, but before... | {
"AcceptedAnswerId": "51008",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T00:02:07.570",
"Id": "50975",
"Score": "6",
"Tags": [
"c++",
"beginner",
"memory-management",
"vectors"
],
"Title": "Creating a custom Vector class"
} | 50975 |
<pre><code>#!/usr/bin/env python
import re
import nltk.corpus
def tokenize(text, **kw):
"""
Break down text into a set of unique lower case words.
"""
plain_words = nltk.corpus.abc.words()
stop_words = nltk.corpus.stopwords.words()
# Defaults
kw.setdefault('min_len', 4)
kw.setdefault('... | [] | [
{
"body": "<ol>\n<li>No, <code>tokenize</code> is not too complex for one function. It does a single operation: it tokenizes a string.</li>\n<li>Your list comprehensions are fine. They are somewhat complex but are still readable and easily understandable.</li>\n<li><p>Instead of using the regex <code>([A-z]+)+<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T03:05:23.470",
"Id": "50980",
"Score": "4",
"Tags": [
"python",
"regex"
],
"Title": "Python function to find and tokenize string data"
} | 50980 |
<p>I'm writing an IRC bot as a toy project, and one of the goals is to be easy and straight-forward to implement and register new commands.</p>
<p>As I'm new to Go, I don't know which would be the "Go way" for doing it.</p>
<p>This is a working "hello world" command:</p>
<pre><code>package example
import (
"fmt... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T03:08:04.297",
"Id": "50981",
"Score": "5",
"Tags": [
"go"
],
"Title": "Most intuitive way to register \"commands\" in an extensible IRC bot in Go"
} | 50981 |
<p>I have a <code>DataGridView</code> on the UI (a win form) and objects in the <code>List <Earnings></code> are shown in the Grid. </p>
<p><strong>View</strong></p>
<pre><code>class Form
{
public BindingSource EarningDetails
{
set {dgEmployeeEarnings.DataSource= value;}
}
}
</code></pre>
<... | [] | [
{
"body": "<p>I believe you will want to use a <code>BindingList</code>, which can notify when entries are updated.</p>\n\n<p>You will need to handle the events raised in order to reflect the changes back to the original source.</p>\n\n<p>See these sources for more:</p>\n\n<ul>\n<li>Documentation : <a href=\"ht... | {
"AcceptedAnswerId": "52596",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T03:49:24.563",
"Id": "50982",
"Score": "2",
"Tags": [
"c#",
".net",
"mvp"
],
"Title": "Reflecting changes in the DataGridView back on the List and then updating database"
} | 50982 |
<p>I have <code>DatabaseContext</code> class.</p>
<pre><code>public interface IDatabaseContext : IDisposable
{
SqlConnection Connection { get; }
}
public class DatabaseContext : IDatabaseContext
{
private readonly string _connectionString;
private SqlConnection _connection;
public DatabaseContext(str... | [] | [
{
"body": "<p>In your dispose method you should also dispose your SqlConnection :</p>\n\n<pre><code>public void Dispose()\n{\n _connection.Dispose();\n}\n</code></pre>\n\n<p>About correct IDispose implementation read here: <a href=\"http://msdn.microsoft.com/en-us/library/b1yfkh5e%28v=vs.110%29.aspx\" rel=\"... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T10:14:12.540",
"Id": "50987",
"Score": "2",
"Tags": [
"c#",
"sql-server"
],
"Title": "Simple Data Access Layer"
} | 50987 |
<p>I need to get a count of correct and incorrect attempts per testID:</p>
<pre><code>select
AttempID,
Test_ID,
Date,
SubjectID,
Date,
sum(Correct) as Correct,
sum(InCorrect) as InCorrect
from tbldemo
group by
AttempID,
Test_ID,
Date,
SubjectID_name,
Date
</code></pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T14:16:24.953",
"Id": "87986",
"Score": "0",
"body": "I've edited your question to what I believe you were asking; if you feel I've missed your intent, please let us know!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>You don't need the second <code>Date</code> in your select or grouping. Other than that, the query itself looks fine.</p>\n\n<p>I'm a bit more worried about how your table is built, though.</p>\n\n<ul>\n<li><p>There appear to be duplicate records. How would you go about selecting a specific reco... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T13:18:09.650",
"Id": "50995",
"Score": "1",
"Tags": [
"sql"
],
"Title": "Getting a count of correct and incorrect test attempts"
} | 50995 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow">Learn You a Haskell</a> explains <code>zip4</code>:</p>
<pre><code>--ghci> zip4 [2,3,3] [2,2,2] [5,5,3] [2,2,2]
-- [(2,2,5,2),(3,2,5,2),(3,2,3,2)]
</code></pre>
<p>Please critique my implementation:</p>
<pre><code>zip4 :: [a] -&g... | [] | [
{
"body": "<p>The end-of-list patterns can be combined into one:</p>\n\n<pre><code>zip4 (b:bs) (c:cs) (d:ds) (e:es) = (b,c,d,e) : zip4' bs cs ds es\nzip4 _ _ _ _ = []\n</code></pre>\n\n<p>There's no need for a separate <code>zip4'</code> helper.</p>\n\n<p>This definition is correct, but it's unnecessarily compl... | {
"AcceptedAnswerId": "51001",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T14:19:46.713",
"Id": "50997",
"Score": "2",
"Tags": [
"haskell",
"reinventing-the-wheel"
],
"Title": "Implementing `zip4` in Haskell"
} | 50997 |
<p>When there is a situation where I want to accumulate a value I see myself using inject/reduce with a conditional statement. E.g., when I want to add 1 to a value each time an element in a list has a certain value I do something like this:</p>
<pre><code>puts names.reduce(0) {|acc, name| triangles.include?(name.poin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T18:11:54.617",
"Id": "88031",
"Score": "0",
"body": "`triangles` is an array? better a structure with O(1) inclusion predicates (i.e. a set)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T21:35:40.9... | [
{
"body": "<p>There's a built-in <code>count</code> method which handles your example cleanly:</p>\n\n<pre><code>names.count {|name| triangles.include?(name.points) }\n</code></pre>\n\n<p>Also, the accumulator version should use <code>+</code>, not <code>+=</code>. <code>reduce</code> uses the block's return va... | {
"AcceptedAnswerId": "51002",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T14:20:27.513",
"Id": "50998",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Better way for accumulating a value than using inject/reduce with conditional operator?"
} | 50998 |
<p>I am working on an Entity-System-Component engine for games, which basically means an entity is an object that points to components attached to it, and systems retrieve components to modify their data.</p>
<p>I have a class, which is the main data holder, containing the entities, components and system, and methods ... | [] | [
{
"body": "<p>I wrote a small method for doing dependency registering/injection a while ago which you may find useful; it's similar to what you're doing here but the implementation is very lightweight. Basically each entity in the system which I would want to use multiple times is registered in a container enti... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T14:43:10.603",
"Id": "51000",
"Score": "5",
"Tags": [
"javascript",
"game",
"entity-component-system"
],
"Title": "Data structure for entities"
} | 51000 |
<p>I did some study on the command pattern but most of its examples were in Java so, there must be some difference in implementation in Python. I implemented it in Python with some minor differences, please let me know if something is not correct.</p>
<pre><code>from abc import ABCMeta
from abc import abstractmethod
i... | [] | [
{
"body": "<p>The important thing to know about commands in Python (or any language with first-class functions) is that they're usually trivial. Commands with only one operation (<code>execute</code>) are simply functions. There's no need to define classes. Even commands with two operations can be represented ... | {
"AcceptedAnswerId": "51006",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T15:30:01.227",
"Id": "51003",
"Score": "3",
"Tags": [
"python",
"design-patterns",
"python-2.x"
],
"Title": "Implementing command pattern in Python"
} | 51003 |
<p>I have this code that's pretty much straightforward: it slides a box out at the bottom of the page and keeps another element fixed when you scroll past it.</p>
<p>What I am wondering is if there's any need for me to throttle the scroll event/handler for performance, considering that it's such a small code. I'm also... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T17:07:36.027",
"Id": "88002",
"Score": "1",
"body": "As for checking for classes before removing them, no, you don't have to -- it's fine to remove a nonexistent class, and should not trigger any errors. You shouldn't have to check... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T15:58:29.243",
"Id": "51004",
"Score": "1",
"Tags": [
"javascript",
"performance",
"jquery"
],
"Title": "Sliding a box out the bottom of a page"
} | 51004 |
<p>I recently wrote a function to calculate the intersection point(s) of two parabolas. Working it out on paper was a nightmare, but I eventually did it (I think it's correct), and ended up with: </p>
<p>\$ x = \frac{\sqrt{c_2 - c_1 + \frac{b_1^2}{4a_1} - \frac{b_2^2}{4a_2} + E}}{\sqrt{a_2 - a_1}} - \frac{b1 - b2}{2(... | [] | [
{
"body": "<p>Well it seems as though I SIGNIFICANTLY overcomplicated the equation for some reason. I just did the equation it a second time and I got something much nicer:</p>\n\n<p>For any two parabolas \\$ ax^2 + bx + c = 0\\$ and \\$dx^2 + ex + f = 0\\$, we get:</p>\n\n<p>\\$\nax^2 - dx^2 + bx - ex + c - f ... | {
"AcceptedAnswerId": "51015",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T18:01:12.533",
"Id": "51011",
"Score": "6",
"Tags": [
"python",
"python-3.x",
"mathematics"
],
"Title": "Calculating the point of intersection of two parabolas"
} | 51011 |
<p>I made a 2048 game clone in Java for training, and I am trying to make it more efficient.</p>
<p>The problem I found is the <code>paintComponent()</code> method always resets all the graphics before doing anything, so I am forced to repaint all 4 rows of the game every time I want to repaint. Obviously I didn't wa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T08:24:51.163",
"Id": "88358",
"Score": "0",
"body": "Welcome to Code Review! It seems like you have misunderstood what this site is about. We help with improving the cleanliness of existing, working code. We are not the site to ask ... | [
{
"body": "<p>Since Simon mentioned that re-writing the output is off-topic here (plus that's not really my area of expertise), I'll just do a general code review.</p>\n\n<p>And FWIW: For a simple project like this, you don't need to do such an optimization.</p>\n\n<hr>\n\n<pre><code>public class Game_Panel ext... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T18:01:38.927",
"Id": "51012",
"Score": "7",
"Tags": [
"java",
"optimization",
"game",
"swing"
],
"Title": "2048 game clone in Java"
} | 51012 |
<p>The javascript I typically need to write seems to be a good fit for the module pattern, e.g., repeatable widgets such as photo galleries, forms, etc. that have their own internal states, but may need to be accessible or editable by other parts of the website.</p>
<p>The particular flavor of the module pattern I've ... | [] | [
{
"body": "<p>I would suggest using a constructor and prototypes (as well as the module pattern) if you want to learn OOP in JavaScript. This is typically how libraries like jQuery and Zepto are built:</p>\n\n<pre><code>var App = (function($) {\n\n 'use strict';\n\n // Gallery\n\n var Gallery = (function() {... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T18:26:01.457",
"Id": "51014",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Anything wrong with my typical module pattern?"
} | 51014 |
<p>Please note that I'm working on a game on Windows Phone 8 using Monogame. The game is fine (60 FPS) all the time, except when the particle system is activated. This is just a smoke particle system that begins to emit when the player jumps and stop to emit as the player is at "0" y velocity after the jump. When this ... | [] | [
{
"body": "<p>I don't have a solution, but here are some tips:</p>\n\n<ol>\n<li>Measuring the difference between structs and classes for particles can make a difference.</li>\n<li>Do not use properties for particles; use simple fields.</li>\n<li>Calculate values once (e.g. pass <code>totalseconds</code> to your... | {
"AcceptedAnswerId": "51104",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T18:42:18.130",
"Id": "51016",
"Score": "9",
"Tags": [
"c#",
"performance",
"animation",
"xna",
"monogame"
],
"Title": "Smoke particle system"
} | 51016 |
<p>Just wanted a few opinions on whether this game's code is efficient, from looking at it, it does look a bit all over the place but I just don't know how to 'tidy' it up to say so. Would love to hear your opinions and even better if you could show me how it's done.</p>
<pre><code>#Here i am importing all necessary m... | [] | [
{
"body": "<p>I can't really comment on the performance since I found it difficult to read, especially the spaces around the operators throughout the code.</p>\n\n<p>As you mention though, I would focus first on cleanup and applying <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\" title=... | {
"AcceptedAnswerId": "51020",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T19:57:17.777",
"Id": "51018",
"Score": "0",
"Tags": [
"python",
"python-3.x",
"pygame"
],
"Title": "Is this Pygame projectile code efficient?"
} | 51018 |
<p>I recently solved problems 18/67 in Project Euler. My code is long and I think it could be more effective. I solved the problem with dynamic programming and am new to it, so I want to improve my dynamic programming. I think my running time is acceptable: 0.214 seconds.</p>
<pre><code>import java.io.BufferedReader;... | [] | [
{
"body": "<p>Even before starting the review I have to disappoint you. The problem has nothing to do with the dynamic programming. Now let's go.</p>\n\n<ol>\n<li><p><strong>Naming</strong>: Avoid meaningless names, such as <code>q</code>, <code>temp1</code>, <code>temp2</code>, <code>calc</code> and <code>othe... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T22:02:18.747",
"Id": "51021",
"Score": "4",
"Tags": [
"java",
"performance",
"programming-challenge"
],
"Title": "Project Euler problems 18/67: maximum path sum"
} | 51021 |
<p>I have this algorithm that calculates the matrix determinant using recursive divide-and conquer-approach:</p>
<pre><code>int determ(int a[max][max],int max) {
int det=0, p, h, k, i, j, temp[max][max];
//base case omitted
for(p=0;p<max;p++) {
h = 0;
k = 0;
for(i=1;i<max;i++) {
... | [] | [
{
"body": "<p>Sorry, it is not a divide and conquer, it's a combinatorial explosion. The timing complexity</p>\n\n<p>$$T(n) = nT(n-1)$$</p>\n\n<p>evaluates to <code>n!</code> - exponential growth. There is no way to heal the code; you have to choose another algorithm.</p>\n",
"comments": [
{
"... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T00:44:32.800",
"Id": "51025",
"Score": "4",
"Tags": [
"optimization",
"c",
"recursion",
"matrix"
],
"Title": "Optimization of matrix determinant calculation"
} | 51025 |
<p>I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using <code>RestTemplate</code> from my main thread. I also have a single background thread in my application which parses the data from the URL and extracts the block list of hostnames f... | [] | [
{
"body": "<p>For adding and removing single host names, I would use a simple <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html\" rel=\"nofollow\"><code>ConcurrentHashMap</code></a> without the <code>AtomicReference</code>. Initialize it with an empty map and drop th... | {
"AcceptedAnswerId": "51037",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T01:23:37.990",
"Id": "51028",
"Score": "4",
"Tags": [
"java",
"performance",
"url",
"rest",
"atomic"
],
"Title": "Constructing a URL for execution using RestTemplate"
} | 51028 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow noreferrer">Learn You a Haskell</a> presents the Caesar Cipher:</p>
<blockquote>
<p>The Caesar cipher is a primitive method of encoding messages by
shifting each character in them by a fixed number of positions in the
alphabet</p>
</b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T02:03:52.230",
"Id": "88055",
"Score": "0",
"body": "Hey 200_Success, thanks for editing to include the proper tag. But, since Anonymous pointed out that it's only a Substitution Cipher, I edited the title and removed the tag."
},... | [
{
"body": "<p>This is a legitimate substitution cipher, but it's not a Caesarean cipher. A Caesarian cipher affects only letters, and it's modulo the alphabet size: <code>caesar 13 \"Hello, world!\"</code> ⇒ <code>\"Urzzb, jbeyq!\"</code></p>\n\n<p><code>encode</code> and <code>decode</code> can be the same fun... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T01:43:13.527",
"Id": "51029",
"Score": "1",
"Tags": [
"haskell",
"caesar-cipher"
],
"Title": "Substitution Cipher in Haskell"
} | 51029 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow">Learn You a Haskell</a> offers the <code>findKey</code> function:</p>
<p>Here's the book's implementation:</p>
<pre><code>findKey :: (Eq k) => k -> [(k,v)] -> v
findKey key xs = snd . head . filter (\(k,v) -> key == k) $ xs ... | [] | [
{
"body": "<p>It's a stylistic choice, yes.</p>\n\n<blockquote>\n <p>is there a way to write <code>findKey</code> such that the <code>[(k,v)]</code> is curried & thus not required in the signature of <code>findKey key xs</code>?</p>\n</blockquote>\n\n<p>If you mean a way to avoid having pairs in the type: ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T01:58:36.633",
"Id": "51032",
"Score": "1",
"Tags": [
"haskell",
"reinventing-the-wheel",
"comparative-review"
],
"Title": "Function Composition: $ versus `.`"
} | 51032 |
<p>I created a <code>Time</code> class. Now I want to modify the code to perform input validation. Hour should be between 0-24, minutes and seconds between 0-59. If class need improvements, please offer suggestions.</p>
<p><strong>Time.h Header File</strong></p>
<pre><code>#ifndef TIME_H
#define TIME_H
class Time
{
... | [] | [
{
"body": "<p>I don't like the internal storage type of (Hour/Min/Seconds).</p>\n\n<pre><code>private :\n int hour;\n int minute;\n int second;\n</code></pre>\n\n<p>This makes it hard to do comparison move forward backwards etc. I personally just store the number of seconds since midnight.</p>\n\n<pre>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T05:06:45.263",
"Id": "51038",
"Score": "3",
"Tags": [
"c++",
"classes",
"datetime"
],
"Title": "Validating C++ Time class objects"
} | 51038 |
<p>On SO, I asked for a way to do it <a href="https://stackoverflow.com/q/23711057/2567683">without variadics</a>. I also provided a typical "normal" implementation <strong>with variadics</strong>: </p>
<pre><code>template <typename V, typename T>
struct Is_in_tuple;
template <typename V, typename T0, typena... | [] | [
{
"body": "<p>Since you're implementing a traits-like check, I would typically expect your traits class types to be derived from <code>std::true_type</code> and <code>std::false_type</code>. This is certainly not required, and overall this implementation doesn't bug me. I was slightly surprised to see <code>std... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T07:55:13.377",
"Id": "51043",
"Score": "6",
"Tags": [
"c++",
"c++11",
"template-meta-programming",
"variadic"
],
"Title": "Test whether a type T is among the types of a tuple"... | 51043 |
<p>I tried use use HTML tags as my own way in PHP using objects.</p>
<p>Is this the correct method of writing or implementing OOP? If not, what is the best way to write such type of code?</p>
<pre><code> <?php
class HTMLCoding {
private $classname;
private $classstyle;
function applyStyle($classna... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T13:30:09.790",
"Id": "88241",
"Score": "1",
"body": "Don't re-invent the wheel, that's the whole point of OOP. If you are going to use objects to churn out a DOM, [take a look at what's already out there](http://www.php.net/DOMDocum... | [
{
"body": "<p>First off, I suggest you separate the logic from the presentation. That means deal with the HTML later, do the structure of the code first. Then before I forget, I recommend you improve your indentation.</p>\n\n<p>OOP is \"Object Oriented Programming\". In simple terms, you treat your code like re... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T07:57:02.240",
"Id": "51044",
"Score": "-2",
"Tags": [
"php",
"object-oriented"
],
"Title": "Is the this the correct way of using OOP for a student class?"
} | 51044 |
<p>Given a hashmap (or a "Dictionary") as a JavaScript object, I'd like to get the Key who has the maximum Value - assuming all Values are integers.</p>
<p>In case there's more than one, I don't care which one of them.</p>
<p>Considering</p>
<pre><code>var b = { '1': 9, '2': 7, '3': 7, '4': 9, '5': 3 };
</code></pre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T11:24:55.407",
"Id": "88090",
"Score": "0",
"body": "It looks like you're seeking the *key* with the largest *value*. Note that the keys are strings while the values are integers."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>I don't know about elegant, but you can omit the initial <code>_()</code>, use <code>+</code> to convert to number instead of <code>parseInt</code> and just pull out the iterator.</p>\n\n<pre><code>var iterator = function(p){return p[1];}\nvar maxKey = +_.chain(b).pairs().max(iterator).value()[0];... | {
"AcceptedAnswerId": "51080",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T10:51:18.637",
"Id": "51053",
"Score": "2",
"Tags": [
"javascript",
"underscore.js"
],
"Title": "Get the Key of the highest Value in JavaScript object"
} | 51053 |
<p>I am in process of making debugging output better for client-side application. We have lots of auto-generated <a href="http://code.google.com/p/protobuf/" rel="nofollow noreferrer">Protocol Buffers</a> classes which are used for communication by our protocol.</p>
<p>I am trying to make an function that would enumer... | [] | [
{
"body": "<p>I'll just point out that you're kind of re-inventing the wheel here. Delphi has built-in facilities for walking a class's properties and generating a \"Json-Like\" output in the form of property streaming (Delphi uses this internally for writing and reading <code>.dfm</code> files).</p>\n\n<p>Have... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T11:42:31.593",
"Id": "51055",
"Score": "2",
"Tags": [
"optimization",
"delphi",
"rtti"
],
"Title": "Drill through and down the object properties with RTTI"
} | 51055 |
<p>I have a <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation" rel="nofollow">WPF</a> app and a bunch of read/write settings that need to be accessible from various view models. a setting can be any type (<code>string</code>, <code>bool</code>, etc) and all are settable, but only from a 'Settings' v... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T14:01:22.427",
"Id": "88113",
"Score": "1",
"body": "Welcome to [codereview.se]! This is a very nice question. You maybe also want to check out our [chat] ;)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-... | [
{
"body": "<blockquote>\n <p>Is this a type-safe way to get the setting values?</p>\n</blockquote>\n\n<p>It's not type-safe in the sense that if you make a mistake in specifying the type parameter of <code>GetSetting</code>, or if someone sets setting to the wrong type, you're going to get an exception.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T13:16:41.637",
"Id": "51059",
"Score": "6",
"Tags": [
"c#",
"wpf",
"singleton",
"mvvm"
],
"Title": "Manage a collection of settings in memory with global scope"
} | 51059 |
<p>I have a small "plugin system" (I'm not sure this is the right name). It allow you to store objects (plugins), and then call some methods from each of them. With this approach we have absolutely no overhead on iterating/object pass/callback call.</p>
<pre><code>// Need this SET, because in C++11 auto can only be st... | [] | [
{
"body": "<p>First, you are not storing <code>&&</code>, but rather <code>&</code>. Why? because <code>plugin1</code> etc. are lvalue references, and because of the <a href=\"http://thbecker.net/articles/rvalue_references/section_08.html\" rel=\"nofollow noreferrer\">reference collapsing rules</a>.... | {
"AcceptedAnswerId": "51172",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T14:50:00.600",
"Id": "51062",
"Score": "4",
"Tags": [
"c++",
"design-patterns",
"c++11",
"template",
"template-meta-programming"
],
"Title": "Plugin system for calling ... | 51062 |
<p>I'd like to code review generated <a href="/questions/tagged/svg" class="post-tag" title="show questions tagged 'svg'" rel="tag">svg</a> animation, while this might stretch definition of this site, I really hope this is interesting and revelant topic, as this SVG file is really like any other programming lan... | [] | [
{
"body": "<p>SVG by default has only single precision numbers so having any number with more than four decimal places is a waste which takes more space and transmission. A similar issue happens with the begin time parameter. A blink of the eye takes .1 second and 30 frames / second is .03 seconds so do not spe... | {
"AcceptedAnswerId": "54252",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T15:20:29.987",
"Id": "51065",
"Score": "-1",
"Tags": [
"python",
"optimization",
"animation",
"svg"
],
"Title": "Optimizing this SVG animation for size"
} | 51065 |
<p>I have designed a simple state machine for the following diagram:</p>
<p><img src="https://i.stack.imgur.com/67EE9.gif" alt="enter image description here"></p>
<p>I am seeking improvements from the community. I especially don't like two things:</p>
<ol>
<li>When calling <code>performAction</code> I wan't to send ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T22:20:03.663",
"Id": "88174",
"Score": "0",
"body": "Note that there are entire libraries dedicated to generate state machines, e.g. [boost's MSM](http://www.boost.org/doc/libs/1_55_0/libs/msm/doc/HTML/index.html)"
},
{
"Con... | [
{
"body": "<p>That's typically how C enums are written, but it's done differently in C++. The <code>typedef</code> keyword is no longer needed, and the name is given after the <code>enum</code> keyword.</p>\n\n<pre><code>enum State {\n Idle,\n Start,\n Stop,\n ChangeSpeed\n};\n</code></pre>\n",
... | {
"AcceptedAnswerId": "51073",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T15:43:28.190",
"Id": "51067",
"Score": "5",
"Tags": [
"c++",
"state-machine"
],
"Title": "Designing simple state machine in C++"
} | 51067 |
<p>I created this abstract class:</p>
<pre><code>public abstract class MeasurementType {
protected String name;
protected String[] units;
public MeasurementType() {}
public MeasurementType(String name) {
this.name = name;
}
protected void setName(String name) {
this.name = name;
}
protected... | [] | [
{
"body": "<p>Using strings in themselves to determine the <code>MeasurementType</code> isn't the biggest problem, but you really don't need to create classes and subclasses and stuff for this.</p>\n\n<p>Instead, use an <strong>enum</strong>!</p>\n\n<pre><code>public enum MeasurementType {\n DENSITY, ACCELER... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T15:55:01.887",
"Id": "51068",
"Score": "5",
"Tags": [
"java"
],
"Title": "Java design for dimensions and units"
} | 51068 |
<p>I'm a beginner in JavaScript and lately I've been trying things with RequireJS, I'd like to get some feedback on how good/poor my code is and in what ways it can be improved.</p>
<p>My example below is just loading up social plugins - Facebook Like/Share, Twitter Tweet & Google +1. The code is functional and wo... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T17:22:19.073",
"Id": "51074",
"Score": "3",
"Tags": [
"javascript",
"beginner",
"require.js",
"facebook"
],
"Title": "Using RequireJS correctly for social plugins"
} | 51074 |
<p>Follow up of <a href="https://codereview.stackexchange.com/questions/50945/pretty-print-with-unit-and-physical-suffix/51076#51076">Pretty print with unit and physical suffix</a></p>
<p>My first code didn't process negative numbers correctly. Additionally I tried to use all of the helpful input to come up with this ... | [] | [
{
"body": "<p>The computation of <code>postdecimal</code> can be simplified to <code>postdecimal = max(precision - predecimal, 0)</code>.</p>\n\n<p><code>eng_format</code> needs a docstring.</p>\n\n<p>On <code>self.seq</code>:</p>\n\n<ul>\n<li>It needs a meaningful name like <code>examples</code>.</li>\n<li>It ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T17:51:10.673",
"Id": "51077",
"Score": "1",
"Tags": [
"python",
"formatting"
],
"Title": "Pretty print with unit and physical suffix II"
} | 51077 |
<p>I decided to try out Python (3.x) two or so weeks ago, and this is my first real script using it. The program I've written below is slow, clunky, inefficient, inaccurate, and probably poorly coded! But it produces what I want most of the time, and it was really just a project to become accustomed to different Python... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T08:31:34.607",
"Id": "88231",
"Score": "0",
"body": "this is a standard problem that has a dynamic programming based solution. you might want to take a look at this - http://algohub.blogspot.com/2014/05/given-dictionary-and-string-f... | [
{
"body": "<p>You know what you're effectively building is one large regular expression containing all the possible words you want to consider. You might want to either try to explicitly build one such regular expression, then see what you find, remove the part you found from the beginning, and repeat with the ... | {
"AcceptedAnswerId": "51105",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T17:58:57.810",
"Id": "51078",
"Score": "7",
"Tags": [
"python",
"algorithm",
"beginner",
"parsing",
"python-3.x"
],
"Title": "Social Media Hashtag Splitting"
} | 51078 |
<p>I read many times about controller code mustn't be too complicated and so on. I was developing new features in my simple project. I added a function, which allow users to get access to news only in one specified category. Now, if a user writes some of this URL:</p>
<blockquote>
<pre><code>/news/common
/news/sport
/... | [] | [
{
"body": "<p>On the surface the code in your question seems fine, but I can tell you from experience that once this door is cracked just a bit, it will continue to creak open wider over time.</p>\n\n<ul>\n<li>\"I'm just checking if we have an ID or category name.\"</li>\n<li>\"This just adds a few meta tags.\"... | {
"AcceptedAnswerId": "51089",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T19:34:31.887",
"Id": "51083",
"Score": "2",
"Tags": [
"php",
"zend-framework"
],
"Title": "Does my controller code look good?"
} | 51083 |
<p>Inside my android app, I currently have methods that look like below code. <br>Since they all need a callback object that basically does the same thing and I would like to try to eliminate the duplicated code seen below. </p>
<p>The object that gets posted via the <code>mBus.post(response);</code> statement needs t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T19:51:35.653",
"Id": "102648",
"Score": "0",
"body": "I see the point of the \"What you can and cannot do\", but it makes it difficult for these old questions. I guess what I really should have done, is posted my updated code a wh... | [
{
"body": "<blockquote>\n <p>One thing that bothers me is, that I have both the type parameter for the class and I am passing in the class to the constructor. It seems like I should not need to pass in the same info in two different ways.</p>\n</blockquote>\n\n<p>The reason for why you have to do that is becau... | {
"AcceptedAnswerId": "57295",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T19:36:35.727",
"Id": "51084",
"Score": "4",
"Tags": [
"java",
"android",
"callback"
],
"Title": "Generic callback object, but I need the type parameter inside methods"
} | 51084 |
<p>I wrote a zscore algorithm in Ruby that runs fine, but is incredibly slow when I have 8000+ entries to score. Can anyone help me figure out a way to improve my code, please?</p>
<pre><code>module Enumerable
def mean
reduce(:+).to_f / length
end
def sample_variance
sum = inject(0){ |acc, i| acc + (i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T08:38:18.410",
"Id": "88543",
"Score": "0",
"body": "If that is a sample variance (as opposed to a population variance), you need to divide by n-1 (not n) for it to be an unbiased estimator (though in this case the difference is neg... | [
{
"body": "<p>The problem is here: <code>collect { |v| (v - mean) / standard_deviation }</code>. <code>standard_deviation</code> is constant but, being inside a block, it is called on each iteration. Set the value to a local variable before. As noted by Flambino, the same principle applies to <code>sample_varia... | {
"AcceptedAnswerId": "51092",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T20:14:45.467",
"Id": "51087",
"Score": "4",
"Tags": [
"performance",
"algorithm",
"ruby",
"statistics"
],
"Title": "Optimize a zscore algorithm"
} | 51087 |
<p>As a Lisp (and functional programming) newbie, I wrote the following code that finds the sum of all the multiples of 3 or 5 below 1000, and I suspect that it is lousy:</p>
<pre><code>(defun multiple-of-3-or-5 (x)
(or (eq (mod x 3) 0) (eq (mod x 5) 0)) )
(defun generate-list (min max)
(cond ((> min max... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T15:11:52.170",
"Id": "88263",
"Score": "2",
"body": "It's [Project Euler problem #1](http://projecteuler.net/problem=1)."
}
] | [
{
"body": "<ol>\n<li><p>You are not using <a href=\"http://en.wikipedia.org/wiki/Tail_call\">tail recursion</a> in <code>my-sum</code>, so the compiler cannot easily turn it into iteration.</p></li>\n<li><p>It depends on the specific problem; in this case I would probably do it iteratively.</p></li>\n<li><p>Sur... | {
"AcceptedAnswerId": "51109",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T21:39:17.530",
"Id": "51093",
"Score": "7",
"Tags": [
"beginner",
"programming-challenge",
"lisp",
"common-lisp"
],
"Title": "Finding the sum of all the multiples of 3 or 5... | 51093 |
<p>Is this okay?</p>
<pre><code>public class BaseRepository<T> where T : class
{
private readonly DbContext _dbContext;
public BaseRepository(DbContext dbContext)
{
_dbContext = dbContext;
}
public T Get(Func<T, bool> predicate)
{
return GetAll(predicate).FirstOrDe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T14:28:46.913",
"Id": "88250",
"Score": "0",
"body": "I have used this layer/pattern for two years in my projects ... most because of all tutorials I have seen when I started on asp.NET MVC. IMHO, `abstract repository` exists just to... | [
{
"body": "<pre><code>public async void Save()\n {\n await _dbContext.SaveChangesAsync();\n }\n</code></pre>\n\n<p>The name shall be SaveAsync code convention!</p>\n\n<p>I would make the BaseRepository as abstract --> this will prevent the repository user from creating the Base Repository!</p>\n",
... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T21:53:21.910",
"Id": "51095",
"Score": "9",
"Tags": [
"c#",
"entity-framework"
],
"Title": "BaseRepository for EF6"
} | 51095 |
<p>I'm a first time user of jQuery (and a huge fan already). I am trying to make the comic picture of <a href="https://xkcd.com/380/" rel="nofollow">an xkcd page</a> <code>onclick</code> to <a href="http://www.explainxkcd.com/wiki/index.php/380" rel="nofollow">the explanation page</a>.</p>
<p>Here's what I've done.</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T08:31:39.023",
"Id": "88216",
"Score": "1",
"body": "It won't work on the latest comic (http://xkcd.com/)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T16:37:57.767",
"Id": "88273",
"Score":... | [
{
"body": "<p>Besides not needing to return the result of <code>window.open</code>, it looks pretty good. See <a href=\"https://stackoverflow.com/q/1357118/1517919\">this thread</a> for an explanation of what returning a value from event does. <a href=\"https://stackoverflow.com/a/1357151/1517919\">From this an... | {
"AcceptedAnswerId": "51101",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T22:33:19.913",
"Id": "51098",
"Score": "6",
"Tags": [
"javascript",
"jquery"
],
"Title": "First time jQuery on xkcd"
} | 51098 |
<p>I'm fairly new to Python - though not new to programming by any means. I have this Python script and it works perfect for my needs but being new(er) to Python I'm just looking to see if there are any general things I could be doing better or 'more Python-esque'. I recently refactored all of this into what you see no... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T00:48:59.077",
"Id": "88187",
"Score": "0",
"body": "I would put this in a class. Also see http://stackoverflow.com/q/2361426/1517919 for more optimal ways to get the first item of an iterator"
}
] | [
{
"body": "<p>The code is more 'Pythonic' than the majority of the codes I have seen here. Are you sure you are just a beginner in python?</p>\n\n<p>One suggestion is to keep consumerKey, consumerKeySecret, accessToken and accessToken secret in another python file, and import these values from that file.\nIf yo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-18T23:18:59.750",
"Id": "51100",
"Score": "3",
"Tags": [
"python",
"beginner",
"twitter"
],
"Title": "Archiving Tweets via Python"
} | 51100 |
<p>I'm trying to replace the use of raw pointers with smart pointers in my C++ code. The following bit is from my first attempt at a self-balancing binary tree, though there is nothing self-balancing at the moment. I am worried about some fundamental problems regarding the use of unique pointers. </p>
<pre><code>templ... | [] | [
{
"body": "<p>These two constructors are never used:</p>\n\n<pre><code> rbnode(): \n left(nullptr), right(nullptr), parent(nullptr), \n color(Red), data(0), key(0) {}\n rbnode(K k, D d): \n left(nullptr), right(nullptr), parent(nullptr), \n color(Red), data(d), key(k) {}\n</cod... | {
"AcceptedAnswerId": "51116",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T04:37:06.280",
"Id": "51111",
"Score": "4",
"Tags": [
"c++",
"c++11",
"tree",
"pointers"
],
"Title": "Binary tree with C++11 smart pointers"
} | 51111 |
<p>I have a little Mario game I started working on and I realized that its format is very messy. Can anyone critique my code on how to make it better, faster, neater, and easier to access?</p>
<p><strong>frame.java</strong></p>
<pre><code>package EvilMario; ... | [] | [
{
"body": "<p>There's two glaring issues jumping into my face in this code. They are both somewhat beginner mistakes, so don't be sad :)</p>\n\n<h2>Commenting:</h2>\n\n<p>\"I commented a lot of lines so you can understand the game logic\"<br>\n<strong>That is not the purpose of comments.</strong> This is a comm... | {
"AcceptedAnswerId": "51123",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T07:48:46.983",
"Id": "51118",
"Score": "13",
"Tags": [
"java",
"game",
"swing",
"awt"
],
"Title": "Small Mario game"
} | 51118 |
<p>My recent post had some things to fix. I think this should be well structured and written for you.</p>
<p>How does this code look to you? If something needs to be changed please tell me.</p>
<pre><code>// Gets all elements by ID's
function elem(id) {
return document.getElementById(id);
};
//
//Check box id"R... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T11:48:02.603",
"Id": "88227",
"Score": "0",
"body": "It seems like you fixed almost nothing :/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T12:02:20.147",
"Id": "88382",
"Score": "1",
"... | [
{
"body": "<p>Just a short remark on some of your if-statements and rules:</p>\n<blockquote>\n<pre><code>if ((charCode == 64) ||\n(charCode == 32) ||\n(charCode >= 65 && charCode <=90) ||\n(charCode >= 97 && charCode <=122))\nreturn true;\nelse return false;\n</code></pre>\n</blockqu... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T10:23:29.620",
"Id": "51126",
"Score": "3",
"Tags": [
"javascript",
"form",
"validation"
],
"Title": "Client-side validator for contact information form (name, phone, e-mail)"
} | 51126 |
<p>I want to erase all memory in a container. Currently I'm using this : </p>
<pre><code>template<typename Cont>
void clear_mem(Cont &container)
{
while (!container.empty())
{
delete container.back();
container.pop_back();
}
}
</code></pre>
<ol>
<li>Should the operation of deleti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T21:30:15.930",
"Id": "88310",
"Score": "0",
"body": "Why are you putting pointers in your containers?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T05:15:54.897",
"Id": "88345",
"Score": "0"... | [
{
"body": "<p>This assumes that the container holds raw pointer and it owns the pointers. it is a better idea to then let the container hold smart pointers.</p>\n\n<p>These will automatically clear the object they hold when they get destroyed (using <code>delete</code> by default).</p>\n\n<pre><code>typedef std... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T11:26:55.460",
"Id": "51129",
"Score": "7",
"Tags": [
"c++",
"memory-management",
"container"
],
"Title": "Deallocate all memory in a container of pointers"
} | 51129 |
<p>I've used the UK Plug -> US Socket and US Plug -> UK Socket analogy. I've also made it possible for UK plug to use a UK socket and a US plug to use a US socket. The output of the SSCCE below is</p>
<pre><code>UKPlug -> UKSocket
USPlug -> USSocket
UKPlug -> UKUSAdapter -> USSocket
USPlug -> USUKAdapte... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T14:17:50.650",
"Id": "88247",
"Score": "0",
"body": "You should add ISocket and IPlug, and your adapter in your case is a socket and a plug in the same time, so IAdapter should inherit from IPlug and ISocket"
},
{
"ContentLi... | [
{
"body": "<p>Assorted thoughts</p>\n\n<p>IAdapter should be renamed Adapter -- when in doubt, look to the standard libraries for guidance on how to name things (List and ArrayList, not IList and ArrayList)</p>\n\n<p>Also, you are missing the abstractions that allow you to substitute the adapter for the socket ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T11:58:39.370",
"Id": "51135",
"Score": "3",
"Tags": [
"java",
"design-patterns"
],
"Title": "Is this an acceptable implementation of the Adapter pattern?"
} | 51135 |
<p>This is how I imagine my project's layering:</p>
<h2>BLL</h2>
<p>Should be independent and contain only pure business logic and properties
Sample Domain Model:</p>
<pre><code>public class Role
{
private UnitOfWork uow { get; set; }
public Role()
{
uow = new UnitOfWork();
}
public int... | [] | [
{
"body": "<p>To start off, I have no idea what a <code>SoC.DAL.Role</code> is. Your namespaces are short abbreviations. This is quite hard to follow for people not really into your project.</p>\n\n<p>Your role can add itself to a repository. This is not behaviour that I would expect. I would have a simple repo... | {
"AcceptedAnswerId": "51206",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T13:59:07.987",
"Id": "51136",
"Score": "1",
"Tags": [
"c#",
"asp.net-mvc"
],
"Title": "ASP.NET MVC Project Layering"
} | 51136 |
<p>I have a requirement where I need to extract pixels of a given rectangle within an image <code>byte[]</code>.</p>
<p>More specifically I have an image where I have narrowed an area that I wish to return and keep and the remainder discard. In my case I'm performing face recognition in real time so I don't want to st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T14:59:41.583",
"Id": "88258",
"Score": "0",
"body": "Quick buy would be to pre-allocate your list size as such: `List<byte> result = new List<byte>(bytesPerPixel * width * height);`"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>At a quick glance it would appear that your code is likely getting slowed down by the use of <code>Linq</code> as well as conversion between <code>List<byte></code> and <code>byte[]</code>. Only profiling and determining a reasonable amount of time for this code to execute is going to tell y... | {
"AcceptedAnswerId": "51146",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T14:18:48.773",
"Id": "51139",
"Score": "3",
"Tags": [
"c#",
"optimization",
"linq",
"image"
],
"Title": "Extracting Pixels From Image Byte[]"
} | 51139 |
<p>I posted not too long ago, asking for tips/improvements I could use on my models. I have changed quite a lot, so I thought I'll give it another go. </p>
<p>My model is supposed to handle all the data I get from the Foursquare API:</p>
<p><strong>venueService.h</strong></p>
<pre><code>typedef void (^TNVenueService... | [] | [
{
"body": "<p>First, I'll focus on some of the easy, obvious things I see. I know the main point of this code is some of the networking stuff, but there are some other things I want to comment on first.</p>\n\n<hr>\n\n<p>First and foremost, this line:</p>\n\n<pre><code>@class TNVenueImageData;\n</code></pre>\n... | {
"AcceptedAnswerId": "51174",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T19:13:42.473",
"Id": "51158",
"Score": "3",
"Tags": [
"objective-c",
"ios"
],
"Title": "Model to handle all the data/networking from Foursquare API in IOS"
} | 51158 |
<p>I see that my code smells. The first file is a controller, and createAction. But I don't know where to delegate this.</p>
<p><a href="https://gist.github.com/anonymous/c2b29c105719fe8cfe17">BookController.php</a> - Whole controller class</p>
<p>So this is most 'smelly' code to me:</p>
<pre><code>public function... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-23T07:47:42.517",
"Id": "103417",
"Score": "0",
"body": "How come you are not using a `postPersist` for the upload in your book, also why are you using `$coverObj->upload();` when it should already be covered by the `postPersist`? Also... | [
{
"body": "<h2>BookController.php</h2>\n\n<p>I don't see anything to change, the only thing which i could do different is the return line from </p>\n\n<pre><code> return $this->render('MatiitBookBundle:Book:new.html.twig', ['form' => $form->createView()]);\n</code></pre>\n\n<p>i would write something l... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T20:06:35.493",
"Id": "51161",
"Score": "6",
"Tags": [
"php",
"controller",
"symfony2"
],
"Title": "Uploading file for related entity"
} | 51161 |
<p>I got this code working but it feels clunky. I am wondering if there is a way I can improve it.</p>
<p>(I'm intermingling JavaScript and jQuery). I'm using jquery-1.11.1.min.js hosted on code.jquery.com.</p>
<p><a href="http://jsfiddle.net/franktudor/m3Dvg/">Here is the jsFiddle</a></p>
<p><strong>JS:</strong></p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T21:41:04.307",
"Id": "88312",
"Score": "0",
"body": "\"intermingling JavaScript and jQuery\". Well, anything else would be impossible. jQuery _is written in_ JavaScript. JavaScript is the language; jQuery is just another library."
... | [
{
"body": "<ol>\n<li>Don't repeat element IDs. What you want is a <code>data-*</code> attribute, e.g. <code>data-property</code>. Or you could use class names, since those can repeat and you'll want to style things anyway. Of course, you could also build your elements as needed.</li>\n<li>Use CSS classes proper... | {
"AcceptedAnswerId": "51171",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T20:13:30.917",
"Id": "51162",
"Score": "7",
"Tags": [
"javascript",
"jquery"
],
"Title": "JSON call for stock info using YQL"
} | 51162 |
<p>Is there a more efficient way of writing this? It seems like so much redundancy that this can be greatly reduced. Basically the only difference is if <code>isNodeWebkit</code> is true then run a function using key code <code>113</code> or <code>112</code></p>
<pre><code> if (isNodeWebkit) {
$(document).k... | [] | [
{
"body": "<p>Yes! Introduce a <code>keyCode</code> variable to hold the one difference between the two otherwise identical code blocks.</p>\n\n<pre><code>var keyCode = isNodeWebkit ? 113 : 112;\n$(document).keyup(function (e) {\n if (e.which == keyCode) {\n $.ajax({\n type: \"POST\",\n ... | {
"AcceptedAnswerId": "51165",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T20:49:26.653",
"Id": "51163",
"Score": "15",
"Tags": [
"javascript",
"jquery",
"ajax"
],
"Title": "Simplifying a repetitive event handler"
} | 51163 |
<p>I am trying to copy files from <code>machineB</code> and <code>machineC</code> into <code>machineA</code> as I am running my shell script on <code>machineA</code>.</p>
<p>If the files are not in <code>machineB</code>, then it should be there in <code>machineC</code> for sure. I will try copying the files from <code... | [] | [
{
"body": "<blockquote>\n <p>I am trying to see is there any better way of doing the same thing using GNU Parallel instead of using <code>&</code>.</p>\n</blockquote>\n\n<p>Essentially you have two different commands and two different parameter lists:</p>\n\n<ol>\n<li>Copy to PRIMARY, these files: 550 274 ... | {
"AcceptedAnswerId": "64448",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T21:40:29.097",
"Id": "51168",
"Score": "4",
"Tags": [
"performance",
"file-system",
"bash",
"linux",
"concurrency"
],
"Title": "Copying into two different folders on a ... | 51168 |
<p>I have recently undertaken a project for programming practice based on a simple text editor. Normally this kind of thing wouldn't bother me, but ever since I completed a software architectures module in college, I question everything about how my code is and should be formatted! (probably a good thing?)</p>
<p>I cu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-01-22T17:16:51.047",
"Id": "141867",
"Score": "0",
"body": "hey man, thanks for the code. May I use this code in my project? I'll assume the answer is yes until you explicitly say no."
},
{
"ContentLicense": "CC BY-SA 3.0",
"C... | [
{
"body": "<p>The only thing that sticks out to me is in your save methods your not calling finally, and that is where your close call should be. This way if the <code>IOException</code> happens before close gets called your possibly holding a file handler open somewhere.</p>\n\n<pre><code>// Method for saving ... | {
"AcceptedAnswerId": "51201",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T00:32:44.467",
"Id": "51175",
"Score": "7",
"Tags": [
"java",
"text-editor"
],
"Title": "Simple text editor class"
} | 51175 |
<p>I'm writing a C# library that's a wrapper around the Yahoo Finance YQL API. I'm stuck on how I want to expose my API to consumers. My design thus far consists of separate interfaces for the different parts of the Yahoo Finance API:</p>
<pre><code>public interface IYahooFinanceCharts {
Task<Image> GetChart... | [] | [
{
"body": "<p>What you're looking for is actually the <a href=\"http://en.wikipedia.org/wiki/Factory_method_pattern\" rel=\"nofollow\">factory pattern</a>. </p>\n\n<p>Your implementation could be something like</p>\n\n<pre><code>public class YahooFinanceFactory{\n\n public IYahooFinanceQuotes GetQuotes()\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T04:04:31.123",
"Id": "51177",
"Score": "0",
"Tags": [
"c#",
".net"
],
"Title": "Exposing a web API wrapper library to consumers"
} | 51177 |
<p>This is a Java program that generates a random keyfile (for OTP, for example).</p>
<pre><code>package kfgen;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.security.SecureRandom;
import java.util.Random;
import java.util.Scanner;
public class Kfgen {
//... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-06-23T03:54:00.147",
"Id": "431395",
"Score": "0",
"body": "https://en.wikipedia.org/wiki/Mebibyte"
}
] | [
{
"body": "<p>You forgot to close your <code>BufferedOutputStream</code> and best practice for that is within a finally clause</p>\n\n<pre><code>try\n{\n}\ncatch (Exception e)\n{\n}\nfinally\n{\n bos.close();\n}\n\nfinal byte[] rand = new byte[MEGABYTE];\n</code></pre>\n\n<p>no real reason to define the byte... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T04:30:55.527",
"Id": "51178",
"Score": "3",
"Tags": [
"java",
"security",
"cryptography",
"file"
],
"Title": "Keyfile Generator"
} | 51178 |
<p>Because <code>std</code> doesn't provide an overloaded version of <code>std::abs</code> for <code>std::size_t</code>, I built a version to calculate distance between unsigned numbers.</p>
<p>It subtracts the smaller one from the larger one, to prevent a negative result, since in unsigned integer it would wrap aroun... | [] | [
{
"body": "<p>This function computes absolute difference, not absolute value, so it shouldn't be called <code>abs</code>. <code>absolute_difference</code>? <code>size_diff</code>?</p>\n\n<p>What will you use this function for? Are you using <code>size_t</code> for something other than sizes, so an absolute diff... | {
"AcceptedAnswerId": "51182",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T05:41:34.057",
"Id": "51179",
"Score": "5",
"Tags": [
"c++"
],
"Title": "Absolute-difference function for std::size_t"
} | 51179 |
<p>In my project, there are some methods which filter some items from a collection. I was told to use the C++ STL whenever I can. But when I use <code>std::copy_if</code>, I feel the code using a simple <code>if</code>-condition looks cleaner. </p>
<p>Which implementation do you like more? Which one is more readable?... | [] | [
{
"body": "<p>The version with the range-for is marginally shorter, while <code>copy_if</code> more clearly specifies the intended result of the block of code. For readability, I'd call it pretty close to a draw.</p>\n\n<p>You might also want to consider a few alternatives. One obvious one would be a Boost <cod... | {
"AcceptedAnswerId": "51186",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T05:50:16.833",
"Id": "51180",
"Score": "2",
"Tags": [
"c++",
"collections",
"stl",
"comparative-review"
],
"Title": "Filter a collection"
} | 51180 |
<p>I have recently designed a module which will do bulk upload for different contents. Basically the user will upload an Excel file, I will have to read and validate headers of excel then each value of cell for all columns. I have designed a framework please validate.</p>
<p>Below are the vo.</p>
<p>Template Header d... | [] | [
{
"body": "<p>Just some general thoughts.</p>\n\n<p>Are your field <code>package protected</code> by purpose? Do prevent creating a do tight coupling of your components while development you should start in general with <code>private</code> and only increase the visibility where necessary. On the other hand if ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T06:03:50.683",
"Id": "51181",
"Score": "12",
"Tags": [
"java",
"design-patterns",
"validation",
"excel"
],
"Title": "Validate and import data from an Excel file"
} | 51181 |
<p>This code reverses each consecutive <em>n</em> elements of a linked list, and for spare nodes, leaves them as they are.</p>
<p>For example, the linked list</p>
<blockquote>
<p>1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7</p>
</blockquote>
<p>for an interval of 3 should result in</p>
<blockquote>
<p>3 -> 2 -> 1-> 6 -> 5 -... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T10:25:52.540",
"Id": "88368",
"Score": "2",
"body": "Out of curiosity : should `1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8` lead to `3 -> 2 -> 1-> 6 -> 5 -> 4 -> 7 -> 8` (7 and 8 kept in the same order because we cannot form a triplet) or... | [
{
"body": "<h2>Architecture</h2>\n<p>This is much more complicated than it needs to be. There's no need to define a custom list class, unless you want to practice low-level destructive list-munging. Use one of the standard classes, like <code>java.util.LinkedList</code>.</p>\n<p>It's simpler to attack this prob... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T06:07:19.057",
"Id": "51183",
"Score": "6",
"Tags": [
"java",
"algorithm",
"linked-list",
"interval"
],
"Title": "Reverse sublists of a linked list"
} | 51183 |
<p>This is the same <a href="https://codereview.stackexchange.com/questions/531/review-request-salestax-problem?rq=1">problem</a>, but I decided to do it using F#. I'm just interested in how I can improve it.</p>
<pre><code>namespace SalexTaxes
module Product =
type ProductType =
|food = 1
|boo... | [] | [
{
"body": "<pre><code>type ProductType = \n |food = 1\n |book = 2\n |medical = 3\n |other = 4\n</code></pre>\n\n<p>This is how you create an enum in F#. But a more idiomatic way would be to create a discriminated union:</p>\n\n<pre><code>type ProductType = \n | Food\n | Book\n | Medical\n ... | {
"AcceptedAnswerId": "51207",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T06:15:56.013",
"Id": "51185",
"Score": "1",
"Tags": [
"f#",
"finance"
],
"Title": "SalesTax challenge"
} | 51185 |
<p>I am a Java developer who is taking Python for the first time.</p>
<p>I'm sure this is not at all elegant since I am thinking more in C syntax.</p>
<pre><code>"""
This module contains two implementations of the algorithm Sieve of
Eratosthenes.
"""
# import ########################################################... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T15:57:44.787",
"Id": "88418",
"Score": "1",
"body": "SieveBasic is not a true Sieve of Eratosthenes algorithm, as the true Sieve algorithm has no division nor modulus operations, only additions. This looks more like the notorious T... | [
{
"body": "<p><strong>Style</strong></p>\n\n<p>You code does not follow <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a>, the usual Python coding convention. You'll find tools such as <code>pep8</code> (or its <a href=\"http://pep8online.com/\" rel=\"nofollow\">online version</... | {
"AcceptedAnswerId": "51196",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T07:16:43.093",
"Id": "51190",
"Score": "5",
"Tags": [
"python",
"primes",
"numpy",
"sieve-of-eratosthenes"
],
"Title": "Sieve of Eratosthenes - Standard and Optimized imple... | 51190 |
<p>The Sieve of Eratosthenes refers to a specific <a href="/questions/tagged/algorithm" class="post-tag" title="show questions tagged 'algorithm'" rel="tag">algorithm</a> to find <a href="/questions/tagged/primes" class="post-tag" title="show questions tagged 'primes'" rel="tag">primes</a>, invented by ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T07:43:04.937",
"Id": "51193",
"Score": "0",
"Tags": null,
"Title": null
} | 51193 |
The Sieve of Eratosthenes is a prime-finding algorithm developed by the ancient Greek mathematician Eratosthenes. It works by writing down as many numbers as needed and then, traversing from lowest to highest, cross out all multiples of a number, beginning with 2. The numbers that remain are considered prime and the lo... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T07:43:04.937",
"Id": "51194",
"Score": "0",
"Tags": null,
"Title": null
} | 51194 |
<p>As part of an academic project I wrote a code about dynamic programming that solves the "Three-machine proportionate flow shop problem with unequal machine".</p>
<blockquote>
<p>In flow shop scheduling it is usually assumed that the processing
times of the operations belonging to the same job are unrelated... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T12:07:48.460",
"Id": "88383",
"Score": "0",
"body": "Have you tried profiling your code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T14:28:20.313",
"Id": "88402",
"Score": "1",
"body":... | [
{
"body": "<p><strong>Missing methods</strong> </p>\n\n<p>The posted code is missing the <code>schedule_left()</code> and <code>CreateOutputFile()</code> method. </p>\n\n<p><strong>Style</strong> </p>\n\n<ul>\n<li><p>you should always be consistent in the style you use. Switching from not using braces <code>... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T08:40:34.247",
"Id": "51198",
"Score": "7",
"Tags": [
"c#",
"performance",
"dynamic-programming"
],
"Title": "Three-machine proportionate flow shop problem with unequal machine"
} | 51198 |
<p>The following is an excerpt of a mostly text-based simulator of the iRobot Roomba robot vacuum. I made a class called Roomba that handles everything the roomba does. For those familiar with QT; There is also a class called MainWindow that handles the GUI. This is not that class.</p>
<p>The roomba has several command... | [] | [
{
"body": "<p>By \"optimizing\" you do not mean speed (as most do), but readability/maintainability. Thats good.</p>\n\n<p>You could create an array of function pointers where you store the actual voids, for example (this is dry-coded, could contain errors):</p>\n\n<pre><code>// somewhere in constructor\ntypede... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T09:01:11.290",
"Id": "51200",
"Score": "1",
"Tags": [
"c++",
"design-patterns",
"classes",
"qt"
],
"Title": "Text-Based Simulator with many commands"
} | 51200 |
<p>As a toy project, I started evaluating the Neo4J graph database and its Rest interface. I'm trying to write a simple graph visualization in JavaScript. In daily business I'm a Java developer and maybe that's the reason why I'm not that happy with my current approach. In Java I would have written a <code>Neo4J</code>... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>The most striking thing is your repeated use of this pattern:</p>\n\n<pre><code>connection.sanitizeId(response['xxx']);\n</code></pre>\n\n<p>I dont believe <code>sanitizeId</code> should be a function of <code>connection</code>. Also, <code>response</code> is not a ... | {
"AcceptedAnswerId": "51220",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T09:35:00.317",
"Id": "51202",
"Score": "3",
"Tags": [
"javascript",
"database",
"graph",
"wrapper",
"rest"
],
"Title": "Neo4J Rest Javascript wrapper"
} | 51202 |
<p>I am using Boost for reading a config file that is in the .json format. I am using a class to do this and I am calling <code>exit(message)</code> in case of bad values or default value gotten by Boost <code>get()</code> function.</p>
<p>The class is here:</p>
<pre><code>class ConfigFile
{
private:
PTree m_ptConf... | [] | [
{
"body": "<h2>Throwing</h2>\n\n<p>Yes, just throw it:</p>\n\n<pre><code>if (val1 < 0)\n throw MissingConfigValueException(\"getVal1() failed or val1 < 0\");\n</code></pre>\n\n<p>Don't print an error message before throwing. Printing is left to whoever catches the exception. For many exceptions (such as ... | {
"AcceptedAnswerId": "51346",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T10:22:30.980",
"Id": "51203",
"Score": "1",
"Tags": [
"c++",
"exception-handling",
"exception"
],
"Title": "How to add exceptions in a class that reads a config file?"
} | 51203 |
<p>I am trying to visualize a pointcloud centered around the origin. I also want to have a user controlled rotation for which I found the arcball.</p>
<p><code>rMat</code> is the model matrix, passed into the shader.</p>
<pre><code>inline QVector3D getArcballVector(const QPoint& pt, int width, int height)
{
Q... | [] | [
{
"body": "<p>After some research I found that it's slightly more efficient to get the half quaternion directly from the double quaternion:</p>\n\n<pre><code>QVector3D rotaxis = QVector3D::crossProduct (vec1, vec2);\ndouble cos = QVector3D::dotProduct (vec1, vec2);\n\n// rotaxis and cos describe the double quat... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T11:24:38.507",
"Id": "51205",
"Score": "7",
"Tags": [
"c++",
"matrix",
"opengl",
"qt"
],
"Title": "User controlled rotation with arcBall"
} | 51205 |
<p>I have posed another question <a href="https://codereview.stackexchange.com/q/51203/42809">here</a> and I am writing this one for some code review:</p>
<pre><code>class ConfigFile
{
private:
PTree m_ptConfig;
public:
ConfigFile(const std::string& name)
{
json::read_json(name, m_ptConfig);
}
~Co... | [] | [
{
"body": "<p>That is not really exception handling:</p>\n\n<h3>In your <code>main()</code> method:</h3>\n\n<p>You are branching on three different types of exceptions, but your action is the same: Print a message.\nDoing so is fine, but the point for different catch blocks is not obvious to me.\nAnyway:</p>\n\... | {
"AcceptedAnswerId": "51211",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T12:31:50.487",
"Id": "51209",
"Score": "0",
"Tags": [
"c++",
"exception-handling"
],
"Title": "Exception-handling optimisation"
} | 51209 |
<p>I have <strong><code>express</code></strong> <strong><code>node.js</code></strong> <em>server code</em> using <strong><code>Passport</code></strong>. It receives a user to authenticate it and send him to some data registration form.</p>
<p>Some concerns:</p>
<ul>
<li>My whole routes definition depends upon a Mongo... | [] | [
{
"body": "<p>First, read about how <a href=\"http://expressjs.com/4x/api.html#app.VERB\" rel=\"nofollow\">.get()</a> can chain multiple callbacks, then read how the <a href=\"https://github.com/jaredhanson/passport-local/blob/master/examples/login/app.js#L101\" rel=\"nofollow\">sample code of Passport</a> uses... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T13:41:38.637",
"Id": "51213",
"Score": "4",
"Tags": [
"javascript",
"node.js",
"mongodb",
"express.js",
"passport"
],
"Title": "Modularize this node.js express server code... | 51213 |
<p>Let's say I've got this string:</p>
<pre><code>$str = '1-2-3';
</code></pre>
<p>and I explode this like so:</p>
<pre><code>$strSplit = explode('-', $str);
</code></pre>
<p>what would be the best way to check if I've got the correct number of elements and whether they are numeric (because the input can vary)?</p>... | [] | [
{
"body": "<p>Using array functions could be the best choice. If you wanted to work on only the input that is numeric, you could use the <a href=\"http://www.php.net/manual/en/function.array-filter.php\" rel=\"nofollow\"><code>array_filter</code></a> function to get only those that are numeric. Otherwise, if yo... | {
"AcceptedAnswerId": "51230",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T13:58:32.940",
"Id": "51215",
"Score": "5",
"Tags": [
"php",
"strings",
"array"
],
"Title": "Check for correct number of elements in exploded string"
} | 51215 |
<p>I have 3 combo boxes with the same 3 selections in each. If the user picks the same selection a 2nd time, the first combo box resets. I have 3 other sections that will do the same with about 15 combo boxes.</p>
<p>Is there a shorter/compact way to code what I'm doing?</p>
<pre><code>Protected Sub ComBox_GER1_Selec... | [] | [
{
"body": "<p>It has been a long time since I've done VB, but here goes:</p>\n\n<p>If you put the comboboxes in an array, you can use 1 handler for all</p>\n\n<pre><code>Protected Sub ComBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComBox_GER1.SelectedIndexChanged ComBox_GER2.SelectedIndex... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T13:59:04.407",
"Id": "51216",
"Score": "4",
"Tags": [
"asp.net",
"vb.net"
],
"Title": "Three combo boxes"
} | 51216 |
<p>I have a shell script which is being used on an embedded human machine interface (HMI). This script is used to copy a few files from a USB stick to a different place on the device, but with multiple instances of the same file under different names.</p>
<p>If it helps:</p>
<ul>
<li>OS is Unix-like (BusyBox v1.11.2)... | [] | [
{
"body": "<p>A few comments. You make many copies of the files but JFFS2 seems to support hard links, so I would use links instead (see <code>man ln</code> and the <code>ln</code> command in the example below). Also you copy all files into temporary directories and then copy them to the target directory. Th... | {
"AcceptedAnswerId": "51976",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T14:05:09.590",
"Id": "51217",
"Score": "7",
"Tags": [
"file-system",
"shell",
"embedded",
"sh"
],
"Title": "Shell Script Image Replication"
} | 51217 |
<p>Previous question: <a href="https://codereview.stackexchange.com/questions/51095">BaseRepository for EF6</a></p>
<p>I've update my code. Is it correct now? I've changed <code>IEnumerable</code> to <code>IQueryable</code>.</p>
<pre><code>public interface IRepository<T> : IDisposable
{
T Get(Expression&l... | [] | [
{
"body": "<blockquote>\n <p><strong>DISCLAIMER</strong> I don't believe in wrapping EF with a repository. Entity Framework <em>is</em> a unit-of-work and repository implementation.</p>\n</blockquote>\n\n\n\n<blockquote>\n <p><em>I've changed IEnumerable to IQueryable.</em></p>\n</blockquote>\n\n<p>You've jus... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T18:05:56.517",
"Id": "51234",
"Score": "2",
"Tags": [
"c#",
"entity-framework"
],
"Title": "BaseRepository for EF6 - updated"
} | 51234 |
<p>I've designed those classes for use in a multiplayer game with possibly very high number of clients for one server. Is this implementation good, or is there something obvious I overlooked or something to improve? I expect this part to have very high performance, so that I can just focus on other things and not come ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T13:24:30.863",
"Id": "88790",
"Score": "1",
"body": "Do you really need to use the Boost threading API? Couldn't you replace it by the `std` one to reduce the number of external libaries?"
},
{
"ContentLicense": "CC BY-SA 3.... | [
{
"body": "<h3>Exception safety</h3>\n\n<p>Your <code>locked_queue</code> isn't exception safe. In particular:</p>\n\n<pre><code> queue.pop();\n return value;\n</code></pre>\n\n<p>If the copy (or move) constructor for <code>_T</code> throws, you could have popped the item from the queue, then the construc... | {
"AcceptedAnswerId": "51874",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T18:16:34.587",
"Id": "51235",
"Score": "24",
"Tags": [
"c++",
"game",
"c++11",
"networking",
"boost"
],
"Title": "UDP Network server/client for gaming using boost.asio"... | 51235 |
<p>I have the situation where as long as the user gives valid input, the StringBuilder object will not be null.</p>
<pre><code>StringBuilder sb = null;
switch(userInput)
{
case 1:
sb = method1();
break;
case 2:
sb = method2();
break;
case 3:
sb = method3();
break;
case 4:
sb = method4();
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T19:40:51.940",
"Id": "88461",
"Score": "0",
"body": "When you say : `The method does a lot of appending` do you refer to `method1` or actually the code your showing? I can get that `method1` does a lot of appending and could need an... | [
{
"body": "<p>You need to ensure that every statement in the <code>switch</code> is one that ensures that <code>sb != null</code> holds, this is not the case currently.</p>\n\n<p>You can fix this by throwing an exception instead of logging a message, like this:</p>\n\n<pre><code>default:\n throw new IllegalA... | {
"AcceptedAnswerId": "51237",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T18:32:40.813",
"Id": "51236",
"Score": "6",
"Tags": [
"java",
"strings",
"null"
],
"Title": "How do I better structure Java code to avoid dereferencing null?"
} | 51236 |
<p>I wrote a program that managed projects and created a set of SQL files for each project. In the logic, I have a few functions that, each time I look at them, I wonder if they could be written in a better way. They are pretty straight forward and compact, however I feel like there are better, more efficient ways of c... | [] | [
{
"body": "<h2>Oxford comma</h2>\n\n<p>Are these really your expected outcomes?</p>\n\n<pre><code># for ['a']\nConfigs not found for: and a.\n\n# for ['a', 'b']\nConfigs not found for: a and b.\n\n# for ['a', 'b', 'c']\nConfigs not found for: a, b, and c.\n</code></pre>\n\n<p>In particular, the case of a sing... | {
"AcceptedAnswerId": "51246",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T18:37:17.027",
"Id": "51238",
"Score": "4",
"Tags": [
"python",
"optimization",
"strings",
"formatting"
],
"Title": "Refactor Oxford Comma function (and other functions)"
} | 51238 |
<p>My current code: </p>
<pre><code>val headers : Map[String, Seq[String]] = ...
//NOTE: ("key" -> Seq()) is valid entry
headers.toList flatMap {x => x._2 map { y => (x._1 -> y) }}
</code></pre>
<p>This feels clumsy...is there a better way to do this?</p>
<h1>Goal</h1>
<p>I have a Map[String, Seq[Stri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T20:22:37.507",
"Id": "88473",
"Score": "0",
"body": "Please provide an explanation of what your code is trying to accomplish, this enables more people to understand your code and you will get answers faster."
},
{
"ContentLi... | [
{
"body": "<p>I don't see how the functional code looks clumsy or difficult to read. If you have problems reading functional code, than don't write it - the imperative code is entirely fine, as long as the side effects remain local to a single function.</p>\n\n<p>A lot of readability can be gained by giving you... | {
"AcceptedAnswerId": "51257",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T19:00:56.653",
"Id": "51241",
"Score": "1",
"Tags": [
"functional-programming",
"scala"
],
"Title": "Converting A Map[String, Seq[String]] To A Seq[(String, String)] in Scala"
} | 51241 |
<p>How can I write my code more efficient (not repeating same code)?</p>
<p>And is there a solution that simplifies the way of having to create a lot of dependency objects over and over again whenever I instantiate a new class (as seen in the load method)?</p>
<p>Any suggestions are welcome.</p>
<pre><code>class Rou... | [] | [
{
"body": "<p>If this unit of code is a router, then it should remain a router. Have the controller handle its dependencies. You could have multiple controllers, each with its own dependencies. You wouldn't want a single router code become a monster just to keep up with the controllers.</p>\n\n<pre><code>class ... | {
"AcceptedAnswerId": "51256",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T19:25:09.410",
"Id": "51244",
"Score": "0",
"Tags": [
"php",
"object-oriented",
"mvc",
"url-routing"
],
"Title": "URL router that loads dependent objects"
} | 51244 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.