body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I made the code, and it works, but it uses many <code>if</code> conditions and it looks ugly. I would really appreciate it if someone could give me a hand by pointing me in the right direction to make it more object-oriented.</p>
<pre><code>package ar.edu.uca.ceis.objetos.imperio;
import ar.uba.fi.algo3.batallaes... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T14:26:18.033",
"Id": "42343",
"Score": "3",
"body": "would you be so kind and rewrite your code in english please. and as far as i can see you make no difference between allied and hostile bases"
},
{
"ContentLicense": "CC B... | [
{
"body": "<p>Your Professor has assigned you code that fails to meet some basic tenets of object-oriented programming, including:</p>\n\n<ul>\n<li><a href=\"http://c2.com/cgi/wiki?EncapsulationIsNotInformationHiding\" rel=\"nofollow noreferrer\">Information Hiding</a></li>\n<li>The <a href=\"http://c2.com/cgi/... | {
"AcceptedAnswerId": "27273",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T14:09:59.637",
"Id": "27268",
"Score": "4",
"Tags": [
"java",
"game",
"homework"
],
"Title": "Battleship type game in Java"
} | 27268 |
<p>I have a program which is primarily illustrative in example to help me learn refactoring techniques and best practices. This program will take the <code>ActiveTabIndex</code> property of a <code>TabContainer</code> control and add a <code>GridView</code> control to the page and bind it to a database using a stored ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T22:11:09.487",
"Id": "42377",
"Score": "1",
"body": "Save \"spTest0\", \"spTest1\", \"spTest2\", etc. as a `Tag` property of a `Tab`. Get the active tab, get its tag, convert that to string and use it as a stored procedure name. Onc... | [
{
"body": "<p>Leonid's comments cover structure nicely, so I will tackle stylistic points (working off your streamlined edit).</p>\n\n<p><strong>Naming</strong></p>\n\n<p>Avoid shortened form variable names. Extra characters on a variable's name are free, and work wonders for a maintenance programmer down the l... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T16:19:43.437",
"Id": "27272",
"Score": "1",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Button clicks to add GridViews inside TabContainer"
} | 27272 |
<p>I have implemented a <a href="https://buddy.codeplex.com/SourceControl/latest#Buddy/Buddy-.NET-4.5/Buddy/WaitGroup.cs" rel="nofollow">WaitGroup</a> class to simulate WaitGroup in Go lang. Then I've found that I can use <a href="http://msdn.microsoft.com/query/dev11.query?appId=Dev11IDEF1&l=EN-US&k=k%28System... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T09:30:11.233",
"Id": "42354",
"Score": "0",
"body": "The question is about C#; not Go. I am \"simulating\" this feature of Go, in C#. It's not a comparison. BTW I like Go."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creatio... | [
{
"body": "<pre><code>if (WaitGroupBarrier.ParticipantsRemaining > 0) {\n WaitGroupBarrier.SignalAndWait();\n}\n</code></pre>\n\n<p>The above is a non-atomic operation. Thus if the if branch gets evaluated and there is one remaining, but finishes before SignalAndWait, then this will throw an exception.</p... | {
"AcceptedAnswerId": "29244",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T09:27:04.083",
"Id": "27274",
"Score": "1",
"Tags": [
"c#",
"multithreading",
"go",
"task-parallel-library"
],
"Title": "Using Barrier to Implement Go's Wait Group"
} | 27274 |
<p>OK, this question may seem a little strange at first; however I'd like to have your comments on it.</p>
<p>Background: I do Java. A lot. Java is a statically typed language, it has means to restrict visibility of instance variables, etc. And as such the builder pattern (see <a href="http://en.wikipedia.org/wiki/Bui... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T20:48:55.950",
"Id": "42370",
"Score": "1",
"body": "Very cool, if you pardon the pun. The names thaw and freeze might be more precisely labelled as `mutable` and `immutable`, or `makeMutable` and `makeImmutable` to avoid any keywor... | [
{
"body": "<p>Pattern pros and cons :</p>\n\n<p>Pros :</p>\n\n<ul>\n<li>easy to use</li>\n<li>readable (provided you are familiar with the pattern)</li>\n</ul>\n\n<p>Cons :</p>\n\n<ul>\n<li>forces a cyclic dependency between builder and the class being built (we're probably not crossing package boundaries, thou... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T18:50:20.590",
"Id": "27276",
"Score": "7",
"Tags": [
"java",
"design-patterns"
],
"Title": "Design pattern review: freeze/thaw (aka, \"reversible builder\" pattern)"
} | 27276 |
<p>I'm converting some C# code to F#. Basically it is some geometry classes that can have properties tuned by a numerical solver. I start with a discriminated union of type <code>parameter</code> that can be fixed or free ( tunable ) and then build tunable geometry objects out of them.</p>
<p>I create a discriminated ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T19:12:13.337",
"Id": "42365",
"Score": "0",
"body": "There are a lot of things for the compiler not to like. Do some basic clean-up (correct caps, supply correct parameter types, etc) and re-post with a specific question."
},
{
... | [
{
"body": "<p>A few suggestions on the first code fragment:</p>\n\n<ul>\n<li>Change type names to upper case</li>\n<li>Change record field names to upper case</li>\n<li>Change fields of <code>line</code> to <code>Begin</code> and <code>End</code> to be descriptive</li>\n<li>Use pattern matching on records inste... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T19:04:21.670",
"Id": "27277",
"Score": "2",
"Tags": [
"f#"
],
"Title": "Improve this numeric solver for properties of geometric objects"
} | 27277 |
<p>I need to concatenate two content_tag and it works but it seems a little messy to me. Any thoughts on how may I refactor this?</p>
<pre><code>def format_price(money)
mny = get_price_string(money).to_money
str = content_tag(:span, @visitor.currency.symbol.html_safe, class: 'pounds')
str << mny.format(no_... | [] | [
{
"body": "<p>Notes:</p>\n\n<ul>\n<li><p>Before refactoring, let's identify what makes this code feel \"messy\". IMO there are two problems: the in-place method <code><<</code> and the inline statement <code>unless</code>. As usual, I'll try to make the case for functional programming (as opposed to imper... | {
"AcceptedAnswerId": "27304",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T21:26:22.530",
"Id": "27279",
"Score": "1",
"Tags": [
"ruby",
"html",
"ruby-on-rails"
],
"Title": "content_tag concatenation clean up"
} | 27279 |
<p>I'm working on a school assignment, and it's working fine, but I have a feeling I'm over-using pointers, and I just can't think of a way to not pass a triple pointer to the function <code>readFile</code>.</p>
<p>I'd be more than grateful for your suggestions, and if you have any other suggestions on how to improve ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T13:40:57.087",
"Id": "42431",
"Score": "0",
"body": "Your tripple pointer is indeed unnecessary - just return the `char**` from `readFile`"
}
] | [
{
"body": "<h3>1. Introduction</h3>\n\n<p>You'll see that I made a lot of comments below, but if you're just starting to learn C, then your code is not at all bad. C is a tough language to write robust code in: it provides many many ways to go wrong, and even the most expert and experienced programmers don't al... | {
"AcceptedAnswerId": "27403",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-11T22:54:10.130",
"Id": "27281",
"Score": "3",
"Tags": [
"c",
"file",
"pointers"
],
"Title": "Use of pointers with file-reading program"
} | 27281 |
<p>I've began to read the book <em>Clean Code</em> by Robert Martin, I had a strong desire to learn how to write code that's easy for others to understand. Please criticize my code.</p>
<p><strong>PuzzlesView.java</strong></p>
<pre><code>// Using of PuzzlesView:
// dimension = new Dimension(rows, columns)
// puzzlesV... | [] | [
{
"body": "<p>Excellent coding. I don't claim to understand all your code, but your writing style made it easier for me to review.</p>\n\n<p>I have three suggestions. I've found these suggestions to be helpful to me with large Java code bases.</p>\n\n<p>1) Define your class variables in alphabetical order by ... | {
"AcceptedAnswerId": "27309",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T07:41:18.763",
"Id": "27292",
"Score": "0",
"Tags": [
"java",
"android"
],
"Title": "Review my PuzzlesView Android component"
} | 27292 |
<p>Could you please help me to review my first function (modified from an example) in terms of best practice, coding style suggestions and any obvious language mistake/improvements?</p>
<pre><code>unsigned int edit_distance(const vector<string> &s1, const vector<string> &s2)
{
const size_t len1... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T13:59:59.420",
"Id": "42432",
"Score": "3",
"body": "For starters you need a function comment, explain what its doing, use readable variable names. You don't get any performance improvement from minified code."
}
] | [
{
"body": "<p>Do you want <code>unsigned int</code> or do you want <code>std::size_t</code>?</p>\n\n<pre><code>unsigned int edit_distance(const vector<string> &s1, const vector<string> &s2)\n</code></pre>\n\n<p>It comes down to what you are trying to convey.<br>\nThe use of <code>string</cod... | {
"AcceptedAnswerId": "27306",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T09:20:47.007",
"Id": "27294",
"Score": "2",
"Tags": [
"c++",
"edit-distance"
],
"Title": "Edit distance function"
} | 27294 |
<p>I have crated the following small script. I just need to improve this complicated code if possible.</p>
<pre><code>def convUnixTime(t):
expr_date = int(t) * 86400
fmt = '%Y-%m-%d %H:%M:%S'
d1 = datetime.date.today().strftime('%Y-%m-%d %H:%M:%S')
d2 = datetime.datetime.fromtimestamp(int(expr_date)).... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T09:54:00.197",
"Id": "42410",
"Score": "1",
"body": "What is your reason to do `strftime` followed by `strptime`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T09:56:05.450",
"Id": "42411",
... | [
{
"body": "<p>I think the main issue here is that you are trying to reuse snippets from Google without trying to understand what is doing what.</p>\n\n<p><strong>Magic numbers</strong></p>\n\n<p>This might be purely personal but I find <code>60*60*24</code> much easier to understand than <code>86400</code>.</p>... | {
"AcceptedAnswerId": "27303",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T09:49:25.310",
"Id": "27295",
"Score": "1",
"Tags": [
"python",
"beginner",
"datetime"
],
"Title": "Converting UNIX time"
} | 27295 |
<p>Is this the correct implementation of a singleton using enum?</p>
<pre><code>public class Item3 {
public static void main(String[] args) {
Singleton s=Singleton.Single.INSTANCE.getInstance();
Singleton s2=Singleton.Single.INSTANCE.getInstance();
System.out.printf("%b",s==s2);
}
}
class Singleton {
... | [] | [
{
"body": "<p>No, it is simpler to code than that:</p>\n\n<pre><code>enum Singleton\n{\n INSTANCE;\n\n // instance vars, constructor\n private final Connection connection;\n\n Singleton()\n {\n // Initialize the connection\n connection = DB.getConnection();\n }\n\n // Static g... | {
"AcceptedAnswerId": "27298",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T09:56:55.700",
"Id": "27296",
"Score": "18",
"Tags": [
"java",
"singleton",
"enum"
],
"Title": "Singleton using enum"
} | 27296 |
<p>I want a good design to implement a master-slave protocol. The protocol is proprietary and similar to <a href="http://www.cctalk.org/" rel="nofollow">cctalk</a>.
We have:</p>
<p>Master: <code>HEADER [ DATA ] CHECKSUM</code><br>
Slave: <code>HEADER [ DATA ] CHECKSUM</code></p>
<p>My choice was to have concrete base... | [] | [
{
"body": "<p>A possible altenrative implementation can be the following:</p>\n\n<p>All the packet have no inheritance, nor recieved packet nor sent packet</p>\n\n<p><code>PacketOutA</code>, <code>PacketOutB</code>, <code>PacketOutC</code> are all classes with a common interface, they have just two method: <cod... | {
"AcceptedAnswerId": "27404",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T10:02:07.120",
"Id": "27297",
"Score": "6",
"Tags": [
"c++",
"design-patterns"
],
"Title": "Design for a protocol based software in C++"
} | 27297 |
<p>Any time I'm testing a Ruby class that calls a Kernel method such as <code>sleep</code> or <code>exit</code>, i define a singleton method on the class instance and test that it has been invoked:</p>
<pre><code>it "must throttle requests" do
sleep_was_called = false
subject.define_singleton_method(:sleep) { |se... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T12:02:56.263",
"Id": "42610",
"Score": "1",
"body": "This seems like more of an SO type question."
}
] | [
{
"body": "<p>I know MiniTest has an expectations framework, but I'm not familiar with it. I use rspec-expectations to accomplish this, like so:</p>\n\n<pre><code>describe ClassName do\n let(:subject) { described_class.new }\n\n describe '#method' do\n it 'should sleep 3 times and output hello world' do\n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T11:16:36.687",
"Id": "27299",
"Score": "0",
"Tags": [
"ruby"
],
"Title": "Am I correctly testing that methods from Kernel have been called?"
} | 27299 |
<p>I need to find the flaws in this design. So far the only ones i can think of are:</p>
<ul>
<li>No use of generics</li>
<li>the class Concept uses a parametrized constructor, which means every sub class would need to pass a parameter. The setter method could be used instead. </li>
</ul>
<p>Can you think of anymore ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T11:55:42.023",
"Id": "42418",
"Score": "1",
"body": "Finding flaws, OK, but you need to tell us what you want to do with these classes first ;)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T11:58:54... | [
{
"body": "<p>i would rewrite your equals method a bit (just for readability)</p>\n\n<pre><code>public boolean equals(Object other) {\n if(this == other) {\n return true;\n }\n\n if(!(other instanceof Concept)) {\n return false; \n }\n\n Concept otherConcept = (Concept) other... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T11:47:12.113",
"Id": "27301",
"Score": "-1",
"Tags": [
"java",
"object-oriented",
"inheritance"
],
"Title": "Design of Concept Class"
} | 27301 |
<p>I'm new to Elixir, and in order to learn the syntax, I'm doing a roman numeral kata which converts a decimal number into roman numeral. I would appreciate any feedback you have.</p>
<pre><code>defmodule RomanNumeral do
@decimal_roman_numerals [[5, 'V'], [4, 'IV'], [1, 'I']]
def converts(number) do
convert... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-18T13:58:13.873",
"Id": "66300",
"Score": "0",
"body": "That is a very Prolog solution, which is good because Erlang is prolog inspired.]"
}
] | [
{
"body": "<p>Your code looks very nice indeed, I only have some minor observations you code use to improve this code:</p>\n\n<p><strong>Naming</strong><br>\nUse the imperative form of the verb (<code>convert</code> instead of <code>converts</code>)</p>\n\n<p><strong>Implementation Hiding</strong><br>\nUse <cod... | {
"AcceptedAnswerId": "60279",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T15:20:06.603",
"Id": "27310",
"Score": "10",
"Tags": [
"beginner",
"roman-numerals",
"elixir"
],
"Title": "Roman numeral kata in Elixir"
} | 27310 |
<p>I am working on a Java program which creates a map using Voronoi. I am using a <a href="http://sourceforge.net/projects/simplevoronoi/" rel="nofollow">Java library which generates Voronoi</a> and it is very fast.</p>
<p>The problem I am facing is that, then, I have to scan every Voronoi edge to know what point is o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T21:37:09.737",
"Id": "42476",
"Score": "0",
"body": "I ALMOST solved it here http://stackoverflow.com/questions/17072832/how-to-optimize-this-loop/17072926?noredirect=1#17072926 HashMap answer"
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>To improve the speed of your code, you'd really have to profile it, and know what the bottleneck is (use a profiler, and find out in what methods most of the time is spent).</p>\n\n<p>Here's what I would have a look at <em>(no promise it will yield significant improvements)</em>.</p>\n\n<ul>\n<li>... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T18:41:13.163",
"Id": "27314",
"Score": "2",
"Tags": [
"java",
"performance",
"coordinate-system"
],
"Title": "Constructing polygons from the edges in a Voronoi diagram"
} | 27314 |
<p>This is DFS/BFS C++ code for Cormen pseudo code. Please comment on this.</p>
<pre><code>#include "iostream"
#include "vector"
#include "list"
enum color{
WHITE,
GREY,
BLACK
};
struct edge{
int destination_vertex;
edge(int ver){
destination_vertex = ver;
}
};
struct vertex{
int... | [] | [
{
"body": "<h2>Preliminaries</h2>\n\n<p>It's conventional to include system headers <a href=\"https://stackoverflow.com/a/3162067/819272\">with brackets instead of quotes</a> and <a href=\"https://stackoverflow.com/a/471461/819272\">prefer <code>std::vector</code> over <code>std::list</code></a> unless proven w... | {
"AcceptedAnswerId": "27372",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T18:50:40.463",
"Id": "27316",
"Score": "5",
"Tags": [
"c++",
"graph",
"breadth-first-search",
"depth-first-search"
],
"Title": "DFS/BFS implementation of Cormen's pseudo co... | 27316 |
<p>I hate having almost two identical blocks do almost the exact same thing.</p>
<p><strong>I am working with Entity Framework 4.4.0.0<br />
Asp.Net MVC</strong></p>
<p>Right now if the user is a "manager" I want to show them the entire list, if they are a normal user or a Team Lead. I only want to show them their s... | [] | [
{
"body": "<p>Merge your if statement into the <code>where</code> clause.</p>\n\n<pre><code>public ActionResult Index()\n{\n AD_CurrentUserProfile currentUP = new ActiveDirectory().GetUserProfile(User.Identity.Name.Split(\"\\\\\".ToCharArray())[1].ToString());\n\n IQueryable<IPACS_DT_MasterList> mod... | {
"AcceptedAnswerId": "97604",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T18:52:56.043",
"Id": "27317",
"Score": "2",
"Tags": [
"c#",
"linq",
"entity-framework",
"asp.net-mvc-4"
],
"Title": "Restricting search to a user's own department, if the u... | 27317 |
<p>Basically, the code converts a large select list with optgroups into a more user-friendly tabbed Twitter-bootstrap component.</p>
<p>I'm not sure how much into detail I need to get but on GitHub I uploaded a <a href="https://github.com/alphacss/bootstrap-tabbed-select" rel="nofollow noreferrer">working example</a>.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T21:13:13.450",
"Id": "42470",
"Score": "0",
"body": "I set up a working example at http://tinker.io/fce06, would you please take a look an make sure that it looks and works as you would expect? It looks good to me."
}
] | [
{
"body": "<p>In order to be able to use this plugin on a page with multiple forms, I would recommend identifying the specific form that you are operating on. I can see that you are aware of the issue because you have been using the context parameter in most of the selectors, but since the <code><form></c... | {
"AcceptedAnswerId": "27324",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T19:57:59.973",
"Id": "27321",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"twitter-bootstrap"
],
"Title": "Twitter-bootstrap add-on"
} | 27321 |
<p>So I have a <code>DataTable</code> that returns results within a month to month range when available. However, when I format the return, I need to still show skipped months as blanks.</p>
<p>I have a working solution, but it's a little verbose and I think it can be done cleaner.</p>
<p><strong>Here's a setup to t... | [] | [
{
"body": "<p>You can have fewer lines of code by creating a the list of missing dates in a single Linq query.</p>\n\n<p>The idea is:</p>\n\n<ul>\n<li>Get the list of all dates in the given time period) </li>\n<li>Left-Outer-Join this list with the list of given dates </li>\n<li>Add the missing dates to the o... | {
"AcceptedAnswerId": "28916",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-12T21:07:37.730",
"Id": "27322",
"Score": "1",
"Tags": [
"vb.net",
".net-datatable"
],
"Title": "Adding blank rows for every skipped value in a DataTable"
} | 27322 |
<p>Ok, So first I must say that everything I know about coding I have learned on my own in my spare time so bear with me if my code is primitive, but please, I am open to any comments to make me better...</p>
<p>Anyway, as for my question. I have an application I am building in C# for .NET Compact Framework (for an HP... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T21:28:03.277",
"Id": "42556",
"Score": "0",
"body": "You could organize the buttons by keeping them in an array or list and then create a generic click event. If you have certain data associated with the buttons, such as prices and ... | [
{
"body": "<h2>Clear your namings</h2>\n\n<p><code>button9.Text = buttonNames[0];</code> should be <code>button0.Text = buttonNames[0];</code>\nThis is also applies to your prices array.</p>\n\n<h2>One event handler method</h2>\n\n<p>Create one event handler which is subscribed on every buttons' <code>OnClick</... | {
"AcceptedAnswerId": "27338",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T06:50:45.957",
"Id": "27335",
"Score": "11",
"Tags": [
"c#",
".net",
"array"
],
"Title": "Repetitive code driving me crazy!"
} | 27335 |
<p>I'm trying to reduce consecutive elements of array to one, but not for all values like:</p>
<pre><code>{3,0,0,0,3,3,3,0,0,0} => {3,0,3,0}
</code></pre>
<p>but for specific one, in my example 0:</p>
<pre><code>{3,0,0,0,3,3,3,0,0,0} => {3,0,3,3,3,0}
</code></pre>
<p>so only zeros (the threes are intact) are ... | [] | [
{
"body": "<p>You can have the same output with <em>regex</em> , using <code>Arrays.toString(char[])</code>:</p>\n\n<pre><code>System.out.println(\"000300300030303330000\".replaceAll(\"[0]+\", \"0\"));\n</code></pre>\n\n<p>or, with a parameter :</p>\n\n<pre><code>char charToRemove = '0' ;\nSystem.out.println(\"... | {
"AcceptedAnswerId": "27345",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T09:16:07.590",
"Id": "27339",
"Score": "2",
"Tags": [
"java",
"algorithm",
"strings",
"array"
],
"Title": "Remove specific consecutive element in array"
} | 27339 |
<p>This algorithm is intended to determine the epsilon of a given double precision number. As numbers increase in value, their accuracy decreases. This algorithm will return the smallest increment / decrement possible at any given value.</p>
<p>Given the way floating point numbers are structured, is there logically an... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T13:24:13.297",
"Id": "42504",
"Score": "0",
"body": "Can you add an explanation or a link to explain what this is supposed to do? And/or sample input. I get 0 no matter what I pass in."
},
{
"ContentLicense": "CC BY-SA 3.0... | [
{
"body": "<pre><code>a != double.NegativeInfinity && a != double.PositiveInfinity\n</code></pre>\n\n<p>This could be simplified to just <code>double.IsInfinity(a)</code>. Though as far as I know, it is correct. I was worried that there may be more values representing infinity, like there are for <code>... | {
"AcceptedAnswerId": "27359",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T11:14:03.923",
"Id": "27344",
"Score": "1",
"Tags": [
"c#",
"algorithm",
"mathematics"
],
"Title": "Is this routine for determining the epsilon of a Double 100% valid?"
} | 27344 |
<p>I am basically looking for Critique on the following code as i know its not the best and i am trying to find a set way of building javascript objects.</p>
<p>Be brutal as you way its a learning tool for me, basically i am pulling in a twitter feed via json and adding it to the dom.</p>
<pre><code>var TwitterTimeli... | [] | [
{
"body": "<pre><code> //Let's wrap this module in a closure so we can have a private scope for our\n //module. That way, we don't expose too many globals as well as place too\n //many things in our namespace\n;\n(function (exports) {\n\n //Let's pull out these guys since they are static, and we don't want the... | {
"AcceptedAnswerId": "27353",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T13:53:25.647",
"Id": "27350",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Best practice javascript objects"
} | 27350 |
<p>Just checking that this shuffling algorithm is suitable. Or maybe there could be improvements?</p>
<pre><code>public static void shuffleArray(Object[] arr, Random rnd){
int lastIndex = arr.length - 1;
for (int i=0; i<=lastIndex; i++){
int k = nextInt(i,lastIndex+1, rnd);
Object a = arr[i]... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T14:33:34.260",
"Id": "42511",
"Score": "1",
"body": "Those +1 and -1 hurt my eyes."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T15:20:49.220",
"Id": "42519",
"Score": "1",
"body": "Hmm,... | [
{
"body": "<p>One small thing is during the last iteration of the loop, the last element is swapped with itself.</p>\n\n<p>Why not just use the <code>Collections.shuffle</code> as a guide?</p>\n\n<pre><code>public static void shuffle(List<?> list, Random rnd) {\n int size = list.size();\n if (size &... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T14:15:02.733",
"Id": "27351",
"Score": "2",
"Tags": [
"java",
"algorithm",
"random"
],
"Title": "Shuffling algorithm suitable?"
} | 27351 |
<p><strong>Edit:</strong> Disclaimer: I am new to templates and traits.
I apologize in advance if this is a bad question.</p>
<p>I am refactoring two similar classes with small differences strewn all over them into one template class (or I am trying to anyway).
This is something I just wrote. (I hope I didn't make any... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T22:34:52.283",
"Id": "42707",
"Score": "1",
"body": "Do you think you could prepare a [Short, Self Contained, Correct Example (SSCCE)](http://sscce.org/) (at minimum, something that can be compiled with an [on-line compiler](http://... | [
{
"body": "<p>Yes, the <code>std</code> way of doing things in C++ would be to provide static member functions of your traits type. Consider:</p>\n\n<pre><code>// declaration - empty\ntemplate <typename SETTINGS>\nstruct SettingsTraits;\n\n// specialization for type CFoo\ntemplate <>\nstruct Setting... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T16:48:22.927",
"Id": "27361",
"Score": "3",
"Tags": [
"c++",
"template",
"template-meta-programming"
],
"Title": "Should I use an object or type as trait?"
} | 27361 |
<p>I am attempting to write a function to calculate a user's Chinese zodiac sign based on his or her birthday for Drupal.</p>
<p>I originally had a function for calculating based on the Gregorian calendar (1924 = Rat, 1925 = Ox). This was easy to write, but several of my users have complained that the Chinese zodiac ... | [] | [
{
"body": "<p>My PHP is a bit rusty, but I think you could use two-dimensional arrays, maybe a structure like this:</p>\n\n<pre><code>$dates = array( \"1924\" => array( \"month\" => 2, \"day\" => 4),\n \"1925\" => array( \"month\" => 2, \"day\" => 23),\n ... );... | {
"AcceptedAnswerId": "27366",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T17:00:10.360",
"Id": "27362",
"Score": "4",
"Tags": [
"php",
"datetime"
],
"Title": "Calculating Chinese zodiac signs based on birthdays"
} | 27362 |
<blockquote>
<ol>
<li>Each element of the array is a coordinate <code>(x, y)</code>.</li>
<li>Each coordinate has two labels.</li>
</ol>
<p>Goal:
sum the elements that have the same two labels.</p>
</blockquote>
<p>How can this be made faster?</p>
<pre><code>import numpy
from scipy import ndimage
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-04T19:16:34.037",
"Id": "98764",
"Score": "9",
"body": "In your example code, where does `position` come from?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T17:33:18.897",
"Id": "27364",
"Score": "5",
"Tags": [
"python",
"array",
"mathematics",
"numpy"
],
"Title": "Summing 2D NumPy array by multiple labels"
} | 27364 |
<p>I just want to know if there room for improvement or something I should redo to be better.</p>
<pre><code>var dataCell = new Array();
dataCell[0] = document.getElementById("data0");
dataCell[1] = document.getElementById("data1");
dataCell[2] = document.getElementById("data2");
dataCell[3] = document... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T18:53:02.870",
"Id": "42540",
"Score": "0",
"body": "No, it does not. Sorry, but it looks pretty bad. You're using ids like arrays, editing HTML as strings and so on."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<ol>\n<li><p>Where you have a load of html elements with similar functions it's useful to either include them in one containing element or give them all the same <code>class</code>. Then you can access them in the JavaScript using:</p>\n\n<pre><code>var dataCell = document.getElementsByClassName('dat... | {
"AcceptedAnswerId": "27370",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T18:41:29.517",
"Id": "27368",
"Score": "4",
"Tags": [
"javascript",
"ajax",
"finance"
],
"Title": "Managing debit/credit accounts"
} | 27368 |
<p>While solving a problem on an online judge, I tried with these two implementations.</p>
<p>These two implementations do the same thing. Task is to report duplicate entry for a given set of data.</p>
<p>Implementation #1 : Converts input data to a <code>String</code> and adds to a <code>HashSet</code>. After all th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T19:38:49.123",
"Id": "42547",
"Score": "3",
"body": "I'd say it's the string concatenation in version 1. Not sure though. You may want to give a try at caliper for being sure."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cre... | [
{
"body": "<ol>\n<li><code>String.equals()</code> compare their <code>char[]</code> inside, which is slower than simply compare two <code>int</code>s.</li>\n<li><code>String</code> concatenation is slower than creating a <code>Database</code>.</li>\n<li><code>String.hashcode()</code> is just like its <code>equa... | {
"AcceptedAnswerId": "27389",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T19:28:32.317",
"Id": "27371",
"Score": "1",
"Tags": [
"java",
"performance",
"comparative-review"
],
"Title": "Reporting duplicate entry for a given set of data"
} | 27371 |
<p>I am working on a way to parse data using xml. </p>
<p>The file that I am given contains lines that look like this:</p>
<pre><code>George | Washington | Carver
</code></pre>
<p>or someone else can send me someting like this</p>
<pre><code>Carver | Washington | George
</code></pre>
<p>And so on...</p>
<p>No ma... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T21:14:17.483",
"Id": "42553",
"Score": "1",
"body": "If you're not going to need to configure anything else, then I think XML is an overkill. A simple text file containing `0 1 2` would suffice."
},
{
"ContentLicense": "CC B... | [
{
"body": "<p>You can use the order of XML nodes as field order:</p>\n\n<pre><code><importformat>\n <firstname/>\n <middlename/>\n <lastname/>\n</importformat>\n</code></pre>\n\n<p>and parse it like that:</p>\n\n<pre><code>public static string[] GetFieldsOrder(string xmlCo... | {
"AcceptedAnswerId": "27399",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T20:20:45.517",
"Id": "27373",
"Score": "1",
"Tags": [
"c#",
"xml"
],
"Title": "Parsing XML in C# .NET"
} | 27373 |
<p>I'm working on a CMS, currently on being able to create static pages, manage menus etc.
so.. I have This function that reads from the DB and finds all the static pages, and their position in the menu.
I want to know what Do you think. </p>
<pre><code>function update_menu(&$pdo, $filepath){
$qry = "SELECT * FROM... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T22:14:59.047",
"Id": "42561",
"Score": "0",
"body": "See: http://codereview.stackexchange.com/a/26810/20611"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T22:25:54.810",
"Id": "42562",
"Score... | [
{
"body": "<p>I think it overall is good, but there's some minor changes that could still quicken this script, namely using <code>fetchAll</code> and <code>foreach</code> instead of <code>fetch</code> and <code>while</code></p>\n\n<p>using fetchAll will get the values quicker then fetch on every single row. als... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-13T22:05:58.410",
"Id": "27375",
"Score": "1",
"Tags": [
"php",
"mysql",
"pdo"
],
"Title": "Pages system PHP/SQL"
} | 27375 |
<p>Previous review of this project:</p>
<p><a href="https://codereview.stackexchange.com/questions/27154/am-i-following-any-bad-practices-in-my-updated-card-and-deck-classes">Card Deck class for a Poker game - version 2</a></p>
<p>This time, I considered combining both classes into one header file so that I can reduc... | [] | [
{
"body": "<p>Okay, I'm liking this better than <code>namespace</code> and <code>extern</code>. No more global access. I've instead moved the variables into <code>Deck</code> while declaring <code>Card</code> as a <code>friend</code>. These variables are still accessible to <code>Card</code>'s implementation... | {
"AcceptedAnswerId": "104183",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T00:08:25.313",
"Id": "27379",
"Score": "6",
"Tags": [
"c++",
"classes",
"playing-cards"
],
"Title": "Deck and Card classes and member-accessing with one header"
} | 27379 |
<p>I have these two functions and I was just wondering if there is any way to shorten the line of code with the many && statements. Shortening of the rest of the code would be cool too, but it's not necessary. I'm trying to learn if there is a better way to accomplish this though. </p>
<pre><code># Accepts two... | [] | [
{
"body": "<p>The code in the if is duplicate, so we can extract it to a method that I will call gte (greater than or equal). The maxs and mins values are used at this comparison, so they will be moved to the new method too:</p>\n\n<pre><code>def gte(bounds1, bounds2)\n min_x, max_x, min_y, max_y = 0, 1, 2... | {
"AcceptedAnswerId": "27387",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T02:04:57.593",
"Id": "27383",
"Score": "1",
"Tags": [
"ruby",
"collision"
],
"Title": "Checking whether two strokes overlap"
} | 27383 |
<p>I wrote a function to find a specific fibonacci number, which runs in <code>O(lg n)</code>. Then I modified it with a template. Though it works, I'm new to template and want to know if I used template correctly. Moreover, I wonder whether someone who has a <code>BigNumber</code> class
can use my function without mod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T04:28:28.497",
"Id": "42576",
"Score": "0",
"body": "`using namespace std` is not good to use. [Read this](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) for more information.`system(... | [
{
"body": "<p>As always, <code>using namespace std;</code> is dangerous. In fact, there is a <code>tuple</code> class in C++11, <code>std::tuple</code>. You could very easily have a naming collision here thanks to that.</p>\n\n<p>Why bother using a template for the size if you compare it to an <code>int</code>... | {
"AcceptedAnswerId": "27394",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T03:21:45.697",
"Id": "27388",
"Score": "3",
"Tags": [
"c++",
"algorithm",
"template"
],
"Title": "O(lg n) algorithm for a fibonacci number with c++ template"
} | 27388 |
<p>Normally I do this:</p>
<pre><code>if (Animal is Dog)
{
Doc d = (Dog)Animal;
// d. etc..
}
else if (Animal is Cat)
{
Cat c = (Cat)Animal;
// c. ....
}
</code></pre>
<p>Is this a good way or are there better ways to implement this code above (performance, ...) ?</p>
<p>Should it be like this?:</p... | [] | [
{
"body": "<p>This question is better suited for <a href=\"https://softwareengineering.stackexchange.com/\">Programmers Stack Exchange</a> than Code Review...</p>\n\n<p>To answer your question - if you do evaluations like that it means that most likely you have a design issue at the first place. In most cases y... | {
"AcceptedAnswerId": "27397",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T07:32:23.417",
"Id": "27395",
"Score": "0",
"Tags": [
"c#"
],
"Title": "Best way to check for specific types"
} | 27395 |
<p>Lets say I build functions.php and I have 3 functions inside of it that I use. Lets say that I build a 4th function, but what I really want to do is simply put the instructions of function 4 into function 1 for example. Is there anything wrong with this?</p>
<p>Consider my example here, where I have included a func... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T07:48:12.963",
"Id": "42593",
"Score": "1",
"body": "Off-topic, but an important sidenote: don't use MD5 for password hashing. Use Bcrypt, Scrypt, or PBKDF2"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-0... | [
{
"body": "<p>It is absolutely ok to call functions from other functions. There is nothing wrong with that. However, there's room for improvements in your code.</p>\n\n<p><strong>function.php</strong>:</p>\n\n<ol>\n<li>There is no need to put simple expressions within parenthesis in your conditions.</li>\n<li><... | {
"AcceptedAnswerId": "27407",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T07:43:25.813",
"Id": "27396",
"Score": "1",
"Tags": [
"php"
],
"Title": "Building functions.php"
} | 27396 |
<p>I had already <a href="https://codereview.stackexchange.com/questions/26143/email-report-generation-from-database">posted a question</a> about the one I am asking right now.</p>
<p>To quickly revisit the scenarios:</p>
<p>I am trying to generate reports which involve fetching data from a DB, writing data to a CSV ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T09:01:30.520",
"Id": "42599",
"Score": "0",
"body": "Why are your start and end date strings? Java has `Date`... Joda Time has even better (`DateTime`)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14... | [
{
"body": "<p>This code needs some refactoring. Here are my suggestions:</p>\n\n<p>1) since you have some kinds of reports, which seem to share some common behaviour, you could use a base class and some classical inheritance. So you have to write the execution logic once for all cases, where no change is needed... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T08:40:35.027",
"Id": "27398",
"Score": "-1",
"Tags": [
"java",
"design-patterns"
],
"Title": "Generating reports from a database"
} | 27398 |
<p>I have an email contact form that is PHP and very basic. I am concerned, however, that injections might be possible through it. So I was wondering if anyone with far superior PHP skills than myself would be willing to take a look and see if I have any gaps or vulnerabilities in my code that could be exploited. I ver... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T19:17:39.430",
"Id": "42630",
"Score": "0",
"body": "Sanitizing input isn't really what you need (to some extent), what is more important is to properly escape your output. Take a look at the answers here: http://stackoverflow.com/q... | [
{
"body": "<h2>Validate, but don't change user input</h2>\n\n<p>Don't change the value of a user input. Either accept or reject it, but don't try to guess what might be ment. Some examples:</p>\n\n<p>The name could be <code>Søren Kierkegård</code>, which in many evironments will become <code>Sren Kierkegrd</cod... | {
"AcceptedAnswerId": "27442",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T18:10:42.333",
"Id": "27408",
"Score": "1",
"Tags": [
"php"
],
"Title": "Is my script secure to prevent email injection?"
} | 27408 |
<p>I'm looking at a class diagram and it shows a method like this:</p>
<pre><code>SavePrintOptions(bool,bool,bool,bool,bool,bool,bool,bool,bool);
</code></pre>
<p>where each of the parameters match up with save options (checkboxes) in the UI. How could I refactor this signature to reduce the number of parameters? <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T19:22:22.123",
"Id": "42631",
"Score": "5",
"body": "As the answer to [this question](http://codereview.stackexchange.com/questions/8737/too-many-parameters-too-few-methods?rq=1) suggests, collect all of the parameters into a class,... | [
{
"body": "<p>That is a real code smell and should be refactored.\nHow should any mortal soul unterstand, what this code does?</p>\n\n<p>Why not using a simple object?</p>\n\n<pre><code>public class{\n\n public bool Whateveryouwant { get; set; }\n public bool Whateveryouwantelse { get; set; }\n}\n</code><... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T19:14:50.807",
"Id": "27409",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Reduce number of parameters of the same type"
} | 27409 |
<p>I have a string of four bits which represent true/false values. There are only seven valid options:</p>
<pre><code>1010
1110
0000
1101
1001
1000
0101
</code></pre>
<p>There are three options which could potentially be selected which are not valid and that I want to check for before I proceed with some other code.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T07:05:15.477",
"Id": "42650",
"Score": "0",
"body": "What about 1111?"
}
] | [
{
"body": "<p>Why not simply test the valids?</p>\n\n<pre><code>if((/0110|0100|0010/).test(precode))\n</code></pre>\n\n<p>Seems more readable to me.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T00:21:33.863",
"Id": "42643",
"Scor... | {
"AcceptedAnswerId": "27419",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T19:20:24.723",
"Id": "27410",
"Score": "2",
"Tags": [
"javascript",
"regex"
],
"Title": "Regular Expression in Javascript to test a string of 1s and 0s"
} | 27410 |
<p>I've been programming for about 5 years now, mostly in C++ and Java, while continuing my college education in Computer Science. As an adult student, I'm always looking for opinions and ways to improve from professionals in the field. Aside from reading from numerous text books, I've read these forums for tips and go... | [] | [
{
"body": "<p>Many of your comments are superfluous. If you flood your reader with useless comments, they might skip some important ones:</p>\n\n<p><code>// adds node to tree</code> - this is already clear from method name - <code>addNode</code>.</p>\n\n<p><code>// end in order tree traversal</code> - markers s... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T19:39:11.513",
"Id": "27412",
"Score": "3",
"Tags": [
"java",
"recursion",
"tree"
],
"Title": "Binary Tree Operations"
} | 27412 |
<p>I have a need to express something like this:</p>
<pre><code>while(bytesToWrite > 0)
{
// get the NEXT location to write from a Key/Value collection of locations
// read a packet from a file at the specified location
// write some bytes to the packet
bytesToWrite -= bytesWritten
}
</code></pre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T20:37:16.217",
"Id": "42634",
"Score": "0",
"body": "Why can't you simply use a `foreach` over the `Dictionary`? If you need to end the loop early due to `bytesToWrite`, you could just use `break`."
},
{
"ContentLicense": "C... | [
{
"body": "<p>It sounds like what you want is a <code>foreach</code> over the <code>Dictionary</code>, combined with a <code>break</code> for the <code>bytesToWrite</code> condition.</p>\n\n<pre><code>foreach (var pin in dictionary)\n{\n if (bytesToWrite <= 0)\n break;\n\n Debug.Print(pin.Key + ... | {
"AcceptedAnswerId": "27418",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T19:49:09.057",
"Id": "27413",
"Score": "2",
"Tags": [
"c#"
],
"Title": "The quest for a succint, readable expression of Next in a sequence"
} | 27413 |
<p>So I'm using the <a href="https://github.com/mbleigh/acts-as-taggable-on" rel="nofollow">acts_as_taggable_on</a> gem to tag 3 different models: <code>Question</code>, <code>Blog</code>, and <code>Video</code></p>
<p>Each one has a <code>site_id</code> to distinguish which site they show up on (SaaS-ish).</p>
<p>I ... | [] | [
{
"body": "<p>Assuming these are all AR models with appropriate associations, I'd create a method on Site that iterates over a site instance's Blogs, Questions and Videos and collects their tags. Something like this maybe:</p>\n\n<pre><code>def get_site_tags\n tags = []\n self.blogs.each do |blog|\n (tags... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T20:04:11.563",
"Id": "27415",
"Score": "1",
"Tags": [
"ruby",
"mysql",
"ruby-on-rails"
],
"Title": "Review my ruby for performance"
} | 27415 |
<p>I just wrote this, and cleaned it up as much as I could. A couple things worry me:</p>
<ul>
<li>I change the scope of <code>$(this)</code> twice (and apparently don't know how to use <code>=></code>)</li>
<li>The big <code>if if/else</code> statement. Is there a better way to write that?</li>
</ul>
<p>Also, it'... | [] | [
{
"body": "<p>You mention the changes in scope as though they're a problem. But you actually want them here, since that's how jQuery operates, and using <code>=></code> would be counterproductive. Anyway here are some notes</p>\n\n<ol>\n<li><p>CoffeeScript has a <code>do</code> keyword for IIFEs. So <code>do... | {
"AcceptedAnswerId": "27448",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T20:17:33.813",
"Id": "27416",
"Score": "1",
"Tags": [
"form",
"coffeescript"
],
"Title": "Conditionally replacing an input field when submitting a form"
} | 27416 |
<p>This is just a simple script for testing sprite sheet animations. I'm trying to improve my code style, so I'm curious about suggestions anyone might have about best practices or readability.</p>
<pre><code><html>
<head>
<script>
//just a shim to provide requestAnimationFram... | [] | [
{
"body": "<pre><code>//I suggest you use this polyfill for the rAF and cAF\n//https://gist.github.com/paulirish/1579671\n\n\n//Enclosing the module in a closure to avoid pollution of the global scope\n(function (exports) {\n\n //Let's make each sprite an object, so that we have a reusable constructor\n funct... | {
"AcceptedAnswerId": "27427",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T20:21:12.193",
"Id": "27417",
"Score": "2",
"Tags": [
"javascript",
"canvas"
],
"Title": "Review a simple sprite sheet animation script"
} | 27417 |
<p>Is this a good implementation for <code>Equals</code> and <code>GetHashCode</code> for a base class in C#? If it's not good enough, can you suggest improvements for it, please?</p>
<pre><code>public abstract class Entity<TKey> //TKey = Type of the Key
{
private string FullClassName;
private bool Ke... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T00:03:41.087",
"Id": "42642",
"Score": "1",
"body": "When you're having to indent your parenthesis, then it should be obvious that you should rewrite your code instead. Having everything in a single huge expression is not a good thi... | [
{
"body": "<pre><code>//TKey = Type of the Key\n//Key of the object, which determine it's uniqueness\n</code></pre>\n\n<p>If you're going to use comments like these, it's useful to use XML documentation comments instead, so that you can see them in IntelliSense.</p>\n\n<p>Also, you should try to keep your comme... | {
"AcceptedAnswerId": "27429",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T23:14:59.533",
"Id": "27421",
"Score": "3",
"Tags": [
"c#",
"inheritance",
"null"
],
"Title": "Implementation of Equals and GetHashCode for base class"
} | 27421 |
<p>I have that $db, that I will use again and again to connect to the database. How do I put this in a central location so if I change my db I will not have to rewrite a bunch of lines of code? Everything I've tried so far just gives me an error concerning variable scope, the variable is not declared in my functions, s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T00:31:38.467",
"Id": "42645",
"Score": "0",
"body": "The second. Sorry."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T00:32:47.487",
"Id": "42646",
"Score": "0",
"body": "Ah, alright. Ha... | [
{
"body": "<p>You can't find the correct answer until your code is just a bunch simple PHP scripts. The ultimate solution would be is to use a dependency injection container and resolver where sou can say for example a PDO instance to keep in use until the request ends (in PHP this would be a singleton behavior... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-14T23:39:08.543",
"Id": "27423",
"Score": "1",
"Tags": [
"php",
"pdo"
],
"Title": "How do I put $db in a central location, but maintain variable scope"
} | 27423 |
<p>I have inherited an application that has code to save and populate values in an ASP.NET checkboxlist control. The existing code is very lengthy and does not appear to be efficient to me. I plan on rewriting this application and have complete control over the database design.</p>
<p>All of the checkboxlist items are... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T12:20:47.600",
"Id": "42654",
"Score": "0",
"body": "If nought else, you can use [`AndAlso`](http://msdn.microsoft.com/en-us/library/wz3k228a(v=vs.110).aspx) and stop check for `True`: `If li.Text = \"AA\" AndAlso Not CodeData.IsOne... | [
{
"body": "<p>I think it's reasonable to look at whether a single column design is possible - it certainly makes life easier:</p>\n\n<pre><code>For Each DataRow dr in CodeDataTable.Rows\n Dim li as ListItem = Me.cblCodes.Items.FindByText(CType(dr[\"Text\"], String))\n li.Selected = True\nNext\n</code></pr... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T04:32:43.017",
"Id": "27426",
"Score": "1",
"Tags": [
"performance",
"asp.net",
"vb.net"
],
"Title": "Populating and saving checkboxlist items to the database"
} | 27426 |
<p>I have a method that takes a generator, converts it into a tuple to sort it, then into a list. It works perfectly, but being as I am fairly new to the Python world, I keep asking myself if it is worth doing or not...</p>
<pre><code>@property
def tracks(self):
if 'tracks' not in self.cache:
s = Search(Tr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T16:40:34.707",
"Id": "42658",
"Score": "0",
"body": "This function would be easier to review if you told us a bit more about the Album class that it is defined on, what is it used for, what the performance considerations are, etc."
... | [
{
"body": "<p>I'm not sure I understand what your question is. You already remove the track numbers from the value you return with:</p>\n\n<pre><code>self.cache['tracks'] = [t for n, t in tracks]\n</code></pre>\n\n<p>Other notes:</p>\n\n<ul>\n<li>I'm a little worried about the line <code>s = Search(Track)</code... | {
"AcceptedAnswerId": "27437",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T15:21:55.950",
"Id": "27431",
"Score": "0",
"Tags": [
"python",
"generator"
],
"Title": "Generator to Tuple to List?"
} | 27431 |
<p>Sometime ago I saw a code which packed key,value pairs into several GET messages. That code had a bug (that is why it was shown to me: as the example of beautiful code which doesn't do what it should).</p>
<p>Today I decided to write this code out of curiosity and for training.</p>
<p>This is what I have written:<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T17:12:44.493",
"Id": "42659",
"Score": "0",
"body": "Are you sure that you want to return the url if there are no key-value pairs, instead returning without generating any values? It makes the base case different than cases with key... | [
{
"body": "<pre><code>def group(url,D,limit):\n</code></pre>\n\n<p>D is a bad parameter name because it doesn't follow the python convention: lowercase_with_underscores, and because it a pointless abbreviation.</p>\n\n<pre><code> if len(D) == 0:\n if len(url) <= limit:\n yield url\n ... | {
"AcceptedAnswerId": "27441",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T16:38:55.233",
"Id": "27435",
"Score": "1",
"Tags": [
"python"
],
"Title": "Group key-value pairs in chunks no longer than specified limit"
} | 27435 |
<p>Trying to implement <a href="http://jqueryui.com/upgrade-guide/1.9/#deprecated-offset-option-merged-into-my-and-at" rel="nofollow">this API</a> in a way that works pre and post jQuery UI 1.9:</p>
<p>I have a subtle feeling that there should be a more elegant way.</p>
<pre><code>/** Prefix number with '+'/'-' or re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-26T15:12:36.790",
"Id": "110880",
"Score": "0",
"body": "I recommend that you put the relevant information from that link into this post in case the link ever goes dead."
}
] | [
{
"body": "<p>Interesting question,</p>\n\n<p>have you tried passing <code>+0</code> as an offset, that should work and make your code a little easier to read. </p>\n\n<pre><code>/** Prefix number with '+'/'-' or return empty string for 0. */\nfunction offsetString(n){\n return '' + ( n < 0 ? n : '+' + n ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-15T20:12:47.243",
"Id": "27439",
"Score": "4",
"Tags": [
"javascript",
"jquery-ui"
],
"Title": "Using jQuery UI .position() in a backwards compatible way"
} | 27439 |
<p>I wrote this a couple months ago and just wanted to get some feedback on it. In the <code>printBoard()</code> function, you see I commented out the system function. I've read this is considered bad practice. Does anyone know of any alternative to clearing the terminal window? I thought it'd be a nice touch to clea... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T08:51:36.860",
"Id": "42681",
"Score": "3",
"body": "To clear the screen in a Linux terminal, use the [ncurses library](http://linux.die.net/man/3/curs_clear). Under windows, see [Microsoft KB 92261](http://support.microsoft.com/kb... | [
{
"body": "<p>Some comments, in no particular order:</p>\n\n<p><strong>1:</strong> For applications like this, I think it is perfectly legitimate to use <code>system()</code>. It's not exactly elegant, but in this particular case I think it's fine. You could do:</p>\n\n<pre><code>void clearScreen() {\n#ifdef WI... | {
"AcceptedAnswerId": "27451",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T08:12:54.713",
"Id": "27446",
"Score": "4",
"Tags": [
"c",
"console",
"connect-four"
],
"Title": "Connect Four game"
} | 27446 |
<p><a href="http://www.codechef.com/JUNE13/problems/COLLECT" rel="nofollow">Here is the link of the problem</a> for which I need your help. </p>
<p>I came up with solution and it is working fine for all cases, but it takes more time. I need your help in reducing the runtime of code. I unable to optimised it more.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T12:58:41.670",
"Id": "42685",
"Score": "0",
"body": "Not an optimization but a code style thingie: when testing `s == change`, if it is true, you could just `continue` instead of having `else`"
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>No optimisation so far but a few comments to make your code easier to read/improve :</p>\n\n<p>1 Don't do <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">\"using namespace std;\"</a></p>\n\n<p>2 Give your variables meaningful names.</p>\n\... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T12:38:46.680",
"Id": "27449",
"Score": "2",
"Tags": [
"c++",
"optimization",
"algorithm",
"programming-challenge"
],
"Title": "Collecting magical berries"
} | 27449 |
<p>I wrote a small particle engine in Java for my Pong clone.</p>
<p>I read that changing a texture is very expensive in OpenGL, so I tried to change the texture as few times as possible. Therefore I change the texture in the render method of the emitter and not in the render method of every particle. Although my fr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T14:31:45.847",
"Id": "42746",
"Score": "1",
"body": "you should calculate `PARTICLE_TEXTURE.getImageWidth()/2.0f` and `PARTICLE_TEXTURE.getImageHeight()/2.0f` only once. If `PATICLE_TEXTURE` is a constant (as the name suggests) it m... | [
{
"body": "<p>A few notes:</p>\n\n<pre><code>for(Integer index : this.getBlockedParticles()){\n this.getParticles()[index].render();\n}\n</code></pre>\n\n<p>This should be:</p>\n\n<pre><code>for( Particle particle : getBlockedLivingParticles() ) {\n particle.render();\n}\n</code></pre>\n\n<p>By maintaining ... | {
"AcceptedAnswerId": "35988",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T14:55:22.523",
"Id": "27450",
"Score": "1",
"Tags": [
"java",
"optimization",
"performance",
"opengl"
],
"Title": "Small particle engine"
} | 27450 |
<p>The following is a code from one of my projects which implements a loading cache with timeout and expiry. The associated tests are <a href="https://raw.github.com/fge/msg-simple/master/src/test/java/com/github/fge/msgsimple/provider/LoadingMessageSourceProviderTest.java" rel="nofollow">here</a> (mixed with a good nu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T18:05:21.187",
"Id": "42755",
"Score": "1",
"body": "Just 2 comments: (i) Technically (although unlikely), `sources` could be `null` in `setupExpiry` as your constructor has not completed yet. (ii) In case of InterruptedException, y... | [
{
"body": "<p>I think you do have a race condition. The test below should expose it.</p>\n\n<pre><code>@Mock\nprivate MessageSource messageSource;\n\n@Test\npublic void testExpiryDuringLoadingDoesNotInterfereWithGetMessageSourceCallInProgress() throws Exception {\n\n MessageSourceProvider sourceProvider = Lo... | {
"AcceptedAnswerId": "27486",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T16:18:49.830",
"Id": "27452",
"Score": "3",
"Tags": [
"java",
"multithreading",
"thread-safety"
],
"Title": "Custom, simple cache with load timeout and expiry; thread safety, ... | 27452 |
<p>I read <a href="https://stackoverflow.com/questions/8388415/does-the-display-attribute-in-the-model-violate-separation-of-concerns-from-view">this question and answers</a>, about if Display Annotations on model properties violates the separation of concerns between view and model. And my interpretation of their ans... | [] | [
{
"body": "<p>A solution could be:</p>\n\n<pre><code>public class RestaurantReviewViewModel : RestaurantReviewModel\n{\n [Display(Name = Resources.Description)]\n public override string Body { get; set; }\n\n [Display(Name = Resources.UserName)]\n [DisplayFormat(NullDisplayText = \"[Anonymous]\")]\n... | {
"AcceptedAnswerId": "27467",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T17:19:57.803",
"Id": "27454",
"Score": "6",
"Tags": [
"c#",
"object-oriented",
"asp.net"
],
"Title": "What Data Annotations need to be shared/different between my Model & ViewM... | 27454 |
<p>I'm new to hand coding a PHP form/email submission. Are the security checks I've included here good enough? Or is this super vulnerable to attacks? </p>
<p>My main concern is protecting the email login credentials below. Any feedback much appreciated.</p>
<p>Thank you! </p>
<pre><code> // IF WE'VE SUBMITTED A F... | [] | [
{
"body": "<ol>\n<li>The whitelist check is giving a false sense of security. Consider its use case: There is no way a normal user will ever submit more parameters than those which are in the form. Therefore, you can safely assume that anyone submitting other parameters is an attacker, who should receive as lit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T21:09:59.063",
"Id": "27459",
"Score": "2",
"Tags": [
"php",
"security",
"form"
],
"Title": "Is my form secure? PHP Security checks"
} | 27459 |
<p>When I wrote this it just felt messy due to the null checks. Any good ideas on how to clean it up would be most appreciated.</p>
<pre><code> def getItemsInStock(self):
itemsInStock = []
items = self.soup.find_all("ul", {'class':re.compile('results.*')})
getItems = [x for x in items if x.fin... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-06-22T07:39:25.587",
"Id": "379609",
"Score": "0",
"body": "This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about [what your code does](//coderev... | [
{
"body": "<p>As an example,</p>\n\n<pre><code> getItems = [x for x in items if x.find(\"div\", class_=\"quantity\")]\n if getItems:\n itemsInStock += getItems\n</code></pre>\n\n<p>can be written</p>\n\n<pre><code> itemsInStock.extend(x for x in items if x.find(\"div\", class_=\"quantity\")]\n</... | {
"AcceptedAnswerId": "27471",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T21:55:30.730",
"Id": "27461",
"Score": "5",
"Tags": [
"python"
],
"Title": "refactor Python code with lots of None type checks"
} | 27461 |
<p>Previous review of this project:</p>
<p><a href="https://codereview.stackexchange.com/questions/27379/deck-and-card-classes-and-member-accessing-with-one-header">Deck and Card classes and member-accessing with one header</a></p>
<p>I'm nearly finished with my deck of cards project, and this time I made changes to ... | [] | [
{
"body": "<p>The way I understand your question, you want <code>Card</code> to be publicly available, yet only <code>Deck</code> should be able to construct a <code>Card</code>. One way to achieve this is to make the <code>Card()</code> constructor private and a <code>friend</code> of <code>Deck</code>:</p>\n... | {
"AcceptedAnswerId": "27464",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T22:32:15.233",
"Id": "27462",
"Score": "4",
"Tags": [
"c++",
"classes",
"playing-cards"
],
"Title": "Nested Deck class design and implementation"
} | 27462 |
<p>I want to know if what I have coded is good enough or if there is any simpler/faster/better/less size taking substitute.</p>
<p>I am trying to take input from push buttons and I also want to remove repeated input so I coded like it and saved in a variable key. I used internal pullup to eradicated random input from ... | [] | [
{
"body": "<p>I don't <em>know</em> the Arduino language but I've recently been learning, from what I can gather on the website unsigned ints will \"roll-back\" to zero if they reach their maximum (which will be reached in a huge \"<strong>fifty days</strong>\" so no need to worry about that.</p>\n\n<p>You can ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T04:10:56.930",
"Id": "27465",
"Score": "1",
"Tags": [
"optimization",
"arduino"
],
"Title": "Taking input from push buttons"
} | 27465 |
<p><em>Update: Now that <a href="https://github.com/bionicspirit/scala-atomic" rel="nofollow">https://github.com/bionicspirit/scala-atomic</a> is available, I have less of a need for this.</em></p>
<p>Am I doing anything bad? I wrote this class to allow modifying an atomic reference with the assurance that two threads... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T07:55:33.440",
"Id": "42729",
"Score": "0",
"body": "This cannot be really called atomic, especially the `run` function; if another thread has a reference to this `AtomicReference` it can modify the value from under your nose. What ... | [
{
"body": "<p>Your approach is definitely valid, I've seen something similar used in GHC's implementation of <a href=\"http://www.haskell.org/ghc/docs/7.6.2/html/libraries/base/Data-IORef.html#v%3aatomicModifyIORef\" rel=\"nofollow\">atomicModifyIORef</a>.</p>\n\n<p>However I have some doubts if such a class is... | {
"AcceptedAnswerId": "28876",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T06:33:48.947",
"Id": "27466",
"Score": "1",
"Tags": [
"scala"
],
"Title": "Subclass of AtomicReference with atomic function application"
} | 27466 |
<p>As a bit of a learning project, I decided to take the concept of proxying objects a bit further and extend it to creating proxy classes which create proxy'd objects. I originally found the idea of proxying objects in python on <a href="http://code.activestate.com/recipes/496741-object-proxying/" rel="nofollow">Acti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T01:54:55.657",
"Id": "42787",
"Score": "0",
"body": "If it were me, I'd make `Proxy` a function which returns the type. It can still be implemented in terms of the class but you shouldn't make it directly accessible. Keep its defini... | [
{
"body": "<p>Some quick thoughts:</p>\n\n<ol>\n<li><p>I can't tell from reading the code what the purpose is. What is this for? What are the use cases? How am I supposed to use it?</p></li>\n<li><p>There's no docstring for the <code>Proxy</code> class or for the <code>usable_base_type</code> method.</p></li>\n... | {
"AcceptedAnswerId": "27511",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T08:28:33.307",
"Id": "27468",
"Score": "3",
"Tags": [
"python",
"object-oriented",
"immutability",
"proxy"
],
"Title": "Creating Proxy classes for immutable objects"
} | 27468 |
<p>Some time ago I had to make a memory game as a college project. I spent around 6hrs coding this since I was also busy juggling exams. I'm not experienced in C# so there are probably a lot of things I could've done better, and I am also bad at conjuring algorithms. So please let me know on what I did right and what I... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T11:30:29.527",
"Id": "42736",
"Score": "2",
"body": "“I have no idea why this is global, it's only used in one place” If you know about some issues in your code, I think it would help if you fixed them first."
},
{
"ContentL... | [
{
"body": "<blockquote>\n <p>how to prevent these mistakes in my future projects.</p>\n</blockquote>\n\n<p><strong>Rewrite your program from scratch</strong></p>\n\n<ul>\n<li>Rewrite, from scratch, several times, as you progress in your skill and knowledge.</li>\n<li>There is no absolutely correct code solutio... | {
"AcceptedAnswerId": "27484",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T10:22:31.917",
"Id": "27472",
"Score": "5",
"Tags": [
"c#",
"beginner",
"game"
],
"Title": "Memory game in C#"
} | 27472 |
<p>This is probably a really simple question.</p>
<p>An embedded device I'm working with will store the device information in an xml file.</p>
<p>In my code, I want to read this xml file and freely reference to it wherever I need to, so I made a simple helper class:</p>
<pre><code>public class DeviceInformation {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T13:24:57.670",
"Id": "42739",
"Score": "0",
"body": "Do you only have one device?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T14:15:21.070",
"Id": "42741",
"Score": "0",
"body": "Multi... | [
{
"body": "<p>I think you should have :</p>\n\n<ol>\n<li><p>A constructor taking device_id, device_type and home as an argument.</p></li>\n<li><p>a static method doing the file handling and calling the constructor previously defined.</p></li>\n</ol>\n\n<p>This would make your code more modular, easier to test a... | {
"AcceptedAnswerId": "27476",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T13:08:36.203",
"Id": "27474",
"Score": "0",
"Tags": [
"java",
"object-oriented"
],
"Title": "Best way to manage a device information class"
} | 27474 |
<p>I have just finished my first iteration of conway's game of life as a codeing excercise. I have little experience with coding, so I think my code could use some refactoring. What i am curios about is the drivers for having a more efficient code. My code is based on a cell object:</p>
<pre><code>//Defining the cells... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T12:34:13.757",
"Id": "42747",
"Score": "3",
"body": "It's a bad idea to use `for ... in` loops on arrays in JavaScript. Use a numeric index and a plain `for` loop. Besides that, your performance problem stems from the fact that you ... | [
{
"body": "<p>Your code could indeed probably use some tuning.</p>\n\n<p>The three major points are:</p>\n\n<ul>\n<li><p>A cell should know it's neighbors, you should only <strong>once</strong> determine the neighbors for each cell and place them in an array in that Cell. This will speed up your code tremendous... | {
"AcceptedAnswerId": "38116",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T12:29:39.033",
"Id": "27481",
"Score": "4",
"Tags": [
"javascript",
"performance",
"game-of-life"
],
"Title": "Conway's game of life - Optimizing the code"
} | 27481 |
<p>I'm building an alarm set to reoccur every 30 days. I was wondering if I could get a few extra sets of eyes to look things over and see if you can notice anything I may have done wrong. Any/all input is greatly appreciated! </p>
<p><strong>SOURCE:</strong></p>
<pre><code>public class WifiMonitor extends Activity... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T19:39:42.867",
"Id": "42768",
"Score": "0",
"body": "Any reason to avoid using cron and a shell script?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T19:41:54.160",
"Id": "42770",
"Score": "... | [
{
"body": "<p>I'm not familiar with Android, so just some generic note:</p>\n\n<ol>\n<li><pre><code>calendar.set(Calendar.DAY_OF_WEEK, 0);\n</code></pre>\n\n<p>What is this line supposed to do? <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#DAY_OF_WEEK\" rel=\"nofollow\">Javadoc of <... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T14:40:21.920",
"Id": "27482",
"Score": "5",
"Tags": [
"java",
"android",
"datetime"
],
"Title": "Building 30 day alarm"
} | 27482 |
<p>I'm a hobbyist Python programmer with not much experience.</p>
<p>I wrote some code for a solution to a Tic Tac Toe AI problem on the internet.</p>
<p>Then yesterday I wrote a simple console Tic Tac Toe game for human vs computer play where the computer plays randomly.</p>
<p>So I thought it would be nice how dif... | [] | [
{
"body": "<p>From <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a> : </p>\n\n<blockquote>\n <p>Comparisons to singletons like None should always be done with is or is not, never the equality operators.</p>\n</blockquote>\n\n<p>,</p>\n\n<blockquote>\n <p>Don't compare boolean va... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T17:15:55.900",
"Id": "27483",
"Score": "1",
"Tags": [
"python",
"design-patterns",
"classes"
],
"Title": "Extending a simple Python console program with external code. Did I handl... | 27483 |
<p>I'm currently working on a small chess game written in Java (<a href="https://github.com/Ouzned/JavaChess/tree/f1a88a76c531e98fd46dc08a2fca7073709e60cd" rel="nofollow noreferrer">on GitHub</a>). The board is modeled as a Board object with a 2D array of Piece objects :</p>
<pre><code>public class Board {
private ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T06:57:10.390",
"Id": "42793",
"Score": "0",
"body": "at a first glance it looks nice to me. just two things: 1. according to Java naming conventions your static final members should be `COLS` and `ROWS` and 2. `bv.visit(board[row][c... | [
{
"body": "<p>At the moment it seems your board holds 64 (8*8) Pieces :</p>\n\n<pre><code>private Piece[][] board;\n</code></pre>\n\n<p>It would be more logical to have :</p>\n\n<pre><code>private Square[][] board;\n</code></pre>\n\n<p>Secondly, you can avoid a lot of nested loops by representing the board with... | {
"AcceptedAnswerId": "27524",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T20:25:17.910",
"Id": "27488",
"Score": "5",
"Tags": [
"java",
"chess",
"visitor-pattern"
],
"Title": "Chess board representation in Java"
} | 27488 |
<pre><code>class ShareModel
constructor: ->
questionaireView = new QuestionnaireView
@previewImages =
shareCurrent: -> ShareModel::getSingle(ModelView::getCurrentImage(),'current',questionaireView.weight(),questionaireView.weightUnits())
shareGoal: -> ShareModel::getSingle(ModelView::getG... | [] | [
{
"body": "<p>Next time, add a brief description of what the code actually does. Sure, we can read it, but it still leaves a lot of questions. For instance, the <code>current</code> parameter: Is that a path to an image, or a number or what?</p>\n\n<p>Anyway, here are some observations, but I don't know enough ... | {
"AcceptedAnswerId": "27523",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T20:48:30.977",
"Id": "27489",
"Score": "-1",
"Tags": [
"coffeescript"
],
"Title": "Coffeescript Review"
} | 27489 |
<p>Previous review of this project: <a href="https://codereview.stackexchange.com/questions/27462/is-this-nested-class-design-ineffective-for-my-deck-class">Nested Deck class design and implementation</a></p>
<p>My program finally meets all of my expectations to the best of my ability, but I'd still like another revie... | [] | [
{
"body": "<p>I haven't followed your previous reviews, so a few of these may be things that have already been pointed out.</p>\n\n<p>Anyway, here's my go at it.</p>\n\n<hr>\n\n<p>The <code>Card::</code> is invalid on the following:</p>\n\n<pre><code>Card::Card(unsigned v, char r, char s) : value(v), rank(r), s... | {
"AcceptedAnswerId": "27500",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T01:58:34.883",
"Id": "27491",
"Score": "4",
"Tags": [
"c++",
"playing-cards"
],
"Title": "Deck of cards program using a card value map"
} | 27491 |
<p>At the suggestion of @templatetypedef, I am posting the code for my quick sort to see if anyone can offer suggestions as to where to make comparisons. And any tips on improving the code. I am using this in conjunction with a Merge Sort and Heap sort to see how the different comparison algorithms sort an array of ra... | [] | [
{
"body": "<p>I'll review the testing procedure here. The <code>main()</code> function is long enough to be worth breaking up.</p>\n\n<p>If you intend to test several sorting algorithms, then the algorithms should all implement a common interface so that they are interchangeable.</p>\n\n<pre><code>public inter... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T03:35:41.247",
"Id": "27495",
"Score": "4",
"Tags": [
"java",
"unit-testing",
"sorting",
"quick-sort"
],
"Title": "Help with comparison counters in quick sort algorithm"
} | 27495 |
<p>I am posting the code for my merge sort to see if I can get folks offer suggestions as to where to make comparisons or if I am making the correctly already. </p>
<p>I will post my heap sort and quick sorts in other posts. I actually have them all in a package that runs them together but separating them out for cl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-23T04:59:01.307",
"Id": "43149",
"Score": "0",
"body": "You seem to be asking us to find bugs in your code. That's not the purpose of this site. The best (and certainly a quicker) way to find bugs is to write unit tests yourself, and... | [
{
"body": "<p>Here's some suggestions on what you can do differently to get a better result (both performance counters and code style).</p>\n\n<p>The <code>MergeSortRun</code> class breaks many rules for naming conventions in Java.... well, actually the class name is OK (<code>MergeSortRun</code>), but the meth... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T03:49:51.390",
"Id": "27497",
"Score": "1",
"Tags": [
"java",
"sorting",
"mergesort"
],
"Title": "Debug merge sort and validate comparison counters"
} | 27497 |
<p>Is there a smarter way to do the following without the <code>$result</code> variable and without the if-statements?</p>
<pre><code> ...
$description = BIG ARRAY
$result = array('error' => '', 'amounts' => array(5, 10, 25, 50));
if (isset($description['error'])) $result['error'] = $description['... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T06:44:46.737",
"Id": "42792",
"Score": "1",
"body": "Can you explain a bit more what you're trying to do? $result has defaults that you're trying to overwrite with values from $description if they exist and are non-null? Are error a... | [
{
"body": "<p>To see if an array has a specific index you should use <a href=\"http://php.net/manual/en/function.array-key-exists.php\" rel=\"nofollow\"><code>array_key_exists</code></a> rather than <code>isset</code>.</p>\n\n<p>In case you want default values, how about just assigning all the defaults at the s... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T06:21:24.693",
"Id": "27501",
"Score": "0",
"Tags": [
"php",
"array"
],
"Title": "Check for existence and assign"
} | 27501 |
<p>I'm receiving a certain string value over the network and I need to call a function based on that value.</p>
<p>So this is more or less what I have at the moment:</p>
<pre><code>String methodName = soapObj.getMethodName();
switch(methodName) {
case "getTemperature":
getDeviceTemp();
break;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-24T22:47:18.070",
"Id": "43235",
"Score": "0",
"body": "Do you mind me asking for more details about your use case or the domain? Just curious to know more about the situation."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creat... | [
{
"body": "<p>The easiest way is to create an interface for your function, for instance:</p>\n\n<pre><code>public interface ParameterGetter\n{\n int getValue()\n}\n</code></pre>\n\n<p>Then have a <code>Map<String, ParameterGetter></code> in which you would pair keys with implementations of <code>Parame... | {
"AcceptedAnswerId": "27505",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T07:54:28.320",
"Id": "27503",
"Score": "8",
"Tags": [
"java",
"soap"
],
"Title": "Dispatching SOAP function calls"
} | 27503 |
<p>All,
I barely have a week of angular behind me and I am still struggling with some of the concepts. Below is a piece of code I came up with. The idea is to let the user add/delete entries in a model (in practice, the model is read from a json and is more complex than what is presented). While this code seems to work... | [] | [
{
"body": "<ul>\n<li><p>Right, you're only manipulating the model, updating the model about a change (thus) updating it in the controller is perfectly fine, and it's what the controller does.</p></li>\n<li><p><code>del_item</code> should be in the controller too, you are correct. That's where it belongs.</p></l... | {
"AcceptedAnswerId": "27718",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T10:58:21.253",
"Id": "27506",
"Score": "3",
"Tags": [
"javascript",
"angular.js"
],
"Title": "Manipulating model elements in angular"
} | 27506 |
<pre><code>class Connection
{
private string param1;
private string param2;
private static readonly ConcurrentDictionary<Tuple<string, string>, Connection>
connections = new ConcurrentDictionary<Tuple<string, string>, Connection>();
private Connection()
{
//Prev... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T13:21:55.813",
"Id": "42826",
"Score": "0",
"body": "Are you saying that if two threads ask for a connection with the same parameters, they should get the same `Connection`? That means the actual code of `Connection` (the one that u... | [
{
"body": "<p>yes. But it's ugly. You won't remember what those parameters means when you come back in a couple of months and have to maintain the code.</p>\n\n<p>I really hate convenience classes like <code>Tuple</code> and <code>Action<T></code> (the latter is OK some times but is usually abused).</p>\n... | {
"AcceptedAnswerId": "27548",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T11:14:17.047",
"Id": "27507",
"Score": "2",
"Tags": [
"c#",
"thread-safety",
"singleton"
],
"Title": "Is this code thread-safe - Singleton Implementation using Concurrent Dicti... | 27507 |
<p>This is my most recent login system I have been developing. It is working with Sessions. I want to know if I am doing well, if my code contains any serious exploits, and if my logic is correct.</p>
<p>This is the login class, handling everything related to users:</p>
<pre><code>/**
* UserHandler.class
*
* Handling... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T12:20:01.913",
"Id": "42824",
"Score": "0",
"body": "Hi and welcome to Code Review! This question involves a *lot* of code and is very open ended, and as such is likely to be closed or go unanswered. I suggest you trim the code down... | [
{
"body": "<p>If I manually set a cookie in my browser with the name 'remember_me', then I am logged in because you are not doing any validation on the cookie to make sure it is a valid cookie and not a forged cookie. </p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T12:06:42.533",
"Id": "27510",
"Score": "3",
"Tags": [
"php",
"object-oriented",
"security",
"validation"
],
"Title": "Exploitable holes in login script"
} | 27510 |
<p>I have a main form for adding and deleting records and a button that opens a child form that displays records from an access database. Child form will have buttons for moving though the rows like first, last, next, previous and search. When user selects a record the child form will close and the selected record wi... | [] | [
{
"body": "<p><strong>Learn about Data Binding</strong></p>\n\n<p><a href=\"http://www.codeproject.com/Articles/24656/A-Detailed-Data-Binding-Tutorial\" rel=\"nofollow noreferrer\">Here is one tutorial</a>. My main point is that with the Visual Studio designer linking back end data and the UI is pretty straig... | {
"AcceptedAnswerId": "27519",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T12:28:48.087",
"Id": "27512",
"Score": "1",
"Tags": [
"c#",
"winforms"
],
"Title": "Multiple forms for accessing records in database"
} | 27512 |
<p>In my app development, I need to fetch data from backed, and it needs to implement it into an HTML page.</p>
<p>I've written the below code for this, but I think it's very lengthy. Can anyone give me suggestions on making this better?</p>
<p><strong>Function:</strong></p>
<pre><code>var JsonHandler = function(ur... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T14:59:35.040",
"Id": "27517",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"json",
"template"
],
"Title": "Data with Handlebars templating function"
} | 27517 |
<p>I'm trying to find an elegant and secure way to track the currently reported site. I originally just used a cookie but realized this was not very secure. I have since switched to combine the session and the cookie. It still feels a bit clumsy. Am I missing something here as far as best practices? Can this be improve... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T16:06:00.520",
"Id": "42836",
"Score": "0",
"body": "I don't understand, what does “currently reported site” mean? How are you going to use the value? How do you set it in the first place?"
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>As you pointed out, relying on cookies means that the user can choose someone else's site. That means you should not use cookies at all, not even in addition to the session. If you choose to use cookies anyway, you have to validate that the current user actually has access to the selected site bef... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T15:31:46.970",
"Id": "27520",
"Score": "0",
"Tags": [
"c#",
"asp.net",
"session"
],
"Title": "Is this a good way to track current site being reported on?"
} | 27520 |
<p>This is my code which implements Nd vectors. I chose valarray as a base of the class. Is this a good idea or I simply need to make a typedef std::valarray gvector instead of writing a class?
Please review this code.</p>
<pre><code>//gvector.h
#ifndef GVECTOR_H_
#define GVECTOR_H_
#include <cmath>
#include &l... | [] | [
{
"body": "<p><code>std::valarray</code> by itself only acts like a 1D array. The <code><valarray></code> <em>header</em> includes a few ancillary classes to do this though. More importantly, <code>valarray</code> itself includes direct support for those classes.</p>\n\n<p>For your purposes, the most impo... | {
"AcceptedAnswerId": "45465",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T20:54:25.837",
"Id": "27527",
"Score": "7",
"Tags": [
"c++"
],
"Title": "Implementation of Nd vectors using valarray"
} | 27527 |
<p>I've been getting help with this script seen below. It allows one input box to be used to put values into a text area and also display a list of the items. The items can be deleted once inserted:</p>
<p><a href="http://jsfiddle.net/ZTuDJ/50/" rel="nofollow">http://jsfiddle.net/ZTuDJ/50/</a></p>
<pre><code>// If JS... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T21:21:38.163",
"Id": "42866",
"Score": "0",
"body": "May I suggest a solution that uses another library in place of jQuery, or just adds another library? There are very good tools that make this very easy to do."
},
{
"Conte... | [
{
"body": "<p>What's good here:</p>\n\n<ul>\n<li>It's fairly simple</li>\n<li>Using <code>prop</code> over <code>attr</code></li>\n</ul>\n\n<p>What I did not like</p>\n\n<ul>\n<li><strong>Using HTML strings</strong> in code makes code <em>very</em> hard to modify later on. It's hard to debug and might cause pot... | {
"AcceptedAnswerId": "27530",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T21:17:32.503",
"Id": "27528",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Jquery improvement of this script - Adding and removing items from list"
} | 27528 |
<p>I'm trying to develop my own math library to use on a Voxel engine, but I'm worried about Matrices multiplication. Everywhere I saw people using 4x4 Matrices on a 2D Float Array but I'm using a 1D Float Array because of performance needs.</p>
<pre><code> public float[] multiplicate(float[] factor){
float... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T22:10:21.223",
"Id": "42879",
"Score": "0",
"body": "in the init part of your loop: `a= 0, b=0` is superfluous since you assign values right at the beginning of the loop body"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Crea... | [
{
"body": "<p>My final code is:</p>\n\n<pre><code>public float[] multiplicate(float[] factor){\n int a = 0;\n int b = 0;\n float[] result = new float[factor.length];\n for (int i = 0; i < factor.length; i++){\n a = (i/4)*4;\n b = (i%4);\n result[i] = (mat4f[a] * factor[b]) + ... | {
"AcceptedAnswerId": "27550",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T21:48:28.680",
"Id": "27529",
"Score": "1",
"Tags": [
"java",
"performance",
"mathematics",
"matrix",
"floating-point"
],
"Title": "Is my 4x4 matrix multiplication on a... | 27529 |
<p>I've never put together a plugin before but I thought this would be useful to push technology forward. It's basically a browser sniffer, but if the user has a modern browser it will reward them for keeping it up to date.</p>
<p>Unfortunately, the code is a little heavier than I expected (6kb minified).</p>
<p>I ju... | [] | [
{
"body": "<p>\"d\", \"b\", \"c\", \"e\" are not good variable names. Use other ones. If you're afraid about the size (and I'll tackle that later), this is gzip's task.\nCreate local variables instead of accessing \"abiejs\" every time.</p>\n\n<pre><code>// for example, from\nabiejs.d...\nabiejs.d.style.color =... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-18T22:17:07.993",
"Id": "27531",
"Score": "2",
"Tags": [
"javascript",
"plugin"
],
"Title": "Review my browser reward plugin"
} | 27531 |
<p>Previous review of this project:</p>
<p><a href="https://codereview.stackexchange.com/questions/27491/deck-of-cards-program-using-a-card-value-map">Deck of cards program using a card value map</a></p>
<p>Based on the previous feedback I've received, my program could become more flexible (it formerly created a stan... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T04:23:11.097",
"Id": "42896",
"Score": "2",
"body": "value seems redundant. it could just be rank<10?rank:10"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T04:29:43.070",
"Id": "42897",
"Scor... | [
{
"body": "<p><strong>1: Yes,</strong> your <code>Card</code> class should expose its <code>rank</code> and <code>suit</code> through a public interface. (See the previous thread and @user225770's answer for <code>value</code>.) It should at least give read-only access, but write access may not be necessary. (I... | {
"AcceptedAnswerId": "27544",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T04:17:11.517",
"Id": "27534",
"Score": "6",
"Tags": [
"c++",
"playing-cards"
],
"Title": "Usage flexibility of Deck class"
} | 27534 |
<p>I'm trying to construct something which would work a bit like <code>Zip</code> for two tasks, but I'm a bit worried about race conditions in this code. </p>
<pre><code>public static Task<R> ContinueWhenBoth<T1, T2, R>(this TaskFactory<R> factory, Task<T1> t1,
... | [] | [
{
"body": "<p>Any chance you are using .NET 4.5? It contains the method that does exactly what you need: <a href=\"http://msdn.microsoft.com/en-us/library/hh160374.aspx\" rel=\"nofollow\">Task.WhenAll</a>.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-... | {
"AcceptedAnswerId": "27539",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T05:46:06.183",
"Id": "27536",
"Score": "1",
"Tags": [
"c#",
"task-parallel-library"
],
"Title": "TaskFactory.CompleteWhenBoth"
} | 27536 |
<p>My implementation in Progress 4GL of the Luhn Algorithm. Any suggestions on improving it?</p>
<pre><code>FUNCTION fnLuhnAlgorithm RETURNS LOGICAL
(INPUT pcNumber AS CHARACTER):
/*------------------------------------------------------------------------------
Purpose: Applies Luhn Algorithm to check a Number
... | [] | [
{
"body": "<p>You are kind of overdoing it a little in my opinion, there are too many variables that don't really add much value, also I would change the parameter to be DECIMAL, to avoid calls using not numbers that would cause run time errors.</p>\n\n<p>My implementation would look like this:</p>\n\n<pre><cod... | {
"AcceptedAnswerId": "27593",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T08:38:11.557",
"Id": "27540",
"Score": "1",
"Tags": [
"algorithm",
"performance",
"progress-4gl"
],
"Title": "Progress 4GL - Luhn algorithm"
} | 27540 |
<p>I've been spending lot of time reading through this site and found plenty of resources that shaped up my code.</p>
<p>I am working on an open source project known as Quizz. It is in a primitive stage as I work only during my spare time I cannot concentrate much. For this JavaScript to work, I have a huge objects an... | [] | [
{
"body": "<p>I can understand your frustration of nested for loops.</p>\n\n<p>However, your data structure is full of nested arrays. How else can you handle them?</p>\n\n<p>One way to have pretty code is to separate each loop in its own function, with clear names.</p>\n\n<p>This way, the main logic remains rea... | {
"AcceptedAnswerId": "27542",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T09:31:58.010",
"Id": "27541",
"Score": "3",
"Tags": [
"javascript",
"quiz"
],
"Title": "JavaScript-based quiz application called Quizz"
} | 27541 |
<p>I have a switch case statement containing enum values as cases. These enum values are time units. Now I want to generate a timespan by using an enum value and a long value so like this:</p>
<blockquote>
<p>2 (long) Minutes (Enum value)</p>
<p>1 (long) Year (Enum value)</p>
</blockquote>
<p>... and so on.</p>
<p>This... | [] | [
{
"body": "<pre><code>private const double yearMultiplier = 365.2425;\n\nprivate Dictionary<TimeUnit, Func<double, TimeSpan>> timespanConverters = new Dictionary<TimeUnit, Func<double, TimeSpan>>\n{\n { TimeUnit.Seconds, TimeSpan.FromSeconds },\n { TimeUnit.Minutes, TimeSpan.FromMi... | {
"AcceptedAnswerId": "27557",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T15:11:27.063",
"Id": "27552",
"Score": "4",
"Tags": [
"c#",
"datetime"
],
"Title": "A switch case statement that returns a timespan"
} | 27552 |
<p>Is there any ways I can write redundant-less code without this infinite loop? I have also tried putting the conditions and the generating number, but since it has two conditions, the output number will be different.</p>
<pre><code>private static final int PERCENT_97 = 3;
/**
* Returns returns a pseudo-random Gauss... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T15:53:33.230",
"Id": "42924",
"Score": "0",
"body": "It's not infinite if you provide a way to escape the loop. That is, if the escape can be reached although."
}
] | [
{
"body": "<p>A do while would be an equivalent construct. I don't really think either is more or less preferable, but is an alternative that avoids the <em>appearance</em> of an infinite loop:</p>\n\n<pre><code>do {\n returningNumber = (generator.nextGaussian() * rangeMean/PERCENT_97) + mean;\n} while (retu... | {
"AcceptedAnswerId": "27556",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T15:39:21.347",
"Id": "27554",
"Score": "2",
"Tags": [
"java",
"random"
],
"Title": "Returning a pseudo-random Gaussian number"
} | 27554 |
<p>First of all, I'm trying to learn OOP PHP, so any advise will be great.</p>
<p>My idea is to create some kind of MVC Framework CMS kind of thing, just to learn OOP PHP and MVC well.</p>
<p>Let's say that I've got this code (note: I will separate the code pieces in different files, but this was just for testing):</... | [] | [
{
"body": "<h1>Overview</h1>\n<p>This isn't OOP. To me, <em>object</em>-oriented programming requires thinking about your programs in terms of classes, their responsibilities, their attributes, and behaviours. This means:</p>\n<ul>\n<li>Information hiding</li>\n<li>Encapsulation</li>\n<li>Polymorphism</li>\n<li... | {
"AcceptedAnswerId": "27575",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T18:54:26.150",
"Id": "27564",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"classes",
"inheritance"
],
"Title": "Classes and variables in PHP"
} | 27564 |
<p>I have wrote few function that grab the values from a form page and pass them to PHP
is there a way to write it better</p>
<pre><code>function resultstype(form) {
var prod_dev=form.results_type.options[form.results_type.options.selectedIndex].value;
self.location='dd.php?pd=' + prod_dev;
}
function stype(form)
{... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T19:34:46.290",
"Id": "42934",
"Score": "1",
"body": "Don't. Why do you need to?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T19:35:32.627",
"Id": "42935",
"Score": "2",
"body": "The cod... | [
{
"body": "<p>I know this is out of scope, but I think there is a lot of redudant code here that can easilly be made shorter. Much shorter. Look:</p>\n\n<pre><code>function stand_name(form)\n{\n var prod_dev=form.results_type.options[form.results_type.options.selectedIndex].value; \n var stand_type=form.s... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T19:18:40.017",
"Id": "27566",
"Score": "-1",
"Tags": [
"javascript",
"php",
"mysql"
],
"Title": "How to change my code to jquery"
} | 27566 |
<p>In my application I am attempting to queue outgoing messages by the following rules</p>
<ul>
<li>By default they should be sent no less than <code>messageDelay</code> apart</li>
<li>Some messages can be sent immediately, completely bypassing all queued messages</li>
<li>Additionally, some immediately sent messages ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T20:53:56.683",
"Id": "42940",
"Score": "0",
"body": "Your code extracts only show the write side locking; how many readers are there? (otherwise, +1 for the recommended use of try/finally!)"
},
{
"ContentLicense": "CC BY-SA ... | [
{
"body": "<p>I can see some problems with the code:</p>\n\n<ul>\n<li><p>As @fge mentions, catching <code>Exception</code> is problematic. You should catch the exceptions that you are expecting to occur, and let any other unchecked exceptions propagate.</p></li>\n<li><p>Wrapping the exceptions in <code>Runtime... | {
"AcceptedAnswerId": "27683",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T19:53:41.540",
"Id": "27567",
"Score": "4",
"Tags": [
"java",
"multithreading",
"locking"
],
"Title": "Is this the best message delay algorithm?"
} | 27567 |
<p>As an extension to <a href="https://codereview.stackexchange.com/questions/27375/pages-system-php-sql">this post</a>, I've created this class/script to handle multi-dimensional <code>Menu</code>s whose data is stored in a DB. I need some feedback and new ideas.</p>
<p><a href="http://pastebin.com/ariBn3pE" rel="no... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-20T06:51:34.623",
"Id": "42977",
"Score": "0",
"body": "`lenght` should be `length`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-16T11:36:17.633",
"Id": "116264",
"Score": "0",
"body": "The w... | [
{
"body": "<p>This code is too complex. It is going to be difficult to maintain or reuse.</p>\n\n<h1>Current Issues</h1>\n\n<p>I see the following problems with the code as it is:</p>\n\n<ul>\n<li>Method names are not consistent: <code>lower_pascal_case</code> is mixed with <code>lowerCamelCase</code></li>\n<li... | {
"AcceptedAnswerId": "27578",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T20:38:43.643",
"Id": "27569",
"Score": "2",
"Tags": [
"php",
"sql",
"array"
],
"Title": "Storing hierarchical data in a database"
} | 27569 |
<p>I'm currently developing a music website using OOP PHP and I'm trying to correctly implement the Model View Controller pattern.</p>
<p>I am creating this website from scratch so I would like to avoid answers suggesting I use frameworks such CakePHP etc please.</p>
<p>Here are simplified snippets of the files I'm u... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T20:07:45.173",
"Id": "42942",
"Score": "0",
"body": "Mostly you are missing MVC. Also adhering to few OOP practice and principles would be preferable."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T2... | [
{
"body": "<h3>albumView.php</h3>\n<p>Views are not glorified templates. They should be instances that acquire data from model layer and, based on that information, produce a response for the user.</p>\n<p>Views <strong>do not</strong>:</p>\n<ul>\n<li>initialize controllers</li>\n<li>load configuration</li>\n</... | {
"AcceptedAnswerId": "27571",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T20:00:12.330",
"Id": "27570",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"mvc"
],
"Title": "Is this correct implementation of MVC pattern for PHP website?"
} | 27570 |
<p>I have built a 3D matrix class in C++, mainly for data I/O, for a project I am working on. The code works ok, but I would like you to help me improve it.</p>
<ol>
<li>Are there any bad programming practices I am doing?</li>
<li>Is there any code that could be simplified?</li>
<li>Is there something that would give ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-20T20:29:27.563",
"Id": "43039",
"Score": "1",
"body": "I just noticed something, and as you're unlikely to read through a giant answer answer again, I figured I'd make a comment. Your `delete G`; should be `delete[] G;` since you allo... | [
{
"body": "<p>We can improve this code.</p>\n\n<p><strong>1:</strong> First of all, I urge you to <strong>change your underlying data structure.</strong> <code>double *** G;</code> hurts my eyes. Consider using for example <code>std::vector<std::vector<std::vector<double> > ></code> instead. (... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T21:47:19.347",
"Id": "27573",
"Score": "3",
"Tags": [
"c++",
"matrix"
],
"Title": "Simple matrix class"
} | 27573 |
<p>We have orange rounded buttons as a standard on our site. For our purposes, we switched everything over to use an anchor tag, instead of input type=button. The exception to this was the File Upload Control. For security reasons, you can't write your own, and since buttons in IE can't be rounded with pure CSS, I deci... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-28T18:09:01.707",
"Id": "43517",
"Score": "2",
"body": "FYI: revealing the path to the file to JavaScript is considered a security vulnerability, which is why only the native form control has access to it. Some older browsers (particu... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-19T22:26:06.960",
"Id": "27574",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"html",
"css",
"user-interface"
],
"Title": "File input control with rounded buttons and styl... | 27574 |
<p>I often need to loop through a list of items and need both the index position, and the item itself:</p>
<pre><code>set names {John Paul George Ringo}
set i 0
foreach name $names {
puts "$i - $name"
incr i
}
</code></pre>
<p>Output:</p>
<blockquote>
<pre><code>0 - John
1 - Paul
2 - George
3 - Ringo
</code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-21T02:40:59.370",
"Id": "43051",
"Score": "0",
"body": "Here's a bit more concise way to \"Break down indexexpr\": `lassign $indexexpr idxvar start step; if {$start == \"\"} {set start 0}; if {$step == \"\"} {set step 1}` (shame about ... | [
{
"body": "<p>I would base something like this on <code>for</code> rather than <code>foreach</code></p>\n\n<pre><code>proc foreach_with_index {idxvar elemvar list body args} {\n array set opts {-start 0 -inc 1}\n if {[llength $args] > 0 && [llength $args]%2 == 0} {array set opts $args}\n upv... | {
"AcceptedAnswerId": "27590",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-20T04:24:48.897",
"Id": "27579",
"Score": "4",
"Tags": [
"tcl"
],
"Title": "Tcl loop idea: for_index_item"
} | 27579 |
<p>After a long search of simple php-jquery script from which i can pick the concept from,i gave up.The scripts i found were not very clear so i decided to make my own.This is the repo <a href="https://github.com/thiswolf/php-jquery-pagination" rel="nofollow">https://github.com/thiswolf/php-jquery-pagination</a></p>
<... | [] | [
{
"body": "<p>Well, first of. This code is not at all secure. you don't check wether the $_GET['page'] var is actually an int. But I don't think that was the point here.</p>\n\n<p>Second: sometimes you put the page numer in the id, this is a number and is thus invalid HTML, and sometimes you simply put it in th... | {
"AcceptedAnswerId": "27610",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-20T08:37:08.967",
"Id": "27581",
"Score": "2",
"Tags": [
"php",
"jquery",
"pagination"
],
"Title": "My method of php ajax pagination"
} | 27581 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.