body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<blockquote>
<p><code>NodeData</code> stores all information of the node needed by the <code>AStar</code>
algorithm. This information includes the value of <code>g</code>, <code>h</code>, and <code>f</code>.
However, the value of all 3 variables are dependent on source and
destination, thus obtains at runtime... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-07-07T13:50:57.157",
"Id": "250842",
"Score": "0",
"body": "Why: if (!openQueue.contains(neighbor)) { openQueue.add(neighbor); }\nis only if `tentativeG < neighbor.getG()`?"
}
] | [
{
"body": "<p>This is quite good and professional-looking code. There are many small aspects which I <em>really</em> like:</p>\n\n<ul>\n<li>Using <code>Collections.unmodifiableMap</code> instead of a shallow copy is brilliant.</li>\n<li>The use of a generic <code>nodeId</code> is clever and makes for elegant co... | {
"AcceptedAnswerId": "38380",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-31T23:32:16.700",
"Id": "38376",
"Score": "31",
"Tags": [
"java",
"algorithm",
"search",
"graph",
"pathfinding"
],
"Title": "A* search algorithm"
} | 38376 |
<p>Is there a way I could improve my code's readability, or have I finally won the war against sloppy coding?</p>
<p>Here's a game launcher I made for <em>The Sims 3</em> to fix the awful performance caused by big cache files.</p>
<pre><code>using System.Collections.Generic;
using System.Diagnostics;
using System.Win... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T16:29:57.883",
"Id": "63955",
"Score": "1",
"body": "This is quite simple code, there isn't much to review here. Why didn't you include the Game class too?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01... | [
{
"body": "<p>You would benefit from removing the hard-coded strings out of the code. Best to put them in an app.config file or a resource file. The config file has the additional advantage that the strings could be changed by the user without recompiling.</p>\n\n<p>The naming of the methods and properties is n... | {
"AcceptedAnswerId": "38387",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T12:00:38.963",
"Id": "38383",
"Score": "2",
"Tags": [
"c#",
".net"
],
"Title": "Game launcher for The Sims 3"
} | 38383 |
<p>I want to get the number if items with state <code>4</code> and <code>1</code> from my database for each day between a certain date. Is there a smarter and more performative way than this one?</p>
<p>I am aware that I should use MySQLi and that MySQL is deprecated.</p>
<p>Code explanation:</p>
<ul>
<li>the <code>... | [] | [
{
"body": "<p>Three major points:</p>\n\n<ul>\n<li>Executing SQL queries in a loop will nearly always cause a performance problem. You want to formulate a query that gives you all the data you want.</li>\n<li><code>mysql_query()</code> and similar functions are deprecated; use <code>mysqli</code> or <a href=\"... | {
"AcceptedAnswerId": "38385",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T12:09:07.293",
"Id": "38384",
"Score": "4",
"Tags": [
"php",
"optimization",
"mysql",
"datetime"
],
"Title": "Optimize MySQL double select inside for-loop"
} | 38384 |
<p>I am trying to concatenate the echo statements but I am failing. Also any other tips are appreciated in your review.</p>
<pre><code><?php
// load all 'category' terms for the post
$terms = get_the_terms($post->ID, 'category');
// we will use the first term to load ACF data from
if( !empty($terms) )
{
$te... | [] | [
{
"body": "<p>The places where I have worked, as well as a number of articles I have read, have taught me that <code>echo</code>ing HTML is bad practice, and really if you think about it from a maintenance perspective you want that clear separation of PHP and HTML. An example of your code with that separation:<... | {
"AcceptedAnswerId": "38389",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T15:08:47.460",
"Id": "38386",
"Score": "0",
"Tags": [
"php"
],
"Title": "Need review on concatenation"
} | 38386 |
<p>I wanted to write a simple Log class for PHP, I use ajax calls with AngularJS and often return the log in an array</p>
<p>Example:</p>
<pre class="lang-php prettyprint-override"><code>$return['data'] = $returnedDataArray;
$return['log'] = $logDataArray;
$return['status'] = 'success';
echo json_encode($return);
</c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T18:41:22.477",
"Id": "64364",
"Score": "0",
"body": "What exactly _are_ you logging in this class? It's not writing anything to anywhere... besides: you've not included the possibility of having to log in a namespaced environment, a... | [
{
"body": "<p>No, using static methods is not a recommand approach. With static methods, your class always knows which class it calls. That means you can never switch to another logger class (e.g. one that writes the logs in a file).</p>\n\n<p>A class should be independent of other classes as much as possible. ... | {
"AcceptedAnswerId": "38395",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T17:51:15.423",
"Id": "38393",
"Score": "1",
"Tags": [
"php",
"object-oriented",
"static"
],
"Title": "Writing a static Log class for PHP"
} | 38393 |
<p>I'm a complete neophyte to Haskell with only a smidge of FP experience – I did some Racket programming academically and have written some semi-FP JavaScript professionally, but now I'm trying to learn Haskell (and FP better). So I read <a href="https://www.fpcomplete.com/school/starting-with-haskell/haskell-fast-har... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T12:22:38.537",
"Id": "63992",
"Score": "0",
"body": "If all you want to do on an invalid input is to raise an error with an inane message, then you can be done with `print $ sum $ map read input`"
}
] | [
{
"body": "<p>The reference solution is already a bit flawed: It depends on the fact that the standard library happens to use commas to separate elements when pretty-printing lists. That's the only reason it can just throw brackets on the string and then run it through <code>reads</code> (these functions recons... | {
"AcceptedAnswerId": "38501",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T18:10:20.590",
"Id": "38394",
"Score": "3",
"Tags": [
"beginner",
"haskell",
"functional-programming",
"type-safety"
],
"Title": "\"Hell Difficulty\" Haskell Fast & Hard"
} | 38394 |
<pre><code>#include "stdafx.h"
#include <iostream>
using namespace std;
int main ()
{
for (int i = 0; i <= 3; i++) //give the user 4 guesses at the word.
{
std::string guess;
cout <<"Guess the word" <<endl;
cin >>guess;
if (guess == "Dog")
... | [] | [
{
"body": "<p><code>#include \"stdafx.h\"</code> is superfluous.</p>\n\n<p>The standard idiom in C++ for doing something 4 times is:</p>\n\n<pre><code>for (int i = 0; i < 4; i++) {\n ...\n}\n</code></pre>\n\n<p>Don't deviate from that pattern unless there is a good reason.</p>\n\n<p>Requiring an extra cha... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T19:19:08.187",
"Id": "38396",
"Score": "4",
"Tags": [
"c++",
"strings"
],
"Title": "Char string review"
} | 38396 |
<p><code>Progress</code> class was written using TDD.</p>
<p>Interface of this class (pseudo-code):</p>
<pre><code>class Progress
constructor(title, progressLength)
getTitle() : String
getLength() : int
getCompletedSteps() : List<Integer>
getCompleted() : int
getUncompleted() : int
</cod... | [] | [
{
"body": "<p>It's not clear to me, what is the purpose of this class? Is it a progress tracker for a process with discrete steps (such as for a multi-page survey) or for a progress bar (such as for a filesystem consistency scanner)? In <code>.complete(int lengthToComplete)</code>, the first line (<code>compl... | {
"AcceptedAnswerId": "38403",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T20:38:59.213",
"Id": "38401",
"Score": "4",
"Tags": [
"java",
"object-oriented",
"unit-testing",
"tdd"
],
"Title": "Simple class to represent progress"
} | 38401 |
<p>Needed a quick stream to get JSON objects.</p>
<pre><code>#ifndef THORSANVIL_SIMPLE_STREAM_THOR_STREAM_H
#define THORSANVIL_SIMPLE_STREAM_THOR_STREAM_H
#include <istream>
#include <mutex>
#include <condition_variable>
#include <vector>
#include <curl/curl.h>
#include <string.h>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T08:19:31.603",
"Id": "63978",
"Score": "0",
"body": "The only thing which strikes me as odd is: Why does all the implementation have to reside in a header file? I usually try to keep my header files lean and mean. Unfortunately with... | [
{
"body": "<p>I have a few comments that are unrelated to the synchronous/asynchronous and/or header-only nature of the code.</p>\n<h2>parameters</h2>\n<h3>bools</h3>\n<p>I don't like passing <code>bool</code>s as parameters. I really dislike a function like your <code>SimpleSocketStreamBuffer</code> constructo... | {
"AcceptedAnswerId": "43205",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T20:45:53.190",
"Id": "38402",
"Score": "14",
"Tags": [
"c++",
"socket",
"stream",
"curl",
"http"
],
"Title": "Stream that opens an HTTP GET and then acts like a normal ... | 38402 |
<p><a href="http://projecteuler.net/problem=82" rel="nofollow noreferrer">Project Euler problem 82</a> asks:</p>
<p><img src="https://i.stack.imgur.com/LXxVG.png" alt="enter image description here"></p>
<p>Here's my solution:</p>
<pre><code>def main():
matrix = [
[131, 673, 234, 103, 18],
[2... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T23:30:18.207",
"Id": "63970",
"Score": "0",
"body": "[Here's a interesting read on #82](http://csjobinterview.wordpress.com/2012/08/03/project-euler-problem-82/) if you haven't seen it yet"
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>To solve the Project Euler challenge, you'll have to handle a large matrix from a file. Therefore, your function should accept the matrix as a parameter.</p>\n\n<p>You used <code>size</code> to represent both the number of rows and the number of columns. I would use two variables to avoid hard-c... | {
"AcceptedAnswerId": "38412",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-01T22:58:46.347",
"Id": "38404",
"Score": "2",
"Tags": [
"python",
"project-euler",
"matrix",
"dynamic-programming"
],
"Title": "Project Euler #82 - path sum: three ways"
} | 38404 |
<p>I consider myself a beginner at writing in Java. I have never had a programming class, nor had my code reviewed. I have come to Code Review for some pointers. (Tips that is, not data references.). I have written a simple server/client set, where the server behaves as a textual message relay, receiving and forwarding... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T11:17:51.817",
"Id": "63988",
"Score": "1",
"body": "\"I really can’t be bothered fixing things and doing it ‘the right way’ for this single purpose.\" That's a bad attitude to request a code review with. Or did I misunderstand you ... | [
{
"body": "<p>You have a lot of things in here to review, so I am just going to cherry-pick the things that stand out to me:</p>\n\n<ul>\n<li>It is unconventional to use the new-line handling you have... It is normal to assume that the 'cursor' is at the start of a line when you print, instead of assuming it is... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T07:05:37.943",
"Id": "38410",
"Score": "3",
"Tags": [
"java",
"server"
],
"Title": "Helping my coding style with a java text server"
} | 38410 |
<p>I wonder if my script is all right. Please review my code:</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Menu</title>
<style>
ul {list-style-type:none; margin:0; padding:0;}
li {display:inline;}
a.active {background:red;}
</style>
</hea... | [] | [
{
"body": "<p>you can use these for <code><a></code> tag</p>\n\n<pre><code>a:link {color:#FF0000;} /* unvisited link */\na:visited {color:#00FF00;} /* visited link */\na:hover {color:#FF00FF;} /* mouse over link */\na:active {color:#0000FF;} /* selected link */\n</code></pre>\n\n<p>See this <a hre... | {
"AcceptedAnswerId": "38417",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T11:41:54.843",
"Id": "38413",
"Score": "4",
"Tags": [
"javascript",
"html",
"css"
],
"Title": "Highlight the active link in a navigation menu"
} | 38413 |
<p>I am still fairly green when it comes to SQL joins. The below code works but I want to check that I am doing it the best way before I copy and paste errors into other work in the future.</p>
<p>The idea of the below code is to get the <code>PropertyID</code> and <code>Name</code> of a property from the first Table ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T14:11:04.493",
"Id": "63998",
"Score": "0",
"body": "Do you mean Microsoft SQL? If so that is the one I am using, do you need more detail"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T14:37:42.340",... | [
{
"body": "<p>In this small of a query I wouldn't alias anything. It doesn't make it any more readable and you don't use those column aliases anywhere else in the <strong>query</strong>.</p>\n\n<p>Don't do the reporting stuff on the SQL Server. you can set the title of the column in the datagrid. Don't do it... | {
"AcceptedAnswerId": "38419",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T11:50:37.450",
"Id": "38415",
"Score": "5",
"Tags": [
"sql",
"asp.net",
"sql-server"
],
"Title": "SQL Join with PropertyID and Name"
} | 38415 |
<p>I've created this code which can call functions/ajax requests or pieces of code sequentially, using jQuery. The code not only can call functions/ajax requests or pieces of code sequentially but it also tracks when those calls fail or succeed and when the code fails it stops and doesn't exectue the rest of the queue.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T14:47:51.797",
"Id": "64010",
"Score": "0",
"body": "If you could be kind enough to summarize what the queue does, and how it works. Because improving the code is one thing. Providing you a better solution is another."
}
] | [
{
"body": "<p>I like the idea of your code but you defenitely have some bugs and convention issues that should be dealt with:</p>\n\n<ol>\n<li>Major bug: call does not remove <code>funcArr[name]</code> after iterating them so if you add something to the \"first\" queue and call the first queue, adding something... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T13:39:32.640",
"Id": "38420",
"Score": "6",
"Tags": [
"javascript",
"jquery"
],
"Title": "Sequential function call in JavaScript"
} | 38420 |
<p>Today, I will require your help to improve an iterator adapter. The goal of the adapter (I called it <code>get_iterator</code>) is to adapt <code>std::map</code> iterators for example: map iterators return <code>std::pair</code> instances, a <code>get_iterator<0, std::map<...>::iterator></code> will prov... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T20:34:05.700",
"Id": "64072",
"Score": "0",
"body": "Still getting used to the new syntax for the return type. Not sure why you are using it here. The normal syntax should work and is much clearer (in my opinion)."
},
{
"Con... | [
{
"body": "<h1>Define <code>get_iterator</code> in terms of <code>transform_iterator</code></h1>\n\n<p>As pointed by @Yuushi, Boost has a <a href=\"http://www.boost.org/doc/libs/1_53_0/libs/iterator/doc/transform_iterator.html\" rel=\"noreferrer\"><code>transform_iterator</code></a> class which will apply a fun... | {
"AcceptedAnswerId": "73981",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T14:38:00.923",
"Id": "38421",
"Score": "11",
"Tags": [
"c++",
"c++11",
"iterator"
],
"Title": "Iterator adaptor for iterators returning tuple-like values"
} | 38421 |
<p>I wrote the following piece of Python as a part of a larger system. Profiling reveals that a large amount of time is spent in <code>DocumentFeature.from_string</code>. So far I've tried compiling the unmodified code with Cython and got a 33% improvement in running time. Any suggestions as to how this code can be imp... | [] | [
{
"body": "<p>I find your error handling is a bit counterintuitive: if the input string is invalid, you return an \"empty\" <code>DocumentFeature</code>, but if there are too many tokens, it raises an exception. I would raise exceptions in both cases, and let the caller decide what to do.</p>\n\n<p>I think tha... | {
"AcceptedAnswerId": "38726",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T14:45:06.643",
"Id": "38422",
"Score": "4",
"Tags": [
"python",
"performance",
"parsing",
"cython"
],
"Title": "Speeding up a Cython program"
} | 38422 |
<p>The following code is to enlarge pictures using bilinear interpolation. What can be modified in the function of <code>slow_rescale</code> to make it more efficient? I expect to modify it from the view of Principles of Computer Organization.</p>
<pre><code>unsigned char *slow_rescale(unsigned char *src, int src_x,... | [] | [
{
"body": "<p>Please make everyone (including yourself) a favor :</p>\n\n<ul>\n<li>Declare your variable in the smallest possible scope. Also define them as your declare them if you can (and you usually can).</li>\n<li>Indent your code properly.</li>\n</ul>\n\n<p>Then you'd get something like :</p>\n\n<pre><cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T14:51:31.143",
"Id": "38423",
"Score": "5",
"Tags": [
"optimization",
"c",
"image"
],
"Title": "Bilinear interpolation"
} | 38423 |
<p>I'm developing a site, which has an image upload section, and members and like the image, but a member can like it only once.</p>
<p>I have a table, named <code>uploads</code> which has columns <code>id, ...{more columns}..., like</code>.</p>
<p>I identify members by a token(a 16 digit number)</p>
<p>Now, when a ... | [] | [
{
"body": "<p>Yes this can be done better. Storing data in a serialized format in a database (be it JSON or XML) is a bad idea more often than not. The main issue is that you will have a hard time querying for specific items in the serialized blob (e.g. trying to find which member has liked which images).</p>\n... | {
"AcceptedAnswerId": "38438",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T15:23:38.137",
"Id": "38425",
"Score": "2",
"Tags": [
"php",
"pdo",
"image"
],
"Title": "Image rate system"
} | 38425 |
<p>I've just started writing my own little templating library in JavaScript, because as I went through others, there is always this voice in head, which says: "Oh, this is a lot of code and functionality. Is that really necessary or would it slow down the performance?"</p>
<p><em>If you are able to follow conventions,... | [] | [
{
"body": "<p><a href=\"http://garann.github.io/template-chooser/\" rel=\"nofollow\"><strong>Different templating libraries</strong></a> offer different functions: including helper functions/logic (eg foreach of an object/array and if statements), precompilation, and DOM binding.</p>\n\n<p>In terms of raw perfo... | {
"AcceptedAnswerId": "38449",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T17:41:03.307",
"Id": "38435",
"Score": "25",
"Tags": [
"javascript",
"template",
"library"
],
"Title": "Templating libraries' intelligibility and their performance (compared to... | 38435 |
<p>Here is a python function I wrote to implement the Newton method for optimization for the case where you are trying to optimize a function that takes a vector input and gives a scalar output. I use numdifftools to approximate the hessian and the gradient of the given function then perform the newton method iteratio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T17:43:57.847",
"Id": "64042",
"Score": "0",
"body": "Can you explain what was wrong with the functions in [`scipy.optimize`](http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.html)?"
},
{
"ContentLicense": "... | [
{
"body": "<p><a href=\"http://en.wikipedia.org/wiki/Newton%27s_method#Failure_analysis\" rel=\"nofollow\">Pathological cases</a> exist where Newton's method will not converge on a solution. Yet, there is no obvious way for the caller to tell whether convergence was achieved. You should distinguish between wh... | {
"AcceptedAnswerId": "39649",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T17:42:05.837",
"Id": "38436",
"Score": "8",
"Tags": [
"python",
"optimization",
"mathematics",
"numerical-methods"
],
"Title": "Python class that implements the Newton meth... | 38436 |
<p>In a current javascript project, I'm working with the browsers localStorage, and it will pretty consistently be full. To overcome this, I wrote a wrapper to surround the localStorage object that would keep track of when an object was added.</p>
<p>The hard(er) part, was coming up with the algorithm to make room for... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T20:18:28.337",
"Id": "64067",
"Score": "0",
"body": "How many items do you expect to manage in localStorage ( maximum ) ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T20:54:44.260",
"Id": "6407... | [
{
"body": "<h1>Object.size</h1>\n\n<p>First off, if it's ok with you to use ES5 APIs (you use <code>localStorage</code>, it should be okay), then here's a quicker way to get the number of keys in an object using <code>Object.keys</code>.</p>\n\n<pre><code>return Object.keys(obj).length\n</code></pre>\n\n<h1>Del... | {
"AcceptedAnswerId": "38445",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T18:51:36.473",
"Id": "38441",
"Score": "5",
"Tags": [
"javascript",
"algorithm",
"html5",
"cache"
],
"Title": "Function to delete oldest items out of HTML5 localStorage. Ca... | 38441 |
<p>I have some code that I wrote almost a year ago exactly (<em>1/9/2013</em>) and I would like to know if I wrote it well or if it can be improved. I don't have any fun input or output, as these are not set results coming out of this column in the table.</p>
<pre><code>-- ============================================... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-03-17T23:46:51.990",
"Id": "151718",
"Score": "0",
"body": "I think you might need to have an argument with somebody about separating the presentation from the data. The code smells because the requirements smell."
}
] | [
{
"body": "<p>If you do not want the XML Tags, then do not add them!</p>\n\n<p>This code frustrates me because:</p>\n\n<ul>\n<li>you have not given any indication as to what this code should be doing.</li>\n<li>you are embedding presentation-layer logic in the database layer</li>\n<li>you convert all the data t... | {
"AcceptedAnswerId": "38668",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T19:39:04.443",
"Id": "38444",
"Score": "8",
"Tags": [
"sql",
"sql-server"
],
"Title": "Small query - removing XML tags"
} | 38444 |
<p>The aim of the code below is to see if selected fields are empty so data can be saved in that field. Since I'm making a library system, I wanted to record the basic info on one record (all the books they have taken out so the ID's of them as well as author and title) but this proves to be quite tricky and quite long... | [] | [
{
"body": "<p>Technically, there is no such thing as if-loops. Your code is just a bunch of if-else <em>statements</em> (sorry, this was the language police speaking)</p>\n\n<p>What your code actually needs, is actually a real loop. Use an array or a list of a record, <code>TLoanProduct</code> and loop through ... | {
"AcceptedAnswerId": "38551",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T20:50:10.227",
"Id": "38448",
"Score": "4",
"Tags": [
"delphi"
],
"Title": "Locating empty field groups for saving data"
} | 38448 |
<p>I would especially like to find out how this project should be constructed to be "fully MVVM". I did some reading about MVVM and I started to implement some ideas, but I don't fully understand it yet.</p>
<p>The game works, but I would like to get some advice regarding what could be done better/differently. Does i... | [] | [
{
"body": "<p>quick look; What the heck is this for ?</p>\n\n<blockquote>\n<pre><code>public event PropertyChangedEventHandler PropertyChanged;\n\n[NotifyPropertyChangedInvocator]\nprotected virtual void OnPropertyChanged(string propertyName)\n{\n PropertyChangedEventHandler handler = PropertyChanged;\n i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T21:24:41.870",
"Id": "38451",
"Score": "10",
"Tags": [
"c#",
"game",
"wpf",
"mvvm"
],
"Title": "Pong game in WPF"
} | 38451 |
<p>This is only my third Python script. Be brutal with me. Any tips, tricks, best practices, or better usages would be great!</p>
<pre><code>import socket
from concurrent.futures import ThreadPoolExecutor
THREADS = 512
CONNECTION_TIMEOUT = 1
def ping(host, port, results = None):
try:
socket.socket().co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T00:17:37.553",
"Id": "64097",
"Score": "0",
"body": "What is the purpose of this code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T00:22:42.123",
"Id": "64098",
"Score": "0",
"body": "... | [
{
"body": "<p>It's not Pythonic to pass in a mutable object and use that to store results (like it is in C).</p>\n\n<p><code>range(start, stop)</code> is not inclusive of stop, so you have an off by one error as well.</p>\n\n<p>Using a catch-all <code>except</code> line is also poor practice. It's important to ... | {
"AcceptedAnswerId": "38476",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T21:45:47.150",
"Id": "38452",
"Score": "9",
"Tags": [
"python",
"multithreading",
"python-3.x",
"socket"
],
"Title": "Python Port Scanner"
} | 38452 |
<p>I'm not familiar with Java at all, so I'd like to get some feedback on this piece of code. </p>
<p>I made it by looking at a few Hello World-esque Java server examples, so it may have drawbacks I'm not aware of.</p>
<p>My task was <strong>turning an existing Java console app into a single-threaded server</strong>... | [] | [
{
"body": "<h2>General:</h2>\n\n<p>Commandline handling in any application is a PITA.... My recommendation is that you change both the client side, and server side, to put each argument on a different line so that you don't have to 'split' it on the Server. This would be relatively simple to do.</p>\n\n<h2>OOP:... | {
"AcceptedAnswerId": "38461",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T21:58:31.363",
"Id": "38453",
"Score": "4",
"Tags": [
"java",
"console",
"socket",
"stream",
"server"
],
"Title": "Turning a Java console app into a server"
} | 38453 |
<p>This is the domain class called <code>WordType</code> which has Id as its unique DB generated value and Name and Description as other values.</p>
<p>I was going through the <em>Effective Java</em> <a href="http://web.archive.org/web/20110622072109/http://java.sun.com/developer/Books/effectivejava/Chapter3.pdf" rel=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T23:29:22.393",
"Id": "64092",
"Score": "1",
"body": "There is a [good checklist](http://stackoverflow.com/a/27609/458193) to check against. Looks like your implementation is fine (assuming `id` can't mutate over time). It is weird t... | [
{
"body": "<p>What exactly <em>is</em> the <code>id</code> variable? <code>int</code>? <code>long</code>? <code>Integer</code>? Your <code>hashCode</code> and <code>equals</code> implementations really just \"pass the buck\" to the <code>id</code>.</p>\n\n<p>That being said, the code you posted will work fin... | {
"AcceptedAnswerId": "38458",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T22:23:32.933",
"Id": "38454",
"Score": "5",
"Tags": [
"java",
"hashcode"
],
"Title": "Equals and hashCode implementation"
} | 38454 |
<p>The review I asked for yesterday was for a header only library.<br />
<a href="https://codereview.stackexchange.com/questions/38402/http-stream-a-stream-that-opens-an-http-get-and-then-acts-like-a-normal-c-istr">Stream that opens an HTTP GET and then acts like a normal C++ istream</a></p>
<p>This has some limitation... | [] | [
{
"body": "<blockquote>\n<pre><code>#include \"ThorsSimpleStream.h\"\n</code></pre>\n</blockquote>\n\n<p>There's no <code>ThorsSimpleStream</code> identifier used in the header: instead, \"ThorsSimpleStream.h\" declares <code>class IThorSimpleStream</code>.</p>\n\n<p>I prefer it if the filename of the header ma... | {
"AcceptedAnswerId": "45159",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T22:31:35.857",
"Id": "38455",
"Score": "10",
"Tags": [
"c++",
"socket",
"stream",
"curl",
"http"
],
"Title": "HTTP Stream Part 2 A stream that opens an HTTP GET and the... | 38455 |
<p>I've built a framework that primarily provides automated Ajax and a way to emulate classes. I've pasted the framework below and I hope it is well-commented.</p>
<p><code>klass()</code> and <code>machine()</code> are the interesting methods.</p>
<p>I've also posted some application code so you have some idea of ho... | [] | [
{
"body": "<p>I'm polarized by this code.</p>\n<p>I see many good practices in use here:</p>\n<ul>\n<li>you <strong><code>use strict</code></strong>, consistently indent your code and apparently lint it too;</li>\n<li>you <strong>correctly use scoping</strong> to provide encapsulation, split code in modules and... | {
"AcceptedAnswerId": "38714",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T23:33:31.000",
"Id": "38460",
"Score": "8",
"Tags": [
"javascript",
"ajax"
],
"Title": "A package for classes and Ajax"
} | 38460 |
<p>I have never really had to use Json.net until now, so I'm very rusty at it. For that reason, I would appreciate it if someone could have a look over my code and let me know if the way I have done it is correct. It works as I want it; I just need a more professional eye.</p>
<p>For the class <code>TravelAdvice</cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T16:11:00.560",
"Id": "64171",
"Score": "0",
"body": "There's not much code to look at here. What concerns you? I'd certainly remove the dead code (in comments), but I don't think that's what you mean by reviewing it..."
},
{
... | [
{
"body": "<blockquote>\n<p>all examples I have seen used lots of code, inside the FcoTravelAdvice class I have used about 5 lines, so I was wondering if I have done it correctly.</p>\n</blockquote>\n<p>If it works, you definitely have!</p>\n<p>Still, I have a couple suggestions.</p>\n<h3>Don't make synchronous... | {
"AcceptedAnswerId": "38535",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-02T23:56:39.123",
"Id": "38464",
"Score": "3",
"Tags": [
"c#",
"beginner",
"json.net"
],
"Title": "TravelAdvice class"
} | 38464 |
<p>I have designed a PySide interface for the 3D rendering software package Maya whose purpose is to take a file with animation on a single stream and break it up and export each range of animation. I'm pretty new to PySide and would like just a general overview (or harsh critique) of what I could do to improve the qua... | [] | [
{
"body": "<p>My PySide is a bit rusty but I can't see anything immediately wrong with your structure. I have noticed a few places you could modify to make the code more readable/easier to manage though.</p>\n\n<ol>\n<li><p>You've manually padded some strings to center them in widgets, don't push buttons cente... | {
"AcceptedAnswerId": "38493",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T01:24:22.930",
"Id": "38467",
"Score": "4",
"Tags": [
"python",
"maya",
"pyside"
],
"Title": "PySide interface for Autodesk Maya"
} | 38467 |
<p>In the Java world while writing the data access layer (for CRUD) and the model layer, I have done something like this:</p>
<pre><code>public abstract class AbstractDao<N extends AbstractModel>{
protected Class<N> persistentClass;
public N findById(String id){
return (N)m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T16:54:53.970",
"Id": "64356",
"Score": "1",
"body": "Nothing prevent your case classes from using inheritance at all. What you can't do is extend case classes. Example https://gist.github.com/fedesilva/d9e636695484d8eaddea"
}
] | [
{
"body": "<p>I believe that in addition to the stated Java -> Scala OO question, that you may also be wondering about a good way to \"organize\" Models/DAOs/Controllers in Play 2. So I will incorporate that in my answer.</p>\n\n<p>I would have asked in a comment, but I don't seem to have the rep yet...</p>\n\n... | {
"AcceptedAnswerId": "39716",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T02:27:46.027",
"Id": "38471",
"Score": "7",
"Tags": [
"scala",
"inheritance"
],
"Title": "Case class design in Scala"
} | 38471 |
<h2>Introduction</h2>
<p>I am designing a website as a hobby. As you can probably tell from the code below, I am an absolute beginner. The first thing I'd like to do is to create a nice webpage template that I can use for every page. This is what I have so far (I've added <code>background-color</code>s to the <code... | [] | [
{
"body": "<p><a href=\"http://jsbin.com/OnATOsOj/1/edit\" rel=\"nofollow noreferrer\">Here's a quick demo of what I did</a></p>\n<h1>Heights</h1>\n<p>First off, I'd avoid height. Let the content define the container's height. Otherwise, you'll run into problems, like when the content is taller than the contain... | {
"AcceptedAnswerId": "38483",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T02:56:01.540",
"Id": "38472",
"Score": "4",
"Tags": [
"html",
"css",
"html5",
"layout"
],
"Title": "Webpage Template"
} | 38472 |
<p>I'm working on a simple game in which I need to track the cardinal direction of an object. I experimented with using the enum's ordinal value, as well as using switches for the rotation, but both seemed wrong. This is what I ended up with. Is the following an adequate solution?</p>
<pre><code>// Defines cardinal di... | [] | [
{
"body": "<p>Conceptually it is a great solution. I can suggest some changes, but in reality they are minor. It would also be 'fun' to tune it abit, but in the bigger picture the changes would be miniscule... still...</p>\n\n<p>My biggest observation is that the constructors can be simplified a lot. Instead o... | {
"AcceptedAnswerId": "38482",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T03:45:32.263",
"Id": "38473",
"Score": "6",
"Tags": [
"java",
"enum",
"lookup"
],
"Title": "Critique of Cardinal Direction Enum"
} | 38473 |
<p>This is a simple <a href="https://en.wikipedia.org/wiki/Brute-force_search" rel="nofollow noreferrer">brute force algorithm</a> that I have programmed in C. All the program does is print out every possible combination of the given <code>alphabet</code> for the given length.</p>
<p>I would prefer suggestions on how... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T04:41:30.980",
"Id": "64111",
"Score": "4",
"body": "Brute force is a category, not an algorithm. It might be useful to specify what this code is supposed to do rather than just saying it's brute force. Might save the next person to... | [
{
"body": "<p>I would say that this is pretty much impeccable as a recursive solution.</p>\n\n<p>In <code>bruteSequential()</code>, I would rename <code>i</code> to <code>len</code> for clarity. As a slightly hackish optimization, you could move the <code>memset()</code> call before the for-loop, since you kno... | {
"AcceptedAnswerId": "74379",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-01-03T04:09:29.717",
"Id": "38474",
"Score": "32",
"Tags": [
"performance",
"algorithm",
"c",
"combinatorics"
],
"Title": "Brute Force Algorithm in C"
} | 38474 |
<p>I have a string util method for finding potential "wrapping points" in a string.</p>
<p>For example, if <code>" "</code> and <code>"-"</code> are considered wrapping chars, then for input string<br>
<code>"Antoni Gil-Bao"</code> the method would return the sorted set <code>[6, 10]</code>.</p>
<pre><code>private s... | [] | [
{
"body": "<p><code>Simplify</code> is a relative term. If you want simple, then I would have:</p>\n\n<pre><code>public static int[] findWrappingIndices(final String s) {\n int pos = 0;\n int[] ret = new int[s.length()];\n for (int i = 0; i < s.length(); i++) {\n if (WRAPPING_CHARS.indexOf(s.... | {
"AcceptedAnswerId": "38484",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T05:03:05.540",
"Id": "38477",
"Score": "5",
"Tags": [
"java",
"algorithm",
"strings",
"guava"
],
"Title": "Simplify finding indices of all instances of certain characters i... | 38477 |
<p>I'm attempting to write a Progress Dialog that I can instantiate, show and then pass a task to complete to. I'm pretty new to Task Based Patterns, so please bear with me.</p>
<p>Ideally my goal is to be able to show the progress of a task in a popup window, similar to the VS "Background Operation in Progress" dialo... | [] | [
{
"body": "<p>I think there is a design problem here.</p>\n\n<p>If your window is truly generic, <em>it need not know</em> how the tasks are being launched/queued. I don't think it's a good idea to schedule operations inside <code>Task.Factory.StartNew</code>—your window has no idea what kind of operations they... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T05:44:58.910",
"Id": "38479",
"Score": "3",
"Tags": [
"c#",
"asynchronous",
"task-parallel-library"
],
"Title": "Generic Task Progress Dialog"
} | 38479 |
<p>I am working on an ASP.NET MVC 5 project, using the code-first approach for database design. I have a question about my code design.</p>
<p>I have an Entity in my database schema called <code>Student</code>:</p>
<pre><code>public partial class Student
{
public int Id { get; set; }
public string RollNumber { ge... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T10:59:41.463",
"Id": "64131",
"Score": "4",
"body": "Take a look at [Repository pattern](http://www.remondo.net/repository-pattern-example-csharp/). Instead of static methods on each type of entity, declare a class that handles retr... | [
{
"body": "<p>I'm no big fan of using partial classes because I find it less readable. Like the other commenter I think you should look at the repository pattern for a cleaner solution.\nIt seems a bit odd that you give Student the responsibility to save itself to the context. </p>\n\n<p>Something in the same n... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T05:59:19.497",
"Id": "38480",
"Score": "2",
"Tags": [
"c#",
"asp.net-mvc-5"
],
"Title": "Student data in a database"
} | 38480 |
<p>I have written a method for removing a link from a linked list for a phonebook project I'm currently working on and it works perfectly. However, I want to know whether or not my code is acceptable from a programmer's perspective. I tried to systematically structure it in a way such that it's understandable, but by d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T10:56:36.273",
"Id": "64129",
"Score": "0",
"body": "Why do you need to reimplement linked list yourself? There's plenty implementations available, and I'm sure Java runtime has one as well."
},
{
"ContentLicense": "CC BY-SA... | [
{
"body": "<p>Code is fine I think, although according to <a href=\"http://www.amazon.co.uk/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882\" rel=\"nofollow\">Robert C. Martin</a>, generally, if you need to add a comment then you have failed to write readable code.</p>\n\n<p>For example, this could be ... | {
"AcceptedAnswerId": "38489",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T10:31:58.490",
"Id": "38488",
"Score": "3",
"Tags": [
"java",
"linked-list",
"reinventing-the-wheel"
],
"Title": "Removing a link from a linked list"
} | 38488 |
<p>I am currently in a challenge with my buddy to see who can code a simple paint program in the least lines. The only requirement, is that the program must include an eraser. How can I possibly shorten this code, while still using proper, beautiful syntax?</p>
<pre><code>import sys, pygame
from pygame.locals import *... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T13:11:30.100",
"Id": "64142",
"Score": "0",
"body": "The indentation seems to have gone wrong. Can you fix, please?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T13:35:42.907",
"Id": "64144",
... | [
{
"body": "<p>I didn't really try to understand much but I reckon this does the same thing as your code :</p>\n\n<pre><code>import sys, pygame\nfrom pygame.locals import *\n\npygame.init() \nscreen = pygame.display.set_mode((1000,720)) \nscreen.fill((255,255,255)) \nbrush = pygame.transform.scale(pygame.image.l... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T12:44:56.213",
"Id": "38494",
"Score": "8",
"Tags": [
"python",
"pygame"
],
"Title": "How can I shorten this paint program?"
} | 38494 |
<p>After reading <a href="http://gigasquidsoftware.com/blog/2013/12/02/neural-networks-in-clojure-with-core-dot-matrix/">this</a> article about Neural Networks I was inspired to write my own implementation that allows for more than one hidden layer. </p>
<p>I am interested in how to make this code more idiomatic - for... | [] | [
{
"body": "<p>I'm the author of <code>core.matrix</code>, so hopefully I can give you some tips from that perspective.</p>\n\n<p>If you want to improve performance, it's much better to use vectors in an optimised format throughout (<a href=\"https://github.com/mikera/vectorz-clj\">vectorz-clj</a> is a fine choi... | {
"AcceptedAnswerId": "38628",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T13:32:42.373",
"Id": "38498",
"Score": "13",
"Tags": [
"functional-programming",
"clojure",
"lisp",
"machine-learning",
"neural-network"
],
"Title": "Clojure Neural Net... | 38498 |
<p>About a year ago when I was applying to jobs for the first time, I had an interview at a company and they posed the following problem to me, which I preceded to bomb. </p>
<p>A year later I actually came up with a solution to the problem, and I couldn't be happier. However, I would love for some critiques as to the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T14:47:09.603",
"Id": "64160",
"Score": "0",
"body": "Would you mind describing the algorithm in pseudo-code ? The problem does seem interesting but I am not very familiar with the Perl syntax anymore."
},
{
"ContentLicense":... | [
{
"body": "<p>There are a few things I see in here that I would suggest could be different.</p>\n\n<p>I don't like that the logic for determining whether a cell is a sink is on both <code>Rainfall</code> and <code>Cell</code>. In fact, both classes have the method called <code>is_sink</code>...</p>\n\n<p>My pre... | {
"AcceptedAnswerId": "38507",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T14:26:53.967",
"Id": "38500",
"Score": "40",
"Tags": [
"recursion",
"unit-testing",
"interview-questions",
"perl"
],
"Title": "Rainfall challenge"
} | 38500 |
<p>I just created a sample project using Spring 3.x, Jetty 9.x, GWT 2.5.1 and Gradle <a href="https://github.com/krishnaraj/JettyGwtSpringSample" rel="nofollow">here</a>. It's a slightly modified version of the 'Greeting' GWT application from Google, the only change being that RPC calls are handled by a spring controll... | [] | [
{
"body": "<p>Just some generic note about the code:</p>\n\n<ol>\n<li><p>If the parameter called <code>input</code> contains a name you should rename it to <code>name</code> to express its purpose.</p></li>\n<li><p>Method names should be verbs. I would rename <code>greetServer</code> to <code>serveGreeting</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T15:12:01.827",
"Id": "38503",
"Score": "2",
"Tags": [
"java",
"thread-safety",
"spring",
"gradle",
"gwt"
],
"Title": "JettyGwtSpringSample web application"
} | 38503 |
<p>Say you have a Python class for something that has an optional gender field. You'd like a helper property/method to get the appropriate pronoun for an instance. You'd also like to be able to get the possessive version of the pronoun. The use for these helpers will be in creating human-readable emails and other such ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T17:20:00.680",
"Id": "64178",
"Score": "0",
"body": "In any case, the correct spelling seems to be \"possessive\" and not \"possesive\"."
}
] | [
{
"body": "<p>I usually try to use data structure over code whenever it's possible.\nIt usually make things shorter, easier to read and easier to update.</p>\n\n<p>If I had to write such a thing, I'd probably write something like (untested code but just to show the idea) :</p>\n\n<pre><code>pronouns = {\n 'm... | {
"AcceptedAnswerId": "38529",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T16:36:25.613",
"Id": "38508",
"Score": "1",
"Tags": [
"python"
],
"Title": "Three ways to add pronoun method/property to gendered class in Python"
} | 38508 |
<p>The Levenshtein distance is applied specifically to two string values. The result describes the number of differences between two strings. More specifically, it is the count of the smallest number of operations that can transform one string into the other string. Operations include the insertion, deletion, substitut... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T16:37:07.210",
"Id": "38509",
"Score": "0",
"Tags": null,
"Title": null
} | 38509 |
A class of problems concerned with finding or minimizing the sequence of change operations (such as insertion, deletion, substitution, or transposition) to convert one list or string into another | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T16:37:07.210",
"Id": "38510",
"Score": "0",
"Tags": null,
"Title": null
} | 38510 |
<p>I'm learning JS/jQuery at the moment and have built the following standalone script but I feel that it can probably be improved in some ways?</p>
<p>For example - is there a better way of switching the selected text on the <code>.dropdown-menu li a</code> click event rather than needing to replace the entire HTML?<... | [] | [
{
"body": "<p>There is no reason to swap the text, find the span in the button and toggle the class</p>\n\n<pre><code>var isDefault = parentBtn.hasClass('defaultbutton')\n$(this).parents('.dropdowncontain').find('.button .caret').toggleClass(\"invert\", isDefault);\n</code></pre>\n\n<p>The context selector is a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T16:45:33.750",
"Id": "38511",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"beginner"
],
"Title": "Drop-down menu button highlighting and hiding"
} | 38511 |
<p><em>Moved to Code Review as per comments received on <a href="https://stackoverflow.com/questions/20907502/can-this-while-loop-be-made-cleaner">https://stackoverflow.com/questions/20907502/can-this-while-loop-be-made-cleaner</a></em></p>
<p>Is there a way to make the following while loop a little more optimized? Wh... | [] | [
{
"body": "<p>Nice little system, I understand though why you think this code could be better.</p>\n\n<p>I think there are a few things which would make a difference. The first is a try-finally block, and the second is a simpler loop</p>\n\n<p>First, the try-finally:</p>\n\n<pre><code> InputStream stream = a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T16:59:11.217",
"Id": "38513",
"Score": "8",
"Tags": [
"java",
"performance",
"android"
],
"Title": "Can this while loop be made cleaner"
} | 38513 |
<p>How will this example affect the using implementation in GetSite?</p>
<pre><code>public abstract class SPSiteBase
{
protected abstract string Url { get; set; }
public abstract SPSite GetSite(string url = null);
}
public class SPSiteFactory : SPSiteBase
{
protected override sealed string Url { get; set... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T20:10:22.043",
"Id": "64225",
"Score": "0",
"body": "`using { return }` is the same as `try { return }`—it won't magically handle errors the calling code. Thus `using` will dispose right away."
}
] | [
{
"body": "<p>No, you can't use a factory to dispose your objects, your code is creating and immediately disposing the SPSite as soon as it steps out of your method. </p>\n\n<pre><code>public override SPSite GetSite(string url = null)\n{\n return new SPSite(string.IsNullOrEmpty(url) ? Url : url))\n}\n</cod... | {
"AcceptedAnswerId": "38534",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T19:03:15.333",
"Id": "38531",
"Score": "1",
"Tags": [
"c#",
"design-patterns",
"factory-method",
"sharepoint"
],
"Title": "using (IDisposable) in c# factory pattern"
} | 38531 |
<p>I have a <code>Dictionary<string, object></code> (named <code>tableDict</code>) that has been parsed from JSON. The <code>string</code> describes the intended construction of a class <code>T</code> which is defined within the housing class of this code. The <code>object</code> is the numerical probability valu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T20:45:50.773",
"Id": "64229",
"Score": "0",
"body": "So why would you want to do this?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T20:50:00.320",
"Id": "64230",
"Score": "0",
"body": "... | [
{
"body": "<p>I'd compact the main loop as such:</p>\n\n<pre><code> for (var i = 0; i < tableDict.Count; i++)\n {\n var kvp = tableDict.ElementAt(i);\n var s = kvp.Key;\n\n // Key is \"( something )\" - entry is constructor\n if (brackets.IsMatch(s))\... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T20:12:27.867",
"Id": "38536",
"Score": "4",
"Tags": [
"c#",
"reflection"
],
"Title": "Can my string to instance construction be improved?"
} | 38536 |
<p>I'm attempting to create a final array with data pulled from 3 functions. The first two functions have all the data but then the 3rd function needs to run looping through one of the fields from function 2 in order to have the complete array at the end.</p>
<p>I'm looking for some advice and examples on how to fix t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T22:56:15.767",
"Id": "64252",
"Score": "1",
"body": "Have you considered ditching async/callbacks for promises, e.g. with [Q](https://github.com/kriskowal/q)? Edit: Sorry, I haven't noticed you already said that."
},
{
"Cont... | [
{
"body": "<p>With <a href=\"https://github.com/kriskowal/q\" rel=\"nofollow\">Q promises</a> it would look more or less like this (taking <a href=\"http://chat.stackexchange.com/rooms/12303/discussion-between-dan-abramov-and-medoix\">this chat</a> into account):</p>\n\n<pre><code>var mongoose = require('mongoo... | {
"AcceptedAnswerId": "38545",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T22:47:58.507",
"Id": "38543",
"Score": "3",
"Tags": [
"javascript",
"node.js",
"asynchronous",
"callback"
],
"Title": "Node.js async callback hell"
} | 38543 |
<p>I am not really having any problems with this. I'm just wondering if anybody has any ideas for a path for me to look down for bettering this little FF turn-based style of game in my free time.</p>
<p>I know somebody is going to complain about my global variables and the fact that I am not using object-oriented pro... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T23:14:22.800",
"Id": "64256",
"Score": "5",
"body": "Learn how to write a function in C++!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T23:16:03.933",
"Id": "64257",
"Score": "0",
"body... | [
{
"body": "<ul>\n<li><p><code>system(\"PAUSE\")</code> is entirely unnecessary here. You could do the same thing by simply clearing out <code>cin</code> and then reading a char.</p></li>\n<li><p>You should generally call <code>srand</code> once, at the beginning of the program. Once you've seeded the PRNG, it... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-03T23:07:05.420",
"Id": "38544",
"Score": "6",
"Tags": [
"c++",
"beginner",
"console",
"battle-simulation",
"role-playing-game"
],
"Title": "Battle system in C++"
} | 38544 |
<p>I am working on a website and I've created four text/image news blocks. I am not sure if it's the right / most efficient way to do this.</p>
<p>See <a href="http://jsfiddle.net/cTM3L/" rel="nofollow">my code here</a> at jsfiddle</p>
<p><strong>HTML:</strong></p>
<pre><code><div id="wrapper">
<div i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T02:17:37.957",
"Id": "64290",
"Score": "1",
"body": "Honestly, what you have looks fine to me. It may be worth looking at some of the frameworks like Bootstrap to see if either they do what you want and you can just use them or if t... | [
{
"body": "<p>As I mentioned in a comment, those blocks look like a 1 row table.</p>\n\n<p>I redid your code with a table and it is actually shorter ( I could take out a few divs ) and it does require less css. I also extracted the style on the image into a css rule.</p>\n\n<p><a href=\"http://jsfiddle.net/koni... | {
"AcceptedAnswerId": "38705",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T00:07:15.890",
"Id": "38552",
"Score": "1",
"Tags": [
"html",
"css"
],
"Title": "Is this the right way to space four news blocks right from each other?"
} | 38552 |
<p>I was reading about opaque pointers and decided to try it with queues. Please review my code and let me know if there are any errors and how to improve code quality and performance.</p>
<p>It uses lines to enqueue and dequeue. All lines have fixed sizes and dequeue/enqueue never share a line. New lines are added on... | [] | [
{
"body": "<p>Your header looks fine - opaque pointers are as simple as that. Don't forget\nthe <code>const</code> on function parameters (pointers) where possible.</p>\n\n<p>Hmmm, a <code>Line</code> structure with double-pointers. That looks suspect. Double\npointers are usually unnecessary. We'll see wha... | {
"AcceptedAnswerId": "38614",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T05:29:29.163",
"Id": "38556",
"Score": "5",
"Tags": [
"c",
"queue"
],
"Title": "Queue implementation in C"
} | 38556 |
<p>I have an application that essentially "pings" all of the servers on my network. I have about 100 servers, and this ping will happen every 10 seconds.</p>
<pre><code>public class HealthChecker {
private static List<InetSocketAddress> servers = new ArrayList<InetSocketAddress>();
public static voi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T13:13:41.143",
"Id": "64342",
"Score": "0",
"body": "I have added an answer with an example which utilizes ThreadPoolExecutor"
}
] | [
{
"body": "<ol>\n<li><p>Instead of spawning a new thread every time you probably should execute them on <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool%28int%29\" rel=\"nofollow\">a thread pool</a>.</p></li>\n<li><p>You want to wrap your <code>servers</... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T06:05:29.763",
"Id": "38557",
"Score": "10",
"Tags": [
"java",
"concurrency",
"server"
],
"Title": "Concurrent multi-server pinging in Java"
} | 38557 |
<p>I was hoping to get some general feedback and thoughts about my implementation of a generic priority queue. Please feel free to be as critical as you want or see fit.</p>
<p>Generic priority queue implementation (please note that the <code>PriorityConvention</code> can be <code>None</code>, <code>HighestPriorityIn... | [] | [
{
"body": "<p><strong>General</strong></p>\n\n<p>Priority queues in general keep a queue per priority. While your implementation achieves that, it is associated with a lot of copying when inserting and removing data due to the array backing structure of <code>List</code>. Using a <a href=\"http://msdn.microsoft... | {
"AcceptedAnswerId": "38564",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T07:36:19.717",
"Id": "38560",
"Score": "7",
"Tags": [
"c#",
"generics",
"queue"
],
"Title": "PriorityQueue<T> implementation"
} | 38560 |
<p>I asked <a href="https://stackoverflow.com/questions/20908568/calculating-daily-and-monthly-sales-from-text-file">this question</a> yesterday, and now I have come up with this code:</p>
<p><strong>stock.h</strong></p>
<pre><code>#ifndef stock_stock_h
#define stock_stock_h
#include <iostream>
class stock {... | [] | [
{
"body": "<ul>\n<li><p><code>stock</code> doesn't need a default constructor if the starting values won't be useful. If you'll never need to create a <code>stock</code> object with default values, then you can just leave this out.</p></li>\n<li><p>In <code>private</code>, declare each member once per line:</p... | {
"AcceptedAnswerId": "38581",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T08:29:34.050",
"Id": "38561",
"Score": "6",
"Tags": [
"c++",
"parsing",
"io"
],
"Title": "Parsing store sales content from a text file"
} | 38561 |
<p>I just submitted <a href="https://github.com/statsmodels/statsmodels/pull/1287" rel="nofollow">this pull request</a> to <a href="https://github.com/statsmodels/statsmodels" rel="nofollow"><code>statsmodels</code></a> (a Python toolkit for statistical and econometric modeling). It adds support for <a href="https://en... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T10:59:45.837",
"Id": "64320",
"Score": "0",
"body": "You have cut out all the documentation from the code you posted. How do you expect us to review it without knowing what it is supposed to do or how to use it? Please restore the d... | [
{
"body": "<p>Some quick comments just based on reading the documentation and the first few lines:</p>\n\n<ol>\n<li><p>Typos, inconsistencies, and omissions:</p>\n\n<ul>\n<li>The first line should be a summary of the behaviour of the function, not a title, so something like \"Exponentially smooth a time series\... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T10:07:26.557",
"Id": "38563",
"Score": "3",
"Tags": [
"python",
"numpy",
"iteration",
"statistics"
],
"Title": "Help improve my my python code for Exponential Smoothing Sumitt... | 38563 |
<p>I am implementing a library in C/C++11 and I have chosen to follow <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml" rel="nofollow" title="Google C++ Style Guide">Google C++ Style Guide</a> as I also use this style guide in my code.</p>
<p>As such all classes and types (including <code>typede... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T16:50:54.280",
"Id": "64355",
"Score": "0",
"body": "I am not certain this question belongs on CodeReview. Perhaps [Programmers](http://programmers.stackexchange.com/help/on-topic) is a better site?"
},
{
"ContentLicense": "... | [
{
"body": "<p>There is no single correct answer in all circumstances. You have to weigh the costs and benefits of the alternatives. Oddly enough my analysis seems to match yours, but here's one additional alternative you didn't explicitly cover:</p>\n\n<ul>\n<li><p>Add redundant typedefs. All types you create w... | {
"AcceptedAnswerId": "38573",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T12:04:11.660",
"Id": "38566",
"Score": "2",
"Tags": [
"c++",
"c++11",
"library"
],
"Title": "Library with Optional traits"
} | 38566 |
<p>I'm doing a <a href="http://codingbat.com/prob/p181646">CodingBat exercise</a> and would like to learn to write code in the most efficient way. On this exercise, I was just wondering if there's a shorter way to write this code.</p>
<pre><code>monkeyTrouble(true, true) → true
monkeyTrouble(false, false) → true
monke... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-09T13:54:58.077",
"Id": "65063",
"Score": "0",
"body": "there is \"Show Solution\" button that shows 3 solutions on the page you linked"
}
] | [
{
"body": "<p>Sometimes it is easy to forget that the simplest logical constructs like boolean are comparable with the <code>==</code> operator, and that, in Java, <code>(false == false)</code> is <code>true</code>.</p>\n\n<p>With this in mind, your code could become:</p>\n\n<pre><code>public boolean monkeyTrou... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T13:20:16.067",
"Id": "38570",
"Score": "12",
"Tags": [
"java"
],
"Title": "Simpler boolean truth table?"
} | 38570 |
<p>I have JSON files of size <code>data_large(150.1mb)</code>. The content inside the file is of type <code>[{"score": 68},{"score": 78}]</code>. I need to find the list of unique scores from each file. </p>
<p>This is what I'm doing:</p>
<pre><code>import ijson # since JSON file is large, hence making use of ijson
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T20:35:09.893",
"Id": "64375",
"Score": "0",
"body": "`ijson` is an *iterative* parser, so `ijson.items` will *not* load the whole file. The `set` creation likely isn’t the bottleneck; reading the huge file is."
},
{
"Content... | [
{
"body": "<p>So… I have spent a bit time on this and generated myself a random JSON file matching your format. Mine is 167 MB in size, so not too far off from yours.</p>\n\n<p>First of all, <code>ijson</code>’s performance is terrible. I’ve tried it multiple times and it’s very slow for me (much slower than yo... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T15:51:36.037",
"Id": "38574",
"Score": "2",
"Tags": [
"python",
"performance",
"json"
],
"Title": "How to find the unique values from the JSON file?"
} | 38574 |
<p>I'm pretty new to C++. I'm trying to design a <code>EntityManager</code> system, and so far this is what I have:</p>
<pre><code>#ifndef ENTITY_MANAGER
#define ENTITY_MANAGER
#include "Entity.h"
#include "Airplane.h"
#include "Runway.h"
#include "Customer.h"
#include <unordered_map>
class EntityManager
{
pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T21:39:12.417",
"Id": "64639",
"Score": "0",
"body": "There is no ownership associated with your code. Who owns a pointer? Is it the entity manager. PS. Stop using pointers. In modern C++ you should practically never see a pointer un... | [
{
"body": "<p>Ahhhhhhhhh</p>\n<pre><code>static EntityManager* instance();\n</code></pre>\n<p>No ownership associated with even the manager.<br />\nIf I get a manager. Who is responsible for destroying it?</p>\n<pre><code>// Do this.\n// Use the classic singleton pattern.\nstatic EntityManager& instance()\n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T16:14:38.260",
"Id": "38576",
"Score": "1",
"Tags": [
"c++",
"beginner"
],
"Title": "Is this a decent way to create an EntityManager?"
} | 38576 |
<p>I wrote a function to calculate the gamma coefficient of a clustering. The bottleneck is the comparison of values from <code>dist_withing</code> to <code>dist_between</code>. To speed this up, I tried to adapt and compile it using Cython (I dealt with C only few times). But I don't know, how to rapidly iterate over ... | [] | [
{
"body": "<p>When you deal with performance in cython, I would suggest using the --annotate flag (or use IPython with cython magic that allow you quick iteration with anotate flag too), it will tell you which part of your code <strong>may</strong> be slow. It generates an Html report with highlighted lines. Th... | {
"AcceptedAnswerId": "40258",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T17:33:02.190",
"Id": "38580",
"Score": "17",
"Tags": [
"python",
"optimization",
"array",
"numpy",
"cython"
],
"Title": "Fastest way to iterate over Numpy array"
} | 38580 |
<p>The Cython language is a superset of the Python language, used to quickly extend and optimize Python code.</p>
<p>The Cython compiler outputs a C or C++ representation of this Python superset, with all necessary boilerplate code in place, ready to be built and loaded as a Python extension.</p>
<p>Cython supplement... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T19:22:44.987",
"Id": "38583",
"Score": "0",
"Tags": null,
"Title": null
} | 38583 |
The Cython language is a superset of the Python language, used to quickly generate Python C extensions. You should also tag with Python when using this tag. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T19:22:44.987",
"Id": "38584",
"Score": "0",
"Tags": null,
"Title": null
} | 38584 |
<p>Is there any way I can cut down on code? I'm new to this.</p>
<pre><code>Sub addtest()
Dim decision As Char
Dim fullline As String = " "
Dim word(9), def(9), minorerror1(49), minorerror2(49), minorerror3(49), minorerror4(49), minorerror5(49) As String
Console.Clear()
Console.WriteLine("Pleas... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T12:04:02.083",
"Id": "96279",
"Score": "0",
"body": "The obvious would be to ommit that case structure that appears to be unused"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T12:25:26.080",
"Id"... | [
{
"body": "<p>You should read up on arrays :</p>\n\n<pre><code> Console.Write(\"Minor error 1: \")\n minorerror1(counter) = Console.ReadLine\n Console.Write(\"Minor error 2: \")\n minorerror2(counter) = Console.ReadLine\n Console.Write(\"Minor error 3: \")\n minorerror3(counter) = Console.Read... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T19:29:21.730",
"Id": "38585",
"Score": "2",
"Tags": [
"beginner",
"vb.net"
],
"Title": "Spelling bee test writer"
} | 38585 |
<p>I wrote a helper to limit <a href="http://github.com/kriskowal/q" rel="nofollow">Q</a> promise concurrency.<br>
If I have a promise-returning function <code>promiseSomething</code>, writing</p>
<pre><code>promiseSomething = PromiseScheduler.limitConcurrency(promiseSomething, 5);
</code></pre>
<p>ensures no more th... | [] | [
{
"body": "<p>Your code looks good to me. Promises/A are a great pattern - however it can be hard to grasp in the beginning, I personally still got problems in understanding the Q library and Promises/A spec to wrap my head around</p>\n\n<p>Your implementation looks familiar to control flow patterns presented h... | {
"AcceptedAnswerId": "40625",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T20:38:46.897",
"Id": "38588",
"Score": "3",
"Tags": [
"javascript",
"node.js",
"asynchronous",
"promise"
],
"Title": "Limiting Q promise concurrency in JavaScript"
} | 38588 |
<p><a href="https://en.wikipedia.org/wiki/Http" rel="nofollow noreferrer">Hypertext Transfer Protocol (HTTP)</a> uses a client-request/server-response model. HTTP is a stateless protocol, which means it does not require the server to retain information or status about each user for the duration of multiple requests.</p... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T21:25:40.747",
"Id": "38589",
"Score": "0",
"Tags": null,
"Title": null
} | 38589 |
HyperText Transfer Protocol (HTTP) is an application level network protocol used for the transfer of content on the World Wide Web. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T21:25:40.747",
"Id": "38590",
"Score": "0",
"Tags": null,
"Title": null
} | 38590 |
HAML is a markup language that’s used to cleanly and simply describe the HTML of any web document without the use of inline code. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T21:27:05.617",
"Id": "38592",
"Score": "0",
"Tags": null,
"Title": null
} | 38592 |
<p>Use this tag for questions involving visual presentations, whether they are generated using bitmap or vector techniques. For questions involving the manipulation and use of stored pictures, use the related tag <a href="/questions/tagged/image" class="post-tag" title="show questions tagged 'image'" rel="tag"... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T21:36:31.153",
"Id": "38593",
"Score": "0",
"Tags": null,
"Title": null
} | 38593 |
Use this tag for questions involving visual presentations, whether they are generated using bitmap or vector techniques. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-04T21:36:31.153",
"Id": "38594",
"Score": "0",
"Tags": null,
"Title": null
} | 38594 |
<p>This is a game I made in Python. While it is not my first, I am not happy with the result. I would like suggestions on ways I can make it better, more user-friendly, and more enjoyable. Also, if you have suggestions on how to get the same effect, but with cleaner, more organized code, please make them.</p>
<p>Pl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-02-17T13:03:14.787",
"Id": "224041",
"Score": "0",
"body": "your indentations are a bit to big"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-10-24T23:29:05.657",
"Id": "272509",
"Score": "0",
"body"... | [
{
"body": "<p>A few suggestions:</p>\n\n<ol>\n<li>Follow <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a>'s code conventions (e.g. spaces after commas, line lengths);</li>\n<li>Put your <code>start()</code> instance method immediately after <code>__init__()</code>; it took me a whi... | {
"AcceptedAnswerId": "38723",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T02:44:53.793",
"Id": "38601",
"Score": "6",
"Tags": [
"python",
"game",
"python-2.x"
],
"Title": "Improvements on Python game?"
} | 38601 |
<p>For my junior high, IT final project, I decided to make a C++ program which functions as a simple library manager. The functions of the manager are to check your own library, view the store's library and buy from it, and check your transaction history. </p>
<p>I made separate arrays for each of the three above, and... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T03:18:35.027",
"Id": "64395",
"Score": "0",
"body": "I'll take a better look at this later, but I can say this for now: global variables and `goto` are bad. Any future answers should address that."
},
{
"ContentLicense": "C... | [
{
"body": "<p>This is my first time reviewing C++ code! I'm may be a bit harsh since this is for a final grade. </p>\n\n<hr>\n\n<p>There is a place in your code where one of your methods could reach then end of a non-void function, and doesn't return anything. <strong>This was actually an error for me, and t... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T02:58:31.313",
"Id": "38602",
"Score": "10",
"Tags": [
"c++"
],
"Title": "A simple array library program"
} | 38602 |
<p>I'm designing in my spare time a game engine (for fun, not so much for profit, haha). I wanted to design the 'core pipeline' as efficiently as possible. Having a quad-core CPU, I decided to take advantage of parallel processing.</p>
<p>I wanted to implement a lock-free algorithm (or at least, low-locking) to make t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T04:32:38.837",
"Id": "64402",
"Score": "0",
"body": "You're confusing atomic safety with application thread safety, essentially - ie `Volatile.Read(ref workloadsRemaining)` _will_ get you the state of the variable, but your comparis... | [
{
"body": "<p>you have a little bit of rewriting that can be done on this chunk of code</p>\n\n<pre><code>private static void InitThreadPool() {\n int numLogicalCores = Environment.ProcessorCount;\n int poolSize = numLogicalCores;\n if (PipelineConfig.MaxThreads > 0 && numLogicalCores > P... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T03:23:08.977",
"Id": "38604",
"Score": "8",
"Tags": [
"c#",
"multithreading",
"lock-free"
],
"Title": "Low-lock Multi-threading Implementation"
} | 38604 |
<p>I wrote this code to handle a fixed number of priority levels. I believe performance will depend on the number of priority levels.</p>
<p>Considering only a few levels (3 to 5), is there a more efficient way of doing this? I would also like to know how to improve code quality.</p>
<p>I'm just storing the elements ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T09:00:03.363",
"Id": "64415",
"Score": "2",
"body": "`Considering only a few levels (3 to 5), is there a more efficient way of doing this?` Short answer: no. A PQ is typically implemented as some type of heap (binary or Fibonacci pr... | [
{
"body": "<p>Like @Corbin said, there is little that can be done to improve the efficiency of your code. But there are a few things I can do to improve the code quality.</p>\n\n<ul>\n<li><p>You list define a lot of priorities in your header file.</p>\n\n<pre><code>#define VERY_HIGH_PRIORITY 4\n#define HIGH_PR... | {
"AcceptedAnswerId": "40231",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T03:26:43.863",
"Id": "38605",
"Score": "5",
"Tags": [
"c",
"queue"
],
"Title": "Very simple priority queue"
} | 38605 |
<p>I have the following scenario: </p>
<pre><code> class Product < ActiveRecord::Base
belongs_to :categories
end
class Category < ActiveRecord::Base
has_many :products
end
</code></pre>
<p>Categories table has 2 level nesting, for example.
Main category is 'Men', sub-category ... | [] | [
{
"body": "<p>These are nested selects, you can try <a href=\"https://github.com/collectiveidea/awesome_nested_set\" rel=\"nofollow\">awesome_nested_set</a>, and use it like this:</p>\n\n<pre><code><%= f.select :parent_id, \n nested_set_options(Category, @category) {|i| \"#{'-' * i.level} #{i.nam... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T03:32:01.917",
"Id": "38606",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"ruby-on-rails",
"ajax"
],
"Title": "Different selects in one form with same name attribute?"
} | 38606 |
<p>I'm creating a custom <code>MembershipProvider</code> for an ASP.NET MVC5 application and am wanting to know if this code is acceptable for creating hashed and salted passwords. Is there anything I can do to improve it?</p>
<p><code>EncodePassword</code> is passed the plaintext password from the override functions... | [] | [
{
"body": "<p>This is a pretty good start: you've got salting done pretty well (<code>RNGCryptoServiceProvider</code> is one of the most common recommended was to generate a salt), and the idea of using multiple iterations is a good one.</p>\n\n<p><strong>However</strong>, doing 38 iterations of HMAC SHA1 yours... | {
"AcceptedAnswerId": "38711",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T04:04:15.067",
"Id": "38608",
"Score": "4",
"Tags": [
"c#",
"asp.net",
"security",
"cryptography"
],
"Title": "Is this password hashing acceptable for a custom MembershipPr... | 38608 |
<p>I am working on a website, and due to some reasons, they want my code to be as short as possible. I have, from my side, tried everything to shorten this code.</p>
<p>So if possible, can you all also help me in making this code shorter? I know that there are vulnerabilities, and I will solve them later.</p>
<p>For... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T14:48:06.847",
"Id": "64578",
"Score": "0",
"body": "If its any help, I open sourced my url shortener http://smfu.in (doesn't work as I'm in the middle of a server move). You can see the code at https://github.com/jsanc623/smfu"
}... | [
{
"body": "<p>Brevity of code seems an odd point of focus, so I plan on ignoring that. I do, however, have quite a few suggestions, and, convieniently for you, those will probably shorten the code.</p>\n\n<hr>\n\n<p>Don't assume user provided variables are actually set. For example, don't access <code>$_POST['u... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T07:00:42.903",
"Id": "38611",
"Score": "0",
"Tags": [
"php",
"html",
"mysqli",
"http"
],
"Title": "Shorten my URL shortener"
} | 38611 |
<p>This JavaScript converts degrees to a compass point, e.g. <code>convert.toCompass(140)</code> gets <code>140° -> SE</code>.</p>
<p>I can't help but think: is there a more concise way to do this?</p>
<pre><code>var convert = {
toCompass: function(degrees)
{
if(degrees >= 0 && degrees &... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T12:25:18.163",
"Id": "64434",
"Score": "0",
"body": "THis question is very similar to another question here. There is a fair amount of discussion on that other question whihc may be useful to you too: http://codereview.stackexchange... | [
{
"body": "<p>By looking at values in your series of <code>if</code>'s, you can make an array (<code>[]</code>), then calculate which index to pick:</p>\n\n<pre><code>var convert = {\n toCompass: function(degrees)\n {\n return ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WS... | {
"AcceptedAnswerId": "38615",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-01-05T08:34:39.770",
"Id": "38613",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "Getting a compass point from 140°"
} | 38613 |
<p><a href="http://qt-project.org/" rel="nofollow">Qt</a> is a cross-platform application and UI framework for developers using <a href="/questions/tagged/c%2b%2b" class="post-tag" title="show questions tagged 'c++'" rel="tag">c++</a> or QML, a <a href="/questions/tagged/css" class="post-tag" title="show questi... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T09:44:21.010",
"Id": "38617",
"Score": "0",
"Tags": null,
"Title": null
} | 38617 |
Qt is a cross-platform application and UI framework for developers using C++ or QML, a CSS & JavaScript like-language. (Also use the [c++] tag for C++ code.) | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T09:44:21.010",
"Id": "38618",
"Score": "0",
"Tags": null,
"Title": null
} | 38618 |
<p>A few years ago I required a lightweight in-app-in-memory cache. Requirements:</p>
<ul>
<li>Time complexity <code>O(1)</code> for individual element read/write access</li>
<li>Space complexity <code>O(n)</code> (for <code>n</code> elements)</li>
<li>Safe for concurrent read/write access </li>
<li>Cache size limited... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-07-10T14:54:17.437",
"Id": "251491",
"Score": "0",
"body": "Can you please publish the improved code? The base seems very nice, and if it's better now..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-03-02T14:2... | [
{
"body": "<p>Before I get to the main issue, first some smaller notes:</p>\n\n<ol>\n<li><p>A type that is nested in a generic type doesn't need to redeclare the type parameters of the parent, it can use them directly:</p>\n\n<pre><code>public class Cache<TKey, TValue>\n{\n protected class CacheValue\n... | {
"AcceptedAnswerId": "38786",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T10:37:51.507",
"Id": "38619",
"Score": "13",
"Tags": [
"c#",
"cache"
],
"Title": "In-memory cache implementation"
} | 38619 |
<p>I am doing a web app for an event company whereby customer can access the website for a self-help instant quotation. Customer will choose the type of event, fill a form and expect an instant quotation.</p>
<p>Can anyone give me some tips how can I improve my design? Below are my current design thoughts.</p>
<p>Quo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T12:50:41.440",
"Id": "64437",
"Score": "1",
"body": "What is this supposed to accomplish, in what way are you **using** these classes?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T00:50:02.413",
... | [
{
"body": "<p>I would suggest the following potential improvements.</p>\n\n<p>Change the Quotation class to the following</p>\n\n<pre><code>public class Quotation\n{\n private Customer customer;\n\n private List<BaseEvent> events = new List<BaseEvent>();\n\n\n // Getters and setters to acce... | {
"AcceptedAnswerId": "38622",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T10:45:42.377",
"Id": "38620",
"Score": "2",
"Tags": [
"java",
"design-patterns"
],
"Title": "Design To Handle Multiple Similar Model Class"
} | 38620 |
<blockquote>
<p>Tom Sawyer has many friends who paints his fence. Each friend painted
contiguous part of the fence. Some planks could stay unpainted, some
could be painted several times. Program must output the number of
painted planks.</p>
<p><strong>Input format:</strong></p>
<p>First line: <em>N</e... | [] | [
{
"body": "<p>Because of this, the first algorithm is of the <a href=\"http://en.wikipedia.org/wiki/Big_O_notation\" rel=\"nofollow\">order</a> \\$O(n^2)\\$:</p>\n\n<pre><code> for i:=2 to n do {for each segment, except the first}\n for j:=1 to i-1 do\n</code></pre>\n\n<p>The second algorithm is also ... | {
"AcceptedAnswerId": "38623",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T10:51:53.183",
"Id": "38621",
"Score": "3",
"Tags": [
"optimization",
"array",
"programming-challenge",
"time-limit-exceeded",
"pascal"
],
"Title": "Painting Tom Sawyer... | 38621 |
<p>Is the below code efficient for parsing the file, or do I face performance issues? If the latter, please offer suggestions.</p>
<pre><code>#include <iostream>
#include <fstream>
#include <map>
using namespace std;
ofstream outfile;
void writedata(string data, string file)
{
outfile.open(file... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T17:05:39.710",
"Id": "64456",
"Score": "2",
"body": "The only real way to know if you'll face performance issues is to actually run the code. If it turns out to be slow, _then_ optimise it."
},
{
"ContentLicense": "CC BY-SA ... | [
{
"body": "<ol>\n<li><pre><code>ofstream outfile;\n</code></pre>\n\n<p>Why is this declared global? The variable is only used in <code>writedata</code>. Declare it in this scope.</p></li>\n<li><pre><code>ofstream out;\n</code></pre>\n\n<p>What is the purpose of this stream? It is opened (multiple times!) in the... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T12:42:18.300",
"Id": "38626",
"Score": "1",
"Tags": [
"c++",
"parsing",
"c++11"
],
"Title": "Is this code efficient for file parsing?"
} | 38626 |
<p>I am still a beginner in C++ and I am always curious about good/best coding methods.</p>
<p>Let's say I have a program which allows a users to edit the salary of a employee.</p>
<ol>
<li><p>The system will prompt the user which to key in a employee's name first.</p></li>
<li><p>The system will then check whether o... | [] | [
{
"body": "<p>Your question is surprisingly hard to answer, largely because you ask one question in your words, but a different question in your code. Your written question is whether looking up a value by sequentially scanning a vector is the best or worst way to do it. And the answer to that question is nuanc... | {
"AcceptedAnswerId": "38634",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T13:36:34.677",
"Id": "38629",
"Score": "3",
"Tags": [
"c++",
"beginner",
"search"
],
"Title": "Searching and comparing a record"
} | 38629 |
<p>I have written a Tic-Tac-Toe game. I have a class called <code>GameEndAnalyzer</code> that will check if the game has already ended or not.</p>
<p>Would it violate the Single Responsibility Principle if I will add more responsibilities to this class to not only decide if someone has won the game, but who has won (... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T18:43:29.173",
"Id": "64464",
"Score": "0",
"body": "I rewrote my earlier Tic Tac Toe implementation to address your question and amended my answer; [check it out](http://codereview.stackexchange.com/a/38639/2634)."
}
] | [
{
"body": "<p>You're using extension methods for cells; why do use <code>for</code> loops for rows? It strikes me as weird. Also, there's plenty of repetition in your analyzer; you can do better by abstracting some things away (more on that below).</p>\n\n<p>To answer your main question, <strong>instead of ret... | {
"AcceptedAnswerId": "38639",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T14:22:26.063",
"Id": "38632",
"Score": "5",
"Tags": [
"c#",
"game",
"tic-tac-toe"
],
"Title": "Adding more responsibility to this endgame-analyzer class"
} | 38632 |
<p>Some time ago I wrote a little property class for a then abandoned project. I just stumbled over it again and I would like to know if the design is using good, efficient C++.</p>
<pre><code>#pragma once
#ifndef NO_THREAD_SAFETY
#include <atomic>
#endif
template<typename T1>
class Property {
public:
#... | [] | [
{
"body": "<p>These are the things that stuck out to me:</p>\n\n<ol>\n<li>Your copy constructor and move constructor don't result in an identical <code>Property<T1></code> as they increment the <code>id</code>. Why is that? (There is no documentation anywhere in this that helps the consumer of your Proper... | {
"AcceptedAnswerId": "38641",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T15:18:27.830",
"Id": "38635",
"Score": "3",
"Tags": [
"c++",
"c++11",
"properties"
],
"Title": "Generic Property class"
} | 38635 |
<p>I'm trying to learning JS good practices. With jQuery, everything was easier and organized. With JS, I really don't know if I doing this right.</p>
<p>I must repeat the element I am manipulating all the time? For example:</p>
<pre><code>elementHere.className = "";
elementHere.classList.add(test);
elementHere.addEv... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T15:19:10.190",
"Id": "64449",
"Score": "0",
"body": "why not: `elementHere.className = test;` ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T15:22:44.867",
"Id": "64450",
"Score": "0",
... | [
{
"body": "<p>This code is perfectly fine (aside from the fact that it's weird to clean up <code>className</code> and then add one item to <code>classList</code>—might as well set <code>className</code> directly).</p>\n\n<p>DRY is about repetition of logic (which is dangerous because you may forget to change it... | {
"AcceptedAnswerId": "38654",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T15:07:34.963",
"Id": "38637",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "How to improve my JS code? Avoid repeated element"
} | 38637 |
<p>I've built a small library that I use to boot or start a web application. The library code has been posted below, as well an example of application code. I'm looking for ways to make the code more concise or "tighter".</p>
<p>If there's anything I can do to make the comments better, let me know.</p>
<p><strong>L... | [] | [
{
"body": "<p>From a once over:</p>\n\n<p>This</p>\n\n<pre><code> if (!name) {\n name = 'X';\n }\n</code></pre>\n\n<p>can be changed by using a fairly common logic trick:</p>\n\n<pre><code>name = name || 'X';\n</code></pre>\n\n<p>This could be simplified, mostly using some sugar:</p>\n\n<pre><code>... | {
"AcceptedAnswerId": "38696",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T17:19:46.883",
"Id": "38643",
"Score": "2",
"Tags": [
"javascript",
"library"
],
"Title": "A package for application booting"
} | 38643 |
<p>I have written my first jQuery plugin for a website. It is, essentially, a Fancybox style popup that uses AJAX to load content from other pages. It's kind of a frankenstein build from multiple tutorials and best guess uses of the jQuery API. It works, but I am looking to refine it further.</p>
<p>As this is my firs... | [] | [
{
"body": "<p>From a once over review </p>\n\n<ul>\n<li>Code is well commented</li>\n<li>You have 2 variables that you did not declare with a <code>var</code> : <code>last</code> and <code>nextURL</code></li>\n<li>Your resize listener will not work, use <code>setHeight();</code> instead of <code>setHeight;</co... | {
"AcceptedAnswerId": "39294",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T17:31:59.527",
"Id": "38644",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html",
"ajax"
],
"Title": "Compacting jQuery Code for Framebox Plugin"
} | 38644 |
<p>I have some data in a .csv file, which looks roughly like this:</p>
<pre><code>[fragment1, peptide1, gene1, replicate1, replicate2, replicate3]
[fragment1, peptide2, gene1, replicate1, replicate2, replicate3]
[fragment2, peptide1, gene2, replicate1, replicate2, replicate3]
[fragment2, peptide2, gene2, replicate1, r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T15:09:12.050",
"Id": "64586",
"Score": "2",
"body": "FWIW I think your code would be much simpler if rewritten using [`pandas`](http://pandas.pydata.org), and I think its `groupby` facilities would come in very handy."
},
{
... | [
{
"body": "<p>First off, if you want re-usability, you should probably encapsulate this into a function with it's specific arguments.</p>\n\n<p>Also, the general style for naming is <code>snake_case</code> for functions and variables, and <code>PascalCase</code> for classes. You also have some other style issue... | {
"AcceptedAnswerId": "96040",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T17:51:07.460",
"Id": "38646",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"csv",
"numpy"
],
"Title": "Reading columns and rows in a .csv file"
} | 38646 |
<p>Is my below merge sort implementation in O(n log n)? I am trying to implement a solution to find k-th largest element in a given integer list with duplicates with O(N*log(N)) average time complexity in Big-O notation, where N is the number of elements in the list.</p>
<pre><code> public class FindLargest {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T20:24:18.170",
"Id": "64469",
"Score": "0",
"body": "Any reason why are you passing `nthElement` as `String`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T20:26:07.537",
"Id": "64470",
"Sco... | [
{
"body": "<blockquote>\n <p>Is my below merge sort implementation in O(n log n)?</p>\n</blockquote>\n\n<p>No, while your merge sort appears to be a good implementation of the <a href=\"http://en.wikipedia.org/wiki/In-place_merge_sort#Variants\" rel=\"nofollow\">in-place merge sort</a>, that sort has a complex... | {
"AcceptedAnswerId": "39782",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T18:59:22.663",
"Id": "38649",
"Score": "5",
"Tags": [
"java",
"sorting",
"mergesort",
"complexity"
],
"Title": "Is this an efficient merge sort implementation with regards ... | 38649 |
<p>Both <code>Cities</code> and <code>Positions</code> are associated to <code>Jobs</code> through a has_many :through relationship.</p>
<p>On the <code>Jobs#Index</code> page, I have a form, which when submitted allows a user to filter jobs based on a combination of city and positions.</p>
<p>I got this to work, but... | [] | [
{
"body": "<p>In <code>models/job.rb</code>, you can add scopes and use them chained on the controller:</p>\n\n<pre><code>class Job < ActiveRecord::Model\n scope :with_cities, ->(city) { includes(:cities).where(cities: { id: @city }) if city }\n scope :with_positions, ->(position) { includes(:positi... | {
"AcceptedAnswerId": "42820",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T19:22:24.987",
"Id": "38650",
"Score": "5",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Filtering index using has_many through relationships"
} | 38650 |
<p>I'm trying to learn basic algorithms which are typically taught in an introduction to CS course, which is usually taught in a compiled language like Java. However, I want to focus on JavaScript, so I wrote the algorithms in JavaScript and encapsulated them into a library.</p>
<p>I'm looking for feedback on the eff... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-19T23:51:42.367",
"Id": "66456",
"Score": "0",
"body": "new version here - http://codereview.stackexchange.com/questions/39619/a-package-for-sort-algorithms-v2"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-0... | [
{
"body": "<p>Note that <code>isSorted</code> has a bit of an off-by-one error. It will check outside the bounds of its argument. This actually works OK, because it compares the last element of the array to <code>undefined</code> which always results in <code>false</code>. However, you should really only check ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T19:39:24.530",
"Id": "38651",
"Score": "3",
"Tags": [
"javascript",
"optimization",
"algorithm",
"sorting",
"modules"
],
"Title": "A package for sort algorithms"
} | 38651 |
<p>Another try at this problem in LISP. This time rather than generating every possible row combination for the melody I tried to calculate the best combination directly. Unfortunately there's a problem - the output is a messy list full of vectors and single values. Is there a good way to concatenate vectors together w... | [] | [
{
"body": "<p>To concatenate vectors, you can do this:</p>\n\n<pre><code>(apply #'concatenate 'vector \n (mapcar (lambda (x) \n (typecase x \n (vector x) \n (t (vector x))))\n list-of-vectors-or-numbers))\n</code></pre>\n\n<p>PS. Since this... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T22:47:39.707",
"Id": "38657",
"Score": "2",
"Tags": [
"beginner",
"common-lisp"
],
"Title": "Finding optimal row sequence for a melody on 5-row Bayan Accordion, v2.0"
} | 38657 |
<p>I'm writing a small library to do some image-processing on GPU for WinRT, however, I'm not sure if such design breaks SRP.</p>
<p>One class loads and saves image, renders and maintains filters - isn't it too much?</p>
<p><a href="http://pastebin.com/h8iYCmzw" rel="nofollow">Code</a></p>
<pre><code>public class Fi... | [] | [
{
"body": "<p><strong>Private Fields</strong></p>\n\n<p>I prefer to prefix my private fields with an underscore, and as <code>readonly</code> as possible. If you don't like the underscore, fine - but then be consistent with <code>this</code>, and don't use it only in your constructor - use <code>this</code> whe... | {
"AcceptedAnswerId": "38669",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-05T23:14:21.130",
"Id": "38658",
"Score": "5",
"Tags": [
"c#",
"image",
"library"
],
"Title": "Does this image-processing library break the Single Responsibility Principle?"
} | 38658 |
<p>I develop a small game using C# and need A* in it. For that, I need a PriorityQueue, which .NET does not have. I wanted to make my own one for practice. Here is it, please comment on performance and usability:</p>
<pre><code>public class PriorityQueue<T> : IEnumerable
{
List<T> items;
List<in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-11T07:00:47.017",
"Id": "86975",
"Score": "0",
"body": "I am just asking: what is the `IEnumerable` in your code?"
}
] | [
{
"body": "<ol>\n<li><p>According to my understanding <a href=\"http://en.wikipedia.org/wiki/Priority_queue\" rel=\"nofollow\">and wikipedia</a> a priority queue serves items with a higher priority first. Your implementation serves items with a lower priority first by inserting them at the front. I guess it dep... | {
"AcceptedAnswerId": "38683",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T00:47:48.457",
"Id": "38659",
"Score": "3",
"Tags": [
"c#",
"queue"
],
"Title": "Priority Queue in C#"
} | 38659 |
<p>As a learning exercise I wrote a short C program that changes the instructions of a function at runtime in order to execute a shell. It's obviously dependent on x86_64 architecture and Linux (for the syscall number). Indeed, it does start a shell when I run it. I was told to post it here by someone on StackOverflow ... | [] | [
{
"body": "<p>It looks pretty good to me. I can see that a lot of research has gone into this. There are a few things I would fix though.</p>\n\n<ul>\n<li><p>You print \"Calling foo\" right before you call it, which I don't really see a need for since you are printing something that looks like a counter withi... | {
"AcceptedAnswerId": "40223",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T02:20:55.800",
"Id": "38662",
"Score": "8",
"Tags": [
"c",
"linux"
],
"Title": "Self-mutating C (x86_64)"
} | 38662 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.