body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Sometimes when developing a WPF application, I need to access a certain <code>Window</code> (<code>View</code>) from the corresponding <code>ViewModel</code>, to perform or fire a method like this for example:</p>
<pre><code>//In the MainWindowViewModel
MainWindowView.Hide();
</code></pre>
<p>But that's not reall... | [] | [
{
"body": "<p>You have multiple options</p>\n\n<p>a. Use an event Aggregator where publish the message from the viewmodel and subscribe from view. see prism documentation for event aggregators:here is sample code </p>\n\n<blockquote>\n<pre><code> //view will subscribe from this message \n_aggregator.GetEvent<... | {
"AcceptedAnswerId": "58250",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T02:09:10.657",
"Id": "58240",
"Score": "4",
"Tags": [
"c#",
".net",
"wpf",
"mvvm",
"xaml"
],
"Title": "Access View from current/corresponding ViewModel"
} | 58240 |
<p>I am trying to understand the workings of reader writer locks. For the sake of learning, I implemented reader writer synchronization by my own. I implemented <code>SynchronizedArrayList</code> with reader writer synchronization.</p>
<p>I set out with following objective:</p>
<ol>
<li>There can be many readers.</li... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T14:59:06.197",
"Id": "104573",
"Score": "0",
"body": "Objective #2 (one writer) appears to conflict with objective #3 (Fairness among writers.) Can you clarify this?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<h1>You Must Construct Additional <strike>Pylons</strike> Code</h1>\n<pre><code>private void waitForSignal() {\n //not yet implemented\n}\n</code></pre>\n<p>This will be a pretty significant part of your implementation. I'll take it at face value and assume it's just looping on <code>wait()</code... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T04:21:29.610",
"Id": "58243",
"Score": "1",
"Tags": [
"java",
"multithreading",
"locking",
"concurrency"
],
"Title": "SynchronizedArrayList implemented using reader writer syn... | 58243 |
<p>I see that there are a few other people who have tackled <a href="http://projecteuler.net/problem=3">Project Euler Problem #3</a>. I hope you're not all sick of that question yet. I've not taken a look at those yet (purposely), but am about to now. </p>
<p>I feel like I did a pretty good job on this one, but you te... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T07:49:12.023",
"Id": "104498",
"Score": "1",
"body": "Although each part of your code works, you are missing a much simpler approach; rather than creating a list of all prime factors and returning the largest, look for the largest f... | [
{
"body": "<p>As you mentioned, a <code>List<T></code> would be a better option than manually resizing the array.</p>\n\n<p>If you ever find yourself resizing an array, <code>List<T></code> is almost certainly what you want. When a resize is required, it <a href=\"http://en.wikipedia.org/wiki/Dynami... | {
"AcceptedAnswerId": "58254",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T04:39:45.367",
"Id": "58244",
"Score": "14",
"Tags": [
"c#",
"programming-challenge",
"primes",
"mathematics"
],
"Title": "Wow that's a big integer! What's its largest prim... | 58244 |
<p>I have implemented the code to convert datareader to list of objects. My intention was to not to use column name string literals while reading the datareader.</p>
<pre><code>public static IEnumerable<T> GetListFromDataReader<T>(IDataReader reader) where T : new()
{
var properties = typeof(T).GetProp... | [] | [
{
"body": "<p><clippy>It appears you are writing an Object/Relational Mapper! Would you like some help?</clippy></p>\n\n<p>Yes, a lot of reflection in loops can be bad thing since reflection is known for its slowness. In a situation like this, it's best to cache the results as your types will not be... | {
"AcceptedAnswerId": "58275",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T06:45:10.593",
"Id": "58251",
"Score": "6",
"Tags": [
"c#",
"reflection",
"ado.net"
],
"Title": "Transform DataReader to List<T> using reflections"
} | 58251 |
<p>I've a slot booking script which is as follows:</p>
<h3>My Current Algorithm</h3>
<ol>
<li>A calendar is shown to the user</li>
<li>The user clicks on a date</li>
<li>I make an ajax call to determine if at least 1 slot is booked on the
clicked date</li>
<li>I return back a form from the ajax page ("Time To", "Time... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T10:15:41.690",
"Id": "104510",
"Score": "3",
"body": "Never trust the client™. There's nothing that's tamper-proof on the client-side. You can use the client-side to _enhance_ the experience by providing more immediate feedback, but... | [
{
"body": "<p>Right now, you have two separate AJAX calls: one to determine if a day has bookings, and one to determine whether a specific time slot can be booked.</p>\n\n<p>I would suggest one of two things:</p>\n\n<ol>\n<li>Send a request only once that returns all booking data for the specified date.</li>\n<... | {
"AcceptedAnswerId": "58271",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T09:53:29.460",
"Id": "58256",
"Score": "6",
"Tags": [
"javascript",
"php",
"jquery",
"html",
"validation"
],
"Title": "Using/storing server-side data on the client side... | 58256 |
<p>I have an input group:</p>
<pre><code><div class="input-group">
<div class="input-group-addon">
@Html.DisplayNameFor(m => m.StorageId)
</div>
@if(ViewData.ModelState["StorageError"] !=null && ViewData.ModelState["StorageError"].Errors.Count>0)
{
<di... | [] | [
{
"body": "<p>Basically, 95% of your code is the same between the two sections, so I'd prefer to use just a single instance with a <code>bool</code> on the page.</p>\n\n<pre><code>@{ \n var error = ViewModel.ModelState[\"StorateError\"];\n var hasErrors = error != null && error.Errors.Any();\n}\n\... | {
"AcceptedAnswerId": "58263",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T10:05:04.640",
"Id": "58257",
"Score": "3",
"Tags": [
"c#",
"html",
"asp.net-mvc",
"razor"
],
"Title": "Replacing div if there is any validation error connected with the di... | 58257 |
<p><a href="https://stackoverflow.com/questions/24985896/">I posted the following snippet to StackOverflow</a>, and someone said there was much to be improved.</p>
<pre><code>{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
class (Show a) => Currency a where unphantom :: a
data USD = USD deriving Show
... | [] | [
{
"body": "<p>You could rely on the fact the types describing your currencies are <code>Enum</code>erable and you can therefore always generate the appropriate token based on the type of an expression. You would write something like this:</p>\n\n<pre><code>{-# LANGUAGE ScopedTypeVariables #-}\n\nmodule Currency... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T10:39:30.053",
"Id": "58261",
"Score": "5",
"Tags": [
"haskell"
],
"Title": "Using phantom types to represent amounts and exchange rates of currencies"
} | 58261 |
<p>I'm new in Python and consequently I am searching for a specific solution for code development. I already asked some <a href="https://stackoverflow.com/questions/24989885/double-for-loop-in-python">pythonic question</a> today and want to present my whole problem. I have found some solution, but I really have intere... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T14:46:11.800",
"Id": "104567",
"Score": "0",
"body": "Hi, welcome to CodeReview.SE! Can you please provide your actual code and what it is supposed to do ? (At the moment, I have doubts that your code is working at all : there is a ... | [
{
"body": "<p>I would strongly recommend creating a class.</p>\n\n<pre><code>class Student:\n def __init__(self, id, graduated):\n self.id = id\n self.graduated = graduated\n</code></pre>\n\n<p>Then your problem is easier.</p>\n\n<pre><code>graduatedchemistry = [student for student in chemistry... | {
"AcceptedAnswerId": "58281",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T13:14:04.260",
"Id": "58264",
"Score": "4",
"Tags": [
"python",
"beginner"
],
"Title": "Finding students who appear on a list"
} | 58264 |
<p>I'd like someone to review these tests to make sure I'm along the right lines in Angular testing.</p>
<p>Note - They do all pass (great) but I feel like I'm struggling to understand the finer points of Angular testing.</p>
<p>Any thoughts?</p>
<pre><code>var headerControllers = angular.module('header.controllers'... | [] | [
{
"body": "<p>It doesn't look to me like proper Unit test.\nYou are <em>injecting</em> the <em>real</em> dependency but are not <em>mocking</em>.\nUnit test is about testing your single Unit of functionality in isolation, with all it dependencies mocked.</p>\n\n<p>Here is example from of my own test code.\nThis... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T13:28:21.600",
"Id": "58266",
"Score": "4",
"Tags": [
"javascript",
"angular.js",
"controller"
],
"Title": "Is this approach correct when testing an Angular controller?"
} | 58266 |
<p>I am rewriting a VB.NET application in C#. I will not subject you to the original code because it's pretty messy. Below is the converted C# code:</p>
<pre><code> public IEnumerable<WebQuery> GetQueries(Request request)
{
var queries = new List<WebQuery>();
foreach (var report in re... | [] | [
{
"body": "<p>Have you tried:</p>\n\n<pre><code> public IEnumerable<WebQuery> GetQueries(Request request)\n {\n List<string> keys = request.Reports.Select(i => i.UserKey).ToList();\n var queries = new List<WebQuery>();\n queries.AddRange((from query in _context.We... | {
"AcceptedAnswerId": "58268",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T13:28:47.183",
"Id": "58267",
"Score": "10",
"Tags": [
"c#",
"linq",
"converting"
],
"Title": "Refactor VB.NET to C#.Net using Linq"
} | 58267 |
<p>The code below generates <strong>only</strong> 10 email domains. To me, this is bruteforce programming. Is there another random integer library? Could I use something like <code>random.seed()</code> in C++?</p>
<p>What is a more elegant way to generate 100 emails names using some Python libs/APIs? </p>
<pre><code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T21:48:20.593",
"Id": "104694",
"Score": "0",
"body": "This question still doesn't make sense; if anything, it's a worse fit here than SO. What exactly is the problem with the standard library `random` module? It has a `seed` functio... | [
{
"body": "<p>From <a href=\"https://stackoverflow.com/questions/306400/how-do-i-randomly-select-an-item-from-a-list-using-python\">this Stack Overflow question</a> :</p>\n\n<pre><code>import random\n\nfoo = ['a', 'b', 'c', 'd', 'e']\nprint(random.choice(foo))\n</code></pre>\n\n<p>In your case,</p>\n\n<pre><cod... | {
"AcceptedAnswerId": "58273",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T13:56:34.137",
"Id": "58269",
"Score": "12",
"Tags": [
"python",
"python-3.x",
"random"
],
"Title": "Generating random email addresses"
} | 58269 |
<p>Right now, my solution counting likes of a specific user is </p>
<ol>
<li>Starting a recursive call on the "/{user-id}/posts" edge</li>
<li>Iterate through all posts</li>
<li>On each post iterate through each like on the likes edge</li>
</ol>
<p>If someone knows a better, easier way with less graph API calls neces... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T15:00:51.323",
"Id": "104574",
"Score": "0",
"body": "Welcome to Code Review! Do know that reviewers can review other aspects of your code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T15:53:45.797... | [
{
"body": "<p>Interesting / fun question.</p>\n\n<p>I don't think there is much to improve there to reduce the API call count.</p>\n\n<p>From a once over, these are some things you might want to look at:</p>\n\n<ul>\n<li><code>forEach</code> is still slower than the good old <code>for</code> loop, not sure that... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T14:00:31.487",
"Id": "58270",
"Score": "9",
"Tags": [
"javascript",
"api",
"graph",
"facebook"
],
"Title": "Getting all likes from a specific user on a news wall with fewer gr... | 58270 |
<p>Using the following query I'm doing transactions with two tables</p>
<pre><code>BEGIN TRANSACTION
UPDATE SalaryTrans SET carried_forward_amount = @carriedForwardAmount, net_wage=@netWage, processed_date = @processedDate WHERE employee_id=@employeeID AND reference = @reference
DELETE FROM CarriedForward WHERE emplo... | [] | [
{
"body": "<p>In terms of the raw/basic functionality, what you have is fine. The transactional logic is good.</p>\n\n<p>Readability is the only concern I have, and would rewrite your code as (note, there are some spaces I added around some <code>=</code> conditions):</p>\n\n<pre><code>BEGIN TRANSACTION \n\n ... | {
"AcceptedAnswerId": "58278",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T14:05:43.160",
"Id": "58272",
"Score": "6",
"Tags": [
"sql",
"sql-server",
"ado.net"
],
"Title": "Multiple SQL statements in a single transaction"
} | 58272 |
<p>I am converting a VB.NET app over to C#. I won't subject you to the old code but the following is done in a little over 100 lines using nested loops. I am using Entity Framework 6 as my ORM. I have cleaned that up some to this:</p>
<pre><code>public void Remove(int key)
{
var myObject = _context.MyObjects.First... | [] | [
{
"body": "<blockquote>\n <p>Can this method be changed to remove all objects in one call?</p>\n</blockquote>\n\n<p>There is no way to remove multiple objects from multiple tables in one statement and there shouldn't be (cascading foreign key constraints notwithstanding). </p>\n\n<p>The problem is that <code>R... | {
"AcceptedAnswerId": "58286",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T15:20:41.733",
"Id": "58280",
"Score": "2",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Can this method be changed to remove all objects in one call?"
} | 58280 |
<p>I have created a QuadTree in Java and would like a general code review or suggestions.</p>
<pre><code>import java.util.ArrayList;
public class QuadTree
{
private QuadTree root, parent, northEast, southWest, northWest, southEast;
Point center;
Double halfDimension;
Double northBound, eastBound, sou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T15:54:26.593",
"Id": "104601",
"Score": "1",
"body": "Hi, and welcome to Code Review. Recommendations on how best to test your code are off-topic here. I'm going to update your title accordingly."
}
] | [
{
"body": "<p>This code is difficult to review for many reasons:</p>\n\n<ul>\n<li>It's not following standard formatting</li>\n<li>It's not following standard naming, for example: <code>iCollider</code>, <code>Objects</code></li>\n<li>There are some unknown external elements, for example: <code>ColliderType</co... | {
"AcceptedAnswerId": "58317",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T15:40:35.113",
"Id": "58283",
"Score": "4",
"Tags": [
"java",
"tree",
"collision"
],
"Title": "A Quadtree implementation with Colliders"
} | 58283 |
<p>This is for adding code into my table really easily, however it will be called 2000+ times per second, so I need to know if this is the most efficient code to add a row to the database.</p>
<pre><code><?php
$site = $_GET['url'];
$con=mysqli_connect("localhost","","","rocket_newsites");
// Check connection
if (my... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T15:45:03.953",
"Id": "104592",
"Score": "10",
"body": "Gonna be some fast SQL injection!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T15:45:44.440",
"Id": "104594",
"Score": "0",
"body"... | [
{
"body": "<p>opening and closing 2000 connections every second is not good for performance, having some sort of connection pool that opens/closes connections as needed would be much less overhead</p>\n\n<p>I would advise looking at <code>mysql_pconnect()</code></p>\n",
"comments": [
{
"Conten... | {
"AcceptedAnswerId": null,
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T15:41:35.703",
"Id": "58284",
"Score": "10",
"Tags": [
"php",
"mysql",
"sql-injection"
],
"Title": "Inserting 1 line into my SQL database"
} | 58284 |
<p>This is a very simple function, but it gets run on a roughly 10ms interval, so I'm looking for ways to improve it. The first obvious thing is that it has to run the comparisons nearly every time as it starts with the lowest probabilities first. Is there a way I can reverse that without breaking it, or a way I can ge... | [] | [
{
"body": "<p>Depending on your requirements and your performance needs you can pre-populate a lookup table of random numbers and implement <code>flip_coin()</code> as a table lookup:</p>\n\n<pre><code>function flip_coin() {\n return ++i >= lookupTable.length ? lookupTable[i=0] : lookupTable[i];\n}\n</code>... | {
"AcceptedAnswerId": "58296",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T15:48:46.173",
"Id": "58285",
"Score": "11",
"Tags": [
"javascript",
"performance",
"random"
],
"Title": "Random weighted 'tick' function"
} | 58285 |
<p>I created a timer library called <a href="https://github.com/jsanc623/PHPBenchTime" rel="nofollow">PHPBenchTime</a> a <a href="https://github.com/jsanc623/PHPBenchTime/blob/3674b13bcce9c600ed59656ff4433f77e166ae00/src/PHPBenchTime.php" rel="nofollow">few years ago</a>, and decided to rewrite it last week.</p>
<p>Th... | [] | [
{
"body": "<h1>Some remarks</h1>\n\n<p>why do you call the reset method in your constructor? The constructor is called on object creation, so nothing has changed yet. Everything still has it's default values.</p>\n\n<p>I like your approach of laps and calling it laps. Makes it easy to understand since we all kn... | {
"AcceptedAnswerId": "59089",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T16:05:17.910",
"Id": "58288",
"Score": "2",
"Tags": [
"php",
"performance",
"library",
"benchmarking"
],
"Title": "Benchmark/timer library - follow-up"
} | 58288 |
<p>I have a data structure that allows for inheritance of properties, in such a way that if a property is not defined within a context, the second most specific context is checked until said property is found. Simplified it's basically the following:</p>
<pre><code>function getCarPartColor($carData, $owner, $brand, $p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T17:41:16.230",
"Id": "104639",
"Score": "0",
"body": "What are the expected returns of each scenario?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T19:57:35.950",
"Id": "104669",
"Score": "0... | [
{
"body": "<p>Long time reader, first time poster, welcoming of critique.</p>\n\n<p>You could create an array populated with each variant of the property you're looking for:</p>\n\n<pre><code> $is_set = array (\n $carData->{$owner}->{$brand}->{$part},\n $carData->{$owner}->{$bran... | {
"AcceptedAnswerId": "58362",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T16:15:17.930",
"Id": "58290",
"Score": "2",
"Tags": [
"php"
],
"Title": "Multiple isset block going from more specific to more generic"
} | 58290 |
<p>I posted a <a href="https://stackoverflow.com/questions/24899147/how-to-implement-a-decision-table-in-objective-c">question</a> on Stack Overflow about how to implement Decision Tables in Objective-C after reading about them for the first time in chapter 18 of <em>Code Complete</em>. Nobody provided an answer, so a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T23:23:30.673",
"Id": "104698",
"Score": "0",
"body": "Is it necessarily important that enemy movement is handled differently? At a minimum, it seems like enemy and non-enemy movement should at least have a common parent class that ... | [
{
"body": "<pre><code>-(id) initWithWorldSizeForCharacter:(CGSize)worldSize andStartingFloor:(int)startingFloor;\n</code></pre>\n\n<p>It's slightly better to use <code>instancetype</code> as the return type here rather than <code>id</code>. What we're actually returning (here) is a <code>DTEnemyMovement</code>... | {
"AcceptedAnswerId": "58294",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T16:22:47.863",
"Id": "58292",
"Score": "12",
"Tags": [
"game",
"design-patterns",
"objective-c"
],
"Title": "Decision Table for the Movement AI in a Game"
} | 58292 |
<p>Could someone review my code, with respect to OOP, clean code and MVC pattern?</p>
<p><strong>Main app:</strong></p>
<pre><code>public class Application
{
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
//test
@Override
... | [] | [
{
"body": "<pre><code> this.view.getToolsMenu().addRectangleListener(new RectangleListener());\n this.view.getToolsMenu().addCircleListener(new CircleListener());\n this.view.getToolsMenu().addLineListener(new LineListener());\n this.view.getToolsMenu().addPencilListener(new PencilListener());\n ... | {
"AcceptedAnswerId": "58381",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T18:19:57.167",
"Id": "58304",
"Score": "3",
"Tags": [
"java",
"design-patterns",
"mvc",
"swing"
],
"Title": "Implementation of MVC pattern with paintComponent method"
} | 58304 |
<p>I've created a lock-free job queue and with the tests I've written, which is also very fast.</p>
<p>That makes me doubt my benchmark procedure, so I'm hoping the collective knowledge will shed some light on the validity of those.</p>
<p>The test basically increments an atomic value (each job is a single increment)... | [] | [
{
"body": "<p>One thing you should do is not use so many (if any) <code>using namespace</code> statements. This does make it a bit easier to write code, but it also can cause many problems with methods being confused with each other. For a detailed discussion of this, check out <a href=\"https://stackoverflow... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T21:15:39.973",
"Id": "58321",
"Score": "15",
"Tags": [
"c++",
"performance",
"c++11",
"queue",
"lock-free"
],
"Title": "Testing a lock-free job queue"
} | 58321 |
<p>This my first foray in F#, and I cannot think (yet) functional. I have implemented an interface for a discount curve and the implementation for a piecewise constant instant rate implementation.</p>
<p>I would like to have your opinion on how to make this more F#. Should I keep the second input of the constructor ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T23:43:58.393",
"Id": "105734",
"Score": "0",
"body": "Could you please post a sample input/output?"
}
] | [
{
"body": "<p>I can't see how tail recursion comes into the picture exactly, but I would start with putting a stop watch around the <code>do</code> that populates the cache and checking how much work it actually needs to do, just to see whether you couldn't get away with what you have now. There's certainly som... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T21:18:05.143",
"Id": "58323",
"Score": "6",
"Tags": [
"beginner",
"f#"
],
"Title": "Discount curve from instant rate"
} | 58323 |
<p>Please, help improve following code. I have list of users, item of the list has buttons <strong>remove</strong> (remove user from list) and <strong>profile</strong> (navigate to user profile). I use <code>MVVM</code> pattern and GalaSoft MVVM Light Libraries.</p>
<p><strong>Model</strong></p>
<pre><code> public ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T23:10:16.593",
"Id": "104697",
"Score": "1",
"body": "The method mentioned in your postscript is probably the right strategy, only partially because it will respond to all events that select an item. Your main strategy might work so... | [
{
"body": "<p>Your code can use stricter access modifiers. For example, some of your properties look like they are not supposed to have public set accessor, yet they do. Commands can also be refactored to auto-properties. Apart from that your code looks pretty clean in my opinion.</p>\n\n<p><code>INotifyPropert... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T21:39:37.950",
"Id": "58324",
"Score": "2",
"Tags": [
"c#",
"design-patterns",
"mvvm",
"windows-phone"
],
"Title": "Select item of IEnumerable<T> in UI (MVVM)"
} | 58324 |
<p>I'm working on an algorithm to calculate <a href="http://mathworld.wolfram.com/WeirdNumber.html" rel="nofollow">weird numbers</a>, and to do so there are several properties that needs to be calculated, one of them being, if it is NOT a <a href="http://mathworld.wolfram.com/PseudoperfectNumber.html" rel="nofollow">se... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T01:27:01.123",
"Id": "104713",
"Score": "0",
"body": "\"It really is ineffective to calculate if a number is semi perfect, just to know if it is NOT.\" Determining if a number is *not* semi-perfect is just as hard as determining if ... | [
{
"body": "<p>I have bad news. From the link you posted,</p>\n\n<blockquote>\n <p>Identifying pseudoperfect numbers is therefore equivalent to solving\n the subset sum problem.</p>\n</blockquote>\n\n<p>and a subset sum article states that</p>\n\n<blockquote>\n <p>The given sum problem is NP-complete.</p>\n</... | {
"AcceptedAnswerId": "58722",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T22:41:04.673",
"Id": "58326",
"Score": "11",
"Tags": [
"java",
"optimization",
"algorithm",
"recursion",
"mathematics"
],
"Title": "Algorithm to calculate semi perfect ... | 58326 |
<p>Here is a C++ wrapper for <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms221482%28v=vs.85%29.aspx" rel="nofollow">SAFEARRAY</a>, including the ability to expose it as a VARIANT, and to create one out of VARIANT. </p>
<p>I am aware of CComSafeArray, however i don't use VC++ so I do not have li... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T22:36:19.477",
"Id": "104920",
"Score": "0",
"body": "What is `SAFEARRAY`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T22:41:26.320",
"Id": "104921",
"Score": "1",
"body": "@LokiAstari ... | [
{
"body": "<blockquote>\n <blockquote>\n <p>Array of VT_BOOL doesn't work, as my template type selector can't distinguish that from VT_I2 - is there any solution to this?</p>\n </blockquote>\n</blockquote>\n\n<p>Underneath the hood, a <code>VARIANT_BOOL</code> is just a <code>short</code>, so your map stra... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T22:47:20.480",
"Id": "58327",
"Score": "6",
"Tags": [
"c++",
"com"
],
"Title": "C++ Wrapper for SAFEARRAY"
} | 58327 |
<p>I've created a web page based on a sample from a book. It works fine, but seems to have become too complicated.</p>
<pre><code>'use strict';
function toggle (triggers, elements, per_trigger, events) {
function toggle(index, per, elem, func) {
for (var i = 0; i < per; i++)
func(elem[index+... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T01:38:55.810",
"Id": "104714",
"Score": "1",
"body": "Can you provide a jsbin giving an example of the functionality. Also what don't you like about your code now -- anything specific?"
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>I wrote this up using a lot more jQuery as an example. Confirmed working JSFiddle <a href=\"http://jsfiddle.net/80e5gjLz/\" rel=\"nofollow\">here</a>.</p>\n\n<p>You can see there's a considerably less lines of code, there's less boilerplate on each line (things like <code>document.getElementsByTag... | {
"AcceptedAnswerId": "59605",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T00:40:12.700",
"Id": "58336",
"Score": "3",
"Tags": [
"javascript",
"optimization",
"jquery"
],
"Title": "Web page based on a sample from a book"
} | 58336 |
<p>I'm currently on Azure Websites & Azure SQL, some documentation recommends using Async as much as possible as cloud services higher latency and have chances of dropping traffic, but it's also cautioning that Async/Await have overhead.</p>
<p>Should I...</p>
<ol>
<li>Implement an IStoreRepository interface (alt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-03-26T15:47:35.343",
"Id": "153149",
"Score": "2",
"body": "I suggest naming your async methods \"SomethingAsync\". So \"GetById\" would be \"GetByIdAsync\". This in case you want to have a synchronous version of the method as well, but a... | [
{
"body": "<ol>\n<li><p>Always program to abstraction, meaning it is always preferred to write your code against interface or abstract class rather than specific implementation. So, <code>IStoreRepository</code> would be a good idea.</p></li>\n<li><p>If you are not going to ever change your implementation, do... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T02:04:26.030",
"Id": "58337",
"Score": "3",
"Tags": [
"c#",
"async-await",
"dapper",
"azure"
],
"Title": "Using dapper.net and repository pattern in Azure websites"
} | 58337 |
<p><a href="http://netty.io/" rel="nofollow">Netty</a> is an asynchronous event-driven network application framework written in Java. It is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T05:01:33.397",
"Id": "58341",
"Score": "0",
"Tags": null,
"Title": null
} | 58341 |
An open source asynchronous event-driven network application framework written in Java. It is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T05:01:33.397",
"Id": "58342",
"Score": "0",
"Tags": null,
"Title": null
} | 58342 |
<p>I have an Android app that shows some fragments, but I'm repeating lots of code.</p>
<p><strong>MainActivity.java</strong></p>
<pre><code>public class MainActivity extends FragmentActivity {
MyPagerAdapter pageAdapter;
ViewPager pager;
@Override
protected void onCreate(Bundle savedInstanceState) {... | [] | [
{
"body": "<p>The main problem is the difficulty of abstracting resources. After compilation, they can only be accessed by their unqiue identifiers, accessible through the generated class <code>R</code> which you already use: <code>R.layout.page1_layout</code>.</p>\n\n<h1>Step 1</h1>\n\n<p>Let's be strict about... | {
"AcceptedAnswerId": "58569",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T05:44:58.357",
"Id": "58344",
"Score": "2",
"Tags": [
"java",
"android"
],
"Title": "Refactoring Android fragments"
} | 58344 |
<p>I'd like to improve this selection sort code</p>
<pre><code>package com.arun.sort;
import java.util.Arrays;
public class SelectionSort {
public static void main(String[] args) {
int[] arr = { 5, 2, 131, 13, 11, 1 };
SelectionSort sort = new SelectionSort();
sort.selectionSort(arr);... | [] | [
{
"body": "<p>I think the <code>selectionSort</code> method better be a static method because the method does not require any internal state within <code>sort</code> object, which is <code>SelectionSort</code> class. </p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicens... | {
"AcceptedAnswerId": "58358",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T06:23:31.803",
"Id": "58346",
"Score": "0",
"Tags": [
"java",
"beginner",
"sorting"
],
"Title": "Selection sorting an int array"
} | 58346 |
<p>I have the block of code from my project service layer and I'm not happy with it. It seems overly complex and I would hate to have to calculate the cyclomatic complexity. This block is called in response to a web service request and it is supposed to process the request depending on the fields that are set. It needs... | [] | [
{
"body": "<p>in my opinion, the problem with this code is well described by on of your first sentences:</p>\n\n<blockquote>\n <p>It needs to be able to handle the creation of a new contact list with supplied valid contacts, update an existing contact list with existing valid contacts and update an existing co... | {
"AcceptedAnswerId": "58387",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T06:49:35.577",
"Id": "58347",
"Score": "1",
"Tags": [
"java",
"spring"
],
"Title": "Java service layer code cleanup"
} | 58347 |
<p>Following-up on <a href="https://codereview.stackexchange.com/q/57889/23788">this post</a> where I implemented a <em>Repository Pattern</em> in <a href="/questions/tagged/vba" class="post-tag" title="show questions tagged 'vba'" rel="tag">vba</a> to abstract ADODB and enable testing my Excel app without hitt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-11-06T14:23:44.193",
"Id": "126128",
"Score": "5",
"body": "\"The problem is that `Implements` doesn't support events.\" <--- this :'("
}
] | [
{
"body": "<p>There's usually very little I can say about your code, but maybe if I just start going down line by line I'll find something. I'm hoping someone else who knows more about <a href=\"/questions/tagged/mvp\" class=\"post-tag\" title=\"show questions tagged 'mvp'\" rel=\"tag\">mvp</a> and <a h... | {
"AcceptedAnswerId": "58442",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T06:59:08.347",
"Id": "58348",
"Score": "19",
"Tags": [
"object-oriented",
"design-patterns",
"vba",
"dependency-injection",
"mvp"
],
"Title": "Down the rabbit hole with... | 58348 |
<p><a href="https://codereview.stackexchange.com/q/58348/23788">Going down the rabbit hole</a>, I wanted to be able to change the size of a form, and not have to worry about the layout of the controls.</p>
<p><a href="/questions/tagged/vba" class="post-tag" title="show questions tagged 'vba'" rel="tag">vba</a>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T12:18:29.643",
"Id": "104773",
"Score": "0",
"body": "And your question is...? Why did you put this code up for review? Do you think it can't be better (and are looking for confirmation), do you think it should be better (and are lo... | [
{
"body": "<p>I really like this method of declaring a bitwise enum.</p>\n\n<pre><code>Public Enum AnchorEdges\n LeftAnchor = 2 ^ 0\n TopAnchor = 2 ^ 1\n RightAnchor = 2 ^ 2\n BottomAnchor = 2 ^ 3\n AnchorAll = LeftAnchor + TopAnchor + RightAnchor + BottomAnchor\nEnd Enum\n</code></pre>\n\n<p>I f... | {
"AcceptedAnswerId": "58585",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T07:00:48.170",
"Id": "58349",
"Score": "8",
"Tags": [
"object-oriented",
"vba",
"mvp",
"layout"
],
"Title": "Honey I shrunk the view"
} | 58349 |
<p>I have accomplished what I wanted to do but I think this can be done better. I want my code to look professional.</p>
<p>What my code does is ask for your name and gives output in below form.</p>
<blockquote>
<p>Input: Jack</p>
<p>Output: j = joyful a = awesome c = curious k = kindhearted</p>
</blockquote>
<p>Please... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T07:45:13.933",
"Id": "104740",
"Score": "2",
"body": "Welcome to CodeReview.SE ! Can you tell us more about what your code is supposed to do ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T07:50:15.... | [
{
"body": "<p><strong>Style</strong></p>\n\n<p>A few things can be easily detected/improved in your code regarding the style. If you want, you'll find various tools to perform checks automatically : <code>pep8</code>, <code>pyflakes</code>, <code>pychecker</code>. They'll give you a great deal of interesting in... | {
"AcceptedAnswerId": "58354",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T07:37:00.060",
"Id": "58351",
"Score": "3",
"Tags": [
"python",
"beginner",
"python-2.x"
],
"Title": "A simple prompt-and-print program"
} | 58351 |
<p>I'm using the following query for multiple transactions. This is the scenario. </p>
<p><em>Generate Salary</em> (this is not in the scope of the query)
I have employee attendance in <code>Attendance</code> table. Then the salary is calculate from the attendance by using a stored procedure and resulting figures will... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T14:16:28.053",
"Id": "104803",
"Score": "0",
"body": "This code doesn't seem to be working as it is."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T16:45:06.670",
"Id": "104832",
"Score": "0"... | [
{
"body": "<p>As this method is quite large, let's start digging through the code.</p>\n\n<ul>\n<li><code>insertStatement</code> should be a <code>const</code> on class level</li>\n<li><p>The creation of the SqlParameters can be extracted to a method</p>\n\n<pre><code>private SqlParameter[] GetInsertEarningsPar... | {
"AcceptedAnswerId": "58625",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T07:47:00.957",
"Id": "58353",
"Score": "4",
"Tags": [
"c#",
"sql",
"sql-server",
"ado.net"
],
"Title": "Batch of SQL statements in a single query"
} | 58353 |
<p>I'm struggling with manually implementing a simple purely functional <code>Set</code> that's also generic and covariant on its type parameter:</p>
<ul>
<li><code>Set</code> must be a trait, allowing for multiple implementations.</li>
<li>it must be covariant on the type of the element it contains.</li>
<li>an imple... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T20:30:28.743",
"Id": "104753",
"Score": "0",
"body": "It might help to add the name of the programming language you're using to the question somewhere if it isn't a C-style language. I'm sure whoever sees this will know based on th... | [
{
"body": "<ol>\n<li><p>The <code>this: Repr[A]</code> is not absolutely necessary, but it you omit it, you're encoding a sort of weird type constraint:\nthat the class is not necessarily a <code>Repr</code>, but its <code>insert[B]</code> must produce a <code>Repr[B]</code> (who's <code>insert[C]</code> produc... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-28T20:15:53.480",
"Id": "58365",
"Score": "12",
"Tags": [
"scala",
"set"
],
"Title": "Implementing a generic and covariant Set in Scala"
} | 58365 |
<p>I'm trying to get familiar with database handling. Can you point out my errors and what I should change?</p>
<p>I want to learn new methods, but just don't want to learn it the wrong way.</p>
<p>I do realize these things below, yet I wanted to make the code more clear:</p>
<ul>
<li>I need to bind values for <cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T18:07:44.760",
"Id": "104870",
"Score": "3",
"body": "I **highly** suggest you learn how other DBALs function, [such as Doctrine](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/). This will help you structure your... | [
{
"body": "<h1><strong>Passwords as plain text!?</strong></h1>\n<p>If I were using an application or website that stored my password as plain text where anyone with access to the DB seeing this would make me feel very scared:</p>\n<pre><code>// inserts into database\n$query->insert('users')\n ->col... | {
"AcceptedAnswerId": "61059",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T10:16:13.743",
"Id": "58366",
"Score": "6",
"Tags": [
"php",
"object-oriented",
"mysql"
],
"Title": "Database layer class"
} | 58366 |
<pre><code>private void find_tile(float[] x, float[] z, int nRigidBodies) {
int serial[]=new int[nRigidBodies];
int numTiles=4;
for(int i=0;i<nRigidBodies;i++)
{
// Check for the loaction of each tile to find which one should be switched on...
//currently only supports 4
for... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T11:51:42.667",
"Id": "104767",
"Score": "0",
"body": "You may want to look into algorithmic improvement, though I am not familiar with any myself. Before people will say that Java is bad for real time physics, remember that you are ... | [
{
"body": "<p><strong>Disclaimer: I have not tested any of these optimizations. Some of these optimizations could potentially even harm the speed - or they could already be covered by the JVM. Do your own benchmarking.</strong></p>\n\n<p><strong>Helping the Compiler/JVM</strong><br>\nIf you don't need to overri... | {
"AcceptedAnswerId": "58374",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T10:28:20.960",
"Id": "58367",
"Score": "1",
"Tags": [
"java",
"optimization",
"performance"
],
"Title": "Optimizing a function with nested loops and if condition"
} | 58367 |
<p>I have created a query in which there is a column that calculates a percentage:</p>
<pre><code>SELECT
u.User_FirstName
,l.[Total Leads]
,SUM(s.SalesCount) AS [New Clients]
,c.Target
,CONVERT(VARCHAR, CONVERT(DECIMAL(11,0),ROUND((CONVERT(DECIMAL(11,2), SUM(s.SalesCount)) / l.[Total Leads]) * 10... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T12:56:57.000",
"Id": "104783",
"Score": "0",
"body": "I'm assuming that `SalesCount` and `TotalSales` are integers?"
}
] | [
{
"body": "<p>You can use implicit numeric conversion to save you a lot of coding here. Specifically, if you use <code>100.0</code> instead of <code>100</code> you will do floating-point arithmetic automatically. Consider the following:</p>\n\n<pre><code>100.0 * SUM([SalesCount]) / [Total Leads]\n</code></pre>\... | {
"AcceptedAnswerId": "58382",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T10:48:29.513",
"Id": "58369",
"Score": "4",
"Tags": [
"sql",
"sql-server",
"floating-point"
],
"Title": "SQL percentage calculation"
} | 58369 |
<p>I'm currently working on an API package. Basically what it does is scrapes team data and stores them in list of Team objects. The team object contains data such as Team.name,rank, country etc.</p>
<p>If a user wants to filter that list to find something in it, I have this really messy and ugly (but working) functio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T14:25:02.710",
"Id": "104807",
"Score": "0",
"body": "[What you can and cannot do after receiving answers](http://meta.codereview.stackexchange.com/a/1765)"
}
] | [
{
"body": "<pre><code> if name:\n if name.lower() == team.name.lower():\n all_args.append(True)\n else:\n all_args.append(False)\n if country:\n if country.lower() == team.country.lower():\n all_args.append(True)\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T13:37:08.297",
"Id": "58380",
"Score": "1",
"Tags": [
"python"
],
"Title": "Filtering data stored using classes via user-called function the proper way?"
} | 58380 |
<p>I have written the following code for returning the list of prime factors. Any speed-enhancing suggestions?</p>
<pre><code>import math
def is_prime(num):
for n in range(2,math.floor(math.sqrt(num)+1)):
if num%n==0:
return False
return True
def find_prime_factors(num):
prim... | [] | [
{
"body": "<h2>Correctness</h2>\n\n<p>1 is not a prime factor:</p>\n\n<pre><code>>>> find_prime_factors(25)\n[5, 5, 1]\n</code></pre>\n\n<h2>Performance</h2>\n\n<p>Primality testing is expensive. You call <code>is_prime()</code> <em>twice</em> on every iteration of the main loop of <code>find_prime_fa... | {
"AcceptedAnswerId": "58388",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T13:56:27.483",
"Id": "58384",
"Score": "1",
"Tags": [
"python",
"performance",
"primes",
"python-3.x"
],
"Title": "Speeding up prime factorization"
} | 58384 |
<p>This is my first SQL post over here, and in fact, I have more or less the experience of a regular SQL programmer, except that the task at hand this time was way harder than normal.</p>
<p>I am expecting, hoping and almost demanding a better version of my code, because my version is really bad, but I do not know how... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T15:06:08.317",
"Id": "104811",
"Score": "0",
"body": "What do you expect `select_templates_with_organization_ids('1001,1002')` to return?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T15:08:30.417",... | [
{
"body": "<p>Easy with a number table.</p>\n\n<pre><code>CREATE TABLE `Num` (`N` INT(11) PRIMARY KEY AUTO_INCREMENT);\nINSERT INTO `Num` () VALUES\n ()\n , ()\n , ()\n , ()\n , ()\n , ()\n , ()\n , ()\n , ()\n , ()\n , ()\n , ()\n , ();\n</code></pre>\n\n<p>So, take the input string (declared in... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T14:36:46.647",
"Id": "58389",
"Score": "5",
"Tags": [
"sql",
"database",
"stored-procedure"
],
"Title": "Selecting template from database using organization ids"
} | 58389 |
<pre><code>var searchUser = function(searchQuery){
var request = $.ajax({
url:"search.php",
type: "POST",
data: { search:searchQuery},
success: function(reply){
$("#search-box").css("display", "block");
$("#search-box").html(reply);
}
});
}
</code>... | [] | [
{
"body": "<ul>\n<li>You should ensure your spacing is consistent.</li>\n<li>Since you're using a function <em>expression</em> rather than a <em>declaration</em>, you should terminate the line with a semicolon.</li>\n<li>You aren't making any use of the <code>request</code> variable, so why even declare it?</li... | {
"AcceptedAnswerId": "58431",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T15:18:58.830",
"Id": "58393",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"ajax"
],
"Title": "Search suggestion box with jQuery and AJAX"
} | 58393 |
<p>I am tasked with cleaning up someone else's Objective-C code, and will admit it is not my language of choice. I am not sure if this is a valid question but was hoping someone could double check my attempt to clean up a method written by someone else, and make sure I didn't miss some minor detail or over simplify the... | [] | [
{
"body": "<p>There are two primary concerns I have.</p>\n\n<hr>\n\n<p>First, rather than accessing <code>[[UserManager sharedManager]isUserLoggedIn]</code> twice, let's access it just once:</p>\n\n<pre><code>BOOL loggedIn = [[UserManager sharedManager] isUserLoggedIn];\n</code></pre>\n\n<p>Now just use the <co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T15:35:08.667",
"Id": "58394",
"Score": "5",
"Tags": [
"objective-c",
"e-commerce",
"authorization"
],
"Title": "Shopping cart logic for authenticated users and guests"
} | 58394 |
<p>I have written two code pieces to check if a given string is a palindrome:</p>
<pre><code>public static bool FirstMethod(string str)
{
int i = 0;
int j = str.Length - 1;
while (i<j)
{
if (str[i] != str[j])
return false;
i++;
j--;
}
return true;
}
</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T16:23:38.520",
"Id": "104829",
"Score": "3",
"body": "I'm not sure either of the methods proposed is an actual valid response.\n\nWikipedia defines a palindrome as :\n\nA palindrome is a word, phrase, number, or other sequence of sy... | [
{
"body": "<p>The first one is probably a bit faster, the second could be cleaned up a bit, but is easier to read. Unless you know you have a performance problem, prefer the second one. </p>\n\n<p>For the second option, you should extract two sub-strings from the original input string called \"firstHalf\" and \... | {
"AcceptedAnswerId": "58400",
"CommentCount": "12",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T15:36:33.777",
"Id": "58395",
"Score": "30",
"Tags": [
"c#",
"palindrome",
"comparative-review"
],
"Title": "Check a string to see if it is a palindrome"
} | 58395 |
<p>If some big event handler is triggered too frequently, it will cause computer lagging.</p>
<p>In my example <code>$(window).resize()</code>, I want the function to be called after the user has completed his resize, instead of firing every time you resize by a single pixel.</p>
<p>So, I made this 'Function Buffer':... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T16:49:21.747",
"Id": "104835",
"Score": "5",
"body": "I believe this is called *event throttling* (fire at most once every *x* milliseconds) or *event debouncing* (fire at most once, at the completion of an action)."
}
] | [
{
"body": "<p>As mentioned in the comments, this is usually called \"debouncing.\"</p>\n\n<p>A simpler and easier-to-use approach would be something like this:</p>\n\n<pre><code>function debounce(fn, delay) {\n var timeout;\n\n return function () {\n var context = this,\n args = argument... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T16:28:16.513",
"Id": "58406",
"Score": "8",
"Tags": [
"javascript",
"jquery",
"event-handling"
],
"Title": "\"Function Buffer\" to avoid triggering an event handler too frequently... | 58406 |
<p>This is another solution for <a href="http://www.cprogramming.com/challenges/celsius_converter_table.html" rel="nofollow">this challenge</a>.</p>
<p>Problem statement:</p>
<blockquote>
<p>In this challenge, write a program that takes in three arguments, a
start temperature (in Celsius), an end temperature (in ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T16:49:50.797",
"Id": "104836",
"Score": "0",
"body": "http://codereview.stackexchange.com/q/44836/9357"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T16:50:50.210",
"Id": "104838",
"Score": "... | [
{
"body": "<ul>\n<li>Don't use <code>#import</code>. This is not standard C++, and will be treated differently by different compilers. <a href=\"http://msdn.microsoft.com/en-us/library/8etzzkb6.aspx\" rel=\"nofollow noreferrer\">Microsoft uses it to indicate that the included file is a type library</a>, while <... | {
"AcceptedAnswerId": "58414",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T16:42:43.530",
"Id": "58410",
"Score": "5",
"Tags": [
"c++",
"programming-challenge",
"converting"
],
"Title": "Temperature conversion table"
} | 58410 |
<p>Let me start by saying that I am brand new to PHP and MySQL.</p>
<p>I have two tables. One table is called domains and it contains the "rep" column which is an integer. It is related to the column "id" in the reps table. The reps table also houses the First and Last names of the rep assigned to a particular domain ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T17:01:23.783",
"Id": "104848",
"Score": "0",
"body": "love the question title :D"
}
] | [
{
"body": "<p>First, about your current code:</p>\n\n<ul>\n<li>You're doing a <code>SELECT *</code>. This is generally poor practice; instead, explicitly identify the columns you need: <code>SELECT id, first_name</code>.</li>\n<li>Your <code>$rep_array</code> is a lookup table, so name it as such. Maybe <code>$... | {
"AcceptedAnswerId": "58417",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T16:55:11.150",
"Id": "58412",
"Score": "5",
"Tags": [
"php",
"mysql",
"join"
],
"Title": "I think I should use JOIN but I did this instead"
} | 58412 |
<p>I was actually pretty proud of this programming project that I came across in this book I'm working through. I only really had problems figuring out the formula for detecting whether or not the two circles had intersecting paths. I'm still getting the hang of object-oriented programming, primarily when and where to ... | [] | [
{
"body": "<ol>\n<li><p>Constructor</p>\n\n<pre><code>CircleInfo(String circleLabel, double centerX, double centerY, double radius)\n</code></pre>\n\n<p>can be simplified to</p>\n\n<pre><code>CircleInfo(String circleLabel, CircleObject obj)\n</code></pre>\n\n<p>because the constructor can get x, y and radius fr... | {
"AcceptedAnswerId": "58487",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T17:38:41.063",
"Id": "58419",
"Score": "14",
"Tags": [
"java",
"computational-geometry",
"javafx"
],
"Title": "Detecting two intersecting circles with editable x, y, and radius... | 58419 |
<p>I have a statistics query I'm trying to run against the below table:</p>
<pre><code>CREATE TABLE "*****"."RUN_D"
(
"WHSE_CODE" CHAR(12 BYTE),
"RUN_NUM" NUMBER(*,0),
"SHEET_NUM" NUMBER(*,0),
"SHEET_SEQ" NUMBER(*,0),
"COUNT_DATE" DATE,
"COUNTED" CHAR(1 BYTE),
"ITEM_NUM" CHAR(30 BYTE),
"BIN_CODE" CHAR(10 BY... | [] | [
{
"body": "<p>No, I cannot see a better way. The group-by constraints are different for the selects, so there is no way to merge them in to one.</p>\n\n<p>The remainder of your code looks good, except I am concerned about your % calculations.... are they accurate?</p>\n\n<blockquote>\n<pre><code>(vary.Variance_... | {
"AcceptedAnswerId": "58425",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T17:50:45.143",
"Id": "58420",
"Score": "6",
"Tags": [
"sql",
"oracle"
],
"Title": "Trying to avoid a double full scan with aggregates in query"
} | 58420 |
<p>I have written a solution for <a href="https://projecteuler.net/problem=28" rel="nofollow">Problem 28</a>.</p>
<blockquote>
<p>Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:</p>
<p>$$\begin{array}{rrrrr}
\color{red}{21} &22 &23 &2... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T19:18:11.623",
"Id": "104890",
"Score": "0",
"body": "I literally just answered this question using a single loop http://codereview.stackexchange.com/a/58409/50094"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<p>It doesn't even need a loop if you simplify:</p>\n\n<ol>\n<li>Notice each shell has a top right corner that is an odd number squared... 1,3,5</li>\n<li>Notice each shell only adds 4 numbers: the square of an odd number (2n-1)^2, the same number with the distance to the previous corner removed, the... | {
"AcceptedAnswerId": "58434",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T18:15:57.473",
"Id": "58423",
"Score": "3",
"Tags": [
"python",
"performance",
"beginner",
"programming-challenge"
],
"Title": "Efficiency of Project Euler 28 - number spir... | 58423 |
<p>This is my sample code to find maximum occurrence of characters in string in C#.</p>
<p>How can I make it better?</p>
<pre><code>public static int GetMaximumOccurence(string str)
{
int _maxcount = 0;
foreach (char c in str)
{
int ix = str.IndexOf(c);
int count = 0;
while (ix!=-... | [] | [
{
"body": "<p>Your code is using a wildcard (' '), wildcards are generally bad as someone else pointed. As a general advice, I would recommend you to avoid writing algorithms based on adding a wildcard when it can be part of the input.</p>\n\n<p>EDIT: this works only if the string does not special UNICODE value... | {
"AcceptedAnswerId": "58469",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T18:22:14.683",
"Id": "58424",
"Score": "5",
"Tags": [
"c#",
"algorithm",
"strings"
],
"Title": "Counting the most frequently appearing character in a string (i.e. the statistic... | 58424 |
<p>The goal of the code is to </p>
<ul>
<li>initialize a Dialog with settings
<ul>
<li>make sure the object is reusable</li>
</ul></li>
<li>Setup the options to reuse the code </li>
</ul>
<p>I'm not quite sure if this is overkill, or I am going about this problem in the entirely wrong way. Any input would be apprecia... | [] | [
{
"body": "<p>It is already a good attempt at making better-looking code. Just a few improvement:</p>\n\n<ol>\n<li><p>Declare all <code>private</code> functions one-by-one with declaring that individual just like you declare your variable (see jQuery code).</p></li>\n<li><p>There is no need for the <code>updat... | {
"AcceptedAnswerId": "58475",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T18:30:15.920",
"Id": "58428",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"jquery-ui"
],
"Title": "jQuery Dialog Settings"
} | 58428 |
<p>I'm working on a client-side API for my ASP.net MVC application and I'm not quite sure I've got the code right. This API allows me to call server-side action methods via Ajax and I've designed it to have a similar call syntax like jQuery uses.</p>
<p>Is the variable <code>HomeActions._ajaxSettings</code> static the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T05:54:46.683",
"Id": "105517",
"Score": "0",
"body": "But, is this javascript? In javascript there's no \"static\" as in Java or C# and there are no concurrency issues since javascript is single thread."
}
] | [
{
"body": "<p>After some testing I discovered that <code>HomeActions._ajaxSettings</code> is indeed static and would cause issues if simultaneous calls were made to the API. After some time away from the code the obvious solution popped into my head as shown below. I've been too caught up in learning the confu... | {
"AcceptedAnswerId": "58719",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T18:58:41.177",
"Id": "58432",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"asp.net-mvc"
],
"Title": "Client-side API design"
} | 58432 |
<blockquote>
<p>Given a doubly linked list which has data members sorted in ascending
order, construct a balanced binary search tree which has same data
members as the given doubly linked list. The tree must be constructed
in-place (no new node should be allocated for tree conversion).</p>
</blockquote>
<p>Thi... | [] | [
{
"body": "<p>(Duplicated answer from here: <a href=\"https://codereview.stackexchange.com/a/63125/49350\">https://codereview.stackexchange.com/a/63125/49350</a>)</p>\n\n<p>Bug:</p>\n\n<p><code>IndexOutOfBoundsException</code> on empty list in <code>BinaryTree.create(List<? extends T> items)</code>. You d... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T19:03:24.527",
"Id": "58433",
"Score": "1",
"Tags": [
"java",
"algorithm",
"linked-list",
"tree"
],
"Title": "Convert a doubly linked list into balanced binary search tree in-... | 58433 |
<p>Here's what I ended up with for <em>Learning Python the Hard Way Ex 51</em> with image upload (save and display).</p>
<p>The form:</p>
<pre><code><div style="margin:300px;border:1px solid #000">
<form method="POST" enctype="multipart/form-data" action="upload">
A Greeting: <input type="text" name="g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T08:20:33.903",
"Id": "104983",
"Score": "0",
"body": "The `upload_form` template seems to be missing. Could you add it to make it easier to run the code and answer your question?"
}
] | [
{
"body": "<p>As pointed out by my comment above, a template is missing. Once it's available, I'll try to expand my answer to cover your question.</p>\n\n<p>In the meantime, please find below a few comments:</p>\n\n<ul>\n<li>Style (<a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T19:25:47.990",
"Id": "58436",
"Score": "-1",
"Tags": [
"python",
"beginner"
],
"Title": "LPTHW Ex51 with image upload"
} | 58436 |
<p>I've been reading "Head First Java" and some of the early projects surround basic swing and basic MIDI.</p>
<p>So I've put the two together and written a basic "Synthesiser"/"Piano" using what I have learned.</p>
<p>I know that I need to add some safety features and there's probably some method optimisation starin... | [] | [
{
"body": "<pre><code>import javax.swing.*;\nimport javax.sound.midi.*;\nimport java.awt.*;\nimport java.awt.event.*;\n</code></pre>\n\n<p>Most style guides will frown upon the wildcard import -- is it so much extra work to list the classes you actually depend on? This will also help you to avoid conflicts, wh... | {
"AcceptedAnswerId": "58443",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T19:33:58.203",
"Id": "58439",
"Score": "9",
"Tags": [
"java",
"swing",
"audio",
"music"
],
"Title": "Very Basic Java Piano"
} | 58439 |
<p>This is a programming contest question. Question as follows</p>
<h2>Problem Definition</h2>
<blockquote>
<p>An ISBN (International Standard Book Number) is a ten digit code that
uniquely identifies a book. The first 9 digits are used to represent
the book and the 10th digit is used to ensure that the ISBN is... | [] | [
{
"body": "<h2>Overview</h2>\n\n<p>Your code is generally pretty good, but there are places where it can be edited.</p>\n\n<h2>Let's start off with...</h2>\n\n<blockquote>\n<pre><code>private boolean isValid(String input) {\n if (input.length() != ISBN_CODE_LENGTH) {\n return false;\n }\n if (!i... | {
"AcceptedAnswerId": "58449",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T22:02:39.353",
"Id": "58441",
"Score": "17",
"Tags": [
"java",
"programming-challenge",
"validation"
],
"Title": "ISBN missing number solver"
} | 58441 |
<blockquote>
<p>Find the union and intersection of linked list, given that elements
don't repeat in a single linked list.</p>
</blockquote>
<p>This question is attributed to GeeksForGeeks. Looking for code-review, optimizations and best practices.</p>
<pre><code>public class IntersectionAndUnionLinkedList<T>... | [] | [
{
"body": "<h2>Intersection</h2>\n\n<p>it seems a little like cheating to me to use a <code>HashSet</code> here. I would probably write my own contains method for the linked list (which is bad for performance, but performance is not really the point here).</p>\n\n<p>Other than that:</p>\n\n<pre><code>largerList... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T22:36:56.207",
"Id": "58444",
"Score": "1",
"Tags": [
"java",
"algorithm",
"linked-list"
],
"Title": "Find union and intersection of linked list"
} | 58444 |
<p>A dollar word is a word for which the sum of the values of the letters adds up to 100 ($1.00).</p>
<p>"a" has a value of 1 and "z" has a value of 26. Special characters such as apostrophes are ignored.</p>
<p>First try looked like:</p>
<pre><code>import string
valMap = {}
for index,item in enumerate(string.lowe... | [] | [
{
"body": "<h2>Strategic themes</h2>\n\n<ul>\n<li><strong>Prefer comprehensions to loops:</strong> List comprehensions and dict comprehensions let you compress loops into one-liners. It's also a nice feeling to initialize an object \"all at once\" rather than building it little by little.</li>\n<li><strong>Avo... | {
"AcceptedAnswerId": "58462",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T23:05:15.773",
"Id": "58446",
"Score": "5",
"Tags": [
"python",
"strings",
"i18n"
],
"Title": "Program to find dollar words"
} | 58446 |
<p>My <code>Function</code> class is similar to <code>std::function</code> with the small-buffer optimization. However, it <em>always</em> uses a small buffer and static asserts if the required size exceeds it.</p>
<p>I would like a review for:</p>
<ul>
<li>correct use of the low-level features</li>
<li>general clas... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T23:39:26.967",
"Id": "104929",
"Score": "1",
"body": "Why reinvent working technology that is part of the standard already?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T23:42:36.420",
"Id": "10... | [
{
"body": "<p>Generally, I can't see any real problems, but there are a few things that I'm going to point out:</p>\n\n<p>In the assignment operator, you use <code>std::swap(storage, rhs.storage)</code> and declare it as <code>noexcept</code>. This should probably be conditionally <code>noexcept</code>, based o... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T23:10:13.683",
"Id": "58447",
"Score": "20",
"Tags": [
"c++",
"c++11"
],
"Title": "Function wrapper like std::function that uses \"small buffer\" allocation"
} | 58447 |
<p>I'd like to make sure I'm following some basic coding best practices since I've had only little practice creating my own classes and using pinvoke. I've found this class to be pretty useful and I'd like to put it up online but not if it's a poorly written or could cause issues I haven't considered. </p>
<p>I would... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T01:11:24.513",
"Id": "104960",
"Score": "0",
"body": "Is there a reason you're not using `Microsoft.Win32.Registry`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T01:13:25.760",
"Id": "104961",
... | [
{
"body": "<p><strong>Scope of methods and const</strong></p>\n\n<p>There is no reason for <code>KEY_QUERY_VALUE</code> to has a public scope. The same is true for the <code>doQuery()</code> method.</p>\n\n<p><strong>Naming</strong></p>\n\n<p>Following the <a href=\"http://msdn.microsoft.com/en-us/library/ms229... | {
"AcceptedAnswerId": "58476",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T00:59:18.903",
"Id": "58454",
"Score": "5",
"Tags": [
"c#",
"classes"
],
"Title": "Class for RegQueryInfoKey pinvoke"
} | 58454 |
<p>Check if all leaves are at same level. This question is attributed to geek for geeks. Looking for code-review, optimization and best practices.</p>
<pre><code>public class LeavesLevel<T> {
private TreeNode<T> root;
public LeavesLevel(List<T> items) {
create (items);
}
pr... | [] | [
{
"body": "<p>To determine whether a tree has all leaves at the same level, it is sufficient to check that</p>\n\n<pre><code>depth(node.left) == depth(node.right)\n</code></pre>\n\n<p>for all nodes. So you can do this something like:</p>\n\n<pre><code>boolean leaves_same_level(TreeNode<T> node)\n{\n re... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T01:01:34.087",
"Id": "58455",
"Score": "1",
"Tags": [
"java",
"algorithm",
"tree"
],
"Title": "Check if all leaves are at same level"
} | 58455 |
<blockquote>
<p>-Hello Agent. Are you on a secure line?</p>
<p>-Yes, secured.</p>
<p>-Good, in 30 seconds the launch codes will be in your e-mail's inbox.
You now have the go. Are you ready for the package?</p>
<p>-Yes.</p>
<p>-The key is: "revi3wJAVA-fim++". You should have the codes by now. Be... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T18:49:53.633",
"Id": "106222",
"Score": "0",
"body": "that question doesn't even have an answer!"
}
] | [
{
"body": "<p>Well, I don't know much about PHP; but I know a little about security so that is what I am going to review. First I am going to review your encryption algorithm: <a href=\"https://en.wikipedia.org/wiki/Advanced_Encryption_Standard\">AES-192</a>. </p>\n\n<ul>\n<li><p>In June 2003, the U.S. Govern... | {
"AcceptedAnswerId": "58526",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T01:06:19.320",
"Id": "58457",
"Score": "15",
"Tags": [
"php",
"security",
"php5",
"cryptography",
"rags-to-riches"
],
"Title": "Cryptographically-secure super-secret go... | 58457 |
<p>I am doing Project Euler problem #6. This is the <strong>question</strong> it asks:</p>
<blockquote>
<p>The sum of the squares of the first ten natural numbers is,</p>
<p>$$1^2 + 2^2 + \ldots + 10^2 = 385$$</p>
<p>The square of the sum of the first ten natural numbers is,</p>
<p>$$(1 + 2 + \ldots +... | [] | [
{
"body": "<p>Your implementation looks fine. This calculation is so trivial for a computer to do that it's not worth spending much time optimizing the implementation.</p>\n\n<p>That said, the fact that you called <code>print</code> without parentheses indicates that you are using Python 2. In Python 2, <a hr... | {
"AcceptedAnswerId": "58470",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T02:39:07.777",
"Id": "58460",
"Score": "11",
"Tags": [
"python",
"programming-challenge"
],
"Title": "Sum of Squares/Square of Sum Difference"
} | 58460 |
<p>I am trying to write a simple domino (five-game) game with 2 players. I must say I am very bad at OOP design, and so I don't want to get myself too deep into coding then realize I have a bad design to start with. I'd appreciate if someone shed some light on how to better design this.</p>
<p>Here is summary of the g... | [] | [
{
"body": "<p>I think this is a good exercise for trying out OOP design. When I was learning OOP I found that working with real-life objects helped a lot and slowly I started getting use to objects that represented abstract concepts. In this example you have a mixture, real-life dominoes and abstract concepts... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T03:22:11.713",
"Id": "58464",
"Score": "7",
"Tags": [
"c#",
"object-oriented",
"game"
],
"Title": "Basic domino game architecture"
} | 58464 |
<blockquote>
<p>Given a singly linked list, remove all the nodes which have a greater
value on right side.</p>
<p>Examples:</p>
<p>a) The list 12->15->10->11->5->6->2->3->NULL should be changed to
15->11->6->3->NULL. Note that 12, 10, 5 and 2 have been deleted
because there is a greater value on the r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T08:55:01.253",
"Id": "104991",
"Score": "1",
"body": "Question: Is the behaviour for a linked list: \"12->15->10->16->5->2->3->NULL\" defined? \"on the right side\" is a little unclear IMO. It could be either: \"15->16->5->3->NULL\"... | [
{
"body": "<p>Nice code. I'm assuming that you read Vogel612 comment and it is doing what you want it to do. </p>\n\n<h2>Naming</h2>\n\n<ul>\n<li><code>ptrNext</code>, <code>ptr</code>, but then only <code>prev</code>? I would make this uniform.\nProbably: <code>next</code>, <code>current</code>, and <code>prev... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T05:41:37.390",
"Id": "58471",
"Score": "2",
"Tags": [
"java",
"linked-list"
],
"Title": "Delete nodes in linkedlist whose next node is greater"
} | 58471 |
<p>I'm new to Java programming and am really enjoying it. I made a bitshift program, but I think it's too long.</p>
<p>I expect the program to:</p>
<ol>
<li>Let users input the number and degree to be shifted</li>
<li>Specify if it is a right or left shift</li>
<li>Restart the program if the user requires at the end<... | [] | [
{
"body": "<p>I think you can do away with the Class BitShift and write your functionality in one class only, unless you can give me some specific reason for using inheritance. Also, i think instead of calling the method and taking the input, you can just ask the user to give the option of his choice and then u... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T03:47:22.640",
"Id": "58472",
"Score": "4",
"Tags": [
"java",
"beginner",
"bitwise"
],
"Title": "BitShift code compacting"
} | 58472 |
<p>I implemented <code>qsort()</code> like this. I was wondering what improvements I could do to make it better.</p>
<pre><code>public static void qsort(int[] a, int start, int end) {
if (start >= end) return;
int pivot = start;
int lt = start + 1;
int gt = end;
int temp;
while (lt <= gt)... | [] | [
{
"body": "<p>One thing I quickly spot is this:<br>\nIf your second while loop completes naturally instead of via a <code>break</code>, you will also exit the first while loop. Thus the last instruction executed, <code>gt--</code>, is unnecessary.</p>\n\n<p>Let's look at the execution paths:</p>\n\n<pre><code>... | {
"AcceptedAnswerId": "58486",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T06:49:48.207",
"Id": "58477",
"Score": "4",
"Tags": [
"java",
"sorting",
"quick-sort"
],
"Title": "Potential quicksort optimizations"
} | 58477 |
<p>In some ways, <a href="http://bem.info/" rel="nofollow">BEM</a> is similar to OOP. It's a way of describing reality in code, a range of patterns, and a way of thinking about program entities regardless of programming languages being used.</p>
<p>BEM principles are used to create a set of front-end development techn... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T08:55:57.630",
"Id": "58481",
"Score": "0",
"Tags": null,
"Title": null
} | 58481 |
BEM, short for Block-Element-Modifier, is a way to develop modular web pages which are easy to support. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T08:55:57.630",
"Id": "58482",
"Score": "0",
"Tags": null,
"Title": null
} | 58482 |
<p>I have the following Ruby code that's designed to update item, price and stock data for items in a MSSQL database. It's running on a Ruby 1.8.6/Rails 1.2.3 installation, in its own controller (for now)</p>
<p>What I'm looking for is <em>ways to optimize performance</em>. </p>
<p>Right now each item takes about 0,2... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T10:25:58.960",
"Id": "105006",
"Score": "1",
"body": "Take a look at [How to import and export XML using BulkInsert.](http://msdn.microsoft.com/en-us/library/ms191184.aspx)"
}
] | [
{
"body": "<p>As for performance, I definitely think you want to use <a href=\"http://msdn.microsoft.com/en-us/library/ms191184.aspx\" rel=\"nofollow\">SQL's Bulk Insert from XML functionality</a>. I don't know how to use it from Ruby, so I'll leave that to another reviewer.</p>\n\n<p>I do want to point out som... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T08:58:21.757",
"Id": "58483",
"Score": "3",
"Tags": [
"ruby",
"sql-server"
],
"Title": "Optimize mass import of XML to SQLServer in Ruby"
} | 58483 |
<p>I have written myself a little JavaScript library for personal use, and anyone who'd like to use it for some reason. The reason why I decided to create my own library instead of using the already existing ones is that I have found out in the course of practice that I only use a very small amount of the functionality... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T13:21:22.690",
"Id": "105035",
"Score": "4",
"body": "Since nobody has reviewed this yet, I don't think there would be a problem with updating the question with your new code. No sense having something reviewed that might not exist ... | [
{
"body": "<h3>Wrap your library code and use strict mode</h3>\n\n<pre><code>(function (exports) {\n \"use strict\";\n\n // ...\n return MF;\n})(window.MF || (window.MF = {}));\n</code></pre>\n\n<ol>\n<li>It allows you to assign a different name (\"namespace\") to your library.</li>\n<li>You are able to use ... | {
"AcceptedAnswerId": "58846",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T09:17:22.013",
"Id": "58484",
"Score": "4",
"Tags": [
"javascript",
"library"
],
"Title": "Yet another JavaScript library"
} | 58484 |
<p>I'm wondering if anyone can code review my code below. That's the core code of my little framework for bash in <a href="https://github.com/icasimpan/shcf" rel="nofollow">GitHub</a>.</p>
<pre><code>## ==========================================================================================
## FUNCTION : autoload_f... | [] | [
{
"body": "<h3>Bug because of subshell</h3>\n\n<p>You are losing the value of <code>ret_val</code> in a subshell here:</p>\n\n<blockquote>\n<pre><code>... || (echo \"ERROR: Missing required ${each_func}\"; ret_val=1)\n</code></pre>\n</blockquote>\n\n<p>Variable assignments in a subshell are local to the subshel... | {
"AcceptedAnswerId": "58501",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T09:23:15.137",
"Id": "58485",
"Score": "6",
"Tags": [
"bash",
"shell",
"dynamic-loading"
],
"Title": "Function autoloading in bash"
} | 58485 |
<p>I am building a website with heavy CSS3 transitions. The menu is hidden on the left and slides in on hover pushing the main content right. The menu contains transformed elements and has a semi transparent background.</p>
<p>I am concerned about the performance of the animations. When the animation is triggered seve... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T10:10:34.820",
"Id": "105003",
"Score": "2",
"body": "Works beautifully for me. I think this is the most efficient method."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T10:21:59.937",
"Id": "105... | [
{
"body": "<p>I'm pretty new to CSS, but I do have a few notes:</p>\n\n<ul>\n<li><p>As @Jivings said, the animation worked nicely for me. No stutter\nor anything.</p></li>\n<li><p>I would use <a href=\"https://fortawesome.github.io/Font-Awesome/\" rel=\"nofollow\">Font Awesome</a> instead of your envelope <cod... | {
"AcceptedAnswerId": "58579",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T09:54:46.700",
"Id": "58488",
"Score": "10",
"Tags": [
"performance",
"css",
"animation",
"css3"
],
"Title": "CSS3 transitions performance enhancement"
} | 58488 |
<p>I have a <code>view</code> which takes a <code>DataPresenterStrategy</code> instance to retrieve the proper text out of some data:</p>
<pre><code>public interface DataPresenterStrategy {
String getDisplayString(Data data);
String getUnit();
}
public class DistanceStrategy implements DataPresenterStrategy... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T10:05:14.840",
"Id": "104999",
"Score": "0",
"body": "Can you please replace the code in question with *real code* opposite to *example code*? We're not asking to show all 25 classes, but show two or three classes that are real."
... | [
{
"body": "<pre><code>enum DataPresenterStrategyType { DISTANCE, POWER }\n\nDataPresenterStrategy toStrategy(StrategyType type) {\n switch(type) {\n case DISTANCE:\n return new DistanceStrategy();\n case POWER:\n return new PowerStrategy();\n }\n}\n</code></pre>\n\n<p>W... | {
"AcceptedAnswerId": "58504",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-07-30T09:59:13.647",
"Id": "58489",
"Score": "8",
"Tags": [
"java",
"design-patterns"
],
"Title": "Strategy pattern instances based on enums"
} | 58489 |
<p>The player will have different spells that can be cast on different keyboard key combinations.</p>
<p>Right now what I have is one .as file with everything on it. A bunch of <code>if</code>s, checking for combos <code>if (combo="WW") {}</code>, <code>if (flightMode) {}</code> and so on, which I know is bad practice... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T11:23:08.510",
"Id": "105016",
"Score": "2",
"body": "Please show more code. Right now my answer would be wholly incomplete in regards to your question. In particular, don't replace the reset content with a comment. I'd also like to... | [
{
"body": "<h2>Single Responsibility Principle</h2>\n\n<p>\"A class should have one, and only one, reason to change.\" (defined in <a href=\"http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod\" rel=\"nofollow\">The Principles of OOD</a>)\nYou can use this principle to group parts of the code that have... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T11:08:48.840",
"Id": "58493",
"Score": "3",
"Tags": [
"optimization",
"beginner",
"design-patterns",
"actionscript-3"
],
"Title": "Game character sprite positioning and moveme... | 58493 |
<p>I wrote an IRC bot in Java using Pircbot for use in twitch(.tv) chat. It is intended to be run locally and to only be connected to one channel at a time. When it is connected to my channel, it will take song requests for MP3s in my music directory. There is a songlist on a Google site. Otherwise I'll just use it in ... | [] | [
{
"body": "<h2>Names matter</h2>\n\n<blockquote>\n <p>How is the documentation? I don't feel like a lot of it is necessary\n but I was just messing around. I would like my code to be clean enough\n so that anyone on twitch could copy my example [...]</p>\n</blockquote>\n\n<p>You should start by <strong>impro... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T11:27:00.933",
"Id": "58496",
"Score": "12",
"Tags": [
"java",
"strings"
],
"Title": "Music & DJ IRC bot"
} | 58496 |
<p>This is my simple implementation on JS HTML table generator which generates a table based on an array of JS objects.</p>
<pre><code>function Column(caption,position,isVisible,values){
this.caption = caption;
this.position = position;
this.isVisible = isVisible;
this.values = values;
}
Column.prototype.pri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T15:59:05.240",
"Id": "105080",
"Score": "0",
"body": "is your table input format can be changed ?"
}
] | [
{
"body": "<ul>\n<li><p>Since <code>position</code> is a number, you can simplify your <code>columnSorter</code> function. It becomes a one-liner, so you could even do:</p>\n\n<pre><code>columnArray.sort(function(a, b) { return a.position - b.position; });\n</code></pre>\n\n<p>Note though that some people consi... | {
"AcceptedAnswerId": "58543",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T13:33:58.823",
"Id": "58507",
"Score": "2",
"Tags": [
"javascript",
"beginner",
"html"
],
"Title": "Simple JavaScript HTML table generator"
} | 58507 |
<p>My code works for the most part. (The problems are on the html side not the python side) however I feel it could run quicker or more efficiently. Due to the size of the XML document it parses it's always going to take a little while though.</p>
<p>The script parses the XML file and finds the names of several things... | [] | [
{
"body": "<p>Not having any example xml file, I cannot test the code provided, but I can see that it relies on <code>xml.dom.minidom.getElementsByTagName</code>. My suggestion here is to give a try <code>xml.sax</code> and see if it's more efficient because:</p>\n\n<ul>\n<li>There's no need to keep in memory t... | {
"AcceptedAnswerId": "58512",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T13:39:27.563",
"Id": "58508",
"Score": "3",
"Tags": [
"python",
"html",
"parsing",
"xml",
"file-system"
],
"Title": "Parsing XML to send data into several files"
} | 58508 |
<p>I was hoping to get a quick review of a script I wrote for retrieving AWS VPC Subnet information. Any and all ideas welcome. I am looking specifically for logic enhancements, and optimizations to make the code more pythonic. Also, I was initially constructing a dictionary, however I had to adjust since many of the ... | [] | [
{
"body": "<p>I haven't used much <code>boto</code>, so I can just focus on some style comments:</p>\n\n<ul>\n<li>Use four spaces per indentation level</li>\n<li>Remove unused imports (<code>boto.exception</code>)</li>\n<li>Try to order imports in alphabetical order</li>\n<li>Move argument parsing and logging c... | {
"AcceptedAnswerId": "58519",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T14:05:34.630",
"Id": "58514",
"Score": "1",
"Tags": [
"python",
"amazon-web-services"
],
"Title": "Gets AWS VPC subnet info"
} | 58514 |
<p>I created this observable storage thing in JavaScript (partly for fun, but also because it came in handy and got bigger without me noticing it).</p>
<p>The repository can be found <a href="https://github.com/pinoniq/eagle" rel="nofollow">here</a>.</p>
<pre><code>(function(window, undefined){
"use strict";
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T07:32:31.727",
"Id": "105225",
"Score": "0",
"body": "@Jamal I don't think your edit was correct. Some fun should be allowed!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T11:09:26.217",
"Id": "... | [
{
"body": "<p>Pretty nice! I have only a few comments:</p>\n\n<ol>\n<li><p>You have a typo: \"arguemnts\" in your <code>throw</code> statements :)</p></li>\n<li><p>I'd avoid all the extra logic in the returned object. I'd prefer the functions to be doing all the argument handling themselves. I do understand why... | {
"AcceptedAnswerId": "58541",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T14:06:49.123",
"Id": "58515",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "JavascriptObservable Storage"
} | 58515 |
<p>Is this too much work for 1 touch listener? Is this bad for devices with slow CPU's?</p>
<pre><code>@Override
public boolean onTouch(View v, MotionEvent event) {
int id = v.getId();
switch(id){
case R.id.sound1:
if(event.getAction()==android.view.... | [] | [
{
"body": "<p>Dodging your question for a quick comment:</p>\n\n<p>Why don't you combine these</p>\n\n<pre><code> if(intLoop ==0){\n mp1=MediaPlayer.create(MainClass.this, R.raw.item1);\n mp1.start();\n v.setPressed(... | {
"AcceptedAnswerId": "58520",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T14:25:16.067",
"Id": "58517",
"Score": "3",
"Tags": [
"java",
"android",
"event-handling"
],
"Title": "Is this too much work for 1 listener?"
} | 58517 |
<p>I have large dataframe containing many replicates.
The replicates are in groups of 3. So the first 3 replicates are in column 1, 2 and 3. The second set 4, 5 and 6... and so on.</p>
<p>Now I create a new dataframe containing for each set of replicates the mean.</p>
<p>The code below works, but it is really clumpy ... | [] | [
{
"body": "<p>Here is a proposal for a different approach that doesn't use a for loop and has some simplifications.</p>\n\n<p>First, an example data frame:</p>\n\n<pre><code>dat <- data.frame(a1 = 9:11, a2 = 2:4, a3 = 3:5,\n b1 = 4:6, b2 = 5:7, b3 = 1:3)\n# a1 a2 a3 b1 b2 b3\n# 1 1 2 3 ... | {
"AcceptedAnswerId": "58547",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T15:09:07.260",
"Id": "58523",
"Score": "7",
"Tags": [
"r"
],
"Title": "Mean of many subsets of a dataframe"
} | 58523 |
<p>I am unable to use CSS for this as I am disseminating this information via e-mail through a sharepoint workflow. I have tried to make this code as MS Outlook compatible as possible. (I removed all live info)</p>
<pre><code><!DOCTYPE: html>
<html>
<!-- variable:eHead -->
<title>Commentary<... | [] | [
{
"body": "<ul>\n<li><p><code><img></code> is a void element. It should look like either <code><img /></code> or <code><img></code>, not <code><img></img></code>.</p></li>\n<li><p><code>Img-align</code> is not a valid CSS property. Your image is already being aligned by the <code>a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T15:37:15.757",
"Id": "58527",
"Score": "2",
"Tags": [
"html",
"email"
],
"Title": "HTML for optimal output in Outlook"
} | 58527 |
<p>I am building a simple adventure game that has "upgrades" feature.<br>
In this game, user controls one player, that can be upgraded to increase things such as:</p>
<ul>
<li>Amount of gold earned</li>
<li>Maximum health</li>
<li>Attack power</li>
<li>(more of this would be added later, for example: defense upgrade, ... | [] | [
{
"body": "<p>I don't know any Java, but I think I can give you some ideas that may help you refine this code and make it easier to extend. Take a look at my question about <a href=\"https://codereview.stackexchange.com/questions/55139/skill-upgrades-for-strategy-game\">skill upgrades</a> on this site, because... | {
"AcceptedAnswerId": "58546",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T16:31:01.043",
"Id": "58532",
"Score": "18",
"Tags": [
"java",
"game"
],
"Title": "Implement \"Upgrades\" Feature for Game"
} | 58532 |
<p>I've come up with two ways to check to see if array is sorted and return true if it is.</p>
<pre><code>public static boolean checkSortedness(int[] data)
{
for(int i = 1; i < data.length; i++)
{
if(data[i-1] > data[i])
{
return false;
}
}
return true;
}
</cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T17:59:25.283",
"Id": "105096",
"Score": "1",
"body": "Arent you missing a Point that array can be sorted in assending as well descending orders. your program only takes care about Arrays sorted in ascending order."
}
] | [
{
"body": "<p>The better way would be your first, as you're just comparing the element A with element B and not creating a copy of the element as you are in the second version. </p>\n\n<p>Additionally, to be a bit of a pedant - you don't want to name a function <code>checkSortedness</code> where its only return... | {
"AcceptedAnswerId": "58536",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T16:51:02.380",
"Id": "58533",
"Score": "8",
"Tags": [
"java",
"array",
"sorting",
"comparative-review"
],
"Title": "Checking if an array is sorted"
} | 58533 |
<p>I am doing Project Euler problem #8:</p>
<blockquote>
<p>The four adjacent digits in the 1000-digit number that have the
greatest product are 9 × 9 × 8 × 9 = 5832.</p>
<pre><code>73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
858615607891129494954595017379... | [] | [
{
"body": "<ul>\n<li><p>The loop iterates over the whole <code>range(len(M))</code>. It means that the last few products exercise less than 13 digits. It doesn't matter in this particular example (they are all zeros anyway), but may lead to erroneous result in general case. Iterate over <code>range(len(M) - 13)... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T17:24:19.837",
"Id": "58535",
"Score": "5",
"Tags": [
"python",
"programming-challenge"
],
"Title": "Efficiency on Project Euler Problem #8"
} | 58535 |
<p>I had the idea the other day to implement an artificial intelligence that could play my strategy game. This could be useful in a variety of different ways. For example, the player could "lose contact" with one of the worlds in the game, and the AI could take over in that event. Or perhaps the player could elect a... | [] | [
{
"body": "<h1>DTGamePlayingAI</h1>\n<p>For this post, I'm only looking at the <code>DTGamePlayingAI</code> class. This is a big question, and this is a big answer. I don't want the lack of commentary on other posted classes to be taken as a sign that they're flawless. And some of the comments from this post... | {
"AcceptedAnswerId": "58581",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T17:28:00.257",
"Id": "58537",
"Score": "7",
"Tags": [
"game",
"objective-c",
"ai"
],
"Title": "AI Governor to Play a Strategy Game"
} | 58537 |
<p>I would love to have your reviews of this sign in and sign up system.</p>
<p>You can see the main structure:</p>
<p><img src="https://i.stack.imgur.com/whZr3.png" alt="enter image description here"></p>
<p>For now, I have a total of 13 files (<code>index.php</code>, <code>top_bar.php</code>, <code>header.php</cod... | [] | [
{
"body": "<p>There's a few things wrong with this. Primarily that there is no separation of concerns - you have PHP mixed with HTML, etc. However, barring that, there are some low hanging fruit that we can nip:</p>\n\n<p>Your index.php contains unnecessary mixtures of <code><?php if(){ ?>...<?}?></... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T18:17:02.090",
"Id": "58544",
"Score": "6",
"Tags": [
"php",
"html"
],
"Title": "Forum Sign up and Sign in software"
} | 58544 |
<p>I am doing this <a href="https://projecteuler.net/problem=9" rel="nofollow">Project Euler Question #9</a>:</p>
<blockquote>
<p>A Pythagorean triplet is a set of three natural numbers, \$a < b < c\$, for which,</p>
<p>$$a^2 + b^2 = c^2$$</p>
<p>For example, \$3^2 + 4^2 = 9 + 16 = 25 = 5^2\$.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T19:12:31.347",
"Id": "105115",
"Score": "1",
"body": "You might want to look up Berggren's algorithm to generate the Pythagorean triples."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-06T21:14:01.490",... | [
{
"body": "<ol>\n<li><p><code>if i + j + c == SUM</code> is not needed as you have already set <code>c = SUM - (i + j)</code></p></li>\n<li><p>When you find the result and <code>break</code> out of the inner loop, you are not breaking out of the outer loop, so the programme will continue through all possible va... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T18:57:19.993",
"Id": "58548",
"Score": "2",
"Tags": [
"python",
"programming-challenge"
],
"Title": "Finding Pythagorean Triple that sums to 1000"
} | 58548 |
<p>I built a custom HTML5 video control bar, and for each second, it updates two readings:</p>
<ol>
<li><p>Time Elapsed</p></li>
<li><p>Time Remaining</p></li>
</ol>
<p>in hh:mm:ss notation, like so:</p>
<p><img src="https://i.stack.imgur.com/ZJNt2.png" alt="enter image description here"></p>
<p>Because of how ofte... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T06:20:52.103",
"Id": "105210",
"Score": "1",
"body": "Don't use `setInterval` to animate, use [`requestAnimationFrame`](https://developer.mozilla.org/en/docs/Web/API/window.requestAnimationFrame). This allows the browser to decide w... | [
{
"body": "<p>When converting time values like this I find it much simpler, and more readable to work up from the smallest units. Consider the following:</p>\n\n<pre><code>// Convert seconds to hh:mm:ss\nfunction secondsToHMS(intime) {\n var numseconds = digitize(intime % 60);\n intime = Math.floor(intime... | {
"AcceptedAnswerId": "58562",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T18:58:01.613",
"Id": "58549",
"Score": "11",
"Tags": [
"javascript",
"jquery",
"user-interface"
],
"Title": "Efficiency of this constantly running time processor for an HTML5 v... | 58549 |
<p>I'm going to develop an Android application that performs simple MySQL operations by invoking server-sided PHP scripts. PHP-MySQL communication is done by MySQLi extension. Each operation that I'd like to perform is in a separate PHP file, and in a separate class. There's an example of <code>update.php</code>:</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-10-24T13:17:28.203",
"Id": "272400",
"Score": "0",
"body": "I think that now, for applications like these, we do not use pure php. Frameworks like `Laravel` are used nowadays."
}
] | [
{
"body": "<p><code>UpdateRecord</code> doesn't make much sense as a class. As a rule, classes should be named as nouns. A verb name suggests that it would be more appropriate as a method, either in the <code>Database</code> class or a subclass of <code>Database</code>.</p>\n",
"comments": [
{
... | {
"AcceptedAnswerId": "58591",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T19:23:07.660",
"Id": "58553",
"Score": "7",
"Tags": [
"php",
"mysql",
"mysqli"
],
"Title": "MySQL update with PHP; MySQLi prepared statement in loop"
} | 58553 |
<p>I recently started my first project with Erlang. I've been skimming documentation and various books to get the information I need, and it's going well, but now that I have something that works I want to go "back to the basics" to fill in some holes in my knowledge, and more importantly, my style. So I took a look at... | [] | [
{
"body": "<p>I see one possible mistake in your code: you do not check if a key already exists before writting a new {Key,Value} pair. This may be intentional, but in this case I think that the read(Key,Db) should return a list of value rather than a single value.</p>\n\n<p>Looking at pattern matching I think ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T20:56:14.757",
"Id": "58564",
"Score": "3",
"Tags": [
"beginner",
"design-patterns",
"recursion",
"functional-programming",
"erlang"
],
"Title": "Erlang pattern matching e... | 58564 |
<pre><code>public static ArrayList<Playlist> getAllPlaylists( Context context ){
ArrayList<Playlist> playlists = new ArrayList<Playlist>();
ArrayList<String> fileList = new ArrayList<>();
//this will get me all playlist files available for my application
for( String file :... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T22:32:24.117",
"Id": "105168",
"Score": "0",
"body": "Nitpicking: it is legal to have a newline in path. You may want to extract filenames in a more diligent way."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | [
{
"body": "<h3>About the slowness...</h3>\n\n<p>I don't see obvious bottlenecks here. When you say \"It takes about 1 second for 1 file...\" do you mean:</p>\n\n<ul>\n<li>A single song? In this case the <code>MediaManager.getSong</code> is a prime suspect. Add logging before and after to measure the difference.... | {
"AcceptedAnswerId": "58573",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T22:19:30.620",
"Id": "58571",
"Score": "2",
"Tags": [
"java",
"android",
"io"
],
"Title": "Android loading playlists function"
} | 58571 |
<p>Hoping for input on the clarity of the docstrings, syntax and performance of these two functions both of which should be self-explanatory:</p>
<pre><code>def tell(paragraph, duration=.1):
"""Print paragraph line by line with pause between each line."""
lines = paragraph.splitlines()
for line in lines:
... | [] | [
{
"body": "<ul>\n<li>Snippet 1.</li>\n</ul>\n\n<p>The way <code>yinyang</code> is organized is quite unconventional. I presume that</p>\n\n<pre><code>tries += 1\n</code></pre>\n\n<p>is a typo (<code>tries -= 1</code> would make much more sense). Even than I don't see a need for a recursion. A simple loop will d... | {
"AcceptedAnswerId": "58604",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-30T23:59:12.077",
"Id": "58578",
"Score": "0",
"Tags": [
"python",
"beginner"
],
"Title": "Basic User Interaction in Python - syntax, docstrings, performance"
} | 58578 |
<p>I have a method that seems to be too much for one method. I might be validating programming methodology. I just don't know what to do with it. Would a switch statement be better? Should I break it up and provide other methods?</p>
<pre><code>public void addToCart(OrderlineType orderline) throws Exception
{
... | [] | [
{
"body": "<p>I'm not an expert at programming in any kind of way, and I don't know Java, but I think I can point out a few things that will be useful to you.</p>\n\n<p>Your questions at the end of your post make me believe that you already know that this method is doing too much, and that it can be improved in... | {
"AcceptedAnswerId": "58593",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T00:58:56.340",
"Id": "58582",
"Score": "5",
"Tags": [
"java"
],
"Title": "Add-to-cart method has too many conditions"
} | 58582 |
<p>I'd like to improve this Insertion sort code</p>
<pre><code>package com.arun.sort;
import java.util.Arrays;
public class InsertionSort {
public static void main(String[] args) {
int[] arr = { 9, 4, 6, 2, 1, 7 };
insertionSort(arr);
System.out.println("Elements after sorting :" + Arrays.toString(arr... | [] | [
{
"body": "<h3>Step 1: extract to a method</h3>\n\n<p>In the current code you have a hardcoded array, and the main logic follows right after. It's hard to test this way. What if you want to see if the implementation works with a different set of numbers? You have to rewrite the array. Better to extract the main... | {
"AcceptedAnswerId": "58598",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T03:03:05.873",
"Id": "58587",
"Score": "2",
"Tags": [
"java",
"beginner",
"sorting",
"insertion-sort"
],
"Title": "Insertion sorting an int array"
} | 58587 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.