body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
KTurtle is an Open Source variant of the popular educational application Logo. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-09T20:46:02.260",
"Id": "53835",
"Score": "0",
"Tags": null,
"Title": null
} | 53835 |
<p>For minimalist sake, let's say I have an image of a button in a game and on the screen.
When you left-click the button, it will disappear. If you right-click (anything), the button will reappear.</p>
<p>I'm trying to improve my code, so if you see anything that is redundant or that can be done cleaner, it'd be awes... | [] | [
{
"body": "<p>I would recommend your second thought creating an Visibility Property.</p>\n\n<p>if you need such an property for different classes you could go even further and create an <code>Interface</code> </p>\n\n<pre><code>interface IDrawable\n{\n bool Visible;\n}\n</code></pre>\n\n<p>now you would be a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-09T20:48:42.413",
"Id": "53836",
"Score": "2",
"Tags": [
"c#",
"xna"
],
"Title": "How can I better handle images that I don't need drawn anymore (for now)?"
} | 53836 |
<p>The goal is to convert a hex string to a byte array with the following requirements:</p>
<ul>
<li>\$O(1)\$ additional space apart from input and output.</li>
<li>\$O(n)\$ runtime</li>
</ul>
<p>This mostly just prohibits creating a new string with a 0 prepended to avoid having to deal with odd strings. </p>
<pre><... | [] | [
{
"body": "<p>In situations like this, when dealing with odd-offset values, and byte-manipulation, I recommend four things:</p>\n\n<ol>\n<li>use a logical frame of reference.</li>\n<li>get familiar with bit-wise operations.</li>\n<li>pre-computing results at compile time is very efficient at runtime.</li>\n<li>... | {
"AcceptedAnswerId": "53846",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-09T21:29:18.597",
"Id": "53839",
"Score": "5",
"Tags": [
"c#",
"strings",
"linq",
"converting"
],
"Title": "Convert hex string to byte array"
} | 53839 |
<p>I know prime number programs have been beaten to death. I have been programming for eight years (not that long, but I'm not in my 20s yet and I got a programming job straight out of high school so I'm not doing too shabby). Everyone's first instinct is the "Naive" approach (nested loops, check for divisors), and I w... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-09T21:48:34.713",
"Id": "93669",
"Score": "0",
"body": "Are you familiar with the [Sieve of Atkin](http://en.wikipedia.org/wiki/Sieve_of_Atkin)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T13:05:06.2... | [
{
"body": "<p>For building a list of prime numbers This code is about 25% faster in my tests:</p>\n\n<p>EDIT: Minor point: My research has led me to the conclusion this is based on the Sieve of Sundaram.</p>\n\n<pre><code>public static List<int> ESieve1(int upperLimit)\n{\n\n int sieveBound = (int)(up... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-09T21:36:50.667",
"Id": "53840",
"Score": "5",
"Tags": [
"c#",
"performance",
"primes"
],
"Title": "Prime Number Speed"
} | 53840 |
<p>I have the below code to check for a winner in a Tic Tac Toe game. I'm wondering if this is a good approach, and if there is a better way of doing this (maybe by monitoring the state of the board).</p>
<pre><code>public void CheckWinner()
{
var board = GameBoard.Content;//stores data as dictionary
for (int... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-09T23:47:21.763",
"Id": "93683",
"Score": "0",
"body": "You have an approach to checking TicTacToe winners that I don't think I have seen before. Because of this, I'm not quite sure how `GameBoard.Content` and `winningIndex` are struct... | [
{
"body": "<p>These variable initializations are not very readable nor maintainable as a single line:</p>\n\n<blockquote>\n<pre><code>int a = winningIndex[i, 0], b = winningIndex[i, 1], c = winningIndex[i, 2];\n</code></pre>\n</blockquote>\n\n<p>Have each one on a separate line:</p>\n\n<pre><code>int a = winnin... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-09T22:12:05.613",
"Id": "53841",
"Score": "4",
"Tags": [
"c#",
"game",
"array",
"hash-map"
],
"Title": "Check winner in a Tic Tac Toe game"
} | 53841 |
<p>Below is a script to find cheating students in a quiz in a daily moodle activity log exported in .xls. It works fine and is written in a procedural way.</p>
<p>Essentially the script isolates the activity log entry in a worksheet for students listed in another worksheet, identifies when they are taking a quiz (look... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-09T23:38:59.003",
"Id": "93679",
"Score": "0",
"body": "Since you're logging each step, can you provide a sample log? It would help to be able to see which parts are slow."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>There is quite a bit of code there. I would start with <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a> formatting as it makes it much easier to read. The other thing that came to mind is using <a href=\"https://docs.python.org/3.4/library/collections.html#collec... | {
"AcceptedAnswerId": "53851",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-09T23:17:42.720",
"Id": "53844",
"Score": "9",
"Tags": [
"python",
"performance",
"object-oriented",
"python-2.x",
"excel"
],
"Title": "Script for finding cheating student... | 53844 |
<p>I wanted to use <a href="http://stateless.co/hal_specification.html" rel="nofollow">hal</a> in one of my personal Clojure projects, but unfortunately the only library I could find <a href="https://github.com/cndreisbach/halresource" rel="nofollow">(halresource)</a> was somewhat out of date when compared to the curre... | [] | [
{
"body": "<p>First of all, great idea -- you should consider contributing to the halresource library to bring it up to date!</p>\n\n<p>Here are my critiques:</p>\n\n<h2>Structure of data</h2>\n\n<p>The structure you have chosen to represent links, while truer to their HAL representations, leads to unnecessaril... | {
"AcceptedAnswerId": "55164",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T01:19:46.840",
"Id": "53849",
"Score": "3",
"Tags": [
"json",
"clojure"
],
"Title": "Clojure code for generating HAL JSON responses"
} | 53849 |
<p>I was trying to refactor the following Python code (keeping the same time-complexity) which is an implementation of Z-Algorithm for pattern matching in strings.</p>
<blockquote>
<pre><code>def compute_z(string):
n = len(string)
z = [n]
L = R = 0
for i in xrange(1,n):
if (i > R):
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T03:18:21.640",
"Id": "94072",
"Score": "2",
"body": "FYI, if `g` is only going to be used by `Func`, you can declare it *inside of* `Func`. Also, those are some truly awful function names."
}
] | [
{
"body": "<h2>Bugs</h2>\n\n<ul>\n<li>In your original <code>compute_z()</code>, you fail to <code>return z</code>.</li>\n<li>In your refactored solution, <code>g()</code> has an undefined variable <code>i</code>.</li>\n<li>The correct z-values for <code>'abaab'</code> are <code>[5, 0, 1, 2, 0]</code>, not <cod... | {
"AcceptedAnswerId": "53969",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T03:50:28.520",
"Id": "53852",
"Score": "10",
"Tags": [
"python",
"algorithm",
"strings",
"python-2.x",
"search"
],
"Title": "Z-Algorithm for pattern matching in strings... | 53852 |
<p>I have three lists, and I need to operate on the <code>i</code>th element of each list simultaneously.</p>
<pre><code>private void TripleForEach<T1, T2, T3>(IEnumerable<T1> a1, IEnumerable<T2> a2, IEnumerable<T3> a3, Action<T1, T2, T3> x)
{
a3.Zip(a2, (t3, t2) => Tuple.Create(t2... | [] | [
{
"body": "<p>I agree, the temporary tuples are a code smell. They carry a performance overhead, but worse, they obscure the purpose of the code. Here is a way of achieving the goal by working directly on the enumerators.</p>\n\n<pre><code>private static void TripleForEach<TFirst, TSecond, TThird>(\n ... | {
"AcceptedAnswerId": "53856",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T04:26:29.510",
"Id": "53855",
"Score": "7",
"Tags": [
"c#",
".net",
"linq"
],
"Title": "Combining List<>.ForEach and List<>.Zip"
} | 53855 |
<p>I'm using <code>System.Timers</code> to schedule tasks. I find this working, but I'm not quite sure if it's ok to do it this way. </p>
<pre><code>using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Timers;
using System.IO;
using System.Threading;
namespace WebApplication2
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T13:18:34.317",
"Id": "93984",
"Score": "1",
"body": "The thread that will be running the `timer1_Elapsed()` method will be a background thread and can be terminated in the middle of execution when the `AppDomain` unloads. So, be car... | [
{
"body": "<p>There's no reason to expose <code>timer1</code> as a public member, I would just have a static method <code>DoFoo()</code> that calls <code>timer1.Start()</code>.</p>\n\n<p>There are a few issues with the way you implement you thread passing. With the short interval and the immediate stop it seem... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T05:04:51.237",
"Id": "53857",
"Score": "3",
"Tags": [
"c#",
"asp.net",
"timer"
],
"Title": "Schedule Global Task by using static System.Timers"
} | 53857 |
<p>I'm working on an ASP.Net MVC 5/WebApi 2 project. I'm using EF 6 code first for my database access.</p>
<p>I have a WebApi action method in which I've to update some data in my database based on the request. To correctly update the data it is very important that:</p>
<ol>
<li>The method doesn't change the same rec... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T06:23:05.973",
"Id": "53859",
"Score": "2",
"Tags": [
"c#",
"entity-framework",
"queue",
"concurrency",
"asp.net-mvc-5"
],
"Title": "WebApi synchronize database (EF 6) acc... | 53859 |
<p>I've read a lot of stuff about mixins, inheritance and such, and in the end I came up with this solution for extending a class with multiple mixins. I haven't seen this anywhere else...</p>
<p>Is this a good method? Do you see any problems with it?</p>
<p>What I'm trying to achieve:</p>
<p>I need classes that sha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T14:22:01.663",
"Id": "93776",
"Score": "0",
"body": "I wrote a js framework that has a class system that supports multiple mixins and even compositions. Check it out, it might work for your situation http://github.com/pllee/luc"
... | [
{
"body": "<p>Trying to use JavaScript like a class based language is what you make it. It sounds like someone was expressing an opinion, rather than imperial evidence.</p>\n\n<p>As for your implementation, it's very confusing how you'll expect to use the <code>Objects</code> object. Be very careful with mixins... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T07:08:14.737",
"Id": "53860",
"Score": "2",
"Tags": [
"javascript",
"inheritance",
"extension-methods",
"mixins"
],
"Title": "JavaScript mixins, extending and super methods"
} | 53860 |
<p>I am needing to import a tab delimited text file that has 11 columns and an unknown number of rows (always minimum 3 rows).</p>
<p>I would like to import this text file as an array and be able to call data from it as needed, throughout my project. And then, to make things more difficult, I need to replace items in ... | [] | [
{
"body": "<p>First I'd like to mention a style point. <a href=\"https://stackoverflow.com/q/6035770/3198973\">Ditch the hungarian notation</a>. You don't need it. It often isn't maintained, so they tend to lie. when they are, it's a bit of a pain to find/replace your variable names. <code>sReader</code> should... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T05:17:57.160",
"Id": "53864",
"Score": "2",
"Tags": [
"optimization",
"array",
"vb.net",
"file",
"io"
],
"Title": "Importing tab delimited file into array"
} | 53864 |
<p>Just wanted to ask if there is an other way of PHP coding for displaying my subcategories and subsubcategries than mine.</p>
<p>My tables:</p>
<blockquote>
<pre><code>Categories
-------------------------
cat_ID | cat_name
------------------
4 | Baby & Kids
5 | Bicycles
6 | Boats
7 | Books &... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T10:05:53.293",
"Id": "93722",
"Score": "0",
"body": "Welcome to Code Review! The first part of your question is on-topic (and a good question), but the second part \"What am I doing wrong?\" is not on-topic here. (Hint if I remember... | [
{
"body": "<p>Yes, let's see:</p>\n\n<ul>\n<li>You are vulnerable to <strong><a href=\"http://en.wikipedia.org/wiki/SQL_injection\" rel=\"nofollow noreferrer\">SQL injection</a></strong>: By including variables directly in the query, you are making yourself vulnerable to SQL injection attacks. Use <strong><a hr... | {
"AcceptedAnswerId": "53869",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T08:13:01.180",
"Id": "53865",
"Score": "3",
"Tags": [
"php"
],
"Title": "Displaying categories and subcategories in php having different tables"
} | 53865 |
<p>Searching on Stack Overflow and Google, I find many and many different implementation for Unit-of-Work/Repository patterns, but none of that really convinced me; each had some small defect that prevented me from using it. So I tried to create my own version and would like to know what you think.</p>
<p>Essentially ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-06-25T11:07:30.757",
"Id": "248453",
"Score": "0",
"body": "Is there ever a reason to not call `StartOperation`? Don't create objects in an invalid state. Call it from the constructor."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<h1>Unit of work</h1>\n\n<p>According to Martin Fowler:</p>\n\n<blockquote>\n <p>A Unit of Work keeps track of everything you do during a business\n transaction that can affect the database. When you're done, it figures\n out everything that needs to be done to alter the database as a result\n of... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T08:28:46.343",
"Id": "53867",
"Score": "3",
"Tags": [
"c#",
"design-patterns",
"hibernate",
"repository"
],
"Title": "A flexible unit-of-work + repository pattern"
} | 53867 |
<p>I am wondering about the feasibility of the following basic implementation of a server and how well it would scale. I know that large-scale, distributed servers should probably be written in a language like Erlang, but I'm interested in the viability of the following code "these days".</p>
<p>Other than bugs/issues... | [] | [
{
"body": "<p>First of all, each connection consumes a local port. Therefore, the number of <em>concurrent</em> connection is hard limited by unsigned short, that is 65536 (so millions are out of question). There are also other limitations you may or may not care about.</p>\n\n<p>Second, thread creation is som... | {
"AcceptedAnswerId": "53909",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T10:35:03.553",
"Id": "53871",
"Score": "8",
"Tags": [
"c",
"multithreading",
"server",
"pthreads"
],
"Title": "Scalability of C server implementation based on pthreads"
} | 53871 |
<p>The following is a series of functions to ensure that various elements on a page line up no matter what window size or when the window is resized. However I'm not sure my code is very concise as I am using the same function on three different event handlers. I read that function expressions aren't "hoisted" so I can... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T16:59:56.083",
"Id": "93798",
"Score": "0",
"body": "Hoisting doesn't matter here. You should be able to just do `$(sameHeight); $(window).on(\"resize scroll\", sameHeight);` and done"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<blockquote>\n <p>I read that function expressions aren't \"hoisted\"</p>\n</blockquote>\n\n<p>Yes. See <a href=\"https://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname\">var functionName = function() {} vs function functionName() {}</a>.</p>\n\n<blockquote>\n ... | {
"AcceptedAnswerId": "53916",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T11:18:20.317",
"Id": "53872",
"Score": "0",
"Tags": [
"javascript",
"beginner",
"jquery"
],
"Title": "Aligning page elements with window size"
} | 53872 |
<p>I have this simple code and it is working fine it is self explanatory: the user will choose a random number 10 times and based on the random number the array will be filled by fruits.</p>
<pre><code>var fruit =[];
for( x=0; x<10,x++){
var r = Math.floor(Math.random() * 100 + 1);
choose(r);
}
function ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T18:11:20.907",
"Id": "93821",
"Score": "1",
"body": "I had an answer for your question, which I have now deleted because it missed the core issue in your code, but it raises another question: what should the behaviour be as you 'dep... | [
{
"body": "<p>As long as you re not accessing DOM element in javascript recursion, you will not face serious performance issue. </p>\n\n<p>By your current logic and random number generation, 'grapes' will get wrongly populated sometimes.</p>\n\n<p><code>var fruit = [];</code> is better than <code>var fruit = ne... | {
"AcceptedAnswerId": "53903",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T11:31:39.200",
"Id": "53873",
"Score": "6",
"Tags": [
"javascript",
"performance",
"recursion"
],
"Title": "Get rid of recursion in fruit picker"
} | 53873 |
<p>Here is the solution to generating possible moves and keeping the king safe.
If someone is willing to look it over and come with some suggestion to perhaps improve it, I would appreciate it.</p>
<p>Full source code is at <a href="https://github.com/casz/chess" rel="noreferrer">GitHub</a></p>
<h2>King:</h2>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T11:56:32.217",
"Id": "93736",
"Score": "0",
"body": "Been thinking perhaps a class MoveList where all kind of moves are added where you could have MoveType but I would like to see if already existing code could be used."
},
{
... | [
{
"body": "<p>It's a good start. Now comes reality.</p>\n\n<p>The moves you missed are castling, en passant, and promoting a pawn. Also, you can't move a piece out of the way that is pinned to your king (in some cases, you can move it as long as it continues to block the check). If the king is already in che... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T11:54:52.057",
"Id": "53875",
"Score": "10",
"Tags": [
"java",
"chess"
],
"Title": "Generating possible Chess moves"
} | 53875 |
<p>I was cleaning up my code when I came across this situation :</p>
<pre><code>var a = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
var count = 1;
var html = '';
for (var i = 0; i < a.length; i++) {
var rowStart = '<div class="row">';
var cell = '<div class="c">';
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T12:43:44.680",
"Id": "93740",
"Score": "0",
"body": "What kind of browser support do you need?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T13:10:07.643",
"Id": "93746",
"Score": "0",
"... | [
{
"body": "<p>It sounds like you want a <a href=\"http://garann.github.io/template-chooser/\" rel=\"nofollow\">JavaScript Template Engine</a> to render raw data into HTML. JavaScript template engines also pair well with a view resolver like <a href=\"https://github.com/gburghardt/bloodhound\" rel=\"nofollow\">B... | {
"AcceptedAnswerId": "53884",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T11:58:03.693",
"Id": "53876",
"Score": "7",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Cleanup code to add div structure to element"
} | 53876 |
<p>I work with a legacy application. This is my attempt to add some sanity in an new feature I want to add.</p>
<p>It's a social application with users, sessions etc. The entire application is run in a procedural fashion. It still uses MySQL, so once this feature is complete, upgrading to PDO will be my next project. ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T13:34:45.867",
"Id": "93761",
"Score": "0",
"body": "found some great tips here http://codereview.stackexchange.com/questions/15825/help-improve-my-first-php-class, Ill keep this post up in case someone wants to review it"
}
] | [
{
"body": "<p>Yes, you are most certainly on the right path, and as a first step, it's very good. Some pointers for the future.</p>\n\n<ul>\n<li><strong>Don't use <code>mysql_*</code></strong> - I know you said you're already planning to. I'm mainly saying this for future users.</li>\n<li><strong>Objects work b... | {
"AcceptedAnswerId": "53889",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T13:23:12.080",
"Id": "53885",
"Score": "5",
"Tags": [
"php",
"object-oriented"
],
"Title": "Social application with users and sessions"
} | 53885 |
<p>I am working on a personal project for managing my bookmarks, which is basically a web page to manage my bookmarks by categories. Managing here means everything - adding, viewing, updating, searching by categories, adding new categories. </p>
<p>As can be guessed there is need of AJAX and JavaScript. I have a JavaS... | [] | [
{
"body": "<h2>The Good</h2>\n\n<ul>\n<li>Naming conventions seem to be consistent</li>\n<li>The programming pattern seems to be consistent</li>\n</ul>\n\n<p>Basically, the code just looks consistently written. That being said, it's not really organized.</p>\n\n<h2>The Bad</h2>\n\n<ul>\n<li>All variables are gl... | {
"AcceptedAnswerId": "53901",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T14:52:30.427",
"Id": "53896",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "Personal project for managing my bookmarks"
} | 53896 |
<pre><code>private void merge(ArrayList<String> operations, ArrayList<LinkedHashSet<String>> setOfStrings) {
String toMerge = operations.get(1);
String fromMerge = operations.get(2);
boolean enteredFirstToMerge = false;
boolean enteredFirstForMerge = false;
// r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T20:55:25.347",
"Id": "93870",
"Score": "0",
"body": "The number one problem with your code is the formatting. Fix that and you're half done."
}
] | [
{
"body": "<ul>\n<li><p>Abstract as much as possible over type: <code>List</code> instead of <code>ArrayList</code>. </p></li>\n<li><p>Use OO where appropriate: <code>List<String> operations</code> should clearly be some\n<code>class MoveOperation(String to, String from)</code>.</p></li>\n<li><p>It's no... | {
"AcceptedAnswerId": "53925",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T16:17:14.430",
"Id": "53899",
"Score": "3",
"Tags": [
"java",
"performance"
],
"Title": "Merging key-value sets as specified by a command"
} | 53899 |
<p>I created a simple number-guessing game. Do I need to divide this program into functions? Please offer suggestions.</p>
<pre><code>#include<iostream>
#include<string>
#include<ctime>
void drawLine(int n, char symbol);
void rules();
int main()
{
int amount;
int bettingAmount;
int gu... | [] | [
{
"body": "<p>Yes, you should divide this into functions. Right now you just have two functions that print lines and such to the screen, which aren't too useful in my opinion. Other than that, <code>main()</code> <em>is</em> doing most of the work, so having additional functions is a good idea.</p>\n\n<p>You ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T17:15:31.120",
"Id": "53902",
"Score": "4",
"Tags": [
"c++",
"game",
"random",
"dice",
"number-guessing-game"
],
"Title": "Number-guessing game in C++"
} | 53902 |
<p>Is this code good practice? What kind of design pattern should I use for this specific situation?</p>
<p>The following function creates a new marker on a map. It sets a new image for it, <em>except when the marker references the user location</em>.</p>
<pre><code>$scope.addMarker = function (lat, lng, isUserLocati... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>I haven't found an obvious best way to do this.</p>\n\n<p>For sure, sending <code>true</code> as a parameter should always be avoided, I'd rather see</p>\n\n<pre><code>var IS_USER_LOCATION = true;\n$scope.addMarker(position.coords.latitude, position.coords.longitude... | {
"AcceptedAnswerId": "59263",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T17:48:03.710",
"Id": "53906",
"Score": "2",
"Tags": [
"javascript",
"design-patterns",
"angular.js"
],
"Title": "Creating a new marker on a map"
} | 53906 |
<p>I've recently started programming (learning Ruby) and wrote a small game. Now I've started reading about MVC and am trying to refracture my code to follow that architecture. The only classes with big changes so far are the intended controller and view (which is completely temporary.</p>
<pre><code># This file will ... | [] | [
{
"body": "<p>This is a little abstract, without much actual code, but perhaps it's useful nonetheless.</p>\n\n<p>A game is actually a little tough to apply \"stringent\" MVC to. It's not quite clear cut what belongs where. The world is obviously a model, resources are obviously models, and tiles are too. But i... | {
"AcceptedAnswerId": "58565",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T17:57:55.683",
"Id": "53907",
"Score": "4",
"Tags": [
"beginner",
"ruby",
"game",
"mvc"
],
"Title": "Writing an MVC project for the first time - how close am I?"
} | 53907 |
<p>In MVP pattern we can use DI when our presenter classes need services as follows:</p>
<pre><code>class APresenter
{
Public Presenter(DataService dataService, PermissionService permissionService)
{
//
}
// can use services injected through parameter...
}
</code></pre>
<p>As my all most all ... | [] | [
{
"body": "<p>I would prefer the first one with constructor parameters primarily because of two reasons.</p>\n\n<p>First, it's easier to test, you are able to pass mocked or dummy services directly to the constructor.</p>\n\n<blockquote>\n <p>Good design is testable, and design that isn't testable is bad.</p>\... | {
"AcceptedAnswerId": "53918",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T18:21:54.777",
"Id": "53910",
"Score": "1",
"Tags": [
"c#",
".net",
"dependency-injection",
"mvp"
],
"Title": "Inheritance or DI in Presenter classes in MVP"
} | 53910 |
<p>I have a script that matches a string against ~20 different regexs for the purpose of changing it. They are ordered and formed that the string will only ever match against one. How can I avoid checking all the <code>str.replace</code>s after I match once?</p>
<p>My code here works, but I repeat myself a lot and it ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T19:15:21.823",
"Id": "93837",
"Score": "0",
"body": "When is `checked` set to `true`? Why is this an infinite loop at all?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T19:42:27.080",
"Id": "938... | [
{
"body": "<p>This seems to be a fine case for a loop over the expressions:</p>\n\n<pre><code>function format_input(input) {\n // decouple DOM things from pure functionality!\n input.value = format_number(input.value);\n}\nfunction format_number(str) {\n var replacements = [\n [/regex1/, 'replac... | {
"AcceptedAnswerId": "53920",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T19:01:00.400",
"Id": "53911",
"Score": "3",
"Tags": [
"javascript",
"strings",
"regex"
],
"Title": "Breaking after one of several string replaces occur"
} | 53911 |
<p>I have a simple strategy game, and I implemented a simple counter object to count down a number whenever the game ticks. I have heard about something called NSTimer but I haven't messed with it at all yet. I have also heard that you should use Core Animations to move objects around when rendering rather than a tic... | [] | [
{
"body": "<p>There's one style issue I want to address, and then I'll talk bigger picture.</p>\n\n<p>This comment may turn irrelevant in this specific case, because bigger picture, the better option is probably going to be to use <code>NSTimer</code>, and I'll go over some samples of how to use that, but this ... | {
"AcceptedAnswerId": "54032",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T19:31:20.330",
"Id": "53915",
"Score": "6",
"Tags": [
"game",
"objective-c",
"timer"
],
"Title": "Simple timer class for game model"
} | 53915 |
<p>The code takes in a hash that comes from a webform and also works with product data from the database. It then uses an eBay gem I built that connects with the eBay API and then returns a response object that you can call <code>#extract</code> on to return desired data. <code>#extract</code> takes an optional argumen... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T06:11:36.953",
"Id": "106065",
"Score": "0",
"body": "I recommend using [`map`](http://ruby-doc.org/core-2.1.2/Enumerable.html#method-i-map) and [`select`](http://ruby-doc.org/core-2.1.2/Enumerable.html#method-i-select) to replace s... | [
{
"body": "<p>Since you are sub-classing <a href=\"http://api.rubyonrails.org/classes/ActiveModel/Model.html\" rel=\"nofollow\"><code>ActiveModel::Model</code></a> you can use\nyou can use its ability to \"magically\" map an input hash to attributes:</p>\n\n<pre><code>def initialize(form={})\n super # magic!... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T20:04:12.637",
"Id": "53919",
"Score": "5",
"Tags": [
"ruby",
"ebay"
],
"Title": "Requesting product data from an eBay webform"
} | 53919 |
<h1>Description</h1>
<p>This is the common code for all my <a href="http://www.zomis.net/cards/" rel="nofollow noreferrer">Card Game projects</a>. It is intended to be very flexible. This is related to the recent <a href="https://codereview.meta.stackexchange.com/questions/1600/code-challenge-2/1608#1608">Community Ch... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T22:11:11.623",
"Id": "93919",
"Score": "0",
"body": "I only looked at it briefly, but it seems very complex for a library for card games. I don't think I would use it if I were to write a card game. I would rather write everything f... | [
{
"body": "<p>I like that you've factored out the idea of the CardModel being separate from the instances of the cards.</p>\n\n<p>It's not at all clear to me why CardModel is trying to support Comparable. The ordering of cards is going to vary with the game that is being played, and even within the game, so I'... | {
"AcceptedAnswerId": "54001",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T20:14:42.927",
"Id": "53921",
"Score": "15",
"Tags": [
"java",
"community-challenge"
],
"Title": "Zones and Cards"
} | 53921 |
<p>I came across the question about <a href="https://stackoverflow.com/questions/19999888/how-to-create-a-memory-efficient-ruby-pipe-class-with-lazy-evaluation/20051293#comment37233276_20051293">creating memory-efficient Ruby pipe class with lazy evaluation.</a> Some code is given to effectively create a pipeline of co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-10-15T20:08:43.617",
"Id": "121702",
"Score": "0",
"body": "Is there a reason you don't call `Enumerator#lazy` in the `pipe` or `tee` methods when you do in all of the others?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>I know it's an old question, but it's an interesting one.</p>\n\n<p>First, a couple small things:</p>\n\n<ol>\n<li><p>In <code>Pipe#run</code>:</p>\n\n<pre><code>enum = method(command).call(enum, options)\n</code></pre>\n\n<p>Calling <code>method</code> has a lot of overhead, and <code>send(comman... | {
"AcceptedAnswerId": "66806",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T21:57:20.160",
"Id": "53928",
"Score": "8",
"Tags": [
"ruby",
"io"
],
"Title": "How to create a 'tee' command in Ruby for a Unix like pipeline?"
} | 53928 |
<p>I'm looking for a review of my Connect4 game board. If there is anything I can do better, easier, shorter, etc., please let me know! If you need to see other files for the game, let me know as well.</p>
<pre><code>var players = {};
var outOfTime;
$(document).ready(function() {
// Game variables.
var board,
... | [] | [
{
"body": "<p>JSLint/JSHint has helped me a lot.</p>\n\n<p>JSLint may seem strange at first, but it helps you to write a code that has a architectural advantage from many different angles.</p>\n\n<p>Main reason why JSLint and JSHint are so widely used is to uglify/minify your JavaScript code later as it prepare... | {
"AcceptedAnswerId": "54549",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T22:24:37.610",
"Id": "53930",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"game"
],
"Title": "Connect4 Game Board"
} | 53930 |
<p>I want to take user input strings and add them together with proper spacing.</p>
<p><strong>HTML:</strong></p>
<pre><code><head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="script.js"><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T16:42:31.117",
"Id": "94028",
"Score": "0",
"body": "If my current answer doesn't suffice then could you please elaborate further on what you're after, I might've misunderstood you."
}
] | [
{
"body": "<p>If I'm not misunderstanding the intent of your script you don't need the if elses at all.</p>\n\n<p>For starters not having a space to trim when calling trim(Right or Left) is not a problem. No errors are thrown. So you could just do this:</p>\n\n<pre><code>function addWords() {\n var value = $... | {
"AcceptedAnswerId": "53943",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T23:05:56.000",
"Id": "53934",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"strings"
],
"Title": "Removing extra spaces from user input"
} | 53934 |
<p>I've asked a question about <a href="https://codereview.stackexchange.com/q/29805/27623">pinging a URL before</a>, but I wanted something that was a bit shorter and still just as efficient. <a href="http://curl.haxx.se/libcurl/" rel="nofollow noreferrer">libcurl</a> seemed to be the perfect answer. Here is my meth... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T04:19:15.350",
"Id": "93918",
"Score": "2",
"body": "You might be testing whether you're in a country that blocks Google from time to time for political reasons."
}
] | [
{
"body": "<p>Unless you're using C89, I would define variables where they are used (I'm looking at <code>curl</code>).</p>\n\n<hr>\n\n<p><code>0</code> is currently interpreted as <code>CURLE_OK</code>. This means that if cURL fails to initialize, you're returning a success code. That's probably not what you m... | {
"AcceptedAnswerId": "53941",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T23:33:57.460",
"Id": "53938",
"Score": "9",
"Tags": [
"performance",
"c",
"curl"
],
"Title": "Pinging a URL with libcurl"
} | 53938 |
<p>I have a plugin that grabs the coordinates of all the cities in our database working in WordPress here.</p>
<pre><code>function findCoordinates($address) {
$latitude = null;
$longitude = null;
if (!is_string($address)) {
throw new InvalidArgumentException("Address must be a string");
}
$url = 'http://maps.goo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T13:17:30.097",
"Id": "93983",
"Score": "0",
"body": "The function `Coordinates_admin()` ends abruptly in your sample code... Also, it's best if you indent the code nicely, it's difficult to parse it this way... What exactly is the d... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T00:08:54.353",
"Id": "53942",
"Score": "2",
"Tags": [
"php",
"plugin",
"wordpress",
"geospatial"
],
"Title": "Plugin that grabs the coordinates of all the cities in our databa... | 53942 |
<p>This is an app that I started on a while back to get digging into Rails. It's grown and is now a functioning app. However, the user model is now over 200 lines long. I would love your opinion on how to clean this up.</p>
<pre><code># == Schema Information
#
# Table name: users
#
# id :integer ... | [] | [
{
"body": "<p>A few tips that come into my mind:</p>\n\n<ol>\n<li><p>Extract <a href=\"https://github.com/sunspot/sunspot/wiki/Setting-up-classes-for-search-and-indexing\" rel=\"nofollow noreferrer\">Sunspot</a> search logic to a separate class. It's not really a user's concern.</p></li>\n<li><p>Inline some sco... | {
"AcceptedAnswerId": "53963",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T01:32:29.903",
"Id": "53944",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails",
"active-record"
],
"Title": "Rails User Model"
} | 53944 |
<p>This code stores the last know location in the session. The location is not stored if it is one of the exceptions in the <code>if</code> statement. </p>
<pre><code>def store_location
if request.fullpath != '/users/sign_in' &&
request.fullpath != '/users/sign_up' &&
request.fullpath != ... | [] | [
{
"body": "<p>this is already simple, it follows Devise wiki: <a href=\"https://github.com/plataformatec/devise/wiki/How-To%3a-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update\" rel=\"nofollow\">https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T05:54:51.913",
"Id": "53950",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Store location with some excluded path"
} | 53950 |
<p>I have a text parser that reads certain information from a given file with a specified format. The text file contains some measured properties of a product. The date model number/lot number is written on the file name.</p>
<pre><code>class SomeTextFileParser
{
private static int POINT_COUNT = 15;
string fi... | [] | [
{
"body": "<p>Some notes:</p>\n\n<ul>\n<li><p><code>POINT_COUNT</code> can be a const.</p></li>\n<li><p>Avoid magic numbers, e.g. in <code>POINT_COUNT + 7</code>.</p></li>\n<li><p>Don't catch <code>Exception</code>. Catch only the exceptions that you know how to handle.</p></li>\n<li><p>Don't call <code>File.Ex... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T06:17:14.020",
"Id": "53951",
"Score": "4",
"Tags": [
"c#",
".net",
"parsing"
],
"Title": "Text parser code elegance"
} | 53951 |
<p>I was working on a project that need to remove extra data such that the remains are not "too close" to each other, and the algorithm should be as generalize as possible. To have more general usage, I try to write in std format.</p>
<p>I'm not sure if the algorithm is the best way to accomplish the goal, or if the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T07:05:22.440",
"Id": "93930",
"Score": "0",
"body": "This code does not compile for C++11: http://ideone.com/Chs3Gu"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T07:16:36.520",
"Id": "93932",
... | [
{
"body": "<p>In all, there's not much to complain about, but I did find a few things that might be improved. All of my comments and testing are about C++11 mode, since that's what I have conveniently available.</p>\n\n<h2>Use <code>const</code> references for the predicate</h2>\n\n<p>Right now, the lambda in y... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T06:44:26.367",
"Id": "53953",
"Score": "7",
"Tags": [
"c++",
"c++11"
],
"Title": "Sequentially remove members \"repelled\" by previous members"
} | 53953 |
<p>I needed to write a settings class for my web app; ideally this class should read its settings from a file (and be able to save them back to the file), and have only 1 instance per application - all threads read the same object, so that the settings only need to be loaded from the file when the app runs for the firs... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T11:17:34.637",
"Id": "93946",
"Score": "0",
"body": "Welcome to Code Review! Here, receive an up-vote as a thank you for apparently understanding what we are about!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | [
{
"body": "<p>Small issues:</p>\n\n<ul>\n<li>Personally I'd indent things in between by curly braces</li>\n<li>I'd use <code>string.Empty</code> instead of <code>\"\"</code></li>\n<li>I'd probably put my default public properties before my custom ones</li>\n</ul>\n\n<p>As a higher level question, do you need to... | {
"AcceptedAnswerId": "53959",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T07:43:55.740",
"Id": "53957",
"Score": "4",
"Tags": [
"c#",
"mvc"
],
"Title": "Settings class for web app"
} | 53957 |
<p>I'm pretty new to microcontrollers and C in general, so I thought asking here would be a good way not to get started with bad habits.</p>
<pre><code>/*
* ringbuffer.h
*
* Created on: Jun 11, 2014
* Author: Silly Freak
*/
#ifndef RINGBUFFER_H_
#define RINGBUFFER_H_
//for size_t
//TODO is it a good idea ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T03:33:12.913",
"Id": "94316",
"Score": "0",
"body": "1) Consider `size_t head, tail, length;`. Then no need for `%` operator. 2) interrupt protect operations on these fields."
}
] | [
{
"body": "<p>As for your <code>TODO</code> related question, yes, absolutely, if you use <code>size_t</code> as part of your code's interface, you should <code>#include</code> the relevant definition for it, so what you've got is correct as it stands. However, there are some things here that I think could be ... | {
"AcceptedAnswerId": "53986",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T09:00:05.497",
"Id": "53962",
"Score": "5",
"Tags": [
"c",
"beginner",
"circular-list"
],
"Title": "Microcontroller ringbuffer"
} | 53962 |
<p>I'm currently learning some jQuery and I am stuck on something. On a small exercise I did, I was asked to perform an action when you mouseover a div class. I gave a different solution than the one suggested and I was wondering which one is written best and why.</p>
<p>HTML code</p>
<pre><code><tr id ='user_1' ... | [] | [
{
"body": "<p>Yours is simpler and therefore better. However, I would simplify it further as:</p>\n\n<pre><code>$('.success').on('mouseover', function() {\n $(this).removeClass('success').addClass('delete');\n});\n</code></pre>\n\n<p>Is shouldn't matter much whether you call <code>.addClass()</code> first o... | {
"AcceptedAnswerId": "53971",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T09:33:26.173",
"Id": "53966",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"event-handling",
"comparative-review"
],
"Title": "Which mouseover handler is better?"
} | 53966 |
<p>I've written some code to calculate how many <a href="http://en.wikipedia.org/wiki/Pomodoro_Technique" rel="nofollow noreferrer">Pomodori</a> can fit into a period of time, including long and short breaks. I'm looking for alternative solutions because what I have at the moment doesn't feel right. I think I'm missing... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T15:16:29.700",
"Id": "94003",
"Score": "3",
"body": "Just FYI, in your table your short breaks are currently 5 seconds long (00:05)... \"I move away from the microphone to breathe in\""
},
{
"ContentLicense": "CC BY-SA 3.0"... | [
{
"body": "<p>I think it would be simpler just to apply some ingenuity and partially unroll the loop. While it's possible to fit in a long cycle (pomodoro, short break, pomodoro, short break, pomodoro, short break, pomodoro, long break) with time left over, then do that. While it's possible to fit in a short ... | {
"AcceptedAnswerId": "53976",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T10:26:07.490",
"Id": "53970",
"Score": "9",
"Tags": [
"python",
"algorithm",
"datetime"
],
"Title": "Calculating how many Pomodori fit into a period of time"
} | 53970 |
<p>I have a list of words (with repetitions), and I intend to find out the longest words amongst them, along with their length. My question is to know if my implementation is too verbose, is using too many operators/functions and if so, what are the better, more idiomatic, readable alternatives.</p>
<p>Given the list ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T11:30:19.377",
"Id": "93948",
"Score": "1",
"body": "Does your example word list consist of string literals?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T20:12:30.083",
"Id": "94058",
"Scor... | [
{
"body": "<p>Whenever I only use the extracted value once in a simple group / map / sortBy monadic operations I use the <code>_</code> placeholders. I think it makes the code a little more compact and readable, especially if it was just a placeholder value like <code>x</code></p>\n\n<p><code>.groupBy(x => ... | {
"AcceptedAnswerId": "54450",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T11:01:46.037",
"Id": "53972",
"Score": "4",
"Tags": [
"scala",
"collections"
],
"Title": "Finding the longest word from a list of words"
} | 53972 |
<pre><code>def is_prime(n):
if n % 2 == 0 and n > 2:
return False
return all(n % i for i in xrange(3, int(math.sqrt(n)) + 1, 2))
</code></pre>
<p>The code works fine for a range of numbers after that it shows:</p>
<pre><code>OverflowError: Python int too large to convert to C long
</code></pre>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T12:03:47.513",
"Id": "93953",
"Score": "3",
"body": "Since the overflow happens only for very large _n_, I don't consider this to be broken code for the purpose of determining whether this question is on-topic."
},
{
"Conten... | [
{
"body": "<p>On a 64-bit CPython 2.x,</p>\n\n<pre><code>all(i for i in xrange(2**63 - 1))\n</code></pre>\n\n<p>works, but</p>\n\n<pre><code>all(i for i in xrange(2**63))\n</code></pre>\n\n<p>overflows. See this <a href=\"https://stackoverflow.com/a/2129017/1157100\">explanation</a>, and a <a href=\"https://st... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T11:45:47.987",
"Id": "53975",
"Score": "4",
"Tags": [
"python",
"primes",
"python-2.x"
],
"Title": "Checking for Prime Numbers"
} | 53975 |
<p>I'm handling user permission in a MVP Winforms application as follows. Here I'll give a full detail of my code as it will be helpful when answering to this question.</p>
<p>My user model has a list called <code>permissions</code> which holds the permissions of the current user.
(eg: <code>CAN_EDIT_ACCOUNT</code>)</... | [] | [
{
"body": "<p>I am looking at this Method</p>\n\n<blockquote>\n<pre><code> private void ValidatePassword()\n {\n var hash = Encryption.GetHash(_LoginView.UserID, _LoginView.Password);\n var user = _DataService.GetPermissions(_DataService.GetUser(_LoginView.UserID));\n if (user != null... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T12:42:21.913",
"Id": "53979",
"Score": "4",
"Tags": [
"c#",
".net",
"dependency-injection",
"mvp"
],
"Title": "Using a UserPermissionService by all Presenters in the Applicati... | 53979 |
<p>I created this class which supposed to take a method and try to execute it. If it fails lets say 10 times, it will throw the original exception thrown by the delegate.</p>
<p>Do you have any ideas for improvement about that code?</p>
<p>I am particularly interested, in where to put this code. Right now it is withi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T12:53:05.493",
"Id": "93974",
"Score": "0",
"body": "@derape side note - I don't think creating assembly for single class is a good idea"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T12:54:07.090",
... | [
{
"body": "<h1>Assemblies and naming</h1>\n\n<p>Assemblies are units of deployment -- you should put this code in the assembly it's being used in; don't over-think it. Use namespaces, not assemblies, for logical partitioning of code, and don't create a new assembly just because some code may be used elsewhere. ... | {
"AcceptedAnswerId": "53984",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T12:44:18.493",
"Id": "53980",
"Score": "6",
"Tags": [
"c#",
"delegates"
],
"Title": "Retry logic for delegates"
} | 53980 |
<p>I have the following structure for my object:</p>
<p><strong>Word (Object)</strong></p>
<ul>
<li><code>Word</code> (String)</li>
<li><code>List<Symbol></code></li>
</ul>
<p><strong>Symbol (Object)</strong></p>
<ul>
<li><code>Symbol</code> (String)</li>
<li><code>List<SymbolChoice></code></li>
</ul>
... | [] | [
{
"body": "<p>This is probably a bug:</p>\n\n<blockquote>\n<pre><code> if (getSymbols().size() <= 1) {\n return new ArrayList<List<SymbolChoice>>();\n }\n</code></pre>\n</blockquote>\n\n<p>should be <code>isEmpty()</code>.... not <code><= 1</code>.</p>\n\n<p>As for your algorithm, you a... | {
"AcceptedAnswerId": "53988",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T13:28:27.873",
"Id": "53981",
"Score": "7",
"Tags": [
"java",
"regex",
"performance"
],
"Title": "Check whether a list of list of string fits a regex efficiently"
} | 53981 |
<p>What can I do to improve this function, which calculates the <a href="http://www.eloratings.net/system.html">win expectancy</a> of a soccer team, given their strength:</p>
<pre><code>def winning_prob(first, second, first_at_home=False, second_at_home=False):
""" Return winning probability, given ELO ratings of ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T13:47:23.627",
"Id": "93989",
"Score": "0",
"body": "Are `first_at_home` and `second_at_home` mutually exclusive?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T13:49:40.990",
"Id": "93990",
... | [
{
"body": "<p>With the possibility of <code>first_at_home</code> and <code>second_at_home</code> both being <code>True</code>, there really is not too much to improve on here.</p>\n\n<p>The only things I see are:</p>\n\n<ol>\n<li>Instead of doing <code>first = first + 100</code>, you can do <code>first += 100</... | {
"AcceptedAnswerId": "53985",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T13:46:18.660",
"Id": "53982",
"Score": "6",
"Tags": [
"python"
],
"Title": "Soccer winning probabilies from ELO strength indicator"
} | 53982 |
<p>I got the inspiration to write this algorithm from <a href="https://codereview.stackexchange.com/questions/53975/checking-for-prime-numbers">this question</a>. The OP cited the <a href="http://en.wikipedia.org/wiki/Sieve_of_Atkin" rel="nofollow noreferrer">Sieve of Atkin</a> as one of the fastest ways to generate pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T15:38:45.187",
"Id": "94016",
"Score": "0",
"body": "You might find some interesting information on [my question.](http://codereview.stackexchange.com/questions/53840/c-prime-number-speed). THere is a sieve of erasthones and atkins ... | [
{
"body": "<pre><code>for x, y in [(x,y) for x in loop_range for y in loop_range]:\n</code></pre>\n\n<p>Here you could avoid the list creation by using a generator (by changing the <code>[]</code> to <code>()</code>) or you could use <code>itertools.product</code>. Probably no difference performance-wise, but t... | {
"AcceptedAnswerId": "54008",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T14:58:19.710",
"Id": "53990",
"Score": "12",
"Tags": [
"python",
"optimization",
"algorithm",
"primes"
],
"Title": "Sieve of Atkins algorithm"
} | 53990 |
<p>I was going to post this code as an answer to a recent question, but I wrote this code a little while ago (like, a year ago; if I recall correctly I wrote this after reading <a href="http://timross.wordpress.com/2008/02/10/implementing-the-circuit-breaker-pattern-in-c/">this article</a>) and I'd like to get some fee... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T16:05:23.277",
"Id": "94022",
"Score": "1",
"body": "Why does `ICircuitBreaker` include methods like `ToClosedState()`? Shouldn't those be internal to the implementation? When would a user ever call those?"
},
{
"ContentLice... | [
{
"body": "<p><strong>Style/Readability</strong></p>\n\n<ul>\n<li><p>Unnecessary XML comments. For example:</p>\n\n<pre><code>/// <summary>\n/// Gets the failure count.\n/// </summary>\n/// <value>\n/// The failure count.\n/// </value>\npublic int FailCount { get { return _failCount; } }... | {
"AcceptedAnswerId": "54031",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T15:00:13.110",
"Id": "53991",
"Score": "10",
"Tags": [
"c#",
"thread-safety",
"exception-handling",
"dependency-injection"
],
"Title": "Will this Circuit Breaker catch fire... | 53991 |
<p>This servlet takes an input from the user and</p>
<ul>
<li>Stores the number inside the bean but with spaces in between each digit then stores the bean in the request scope.</li>
<li>If the last digit is even, sums the numbers and stores it in the request attribute. It will be displayed by even.jsp. Otherwise, the ... | [] | [
{
"body": "<p>I am not aware of how to improve the code so that it will be shorter. What I would suggest is that this code can be improved in terms of clarity of intent (in this case, the LOCs will increase). This can be achieved by using small functions and good names for the functions (for more information lo... | {
"AcceptedAnswerId": "54003",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T15:25:28.327",
"Id": "53993",
"Score": "10",
"Tags": [
"java",
"servlets"
],
"Title": "Simple servlet code to sum digits"
} | 53993 |
<p>This is some boilerplate I found myself writing on a new abstract class. It seems ripe for refactoring, but I'm not sure the best way to implement it more effectively. Is there a pattern for these sort of time-stamping/status-updating methods?</p>
<pre><code>def create() {
tsCreated = new DateTime()
userCre... | [] | [
{
"body": "<p>No idea about groovy, but it looks like a case for an <code>EnumMap<RequestStatus, Data></code> with the map storing the (last) corresponding time and user. You need a single method</p>\n\n<pre><code>def action(RequestStatus status) {\n map.put(status, new Data(new DateTime(), springSecur... | {
"AcceptedAnswerId": "53996",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T15:45:50.037",
"Id": "53995",
"Score": "5",
"Tags": [
"groovy",
"grails"
],
"Title": "Avoiding repetitive code for timestamping and updating status"
} | 53995 |
<p>I am a beginner at programming. I was able to build the thing below, which achieves what I want with a small dataset. With larger datasets, my RAM gets swamped bringing the computer to a halt (2014 Macbook Pro with 16GB RAM). Can I simplify my process somehow?</p>
<pre><code># This code starts from a co-occurrence ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T16:37:53.650",
"Id": "94026",
"Score": "5",
"body": "Just a friendly comment to say this is an excellent well-presented question! Hope you'll have good reviews!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "20... | [
{
"body": "<p>What I like</p>\n\n<ul>\n<li>Comments at the beginning describing what the code should do</li>\n<li>Variable names that are easy to read</li>\n<li>constants are put one place (<code>timewindow = 7</code>) so they are easy to understand and modify</li>\n</ul>\n\n<p>What I didn't like</p>\n\n<ul>\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T16:28:31.477",
"Id": "53998",
"Score": "11",
"Tags": [
"python",
"performance",
"beginner",
"pandas"
],
"Title": "Simplifying Python Pandas code for selecting co-occurrences i... | 53998 |
<p>I was bothered by inability of C++ to mix <code>cout</code> and <code>wcout</code> in the same program - so I've found this question:</p>
<p><a href="https://codereview.stackexchange.com/questions/419/converting-between-stdwstring-and-stdstring">Converting between std::wstring and std::string</a></p>
<p>It didn't ... | [] | [
{
"body": "<ul>\n<li><p><code>ssize_t</code> is essentially unsigned; that is, the comparison <code>res >= 0</code> is always true.</p>\n\n<p>The test should be</p>\n\n<pre><code>res != static_cast<std::size_t>(-1)\n</code></pre></li>\n<li><p><code><cstdlib></code> and <code><cwchar></code>... | {
"AcceptedAnswerId": "54013",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T16:56:57.750",
"Id": "54000",
"Score": "3",
"Tags": [
"c++",
"strings",
"converting",
"linux"
],
"Title": "Converting from std::wstring to std::string in Linux"
} | 54000 |
<p>This code horrifies and scares me. <em>I wrote this.</em></p>
<pre><code>public IQueryable<StudentTrack> StudentTracks(int employeeId)
{
IQueryable<StudentTrack> EducationPortalStudentTracks =
from studentTrack in _dbContext.EducationPortalStudentTracks
join track in _dbContext.Educ... | [] | [
{
"body": "<p>Break it down into more methods. <code>StudentTracks</code> has multiple responsibilities, you could <em>extract a private method</em> whose job would be to <code>CalculatePercentCompletion(studentTrack)</code>, making your method look like this:</p>\n\n<pre><code>public IQueryable<StudentTrack... | {
"AcceptedAnswerId": "54010",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T17:45:17.727",
"Id": "54004",
"Score": "5",
"Tags": [
"c#",
"linq",
"mvc"
],
"Title": "Nested LINQ Nightmare, calculating %completed"
} | 54004 |
<p>I am currently developing a puzzle game that has sequence numbers. The player has to fill the grid with sequence numbers in ascending order. Starting from <code>1</code> the player can move horizontally or across and can skip a square in between if it is empty or blocked.</p>
<p>To generate the puzzle automatically... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T10:00:47.310",
"Id": "94535",
"Score": "0",
"body": "Please confirm, that you want an optimized algorithm. And not just optimizing execution time, memory usage or best practices on coding."
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>I've dug into the concept a little bit and as a start here are some bits of code and discussion to help out. Obviously, the real meat here is doing the backtracking efficiently but I think starting with simplifying the problem a bit would help.</p>\n\n<p>For starters, it seems that turning the gri... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T17:46:36.863",
"Id": "54005",
"Score": "8",
"Tags": [
"php",
"optimization",
"algorithm",
"game"
],
"Title": "Optimizing puzzle game involving sequence numbers"
} | 54005 |
<p>I written this code to search 'blob' items (text files) on the basis of their content. For example, if I search for "Good", then the names of files that contain "Good" or "good" should appear in the search result.</p>
<p>My code is working but I want to optimize it:</p>
<pre><code>class BlobSearch
{
public sta... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T11:02:21.980",
"Id": "94042",
"Score": "0",
"body": "Optimize against what? What specific problem are you having? Please [edit] your question to explain what issues you are experiencing and why you think the code should be improve... | [
{
"body": "<p>If I understand correctly:</p>\n\n<ol>\n<li><code>blobContainer.ListBlobs()</code> is what is taking a long time</li>\n<li><code>ListBlobs</code> is not code that you control or can improve</li>\n<li>There isn't a way to perform the filtering you want without calling <code>ListBlobs</code></li>\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T06:13:34.850",
"Id": "54009",
"Score": "5",
"Tags": [
"c#",
"search"
],
"Title": "\"Good\" Blob search"
} | 54009 |
<p>Getting a hook on an open instance of Excel is something I do all the time. I'm now questioning if I'm doing this the best way. I'm particularly concerned with the fact that I rely on the <code>GetObject</code> method to throw an error. I'd like to avoid it if possible.</p>
<p>I have a Utils module that contains a ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T19:42:48.630",
"Id": "94051",
"Score": "0",
"body": "Just to clarify, this isn't Excel-VBA, right?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T19:43:45.803",
"Id": "94052",
"Score": "0",
... | [
{
"body": "<p>As was pointed out in chat earlier, a module called <code>Utils</code> might as well be called <code>Helpers</code> or <code>DumpAnythingYouWantHere</code>.</p>\n\n<p>You should prefer using <code>vbNewLine</code> over <code>vbCrLf</code>: <code>vbNewLine</code> will produce a platform-specific ne... | {
"AcceptedAnswerId": "54042",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T19:37:34.147",
"Id": "54011",
"Score": "9",
"Tags": [
"vba",
"error-handling",
"excel"
],
"Title": "Test if Excel is open without relying on catching an error"
} | 54011 |
<p>How do I make these line of codes more scala-ish (shorter?). I still get the Java feeling in it (which I want to stay away from).</p>
<pre><code>import scala.collection.mutable
val outstandingUserIds: mutable.LinkedHashSet[String] = mutable.LinkedHashSet[String]()
val tweetJson = JacksMapper.readValue[Map[Stri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T20:44:44.730",
"Id": "94060",
"Score": "0",
"body": "Welcome to Code Review! To make life easier for reviewers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of d... | [
{
"body": "<p>You usually want to avoid mutable collections in Scala, unless you have a good reason.</p>\n\n<pre><code>val outstandingUserIds: Set[String] = ... // immutable\n\nval userId: Option[String] = tweetJson.get(\"user\")\n .flatMap(userObj => userObj.asInstanceOf[Map[String, AnyRef]].get(... | {
"AcceptedAnswerId": "54019",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T20:25:45.540",
"Id": "54014",
"Score": "5",
"Tags": [
"scala",
"json"
],
"Title": "Parsing JSON to a Map and Set structure"
} | 54014 |
<p>I've implemented the Floyd Warshall algorithm in <a href="http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=762" rel="nofollow">this</a> problem. However, as this is my first time in handling with adjacency list, I was not able to make it memory efficient.</p... | [] | [
{
"body": "<p>Problem statement <a href=\"http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=762\">linked above</a> says 'Page numbers will always be in the range 1 to 100', I don't understand why you need to keep size = 1000, size = 101 should work just f... | {
"AcceptedAnswerId": "54027",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T20:30:36.643",
"Id": "54015",
"Score": "4",
"Tags": [
"c++",
"optimization",
"algorithm"
],
"Title": "Optimizing graph analysis"
} | 54015 |
<p>I made this small text adventure just to see what I could do with Python, and I'm basically wondering how it could be optimized, especially my combat as right now I'd have to rewrite it every time I want combat.</p>
<pre><code>import time
import random
spider_damage = 10
inventory = []
iron_dagger_damage = random.... | [] | [
{
"body": "<p>The most obvious problem is that parts of your code don't make any sense. For example:</p>\n\n<pre><code>iron_dagger()\niron_dagger = iron_dagger()\nchoice1_end(iron_dagger)\n</code></pre>\n\n<p><em>What?!</em> This:</p>\n\n<ol>\n<li>Calls the function and ignores the returned value;</li>\n<li>Cal... | {
"AcceptedAnswerId": "54026",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T20:38:04.500",
"Id": "54016",
"Score": "7",
"Tags": [
"python",
"game",
"adventure-game"
],
"Title": "Small text adventure"
} | 54016 |
<p>I wanted to create a cart that I can easily add some item or simply help someone at the other end over the phone. I decided to create a cart that would store everything on MySQL instead of using <code>$_SESSION</code>.</p>
<p>I did not code the whole cart just in case that this idea is very very bad. But I wanted ... | [] | [
{
"body": "<h2>Database</h2>\n\n<ul>\n<li>Normalize your database! Don't keep a string of serialized objects in the database, that's extremely brittle and extremely not helpful in all but the most simple cases. Instead, you should have 3 tables (two of which you already have):\n\n<ul>\n<li><code>items</code> - ... | {
"AcceptedAnswerId": "54046",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T21:00:44.373",
"Id": "54018",
"Score": "1",
"Tags": [
"php",
"mysql"
],
"Title": "A cart that uses SessionID"
} | 54018 |
<p>I'm writing a small scientific programming language, and I thought my first step would be to write a calculator with built in <a href="https://en.wikipedia.org/wiki/Significant_figures" rel="nofollow">significant figures</a>. I wrote this with <a href="http://jparsec.codehaus.org/" rel="nofollow">JParsec</a> for the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T22:56:04.533",
"Id": "94495",
"Score": "0",
"body": "I don't understand the naming of WHITESPACE_MUL nor why it returns MUL"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T00:19:04.673",
"Id": "94... | [
{
"body": "<p>I only have some simple style recommendations for now, so here goes:</p>\n\n<ol>\n<li>In <code>SigDec.java</code>, add some newlines between methods (or at least be consistent in how you deal with whitespace between methods). Also, you have an extra tab before the ending brace of <code>getSignific... | {
"AcceptedAnswerId": "54035",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T21:31:08.757",
"Id": "54020",
"Score": "5",
"Tags": [
"java",
"floating-point",
"calculator",
"interpreter"
],
"Title": "Calculator with significant figures"
} | 54020 |
<p>I am using the following macro to insert a mini table of contents between two identical heading styles (e.g. Heading 1). It works fine on small documents, but is very slow on large documents.</p>
<pre class="lang-vb prettyprint-override"><code>Sub MiniTOCFields(HeadingNumber As Long, TOCLevel As Long)
' Add mini ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T23:29:31.117",
"Id": "94095",
"Score": "0",
"body": "Is it the paragraph loop or the TOC updates that take too long? I don't think you need the `.Range.Select` call, just `.Update` should be enough to update the `currentTOC`."
},
... | [
{
"body": "<h2>Optimization:</h2>\n\n<p>You've done a good job of making sure you're not processing more than you have to, but there are a couple of things you can do here to improve performance. Instead of looping through all of the MiniTOCs you've just inserted, updating each one individually. Just update all... | {
"AcceptedAnswerId": "54030",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-11T22:58:17.403",
"Id": "54028",
"Score": "7",
"Tags": [
"performance",
"vba",
"ms-word"
],
"Title": "Macro for inserting a mini table between heading styles"
} | 54028 |
<p>This is my first Scala game. I would love some feedback on my coding style, or your brief input on how you would do it.</p>
<pre><code>object tictactoe extends App {
def tttFormat(board: Array[Char]): String =
"|" + board(0) + "|" + board(1) + "|" + board(2) + "|\n" +
"|" + board(3) + "|" + board(4) + "|... | [] | [
{
"body": "<ul>\n<li><p>Whether Scala or any other language, it's not a good sign when you have big blocks made of pasted/copied lines (tttFormat, board and atPlay). There is some logical structure to those repeated lines and you should code that instead of copying lines.</p></li>\n<li><p>There is a bug: the m... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T01:21:08.800",
"Id": "54034",
"Score": "3",
"Tags": [
"game",
"functional-programming",
"scala"
],
"Title": "Scala Tic Tac Toe Game"
} | 54034 |
<p>I have a working version of a logfile searcher that targets a specific directory by extension type, and searches the files for certain words. </p>
<p>I'm wondering if my method is the most efficient implementation, or if there are things I could do better.</p>
<pre><code>string startFolder = @"C:\logs\";
// sea... | [] | [
{
"body": "<p>There is one thing you could have done more efficient. When you read the files you wrote [star.star] which means that all files, regardless of type will get returned. This might be insufficient if there are many different files that are not related to your program in the target directory</p>\n",
... | {
"AcceptedAnswerId": "54039",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T01:58:11.790",
"Id": "54036",
"Score": "7",
"Tags": [
"c#",
"linq",
"search",
"directory"
],
"Title": "File text searcher"
} | 54036 |
<p>I recently wrote my first WordPress plugin, which was also my first PHP project. After I was done, I didn't care for the code at all, so I have spent the past couple of days refactoring it. I'm trying to take a more OOP approach to improve readability and make it easier to optimize. Prior to this, my only real expos... | [] | [
{
"body": "<p>I'm just going to write some comments from the top down.</p>\n\n<p>First of all I would like to point you to PSR, and especially <a href=\"http://www.php-fig.org/psr/psr-2/\" rel=\"nofollow noreferrer\">PSR-2</a>, since following a well known coding style will help other developers read your code.... | {
"AcceptedAnswerId": "54276",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T03:54:08.570",
"Id": "54040",
"Score": "2",
"Tags": [
"php",
"database",
"wordpress"
],
"Title": "DB security and efficiency in WordPress plugins"
} | 54040 |
<p>In this <code>strstr</code> implementation, I am basically skipping the already matched and checked characters with an <code>if else</code> condition. Is this a right way of implementing it?</p>
<pre><code>char *strstrImp(char *input, char *find) {
if(*find=='\0')
return input;
if(*input=='\0')
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T06:44:46.403",
"Id": "94121",
"Score": "6",
"body": "Are you trying to implement this in C++ specifically? This looks more like C."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T14:48:36.990",
"... | [
{
"body": "<h2>Const-correctness</h2>\n<p>Since you tagged this question as <a href=\"/questions/tagged/c%2b%2b\" class=\"post-tag\" title=\"show questions tagged 'c++'\" rel=\"tag\">c++</a>, you must take care of const-correctness:</p>\n<pre><code>cr54045.cpp:36:18: warning: conversion from string lite... | {
"AcceptedAnswerId": "54047",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T06:40:22.897",
"Id": "54045",
"Score": "11",
"Tags": [
"c++",
"strings",
"search",
"reinventing-the-wheel",
"pointers"
],
"Title": "strstr() implementation"
} | 54045 |
<p>I'm learning segment trees and their implementation. For the purpose, I tried solving the problem <a href="http://www.codechef.com/problems/FLIPCOIN" rel="nofollow">on CodeChef</a>.</p>
<p><a href="http://ideone.com/rak3iM" rel="nofollow">Full code here</a></p>
<p>My tree implementation is as follows: </p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T11:46:58.177",
"Id": "94138",
"Score": "0",
"body": "Welcome to CodeReview.SE! It is probably worth adding some comments telling us how the code is supposed to be working and the reasons behind the choices."
}
] | [
{
"body": "<p>In your <code>if-else</code> logic :</p>\n\n<ul>\n<li><p>you can get rid of a few <code>return</code>s</p></li>\n<li><p>if you have something like <code>if (condition) { some_code(); some_more_code1(); } else { some_code(); some_more_code2(); }</code>, you can write it by moving the common code : ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T08:15:57.397",
"Id": "54048",
"Score": "5",
"Tags": [
"c++",
"algorithm",
"tree",
"interval"
],
"Title": "Segment tree implementation"
} | 54048 |
<p>I wanted to know if this code is safe against SQL injection or not?
Also do I need to <code>mysqli_close</code> if I already did the <code>mysqli_stmt_close</code>? Other suggestions are always welcome.</p>
<pre><code>if ($stmt = mysqli_prepare($connect, "SELECT subcategories.subcat_name, subsubcategories.subsubca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T21:20:29.967",
"Id": "94275",
"Score": "0",
"body": "This seems like a practice project, but as soon as your projects get larger, you're going to want to separate the database and the presentation of the application. That would mean... | [
{
"body": "<h2>SQL Injection</h2>\n\n<p>Yes, your code is <strong>safe</strong> against SQL Injection. Make sure to use prepared statements when fetching things from the database as well, even in internal application services without user input.</p>\n\n<h2>Others</h2>\n\n<p>Well, I'm guessing this is a subset o... | {
"AcceptedAnswerId": "54051",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T08:52:35.323",
"Id": "54050",
"Score": "2",
"Tags": [
"php",
"mysqli",
"sql-injection",
"join"
],
"Title": "Displaying subcategories of subcategories"
} | 54050 |
<p>I have the following string replacement program for a string of size 256:</p>
<p>I am replacing the string</p>
<blockquote>
<p>"\'"</p>
</blockquote>
<p>with the string</p>
<blockquote>
<p>&<strong>apos</strong>;</p>
</blockquote>
<p>Please suggest any modifications if needed or any mistake I have done.... | [] | [
{
"body": "<ul>\n<li>Many strange numbers. Why is <code>Tmp2</code> only 250 long?</li>\n<li>Why is <code>buffer</code> static?</li>\n<li>Why is <code>Tmp2</code> not <code>free</code>d in the else branch? Most likely the <code>malloc()</code> should also only happen in the then branch.</li>\n<li>The <code>repl... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T10:05:30.760",
"Id": "54052",
"Score": "3",
"Tags": [
"c",
"strings",
"recursion",
"linux"
],
"Title": "Optimizing string replacement program that uses recursion"
} | 54052 |
<p>I have the following function which runs as expected and is defined in the <code>window</code> object:</p>
<pre><code>function myFunction(url, timeout, type, sc, ec) {
return $.ajax({
url: url,
timeout: timeout,
type: type,
success: function (data) {
if (typeof sc ===... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T11:03:29.403",
"Id": "94131",
"Score": "0",
"body": "Is it really named `myFunction`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T11:05:21.517",
"Id": "94132",
"Score": "0",
"body": "[... | [
{
"body": "<p>I would prefer a setting object for each function you want to call instead of merging them together into one, because then it is clear who needs this parameters. Otherwise this information gets lost. And who knows what jquery will do with this options in future releases? Maybe something useful, ma... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T10:51:53.193",
"Id": "54055",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"ajax",
"callback"
],
"Title": "JavaScript parameters - best practices for settings object/callba... | 54055 |
<p>I am using a Telerik <code>Datetime</code> control. On <code>onBlur</code> event of input box I am checking if the date is valid/in-valid, based upon that I am enabling or disabling the submit button (anchor tag actually).</p>
<pre><code>var embedUrl = null;
function onBlur(sender) {
var constants = {
c... | [] | [
{
"body": "<p>Some things that crossed my mind:</p>\n\n<ul>\n<li>Your'e polluting the global namespace with <code>embedUrl</code>. Wrap your code in an IIFE, or make use of jQuery's <a href=\"http://api.jquery.com/jquery.data/\" rel=\"nofollow noreferrer\"><code>data()</code></a> method to pass around \"global\... | {
"AcceptedAnswerId": "54162",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T12:06:07.100",
"Id": "54059",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"event-handling"
],
"Title": "Enabling/Disabling button on a certain condition"
} | 54059 |
<p>I've written an image processing library for downscaling, sharpening, compressing and caching images using PHP and ImageMagick. </p>
<p>Having recently been a chef in the kitchen of procedural and vague spaghetti code, I would appreciate feedback on:</p>
<ul>
<li>Code quality and appropriateness</li>
<li>Code clar... | [] | [
{
"body": "<p>Ok, on first glance there are a couple of problems that need fixing. My review might seem harsh, but remember: my only motive is to help.</p>\n\n<p>It's a bit of a hangup of mine, but please <a href=\"http://www.php-fig.org\" rel=\"nofollow\">subscribe to the standards</a> when it comes to coding ... | {
"AcceptedAnswerId": "54066",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T12:06:13.743",
"Id": "54060",
"Score": "1",
"Tags": [
"php",
"object-oriented",
"image"
],
"Title": "PHP ImageMagick Image Processing Class"
} | 54060 |
<p>I am creating a two-dimensional array, which I am going to process later in ways similar to image MinFilter, procedural labyrinth generation, etc. -- implying using coordinates and neighbors.</p>
<p>Here are two ways I came up with now:</p>
<pre><code>array := make([][]byte, 0, HEIGHT)
for i := 0; i < HEIGHT; i... | [] | [
{
"body": "<p>In terms of speed, there will be almost no difference. Both allocate enough space up front in the slice, hence any calls to <code>append</code> will not perform a reallocation. That being said, I imagine that using <code>append</code> could potentially incur a <em>very slight</em> penalty as, on e... | {
"AcceptedAnswerId": "54336",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T12:31:53.180",
"Id": "54062",
"Score": "2",
"Tags": [
"array",
"go",
"comparative-review"
],
"Title": "Two-dimensional array allocation in Go"
} | 54062 |
<p>I just started using Perlin noise a few days ago, and the results look quite good. But it takes over 3 seconds to calculate and draw a 1024x1024 bitmap of said noise. I use an array of 1024x1024 to store <code>int32</code>s ranging from -1 to 1.</p>
<p>Please note that the variable <code>tileSize</code> equals <cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T14:39:14.540",
"Id": "94182",
"Score": "1",
"body": "The code you posted isn't a perlin noise implementation; it just converts some values in `array` to colors and fills an image with them. If you want us to review the actual noise ... | [
{
"body": "<p>Since noise is essentially random, your large block of <code>if-else</code> chains is causing severe CPU stalls due to branch miss predictions. </p>\n\n<p>You should create a look up table (LUT) and quantize <code>array[x,y]</code> to an integer which indexes into the LUT. This should get rid of m... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T12:56:42.730",
"Id": "54065",
"Score": "7",
"Tags": [
"c#",
"optimization",
"array",
"image"
],
"Title": "Is there a way to optimise my Perlin noise?"
} | 54065 |
<p>Currently I have</p>
<pre><code>var l1 = [...];
var l2 = [...];
if (l1.length > l2.length){
var i = l2.indexOf(l1[0]);
if (i !== -1){
action_a(i);
}else{
action_c();
}
} else if (l1.length < l2.length){
var i = l1.indexOf(l2[0]);
if (i !== -1){
action_b(i);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-17T17:56:21.330",
"Id": "95170",
"Score": "0",
"body": "Is there a typo on the 4th line of the original code? Should `l[0]` be `l1[0]`? The same typo seems to be in the refactored code as well."
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>After re-reading the question I realized my answer was the same as your original code. Which frankly I don't see a problem with (the upper one, the later one is worse). </p>\n\n<p>It has a clear structure which says \"Okay, I'm treating three cases: less, equals and greater and doing different thi... | {
"AcceptedAnswerId": "54072",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T13:49:31.680",
"Id": "54069",
"Score": "7",
"Tags": [
"javascript"
],
"Title": "Refactoring decision tree"
} | 54069 |
<p>I have a code that creates a 3D array of values from a minimum to a maximum in X and Z with constant Y.</p>
<p>Right now I make it in normal Python, and then I transform it in a <code>np.array</code>. Is there a way to make it directly a NumPy array? How can I translate the code in NumPy to make it faster?</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T14:38:13.563",
"Id": "94181",
"Score": "1",
"body": "I'm sort of sad you deleted your other question. I had a nice review going xD"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T14:51:35.207",
"I... | [
{
"body": "<p>You could use the <a href=\"http://docs.scipy.org/doc/numpy/reference/generated/numpy.fromiter.html\" rel=\"nofollow\"><code>np.fromiter</code></a> function and Python's built in <a href=\"https://docs.python.org/2/library/itertools.html#itertools.product\" rel=\"nofollow\"><code>itertools.product... | {
"AcceptedAnswerId": "54084",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T13:51:37.097",
"Id": "54070",
"Score": "3",
"Tags": [
"python",
"performance",
"python-2.x",
"numpy"
],
"Title": "Fast loop to create an array of values"
} | 54070 |
<p>I have taken a widget/ plugin that I wrote yesterday and just now it has been re-written in an object oriented format. It is certainly more code to write it the OO way, so please let me know also how to analyze the performance of each example of the same widget below:</p>
<p>Please keep in mind that I use <code>dat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T15:31:14.733",
"Id": "94223",
"Score": "1",
"body": "Welcome to Code Review! Nice first post you got here, I hope you enjoy your CR experience and come back often - you now have >15 reputation score and have earned the privilege to ... | [
{
"body": "<p>First of all, maybe you should give the user a way to configure the selector - this gives most applications the chance to go for an id selector, others might want to have a more global or unobstrusive approach - so they can just use a data-selector. </p>\n\n<p>Your object oriented approach is not ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T14:11:17.020",
"Id": "54076",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"object-oriented"
],
"Title": "Object Oriented vs Not jQuery & JS"
} | 54076 |
<blockquote>
<p>An 'abecedarian' is a word whose letters appear in alphabetical order.
Write a program which will determine whether the given word is
abecedarian or not and print <code>1</code> if abecedarian, <code>0</code> if not.</p>
<pre class="lang-none prettyprint-override"><code>Input : user enter a str... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T09:50:27.483",
"Id": "94344",
"Score": "2",
"body": "You should use vertical whitespace more sparingly and indent your code properly (there are automatic tools to help you with this)."
}
] | [
{
"body": "<p><strong>Formatting</strong></p>\n\n<p>The obvious wrong thing with your code is the indentation (I don't know if it is because of the copy on CodeReview.SE).</p>\n\n<p>Also, the lines breaks seem to be used randomly. They should be used to divide the different logical parts of your function/progra... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T14:25:01.530",
"Id": "54079",
"Score": "2",
"Tags": [
"c",
"strings"
],
"Title": "Check Abecedarian word"
} | 54079 |
<p>I have posted below a small project of mine in AS3 regarding a super simple Expense Tracker. I finally made it basically functional, and I learnt A LOT in the way. But even I can tell that my design is horrible. If anyone was kind enough as to mention my mistakes to me and/or give me some advice, I would be extremel... | [] | [
{
"body": "<p>You said your structure is horrible, but it's not really <em>horrible</em>! I suggest you skim <a href=\"http://www.swinburne.edu.au/design/tutorials/P-flash/T-The-Model-View-Controller-Design-Pattern-in-Actionscript-3/ID-144/\" rel=\"nofollow noreferrer\">this</a> (a bit old, but relevant) and tr... | {
"AcceptedAnswerId": "54107",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T16:23:24.677",
"Id": "54089",
"Score": "4",
"Tags": [
"actionscript-3",
"actionscript"
],
"Title": "Simple expense tracker"
} | 54089 |
<p>I am going through the example of <a href="http://en.wikipedia.org/wiki/SHA-2#Pseudocode" rel="nofollow">SHA256 over at Wikipedia</a> and wanted to make sure I understood all the operations of the manipulation math before trying to actually attempt the implementation itself. The comments explain the entire thing.</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T18:37:08.060",
"Id": "94250",
"Score": "1",
"body": "the XOR, NOT and AND are simple to tell if they work or not you just line them up and do it manually, and it looks like those three are functioning properly to me"
},
{
"C... | [
{
"body": "<p>I don't know about optimization, but <code>test_set</code> seems to scream for a <a href=\"https://docs.python.org/3.4/tutorial/datastructures.html#dictionaries\" rel=\"noreferrer\"><code>dict</code></a>. It seems more appropriate than a list of lists, especially since the indices are known and th... | {
"AcceptedAnswerId": "54170",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T17:44:06.280",
"Id": "54091",
"Score": "8",
"Tags": [
"python",
"bitwise"
],
"Title": "Implementations of rotate, shift, XOR, NOT and AND"
} | 54091 |
<p>I've been trying to figure out the best way to manage database connections for a while now and am still unsure of how I should be doing things. I know there are a lot of similar questions on here, but I've read many of them and am still confused.</p>
<p>Some answers on here say singletons should be used, but it see... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T23:02:19.457",
"Id": "94291",
"Score": "2",
"body": "[A long but outstanding read on the subject is here](http://kunststube.net/static/). Basically, you should be passing it in because (1) it will make your application architecture... | [
{
"body": "<p>Let's start with the review, and then talk about correctness of the approach.</p>\n\n<ul>\n<li><p><strong>Pass things by parameters</strong> - What do you do if your credentials change? Don't you want to reuse the function? Pass the credentials as parameters to the <code>createPDO</code> function,... | {
"AcceptedAnswerId": "54301",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T17:51:18.673",
"Id": "54092",
"Score": "2",
"Tags": [
"php",
"pdo"
],
"Title": "Should a PDO object be passed to classes and procedural functions as a parameter?"
} | 54092 |
<p>I am implementing a Point in polygon algorithm.</p>
<p><strong>Inputs:</strong></p>
<ul>
<li><code>M</code>, <code>N</code>: size of the matrix</li>
<li><code>poly</code>: a list of tuples that represent the points of polygon. </li>
</ul>
<p><strong>Output:</strong></p>
<p>A mask matrix which is ones everywhere,... | [] | [
{
"body": "<p>When you say \"points of polygon\", I am assuming you are referring to vertices.</p>\n\n<p>I don't think what you have is the fastest. A simple improvement to this could be to divide your matrix in to a grid of <code>p x p</code> cells, where <code>p</code> is a parameter, and classify each grid-c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T17:56:15.283",
"Id": "54093",
"Score": "4",
"Tags": [
"python",
"algorithm",
"matrix",
"numpy",
"computational-geometry"
],
"Title": "Point in a polygon algorithm"
} | 54093 |
<p>The following example shows how to implement a queue in an employee structure. I am looking for a review of the implementation:</p>
<pre><code>import java.util.LinkedList;
class GenQueue<E> {
private LinkedList<E> list = new LinkedList<E>();
public void enqueue(E item) {
list.addLast(... | [] | [
{
"body": "<h1>!The Queue</h1>\n<p>About the not-the-queue things:</p>\n<ul>\n<li><p>your Employee and HourlyEmployee classes have public fields (<code>firstname</code>, etc.) You should instead have 'getters' for them (like <code>getFirstName()</code>). I would recommend making those values 'final' as well, bu... | {
"AcceptedAnswerId": "54097",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T18:16:06.240",
"Id": "54095",
"Score": "4",
"Tags": [
"java",
"queue"
],
"Title": "Queued Employees"
} | 54095 |
<p>I've spent the last couple of evenings trying to build a system for redistribution of votes in a ranked voting system. I've finally come up with the model for redistributing surpluses from a candidate whose number of votes exceeds the threshold. </p>
<p>I'm at the beginning of my learning curve and I've used Stack ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T23:28:21.963",
"Id": "94292",
"Score": "3",
"body": "How did you manage to do this? I am utterly impressed that you're getting correct results (If you are. I haven't checked yet.) I'll take a look at this as soon as I have a chance.... | [
{
"body": "<p>Disclaimer: I'm a SQL Server guy. I might get the particular syntax of MySQL wrong. I apologize if I do.</p>\n\n<p>The first thing I notice is this that subquery shows up over and over again in your query.</p>\n\n<pre><code>SELECT FLOOR((COUNT(*) / (2 + 1)) + 1) threshold\nFROM votes\n</code></pre... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T18:38:43.820",
"Id": "54099",
"Score": "25",
"Tags": [
"sql",
"mysql"
],
"Title": "Complex query to count votes with a redistribution system"
} | 54099 |
<p>I'm using Entity Framework 6 with database first. See the image for the relevant database schema<img src="https://i.stack.imgur.com/QcLJB.png" alt="enter image description here"></p>
<p>I have the following method to save a <code>Set</code> to the database:</p>
<pre><code>/// <summary>
/// Saves the list of ... | [] | [
{
"body": "<blockquote>\n<pre><code>/// <summary>\n/// Saves the list of data sources. This assumes that the ModelTemplateID, SetNumber and TaskNumber\n/// are already properly set. Adds a new record to the DataSourceGroups table if necessary.\n/// </summary>\n/// <param name=\"dataSources\">T... | {
"AcceptedAnswerId": "54113",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T18:56:26.123",
"Id": "54101",
"Score": "3",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Method to save child objects"
} | 54101 |
<p>I'm very new to Haskell. I did try it for a few days, a few years ago... but other than that, this is my second day. I'm equally unused to functional programming, by the way.</p>
<p>After much trial and error, I managed to write this function:</p>
<pre><code>chunk :: Int -> [a] -> [[a]]
chunk n xs = chunk' n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T22:55:44.843",
"Id": "94289",
"Score": "1",
"body": "I'm rolling back Rev 3 → 2. Please see our [policy for iterative reviews](http://meta.codereview.stackexchange.com/q/1763/9357), and re-post your update accordingly."
},
{
... | [
{
"body": "<p>Using <code>++</code> to concatenate lists is a bad idea for performance, and it's a sign that you are not using recursion smartly.</p>\n\n<p>Here's what I came up with:</p>\n\n<pre><code>chunk :: Int -> [a] -> [[a]]\nchunk n xs = \n if length chunk' < n then []\n else (chunk' : chun... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T19:06:01.117",
"Id": "54102",
"Score": "9",
"Tags": [
"beginner",
"haskell"
],
"Title": "Splitting a list into overlapping sub-lists"
} | 54102 |
<p>I'm using a <a href="http://blogs.msdn.com/b/pfxteam/archive/2010/04/07/9990421.aspx">StaTaskScheduler</a> (TPL extension) to open some web browser windows simultaneously and navigate to different sites (using <a href="http://watin.org/">WaitN</a>, but it might as well just be a <code>WebBrowser</code>). </p>
<p>In... | [] | [
{
"body": "<p>I would make your lock a little more tight:</p>\n\n<pre><code>lock (ret)\n{\n ret.AddRange(result);\n}\n</code></pre>\n\n<p>But otherwise, looks like an all right implementation.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T22:3... | {
"AcceptedAnswerId": "54111",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T21:09:23.790",
"Id": "54106",
"Score": "8",
"Tags": [
"c#",
"multithreading"
],
"Title": "Concurrent blocking Tasks in a BackgroundWorker"
} | 54106 |
<p>I'm a Scala beginner, so it'd be great if anyone would be so kind to give some feedback.</p>
<pre><code>package heap
import scala.collection.mutable.ListBuffer
class Heap[T](compareFunction: (T, T) => Int) {
private val HIGHER = 1
private val LOWER = -1
private val heapRepresentation = new ListBuffer[T]()
p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T22:43:13.597",
"Id": "94287",
"Score": "2",
"body": "Perhaps you could add some background to your script? What should it do? Are you looking for a focus on a specific part or concept?"
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>Writing utility classes is hard enough without reinventing everything from scratch each time. Whenever possible, class authors should take advantage of available tools. In this case, Scala has a trait for ordering objects in a collection: <a href=\"http://file:///Users/dmclean/Library/java/scala-d... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T21:56:50.653",
"Id": "54108",
"Score": "6",
"Tags": [
"beginner",
"scala",
"heap"
],
"Title": "Scala heap implementation"
} | 54108 |
<p>Here is some code I have that has been extracted and shrunk down from a project of mine.</p>
<pre class="lang-c prettyprint-override"><code>#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <string.h>
#define streq(x, y) (strcmp((x), (y)) == 0)
#define ARRAY_SIZE(x) (sizeof(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T23:45:39.900",
"Id": "94295",
"Score": "0",
"body": "Sort your array and bin search it, no?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T23:50:42.743",
"Id": "94297",
"Score": "0",
"bod... | [
{
"body": "<p>As requested.</p>\n\n<p>An unstructured array may only be searched in linear order. To get better asymptotics you need a more search-friendly structure. A simplest solution would be to presort the <code>Command</code> array, and apply a binary search to find the command. A definite advantage here ... | {
"AcceptedAnswerId": "54454",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T23:23:21.627",
"Id": "54112",
"Score": "10",
"Tags": [
"performance",
"c",
"strings",
"design-patterns",
"parsing"
],
"Title": "Scalability of running commands from use... | 54112 |
<p>I have a .net 4.5 desktop script which has dependencies on some third party libraries (dll's). These libraries are used in my <code>MainWindowViewModel</code>. I need to check that these dll's are present before their absence allow the program to break (which is basically at the starting point of the code). This is ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T00:27:32.170",
"Id": "94302",
"Score": "0",
"body": "Where is the late binding happening? In the *ViewModel*? In the *View*? Is it supposed to be in this code and it's not written yet? As it stands your question isn't very clear. Th... | [
{
"body": "<p>As I mentioned in the comments, the code you've posted could very well be doing <em>anything</em> that could potentially throw <em>any</em> exception.</p>\n\n<pre><code>MainWindow window = new MainWindow();\n</code></pre>\n\n<p>By putting this constructor call <em>outside</em> the <code>try</code>... | {
"AcceptedAnswerId": "54119",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T00:20:34.803",
"Id": "54115",
"Score": "9",
"Tags": [
"c#",
"library",
"wpf",
"mvvm"
],
"Title": "Am I handling \"spot the missing DLL\" right?"
} | 54115 |
<p>Seeking to improve upon my high score 'module' code. It saves users' high score in a pickle database and if needed prints out the current scores in the database.</p>
<pre><code>import pickle
import os
global high_scores
def setup_scores():
global high_scores
high_scores = {}
if os.path.isfile('highsco... | [] | [
{
"body": "<ul>\n<li>Use of <code>global</code> should generally be avoided. You could create a class to hold the dictionary and the three functions would become methods.</li>\n<li>Don't repeat yourself: use a variable for the file name so you don't have to change it in three places if it needs to change. </li>... | {
"AcceptedAnswerId": "54128",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T00:42:01.650",
"Id": "54117",
"Score": "10",
"Tags": [
"python",
"python-2.x"
],
"Title": "Saving high scores in a pickle database"
} | 54117 |
<p><strong>Feature-based authorization</strong> </p>
<p>It seems to me that if you rely on roles to authorize a web application it makes it very difficult to render UI or code based on a set of features. This means that each role would have be checked against for each feature. </p>
<pre><code>if(User.IsInRole("SomeRo... | [] | [
{
"body": "<p>Couple of items that might need a re-look:</p>\n\n<ul>\n<li><p>The now deprecated <a href=\"http://msdn.microsoft.com/en-us/library/ff649313.aspx\" rel=\"nofollow\">AzMan</a> has very similar concepts. The conceptual equivalent for the '<em>Feature</em>' in your application is an '<em>Operation</e... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T01:10:56.167",
"Id": "54118",
"Score": "10",
"Tags": [
"c#",
"asp.net-mvc",
"razor",
"authorization"
],
"Title": "Feature-based authorization"
} | 54118 |
<p>I've been toying around making my repositories a bit more fluent for a while. I was ending up with crazy long method names when I had to query on multiple conditions. So I've been working on a way to query fluently.</p>
<p><strong>Usage</strong></p>
<p><strong>Insert/Update/Delete</strong></p>
<p>Looks and behave... | [] | [
{
"body": "<p>I quite like the concept. The only thing that stands out for me initially is that I would probably leave the wrapping methods the same as their wrapped name.</p>\n\n<p>i.e.</p>\n\n<pre><code>TEntity FirstOrDefault()\nTask<TEntity> FirstOrDefaultAsync()\nIEnumerable<TEntity> All()\nTas... | {
"AcceptedAnswerId": "54283",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T02:17:52.397",
"Id": "54120",
"Score": "7",
"Tags": [
"c#",
"repository",
"fluent-interface"
],
"Title": "Fluent Repository/QueryBuilder"
} | 54120 |
<p>This code will check the database for an order number. If none exist it creates one. If one does exist then it will increment it by one and update the database. Is this the most efficient way to handle this?</p>
<pre><code>// Order Number check
let updateOrderNumber bizLocId =
// order number record exist
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-18T18:05:20.190",
"Id": "95434",
"Score": "1",
"body": "I think you need to use transactions here. Otherwise, two instances of this running at the same time could create the same ID."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T02:40:53.187",
"Id": "54121",
"Score": "3",
"Tags": [
"f#"
],
"Title": "Check the database for an order number"
} | 54121 |
<p>I use a lot of "when user clicks on element then another element will be displayed as visible/hidden... aka toggle". </p>
<p>So I'm trying to make a general function to abide the DRY principal.</p>
<p>Before jumping into the code, I just wanted to state that there are still bugs. I just want to know before continu... | [] | [
{
"body": "<p>I know you're trying to be flexible here, but your approach comes at a cost: <em>The API isn't understandable.</em> I can see you're trying to toggle the second parameter element with the first parameter as the toggle, But I don't understand exactly how the third or fourth works, if it's even nee... | {
"AcceptedAnswerId": "54134",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T03:00:30.790",
"Id": "54123",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"event-handling"
],
"Title": "Creating a function when user clicks on element to toggle another el... | 54123 |
<p>Here is some code I wrote 10 years ago. I'm now reviewing it and there are a lot of things I don't like.</p>
<p>There is possibility for weird behaviour if the template is attempted to be used with a type that I didn't intend. Also I don't like the big macros for <code>DECLARE</code> and <code>DEFINE</code>; and we... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T15:06:10.713",
"Id": "94402",
"Score": "0",
"body": "Have a look here. http://codereview.stackexchange.com/a/14315/507 you don't need C++11 logic to make this work well."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>Since you have access to a C++11 compiler, you should use the standard type trait <a href=\"http://en.cppreference.com/w/cpp/types/is_enum\" rel=\"nofollow\"><code>std::is_enum</code></a> in the default version of your template instead of just writing <code>is_enum = false</code>. Also, it should ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T04:15:20.283",
"Id": "54124",
"Score": "10",
"Tags": [
"c++",
"template",
"enum"
],
"Title": "Smart enum templates"
} | 54124 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.