body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>The online book <a href="http://gameprogrammingpatterns.com/command.html">Game Programming Patterns</a> briefly describes the use of the command pattern to handle input in a game. I've attempted to write my own "one size fits all" input handling system based on the command pattern, as shown below.</p>
<ul>
<li>Is t... | [] | [
{
"body": "<blockquote>\n <p>Is this a correct implementation and use of the command pattern?</p>\n</blockquote>\n\n<p>Yes, <a href=\"http://en.wikipedia.org/wiki/Command_pattern\" rel=\"noreferrer\">I think it is good enough</a>.</p>\n\n<blockquote>\n <p>Would it be better (more efficient, more maintainable)... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T18:30:03.517",
"Id": "55365",
"Score": "23",
"Tags": [
"c++",
"design-patterns",
"game"
],
"Title": "Input handling system using the command pattern"
} | 55365 |
<p>This is a script I made for testing a simple operating system.</p>
<p>It assembles the source and creates a boot image, then It automates the configuration of a Virtual Box machine. </p>
<pre><code>#!/bin/bash
OS_NAME="hello"
MEMORY_SIZE=8
build_main () {
# remove old files
rm -f $OS_NAME.bin
rm -f $... | [] | [
{
"body": "<p>Overall it's a pretty nice script. I can mostly nitpick, with a few exceptions. Here we go, from top to bottom.</p>\n\n<hr>\n\n<p>It might be a good idea to set the <code>-e</code> flag to make the script stop running when something unexpected goes wrong, like this:</p>\n\n<pre><code>#!/bin/bash -... | {
"AcceptedAnswerId": "56083",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T19:36:59.240",
"Id": "55371",
"Score": "6",
"Tags": [
"bash"
],
"Title": "OS testing script"
} | 55371 |
<p>Follow up question for: <a href="https://codereview.stackexchange.com/questions/55318/conditional-row-count-across-4-tables">Conditional row count across 4 tables</a>
<br />
After getting some excellent help from 200_success, i managed to output the <code>SUM()</code> total of my query using the following code: </p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T19:49:45.183",
"Id": "97053",
"Score": "0",
"body": "Can you run your query? Seems like it's missing `GROUP BY` clauses which I thought were needed when you are selecting an aggregate function like `SUM()` or `COUNT()`..."
},
{
... | [
{
"body": "<p><strong>MySQL</strong></p>\n\n<p>Your query looks fine, I'm not sure it could be further optimized of itself. What I would suggest though is to plug it into a stored procedure, and there are a few good reasons to do this. </p>\n\n<ol>\n<li><p>Cleaner PHP script by only having your behavioral code ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T19:38:39.860",
"Id": "55372",
"Score": "3",
"Tags": [
"php",
"mysqli"
],
"Title": "Outputting results from a conditional row count across multiple tables"
} | 55372 |
<p>After some free ASCII flowchart drawer started charging money, I decided to write my own. Salient features are that you can draw a box (mouse down, mouse move, mouse up), then <kbd>ctrl</kbd><kbd>B</kbd> will draw a box. Copy/Paste, Undo, Redo, click anywhere and type are all working features. I pasted the main code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T21:56:52.690",
"Id": "97317",
"Score": "0",
"body": "Curlies on own line is a valid option on jsbeautifier.org, try it, you might like. I will look into mac ctrl keys, completely forgot about that."
},
{
"ContentLicense": "C... | [
{
"body": "<p>I like it! I've got some quibbles about the style, but that's personal opinion, and the code works, so I won't go into that. I haven't gone through the code line-by-line (there's a lot!), but I've tried looking at the overall structure.</p>\n\n<p>If I were to suggest something, it might be a more ... | {
"AcceptedAnswerId": "55550",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T19:43:18.450",
"Id": "55375",
"Score": "12",
"Tags": [
"javascript",
"google-chrome",
"ascii-art"
],
"Title": "ASCII flow chart drawer"
} | 55375 |
<p>I have the following function to compare a string with a wildcard string (containing ? and *), as C# doesn't seem to have a builtin function to do it. </p>
<pre><code> /// <summary>
/// Compares wildcard to string
/// </summary>
/// <param name="WildString">String to compare</par... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T21:21:08.430",
"Id": "97067",
"Score": "1",
"body": "why dont you use Regex and you save yourself this hassle http://www.codeproject.com/Articles/11556/Converting-Wildcards-to-Regexes"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>What you want to do is called \"globbing\". <a href=\"https://stackoverflow.com/questions/188892/glob-pattern-matching-in-net\">It's actually quite easy to do with a <code>Regex</code>.</a></p>\n\n<p>There are a few code smells here. The recursion is the obvious one. The other is the special-cases... | {
"AcceptedAnswerId": "55403",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T20:20:16.687",
"Id": "55379",
"Score": "9",
"Tags": [
"c#",
"strings",
"array"
],
"Title": "Compare string with wildcard string"
} | 55379 |
<p>The following is working and readable SQL for Eloquent that I have created. The downside is that it looks more like a 1:1 with SQL and I don't think I'm using the full potential of Eloquent. I thought of using scope queries to shorten it, but for some reasons the <code>selectRaw</code> prevents it (due to multiple j... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T03:25:00.463",
"Id": "97650",
"Score": "0",
"body": "It might not help you at all but `groupBy('book.id')` on `Books` table ? looks like the Books table has many books with same ID, which is not good in most cases. can you update t... | [
{
"body": "<p><strong>SQL formatting</strong></p>\n\n<p>Your SQL script in my opinion could use some indentation and a few more line breaks. </p>\n\n<p><strong>Variable names</strong></p>\n\n<p>Table & column aliases are useful. But it is a good practice to use a variable name that at least says <em>somethi... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T21:32:01.967",
"Id": "55382",
"Score": "1",
"Tags": [
"php",
"laravel",
"eloquent"
],
"Title": "Optimizing Laravel Eloquent multiple joins"
} | 55382 |
<p>Looking for code review, optimizations and best practices.</p>
<pre><code>public class FindMiddleStack<T> {
private Node<T> top;
private Node<T> middle;
private int size = 0;
private static class Node<T> {
Node<T> left;
T item;
Node<T> ri... | [] | [
{
"body": "<h2>Implementing \"correctly\":</h2>\n\n<p>Your Classname says, you have implemented a <code>Stack</code> with additional operations. Why do I not see <code>implements</code> or <code>extends</code> in your code then?</p>\n\n<blockquote>\n<pre><code>public class FindMiddleStack<T> {\n</code></p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T21:50:38.927",
"Id": "55384",
"Score": "4",
"Tags": [
"java",
"algorithm",
"stack"
],
"Title": "Stack with \"getMiddle\" and \"deleteMiddle\" operation"
} | 55384 |
<p>I have a working function that may be optimizable. </p>
<p>Currently processing 4 objects gives me <code>0.0459822</code> for the elapsed time in seconds - used for testing purposes. Once implemented into the app I will be checking > 1000 objects at a time and would like to speed this up if possible. The format of ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T13:10:08.853",
"Id": "97198",
"Score": "1",
"body": "The `StopWatch` is running when you are declaring the variables in your sample - Is this intended?"
}
] | [
{
"body": "<p>I'm not sure how to optimize your code, but let's talk about those variable names. </p>\n\n<p>Naming is <em>hard</em>. It's doubly hard in vb.net, because it's case insensitive. That fact makes it difficult not to step on keywords like <code>Field</code>. I don't like recommending this, but withou... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T22:00:34.170",
"Id": "55385",
"Score": "13",
"Tags": [
"optimization",
"performance",
"datetime",
"vb.net"
],
"Title": "Optimize a Date and Timespan function"
} | 55385 |
<p>Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack. All these operations of SpecialStack must be O(1). To implement SpecialStack, you should only use standar... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T08:19:54.067",
"Id": "97147",
"Score": "0",
"body": "**Use Generics**. `StackMinimum<T extends Comparable<T>>`. **Don't cast**."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T15:17:07.897",
"Id":... | [
{
"body": "<p>It looks very good for me, you can use the <code>extend</code> keyword on generics to insure type safety and to avoid unnecessary casts. And this is called a <code>Bounded type</code> </p>\n\n<pre><code>class StackMinimum<T extends Comparable>{\n public void push(T item) {\n stack... | {
"AcceptedAnswerId": "55395",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T22:12:06.803",
"Id": "55386",
"Score": "6",
"Tags": [
"java",
"algorithm",
"stack"
],
"Title": "Stack with 'getMinimum' operation"
} | 55386 |
<p>According to the <a href="https://laravel.com/docs/5.2/eloquent" rel="nofollow">official documentation</a></p>
<blockquote>
<p>The Eloquent ORM included with Laravel provides a beautiful, simple
ActiveRecord implementation for working with your database. Each
database table has a corresponding "Model" which i... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T22:35:52.230",
"Id": "55391",
"Score": "0",
"Tags": null,
"Title": null
} | 55391 |
Eloquent is Laravel's own object-relational mapper. It is named "Eloquent" because it allows you to work with your database objects and relationships using an eloquent and expressive syntax. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T22:35:52.230",
"Id": "55392",
"Score": "0",
"Tags": null,
"Title": null
} | 55392 |
<p>I've recently learned how to use MySQL to store/retrieve data. I've created a <code>MySQLManager</code> class for creating connections and executing queries/updates. Would this be an efficient way to do so?</p>
<pre><code>public class MySQLManager {
private String host;
private String port;
private String database... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T09:35:37.567",
"Id": "97162",
"Score": "4",
"body": "Do you have a good reason for reconnecting to the DB for every query? Why not just use one connection for each instance of your manager class?"
}
] | [
{
"body": "<p>You've written a wrapper around JDBC that automatically connects/disconnects, and swallows exceptions. Don't do that.</p>\n\n<p>JDBC wants you to establish connections explicitly because it's a high-overhead activity. Connecting involves a TCP handshake, authentication, opening the requested dat... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T01:56:12.530",
"Id": "55401",
"Score": "12",
"Tags": [
"java",
"mysql"
],
"Title": "Creating connections and executing queries/updates"
} | 55401 |
<p>I've been working on a generic graph library for a while now, in a bit of an off and on fashion. I realise that <code>boost::graph</code> exists, but it is a complex library that allows the user a huge amount of customisation. I have gone for a different approach; I constrain the library user much more, but this (ho... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T04:01:54.503",
"Id": "97121",
"Score": "0",
"body": "What is the intended use of this library? Is performance (for scientific computing, say) a major concern? Hash maps kill cache-locality, although since your graph classes are muta... | [
{
"body": "<h1>Subtypes names</h1>\n\n<p>First of all, I would make sure that the type names in your classes match those in the standard library classes. We can see that some of them differ:</p>\n\n<ul>\n<li><code>allocator</code> should be <code>allocator_type</code>.</li>\n<li><code>base_container</code> shou... | {
"AcceptedAnswerId": "55684",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T02:35:32.880",
"Id": "55402",
"Score": "13",
"Tags": [
"c++",
"c++11",
"graph"
],
"Title": "Generic Graph Library"
} | 55402 |
<p>Is this the most elegant way to avoid declaring additional variables outside the <code>following_triggers</code> loop?</p>
<pre><code> closest_trigger_utc_time = (2**(0.size * 8 -2) -1)
following_triggers.each do |test|
closest_trigger_utc_time = test.utc_time if test.utc_time < closest_trigger_... | [] | [
{
"body": "<p><a href=\"http://www.ruby-doc.org/core-2.1.1/Enumerable.html\" rel=\"nofollow\">Enumerable</a> has many useful methods that solve problems like this. In this case you want <code>map</code> and <code>min</code> or <code>min_by</code>:</p>\n\n<pre><code>closest_trigger_utc_time = following_triggers.... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T02:55:44.543",
"Id": "55405",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Better practice to find the max/min element in a loop"
} | 55405 |
<p>I have three types of variable assign expression with multiple expressions.</p>
<p>It looks ugly, but I'm not sure how to make it more readable.</p>
<p>Type 1</p>
<pre><code> following_triggers = alarm_test_group.map{ |alarm_test|
self.class.where{ sony_alarm_test_id.eq(alarm_test.id) }
.where{ utc_t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T21:03:18.887",
"Id": "97304",
"Score": "1",
"body": "have you considered using scopes?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T18:48:51.233",
"Id": "97576",
"Score": "0",
"body": "... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T03:02:10.733",
"Id": "55406",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails",
"active-record"
],
"Title": "Variable assign expression with multiple expressions"
} | 55406 |
<p>I have found myself needing to sample numbers from a given distribution and was wondering what the most efficient method of doing so is.</p>
<p>I have a set of <code>N</code> elements <code>0</code> to <code>N-1</code> and an array mapping those elements to the probability of their selection, <code>pp</code>.</p>
... | [] | [
{
"body": "<p>Just a suggestion: </p>\n\n<p>I think you can use better variable names than <code>pp</code> and <code>q</code>.</p>\n\n<p><code>cdf</code> can be <code>clonedArray</code>, and the same for other variable names.</p>\n\n<p>This doesn't matter so much but increases the readability of the program.</p... | {
"AcceptedAnswerId": "55565",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T03:56:31.643",
"Id": "55409",
"Score": "6",
"Tags": [
"java",
"statistics"
],
"Title": "Sampling from a distribution with given probabilities"
} | 55409 |
<p>I have made a bootstrap accordion navigation bar that loads data dynamically from a database with PHP.</p>
<p>Here are the two tables that I use:</p>
<pre><code>CREATE TABLE IF NOT EXISTS `top_tier` (
`id` varchar(50) NOT NULL,
`name` varchar(255) NOT NULL,
`date_created` timestamp NOT NULL DEFAULT '0000-00-... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T04:24:02.927",
"Id": "97128",
"Score": "1",
"body": "I see an SQL injection point."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T04:25:06.387",
"Id": "97129",
"Score": "0",
"body": "@Ale... | [
{
"body": "<p><strong>Timestamp</strong></p>\n\n<p>Why do you insert an invalid value <code>'0000-00-00 00:00:00'</code> into your <code>TIMESTAMP</code> columns by <code>DEFAULT</code>? I think you would be much better served by using something relevant, like <code>CURRENT_TIMESTAMP</code>...</p>\n\n<blockquot... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T04:11:23.940",
"Id": "55410",
"Score": "3",
"Tags": [
"php",
"mysql",
"mysqli",
"twitter-bootstrap"
],
"Title": "Dynamically load data into bootstrap accordion navigation bar"... | 55410 |
<p><code>Exercises</code> have <code>Muscles</code> and <code>Tools</code>. When someone adds or updates an <code>Exercise</code>, they also send an array of Tools and Muscles. Adds are pretty straightforward, but my update method feels a bit bulky. How can I simplify this?</p>
<pre><code>public void UpdateExercise... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T07:32:42.887",
"Id": "97143",
"Score": "0",
"body": "How is Excerise built to begin with. I'm unsure why you need to go through all this if Excerise is already a model from your db"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Use design patterns to simplfiy your Data Access Layer and the Separation of concerns.</p>\n\n<p>This method UpdateExercise(Exercise exercise) is very complicated and is not SRP.</p>\n\n<p>Your problem in the model architecture more than in code. Of course you can use some tricks to simplify the c... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T04:59:23.623",
"Id": "55413",
"Score": "3",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Entity Framework - updating two different arrays of child associations"
} | 55413 |
<p>How's the following function to update an immutable <code>Map</code>'s values? </p>
<pre><code>scala> def updateMap[A](map: Map[A, Set[A]], item: A, toAdd: A) = {
map.map(x => if(x._1 == item) (x._1, (x._2 + toAdd)) else (x._1, x._2))
}
scala> val map = Map(1 -> Set(2), 3 -> Set(4))
scala>... | [] | [
{
"body": "<p><a href=\"http://www.tutorialspoint.com/scala/scala_pattern_matching.htm\" rel=\"nofollow\">Pattern matching</a> is a more readable and important feature of Scala, which you can use.</p>\n\n<p>And in the <code>else</code> condition, you are using <code>(x._1, x._2)</code>; you can use <code>x</cod... | {
"AcceptedAnswerId": "55424",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T05:12:28.493",
"Id": "55415",
"Score": "2",
"Tags": [
"scala"
],
"Title": "Update Immutable Map"
} | 55415 |
<p>A hash map (or hash table) is a data structure which contains "key-value" pairs and allows retrieving values by key.</p>
<p><a href="http://en.wikipedia.org/wiki/Hash_table" rel="nofollow noreferrer">Hash maps (wikipedia)</a> are part of the standard libraries for many languages:</p>
<ul>
<li>C++: <code>st... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-06-27T05:36:17.283",
"Id": "55418",
"Score": "0",
"Tags": null,
"Title": null
} | 55418 |
A data structure that uses a hash function to map identifying values, known as keys, to their associated values | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T05:36:17.283",
"Id": "55419",
"Score": "0",
"Tags": null,
"Title": null
} | 55419 |
<p>I have written my first real C++ project, a Sudoku solver! It's not elegant, but it works well. It solves easy and medium but not hard!</p>
<pre><code>#include <locale>
#include <iostream>
#include <fstream>
#include <string>
#include <ctype.h>
#include <cstring>
const char t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T17:27:22.013",
"Id": "97254",
"Score": "0",
"body": "Sudoku is easily solved using a brute force (try every combination until you get a working one). The grid size is so constrained (9*9) that the number of possible solutions are li... | [
{
"body": "<p>Hard grids often require a guess, followed by normal solving. If it fails, then you need to back track and try another guess.</p>\n\n<p>An approach I like is to create objects that are \"views\" of the grid. That is, each view is an array of 9 cells. Separate arrays of these views are created for ... | {
"AcceptedAnswerId": "55431",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T06:17:02.797",
"Id": "55420",
"Score": "6",
"Tags": [
"c++",
"beginner",
"sudoku"
],
"Title": "Sudoku Solver (easy/medium)"
} | 55420 |
<p>(This is a follow on to <a href="https://codereview.stackexchange.com/questions/55402/generic-graph-library">this question</a>).</p>
<p>Having given an implementation for some of the graph structures, here is a portion of the algorithms that are defined to work over them:</p>
<blockquote>
<p>graph_degree.hpp</p>... | [] | [
{
"body": "<p>There are several places where you could improve the readability of your code:</p>\n\n<ul>\n<li><p>First of all, you also use iterator-based <code>for</code> loops while you could use range-based <code>for</code> loop instead. Consider this function:</p>\n\n<pre><code>template <typename Graph&g... | {
"AcceptedAnswerId": "55789",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T06:19:17.480",
"Id": "55421",
"Score": "6",
"Tags": [
"c++",
"algorithm",
"c++11",
"graph"
],
"Title": "Generic Graph Library Part 2 : Algorithms"
} | 55421 |
<p>I have two class <code>Task</code> and <code>Award</code> which extends <code>Task</code>. I create this class objects according JSON data. At the moment I have one method that read data passed data and create <code>Task</code>. If I need <code>Award</code> I use method which convert <code>Task</code> to <code>Award... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T09:02:37.373",
"Id": "97154",
"Score": "5",
"body": "Award does not sound like a descendant of Task. Can you enlighten us?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T12:10:28.670",
"Id": "971... | [
{
"body": "<p>A <code>Task</code> and an <code>Award</code> seem like very different things. Part of the reason you are having trouble converting them is because they don't want to be the same thing. It is much more likely that a certain <code>Task</code> might provide a certain <code>Award</code> when the play... | {
"AcceptedAnswerId": "55449",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T08:46:58.870",
"Id": "55425",
"Score": "4",
"Tags": [
"java",
"classes"
],
"Title": "Best practices to create extended class"
} | 55425 |
<p>The problem is described in full here - <a href="https://open.kattis.com/problems/aaah" rel="nofollow noreferrer">Aaah!</a>.</p>
<blockquote>
<h3>Input</h3>
<p>The input consists of two lines. The first line is the “aaah”
Jon Marius is able to say that day. The second line is the “aah” the
doctor wants to hear. Only... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T10:48:46.830",
"Id": "97182",
"Score": "1",
"body": "Get rid of those `gets` calls. Those are buffer overflows by definition."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T10:53:13.803",
"Id": "... | [
{
"body": "<p>The obvious performance enhancement is to stop using <code>malloc</code> and instead use the stack. Stack allocation is much faster than heap allocation. Change your string declarations to:</p>\n\n<pre><code>char strJon[MAX_INP], strDoc[MAX_INP];\n</code></pre>\n\n<p>Then get rid of the calls to... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T23:42:09.173",
"Id": "55426",
"Score": "5",
"Tags": [
"performance",
"c",
"programming-challenge"
],
"Title": "Go Aaaaaaaaaaah"
} | 55426 |
<p>I am learning C++ from a C background, and I was wondering if I could convert this old C program I'd written into C++ as a personal exercise. The original C program is a simple Monte Carlo simulation that simulates a virus spreading throughout a school population.</p>
<p>Currently, my C++ implementation is almost i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T18:56:04.057",
"Id": "97279",
"Score": "1",
"body": "Even if you follow the advice of @Nobody I would still not consider this C++. This is what is commonly refereed to as \"C with Classes (even though it has no classes (its the name... | [
{
"body": "<h2>Reduce global variables</h2>\n\n<p>It might be only a toy application but for the sake of future growth (and multithreading) it is a good idea to avoid global variables.</p>\n\n<p>Even for C code I find it inappropriate to have them. I would place these variables in an own class <code>Simulation<... | {
"AcceptedAnswerId": "55533",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T09:24:12.220",
"Id": "55432",
"Score": "11",
"Tags": [
"c++",
"simulation"
],
"Title": "Monte Carlo virus infection simulation"
} | 55432 |
<p>Follow up question for:</p>
<p><a href="https://codereview.stackexchange.com/questions/54969/update-database-reload-page-then-show-a-success-message">Update database, reload page then show a success message</a></p>
<p>I have a table of articles, in each row is a button to <code>activate / deactivate</code> the art... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-03-15T05:50:07.613",
"Id": "507900",
"Score": "0",
"body": "Ahoy! Bearing in mind this was posted almost seven years ago, is the code still maintained in this fashion? If so, could updated data to display in the table of articles be sent ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T10:38:01.513",
"Id": "55438",
"Score": "3",
"Tags": [
"php",
"jquery",
"ajax"
],
"Title": "Update database, refresh the page to show changes, show a success message"
} | 55438 |
<p>This is my first attempt at creating a DAO.</p>
<p>I would like to get some feedback regarding the following aspects if possible:</p>
<ul>
<li>Code readability</li>
<li>Efficiency</li>
<li>Usability</li>
</ul>
<p>I also would appreciate any other suggestions for improvement as well.</p>
<p><strong>UserDAO</stron... | [] | [
{
"body": "<p>Well it looks incredibly clean, the amount of effort to read it is almost minimal. Everything seems very straight forward too! Nice.</p>\n<p>However, that leaves little to actually be critiqued!</p>\n<h2>UserDAO</h2>\n<ul>\n<li><p>It's common to see <code>private</code> variables prefixed with an ... | {
"AcceptedAnswerId": "55532",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T10:38:33.900",
"Id": "55439",
"Score": "3",
"Tags": [
"php",
"sql",
"mysql",
"crud"
],
"Title": "UserDAO with CRUD functionality for my UserRepository"
} | 55439 |
<p>I am trying to merge overlapping/intersecting sets given as a list of string vectors below in R (my actual data set has thousands of such sets). The overlap/intersection is based on the <code>SDxyz:</code> string and not the string after the ":".</p>
<pre><code>d <- list(
c("SD1:LUSH", "SD44:CANCEL", "SD384:FR... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T17:15:32.517",
"Id": "97252",
"Score": "0",
"body": "I really don't get what you're trying to do here. The `out` vector looks like a union of all the vectors without duplicates, but instead of a simple vector of N string elements, i... | [
{
"body": "<p>Using the <code>data.table</code> syntax, you can shorten and speed up your code a lot. The following code should get the same result as you got (except for the order). </p>\n\n<pre><code>### Create a data.table Bloc with one column with original groups and the other with the separated ids\nd <... | {
"AcceptedAnswerId": "82582",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T10:42:02.467",
"Id": "55440",
"Score": "7",
"Tags": [
"optimization",
"performance",
"r",
"vectorization"
],
"Title": "Merging overlapping/intersecting string vectors"
} | 55440 |
<p>From the <a href="https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/objc_classic/_index.html" rel="nofollow">Foundation Framework Reference</a>:</p>
<blockquote>
<p>The Foundation framework defines a base layer of Objective-C classes.
In addition to providing a set of useful primi... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T11:27:47.947",
"Id": "55441",
"Score": "0",
"Tags": null,
"Title": null
} | 55441 |
The Foundation framework defines a base layer of Objective-C classes. In addition to providing a set of useful primitive object classes, it introduces several paradigms that define functionality not covered by the Objective-C language. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T11:27:47.947",
"Id": "55442",
"Score": "0",
"Tags": null,
"Title": null
} | 55442 |
<p>I have an object which represents historical prices of certain financial instruments as below:</p>
<pre><code> class DailyPrice
{
public DateTime? Date { get; set; }
public double? Price { get; set; }
}
</code></pre>
<p>This needs to be converted into <code>QuarterlyPrice<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T15:14:50.237",
"Id": "97216",
"Score": "4",
"body": "A `GroupBy` might be a better option."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T15:15:35.447",
"Id": "97217",
"Score": "7",
"body... | [
{
"body": "<p>What about a slightly different way of creating your classes?</p>\n\n<pre><code>class Quarter\n{\n int Year { get; set; }\n List<DailyPrice> Prices { get; set; }\n}\nclass DailyPrice\n{\n public DailyPrice(DateTime? date, double? price)\n {\n Date = date;\n Price = ... | {
"AcceptedAnswerId": "55460",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T15:08:35.600",
"Id": "55459",
"Score": "2",
"Tags": [
"c#",
"finance"
],
"Title": "Representing historical prices of certain financial instruments"
} | 55459 |
<p>I'm writing a PHP function to collect data from different positions in a given array. I've done it as follows which gives me what I require. </p>
<pre><code>for ($a=9; $a < 13; $a++) {
$n = $arr[$a][2];
$p = $arr[$a][3];
$c = $p;
$v1[] = array($n,$p,$c);
}
for ($b=3; $b < 16; $b+=4) {
$... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T16:11:53.327",
"Id": "97222",
"Score": "0",
"body": "I think there's a mistake on this line: `$c = $arr[$a][3]);`. Shouldn't that parenthesis be removed, and shouldn't the index be 4 instead of 3 (it's currently the same as the lin... | [
{
"body": "<p>From the answer of Scott Jungwirth, but a bit optimized :</p>\n\n<pre><code>for ($i=0; $i < 4; $i++)\n{\n $a = $i + 9;\n $b = $i*4 + 3;\n $v1[] = array($arr[$a][2],$arr[$a][3],$arr[$a][3]);\n $v2[] = array($arr[6][$b],$arr[5][$b],$arr[4][$b]);\n $r[] = array(\n 'n... | {
"AcceptedAnswerId": "55470",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T16:06:56.260",
"Id": "55467",
"Score": "2",
"Tags": [
"php"
],
"Title": "Collecting data from different positions in a given array"
} | 55467 |
<p>I have an app that will be sending images ranging from few KB to ~20MB and I need to write a code that will do that in the fastest and most efficient way. I currently have a code that does this, but I fear that it's inefficient and slow:</p>
<pre><code>// Read bitmap from file
Bitmap bitmap = null;
Uri uri = Uri.fr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T16:17:21.917",
"Id": "97226",
"Score": "0",
"body": "I don't understand why you decode the JPEG file to a bitmap and then compress it to JPEG. Is this important or could you just send the JPEG from the camera \"raw\" to your server?... | [
{
"body": "<p>I've implemented a tiny wrapper around <code>HttpURLConnection</code> called <a href=\"http://hgoebl.github.io/DavidWebb/\" rel=\"nofollow\">DavidWebb</a>. You can set the body as <code>File</code> or <code>InputStream</code> and it will stream the content to the server:</p>\n\n<pre class=\"lang-j... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T00:47:23.263",
"Id": "55471",
"Score": "3",
"Tags": [
"java",
"android",
"image",
"http"
],
"Title": "Efficient and fast way to send data from Android to server"
} | 55471 |
<p>I need to optimize this snippet to be faster:</p>
<pre><code>Dim lst = (From t In DocElet.ChildNodes Select ID = t.item("ID").outerxml).Distinct().ToList()
Parallel.For(0, lst.Count, Sub(i)
Dim P As XmlElement = GetElement(lst(i))
Dim ls = (From t In DocElet.ChildNodes Where t.item("ID").inne... | [] | [
{
"body": "<p>The indentation makes your snippet quite hard to read - the VB.NET syntax for inline delegates is fairly bulky (at least compared to C#), I'd give it more air; being able to <em>read</em> the code is step one.</p>\n\n<pre><code>Dim lst = (From t In DocElet.ChildNodes \n Select ID = t.ite... | {
"AcceptedAnswerId": "55485",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T14:48:54.897",
"Id": "55475",
"Score": "3",
"Tags": [
".net",
"linq",
"xml",
"vb.net"
],
"Title": "Optimisation XML handling within vb.net application"
} | 55475 |
<p><a href="http://netty.io/" rel="nofollow">Netty</a> is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients.</p>
<p>If you have a question about using Netty in your network application, this is the tag you should use.</p>
<... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T15:11:47.663",
"Id": "55479",
"Score": "0",
"Tags": null,
"Title": null
} | 55479 |
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-06-27T15:11:47.663",
"Id": "55480",
"Score": "0",
"Tags": null,
"Title": null
} | 55480 |
<p>NIO stands for 'New I/O'. It was introduced in JDK 1.4 in the java.nio package. It comprises several elements:</p>
<ol>
<li>A family of buffers that encapsulate the current position and limit, and can contain primitive types and arrays of them, and whose data can be held at either the Java level or the native level... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T15:12:49.830",
"Id": "55481",
"Score": "0",
"Tags": null,
"Title": null
} | 55481 |
NIO is Java 'New I/O' introduced in 1.4, providing non-blocking and multiplexed network I/O; 'direct' (native) buffers; file locks and mapped files; and character set codecs. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T15:12:49.830",
"Id": "55482",
"Score": "0",
"Tags": null,
"Title": null
} | 55482 |
Upload refers to the sending of data from a local system to a remote system such as a server or another client with the intent that the remote system should store a copy of the data being transferred, or the initiation of such a process | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T15:13:36.053",
"Id": "55484",
"Score": "0",
"Tags": null,
"Title": null
} | 55484 |
<p>I made this admin login script a while ago. It works fine in terms of checking the database for username and password and logs me in. What I don't quite understand is how to secure my login once in.</p>
<p><strong>Currently using:</strong></p>
<ul>
<li><p>Cookie and Session check to show admin pages</p>
<pre><co... | [] | [
{
"body": "<h3>Basic login idea</h3>\n<p>The easiest way is to set a username and password cookie and to check each time if the details are valid. This is, however, not very safe, as one could simply set their cookies as the password's hash and be logged in, without needing to know the clear text password. It's... | {
"AcceptedAnswerId": "55528",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T15:58:58.390",
"Id": "55487",
"Score": "5",
"Tags": [
"php",
"html"
],
"Title": "Admin Login Function with custom anti-spam"
} | 55487 |
<p>I have a series of four method calls that all return Try[Something], with the last returning Try[Unit]. Something like this:</p>
<pre><code>def getFields(): Try[List[A]] = { ... }
def getValues(): Try[List[B]] = { ... }
def createTmpFile(as: List[A], bs: List[B]): Try[C] { ... }
def runProcessWithFile(c: C): Try[Un... | [] | [
{
"body": "<p>Having a <code>Try[Unit]</code> is completely ok - it models the fact that there may be exceptions on a side effecting operation in a type. That your code looks ugly is not because your monad is wrong but because you used it wrong. You already started in modeling your application with monads, why ... | {
"AcceptedAnswerId": "55506",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T17:23:48.020",
"Id": "55490",
"Score": "2",
"Tags": [
"scala",
"exception-handling"
],
"Title": "Branching with multiple Try"
} | 55490 |
<p>I'm new to Databinding in MVP and I want to bind my DataGridView to a object list. This grid may be populated in two ways. </p>
<p>There are TextBoxes in the form and users can enter text, and when they press <kbd>Add</kbd> button, a new object is instantiated with the provided fields and then it is added to the li... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T18:12:45.590",
"Id": "97265",
"Score": "2",
"body": "You should probably spend some time to read through the MSDN walkthroughs. Specifically, you may want to look at the [How to: Bind Data to the Windows Forms DataGridView Control]... | [
{
"body": "<p>First some nitpicks:</p>\n\n<ul>\n<li><p>Variables should be camelCased, not PascalCased. The underscore prefixes are okay, but <code>_Model</code> is not. Let the underscore be your visual indicator. What you've done is confusing on the eyes. </p></li>\n<li><p>Don't fully qualify names unless you... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T17:43:29.477",
"Id": "55492",
"Score": "3",
"Tags": [
"c#",
".net",
"winforms",
"mvp",
"databinding"
],
"Title": "Binding a DataGridView to a List"
} | 55492 |
<p>As the title says, I refuse to use a common template engine. I have my reasons, so instead of doing this:</p>
<pre><code><ul>
<li><a href = "#">test</a>
<li>{CommonParam}</li>
</ul>
</code></pre>
<p>I do this:</p>
<pre><code>function listBlock($array){
echo '<ul>';
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T18:29:26.317",
"Id": "97269",
"Score": "0",
"body": "Depends where the array is coming from i guess, is it coming from a database, is it user inputted or is simply sent as arguments from a page?"
},
{
"ContentLicense": "CC B... | [
{
"body": "<p><a href=\"https://stackoverflow.com/questions/1942019/is-it-a-bad-idea-to-return-the-html-code-from-a-function-or-method\">Answer courtesy of JC</a></p>\n\n<p>In MVC Frameworks, you will often find this question answered a multitude of ways. Here are two principles that I attempt to live by, with ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T18:01:42.993",
"Id": "55494",
"Score": "1",
"Tags": [
"php",
"mvc",
"template"
],
"Title": "Refusing to use a common template engine"
} | 55494 |
<p>I'm trying to figure out how to refactor some code based on what codeclimate is telling me. So far it seems that any method that is longer than 5 lines or has an <code>if</code> statement is "complex". In this instance, I'm trying to create an event for a calendar based off of a meeting record.</p>
<p>Here is the ... | [] | [
{
"body": "<p>A few things caught my eye:</p>\n\n<ul>\n<li><p>You don't check whether <code>e.save</code> actually worked. If it fails, you'll have problems down the line. </p></li>\n<li><p><code>meeting.meeting_date_end ||= meeting.meeting_date_start</code><br>\nDon't set an attribute on a record you don't \"o... | {
"AcceptedAnswerId": "55514",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T18:27:06.567",
"Id": "55498",
"Score": "4",
"Tags": [
"ruby",
"ruby-on-rails",
"datetime"
],
"Title": "How could this \"complex method\" for codeclimate be refactored?"
} | 55498 |
<p>I have created a script to munge data off <a href="http://wals.info/languoid.tab?sEcho=1&iSortingCols=1&iSortCol_0=0&sSortDir_0=asc" rel="nofollow">this</a> tab-delimited table.</p>
<pre><code>from collections import defaultdict
from utils import sync_and_read, currentdirectory
class MiniWALS(dict):
... | [] | [
{
"body": "<p>There are a few efficiency improvements I can see:</p>\n\n<ol>\n<li><p>Don't continually do an operation on data if that data doesn't change. Take your <code>headerline</code> variable. Each time you loop through your <code>data</code>, you do <code>headerline.split('\\t')[1:]</code>. This is fair... | {
"AcceptedAnswerId": "55509",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T18:32:13.377",
"Id": "55499",
"Score": "2",
"Tags": [
"python",
"json",
"csv"
],
"Title": "Munging data off the World Atlas of Language Structures website"
} | 55499 |
<p>The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the pric... | [] | [
{
"body": "<p>The basic algorithm here looks decent.... though the use of the Stack is overkill. There is no need to keep previous members. in fact, a simple while loop, using what you have learned in previous loops, will be fine.</p>\n\n<p>Consider this:</p>\n\n<pre><code>public static int[] stockSpan(int[] st... | {
"AcceptedAnswerId": "55502",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T18:33:19.480",
"Id": "55500",
"Score": "5",
"Tags": [
"java",
"stack"
],
"Title": "Stock span problem"
} | 55500 |
<blockquote>
<p>Given an array of non-negative integers, find the largest multiple of 3 that can be formed from array elements.</p>
<p>For example, if the input array is {8, 1, 9}, the output should be "9 8 1", and if the input array is {8, 1, 7, 6, 0}, output should be "8 7 6 0".</p>
</blockquote>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T21:20:15.340",
"Id": "97307",
"Score": "0",
"body": "I got to this question as a result of inadvertedly leaving \"Ruby\" out of my search string, but before departing I cannot resist:\nfor `1.upto(a.size).flat_map { |n| a.permutatio... | [
{
"body": "<blockquote>\n <p>For example, if the input array is {8, 1, 9}, the output should be “9 8 1″</p>\n</blockquote>\n\n<p>So, let's say that the input array is <code>{ 4, 8, 15, 16, 23, 42 }</code>, what should the output be then? At first I expected it to be <code>\"4 8 15 16 23 42\"</code>, but then @... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T19:14:06.697",
"Id": "55503",
"Score": "5",
"Tags": [
"java",
"algorithm",
"queue"
],
"Title": "Find max-number div by three to be formed by array elements"
} | 55503 |
<p>My program 'Monkey', written in Go, can take a file like this:</p>
<blockquote>
<pre><code>+ 9 13
/ 10 2
</code></pre>
</blockquote>
<p>And prints the output (in the case for the 'file' above, '22' and '5'.)
Variables can also be declared to an expression. In this 'file':</p>
<blockquote>
<pre><code>* 5 4 : a
+ a... | [] | [
{
"body": "<p>As a general naming convention, go methods are either named <code>LikeThis</code> (for public methods) or <code>likeThis</code> (for package private methods). For a small, single file project like this it doesn't really matter too much, but it is a good habit to get into regardless.</p>\n\n<p>Your... | {
"AcceptedAnswerId": "55848",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T19:38:24.173",
"Id": "55508",
"Score": "4",
"Tags": [
"mathematics",
"go"
],
"Title": "File-based Equation Evaluation in Go"
} | 55508 |
<blockquote>
<p>Suppose there is a circle. There are n petrol pumps on that circle. You are given two sets of data.</p>
<ol>
<li>The amount of petrol that petrol pump will give.</li>
<li>Distance from that petrol pump to the next petrol pump.</li>
</ol>
<p>Calculate the first point from where a truck will be able to co... | [] | [
{
"body": "<p>Can you <em>prove</em> the algorithm works? It really looks suspicious. Besides, running it against a</p>\n\n<pre><code>{4,6}, {6,5}, {1,3}, {7,3}, {4,5}\n</code></pre>\n\n<p>test case returns <code>2</code>. (Hint: the correct algorithm is much simpler).</p>\n",
"comments": [],
"meta_data... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T19:59:43.443",
"Id": "55511",
"Score": "2",
"Tags": [
"java",
"queue"
],
"Title": "Decide the start of the circular gas station path"
} | 55511 |
<blockquote>
<p>Given an array and an integer <em>k</em>, find the maximum for each and every contiguous subarray of size <em>k</em>.</p>
<p>Examples:</p>
<p>Input:</p>
<pre><code>arr[] = {1, 2, 3, 1, 4, 5, 2, 3, 6}
k = 3
</code></pre>
<p>Output:</p>
<pre><code>3 3 4 5 5 5 6
</code></pre>
<p>Input:</p>
<pre><code>arr[]... | [] | [
{
"body": "<p>Here you are using a few structures which I feel are not the right tool for the job.</p>\n\n<p>Firstly, you are given an array of int, but you are returning a <code>List<Integer></code>. I dislike <code>List<Integer></code>, but even worse than using a List for primitives, is using a m... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T20:57:35.643",
"Id": "55513",
"Score": "2",
"Tags": [
"java",
"algorithm",
"queue"
],
"Title": "Maximum of all subarrays of size k"
} | 55513 |
<p>What can I improve in this form builder? I'm looking for code review, optimization, and best practices.</p>
<pre><code><?php
/**
* Project: validator - File: form_builder.php
* Author: danutz0501 ©copyright 2014
* Date : (m/y) 06/2014
*/
class form_builder{
private $form;
public function __construc... | [] | [
{
"body": "<p>Let's start with the dry review, and then jump to the juicy stuff.</p>\n\n<ul>\n<li>Naming convention, it's common in PHP to name Class names in uppercase, <code>class FormBuilder</code>.</li>\n<li>Empty constructor, if you don't need a constructor, why make one?</li>\n<li><strong>XSS vulnerabilit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T21:28:36.083",
"Id": "55515",
"Score": "4",
"Tags": [
"php"
],
"Title": "Form builder improvment"
} | 55515 |
<p>I have the code below that gets hit several hundred times per second. I'm wondering what I can do to improve performance. It seems that there should be some way to build up a substring index. Is there some existing examples of that or an explanation on how to do this?</p>
<pre><code>using System;
using System.Colle... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T22:06:35.483",
"Id": "97319",
"Score": "0",
"body": "The two readonly Lists should be `static`, but that won't affect the speed."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T22:09:01.153",
"Id"... | [
{
"body": "<p>As with every performance question: <strong>run your code through a profiler</strong></p>\n\n<p>That said, your <code>ShouldNotLog</code> method can be simplified. There is not much reason to check your auto subscribe list prior to checking your suppress list:</p>\n\n<ul>\n<li>_shouldNotLogs is a... | {
"AcceptedAnswerId": "55525",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T21:52:25.300",
"Id": "55518",
"Score": "3",
"Tags": [
"c#",
"performance"
],
"Title": "performance on this substring search"
} | 55518 |
<p>I'm getting familiar with python and I'm still learning it's tricks and idioms. </p>
<p>Is there an better way to implement <code>print_html()</code> without the multiple calls to <code>html_file.write()</code>? I only separated the HTML for clarity instead of putting the entire string inside <code>write()</code>... | [] | [
{
"body": "<p>You can make the HTML a multi-line string with formatting templates (see <a href=\"https://stackoverflow.com/q/2504411/3001761\">this SO question</a> for discussion on indentation, I've kept it simple):</p>\n\n<pre><code>def print_html(car, html_file):\n html = '''<h3>{0[price]}</h3>... | {
"AcceptedAnswerId": "55543",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T22:19:21.187",
"Id": "55522",
"Score": "5",
"Tags": [
"python",
"html",
"web-scraping"
],
"Title": "Clean up repeated file.writes, if/elses when adding keys to a dict"
} | 55522 |
<p>This is the second time I have implemented saving and loading for a game using Objective-C. I am using the built in NSCoding methods. I would love to hear opinions about NSCoding and whether or not it is a viable option for saving and loading games. My code does function, however there is a lot of boilerplate cod... | [] | [
{
"body": "<blockquote>\n <p>Is this method of implementing saving and loading reliable and efficient?</p>\n</blockquote>\n\n<p>It should be reliable. And if saving all of this information is necessary, then this is almost certainly the most efficient way to do it all.</p>\n\n<p>The way to improve efficiency ... | {
"AcceptedAnswerId": "55536",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T22:48:00.577",
"Id": "55527",
"Score": "7",
"Tags": [
"game",
"objective-c",
"serialization",
"file-structure"
],
"Title": "Save Games on iOS with NSCoding"
} | 55527 |
<p>I've posted <a href="https://meta.stackexchange.com/questions/234662/should-shift-spacebar-create-a-tab-indent-in-se">this feature request</a> and would like to improve the code involved to handle a few "bugs" (not that it's necessary to provide such code, just for my own practice), but <a href="http://jsfiddle.net/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T00:03:11.273",
"Id": "97330",
"Score": "0",
"body": "Oops, I made a change there that I didn't test and I've got variable conditions there that are out of scope! fail..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>You can use <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\" rel=\"nofollow\"><code>charAt</code></a> to grab the preceding character and check it against a space, newline, or empty string (the case when the cursor is at the start). But let... | {
"AcceptedAnswerId": "55534",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T23:41:29.100",
"Id": "55531",
"Score": "10",
"Tags": [
"javascript",
"stackexchange"
],
"Title": "Script to convert Shift + Spacebar into four spaces on SE"
} | 55531 |
<p>I wonder if the following configuration is correct and the handlers are in the right order:</p>
<pre><code>application: myAppName
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: website/index.html
upload: website/index.html
- url: /
static_dir: website
</code></... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T04:33:36.530",
"Id": "55539",
"Score": "4",
"Tags": [
"google-app-engine",
"yaml"
],
"Title": "App.yaml configuration for Google App Engine"
} | 55539 |
<p><img src="https://i.stack.imgur.com/v7Yd1.png" alt="Play! Framework logo"></p>
<p>The <strong><a href="http://www.playframework.com/" rel="nofollow noreferrer">Play! Framework</a></strong> is a modern Java (and Scala) web application open-source framework that provides a clean alternative to bloated Enterprise Java... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T06:19:27.540",
"Id": "55540",
"Score": "0",
"Tags": null,
"Title": null
} | 55540 |
The Play! Framework is a modern Java and Scala web application open-source framework that provides a clean alternative to bloated Enterprise Java stacks. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T06:19:27.540",
"Id": "55541",
"Score": "0",
"Tags": null,
"Title": null
} | 55541 |
<p>I've posted a similar program previously, but I have not made any major modifications in the code, so I am posting it again by deleting the previous question.</p>
<p><strong>I am afraid of the thread keyword</strong> and I am not too familiar with threads and blocking, so can you please review this code for me?</p>... | [] | [
{
"body": "<p>First, remove <code>import play.api.libs.concurrent.Execution.Implicits._</code>. You don't want the default Play execution context. Instead, you should use one of the <code>ExecutionContext</code>s you've defined and aren't using. Perhaps define one for S3 operations alone, and you don't need the... | {
"AcceptedAnswerId": "55551",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T09:53:00.177",
"Id": "55544",
"Score": "4",
"Tags": [
"multithreading",
"scala",
"amazon-s3"
],
"Title": "Uploading a video in S3 Using Future"
} | 55544 |
<p>My objective is to update necessary data using one function instead of having different functions to update different fields. So, I've created one and I think this is not really elegant, efficient or secure. I would seriously like a review if possible.</p>
<blockquote>
<pre class="lang-none prettyprint-override">... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T12:23:10.067",
"Id": "97374",
"Score": "0",
"body": "i would use ? for data[0] too"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T12:23:37.510",
"Id": "97375",
"Score": "0",
"body": "@Mar... | [
{
"body": "<p><a href=\"http://www.bobby-tables.com\">You are vulnerable to SQL Injections.</a> Even when you are using Prepared statements, doing It wrong will kill you.</p>\n\n<blockquote>\n<pre><code>$sql = \"UPDATE users SET \" . $data[0] . \"=? WHERE username=?\";\n</code></pre>\n</blockquote>\n\n<p>This m... | {
"AcceptedAnswerId": "55548",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T12:15:26.033",
"Id": "55546",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"security",
"mysqli"
],
"Title": "Updating necessary data using just one function"
} | 55546 |
<p>I have run into a bit of a dilemma. Binding user input and building a prepared statement is all well and good, but what if I need the user input as a variable for a compare?</p>
<p>Can I just create a function to clean the input?</p>
<p>This is the line that worries me:</p>
<pre><code>$password = $_POST['passwor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T12:56:12.893",
"Id": "97388",
"Score": "4",
"body": "http://www.php.net/manual/en/function.password-hash.php"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T12:57:51.330",
"Id": "97390",
"Scor... | [
{
"body": "<p>You should also make heavy use of the filter functions of PHP.</p>\n\n<pre><code><?php\n\nif (filter_input(INPUT_POST, \"form_id\", FILTER_UNSAFE_RAW) === filter_input(INPUT_SESSION, \"form_id\", FILTER_UNSAFE_RAW)) {\n $username = filter_input(INPUT_POST, \"username\", FILTER_SANITIZE_STRING,... | {
"AcceptedAnswerId": null,
"CommentCount": "14",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T12:47:15.840",
"Id": "55549",
"Score": "7",
"Tags": [
"php",
"pdo",
"authentication"
],
"Title": "Login system, PDO and me"
} | 55549 |
<p>I wrote the following that tries to crack a message that was encrypted via a simple Caesar cipher through brute force. I'm fairly new to Haskell, so any and all input is appreciated.
Because there are infinite ways that something could have been encrypted, it assumes very simple "offset" encryption; like what <code>... | [] | [
{
"body": "<pre><code>import Data.Char (chr, isPunctuation, isSymbol, ord)\n\ndecUpper = 127 --Upperbound of normal characters\ndecLower = 32 --Lowerbound of normal characters\ndecRange = decUpper - decLower --Total range\n\ntype Message = String\n\n-- | Checks if the char is in range\nisInRange :: Char -> B... | {
"AcceptedAnswerId": "56692",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T15:45:56.797",
"Id": "55553",
"Score": "5",
"Tags": [
"beginner",
"haskell",
"caesar-cipher"
],
"Title": "Brute force Caesar Cipher decrypter"
} | 55553 |
<p>After reading a lot about F#, I am today cutting my very first real life F# code and I'd appreciate any feedback on my approach.</p>
<p>I'm writing a simple utility to analyse a log file. The code below represents my approach for identifying sections of the log and representing them in a structure. The "real life... | [] | [
{
"body": "<p>Welcome to the world of F#! Your code is looking good, and thanks for posting the LinqPad file. Here are a couple of pointers:</p>\n\n<ul>\n<li><code>sprintf ... |> System.Console.WriteLine</code> can be replaced by a call to <code>printfn</code>.</li>\n<li>The variable name <code>i</code> in t... | {
"AcceptedAnswerId": "55606",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T16:35:14.687",
"Id": "55554",
"Score": "4",
"Tags": [
"f#"
],
"Title": "Parsing sections from a log file using F#"
} | 55554 |
<p>I've been designing a game server, where a player has inventory, bank, and other features with items.</p>
<p><em>There are some definitions of what item can be in my game:</em></p>
<ul>
<li>Item is either stackable or not stackable.</li>
<li>If item is stackable, item's amount can be up to 100 per stack.</li>
</ul... | [] | [
{
"body": "<h3>About your existing code</h3>\n<p>There's only two things I have to complain about in your current <code>ItemStorage</code>.</p>\n<ol>\n<li><p><code>public void setItems(int[] a, int[] b)</code> See those parameter names? <code>a</code> and <code>b</code>. They represent completely different thin... | {
"AcceptedAnswerId": "55559",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T17:15:09.990",
"Id": "55555",
"Score": "11",
"Tags": [
"java",
"object-oriented",
"game"
],
"Title": "Inventory - how to handle items?"
} | 55555 |
<p>The program should output this:</p>
<pre class="lang-none prettyprint-override"><code>_1 _1
_1 0
_1 1
0 _1
0 1
1 _1
1 0
1 1
</code></pre>
<p>Currently I have this code:</p>
<pre class="lang-none prettyprint-override"><code>(4 ~: i.9) # (3 # i:1) ,. 9 $ i:1
</code></pre>
<p>But I think it can be better.... | [] | [
{
"body": "<p>\nYour solution relies excessively on magic numbers, such as 9 and 3. It also obscures the Cartesian-product aspect of the problem. Therefore, I think it could be better written as:</p>\n\n<pre class=\"lang-none prettyprint-override\"><code>(< (< (< 4))) { ,/ > { ;~i:1\n</code></pre>... | {
"AcceptedAnswerId": "55600",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T18:53:24.187",
"Id": "55557",
"Score": "2",
"Tags": [
"functional-programming",
"matrix",
"j"
],
"Title": "Initializing an array of relative coordinates of all adjacent 2D matr... | 55557 |
<p>I'm implementing a login script and I want it to be more secure:</p>
<pre><code>function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = SECURE;
// This stops JavaScript being able to access the session id.
$httponly = true;
//... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T07:17:39.153",
"Id": "97473",
"Score": "0",
"body": "If i can get physical access to your machine as an attacker i can grab your session.\nThe rest of his script can be found here:\nhttp://www.wikihow.com/Create-a-Secure-Login-Scrip... | [
{
"body": "<p>Checking an \"constant\" IP address is an bad idea because of ISP with load balancing. IP address should change to less busy proxy. </p>\n\n<p>In most of cases IP address belongs to the same block. It is called CIDR matching:</p>\n\n<pre><code>function cidr_match($ip, $range)\n{\n list ($subnet... | {
"AcceptedAnswerId": "55561",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T20:13:50.977",
"Id": "55558",
"Score": "4",
"Tags": [
"php",
"security",
"session"
],
"Title": "Preventing session hijacking"
} | 55558 |
<p>This script fast forward merges a branch and then deletes the old one. I normally run it like this:</p>
<blockquote>
<pre><code>git m master feature
</code></pre>
</blockquote>
<p><a href="https://gist.github.com/tieTYT/78d1680eaba4fb08bc90" rel="nofollow">Here's a link to the gist</a>.</p>
<pre><code>#!/bin/bas... | [] | [
{
"body": "<p>Two minor notes:</p>\n\n<ol>\n<li><p>You can restore a deleted branches with the <a href=\"https://stackoverflow.com/q/3640764/843804\">reflog</a> (although reflog entries can expire).</p></li>\n<li><p>I would check at the beginning whether the feature (<code>$2</code>) branch exists or not. In th... | {
"AcceptedAnswerId": "55569",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T23:25:41.373",
"Id": "55566",
"Score": "4",
"Tags": [
"bash",
"git"
],
"Title": "Git script that fast forward merges and deletes the old branch"
} | 55566 |
<p>I've refactored my code such that every function has only one responsibility. Now I'd like like to work on making it DRY.</p>
<p>I'm noticing a lot of duplication in the <code>DocumentAnalyzer</code> class. In nearly every function, I make a reference to <code>@document</code>.</p>
<p>Should my one-statement funct... | [] | [
{
"body": "<p>To my eyes, there should really only be one class: <code>Document</code>.</p>\n\n<p>As you noticed, the methods in <code>DocumentAnalyzer</code> all use <code>@document</code>. The analyzer class is so tied up in <code>Document</code> (and its methods are so simple) that it probably shouldn't be a... | {
"AcceptedAnswerId": "55572",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T23:45:51.150",
"Id": "55567",
"Score": "7",
"Tags": [
"object-oriented",
"ruby"
],
"Title": "Less-repetitive code for document-analyzer"
} | 55567 |
<pre><code>public HttpResponseMessage Post(LongUrlModel model)
{
if (ModelState.IsValid)
{
var baseAddress = Request.RequestUri.ToString().TrimEnd('/');
if (model.LongUrl.StartsWith(baseAddress))
{
ModelState.AddModelError("", "You cant shorten a URL that belongs to this doma... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T01:53:36.250",
"Id": "97458",
"Score": "0",
"body": "what does *snip* mean? And also, is this a MVC WebApi project?"
}
] | [
{
"body": "<p>In regards to your question:</p>\n\n<blockquote>\n <p>I feel as though there could be a way to refactor this code so that\n <code>Request.CreateErrorResponse</code> only occurs in the code once, but I cannot\n see how at the moment.</p>\n</blockquote>\n\n<p>I would consider reducing the nesting... | {
"AcceptedAnswerId": "55577",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T01:18:17.007",
"Id": "55573",
"Score": "4",
"Tags": [
"c#",
"validation"
],
"Title": "Additional model validation"
} | 55573 |
<p>I have written code which is easy to understand, but may not be efficient but will solve the purpose.</p>
<pre><code>public static void main(String a[]){
int ar[] ={1,2,3,4};
boolean flag=false;
int count=0;
while(count<ar.length){
for(int i=0;i<ar.length-1;i++){
... | [] | [
{
"body": "<p>As you may be aware, your solution takes O(<em>n</em><sup>2</sup>) time. Sorting can bring that down to O(<em>n</em> log <em>n</em>). Hashing can produce an O(<em>n</em>) solution. Of course, for a four-element array, performance isn't an issue at all.</p>\n\n<hr>\n\n<p>Please take care to inde... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T03:32:33.583",
"Id": "55575",
"Score": "5",
"Tags": [
"java",
"array"
],
"Title": "Searching for duplicates without any collection or sorting"
} | 55575 |
<p>I really enjoy Haskell but feel I still have a total beginner's style, and would like to move beyond that. The code below - for Dijkstra's shortest path algorithm - is a case in point. I feel as though I have ended up with a copy of the imperative pseudo code I began with, having done some small transformations, b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T08:41:46.740",
"Id": "97486",
"Score": "0",
"body": "Please update the code so that it compiles, in particular, `DijkstraScores` and `largeVal` isn't defined."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014... | [
{
"body": "<p>Nice exercise!</p>\n\n<blockquote>\n <p>But the big decision I needed was how to store the 3 elements of state</p>\n \n <ul>\n <li>The results</li>\n <li>The Dijkstra scores of the points not yet turned into results; and</li>\n <li>The set of points already found (i.e. the keys of the result... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T06:09:40.600",
"Id": "55579",
"Score": "5",
"Tags": [
"algorithm",
"haskell",
"graph"
],
"Title": "Dijkstra's Algorithm in Haskell"
} | 55579 |
<p>I am new to jMockIt and so wanted to learn it. I thought of implementing a synonym servlet kata. The servlet takes a word as input and returns the synoyms of the words as a comma seperated string. The objective of the kata that I implemented was:</p>
<ol>
<li>Learning jMockIt stubbing and mocking features.</li>
<li... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T15:18:50.820",
"Id": "97523",
"Score": "0",
"body": "It's just a detail, but declaring the member variables at the end of the class is unusual and does not help for readability."
}
] | [
{
"body": "<p>Your tests looks good although I don't have any experience with JMockit (just Mockito and EasyMock) so I might miss some JMockit-specific issues. Here is a few notes about the code:</p>\n\n<ol>\n<li><p>Instead of</p>\n\n<blockquote>\n<pre><code>String[] tokenizedURL = URL.split(\"/\");\nString wor... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T06:30:28.887",
"Id": "55580",
"Score": "1",
"Tags": [
"java",
"unit-testing",
"mocks"
],
"Title": "State and Interaction based testing using jMockIt"
} | 55580 |
<p>I started a project to build my own invoicing and management system to take the place of prohibitively expensive QuickBooks software. This will be broken down in 5 steps, with the current step in bold font, and previous steps linked. </p>
<ol>
<li><strong>Design the DB schema and table relationships, and insert dat... | [] | [
{
"body": "<p>I'll review your SQL statements as code. For a proper review of the schema, consult <a href=\"http://dba.stackexchange.com\">Database Administrators</a> instead.</p>\n\n<p><del>You haven't declared any <a href=\"http://dev.mysql.com/doc/refman/5.5/en/create-table-foreign-keys.html\">foreign key c... | {
"AcceptedAnswerId": "55587",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T07:15:18.937",
"Id": "55583",
"Score": "9",
"Tags": [
"sql",
"mysql"
],
"Title": "Step 1: PsychoProductions management tool project"
} | 55583 |
<p>I'm polling an ashx handler to check if a specific file is present and return true or false depending on it.</p>
<pre><code>public void ProcessRequest(HttpContext context)
{
int myId;
if (context.IsRequestClean())
{
if (int.TryParse(context.Request["id"], out myId))
{
var dir... | [] | [
{
"body": "<p>If you want a shorter time between file is created until the client is notified, I recomment you implement long-running queries, for example using SignalR. </p>\n\n<p>Then setup a <a href=\"http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx\" rel=\"nofollow\">Fi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T07:19:59.023",
"Id": "55584",
"Score": "2",
"Tags": [
"c#",
"performance",
"file-system"
],
"Title": "Faster file lookup"
} | 55584 |
<p>I recently started using the builder pattern in one of my projects:</p>
<pre><code>public final class DataKey {
private final long userId;
private final String uuid;
private final String deviceId;
private final int clientId;
private final long timeout;
private final FlowEnum flow;
priv... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T09:10:08.180",
"Id": "97494",
"Score": "0",
"body": "Personally I would opt for a factory method pattern as the Builder class does very little. There would be two static factory methods - createFromUserId(...) and createFromDeviceId... | [
{
"body": "<h1>DataKey</h1>\n\n<h3>State- vs. Input validation:</h3>\n\n<p>In your constructor you do something not quite intelligent. You first set all the fields and <strong>then</strong> check them for integrity. </p>\n\n<p>IMO you should check the input data for validity <strong>before</strong> using it wit... | {
"AcceptedAnswerId": "55602",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T07:43:05.020",
"Id": "55585",
"Score": "4",
"Tags": [
"java",
"performance",
"design-patterns"
],
"Title": "Acquiring a data key"
} | 55585 |
<p>My task was to take a configuration specified as a dictionary and run some function with it (the actual function is not relevant here). After implementing that, I was asked to allow some "sweeping" of values for the parameters.</p>
<p>After some discussion it was decided to keep the dictionary structure, but allow ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T17:28:46.570",
"Id": "97981",
"Score": "0",
"body": "Can you explain your task in more detail, please? I read your opening paragraph and it makes no sense to me. The examples don't help either: they are totally meaningless. More con... | [
{
"body": "<h3>1. General comments</h3>\n\n<ol>\n<li><p>To run the doctests in <code>file.py</code>, just run:</p>\n\n<pre><code>python -m doctest file.py\n</code></pre>\n\n<p>(See the documentation for the <a href=\"https://docs.python.org/3/library/doctest.html#simple-usage-checking-examples-in-docstrings\" r... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-06-29T08:03:49.063",
"Id": "55588",
"Score": "4",
"Tags": [
"python",
"beginner",
"recursion",
"hash-map"
],
"Title": "Modifying nested dictionaries in Python"
} | 55588 |
<p>I've written some code that is suppose to read socket all the time and when needed return the partial data from it. I just want the response to send a command. It works, but this is a bit messy implementation.</p>
<p>Is it possible to write it better?</p>
<pre><code>public StringBuilder message = new StringBuilder... | [] | [
{
"body": "<p>You are locking on a public field <code>message</code> which might cause a <code>deadlock</code>. If locking is needed, then do it on a <code>private</code> field.</p>\n\n<pre><code>private final Object SYNC_OBJECT = new Object();\n...\nsynchronized(SYNC_OBJECT){\n}\n</code></pre>\n\n<p>Your class... | {
"AcceptedAnswerId": "55611",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T08:57:47.830",
"Id": "55591",
"Score": "6",
"Tags": [
"java",
"socket"
],
"Title": "Read partial socket message"
} | 55591 |
<p>J is a high-level, general-purpose, high-performance array programming language.</p>
<p>J is particularly strong in the mathematical, statistical, and logical analysis of data.</p>
<p>J systems have:</p>
<ul>
<li>an integrated development environment</li>
<li>standard libraries, utilities, and packages</li>
<li>a... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T10:10:43.243",
"Id": "55596",
"Score": "0",
"Tags": null,
"Title": null
} | 55596 |
J is a high-level, general-purpose, high-performance array programming language. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T10:10:43.243",
"Id": "55597",
"Score": "0",
"Tags": null,
"Title": null
} | 55597 |
<p>In a jPanel, I'm displaying a 1203x1203 background that I rotate every 30ms. Problem is, Swing is known to be a slow library, and I assume rotating a huge picture at a quick rate would be quite resources demanding. But I've a powerful PC, and even if on mine it runs fine, I wonder if on slower machines it will be as... | [] | [
{
"body": "<p>Here is something you could do which would work for computers not fast enough to rotate the image every 30 ms. Instead of requesting a repaint every 30ms, define the <code>angularVelocity</code> (rads / second) and call a repaint every 30 ms <strong>or</strong> as fast as possible, if it can't ma... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T11:08:43.523",
"Id": "55599",
"Score": "6",
"Tags": [
"java",
"performance",
"swing",
"image",
"animation"
],
"Title": "Rotating background using Swing: performance issues... | 55599 |
<p>I made a LinkChecker program which checks URLs from a text file and outputs status into another file like this:</p>
<blockquote>
<pre><code>http://valid-url.com;OK
http://invalid-url.com;The remote server returned an error: (404) Not Found.
</code></pre>
</blockquote>
<p>I have about 1400 URLs in the input file an... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-03T09:09:20.223",
"Id": "98411",
"Score": "0",
"body": "If you want high degrees of concurrency, you'll need to increase [ServicePointManager.DefaultConnectionLimit](http://msdn.microsoft.com/en-us/library/system.net.servicepointmanage... | [
{
"body": "<p>You forgot using <code>using</code> in your <code>StreamReader</code></p>\n\n<pre><code> using(StreamReader file = new StreamReader(inputFile)){\n string outputFile = @\"D:\\tmp\\out.txt\";\n\n ClearOutputFile(outputFile);\n\n while(!string.IsNullOrEmpty(line = file.ReadLine()))\n {... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T12:56:26.687",
"Id": "55603",
"Score": "7",
"Tags": [
"c#",
"http",
"url"
],
"Title": "How can I better my URL checker program?"
} | 55603 |
<p>I have a <code>comboBox</code> and a <code>TextBox</code> in the <code>View</code> and when the view is loaded, the <code>ComboBox</code> should be populated. After that when a user selects particular item from the <code>ComboBox</code>, its related <code>ValueMember</code> should be displayed in the <code>TextBox</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T10:56:56.300",
"Id": "97683",
"Score": "1",
"body": "Unless you are supporting some 10 years old project, you should consider switching to wpf. Winforms is an obsolete framework."
}
] | [
{
"body": "<p>It looks pretty clean. As far as I can tell, you have a good separation of concerns. Everything is properly cased and your functions have verb-noun names. All good things. </p>\n\n<p>The only nitpick I have is the <code>bs</code> variable. I'm not a fan of ultra short names of any kind. You could ... | {
"AcceptedAnswerId": "55986",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T13:02:16.290",
"Id": "55605",
"Score": "2",
"Tags": [
"c#",
".net",
"winforms",
"mvp"
],
"Title": "Binding data to a ComboBox and then showing ValueMember in another TextBo... | 55605 |
<p>I have a method that transforms any input <code>uint</code> into a <code>[min,max]</code> set. I am looking for improvements on the function, specifically to get rid of the <code>input == uint.MaxValue</code> case.</p>
<pre><code>public static uint NumberInRange(uint input, uint min, uint max)
{
decimal divider... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T14:48:21.887",
"Id": "97521",
"Score": "0",
"body": "you should write some edge-case unit-tests but I don't think that you need the part where you check vor max-Value at all"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creat... | [
{
"body": "<p>This code implicitly types the <code>i</code> variable. Why? You already know that <code>i</code> will be a <code>uint</code> type. <a href=\"http://msdn.microsoft.com/en-us/library/bb384061.aspx\" rel=\"nofollow\">Microsoft recommends against this</a>.</p>\n\n<blockquote>\n <p>The use of var doe... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T13:29:14.277",
"Id": "55607",
"Score": "4",
"Tags": [
"c#",
"interval"
],
"Title": "Mapping uint to value within min/max set"
} | 55607 |
<p>Please take a look at this class and point out its flaws. I am developing a simple <a href="http://en.wikipedia.org/wiki/Finite_element_method" rel="nofollow">Finite Element Method</a> analysis with PHP.</p>
<p>What this class basically does:</p>
<p>Given an input set (coordinates, properties, plane type), calcul... | [] | [
{
"body": "<p>Someone else will most likely point out several more points to your code.</p>\n\n<p>However, here are two things that have jumped out:</p>\n\n<ol>\n<li><p>Your static class is not scalable. This is one flawed aspect of the class that you have written. Also, OOP means Object Oriented, right? You ca... | {
"AcceptedAnswerId": "55804",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T16:22:08.137",
"Id": "55615",
"Score": "4",
"Tags": [
"php",
"object-oriented"
],
"Title": "Finite Element Method analysis"
} | 55615 |
<p>I was trying to implement a <code>foldTree</code> function to generate a balanced binary tree from a list of values using <code>foldr</code> (Question 2 <a href="http://www.cis.upenn.edu/~cis194/hw/04-higher-order.pdf" rel="nofollow">here</a>), but the resulting solution is not really written in a proper manner:</p>... | [] | [
{
"body": "<p>While the output should be a balanced tree, it seems it's not required to be ordered in any way (at least the given example there isn't). So it's definitely not a heap. And the solution is required to use <code>foldr</code>, which yours doesn't satisfy.</p>\n\n<p>You need to split the task into tw... | {
"AcceptedAnswerId": "55624",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T17:44:53.300",
"Id": "55620",
"Score": "2",
"Tags": [
"haskell",
"functional-programming",
"tree",
"higher-order-functions"
],
"Title": "Folding with trees"
} | 55620 |
<p>In this problem you are given input of phone numbers and you are supposed to determine whether any number is the prefix of another. I have an <code>addchild</code> method that returns true or false if a given string can be inserted and is not a prefix of another string. How could I improve the efficiency of my code ... | [] | [
{
"body": "<ul>\n<li><p>Instead of <code>children = new Node[11]</code>, I would use a <code>Map<Integer, Node></code>. I'm not sure how you came up with 11.</p></li>\n<li><p>Sorting is quite expensive. Maybe you can solve it with a trie alone without sorting, or with sorting alone without a trie.</p></... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T18:06:11.353",
"Id": "55622",
"Score": "2",
"Tags": [
"java",
"optimization",
"algorithm",
"strings",
"trie"
],
"Title": "Trie SPOJ Problem - PhoneList TLE"
} | 55622 |
<p>Could you please tell me if there is better way of performing division without <code>+</code>, <code>*</code> or <code>/</code>?</p>
<p>I've tested this code for different values of <code>a</code> and <code>b</code>. Could you please tell me if there is a cleaner solution?</p>
<pre><code> private static int div... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T18:57:02.303",
"Id": "97578",
"Score": "0",
"body": "When you tested this code for different values, what values did you test? Were the results correct? Even the most simplest tests I'm doing returns incorrect results. Code Review i... | [
{
"body": "<p>First of all, please keep your indentation consistent; it's all over the place here. Java code is supposed to be indented by four spaces. Also, try not to put whitespace in random places. Keep things consistent.</p>\n\n<p>Also, here are some additional cleanliness tips:</p>\n\n<ul>\n<li><p>Don'... | {
"AcceptedAnswerId": "55628",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T18:28:26.360",
"Id": "55625",
"Score": "0",
"Tags": [
"java",
"interview-questions"
],
"Title": "Division without using addition, multiplication or division"
} | 55625 |
<p>Detect if tree is complete binary tree. This question is improvement over previously asked <a href="https://codereview.stackexchange.com/questions/54970/detect-a-complete-binary-tree">here.</a> Looking for code-review, optimizations and best practices.</p>
<p>Verifying both space and time complexity to be O(n), whe... | [] | [
{
"body": "<p>I'm not even going to look at cosmetic issues like variable names (which look reasonably ok anyway).</p>\n\n<ol>\n<li><p>I fail to see why the constructor consists of just one line, which is a call to a private method. Eliminate the <code>create</code> method and roll it's code into the constructo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T18:48:59.483",
"Id": "55626",
"Score": "2",
"Tags": [
"java",
"algorithm",
"tree",
"reinventing-the-wheel"
],
"Title": "Detect if a tree is complete binary tree"
} | 55626 |
<p>We have machine hostname as -</p>
<pre><code>dbx111.dc1.host.com
dbx112.dc2.host.com
dcx113.dc3.host.com
dcx115.dev.host.com
</code></pre>
<p>Here <code>dc1</code>, <code>dc2</code>, <code>dc3</code> and <code>dev</code> are our <code>datacenter</code> and we will be having only four <code>datacenter</code> as of... | [] | [
{
"body": "<p><code>final</code> is meaningless on static methods :</p>\n\n<pre><code>private static final String getHostNameOfServer() {\n</code></pre>\n\n<p>For the following :</p>\n\n<pre><code>// below if else, looks pretty odd, may be it can be improved better?\nif (f.equals(FlowTypeEnum.DEVICEFLOW)) {\n ... | {
"AcceptedAnswerId": "55633",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T18:49:01.433",
"Id": "55627",
"Score": "6",
"Tags": [
"java",
"optimization",
"enum"
],
"Title": "Efficiently returning the string basis on current datacenter"
} | 55627 |
<p>Curious to know how I can improve it, especially the pattern matching part seems a bit repetitive at the moment (lots of <code>case x if ds(x)</code>)</p>
<pre><code> def binarySearch(ds: Array[Double], key: Double): Int = {
@annotation.tailrec
def go(low: Int, mid: Int, high: Int): Int = {
mid match... | [] | [
{
"body": "<p>the <code>high <= low</code> part does not involve <code>x</code> and could be pulled out of the case. The rest is fine IMHO.</p>\n\n<p>One remark: the <code>-1</code> return in the error-case is a bit of a <em>smell</em> - why not return <code>Option[Int]</code> instead?</p>\n\n<p>And finally:... | {
"AcceptedAnswerId": "55631",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T18:57:16.600",
"Id": "55629",
"Score": "7",
"Tags": [
"beginner",
"functional-programming",
"scala"
],
"Title": "Binary search in functional-style Scala"
} | 55629 |
<p>I've created a utility program for combining multiple .vec files into one. The program's main application is in training haar cascade classifiers in openCV (<a href="http://docs.opencv.org/doc/user_guide/ug_traincascade.html" rel="nofollow">details</a>). This is my first open source contribution that other people ma... | [] | [
{
"body": "<p>I'm not an expert in Python, but I think you can improve it in some ways:</p>\n\n<ul>\n<li><p>Instead of making the user write down the names at the end of the file, you could make the script take them from the console using (after checking they exist)</p>\n\n<pre><code>vec_directory = sys.argv[1]... | {
"AcceptedAnswerId": "55635",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T19:47:51.760",
"Id": "55632",
"Score": "3",
"Tags": [
"python",
"opencv"
],
"Title": "Combining multiple files of uncommon filetype into one"
} | 55632 |
<blockquote>
<p><strong>K and R Exercise 5-10</strong></p>
<p>Write the program expr, which evaluates a reverse Polish expression
from the command line, where each operator or operand is a separate
argument. </p>
<p>For example,</p>
<pre><code>expr 2 3 4 + *
</code></pre>
<p>evaluates</p>
<pre><c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T21:31:02.683",
"Id": "97617",
"Score": "0",
"body": "So what exactly are you asking, exactly?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T01:49:34.650",
"Id": "97646",
"Score": "1",
"b... | [
{
"body": "<ul>\n<li>Your function is called <code>parse_polish()</code>, but it actually does much more: it evaluates the expression too!</li>\n<li><code>pop()</code> takes no arguments, and <code>push()</code> takes just one argument, so I deduce that they must be operating on a global variable, which is bad ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T20:04:22.347",
"Id": "55634",
"Score": "5",
"Tags": [
"c",
"programming-challenge",
"math-expression-eval"
],
"Title": "Basic Reverse Polish CL Parser"
} | 55634 |
<p>The model takes a long time to run. I have tried to vectorise it as far as I can, but it's still taking about a day to compute. I'm wondering if it's possible to speed it up.</p>
<p>Maybe the problem isn't even with the code, but with the model being improper/bad priors/...? Or maybe the data set is simply very lar... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T22:05:50.370",
"Id": "97619",
"Score": "0",
"body": "Could you describe the purpose of this code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T22:26:14.250",
"Id": "97622",
"Score": "0",
... | [
{
"body": "<p>You made a typo. The line</p>\n\n<pre><code>responses ~ bernoulli_logit(theta);\n</code></pre>\n\n<p>should be outside the <code>for</code> loop in the <code>model</code> block.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T21:31:14.257",
"Id": "55640",
"Score": "2",
"Tags": [
"performance",
"r",
"stan"
],
"Title": "Data model code running too slowly"
} | 55640 |
<p>The <a href="http://mc-stan.org" rel="nofollow">stan Webpage</a> describes this package as:</p>
<blockquote>
<p>Stan is an open-source package for obtaining Bayesian inference using the No-U-Turn sampler, a variant of Hamiltonian Monte Carlo. </p>
</blockquote>
<p>Stan is developed by statistician <a href="http:... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T21:37:21.743",
"Id": "55641",
"Score": "0",
"Tags": null,
"Title": null
} | 55641 |
Stan is open source software for Markov chain Monte Carlo sampling, often used for multilevel Bayesian modeling. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T21:37:21.743",
"Id": "55642",
"Score": "0",
"Tags": null,
"Title": null
} | 55642 |
<p>This is a follow-up to this question:</p>
<p><a href="https://codereview.stackexchange.com/questions/55625/division-without-using-addition-multiplication-or-division">Division without using addition, multiplication or division</a></p>
<p>Could you please tell me if there is better way of performing division withou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T12:02:08.610",
"Id": "97687",
"Score": "0",
"body": "You seem to be using the - operator in it's unary form. Is this a specific exception in the question or a bug? It should be possible enough to implement two's compliment using bit... | [
{
"body": "<p>Seems like the approach you've taken is to implement the <code>+</code> operator yourself. And when using the <code>+</code> operator on negative numbers, you've implemented your own <code>-</code> operator.</p>\n\n<p>I have to congratulate you for being able to implement these operators from scra... | {
"AcceptedAnswerId": "55645",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T22:37:44.953",
"Id": "55644",
"Score": "8",
"Tags": [
"java",
"interview-questions",
"mathematics"
],
"Title": "Implementing division without addition, multiplication, division... | 55644 |
<p>Tear it apart. I'm mostly concerned around the appropriate use of <code>ConfigureAwait(false)</code>, and possible poor handling and duplication of the <code>HttpClient</code> in <code>Invest</code> and <code>Get<T></code>.</p>
<p>Additionally, I'd also like thoughts on the fact that for usage of these method... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T01:00:54.077",
"Id": "97642",
"Score": "1",
"body": "Welcome to Code Review! Nice first post, \"tear it apart\" ... lol, that's the spirit! :)"
}
] | [
{
"body": "<p>There's something odd about your constructors - normally chained constructors call the constructor with the most parameters, not the other way around:</p>\n\n<pre><code>public ProsperApi(string username, string password, string baseUrl) \n : this(username, password)\n</code></pre>\n\n\n\n<pre><... | {
"AcceptedAnswerId": "55651",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T23:44:47.293",
"Id": "55647",
"Score": "11",
"Tags": [
"c#",
"api",
"http",
"async-await",
"wrapper"
],
"Title": "Async wrapper around public API"
} | 55647 |
<p>I would like to use this in a program to save users' names even after they relaunch the script. I was just wondering if there were some ways I could clean up this code.</p>
<p>Note: this currently was made to not support name changing, but could possibly be implemented in the future.</p>
<pre><code>if os.path.isfi... | [] | [
{
"body": "<p>I'm not sure why you are reading all of the file and checking for <code>istitle()</code>. Here I make the assumption that if the file exists, it will always include the player name on the first line.</p>\n\n<pre><code>if os.path.isfile('names.json'):\n with open('names.json') as f:\n player_na... | {
"AcceptedAnswerId": "55670",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T00:45:08.443",
"Id": "55648",
"Score": "10",
"Tags": [
"python",
"python-2.x",
"console",
"io"
],
"Title": "Saving player name throughout script-launches"
} | 55648 |
<p>I find that this function is one of the biggest causes of slow program execution. I can write a square root version with BigInteger only, but with the cube root, the algorithm sometimes gets caught in an endless loop unless I also use BigDecimal, because the values of <code>r</code> and <code>s</code> never reach eq... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T04:15:02.160",
"Id": "97653",
"Score": "1",
"body": "Can you post an input for which the BigInteger-only version does not terminate?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T02:52:02.027",
... | [
{
"body": "<p>Your current code is totally unreadable and very hard to understand.</p>\n<h3>For vs. While</h3>\n<p>You've literally packed everything inside a for-loop without a body. WHY!?</p>\n<p>This would be a lot more readable using a while-loop.</p>\n<pre><code>BigDecimal s = BigDecimal.ZERO;\nwhile (!res... | {
"AcceptedAnswerId": null,
"CommentCount": "14",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T03:39:13.130",
"Id": "55652",
"Score": "7",
"Tags": [
"java",
"optimization",
"algorithm",
"mathematics",
"fixed-point"
],
"Title": "How do I optimize this Java cube root... | 55652 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.