body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I have to reverse the string "He is the one" to "one the is He". I have written some programs in Java but am looking for other best solutions. Suggest any possible ways to minimize the current program.</p>
<p>First approach:</p>
<pre><code>class StringRev{
public static void main(String args[]){
String s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T17:30:03.720",
"Id": "61785",
"Score": "0",
"body": "If you are attempting to write as few characters as possible, you should instead go to [Code Golf](http://codegolf.stackexchange.com)"
},
{
"ContentLicense": "CC BY-SA 3.0... | [
{
"body": "<p>Here is a clean approach to reverse a string by its parts:</p>\n\n<pre><code>public class Main {\n\n // ReverseParts: reverses a string by words as opposed to characters.\n public static String ReverseParts(String input, String splitBy, String joinBy) {\n StringBuilder built = new Str... | {
"AcceptedAnswerId": "37407",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T17:21:13.557",
"Id": "37364",
"Score": "11",
"Tags": [
"java",
"algorithm",
"strings"
],
"Title": "Reversing words in a string"
} | 37364 |
<p>I have an image loader, now only for bitmaps. I'm a little confused because I want to split my code to different classes, one for writing a BMP data to a file (<em>WRITER</em>), one for loading BMP data from file, or from pre-generated dataset <em>(1)</em> and storing it in its private members.<em>( (1) like a noise... | [] | [
{
"body": "<p>The only standard ways to access private data from another class are:</p>\n\n<ol>\n<li>Getters </li>\n<li>Friend class</li>\n</ol>\n\n<p>If you want to make a friend class, just do something like this:</p>\n\n<pre><code>class Writer ;\n\nclass BMP\n{\n //...\nprivate:\nfriend class Writer ;\n}... | {
"AcceptedAnswerId": "37382",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T17:25:50.110",
"Id": "37365",
"Score": "3",
"Tags": [
"c++",
"design-patterns",
"classes",
"image"
],
"Title": "Image loader/writer design (no API, pure C++ on Windows)"
} | 37365 |
<p>I am writing a flask app that I will deploy it on Heroku to test it. There is a page that will generate daily photos and information based on a JSON file. The view is valid for 24 hours beginning from 00:00 to 23:59 of everyday.</p>
<p>I am thinking about using a cache, otherwise the app will consume unnecessary re... | [] | [
{
"body": "<p>Why not take advantage of the RESTful architecture of the internet? I suggest you have the code generate a static page and set the expires header on that resource (or set of resources) to the end of that day (considering your audience's time zones, I guess). <a href=\"https://devcenter.heroku.com/... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T17:57:36.097",
"Id": "37366",
"Score": "4",
"Tags": [
"python",
"cache",
"flask"
],
"Title": "Caching a function view for a day"
} | 37366 |
<p>I'm trying to make a scala interface to the spotify API. I'm using it to learn Scala. I come from mostly a python background.</p>
<pre><code>import dispatch._, Defaults._
trait Request {
val name: String
val endpoint: String
}
case class Track(name: String) extends Request {
override val endpoint = "track.j... | [] | [
{
"body": "<p>Decouple everything.</p>\n\n<p>I am certain that Scala veterans will have more to say than I do and possibly comment over my comments.</p>\n\n<p>Here are some changes and respective comments to your code.</p>\n\n<pre><code>import dispatch._, Defaults._\n\n// decouple from any \"master\" class.\nca... | {
"AcceptedAnswerId": "37377",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T21:21:41.233",
"Id": "37375",
"Score": "2",
"Tags": [
"scala"
],
"Title": "Interface for Spotify API"
} | 37375 |
<p>How would one optimize this code? </p>
<pre><code>import java.util.*;
public class VendingMachineAssignement {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double item1 = 1.25;
double item2 = .75;
double item3 = .90;
double item4 =... | [] | [
{
"body": "<h2>Things I would fix:</h2>\n\n<p>All of your condition test statements do exactly the same thing. </p>\n\n<blockquote>\n<pre><code>else if (item == 1)\n{\n if (paid >= item1) \n {\n System.out.println(\"Thank you for buying item \" + item + \", your change is $\" + (paid-item1) + \"... | {
"AcceptedAnswerId": "37379",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T21:48:30.483",
"Id": "37376",
"Score": "14",
"Tags": [
"java",
"console"
],
"Title": "Vending machine implementation"
} | 37376 |
<p>I'm building an http handler at work which has about 6 methods and I'm trying to figure out what design pattern will work the best for my needs:</p>
<p>What's done already (Only an example to make this more clear, methods are not real, but the main concept is there):</p>
<pre><code>#region interfaces
public interf... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T23:26:23.473",
"Id": "61835",
"Score": "0",
"body": "“is there a better way?” Not reinventing the wheel and using something like ASP.NET Web API?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T23:35:... | [
{
"body": "<p>Let me admit up front I don't know a lot about implementing web handlers and the various frameworks, so this answer ignores a probably very legitimate point about reusing the wheels that are already out there. Instead this answer addresses how the code is factored.</p>\n\n<p>Your third block of co... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T21:59:37.707",
"Id": "37378",
"Score": "2",
"Tags": [
"c#",
"object-oriented",
"design-patterns"
],
"Title": "Best design pattern to approach http handler with multiple methods"
} | 37378 |
<p>Does my PHP look secure enough for a sign up form?</p>
<pre><code><?php
$con=mysqli_connect("host","user","password","db_name");
$sql="INSERT INTO users values (?, ?, ?)";
if ($stmt = mysqli_prepare($con,$sql)) {
mysqli_stmt_bind_param($stmt, "sss",
$_POST["username"], $_POST["pwd"], $_POST["email"]);
i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T23:37:55.273",
"Id": "61839",
"Score": "3",
"body": "From PHP side of view: you might want to check if connection is successful first. It's important to check if all variables are valid (not empty, matching something). Also someone ... | [
{
"body": "<p>It looks like you have a good and solid <code>Insert</code>, probably pretty safe, but this still allows a user to enter data into the database that could be run at a later time, you should still check the input coming in before inserting it into the Database even though it has been \"prepared\".... | {
"AcceptedAnswerId": "39006",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T23:17:13.590",
"Id": "37383",
"Score": "3",
"Tags": [
"php",
"sql",
"security",
"mysqli"
],
"Title": "Increase security of sign up form code"
} | 37383 |
<p>Is there a more optimal way of retrieving the character for the letter? I would assume that I would just replace my Entry set loop with another map, but I do not want to bloat the code, because it will reduce scalability.</p>
<pre><code>import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
pu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T04:06:24.637",
"Id": "61862",
"Score": "0",
"body": "BTW: I see nothing that is [ASCII](http://en.wikipedia.org/wiki/Ascii) specific here. Your solution appears to be character set agnostic - which is good."
}
] | [
{
"body": "<p>This is one of those occasions where a 'sparse' dataset may be very helpful.</p>\n\n<p>But, first some nit-picks:</p>\n\n<ul>\n<li>You should probably call the class <code>AsciiLetters</code> instead of <code>AciiLetters</code></li>\n<li><p>Declaring multiple constants on one line is unconventinal... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T03:38:53.147",
"Id": "37392",
"Score": "5",
"Tags": [
"java",
"optimization",
"cache",
"hash-map",
"lookup"
],
"Title": "Optimize text to ascii lookup map and scalability"... | 37392 |
<p>I'm creating a program to retrieve web content in order to learn how these things work. I would like it to be as correct as possible, ideally fully compliant.</p>
<p>But I'm not sure this is the right approach to the problem. Is the following structure an appropriate way to hold server response header data after pa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T05:50:51.797",
"Id": "61864",
"Score": "3",
"body": "Adding all of these headers explicitly into a struct doesn't work very well because it's entirely possible to send/receive non-standard headers. You really just need a map of stri... | [
{
"body": "<p>The way I would do it is by simply representing the headers as map of <code>char*</code> to <code>char*</code>. That'll be the most flexible and extensible situation, since HTTP headers are added over time, and custom headers are completely acceptable and allowed for by the standard. Any solution ... | {
"AcceptedAnswerId": "37400",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T05:38:34.980",
"Id": "37395",
"Score": "6",
"Tags": [
"c",
"http"
],
"Title": "Holding server response header data after parsing it"
} | 37395 |
<p><a href="http://projecteuler.net/problem=9" rel="nofollow">Project Euler problem 9</a> says:</p>
<blockquote>
<p>A Pythagorean triplet is a set of three natural numbers, <em>a</em> < <em>b</em> < <em>c</em>,
for which,</p>
<p><em>a</em><sup>2</sup> + <em>b</em><sup>2</sup> = <em>c</em><sup>2</sup></p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T07:58:43.927",
"Id": "61870",
"Score": "3",
"body": "This is [Project Euler Problem 9](http://projecteuler.net/problem=9)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T07:01:05.563",
"Id": "619... | [
{
"body": "<p>Here are some changes I would do in your code:</p>\n\n<ol>\n<li><p>Since you already have two variables <code>x</code> and <code>y</code> from the loop, you don't need <code>a</code> and <code>b</code>. Get the 3 numbers as - <code>x</code>, <code>y</code>, and <code>1000 - x - y</code>, and use ... | {
"AcceptedAnswerId": "37401",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T07:03:27.883",
"Id": "37398",
"Score": "7",
"Tags": [
"python",
"optimization",
"beginner",
"project-euler",
"mathematics"
],
"Title": "Finding the Pythagorean triplet ... | 37398 |
<p>I am still new to C++ and don't have a great insight on my coding yet, so I would be very grateful to anyone and everyone that gives advice.</p>
<p><strong>Also, this code is meant to:</strong> keep all of my objects in an ordered fashion based on depth. I have a couple functions that allow for easy management and ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T16:24:33.220",
"Id": "61910",
"Score": "0",
"body": "Can you elaborate more on the purpose? Why is this better than a single flat vector of `object`s ordered by `depth`? What are the use cases, besides iterating though all objects i... | [
{
"body": "<p>Some remarks to your current <code>map</code>-based implementation:</p>\n\n<ol>\n<li><p>The idiomatic way of accessing an item in a map and adding it if not present usually goes like this:</p>\n\n<pre><code>if not map.contains(key)\n map[key] = new value\n\nvalue = map[key]\n... modify value\n<... | {
"AcceptedAnswerId": "37483",
"CommentCount": "12",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T08:31:48.660",
"Id": "37402",
"Score": "5",
"Tags": [
"c++",
"performance",
"object-oriented",
"beginner",
"memory-management"
],
"Title": "Could this depth system for... | 37402 |
<p>Im creating an single page application with not reload or redirects so I display all my contents with partial view(since im using <strong>MVC4</strong> and <strong>angularjs</strong> ) and modals.</p>
<p>But I came with a situation, and that is that in some cases when i request a view with ajax to the server I need... | [] | [
{
"body": "<h2>Read your framework's documentation</h2>\n\n<p>Before you actually do some voodoo magic on your code, I suggest you read your framework's documentation. It's quite impossible that a web framework has not taken into account JS's asynchronous nature. There should be a proper way to do this.</p>\n\n... | {
"AcceptedAnswerId": "37416",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T12:06:04.483",
"Id": "37408",
"Score": "2",
"Tags": [
"javascript",
"performance"
],
"Title": "Create an alternative wait in javascript"
} | 37408 |
<p>I would be glad if someone could take a look at my code and maybe improve it. It's an animation effect to gradually reveal text as if it were being decoded. I wouldn't mind if it could run with jQuery (if it's shorter or better). I uploaded it on <a href="http://jsbin.com/OtUZaGOy/1/edit?html,js,output" rel="nofollo... | [] | [
{
"body": "<pre><code>var decrypted = document.getElementById(\"decoded\");\nvar encrypted = document.getElementById(\"encoded\");\n\nfunction startdecrypt() {\n // Original text, split into an array and reversed (for faster pop())\n var originalText = decrypted.textContent.split('').reverse();\n var d... | {
"AcceptedAnswerId": "37420",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T13:33:05.713",
"Id": "37411",
"Score": "3",
"Tags": [
"javascript",
"performance",
"jquery",
"html",
"animation"
],
"Title": "Text revelation effect"
} | 37411 |
<p>This code works great, but I think it can be reduced.</p>
<pre><code>@if (Session["Success"] != null)
{
<text>
<div class="alert alert-success">@Session["Success"]</div>
</text>
Session.Remove("Success");
}
else if (Session["Error"] != null)
{
<text>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T15:05:52.863",
"Id": "61893",
"Score": "1",
"body": "What should happen when `Session` contains both `\"Success\"` and `\"Error\"`? Should that behave exactly the same as your code (i.e. print the success case)? Or is that situation... | [
{
"body": "<p>It's a bad idea to modify the session state from inside a view or a partial view. Instead, I would create an alert view model</p>\n\n<pre><code>public class AlertViewModel\n{\n public AlertType AlertType { get; set; }\n public string Message { get; set; }\n}\n\npublic enum AlertType\n{\n ... | {
"AcceptedAnswerId": "37429",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T13:58:24.003",
"Id": "37414",
"Score": "5",
"Tags": [
"c#",
".net",
"asp.net-mvc",
"razor"
],
"Title": "Displaying alert from an action"
} | 37414 |
<h3>1. Introduction</h3>
<p>This is a solution to <a href="https://codereview.meta.stackexchange.com/a/1248/11728">Weekend Challenge #3</a>: a Sudoku solver in Python. It works by translating a Sudoku puzzle into an <a href="https://en.wikipedia.org/wiki/Exact_cover" rel="noreferrer">exact cover</a> problem, and then ... | [] | [
{
"body": "<p>I have only a minor comment:</p>\n\n<p>In <code>ExactCover.__init__</code>, I would use <code>iteritems</code> rather than iterating over the keys of <code>constraints</code>:</p>\n\n<pre><code>for choice, constraintsList in self.constraints.iteritems():\n for constraint in constraintsList:\n ... | {
"AcceptedAnswerId": "37492",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T14:31:55.517",
"Id": "37415",
"Score": "27",
"Tags": [
"python",
"algorithm",
"recursion",
"sudoku",
"community-challenge"
],
"Title": "Sudoku using 'exact cover' solve... | 37415 |
<p>I am building a cypher program which uses a matrix of numbers and letters. A message is encoded according to the row and column each letter of the message is found in the matrix.</p>
<p>I am trying to find a nice way of iterating over the 2D matrix (6*6).</p>
<pre><code> for char in range (0, len(message), 1):
f... | [] | [
{
"body": "<p>Don't search – find. Specifically, don't iterate through all matrix entries for each character. Instead, build a dictionary that maps the characters in the matrix to a pair of indices.</p>\n\n<p>Also, don't loop over indices (in <code>message</code>) unless you have to. Now we have:</p>\n\n<pre><c... | {
"AcceptedAnswerId": "37419",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T14:34:48.413",
"Id": "37417",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"matrix"
],
"Title": "Reading Multidimensional arrays"
} | 37417 |
<p>I have made an application to display images in the form of gallery, from terminal if you are standing at the same location then it will open those images in the gallery if it does not have it will prompt to select the directory.</p>
<p>below is the module: <strong>gallery.py</strong></p>
<pre><code>import sys
imp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T05:17:30.260",
"Id": "62214",
"Score": "0",
"body": "MyListModel.colData() and MyListData.headerData() don't do anything. They always return None."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T15:22... | [
{
"body": "<p><strong>Disclaimer:</strong> this is not a design pattern review, but rather a Pythonization one.</p>\n\n<ol>\n<li><p>Not always returning a value: <code>MyListModel.colData()</code> <code>MyListModel.headerData()</code>. Even though Python implicitly returns <code>None</code> if you don't specify... | {
"AcceptedAnswerId": "37485",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T14:50:01.367",
"Id": "37418",
"Score": "0",
"Tags": [
"python",
"design-patterns"
],
"Title": "Feedback on logic implementation of PyQt4 based Image gallery using QTableView"
} | 37418 |
<p><a href="http://www.spoj.com/problems/SHPATH/" rel="nofollow">This is the problem</a> and my solution to this is:</p>
<pre><code>#include "iostream"
#include "stdio.h"
#include "algorithm"
#include "math.h"
#include "string.h"
#include "time.h"
#include "stdlib.h"
#include <list>
#include <vector>
#incl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T16:35:18.500",
"Id": "61913",
"Score": "2",
"body": "Note: `for(;(c<48 || c>57);c = gc());` is an endless loop should `c` equal EOF."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T16:38:13.387",
... | [
{
"body": "<p>In your hash function, you're doing <code>x.size()</code> in a loop, which will slow the function down quite a lot for a long string. Instead, store the size in a variable and compare to that</p>\n\n<pre><code>int hash(const string &x)\n{\n int y=0;\n int xLength = x.size();\n for (in... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T16:03:10.057",
"Id": "37422",
"Score": "4",
"Tags": [
"c++",
"graph",
"stl",
"time-limit-exceeded"
],
"Title": "STL and Dijkstra's algorithm optimization"
} | 37422 |
<p>I have a UIImage Category for iOS Objective-C which tints an image based on a given UIColor value. You can take a look at the method below:</p>
<pre><code>- (UIImage *)tintImageWithTint:(UIColor *)color withIntensity:(float)alpha {
CGSize size = self.size;
UIGraphicsBeginImageContextWithOptions(size, NO, [... | [] | [
{
"body": "<p>your image might have 111 KB compressed as an jpg or a png. But for image processing it needs to be decompressed. It will be loaded into memory with 8 or 16 bit for each color channel. With RGB it would be up to 48 bit per pixel and 8 bit for the alpha cannel in case of png. So 5MB would represent... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T16:30:08.100",
"Id": "37423",
"Score": "3",
"Tags": [
"objective-c",
"memory-management",
"ios"
],
"Title": "UIGraphicsImageContext Memory Spike - Reducing Footprint"
} | 37423 |
<p>I've seen usage of <code>switch(true)</code> multiple times and have used it myself today instead of multiple <code>else</code>if`s. Here is the case I used it for:</p>
<pre><code>var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') != -1;
var isSafari = navigator.userAgent.toLowerCase().indexOf('safa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T17:30:14.880",
"Id": "61918",
"Score": "0",
"body": "The else-if alternative is shorter and more explicit."
}
] | [
{
"body": "<p>Assuming that you bad a bunch of boolean variables already defined, I think a chained ternary conditional expression would be even better, because it's more compact, and also emphasizes that the goal is to assigning <em>something</em> to <code>browser</code>.</p>\n\n<pre><code>var browser = isChro... | {
"AcceptedAnswerId": "37427",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T16:45:16.290",
"Id": "37424",
"Score": "6",
"Tags": [
"javascript",
"cross-browser"
],
"Title": "User agent classification using switch (true)"
} | 37424 |
<p>This is part of my attempt at the <a href="https://codereview.meta.stackexchange.com/questions/1245/weekend-challenge-3">Week-End Challenge #3</a>. The overall problem is larger than will fit in one question. This is a well-contained subset of my larger program.</p>
<p>The goal of this part is to brute-force all po... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T17:18:54.860",
"Id": "61917",
"Score": "1",
"body": "For the record, I've seen 6 x 6 puzzles, where each box is 2 x 3. As long as you handle 9 x 9, though, that's OK."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<h2><code>buildFollowing</code></h2>\n\n<p>The logic of this this function is difficult to follow. Part of it is because of your insistence on very short names (<code>rb</code>, <code>cb</code>, etc.) with comments breaking up the flow of the code; as a rule of thumb, if you need a comment to describ... | {
"AcceptedAnswerId": "37439",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T16:46:45.107",
"Id": "37425",
"Score": "14",
"Tags": [
"java",
"algorithm",
"recursion",
"weekend-challenge",
"sudoku"
],
"Title": "Sudoku Week-End Challenge - Brute-Fo... | 37425 |
<p>I had this code lying around, so I figured I would submit this as my first attempt at a <a href="/questions/tagged/weekend-challenge" class="post-tag" title="show questions tagged 'weekend-challenge'" rel="tag">weekend-challenge</a>. I would prefer if reviews contained suggestions on how to improve the algo... | [] | [
{
"body": "<p>I would love to go through and find all sorts of things that this code does badly... but, it's short, sweet, and works, and that in itself speaks to a measure of sophistication.</p>\n\n<p>This solution is very lightweight on all resources other than CPU cycles, and it does not carry much through o... | {
"AcceptedAnswerId": "37433",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T17:47:41.137",
"Id": "37430",
"Score": "38",
"Tags": [
"c",
"weekend-challenge",
"sudoku"
],
"Title": "Sudoku Solver in C"
} | 37430 |
<p>This is my first, very-very first attempt at <a href="/questions/tagged/java" class="post-tag" title="show questions tagged 'java'" rel="tag">java</a>. I haven't started tackling the actual resolution of the <a href="/questions/tagged/sudoku" class="post-tag" title="show questions tagged 'sudoku'" re... | [] | [
{
"body": "<ul>\n<li><p>Instead of your <code>String puzzle</code> you could use an <code>String[]</code> like below (not saying you have to, but you should know that the alternative exists). You are currently converting it to a <code>String</code> array later anyway, so why not have it as a String array right... | {
"AcceptedAnswerId": "37438",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T19:37:58.777",
"Id": "37435",
"Score": "8",
"Tags": [
"java",
"beginner",
"parsing",
"weekend-challenge",
"sudoku"
],
"Title": "Hello Java World ~> Parsing a Sudoku Gri... | 37435 |
<p>This is a Python script that generates a grid of random HTML colors. It works by reading random data from <code>/dev/urandom</code> and then encoding it as a hexadecimal string. This string is spit into individual values that will be represented as a color.</p>
<p>I am wanting to know if this is the best way to g... | [] | [
{
"body": "<p>An implementation that uses the <code>random</code> module has the benefit of being platform independent. This code isn't going to run so well if you try it on Windows.</p>\n\n<p>There is also another alternative. <a href=\"http://docs.python.org/2/library/os.html#os.urandom\" rel=\"nofollow noref... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T21:05:05.680",
"Id": "37440",
"Score": "6",
"Tags": [
"python",
"html",
"random"
],
"Title": "Generating random HTML color grid"
} | 37440 |
<p>I have written <code>ExtendedConfigParser</code> class that adds ability to dot access config values like ExtendedConfigParser().section_name.option_name:</p>
<pre><code>from ConfigParser import SafeConfigParser
class ExtendedConfigParser(SafeConfigParser):
def __init__(self, config_file=None, type_conversio... | [] | [
{
"body": "<p>I'd start with the caveat that you're buying some syntax sugar at the cost of possible bugs - the need to do the attribute resolution, and as you point out the possibility of name clashes, makes it seem like it may not be worth the effort unless you need to access these class properties in lots of... | {
"AcceptedAnswerId": "37539",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T21:27:43.163",
"Id": "37441",
"Score": "1",
"Tags": [
"python"
],
"Title": "Risks related to overriding attribute access"
} | 37441 |
<p>Even though it's the first time I'm writing something this "big", it feels like I know C# quite well (it is very similar to Java after all). It's been nice to learn LINQ also and I am very impressed by the features (which is just like Steams in Java 8), and perhaps I have overused it here (if it's possible to do tha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T22:25:57.517",
"Id": "61948",
"Score": "14",
"body": "Simon-André \"Extra Mile\" Forsberg is the name!"
}
] | [
{
"body": "<p>Impressive. I mean it.</p>\n\n<p>Couple observations:</p>\n\n<p>Your enums...</p>\n\n<pre><code>public enum SudokuProgress { FAILED, NO_PROGRESS, PROGRESS }\n</code></pre>\n\n<p>Should be:</p>\n\n<pre><code>public enum SudokuProgress { Failed, NoProgress, Progress }\n</code></pre>\n\n<hr>\n\n<p>Wh... | {
"AcceptedAnswerId": "190333",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T22:22:52.040",
"Id": "37448",
"Score": "81",
"Tags": [
"c#",
"linq",
"community-challenge",
"sudoku"
],
"Title": "SudokuSharp Solver with advanced features"
} | 37448 |
<p>I'm trying to figure out a way to have cleaner, efficient code for a web audio project i've been working on. the code I have right now is this:</p>
<pre><code>//OSCILLATOR INFO//
// Oscillator Pitch is in Hz.
// Oscillator Detune is in Cents & can be positive or negative values.
// 1 Octave = double/half the n... | [] | [
{
"body": "<p>I just picked one part of the code that could use some polishing. Consider the following :</p>\n\n<pre><code>$('#play_pause_osc1').click(function () {\n if ($(this).val() == \"Play Osc1\") {\n $(this).val(\"Pause\");\n oscillator1Start();\n } else {\n $(this).val(\"Play ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T00:41:47.523",
"Id": "37454",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"jquery-ui",
"audio"
],
"Title": "Web Audio Constructors and jQuery"
} | 37454 |
<p>I am building an array of strings to form the "empty" representation of a puzzle onto which I will overwrite single characters as necessary <em>for debugging purposes</em>. However, building the array using scalar multiplication results in shared string instances among the rows which breaks when I modify them.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T01:44:14.680",
"Id": "61967",
"Score": "1",
"body": "Do I smell the beginning of a [tag:weekend-challenge] submission?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T16:33:54.567",
"Id": "62502",... | [
{
"body": "<p>I might do this:</p>\n\n<pre><code>grid = 9.times.map { \"... \" * 3 }\n</code></pre>\n\n<p>Or, better yet, as Naklion proposes in the comments:</p>\n\n<pre><code>grid = Array.new(9) { \"... \" * 3 }\n</code></pre>\n\n<p>to get the rows (as separate string instances), and this</p>\n\n<pre><code>gr... | {
"AcceptedAnswerId": "37502",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T00:58:22.870",
"Id": "37455",
"Score": "3",
"Tags": [
"ruby",
"array"
],
"Title": "Clone array elements when multiplying by a scalar"
} | 37455 |
<p>I'm writing a function in Python that compares the modification time of a file in Linux (using os.stat) with a specific time and compare the dates. If the modification date is older than the date I specified, an event should happen. </p>
<pre><code>import os
import time
import datetime
# File Modification time in ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T20:52:55.320",
"Id": "61992",
"Score": "3",
"body": "Side note: it is better to never call a variable `file`: this shadows the built-in `file` class."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-03-28T01... | [
{
"body": "<p>Mainly, you are working with timestamps, so instead of calling <em>both</em> <code>datetime.datetime.today()</code> and <code>time.time()</code> (which introduces a slight discrepancy), you could do your computations based on <code>time.time()</code> alone:</p>\n\n<p>You could replace</p>\n\n<pre>... | {
"AcceptedAnswerId": "37467",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-09T18:59:34.820",
"Id": "37465",
"Score": "7",
"Tags": [
"python",
"datetime",
"file-system"
],
"Title": "Compare last modification time with specfied time"
} | 37465 |
<p><strong>Original</strong> </p>
<p>quicksort.h </p>
<pre><code>#include <algorithm>
namespace quicksort {
template <typename iterator, typename value_type>
struct traits
{
static iterator choose_pivot (iterator first, iterator last) {
return first + (last - first) / 2 ;
}
stati... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T16:18:54.657",
"Id": "88822",
"Score": "0",
"body": "I'm sorry that I asking this. But you trying to implement quicksort algoritm, or it is somehow different from std::sort? There is no offense, I just not really good understand qui... | [
{
"body": "<p>Let's start with things that can be cleaned up in your <code>traits</code> struct:</p>\n\n<p>Firstly, by convention, all template parameters should be <code>UpperCaseFirstLetter</code>. Secondly, you don't need to pass in a <code>value_type</code>, because you can get this directly from the iterat... | {
"AcceptedAnswerId": "37480",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T04:37:10.290",
"Id": "37474",
"Score": "10",
"Tags": [
"c++",
"c++11",
"template",
"quick-sort"
],
"Title": "Templated Quicksort"
} | 37474 |
<p>I have some concerns:</p>
<ol>
<li><p>Is it normal for the class to have at least one node? In other words, this implementation cannot have an empty linked list; the length is always 1.</p></li>
<li><p>Would this be a proper way to implement a linked list in, say, a professional environment? Or perhaps there is a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-23T10:54:00.333",
"Id": "63146",
"Score": "2",
"body": "Don't worry; you're not alone. C++ takes just a few lifetimes to master."
}
] | [
{
"body": "<blockquote>\n <p>For example, is it normal for the class to have at least one node? In\n other words, this implementation cannot have an empty linked list. The\n length is always 1.</p>\n</blockquote>\n\n<p>No, a linked list can be empty (i.e. size 0).</p>\n\n<p>But there are designs that intenti... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T04:48:19.547",
"Id": "37475",
"Score": "14",
"Tags": [
"c++",
"c++11",
"linked-list"
],
"Title": "Implementing a proper linked list for a professional environment"
} | 37475 |
<p>Let me start by saying that the code works as is but I think it has a lot of redundancy. It is written this way as I kept getting nullpointerexceptions if I try to put the fileCounter > gameDiff if/else inside one for loop.</p>
<p>The program allows a user to create directories and add images to them. It will also ... | [] | [
{
"body": "<p>First of all, Java code doesn't really make sense outside of the context of a class and a method. Sometimes you can get away without the class, but the method signature is definitely important. In this case, you've included references to variables without a type: are these arguments to a method? M... | {
"AcceptedAnswerId": "37481",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T05:37:38.657",
"Id": "37478",
"Score": "5",
"Tags": [
"java",
"file-system",
"image"
],
"Title": "Improve this image file browser (remove redundancy)?"
} | 37478 |
<p>I have been changing this code and I don't get to make it much better. I changed a little bit the structure, reimplemeted a new function for splitting Strings which is more efficient, etc. I have been tested with MR-Unit (it's part of map-reduce code).</p>
<p>I'm testing the code with 1.5 millions calls. It takes a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T09:48:58.433",
"Id": "62049",
"Score": "0",
"body": "What is your split implementation?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T10:09:50.413",
"Id": "62055",
"Score": "0",
"body": ... | [
{
"body": "<p>What about the following code. I've improved it by not using regular expressions (except one call of <code>String.split</code>, perhaps you already improved this by your own function <code>split</code>).</p>\n\n<pre><code>private final static char EXPR_VAR = '$';\nprivate final static char EXPR_ST... | {
"AcceptedAnswerId": "37495",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T08:50:56.100",
"Id": "37487",
"Score": "8",
"Tags": [
"java",
"performance",
"strings",
"regex",
"mapreduce"
],
"Title": "Map-reduce implementation for splitting string... | 37487 |
<p>I have created a small HomeScreen Widget which displays random numbers.
Attached is the code. Please let me know if the approach is good.</p>
<p><a href="https://github.com/gottp/HomeWidgetTest/tree/b8a9a2fee0b76dd5eb70da1e6cf24ffe2977aebe">https://github.com/gottp/HomeWidgetTest</a></p>
<p>MainAppClass.java</p>
... | [] | [
{
"body": "<p>Looks like some nice Java! I just have a few comments. (Better late than never? Haha)</p>\n\n<h1>TL;DR</h1>\n\n<ol>\n<li><strong>Better variable names.</strong> Things like <code>h</code>, <code>s</code>, and <code>i</code> don't make for good variable names. Try to be descriptive and to name... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T08:51:41.057",
"Id": "37488",
"Score": "8",
"Tags": [
"java",
"android"
],
"Title": "Home screen widget to display random numbers"
} | 37488 |
<p>I'm new to C# and OO programing.
I have an aspx page with 3 lists of checkboxes and I would like to generate them from the DB.
how should I structure my code?</p>
<p>Here is an example of what I did so far:</p>
<ol>
<li><p>ASPX page</p>
<pre><code><asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp... | [] | [
{
"body": "<p>In general for OO programming you separate out code into objects and each object focuses on doing one thing and doing it well.</p>\n\n<p>Each object should then generally have it's own source file in your code tree.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T10:30:06.990",
"Id": "37493",
"Score": "3",
"Tags": [
"c#",
"asp.net"
],
"Title": "3 layer design and multiple dataset"
} | 37493 |
<p>I am learning <code>getopt</code> in Python to parse and validate command line inputs:</p>
<pre><code>#!/usr/bin/python
'''\nMailing Script
Usage: python script.py -y <year> -c <type_user>"
Arguments:
-y, --year any value from 2008 to 2013
-c, --campaign any value in:
'80c'... | [] | [
{
"body": "<p>I think you have too many try/excepts. More than one of them raise and catch their own exceptions. I've made some changes that improves readability.</p>\n\n<p>For clarity the new code created a new exception class and raises it when appropriate. </p>\n\n<p>Also using getopt's own handler for bogu... | {
"AcceptedAnswerId": "37510",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T11:52:47.643",
"Id": "37499",
"Score": "6",
"Tags": [
"python",
"parsing"
],
"Title": "Using getopt parse and validate command line arguments"
} | 37499 |
<p>In my project i work with COM object via <code>System.Reflection</code>. COM object returns pointer on structure <code>VARIANT</code>, that i cast as <code>object</code> and then i cast one as <code>byte array</code>. There are many structures that i get from COM object. Since i know about how organize these structu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T16:15:50.897",
"Id": "62101",
"Score": "0",
"body": "I think that if possible, you shouldn't do this manually. Can you use .Net 4.5.1? It seems to have a [new method](http://msdn.microsoft.com/en-us/library/dn261460) that could help... | [
{
"body": "<pre><code>int msgId\n</code></pre>\n\n<p>I think it would be better if this was an <code>enum</code>. That way, it's clear what values are acceptable for this parameter.</p>\n\n<pre><code>object msgObject\n</code></pre>\n\n<p>Since this method only accepts <code>byte[]</code>, I think that should be... | {
"AcceptedAnswerId": "37518",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T13:31:11.650",
"Id": "37501",
"Score": "2",
"Tags": [
"c#",
"generics",
"com"
],
"Title": "VARIANT structure deserialization code organization"
} | 37501 |
<p>I am working on a (HTML/CSS) website to improve my skills but I am not sure if I am doing it the right way, because I have a lot of floats and sizes. I also need help with some CSS things:</p>
<p>What I have:</p>
<p><img src="https://i.stack.imgur.com/pOMUy.jpg" alt="i.imgur.com/r3VGbWy.png"></p>
<p>What I am Sho... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T15:22:53.043",
"Id": "62092",
"Score": "0",
"body": "Code review is not for \"fixing HTML/CSS layout to look correctly\". Code Review is essentially about having working and correct code, then rewriting parts of that code so that yo... | [
{
"body": "<p>instead of using ID's you should be using classes. like this</p>\n\n<pre><code><div id=\"wrapper\">\n <div id=\"mainContent\">\n <div id=\"newsHolder\">\n <div class=\"item1\">\n <img src=\"img/item1.jpg\">\n </div>\n &l... | {
"AcceptedAnswerId": "37531",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T14:53:03.167",
"Id": "37504",
"Score": "6",
"Tags": [
"html",
"css"
],
"Title": "How to optimize my CSS/HTML webpage?"
} | 37504 |
<p>I'm using this method from my <code>Downloads()</code> class in a back-end admin system, where these can upload some files, which must be .rar or .zip I'm not to concern about filesize, yet. Eventually, these compressed files, will be holding only .mp3 files.</p>
<p>Well, here's the code. As you can see, I'm checki... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T16:23:33.287",
"Id": "62104",
"Score": "0",
"body": "Check the second half [of my answer to this question](http://codereview.stackexchange.com/questions/36411/secure-image-upload-class/36457#36457) it deals with various ways to chec... | [
{
"body": "<p>Right, seeing as I could go on and review your code in comments, I'd thought I'd post my comments + extra review in one go instead (after all, that's what this site is for).</p>\n\n<p>Starting from the top:</p>\n\n<pre><code>public function uploadFile($titulo,$file) {\n</code></pre>\n\n<p>A couple... | {
"AcceptedAnswerId": "37658",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T14:54:38.830",
"Id": "37505",
"Score": "1",
"Tags": [
"php"
],
"Title": "Checking mimetype and uploading a file"
} | 37505 |
<p>I have created a list of files using <code>find</code>, <code>foundlist.lst</code>.</p>
<p>The find command is simply <code>find . -type f -name "<search_pattern>" > foundlist.lst</code></p>
<p>I would now like to use this list to find copies of these files in other directories.</p>
<p>The 'twist' in my ... | [] | [
{
"body": "<p>Instead of calling sed twice, you can use Parameter expansion in bash:</p>\n\n<pre><code>search_base=${name%.*}'.*' # Remove everything after the last dot (included).\nsearch_base=${search_base#./} # Remove the leading dot and slash.\n</code></pre>\n\n<p>Keep in mind, though, that some files ca... | {
"AcceptedAnswerId": "37532",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T16:11:24.697",
"Id": "37511",
"Score": "4",
"Tags": [
"bash",
"file-system"
],
"Title": "Is there a 'better' way to find files from a list in a directory tree"
} | 37511 |
<p>I am looking for some guidance and optimization pointers for my custom JavaScript function which counts the bytes in a string rather than just chars. The website uses UTF-8 and I am looking to maintain IE8 compatibility.</p>
<pre><code>/**
* Count bytes in string
*
* Count and return the number of bytes in a giv... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-01-21T10:14:13.340",
"Id": "218513",
"Score": "0",
"body": "[Here](http://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript#answer-34920444) is an independent and efficient method to count UTF-8 bytes of a string. N... | [
{
"body": "<p>My 2 cents</p>\n\n<ul>\n<li>Please do not abbreviate words, choose short words or acronyms ( Len -> Length )</li>\n<li>Please lower camel case ( normal_val -> normalValue )</li>\n<li>Consider using spartan conventions ( s -> generic string )</li>\n<li><code>new Array()</code> is considered old sko... | {
"AcceptedAnswerId": "37552",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T16:22:08.733",
"Id": "37512",
"Score": "16",
"Tags": [
"javascript",
"performance",
"strings",
"utf-8"
],
"Title": "Count byte length of string"
} | 37512 |
<p>I am having problem with a simple Hanoi tower program. I need to do something to reduce its time.</p>
<pre><code>#include <stdio.h>
#include <fstream>
using namespace std;
int hanojus(int n, char a, char b, char c) {
ofstream fr("hanoj.out",ios::app);
if (n == 1)
fr<<a<< ... | [] | [
{
"body": "<p>Try moving the ofstream outside of the method so that you're not creating it every time you make a recursive call.</p>\n\n<p>Like this:</p>\n\n<pre><code>#include <stdio.h>\n#include <fstream>\n\nusing namespace std;\n\nint hanojus(int n, char a, char b, char c, ofstream& fr)\n{\n ... | {
"AcceptedAnswerId": "37515",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T14:59:14.563",
"Id": "37514",
"Score": "3",
"Tags": [
"c++",
"performance",
"recursion"
],
"Title": "Hanoi towers time exeeded"
} | 37514 |
<p>Considering the code sample below, which approach of service method design would be considered best-practice and why? The one used in <code>SaveOrder1</code> or the one in <code>SaveOrder2</code>?</p>
<p><strong>UPDATE:</strong> To be clear, I'm <em>not talking about web service here</em>, but application-type-agno... | [] | [
{
"body": "<p>Honestly I'd rather see a validation routine called first and an exception thrown with validation errors in a custom exception type.</p>\n\n<p>That said, I'm also not a fan of out parameters. So #1 over #2.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"Creati... | {
"AcceptedAnswerId": "37607",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T16:59:00.513",
"Id": "37516",
"Score": "4",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Which pattern to choose for passing alerts from service method back to user?"
} | 37516 |
<p>Here is my attempt at <a href="https://codereview.meta.stackexchange.com/q/1245/9357">Weekend Challenge #3</a>.</p>
<p>Out of scope:</p>
<ul>
<li>It only will do 9*9</li>
<li>It will stop at the first solution</li>
<li>Could have been smarter at re-using the cache when recursively calling <code>solveGrid</code></l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T23:35:34.093",
"Id": "62172",
"Score": "0",
"body": "Heh, tried to make it report \"unsolvable\", but it actually solves a completely blank grid without complaining :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [
{
"body": "<p>All in all, an interesting approach to the problem, and seeing JavaScript used in such an efficient way is a pleasure (stick it to all those people who think JavaScript is ... ).</p>\n\n<p>I have the following small criticisims of the code (nothing can be perfect, right?)...</p>\n\n<h2>Variables</... | {
"AcceptedAnswerId": "38034",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T17:02:03.753",
"Id": "37517",
"Score": "10",
"Tags": [
"javascript",
"recursion",
"sudoku",
"community-challenge"
],
"Title": "Sudoku solver: pencil marks & recursive patie... | 37517 |
<p>Project contains 3 classes:</p>
<pre><code>/*************************************************************************************
The purpose of this project is to create 3 classes. Pile contains the number of marbles
in a randomly generated pile, and also a remove method to determine how many marbles are
to be rem... | [] | [
{
"body": "<p>There is a lot of code in <code>main()</code>. It would be better to break this up into smaller pieces.</p>\n\n<hr>\n\n<p>There is a lot of extra white space. There generally is no need for multiple consecutive empty lines.</p>\n\n<p>Within <code>playTurn()</code>, you separate a sequence of if-el... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T17:16:13.437",
"Id": "37521",
"Score": "7",
"Tags": [
"java",
"game"
],
"Title": "Marbles game with classes"
} | 37521 |
<pre><code>def current_time():
'''Returns a tuple containing (hour, minute) for current local time.'''
import time
local_time = time.localtime(time.time())
return (local_time.tm_hour, local_time.tm_min)
(hour,minute) = current_time()
def ishtime(hour, minute):
import random
Starting_str =... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T09:07:26.743",
"Id": "62112",
"Score": "1",
"body": "You could start by removing \"its\" and fixing \"Perpectly\" and capitalization."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-21T10:37:33.940",
... | [
{
"body": "<p>Python supports double-ended inequalities:</p>\n\n<pre><code>End_str = ['at night', 'in the morning','in the afternoon','in the evening']\n\nif 0 <= hour < 6:\n Ending = End_str[0]\nelif 6 <= hour < 13:\n Ending = End_str[1]\nelif 13 <= hour < 19:\n Ending = End_str[2]\n... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T07:59:14.927",
"Id": "37522",
"Score": "3",
"Tags": [
"python",
"datetime"
],
"Title": "Expressing current time with natural language"
} | 37522 |
<p>See, I have a file which consists of a bunch of lines like</p>
<pre><code>NAME:0001;some text
ANOTHERNAME:000103;some more text
NEWNAME:42; blah blah
</code></pre>
<p>So what I need to do is to have a list of those names, list of numbers (IDs actually, so the order matters) and list of further comments. I wrot... | [] | [
{
"body": "<p>You can say:</p>\n\n<pre><code>>>> import re\n>>> re.split('[:;]', 'NAME:0001;some text')\n['NAME', '0001', 'some text']\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T15:31:38.637",
"Id": "62113"... | {
"AcceptedAnswerId": "37524",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T15:10:19.387",
"Id": "37523",
"Score": "1",
"Tags": [
"python",
"parsing"
],
"Title": "How parse nicely a string into three (or more) pieces?"
} | 37523 |
<p>I need to display a list of category links, like so:</p>
<p>Category 1, Category 2, Category 3</p>
<p>I've got it working already but the code seems pretty repetitive and a bit of a mess, I was wondering if there was a better way of doing it.</p>
<p>This is what I've got so far:</p>
<pre><code>for (var i = 0; i ... | [] | [
{
"body": "<p>This doesn´t look all too repetitive to me, I see no obvious duplication.\nYou could extract a local variable or two to make the naming more explicit and to not query for the same element twice.\nThat would however be a tradeoff between function size and readability. Also you see a few references ... | {
"AcceptedAnswerId": "37543",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T20:03:06.163",
"Id": "37536",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Better way to display list of categories"
} | 37536 |
<p>Is it possible to combine all the functions into a single function? I'm providing <a href="http://jsfiddle.net/hB2T8/" rel="nofollow">my fiddle</a> as well.</p>
<p><strong>I am trying to test it for different scenarios..
but I am not sure how to combine all the scenarios into one..</strong></p>
<pre><code>var myN... | [] | [
{
"body": "<p>I think your code would be cleanest if you wrote the program as a composition of a minimum-absolute-value-of-array function and a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter\" rel=\"nofollow\">filter</a>.</p>\n\n<p>Assuming that performan... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T20:11:17.783",
"Id": "37538",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"performance"
],
"Title": "Convert three functions into a single function"
} | 37538 |
<p>There is a pattern that keeps coming up in my ruby code and I'm somewhat ambivalent about it. It's somewhere between a Hash and a Struct. Basically
I used method_missing to return/set values in the Hash unless I want to
override a specific value with some logic or flatten out the complex underlying structure in the... | [] | [
{
"body": "<p>I have the feeling that your patterns is very similar to the idea behind <a href=\"http://www.ruby-doc.org/stdlib-2.0/libdoc/ostruct/rdoc/OpenStruct.html\" rel=\"nofollow\"><code>OpenStruct</code></a> and similar libraries, such as <a href=\"https://github.com/intridea/hashie#mash\" rel=\"nofollow... | {
"AcceptedAnswerId": "37675",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T20:54:05.330",
"Id": "37542",
"Score": "4",
"Tags": [
"ruby",
"design-patterns"
],
"Title": "Ruby Dynamic Struct - Pattern or AntiPattern?"
} | 37542 |
<p><a href="http://projecteuler.net/problem=10" rel="nofollow">Project Euler Problem 10</a> asks: "What is the sum of all prime numbers below 2 million?"</p>
<p>How do I speed up my code? It's taking forever and I have never gotten the answer. However, I am sure that my code is right; I cheated the answer from online ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T23:17:52.783",
"Id": "62169",
"Score": "0",
"body": "Srry, Edited and improved a bit."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T02:41:51.873",
"Id": "62391",
"Score": "1",
"body": "O... | [
{
"body": "<p>Unfortunately, I don't speak python so I can't provide any code but there's a couple of things I see that can be improved algorithmically:</p>\n<ol>\n<li>In <code>isPrime</code> start checking if it's divisible by two, then start check 3 and increase by two on each step. So instead of checking 2,3... | {
"AcceptedAnswerId": "37562",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T22:47:09.557",
"Id": "37550",
"Score": "5",
"Tags": [
"python",
"performance",
"primes",
"project-euler"
],
"Title": "Summation of primes takes forever"
} | 37550 |
<p>I have created a generic repository for my MVC 3 page. I am using interfaces and a UnitOfWork. But before I set out to do this? Is this the right way to separate my databaseaccess from my viewmodels and views?</p>
<p><strong>WHY I DID IT:</strong></p>
<p>I want to seperate my databaseaccess from my viewmodels and ... | [] | [
{
"body": "<p>I think if you are going to have only one Repository, then yeah this is over complicated! But if you will have many Repositories and you will be adding more and more, then you are on the right track. But couple of points: </p>\n\n<p>I am not sure how your are using your UoW. From my point of view ... | {
"AcceptedAnswerId": "37626",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T23:17:56.867",
"Id": "37554",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Generic Repository: Am I over-complicating?"
} | 37554 |
<p>I have made this search filter and it works fine, but I think the code looks a little messy and I have no idea how to clean it up.</p>
<p>I hope the following makes sense, otherwise please tell me which information you need, and I will provide it ASAP.</p>
<pre><code>// GET THE POST VALUE FROM FORM FIELDS
... | [] | [
{
"body": "<ul>\n<li><p>comments should explain what the code does, at least the complicated blocks, such as the array merging, and/or a comment to describe the whole thing</p></li>\n<li><p>Be consistent with naming things: you use camelCase sometimes (e.g. <code>userArray</code>) and underscores other times (e... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T02:11:19.083",
"Id": "37561",
"Score": "1",
"Tags": [
"php",
"array"
],
"Title": "Copying a lot of code to filter four PHP arrays"
} | 37561 |
<p>I have a program written in PyQt that has a lot of content. The basic way I've been doing it is using a stacked widget with all the content on pages and buttons to navigate through the pages.</p>
<p>However, a lot of the pages are just the same stuff with maybe a couple of different things. What I've been doing is:... | [] | [
{
"body": "<p>I quite that you've chosen to use a dictionary here as it is a readable way to group your widgets with their initialisation arguments, but I see two problems:</p>\n\n<ol>\n<li>You are labelling each widget twice: once in <code>self</code> and once in the dictionary. </li>\n<li>Your arguments are ... | {
"AcceptedAnswerId": "37818",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T05:37:53.460",
"Id": "37571",
"Score": "0",
"Tags": [
"python",
"pyqt"
],
"Title": "Widget configurer"
} | 37571 |
<p>I want my code to be reviewed and I'd like to hear your opinions.</p>
<p>Sun's code to compute hash of string:</p>
<blockquote>
<pre><code>public int hashCode() {
int h = hash;
if (h == 0 && value.length > 0) {
char val[] = value;
for (int i = 0; i < value.length; i++) {
h... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T06:51:52.427",
"Id": "62217",
"Score": "3",
"body": "That code, which you claim is from sun, is broken, (some places you have `val` and other places you have `value`. Is this not a copy/paste?"
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>I do not understand why <code>val</code> was introduced in addition to <code>value</code> – it isn't even a copy of the contents.</p>\n\n<p>On the other hand <code>h</code> does make sense once you consider thread safety. Assume we have two threads which calculate the hash of the string at nearly ... | {
"AcceptedAnswerId": "37578",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T06:45:57.540",
"Id": "37572",
"Score": "2",
"Tags": [
"java",
"strings",
"hashcode"
],
"Title": "Computing hash of string"
} | 37572 |
<p>The title could probably be better, but in any case here goes.</p>
<p>I am having a bit of a problem understanding how to move methods/functions to other classes to organize things.</p>
<p>So, I have moved a method of sorts, but as I am skeptical of it, I would like to get it reviewed and hear opinions on what can... | [] | [
{
"body": "<p>It seems to me like you are really asking about <code>static</code> vs <code>non-static</code></p>\n\n<ul>\n<li><code>static</code></li>\n</ul>\n\n<p>This means that your instance or instance variable is class-bound. No matter how many objects you make, they will all share the same <code>static</c... | {
"AcceptedAnswerId": "37575",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T07:18:12.260",
"Id": "37573",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Improving function when used from another class"
} | 37573 |
<p>I am using Dr.Racket, <em>Intermediate Student with Lambda</em>. I was wondering if there was any way I can simplify this code using any sort of method like lambda, abstraction, map, filter, etc.</p>
<pre><code> ; alien-at-edge?: alien --> boolean
(define (alien-at-edge? an-alien)
(or (alien-at-right-edge? an-al... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T17:47:35.463",
"Id": "62336",
"Score": "0",
"body": "In what sort of ways do you think lambda, filter, map, and abstraction might be applied to simplify the code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | [
{
"body": "<pre><code> ; alien-at-edge?: alien --> boolean\n(define (alien-at-edge? an-alien)\n(or (alien-at-right-edge? an-alien)\n(alien-at-left-edge? an-alien)))\n</code></pre>\n\n<p>Not much to do here but don't forget about indentation to make your code readable.</p>\n\n<pre><code>; any-alien-at-edge?: ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T08:12:02.917",
"Id": "37576",
"Score": "3",
"Tags": [
"racket"
],
"Title": "Simplifying Dr.Racket alien code"
} | 37576 |
<p>I am using Dr.Racket, <em>Intermediate Student with Lambda</em>. I was wondering if there was any way I can simplify this code using any sort of method like lambda, abstraction, map, filter, etc.</p>
<pre><code> ; DRAWING FUNCTIONS
; draw-rocket: rocket scene --> scene
; Purpose: To draw the given rocket in t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T09:33:34.533",
"Id": "62234",
"Score": "0",
"body": "Your `draw-world` has mismatched parentheses."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T13:14:33.107",
"Id": "62272",
"Score": "0",
... | [
{
"body": "<p>There are significant issues here:</p>\n\n<pre><code>; draw-rocket: rocket scene --> scene\n; Purpose: To draw the given rocket in the given scene\n(define (draw-rocket a-rocket a-scene) \n(place-image rocket-img a-rocket ROCKET-Y a-scene))\n</code></pre>\n\n<p>Why break the pattern from drawin... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T08:41:36.627",
"Id": "37579",
"Score": "2",
"Tags": [
"image",
"racket"
],
"Title": "Simplifying Dr.Racket drawing code"
} | 37579 |
<p>Is there any other way to optimize the below code? I feel the below code is huge for the operations it performs.</p>
<pre><code>{
if ((currentElement == null ||
(firstGridRow["Low"].ToString() == string.Empty ||
firstGridRow["High"].ToString() == string.Empty ||
firstGridRow["Mean"].ToSt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T10:48:10.583",
"Id": "62243",
"Score": "0",
"body": "Is the double if() at the start a typo/copy paste issue?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T10:49:38.093",
"Id": "62245",
"Sco... | [
{
"body": "<p>So I'll preface this with it's a little difficult without the actual context of the code, and that all suggestions need to be checked to ensure they don't break the existing flow of control.</p>\n\n<p>A few options:</p>\n\n<ul>\n<li>Breaking out repetitive operations into reusable methods</li>\n<l... | {
"AcceptedAnswerId": "37585",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T10:43:23.850",
"Id": "37582",
"Score": "11",
"Tags": [
"c#"
],
"Title": "Multiple values against same condition"
} | 37582 |
<p>I've created unit test for the "student" CRUD operations that looks like this:</p>
<pre><code>[Test]
public void Can_Exec_CrudOps()
{
#region Prepare
var account = Processor.Execute(new CreateAccount
{
Email = "email@example.com",
Username = "username",
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T13:28:31.657",
"Id": "62277",
"Score": "2",
"body": "Please include a language tag next time, since this looks like C#, I added that tag."
}
] | [
{
"body": "<p>No, I would say, and the reason for that is that you have too many asserts in your test (it does to many thinks). There should only be one reason for a test to fail. So:</p>\n\n<p>Split your test into smaller ones with a more descriptive name and stick to one assert per test. By doing so it's also... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T11:44:14.803",
"Id": "37584",
"Score": "1",
"Tags": [
"c#",
"unit-testing"
],
"Title": "Is this good practice with unit-testing?"
} | 37584 |
<p>This is more like a share and a request than a question. I converted Eric Lengyel's code, which calculates tangents of a mesh for the purpose of texturing and normal mapping, to support SIMD. For this I used DirectXMath library from windows SDK. I don't know if this is actually faster than regular floating point ver... | [] | [
{
"body": "<p>Here's my pass at it; without the rest of your source I can't verify it's integrity so I don't know if this will compile correctly with the rest of your code, so hopefully it can help:</p>\n\n<pre><code>// outside function since they're consts, decreases run time as no more construction each funct... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T14:34:46.907",
"Id": "37592",
"Score": "1",
"Tags": [
"c++",
"optimization",
"computational-geometry",
"matrix",
"simd"
],
"Title": "Computing tangent space basis vectors ... | 37592 |
<p>I've played with F# for over a year, but I've only recently begun tentatively using it for professional work. I'm concerned that my c-style OOP principles are blinding me to the advantages of a functional language. I wrote the following code and it works just fine, but I feel like I'm just not quite using the langua... | [] | [
{
"body": "<p>I think that functional programming shows itself most when you're manipulating data. You almost don't have that in your code, so there isn't much to change.</p>\n\n<p>Though there are some small things that you could change:</p>\n\n<ol>\n<li>You could create a type for user name. This would make s... | {
"AcceptedAnswerId": "37608",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T15:01:40.970",
"Id": "37594",
"Score": "2",
"Tags": [
"object-oriented",
"functional-programming",
"f#"
],
"Title": "Using types in F#"
} | 37594 |
<p>I have the following class designs, and I'm looking for the best practices, aligned to the OOP design principles/patterns.</p>
<p>The <code>ParameterParser</code> will be used inside a foreach block through 10 items approximately.</p>
<p>Any comments regarding the method body will also be appreciated, though the f... | [] | [
{
"body": "<p>The important thing is to ask yourself: <strong>How would you use it?</strong></p>\n\n<p>If you are only going to parse with the same parameters multiple times, then the first method would be preferable since you only have to send it the parameters once. However, if you're doing the same thing ove... | {
"AcceptedAnswerId": "37602",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T15:28:22.217",
"Id": "37597",
"Score": "6",
"Tags": [
"c#",
"object-oriented",
"design-patterns",
"classes"
],
"Title": "One instance per method call or multiple method cal... | 37597 |
<p>I recently started learning and programming Java based on a series of beginner videos created by a Youtuber (TheNewBoston), who had a tutorial on a calculator. So based on everything else I've previously learned, I have tried to mix it in to create a bit more advanced one. If you are able to minimize and clean up t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T16:00:34.947",
"Id": "62302",
"Score": "0",
"body": "Oh, and by the way would I be able to apply a Switch Statement in this, since i tested the variable selection for the operator."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>In this case we'd eliminate the repeated code and have left only the different code from your original:</p>\n\n<pre><code>import java.util.Scanner;\n\nclass apples{\n public static void main(String args[]){\n Scanner checker = new Scanner(System.in);\n int selection = 1;\n ... | {
"AcceptedAnswerId": "37605",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T15:43:38.457",
"Id": "37598",
"Score": "6",
"Tags": [
"java",
"beginner",
"calculator"
],
"Title": "Cleaning up calculator program"
} | 37598 |
<p>I have a Django form with a lot of fields, including some FileFields. I want to validate the form based on the contents of the files: they must be valid gdal datasets, and if both are present (one of them is optional) then the optional dataset's extent must entirely cover the required file's extent.</p>
<p>To do th... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T15:58:35.270",
"Id": "37600",
"Score": "4",
"Tags": [
"python",
"form",
"django"
],
"Title": "Django form validation based on the contents of uploaded files"
} | 37600 |
<p>I created a plug-in powered by jQuery that simplifies the developer's life to create responsive applications. It's flexible and I want to give to users a good syntax to write.</p>
<p>How can I improve this?</p>
<p><a href="https://github.com/chiefGui/sensitivejs" rel="nofollow">GitHub</a></p>
<pre><code>; (functi... | [] | [
{
"body": "<p>My 2 cents : </p>\n\n<ul>\n<li>Why jQuery, libraries targetting mobile should not require jQuery, #perfmatters</li>\n<li>Your github project should have a production version where debug is excluded, your code is 4215 bytes with debug feature, 3014 without debugging ( removing all debugging related... | {
"AcceptedAnswerId": "37619",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T18:29:14.880",
"Id": "37612",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Responsive jQuery plug-in"
} | 37612 |
<p>I'm working on my pet project with MVC 5 and EF, and everytime I'm adding a parent with it children (I have the children ID's) I have to go to the database, because if I just create a new child with this ID it just inserts a child object. Is there anyway to avoid this? </p>
<p>This is part of my code:
My classes: <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T18:48:40.283",
"Id": "62343",
"Score": "0",
"body": "I like my navigation properties to be `ICollection` - `List<T>` is an implementation of that interface."
}
] | [
{
"body": "<p>Since <code>FeatureType</code> - <code>ItemTupe</code> is a many-to-many association you can only handle it as an <a href=\"https://stackoverflow.com/q/5281974/861716\"><em>independent association</em></a>, because there is no junction class in the class model that exposes the primitive foreign ke... | {
"AcceptedAnswerId": "37666",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T18:29:37.347",
"Id": "37613",
"Score": "1",
"Tags": [
"c#",
"entity-framework"
],
"Title": "EF adding Item with children"
} | 37613 |
<p>I'm new to Java and have just started making <code>JFrame</code>s. I wrote a program for a game project I'm working on and would like help on where I can improve. I'm not new to programming, I also know HTML and Python well.</p>
<p>I believe one of the goals for all programmers is to make a useful/fun program as si... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T22:24:57.800",
"Id": "62382",
"Score": "3",
"body": "\"as simple and short as possible\", pffft... you apparently don't know me..."
}
] | [
{
"body": "<p>Just about the only thing I could comment on is your indentation the last two brackets</p>\n\n<pre><code> launcher.setLocation(dim.width/2-launcher.getSize().width/2, dim.height/2-launcher.getSize().height/2);\n }\n }\n</code></pre>\n\n<p>should be:</p>\n\n<pre><code> laun... | {
"AcceptedAnswerId": "37628",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T20:20:19.473",
"Id": "37622",
"Score": "1",
"Tags": [
"java",
"beginner",
"swing"
],
"Title": "Shortening code to create a JFrame"
} | 37622 |
<p>The following code sorts an HTML table with JavaScript (without using any external libraries like jQuery). Are there any shortcomings or possible improvements I could make?</p>
<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T09:37:37.393",
"Id": "62377",
"Score": "5",
"body": "Is the code otherwise working? If you're looking for just feedback, you should post to [codereview.se] instead."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | [
{
"body": "<p>To speed up the sorting you first have to find what is consuming time. In your case the slower part of your code is:</p>\n\n<pre><code>for(i = 0; i < rlen; i++){\n rows[i].innerHTML = \"<td>\"+arr[i].join(\"</td><td>\")+\"</td>\";\n}\n</code></pre>\n\n<p>The reason is... | {
"AcceptedAnswerId": "37633",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T09:35:37.360",
"Id": "37632",
"Score": "17",
"Tags": [
"javascript",
"html",
"sorting"
],
"Title": "Sorting an HTML table with JavaScript"
} | 37632 |
<p>I have created a MySQL query that works, but I feel there must be a better way. The query will be used by a PHP script whose purpose is to assign conditions & subconditions to new participants in an online experiment based on how many times each combination of condition & subcondition was already assigned to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T23:13:23.217",
"Id": "62388",
"Score": "1",
"body": "I'd suggest pasting an ERD, or sample data for this. Odds are the SQL statement is just the symptom of a bigger problem: badly designed tables and relationships."
},
{
"Co... | [
{
"body": "<p>The generic solution that won't require changing when adding new subconditions involves several subqueries and will probably be very slow. There isn't too much data here, but it can be sped up (see below).</p>\n\n<p><strong>1. Completes</strong></p>\n\n<p>You have this one already in your query.</... | {
"AcceptedAnswerId": "37657",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T22:46:37.937",
"Id": "37637",
"Score": "4",
"Tags": [
"php",
"mysql",
"sql"
],
"Title": "Make this MySQL query more elegant &/or efficient"
} | 37637 |
<p>Below is my typical WindowController module for presenting a modal dialog (could be settings, asking username/password, etc) loaded from a XIB. It seems a bit too complex for something like this. Any ideas how this can be done better/with less code?</p>
<p>Never mind that it's asking for a password, it could be any... | [] | [
{
"body": "<p>Based on Ken Thomases answer given <a href=\"https://stackoverflow.com/questions/20477717/presenting-modal-dialogs-from-xib-in-cocoa-best-shortest-pattern/20647814#20647814\">on SO here</a>, here is my revised modal window module. Note that the window should have the system close button disabled, ... | {
"AcceptedAnswerId": "37649",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T23:32:38.893",
"Id": "37640",
"Score": "5",
"Tags": [
"objective-c",
"cocoa",
"osx"
],
"Title": "Presenting modal dialogs from XIB in Cocoa: best/shortest pattern?"
} | 37640 |
<p>Here is a implementation of the cryptographic hash function SHA1 written in Python. It does not use any external libraries, only built-in functions. I know that it would be faster to use an external library, but my code is for learning purposes.</p>
<p>I want to know if I am properly implementing the algorithm. A... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T02:47:05.580",
"Id": "62412",
"Score": "2",
"body": "http://docs.python.org/2/library/hashlib.html"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T05:09:38.407",
"Id": "62415",
"Score": "1",
... | [
{
"body": "<p>I'm no expert on SHA1, and I see mostly small things, but one big thing that gave me pause. As an overall observation, you seem to value readability over memory usage. Since hashes are often used for large files, this seems to be a risky tradeoff, and python does provide good ways to handle this a... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T02:32:41.667",
"Id": "37648",
"Score": "13",
"Tags": [
"python",
"cryptography",
"reinventing-the-wheel"
],
"Title": "Python implementation of SHA1"
} | 37648 |
<p>I am currently storing form data in an XML format:</p>
<pre><code><cfsavecontent variable="myFormData">
<cfoutput>
<ul class="xoxo">
<cfloop list="#form.fieldnames#" index="item">
<cfloop list="#form[item]#" index="eachItem">
<li><b>#xmlformat(item)#</b> <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T06:58:23.317",
"Id": "62437",
"Score": "0",
"body": "How is the data used? It seems very odd to render it as an HTML list, then store it thus."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T13:47:12.... | [
{
"body": "<p>Well, it depends what you want to do with this data. If you ever want to query individual field names or debug an issue with a field you will have a hard time extracting this kind of information out of an XML blob.</p>\n\n<p>Potential pitfall: According to the <a href=\"http://livedocs.adobe.com/c... | {
"AcceptedAnswerId": "37661",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T05:17:58.407",
"Id": "37653",
"Score": "2",
"Tags": [
"sql-server",
"xml",
"coldfusion",
"cfml"
],
"Title": "Storing arbitrary form data in SQL as an XML blob"
} | 37653 |
<p>I have used multiple lines of code in one <code>if</code> condition without using curly braces, which is executing properly. So what is the main necessity of using curly braces in <code>if</code> statements for multiple lines?</p>
<pre><code> if (ggcCompareGrid.TopLevelTable != null)
foreach (GridRow ro... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T12:15:15.690",
"Id": "62455",
"Score": "5",
"body": "Have you researched this all through SE? This question (and fairly large list of related cousins) is old enough to have whiskers on it.\n\nhttp://programmers.stackexchange.com/que... | [
{
"body": "<p>You're not using multiple lines of code in one <code>if</code> without curly braces, only one. For example, your <code>foreach</code> loop is considered as one statement, even if the code inside your loop is on multiple lines. That's why you don't need curly braces for your first <code>if</code>. ... | {
"AcceptedAnswerId": "37670",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T10:59:46.143",
"Id": "37665",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Multiple lines of code in if statement without curly braces"
} | 37665 |
<p>I'm making a text-based RPG in JavaScript. It works but I'd like to know how to improve it, like code-wise. Also, I want to know how to make it run on anything other than Internet Explorer.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T13:57:25.880",
"Id": "62470",
"Score": "0",
"body": "I read your post but i'm not sure what your question is. Please clarify if you want to be able to run this on any other browser, i.e., Chrome, Firefox, or if you want to be able ... | [
{
"body": "<ul>\n<li><p>You have a lot of inconsistent indentation. (See link at the bottom for an easy way to fix this)</p></li>\n<li><p>Inconsistent positioning of <code>{</code>, are you going to place it on it's own line (common C# style) or on the previous line (common Java style)? The JavaScript conventio... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T13:39:34.920",
"Id": "37672",
"Score": "6",
"Tags": [
"javascript",
"game",
"role-playing-game"
],
"Title": "JavaScript text-based RPG"
} | 37672 |
<p>I've been working on a small "frame" for a text adventure in Python.</p>
<p>So it's less of a real adventure and more of a small testing location for all the commands.</p>
<p>I pretty much just started learning Python after completing the Codecademy tutorial and don't want to pick up any bad habits.</p>
<pre><cod... | [] | [
{
"body": "<p>There's a lot of code here, so it's hard to make a cohesive review. Instead I'll point out a few things related to your comment about avoiding picking up bad habits. The most common problems I see in your code are repeated work, and misplacement of responsibilities.</p>\n\n<p>This isn't comprehens... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T16:00:05.563",
"Id": "37677",
"Score": "10",
"Tags": [
"python",
"game",
"python-2.x"
],
"Title": "A small Python text adventure \"frame\""
} | 37677 |
<p>Suppose I have data coming from different sources that tells me information about a large group of stores that has the following (just an example):</p>
<p><strong>Necessary to define what store we're dealing with:</strong></p>
<ul>
<li>Store_Name (String)</li>
<li>Location (String)</li>
</ul>
<p><strong>Store cha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T14:40:06.317",
"Id": "62503",
"Score": "1",
"body": "One suggestion I can make is rather than calling `StoreData.ContainsKey` you could call `StoreData.TryGetValue`. This way you don't have to do a 2nd lookup in your `Else` block."
... | [
{
"body": "<p>If you're stuck with <code>Tuple<T1,T2></code> as a key, you want to provide an <code>IEqualityComparer<Tuple<T1,T2>></code> implementation in <a href=\"http://msdn.microsoft.com/fr-fr/library/ms132072%28v=vs.110%29.aspx\" rel=\"nofollow\">the constructor</a> of your dictionary.<... | {
"AcceptedAnswerId": "37682",
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T14:32:36.323",
"Id": "37679",
"Score": "3",
"Tags": [
"c#",
".net",
"vb.net",
"hash-map"
],
"Title": "Is there a better, more efficient way than Dictionary(Of Tuple(), MyC... | 37679 |
<p>I am learning the Strategy pattern but hate the idea of passing a new object to the Context each time I need to change the desired algorithm. Instead I think it would be best to create an enum that holds all of the Concrete Strategy objects, and simply update them with a setter on the context. Below is my implementa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T17:19:17.207",
"Id": "62521",
"Score": "0",
"body": "Is ConcreteStrategies an enum or a class?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T17:25:23.597",
"Id": "62525",
"Score": "1",
"... | [
{
"body": "<p>The overall quality of your code is very good. It is, at least in my opinion, perfectly fine to have an enum containing the strategy implementations.</p>\n\n<p>A few comments and suggestions though:</p>\n\n<ul>\n<li><code>private Object concreteStrategy;</code> in your enum can and should be <code... | {
"AcceptedAnswerId": "37685",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T16:52:17.657",
"Id": "37683",
"Score": "7",
"Tags": [
"java"
],
"Title": "Implementation of the Strategy pattern"
} | 37683 |
<p>I want to extract some values in i-commas(") from lines like this: </p>
<pre><code><P k="9,0,1" vt="191" v="100.99936" z="" />
</code></pre>
<p>Example:</p>
<pre><code>getCharVal ( cp, char "k=\"", 9)
</code></pre>
<p>where cp is a pointer the line above should return "9,0,1"</p>
<p>The function:</p>
<pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T03:04:17.527",
"Id": "62594",
"Score": "0",
"body": "[Use a regular expression](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454)! (seriously, **don't!**)"
}
] | [
{
"body": "<p>The easiest code to maintain is code that doesn't exist. For parsing XML, use an XML-parsing library, preferably with XPath support. Sometimes it <em>might</em> be justified to whip up your own code to extract values from XML, but it clearly does not make sense in this case. Not only is the cod... | {
"AcceptedAnswerId": "37712",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T17:02:32.920",
"Id": "37684",
"Score": "3",
"Tags": [
"c",
"strings",
"parsing",
"xml"
],
"Title": "Small function for getting character value"
} | 37684 |
<p>I am writing a simple web application where I have a User entity and set of pre-defined questions to be answered by the User. The answers provided by the users for these questions would need to be stored against the userId and questionId. After a bit of googling and with the help of stackoverflow, I have designed th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T20:15:45.807",
"Id": "62551",
"Score": "1",
"body": "XML is a data-interchange format. It is not something that is supposed to be pretty, or 'looks elegant'. It is supposed to be easily computer-readable, and sophisticated developer... | [
{
"body": "<p>Rename QuestionAnser to QuestionAnswer but I think this is obvious..</p>\n\n<p>IMHO your Entitynames are to complicated and contain duplicate answers. I would rename QuestionMaster to Question and QuestionAnswer to QuestionAnswer. </p>\n\n<p>Why do you have an embedded ID?</p>\n",
"comments": ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T17:57:12.887",
"Id": "37687",
"Score": "1",
"Tags": [
"java",
"xml",
"hibernate"
],
"Title": "A query on Hibernate database design"
} | 37687 |
<p>I'm trying to make a few webpages that will allow us in the tech support team at the factory I work at to provide support faster by adding a simple interface to actions we perform everyday directly on the database. </p>
<p>The following is for a simple page where we will enter a list of serial numbers and select fr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T08:10:18.347",
"Id": "62757",
"Score": "0",
"body": "No, please don't advise to add a switch statement. It's clear that you should replace these conditions with polymorphism (sub classes). You create a Interface or Abstract base cla... | [
{
"body": "<p>Simplify your properties with the <code>as</code> operator:</p>\n\n<pre><code>private List<string> CRIDS\n{\n get\n {\n return ViewState[\"CRIDS\"] as List<string>;\n }\n\n set\n {\n ViewState[\"CRIDS\"] = value;\n }\n}\n\nprivate List<string> Seri... | {
"AcceptedAnswerId": "37707",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T18:02:19.280",
"Id": "37688",
"Score": "6",
"Tags": [
"c#"
],
"Title": "Advice to improve code in simple webpage"
} | 37688 |
<p>I want to establish a hierarchy, where at each level of the hierarchy, each type can contain a <code>list<its own type></code>. So <code>Node</code> (root of object class hierarchy) contains a <code>list<Node*></code>, <code>SpecialNode : Node</code> contains a list of <code>SpecialNode</code>. <code>S... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T19:48:43.493",
"Id": "62544",
"Score": "0",
"body": "What are you trying to achieve with this? From your code it looks like you're only inheriting from `Node` so that you can have a 'level' to each node, is there a specific need to ... | [
{
"body": "<p>You might prefer to not use polymorphism at all if you want to make sure that your types remain unique. Consider something more like:</p>\n\n<pre><code>class Node\n{\nprivate:\n list<Node*> children ;\n int v ;\n\npublic:\n Node( int iv ) : v(iv) { }\n\n void add( Node* child )\n... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T19:07:27.677",
"Id": "37691",
"Score": "3",
"Tags": [
"c++",
"collections"
],
"Title": "Hierarchy with `list<self>` type"
} | 37691 |
<p>I'm iterating through a number of text files, trying to locate all carriage-returns, and individually save the text between carriage-returns. I get the index numbers of all carriage-returns, but I haven't got the slightest about saving the text.</p>
<p>Basically I want to save every string between two carriage-retu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-23T04:14:08.137",
"Id": "63132",
"Score": "0",
"body": "Seeb, do you want it to work with this paragraph? :-)"
}
] | [
{
"body": "<pre><code>text = File.read \"test.txt\"\nputs \"#{text.split(\"\\n\").size} lines.\"\nparagraphs = text.split \".\\n\"\nputs \"#{paragraphs.length} paragraphs.\"\n\nwords_in_each_paragraph = paragraphs.map.with_index do |paragraph, i|\n puts \"working on paragraph ##{i}\"\n paragraph.split(\"\... | {
"AcceptedAnswerId": "37743",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T20:08:21.013",
"Id": "37696",
"Score": "5",
"Tags": [
"ruby",
"array",
"hash-map"
],
"Title": "Splitting a text file into paragraphs and words"
} | 37696 |
<pre><code>def truthy(v):
if issubclass(v.__class__, numbers.Number):
return bool(int(v))
if isinstance(v, basestring):
vl = v.lower()[0]
if vl == 'y' or vl == 't':
return True
return False
</code></pre>
<ol>
<li><p>Is there some type/class I missed that can be evaluated... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T21:41:18.807",
"Id": "62568",
"Score": "2",
"body": "What do you plan to use this for?"
}
] | [
{
"body": "<p>How about:</p>\n\n<pre><code>accepted_truthy_characters = {'y', 't'}\n\ndef truthy(value):\n if isinstance(value, basestring):\n return value and value[0].lower() in accepted_truthy_characters\n return bool(value)\n</code></pre>\n\n<p>In Python 3.x, basestring won't work and you'll ne... | {
"AcceptedAnswerId": "37875",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T21:33:22.940",
"Id": "37698",
"Score": "2",
"Tags": [
"python"
],
"Title": "Truthy/falsy in Python"
} | 37698 |
<p>I am sorry for the simple request, but I'm trying to figure out the best way to optimizing the following bit of code. I hate using 20 lines of code when 12-15 will suffice. I also don't like having to use intermediate variables if I don't need to.</p>
<pre><code>$total_query_raw = "SELECT SUM( total ) AS total
... | [] | [
{
"body": "<p>you might want to write it like this</p>\n\n<pre><code>$total_query_raw = \"SELECT SUM( total ) AS total\n FROM `tblinvoices` \n WHERE `datepaid` \n BETWEEN '$start_date 00:00:00' AND '$end_date 23:59:59'\";\n\n$total_que... | {
"AcceptedAnswerId": "37706",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T22:42:14.753",
"Id": "37703",
"Score": "3",
"Tags": [
"php",
"optimization",
"mysql"
],
"Title": "Need help optimizing PHP/MySQL code snippet"
} | 37703 |
<h2>Task</h2>
<p>Create a matrix of checkboxes. The user must be able to select only 1 checkbox in a row or unselect all of them.</p>
<p><img src="https://i.stack.imgur.com/i91DZ.png" alt="enter image description here" /></p>
<h2>Solution</h2>
<pre><code><!DOCTYPE html>
<html>
<head>
<meta ht... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T09:37:26.533",
"Id": "62615",
"Score": "0",
"body": "why not change to radio buttons?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T09:51:18.730",
"Id": "62618",
"Score": "0",
"body": "@... | [
{
"body": "<p>Assuming an unchecked starting condition you can eliminate a parameter and thus drop the conditional:</p>\n\n<pre><code>function switch_checkbox(id_pair)\n{\n document.getElementById(id_pair).checked = false;\n}\n</code></pre>\n\n<p>...</p>\n\n<pre><code><input type=\"checkbox\" name=\"group... | {
"AcceptedAnswerId": "37715",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T00:47:04.777",
"Id": "37708",
"Score": "2",
"Tags": [
"javascript",
"html",
"matrix"
],
"Title": "Matrix of checkboxes - only 1 allowed in a row"
} | 37708 |
<p>I've made the following and have a few questions:</p>
<ol>
<li><p>Do I have some (big) mistakes in this approach? (bad practices, 'this code is trash'...)</p>
<p>1.1 If I do, can you suggest what to fix?</p></li>
<li>Are appended element created in good way?</li>
<li>Code in success function seems to be a little l... | [] | [
{
"body": "<h1>My 2 cents:</h1>\n\n<ul>\n<li><p>You could use <code>$().hide()</code> instead of assigning your custom hiding css class</p></li>\n<li><p>Similarly you could use <code>$().show()</code> instead of removing your custom hiding css class</p></li>\n<li><p>You do not have to check the length of a jQue... | {
"AcceptedAnswerId": "37808",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T01:37:14.927",
"Id": "37711",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"html",
"ajax",
"html5"
],
"Title": "Creating <select> element and append data to it"
} | 37711 |
<p>This is my first real program in python (and my first real program) and I would like to have input by some more advanced programmers on the code, on the writing style and on the amount of comments (is it clear enough?).</p>
<p><code>new_name(scheme)</code> does seems a bit bloated to me, but I can't figure out how ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-06-07T07:42:37.877",
"Id": "244847",
"Score": "0",
"body": "Looks like quite a lot of people are looking at this code to use it, so here's a shameless plug for the actual git repository for rename-flac: https://gitlab.com/baldurmen/rename... | [
{
"body": "<ol>\n<li><p>This does not seem really useful:</p>\n\n<pre><code>else:\n pass\n</code></pre></li>\n<li><p>On the Internet, you'll find various ways to perform the string replacement in a case-insensitive way (<a href=\"https://stackoverflow.com/questions/919056/python-case-insensitive-replace\">fo... | {
"AcceptedAnswerId": "37748",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T04:14:57.423",
"Id": "37721",
"Score": "6",
"Tags": [
"python",
"beginner",
"linux",
"file-system"
],
"Title": "Batch rename flac files"
} | 37721 |
<p>This week's <a href="https://codereview.meta.stackexchange.com/q/1245/9357">weekend challenge #3</a> seemed like a great opportunity to learn Ruby! Unfortunately, my workload and looming vacation did not cooperate. :( The puzzle will make forced moves automatically, but I was hoping to implement rules such as Naked ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T16:17:24.297",
"Id": "62685",
"Score": "0",
"body": "What kind of feedback are you looking for? For example, are you looking for feedback on readability, performance, etc.?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creat... | [
{
"body": "<p>It's definitely a nice start. But it's funny; I can tell you're coming to Ruby from Java :)<br>\nI don't mean anything negative by that, by the way. It's just interesting how some subtle clues here and there give it away.</p>\n\n<p>Anyway, if you want to develop good habits early, unit testing and... | {
"AcceptedAnswerId": "37856",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T06:41:47.017",
"Id": "37723",
"Score": "13",
"Tags": [
"ruby",
"community-challenge",
"sudoku"
],
"Title": "Ruby Sudoku solver"
} | 37723 |
<p>I've inherited a class in a project which is purposed to execute a function that exists in POST data from a specified class. I've tried to clean this up as much as possible as well as secure it against SQL injection but I'm wondering if I could have done a better job or written this better. Any assistance would be m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T09:03:47.977",
"Id": "62610",
"Score": "0",
"body": "Whatever you are trying to do, there _has_ to be a better way than to use `$_POST` data to call a function! besides, your syntax is ambiguous: should PHP evaluate `$SP->$sanitized... | [
{
"body": "<p>Well, I'm going to post it as an answer, simply because comments aren't the right place for this:</p>\n\n<blockquote>\n <p>See edit for justification</p>\n</blockquote>\n\n<p>You <em>can't</em> justify using <code>$_POST</code> data to call functions or methods in a script. <strong><em>never trus... | {
"AcceptedAnswerId": "37732",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T07:16:27.987",
"Id": "37724",
"Score": "4",
"Tags": [
"php",
"optimization",
"classes",
"security",
"sql-injection"
],
"Title": "Using POST data to call a function from... | 37724 |
<p>I wrote these classes and I would like to know if this is a correct way. I created a new Project with Blank activity and "Scrollable Tabs + Swipe" as Navigation type.</p>
<p>My main activity:</p>
<pre><code>public class MyMainActvity extends FragmentActivity {
private static String url = "http://www.myurl.it"... | [] | [
{
"body": "<p>I'm not too familiar with Android, so just some generic notes about the Java code:</p>\n\n<ol>\n<li><p>Instead of using magic numbers in the switch-case use named constants. It would help maintenance a lot. There is more than one switch-case with the same 0-3 case branches. A reader might wonder: ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T09:54:36.237",
"Id": "37726",
"Score": "6",
"Tags": [
"java",
"android",
"json"
],
"Title": "Populate views in Android application"
} | 37726 |
<p>I made a simple Universal-File-Duplicator (Example: make 125 duplicates of one file).
Very useful if you want to fill a whole USB flash drive or an old harddisk with an important file (Example: Bitcoin wallet.dat or privatekey) and you don't want to hit <kbd>Ctrl</kbd>+<kbd>V</kbd> all the time...</p>
<p>Suggestion... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T17:21:35.243",
"Id": "62699",
"Score": "0",
"body": "Why would you want to fill a whole harddisk with one file? If the drive crashes, it crashes. Even though this could be useful for when only some sectors of a drive goes down, maki... | [
{
"body": "<p>You've got a <code>using namespace std;</code> in your code. <a href=\"https://stackoverflow.com/questions/1265039/using-std-namespace\">Don't do that</a>. (<a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">No, really</a>).</p>\n\n<hr>\n\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T10:24:35.413",
"Id": "37728",
"Score": "4",
"Tags": [
"c++",
"file",
"console"
],
"Title": "Universal File Duplicator"
} | 37728 |
<p>The task is fairly simple. I want to create a collection of intervals and implement an <code>Add</code> method which would insert new intervals to the collection and merge overlapping ones. I would also like this method to somehow tell me which parts of the added interval were not in the collection before adding.</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T13:00:04.827",
"Id": "62632",
"Score": "0",
"body": "Does performance matter? In other words, is going through all intervals for each insert okay, or do you need something better than that?"
},
{
"ContentLicense": "CC BY-SA ... | [
{
"body": "<p>Unless necessary you should consider making your <code>Interval</code> immutable by making the <code>set</code>s private. It's easier to deal with such \"value containers\" if they're immutable (see <code>Point</code>, <code>DateTime</code>, etc.).</p>\n\n<p>Also at the moment you can break your c... | {
"AcceptedAnswerId": "37938",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T10:26:04.753",
"Id": "37729",
"Score": "5",
"Tags": [
"c#",
"collections",
"interval"
],
"Title": "Inserting interval into a collection"
} | 37729 |
<p>I'm building an API wrapper for a bookkeeping SOAP API. </p>
<p>I have some questions regarding bast practice for structure of the wrapper and for error handling.</p>
<p>For now i've structured it like this:</p>
<p><em>EconClient.php</em></p>
<pre><code>class EconClient {
public function __construct()
... | [] | [
{
"body": "<p>As for passing in <code>$client</code> in your resource class I don't see a real problem there, are there any specific reason for why you do not want to do it?</p>\n\n<p>...</p>\n\n<p>When it comes to error handling in API's there's a few things you can do that are usually API-specific.</p>\n\n<p>... | {
"AcceptedAnswerId": "37741",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T10:51:20.230",
"Id": "37731",
"Score": "3",
"Tags": [
"php",
"object-oriented",
"api",
"wrapper"
],
"Title": "Structure of API wrapper"
} | 37731 |
<p>Some time ago I <a href="https://bitbucket.org/BigYellowCactus/mdclj">created a markdown parser in clojure</a> and I would like to get some feedback, since I'm a clojure noob in the first place (is the code understandable?/is it idiomatic?/can some things be improved?). </p>
<p>So I'm looking for feedback on best p... | [] | [
{
"body": "<p>This is overall very impressive! Here are my thoughts:</p>\n\n<p>It looks like you've pretty much written your parser \"from scratch\" -- you have it set up so that it takes text as an input and dissects it line by line, looking for blocks and spans, and labeling and converting them appropriately.... | {
"AcceptedAnswerId": "44992",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T12:26:42.223",
"Id": "37736",
"Score": "10",
"Tags": [
"parsing",
"clojure",
"markdown"
],
"Title": "Idiomatic clojure code in a markdown parser"
} | 37736 |
<p><strong>What should the code do:</strong> Process client HTML requests, query database and return the answer in XML. Working with a high load.
I need to know how can it be optimized.
Is something terribly wrong with this code?</p>
<p><strong>Input data:</strong> HTML-session, MAC-address (in form of GET argument).<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-27T19:25:36.103",
"Id": "67564",
"Score": "1",
"body": "Ensure that you have indexes defined on the `device` table for the `session_id` and `mac` columns."
}
] | [
{
"body": "<p>Some minor random notes:</p>\n\n<ol>\n<li><p>Instead of commenting, like this:</p>\n\n<pre><code> //If session_id is not null, we need to check if it is valid for mac provided\n if (!(device.getSessionId().equals(session.getId()))) {\n makeXml (request,response,session_id, RESPONSE_ST... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T12:51:08.037",
"Id": "37740",
"Score": "10",
"Tags": [
"java",
"mysql",
"servlets"
],
"Title": "Servlet for querying database on some high-loaded system"
} | 37740 |
<pre><code>public class ConsoleQuery {
public static void main(String[] args) throws SQLException {
if (args.length == 0) {
System.out.println("You must specify name");
return;
}
String name = args[0];
Map < String, Object > device = getDeviceByName(name... | [] | [
{
"body": "<p>Well, the most important optimization you can make to this code is to improve your SQL query. You are currently pulling down the entire db but only care about one row; you're doing half your query on the client side. Use SQL, not Java, for selecting data from the db! Consider the following version... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T13:26:41.873",
"Id": "37745",
"Score": "0",
"Tags": [
"java",
"optimization"
],
"Title": "Simple command line tool to query database. Need code optimized"
} | 37745 |
<p>I have a method which returns an Array. This array can contain values or can be empty. Here is the code:</p>
<pre><code>function getCustomerIds() {
//this declaration is at the top to inform about returning value of the method; I don't declare variables at the top
var customerIds = [];
var linkedContact... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T14:43:33.070",
"Id": "62648",
"Score": "2",
"body": "Why does the `customerIds` variable exists at all?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T14:45:48.050",
"Id": "62649",
"Score": "... | [
{
"body": "<p>It's debatable. Or perhaps I'd say: it's very dependent on context.</p>\n\n<p>If you return early (as you do here), I think it's probably good to return <code>[]</code>. When you read the code, you see the conditional and its effect: an empty array is returned, period. To me early returns feel a b... | {
"AcceptedAnswerId": "37761",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T14:26:16.360",
"Id": "37750",
"Score": "16",
"Tags": [
"javascript"
],
"Title": "Multiple returns in a method or one return"
} | 37750 |
<p>We are given a string which is compressed and we have to decompress it.</p>
<blockquote>
<p>(a(bc2)d2)$</p>
</blockquote>
<p>"$" indicates end of string.</p>
<blockquote>
<p>(abcbcd2)$</p>
<p>abcbcdabcbcd (This is the final uncompressed string.)</p>
</blockquote>
<p>My code:</p>
<pre><code>import java... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T18:37:43.613",
"Id": "62714",
"Score": "0",
"body": "Can you explain a bit about what your code does, how it works?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T18:40:25.790",
"Id": "62716",
... | [
{
"body": "<p>Did you start out code golfing?</p>\n\n<p>Use variable names that mean something. The only variable you used that has any meaning to the reader is <code>end</code>. This means that unless you remember, every time you hit a variable you have to scroll up to find out what it is.</p>\n\n<p>This almos... | {
"AcceptedAnswerId": "37768",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T18:20:16.197",
"Id": "37763",
"Score": "5",
"Tags": [
"java",
"strings"
],
"Title": "Decompressing a string"
} | 37763 |
<p><a href="http://projecteuler.net/problem=11">Project Euler problem 11</a> says:</p>
<blockquote>
<p>In the 20×20 grid below, four numbers along a diagonal line have been marked in bold. [<em>red in the original</em>]</p>
<p><code>08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08</code><br>
<code>... | [] | [
{
"body": "<ul>\n<li><code>xrange(0, N)</code> to <code>xrange(N)</code></li>\n<li>name your loop variables something meaningful, like <code>row</code> and <code>col</code></li>\n<li>create some variables for the indices you need, e.g. <code>one_cell_up = grid[h*whatever]</code></li>\n<li>do you need a list o... | {
"AcceptedAnswerId": "37777",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-19T18:46:37.143",
"Id": "37767",
"Score": "9",
"Tags": [
"python",
"beginner",
"project-euler"
],
"Title": "Largest product in a grid"
} | 37767 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.