body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I recently bought a PSP and wanted to know the best ISO files and wrote a scraper to retrieve games ISOs titles that received a high rating and send them to a csv. Any recommendations as to readability, and/or better code optimizations?</p>
<pre><code>var request = require('request');
var cheerio = require('cheerio... | [] | [
{
"body": "<p>After revisiting this, and even though I prefer to handle tasks like this with node, it is possible to write a bash script using curl, and/or xpath that accomplishes this same task. The ratings could filtered with a regex pattern within grep just to lay down a few ideas. Again, this is just an alt... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T16:58:38.243",
"Id": "55046",
"Score": "3",
"Tags": [
"javascript",
"node.js",
"web-scraping"
],
"Title": "Node PSP ISO Scraper"
} | 55046 |
<p>I am implementing <code>atoi()</code> by traversing a string from the beginning as well as from the end. Is there anything I can improve?</p>
<pre><code>using namespace std;
int atoiLefttoRight(char *s){
int num = 0;
int negative = 1;
if(s)
{
if(*s == '-')
{
neg... | [] | [
{
"body": "<p>For the moment I'll concentrate on the left to right version. Most of the same comments apply to the right to left version as well though.</p>\n\n<pre><code>int atoiLefttoRight(char *s){\n</code></pre>\n\n<p>Since you're not going to modify the original string, the parameter should be <code>char c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T17:27:36.410",
"Id": "55048",
"Score": "5",
"Tags": [
"c++",
"strings",
"converting",
"reinventing-the-wheel"
],
"Title": "Bi-directional atoi()"
} | 55048 |
<p>I am trying to learn Ruby and made a simple Caesar cipher program and I was wondering if the following code follows the 'ruby way' or the way most ruby users would do it </p>
<pre><code># Implements the classes caesar cipher encryption and decryption.
class CaesarCipher
def initialize(shift)
@shift = shift
... | [] | [
{
"body": "<p>That's a pretty good start, however I noticed that your code only works on letters. For non-alphabetic characters it returns confusing results e.g. encrypting and decrypting <code>!</code> gives you <code>;</code>. I can think of three good ways to handle non-alphabetic characters:</p>\n\n<ul>\n<l... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T08:18:51.557",
"Id": "55049",
"Score": "6",
"Tags": [
"ruby",
"caesar-cipher"
],
"Title": "Learning Ruby Caesar Cipher"
} | 55049 |
<p>I have a softmatch function (below) that takes a donor list and a new entry and looks to see if the given donor already exists. </p>
<p>The data is not exact, so I have to use a softmatch to determine whether a given record exists (ex: Jon Doe at 123 Sesame St. is the same as John P. Doe at 123 Sesame Street). I ... | [] | [
{
"body": "<p>I recommend you try different approaches:</p>\n\n<ol>\n<li>Use <code>quick_ratio</code> instead of <code>ratio</code></li>\n<li>Apply <code>.lower().split(' ')</code> to the data before sending it to the <code>SequenceMatcher</code></li>\n<li>Add a line somewhere that checks if the two strings are... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-06-23T17:58:53.607",
"Id": "55051",
"Score": "4",
"Tags": [
"python",
"strings",
"time-limit-exceeded",
"edit-distance"
],
"Title": "Python softmatcher using difflib impracticably s... | 55051 |
<p>I've been trying to write a really basic function to determine the difference (in days) between two dates. I am <strong>very</strong> new to C++ so as you can imagine I am very happy with my work.
This function is part of a much larger code so I have missed off my includes, but the function does compile without warn... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T19:13:11.103",
"Id": "96358",
"Score": "1",
"body": "Would be a lot easier to calcularte the difference in seconds. Then convert that to days."
}
] | [
{
"body": "<p>I see a number of problems with this:</p>\n\n<ul>\n<li>The code as provided does not compile; you haven't shown what <code>#include</code> directives you've used.</li>\n<li>You don't validate the input to make sure it is in the proper DD/MM/YYYY format.</li>\n<li>You don't validate the parsed year... | {
"AcceptedAnswerId": "55057",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T18:50:32.723",
"Id": "55054",
"Score": "6",
"Tags": [
"c++",
"beginner",
"datetime"
],
"Title": "Difference in days between two dates"
} | 55054 |
<p>I've spent a couple days making this script in Outlook that checks my emails and saves/sorts/sends a reply based on the subject. This also happens to be my first experience in working with VBA. Now that I have it working, I was wondering how I could simplify it or "make it prettier" (I always got docked points in my... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T17:33:25.247",
"Id": "96757",
"Score": "0",
"body": "Your professor should probably step outside of academia into a real code base sometime...."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T17:38:03... | [
{
"body": "<p><strong>Readability</strong></p>\n\n<ul>\n<li><p>Proper indentation is important for readability. Everything inside of <code>Sub...End Sub</code> should be indented one tab (or four spaces). <code>Else If</code> statements should line up with their corresponding <code>If</code> statements. For exa... | {
"AcceptedAnswerId": "55125",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T19:03:28.277",
"Id": "55055",
"Score": "10",
"Tags": [
"vba",
"email",
"outlook"
],
"Title": "Script for saving/sorting/sending emails based on their subject"
} | 55055 |
<p>I've just published <a href="https://adexploder.codeplex.com" rel="nofollow">ADExploder</a>. It's a single-script PowerShell app (<a href="https://adexploder.codeplex.com/SourceControl/latest#adexploder.ps1" rel="nofollow">source</a>) that uses classic Windows Forms and the Directory Services API to be able to brows... | [] | [
{
"body": "<p>Your code looks pretty good to me.</p>\n\n<hr>\n\n<p>You can replace this:</p>\n\n<pre><code>[string]::Format('{0} = 0x{0:X8}', $val)\n</code></pre>\n\n<p>with this:</p>\n\n<pre><code>'{0} = 0x{0:X8}' -f $val\n</code></pre>\n\n<hr>\n\n<p>Empty \"catch all\" catch blocks are not a good idea:</p>\n\... | {
"AcceptedAnswerId": "55075",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T19:12:43.917",
"Id": "55056",
"Score": "8",
"Tags": [
"winforms",
"powershell",
"active-directory"
],
"Title": "PowerShell Active Directory Browser"
} | 55056 |
<p>I used the information from the article <a href="http://weblogs.asp.net/scottgu/auto-start-asp-net-applications-vs-2010-and-net-4-0-series" rel="nofollow">"Auto-Start ASP.NET Applications (VS 2010 and .NET 4.0 Series)"</a> to create a background task that runs on an infinite loop. Ultimately, this program is going t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T18:24:26.797",
"Id": "96606",
"Score": "0",
"body": "Interesting. I've been keeping an eye on the Auto-Start feature but haen't gotten a chance to use it much. Any idea how it does with [these limitations of IIS applications](http:/... | [
{
"body": "<p>There are some things that you could have done better certainly.</p>\n\n<p>My first pick is the class name <code>DoStuff</code>. Please try pick a more meaningful name like <code>Action</code> or <code>Task</code>. </p>\n\n<p>In this class you seem to be appending the current time to the property ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T19:21:39.187",
"Id": "55059",
"Score": "5",
"Tags": [
"c#",
"asp.net-mvc-4"
],
"Title": "PreWarmCache for MVC Application with Stopwatch Infinite Loop"
} | 55059 |
<p>I have been working on a small game called apple picker, it's text-based, and relvolves around picking and selling apples. Unfortunately I've been using global variables for this whole thing and it's starting to get a bit ugly looking. Is there a more efficient way to do this than using global variables? </p>
<pre>... | [] | [
{
"body": "<p>You don't need to list those as globals. Variables defined at the module-level namespace are available in functions in that module. Just remove the global declarations and you should be fine.</p>\n\n<p>Another thing: calling <code>main()</code> is kind of dangerous. It's always better to do this i... | {
"AcceptedAnswerId": "55066",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T19:31:29.547",
"Id": "55060",
"Score": "3",
"Tags": [
"python",
"python-2.x"
],
"Title": "Apple picking game. More efficient method than using global variables"
} | 55060 |
<p>I am working through more tutorials on Design Patterns and came across the Abstract Factory Pattern. I extended it out a bit (the example that is) and want your opinion:</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DoFactory.GangOfFour.Abstract.Real... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T12:29:48.247",
"Id": "96482",
"Score": "0",
"body": "In my experience, the factory pattern is a particularly good fit when you have a class that needs to construct instances of other classes, and those classes have other dependencie... | [
{
"body": "<h3>Single Inheritance</h3>\n<p>By using <em>abstract classes</em> like this...</p>\n<blockquote>\n<pre><code>abstract class ContinentFactory\n{\n public abstract Herbivore CreateHerbivore();\n public abstract Carnivore CreateCarnivore();\n public abstract Problem CreateProblem();\n publi... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T19:37:48.657",
"Id": "55062",
"Score": "8",
"Tags": [
"c#",
"abstract-factory"
],
"Title": "Abstract Factory Pattern C# Example"
} | 55062 |
<p>I'm doing some of the Codility challenges using Ruby. The current challenge is "The <a href="https://codility.com/programmers/lessons/2" rel="nofollow">MaxCounter</a>," which is described as:</p>
<blockquote>
<p>Calculate the values of counters after applying all alternating operations: increase counter by 1; set... | [] | [
{
"body": "<p>I can't speak to performance, since I don't know what codility considers acceptable, but I'll give it a go.</p>\n\n<p>In terms of reviewing your code, your solutions seem to be getting more and more compact, but that doesn't necessarily help performance. <em>Shorter code does not equal faster cod... | {
"AcceptedAnswerId": "55073",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T19:50:26.830",
"Id": "55063",
"Score": "4",
"Tags": [
"optimization",
"performance",
"algorithm",
"ruby",
"programming-challenge"
],
"Title": "Performance of Codility M... | 55063 |
<p>I have been going through algorithms and data structures and recently came across string matching algorithms. I have not yet wrapped my head around the significance KMP algorithm so I came up with the function below. Is it really efficient or is there a better approach?</p>
<pre><code>bool simplePatternMatch(cons... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T20:43:30.550",
"Id": "96383",
"Score": "1",
"body": "Will fail for `simplePatternMatch(\"CCAT\", \"CAT\")`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T04:32:38.143",
"Id": "96419",
"Score"... | [
{
"body": "<h1>Code Style</h1>\n\n<h3>Whitespace and Braces</h3>\n\n<p>Be consistent in your usage of whitespace and braces. <code>for</code> and <code>if</code> statments should have a space between the keyword, parentheses, and opening brace (if using K&R style braces). Also, don't omit braces in an <code... | {
"AcceptedAnswerId": "58334",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T20:04:48.157",
"Id": "55064",
"Score": "6",
"Tags": [
"c++",
"algorithm",
"strings",
"c++11"
],
"Title": "String matching algorithm"
} | 55064 |
<p>I wrote the following code using Ruby to compute item-based <a href="http://en.wikipedia.org/wiki/Collaborative_filtering">collaborative filtering</a> (using <a href="http://en.wikipedia.org/wiki/Jaccard_index">Jaccard coefficient of similarity</a>). </p>
<p>I would appreciate feedback about any potential issues wi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T01:48:18.310",
"Id": "96403",
"Score": "0",
"body": "Please provide the actual hash passed to the method. The data in your question is a) a JSON string, and b) indexed by user. Unless I'm mistaken, the method operates on the inverse... | [
{
"body": "<p>Stuff I noticed:</p>\n\n<ul>\n<li><p>Use <code>next</code> to skip an <code>each</code>-iteration instead of wrapping everything in an <code>if</code> statement</p></li>\n<li><p>No need for <code>Set</code>. A hash's keys are already a set, so in your <code>compute_jaccard_coefficients</code> meth... | {
"AcceptedAnswerId": "55218",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T22:14:29.427",
"Id": "55070",
"Score": "6",
"Tags": [
"ruby",
"clustering"
],
"Title": "Item-based collaborative filtering"
} | 55070 |
<p>Here is a Tic Tac Toe game in C++ that I have been working on. My questions are as follows:</p>
<ol>
<li><p>I tested it for bugs, but if you find any, please post the solution!</p></li>
<li><p>I want to make the code more recursive, in a sense. Instead of having multiple lines of code that do the same things with d... | [] | [
{
"body": "<p>The most obvious improvement will come from the <code>check_for_overlap</code> function. You can replace your entire implementation with:</p>\n\n<pre><code>int check_for_overlap(int pos1, int pos2, char playerPiece)\n{\n if (board[pos1-1][pos2-1] != '-'){\n std::cout << \"\\nOVERLA... | {
"AcceptedAnswerId": "55076",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T23:54:53.640",
"Id": "55074",
"Score": "5",
"Tags": [
"c++",
"recursion",
"tic-tac-toe"
],
"Title": "Making this Tic Tac Toe implementation more recursive"
} | 55074 |
<p>I've been working on ubuntu since many years but not quite familiar with bash scripting. My development tools involve servers like nginx and apache, the mysql database and beanstalkd. Obviously, I just can't keep all these services running always and overwhelm my CPU capacity!, so I need a way of starting a bunch of... | [] | [
{
"body": "<p>Addressed below are purely coding problems. </p>\n\n<ul>\n<li><p>Do not spell out same path many times. Define it once (e.g. <code>NGINX=/home/prahlad/programs/nginx-1.6.0/sbin/nginx</code>), and refer to it as necessay (e.g. <code>$NGINX</code>)</p></li>\n<li><p>Error message in <code>docmd</code... | {
"AcceptedAnswerId": "56258",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T02:18:44.060",
"Id": "55077",
"Score": "6",
"Tags": [
"bash",
"linux",
"unix"
],
"Title": "Small bash script to start and stop named services"
} | 55077 |
<p>Using x64 assembly, I solved the <a href="http://projecteuler.net/problem=3">Largest Prime Factor</a> problem on Project Euler.</p>
<p>The problem is as follows:</p>
<blockquote>
<p>The prime factors of 13195 are 5, 7, 13 and 29.</p>
<p>What is the largest prime factor of the number 600851475143 ?</p>
</blo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T07:56:43.387",
"Id": "96435",
"Score": "2",
"body": "I would suggest you write your comments in pseudocode instead. As you describe WHAT the program does, do it in code instead of words. If you described WHY the program was writt... | [
{
"body": "<p>One optimisation that would make your code run up to twice as fast, is to use the observation that a prime factor of <code>n</code> cannot be greater than <code>n/2</code>. So you can limit the number of times you iterate through your loop.</p>\n\n<p>Additionally, you know that once you have teste... | {
"AcceptedAnswerId": "55081",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T02:35:24.087",
"Id": "55078",
"Score": "12",
"Tags": [
"beginner",
"primes",
"programming-challenge",
"assembly"
],
"Title": "x64 Assembly - checking for largest prime fact... | 55078 |
<p>I'd like some input on the way I've structured some things in a side-project I'm working on.</p>
<p>I declare an abstract class, <code>CelestialObj</code>, which will contain the common elements between <code>Planet</code>s, and <code>Moon</code>s (both of which I'd like to be derived from <code>CelestialObj</code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T07:54:01.733",
"Id": "96434",
"Score": "1",
"body": "I’m not sure whether this question might actually be a better fit for SO. It can be rephrased as: “Is having a sibling class as member dangerous?” or something like that, which so... | [
{
"body": "<p>There is no <em>dangerous</em> issue with that code. It would be even okay if you had a direct <code>Moon</code> member, instead of having a vector of Moons (this is worth noting, because with a vector (just as with a pointer), the actual Moon object is not in the same memory region as the Planet ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T05:40:41.410",
"Id": "55082",
"Score": "5",
"Tags": [
"c++",
"inheritance"
],
"Title": "Cons of declaring derived class type member in another derived class (both of which share the s... | 55082 |
<p>I used Python to write the following program: </p>
<pre><code>"""
A desired equation includes a 4-digit integer multiplied with a single-digit integer
to give another 4-digit integer and all 9 digits(1-9) are used in the equation.
"""
import random
found=False
while not found:
full_range=range(1,10)
fou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T02:35:44.570",
"Id": "97114",
"Score": "0",
"body": "Without getting into the math (because I don't do math). \n\n\nfour_digit_num=\"\"\nmultiple=\"\" \nrefactors to four_digit_num=multiple=\"\""
}
] | [
{
"body": "<p>What about simple brute force?</p>\n\n<pre><code>def check(i, j, c):\n istr = list(str(i))\n cstr = list(str(c))\n if \"0\" in istr: istr.remove(\"0\")\n if \"0\" in cstr: cstr.remove(\"0\")\n Jval = [\"%d\"%j]\n Set_String = set(istr + cstr + Jval)\n return len(Set_String) ==... | {
"AcceptedAnswerId": "55094",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T05:52:14.857",
"Id": "55083",
"Score": "2",
"Tags": [
"python"
],
"Title": "Find an equation that uses all 9 digits (1-9)"
} | 55083 |
<p>I am purely new to C++ memory management. Am I on the right path, or should I employ a different design strategy or a different memory manager policy (such as <code>weak_ptr</code>)?</p>
<pre><code>#include <mutex>
#include <assert.h>
#include <iostream>
#include <unordered_map>
#include &l... | [] | [
{
"body": "<p>Just a note to your mutex usage:</p>\n\n<p>You have to be careful to make sure you always unlock your mutex on any code path otherwise you run into the danger of locking your cache forever potentially causing deadlocks which will be hard to track down.</p>\n\n<p>Right now you have forgotten to unl... | {
"AcceptedAnswerId": "55093",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T06:29:44.353",
"Id": "55084",
"Score": "4",
"Tags": [
"c++",
"beginner",
"multithreading",
"c++11",
"cache"
],
"Title": "Creating a cache manager"
} | 55084 |
<p>I would like some feedback on a Java program which implements the Sieve of Eratosthenes to find prime numbers. Some of the 'features' I've included in the program include:</p>
<p>It uses a <code>BitSet</code> for identifying primes. What really gets checked is whether the index of any bit is prime. This eliminat... | [] | [
{
"body": "<p>You seem to have implemented it correctly from a complexity point of view, which is good.</p>\n\n<p>I noticed a few things you could improve:</p>\n\n<ul>\n<li>Why would a <code>getTheMaxNumber</code> method return a <code>String</code>? Why is the string called <code>name</code>?</li>\n<li>You hav... | {
"AcceptedAnswerId": "55088",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T06:43:44.433",
"Id": "55086",
"Score": "5",
"Tags": [
"java",
"primes",
"sieve-of-eratosthenes"
],
"Title": "Submitting a Java program which implements the Sieve of Eratosthene... | 55086 |
<p>Can someone let me know if this is a proper (and efficient) way of doing it? It works, but I wanted to understand if there's a way it be made better (I can use a for loop for the clones, but my browser gets stuck if I do it).</p>
<p><a href="http://jsfiddle.net/4ksxw/" rel="nofollow">Here's the fiddle</a></p>
<pre... | [] | [
{
"body": "<p>I think not, this is how it is meant to be.</p>\n\n<p>That being said, you</p>\n\n<ul>\n<li>Have a few missing semicolons</li>\n<li>Capture <code>c1</code> & <code>c2</code> for no good reason</li>\n<li>Calculate <code>secAngle</code> for no good reason</li>\n<li>Have a veritable legion of har... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T07:07:26.617",
"Id": "55092",
"Score": "3",
"Tags": [
"javascript",
"raphael.js"
],
"Title": "Is there a more efficient way of implementing this clock in Raphael JS?"
} | 55092 |
<pre><code>package standardcalculator;
/**
*
* @author BSK
*/
public class calculator2 extends javax.swing.JFrame {
private String input="";//We have nothing to display on the screen,if we dont do this creates the problem of displaying the null.
private String firstOperand="0"; //Standard firstOperand.
pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T16:46:23.787",
"Id": "96577",
"Score": "0",
"body": "Would you consider using Java 8? Just for my suggestions..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T16:52:08.127",
"Id": "96580",
"... | [
{
"body": "<p><strong>Step 1 :</strong> Reduce different event handlers which performs almost same task. </p>\n\n<p><strong>How:</strong></p>\n\n<p><strong>Step 1.1:</strong> The button click events (button1ActionPerformed and similar others) which are calling the commonAction method, delete all except 1 method... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T08:18:50.720",
"Id": "55097",
"Score": "3",
"Tags": [
"java",
"beginner",
"algorithm",
"calculator"
],
"Title": "Is this code for a calculator efficient?"
} | 55097 |
<p>I am generating a random numerical 6-10 digit password. I need some important reviews of yours. Is it OK or are there some needed modifications?</p>
<pre><code>val AB = "0123456789669900"
val rnd = new Random()
def randomNumericalString(): String = {
val len = rnd.nextInt(5) + 5
val sb = new StringBuilder... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T09:32:12.840",
"Id": "96447",
"Score": "1",
"body": "Does it have to be numerical? For safety issue's I don't recommand that(bruteforce on int pw's goes very fast). If not => scala has also : `nextString(length: Int)`"
},
{
... | [
{
"body": "<p>Your algorithm makes the probabilities of some numbers much higher than other numbers. Is this intentional? For example, 0 will appear 3 times as often as 1. It would be better to simply have the input string <code>\"0123456789\"</code> and have the uniform distribution.</p>\n\n<p>The range you su... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T09:05:42.200",
"Id": "55098",
"Score": "4",
"Tags": [
"scala",
"random"
],
"Title": "Random 6 to 10 digits number"
} | 55098 |
<h1>This is a continuation of <a href="https://codereview.stackexchange.com/questions/54986/platform-independant-thread-pool-v3">this</a> question.</h1>
<p>Following the previous advise, the thread pool now can handle almost all types of input, except for one key form, where the function/functor requires one of its ar... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T09:14:48.823",
"Id": "97157",
"Score": "0",
"body": "Why do you use a `static_cast` here? `static_cast<task_package *>(package_ptr.get())`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T09:25:31.347"... | [
{
"body": "<p>I would make the overriding behaviour explicit in <code>task_package_impl</code> by adding the <a href=\"http://en.cppreference.com/w/cpp/language/override\" rel=\"nofollow\"><code>override</code> specifier</a> to <code>run</code> and <code>set_exception</code>:</p>\n\n<pre><code>virtual void run(... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T09:18:02.953",
"Id": "55100",
"Score": "9",
"Tags": [
"c++",
"multithreading",
"reinventing-the-wheel",
"c++14"
],
"Title": "Platform independant thread pool v4"
} | 55100 |
<p>This is a client module of an Eclipse plugin. I am planning to use this code as a "good exception handling" code example in one of my papers. How does it look?</p>
<pre><code>HttpURLConnection httpconn=null;
BufferedReader breader=null;
try{
URL url=new URL(this.web_service_url);
httpconn=(HttpURLConnec... | [] | [
{
"body": "<h1>General</h1>\n<p>As example code, there is a fair amount to comment on. For an eclipse plugin, I would at least expect you to select-all and <kbd>Ctrl</kbd>-<kbd>Shift</kbd>-<kbd>F</kbd> ....</p>\n<ol>\n<li>consistent use of braces (on the end of the line, not start of the new line)</li>\n<li>con... | {
"AcceptedAnswerId": "55118",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T09:26:39.860",
"Id": "55101",
"Score": "3",
"Tags": [
"java",
"error-handling",
"http",
"eclipse"
],
"Title": "JSON fetcher for Eclipse plugin"
} | 55101 |
<p>In my (c#) code, I need to generate a string (from a longer string) which when UTF-8 encoded, is no longer than a given max length (in bytes).</p>
<pre><code> public static string OfMaxBytes(this string str, int maxByteLength)
{
return str.Aggregate("", (s, c) =>
{
if (Encoding... | [] | [
{
"body": "<p>It depends what you mean by correct. Consider this program:</p>\n\n<pre><code>const string Input = \"a\\u0304\\u0308bc\\u0327\";\nvar bytes = Encoding.UTF8.GetByteCount(Input);\nConsole.WriteLine(\"{0} ({1} bytes in UTF-8)\", Input, bytes);\nfor (var i = 0; i <= bytes; i++)\n{\n var result =... | {
"AcceptedAnswerId": "55114",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T09:41:35.247",
"Id": "55103",
"Score": "7",
"Tags": [
"c#",
"strings",
"utf-8"
],
"Title": "Method to return a string of max length (in bytes vs. characters)"
} | 55103 |
<p>I am following up on <a href="https://stackoverflow.com/a/16447514/315711">this answer</a> for a scenario that I am currently working on. Like the OP, I am too concerned about the longevity of the code.</p>
<pre><code>public IQueryable<TEntity> EmptyEnumerable()
{
return Enumerable.Empty<TEntity>().... | [] | [
{
"body": "<p>I guess that you're assuming that the MethodCall expression should be a call to Queryable.Where(...) ?</p>\n\n<ol>\n<li><p>You should check that explicitly via something like :</p>\n\n<pre><code>// yea, that's ugly. But that's for the demo. \n// I'm pretty sure you'll find the proper way to get ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T10:12:47.170",
"Id": "55108",
"Score": "4",
"Tags": [
"c#",
"api"
],
"Title": "Parsing ODataQueryOptions<T> to Expression<Func<T, bool>>"
} | 55108 |
<p>Problem is <a href="http://www.talentbuddy.co/challenge/5233cc274af0110af382f4105233cc274af0110af382f40e" rel="nofollow noreferrer">Talent Buddy</a>.</p>
<p>Your task is to</p>
<blockquote>
<ul>
<li>write a function that prints to the standard output (stdout) for each query the user name that matches the query... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T13:13:23.400",
"Id": "96487",
"Score": "2",
"body": "Not sure if this can help you but there is another question about this problem in Python too : http://codereview.stackexchange.com/questions/54480/typeahead-autocomplete-functiona... | [
{
"body": "<pre><code>def typeahead(usernames, queries):\n from bisect import bisect_left\n wordlist=sorted(usernames,key=str.lower)\n l_wordlist=map(str.lower,wordlist)\n for i in queries:\n word_fragment=i.lower()\n x=bisect_left(l_wordlist, word_fragment)\n ... | {
"AcceptedAnswerId": "55676",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T12:23:48.077",
"Id": "55120",
"Score": "3",
"Tags": [
"python",
"optimization",
"performance",
"programming-challenge",
"search"
],
"Title": "Typeahead Talent Buddy"
} | 55120 |
<p>This is the first time using a class. Please review this and tell me if it's secure and if it's the right way to do it. The code itself is working, but I have doubts in the way I used all this.</p>
<pre><code>// register.php
<?php
...
$db_password = $hash = password_hash($pass, PASSWORD_BCRYPT, array("cost" =&g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T12:55:53.947",
"Id": "96484",
"Score": "0",
"body": "`$pass = strip_tags($pass);` => This invalidates passwords like `eSD<eV3>u`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T13:45:01.040",
"Id"... | [
{
"body": "<ul>\n<li><p>Your class manages Users. Its job is to handle users. So connecting to a database is not its job! Inject the database connection to the class like so:</p>\n\n<pre><code>public function __construct(\\PDO $connection) {\n</code></pre></li>\n<li><p>Return values from <code>__construct()</co... | {
"AcceptedAnswerId": "55133",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T12:40:10.077",
"Id": "55122",
"Score": "3",
"Tags": [
"php",
"object-oriented",
"pdo",
"authentication"
],
"Title": "My first login class in PHP with PDO and bcrypt"
} | 55122 |
<p>I want to create a table that looks like this:</p>
<pre class="lang-none prettyprint-override"><code>--------------------------------------------------
| | USD |CAD |
--------------------------------------------------
|Smallest Donation | 100 |250 |
-------... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T14:52:51.887",
"Id": "96483",
"Score": "0",
"body": "i dont think condensing everything to one loop will make things run that much faster - looks like what you are doing is good."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>I rewrite in my style with only loop. It maybe easier to read.</p>\n\n<pre><code>perCurrency = {\n USD: { 0:100, 1:200, 2:9200, 3:1500, 4:1500 },\n CAD: { 0:250, 1:7600, 2:150, 3:3000 }\n};\nvar numOfCurrency = Object.keys(perCurrency).length + 1;\nvar donation_table;\ndonation_table = $('<ta... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-23T14:48:05.747",
"Id": "55124",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Dynamically create a table with values from an object"
} | 55124 |
<p>I have a Unit of Work / Repository pattern in place to abstract away some <code>nHibernate</code>. Most examples I've seen though use the pattern a little differently.</p>
<p>In particular, in the constructor for <code>UnitOfWork</code>, most examples start the transaction immediately and have one transaction per u... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T03:58:05.267",
"Id": "97851",
"Score": "0",
"body": "I don't see any benefit to having the ReadRepository and WriteRepository properties on an IReadWriteRepository."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | [
{
"body": "<blockquote>\n <p>Is there a reason why others instantiate their transaction per unit of work?</p>\n</blockquote>\n\n<p>Yes, this is because more often than not, a unit of work is a single transaction, either it's committed, or it's not.</p>\n\n<p>Committing part of the work and not other parts, is ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T13:29:40.610",
"Id": "55127",
"Score": "6",
"Tags": [
"c#",
"design-patterns",
"repository"
],
"Title": "Unit of Work / Repository nHibernate"
} | 55127 |
<p>There have been a number of questions asking for comments on code for the <a href="http://projecteuler.net/problem=3">Project Euler problem</a> to compute the largest prime factor of a number. A primary intent of this task is to find the factor as quickly as possible.</p>
<p>I decided to implement the code in C++ u... | [] | [
{
"body": "<p>The sieve can be optimized by concentrating on eliminating only multiples of odd numbers.</p>\n\n<p>So you can step by 2, and in the inner loop, every multiple up to the prime squared is already eliminated, so it can start there. Since that will be an odd multiple and all the even multiples have ... | {
"AcceptedAnswerId": "55162",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T13:29:47.850",
"Id": "55128",
"Score": "9",
"Tags": [
"c++",
"primes",
"programming-challenge"
],
"Title": "Largest Prime Factor redux"
} | 55128 |
<p>I started improving my validator library even more, and I think I'm at the last final element (domain object / entity validations) before I can gladly say that my Validator library is completely done and it supports all of it.</p>
<p><a href="https://codereview.stackexchange.com/q/54799/39625">Here</a> you can see ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T14:19:04.013",
"Id": "96516",
"Score": "0",
"body": "I think it's a bit of an overkill to have whole objects for `Alpha` or `Numeric`, don't you?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T14:43... | [
{
"body": "<p>Coding-wise it looks pretty good. Consistent naming convention and code style, no apparent security vulnerabilities (assuming your Rule classes do what I expect them to do).</p>\n\n<p>Let's talk about approach and scale.</p>\n\n<h2>Scale</h2>\n\n<p>It doesn't really make sense for you to write a v... | {
"AcceptedAnswerId": "55310",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T13:42:24.067",
"Id": "55130",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"validation"
],
"Title": "Validator extended to handle domain objects / entities"
} | 55130 |
<p>First project in Dart - looking for style tips. I feel like I'm writing it a bit like Java, and would like to learn how to write dart-y dart. </p>
<p>Also - what's the convention on multiple files in a project? There are other files in this project, and I do not know how to include them in each other, etc...</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T14:00:25.167",
"Id": "96507",
"Score": "0",
"body": "I believe one of the main goals of dart is to look more like Java than javascript, so you should probably not worry about your code looking too much like Java."
},
{
"Cont... | [
{
"body": "<p>Very clean Dart code! Just a couple of (minor) styling issues issues I can see:</p>\n<h1>Screaming caps</h1>\n<p>In the <a href=\"https://www.dartlang.org/guides/language/effective-dart/style#prefer-using-lowercamelcase-for-constant-names\" rel=\"nofollow noreferrer\">Effective Dart: Style</a> gui... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T13:46:46.347",
"Id": "55131",
"Score": "5",
"Tags": [
"game",
"snake-game",
"dart"
],
"Title": "Snake Game in Dart"
} | 55131 |
<p>Some might not think it's worth asking but I consider good function names quite important. I am not sure what should be the overridable function name in what I think is template design pattern. I am printing a report which has 3 types. There are lots of <code>if</code>-<code>else</code> which is confusing. I replace... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T15:19:02.373",
"Id": "96549",
"Score": "1",
"body": "I think you'd find that most of us find that good names are extremely important. =)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T00:12:38.527",
... | [
{
"body": "<p>How about calling your method <code>PrintSpecializedReportData</code> and call your subclasses <code>CPrintVerificationReport</code> and <code>CPrintIdentificationReport</code>?</p>\n\n<p>Also, rename <code>PrintCommon</code> to <code>PrintCommonData</code>.</p>\n\n<p>And remove the comments that ... | {
"AcceptedAnswerId": "55228",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T14:01:58.740",
"Id": "55132",
"Score": "2",
"Tags": [
"c++",
"design-patterns",
"template"
],
"Title": "Naming a template print method properly"
} | 55132 |
<p>I've got the following code inside an integration test.</p>
<pre><code>[TestMethod]
public void Integration_GetUser_WithoutLoggingIn_ThrowsInvalidOperationException()
{
var myApi = new Api(new Session());
try
{
var irrelevant = myApi.GetUserInfoAsync().AsTask().Result;
}
catch (Aggregat... | [] | [
{
"body": "<blockquote>\n <p>I am blocking the call using <code>AsTask().Result</code>, is this the most appropriate method?</p>\n</blockquote>\n\n<p>Can't you use <code>await</code>? Most testing frameworks (<a href=\"https://stackoverflow.com/a/10736873/41071\">apparently including MSTest</a>) support <code>... | {
"AcceptedAnswerId": "55154",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T14:13:03.070",
"Id": "55135",
"Score": "15",
"Tags": [
"c#",
"unit-testing",
"exception-handling",
"asynchronous",
"windows-runtime"
],
"Title": "Verifying the type of ... | 55135 |
<p>Windows Runtime (WinRT) is a Microsoft platform architecture that allows applications to run in a sandboxed environment exposing a <em>Windows Modern Style</em> UI/UX (previously known by it's codename 'Metro', see <a href="/questions/tagged/microsoft-metro" class="post-tag" title="show questions tagged 'microso... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T14:14:13.863",
"Id": "55136",
"Score": "0",
"Tags": null,
"Title": null
} | 55136 |
Windows Runtime (WinRT) is a Microsoft platform architecture that allows applications to run in a sandboxed environment exposing a 'Windows Modern Style' UI/UX.
Not to be confused with Windows RT, the edition of Windows 8 for ARM devices; see windows-rt. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T14:14:13.863",
"Id": "55137",
"Score": "0",
"Tags": null,
"Title": null
} | 55137 |
<p>I built a simple class to handle skill increases for the workers in a strategy game for iOS. The basic idea is that whenever a worker finishes a job, their skill (which starts at 0) will increase by 1. Whenever the skill reaches a multiple of 10, this increases the skill multiplier by 0.10. This multiplier is mul... | [] | [
{
"body": "<p><strong>Lots of duplicated code</strong></p>\n\n<p>You have 7 methods like <code>-(void) skillUpMining;</code>. They all do the same thing - increment a variable. Why not write one method that takes an argument specifying <em>which</em> skill to tweak? Keep 1 copy of the code, not 7 copies. The... | {
"AcceptedAnswerId": "55174",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T14:23:11.527",
"Id": "55139",
"Score": "6",
"Tags": [
"object-oriented",
"game",
"objective-c",
"simulation"
],
"Title": "Skill Upgrades for Strategy Game"
} | 55139 |
<p>I'm trying to design an API.NET for some communication purposes with Testing Equipment and I cannot figure out a proper way for designing the architecture.</p>
<p>Basically, we have different (physical) products:</p>
<ul>
<li><p>A Controller to perform measurement on channel inputs (e.g. Current, Voltage, Frequency,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T17:54:01.220",
"Id": "96602",
"Score": "0",
"body": "\"Let's start with Message Class, with the virtual calls in the constructor\" I don't see a constructor"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-0... | [
{
"body": "<p>I focused on some smaller issues, not really on the problems you mentioned (I'm not sure those have simple solutions).</p>\n\n<hr>\n\n<pre><code>private const String _separatorIdKeyword = \"_\";\nprotected String SeparatorIdKeyword\n{\n get\n {\n return Message<TDeviceId, TDeviceMe... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-06-24T15:47:14.613",
"Id": "55144",
"Score": "5",
"Tags": [
"c#",
"design-patterns",
"generics"
],
"Title": "Message Based Communication Design"
} | 55144 |
<p>The problem I am talking about is <a href="http://codingbat.com/prob/p196409" rel="nofollow">this</a>:</p>
<blockquote>
<p>We'll say that a "mirror" section in an array is a group of contiguous
elements such that somewhere in the array, the same group appears in
reverse order. For example, the largest mirror ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T07:45:04.870",
"Id": "96748",
"Score": "1",
"body": "As your code has already been reviewed, I would just like to propose another solution: to find the longest common \"substring\" of the array and its reversal. Finding this by dyna... | [
{
"body": "<p><strong>Readibility</strong></p>\n\n<p>Whitespaces are free and make things easier to read. Also, you do not need that many parenthesis.</p>\n\n<p>Also, indentation seems a bit weird. After fixing this, here is what I have :</p>\n\n<pre><code>public class MaxMirror {\n\n public static int maxMi... | {
"AcceptedAnswerId": "55148",
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T15:48:52.280",
"Id": "55145",
"Score": "7",
"Tags": [
"java",
"programming-challenge",
"palindrome"
],
"Title": "Finding the largest mirror image of a subset/set of integers p... | 55145 |
<p>Is it considered bad style to have that <code>BOTH</code> value in the Direction <code>enum</code>? Problems can arise from <code>BOTH</code> being present, for example when trying to build a procedural UI for the Car class, it (the generator) would see the <code>setTurnSignal(Direction)</code> method and create a w... | [] | [
{
"body": "<p>The problem here is that your class is not symmetrical.</p>\n\n<p>If you gave a 'getter' that can return Direction.BOTH (when <code>hazards == true</code>), then you should have a matching 'setter'.</p>\n\n<p>In your class, I imagine you have a setHazards, as well as the method <code>setTurnSignal... | {
"AcceptedAnswerId": "55158",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T16:34:13.880",
"Id": "55147",
"Score": "9",
"Tags": [
"java",
"enum"
],
"Title": "An enum that has situationally invalid entries"
} | 55147 |
<p>I've written the following code to get all <code>.txt</code> files in a directory and read+delete them, repeating every 15 seconds.</p>
<pre><code>var fs = require("fs");
var path = require("path");
var Q = require("q");
var dir = "stuff";
var analyseFile = function(fileData, callback) { ... }; // Not important.
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T18:46:24.563",
"Id": "96609",
"Score": "2",
"body": "Looks fine, apart from the fact that any self-written functions (`analyseFile`, `deleteFile`) should return promises right away instead of taking callbacks."
}
] | [
{
"body": "<p>This is Bluebird, but it's very similar to Q in syntax. Note the automatic promisification and utility methods:</p>\n\n<pre><code>var Promise= require(\"bluebird\");\nvar fs = Promise.promisify(require(\"fs\"));\nvar path = require(\"path\");\n\nvar dir = \"stuff\";\n\nvar analyseFile = function(f... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T18:04:59.293",
"Id": "55159",
"Score": "2",
"Tags": [
"javascript",
"node.js",
"callback"
],
"Title": "Can this code utilizing promises be written more succinctly?"
} | 55159 |
<p>The following code is intended to parse a string of the following format and return whether the current time falls in that window:</p>
<pre><code>start_time-stop_time [(day|day-day[, ...])][; ...]
</code></pre>
<p>For example,</p>
<pre><code>0900-1200 (mon-wed, sat); 0100-0200 (sun, tue)
</code></pre>
<p>The cod... | [] | [
{
"body": "<h3>1. Bugs</h3>\n\n<ol>\n<li><p>Supposing that I want to specify an interval of time spanning midnight, for example starting at 23:00 on Monday and ending at 01:00 on Tuesday, how do I do it? The best I can do seems to be:</p>\n\n<pre><code>2300-2359 (mon); 0000-0100 (tue)\n</code></pre>\n\n<p>but t... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T18:44:14.183",
"Id": "55161",
"Score": "4",
"Tags": [
"python",
"strings",
"parsing",
"datetime"
],
"Title": "Parsing time ranges with PyParsing"
} | 55161 |
<p>I am trying to implement an infix to postfix conversion program using stacks. I have actually have done it successfully, but I'm uncertain about the complexity of the logic that I used for the priority checking.</p>
<pre><code>int hasLowerPriority(char ch,char ch2)
{
int num=0,num2=0;
if(ch=='+'||ch=='-')
... | [] | [
{
"body": "<p>There is duplicated code that can be removed.</p>\n\n<pre><code>static int precedence(char operator) {\n switch (operator) {\n case '*': case '/':\n return 2;\n case '+': case '-':\n return 1;\n default:\n return 0;\n }\n}\n\nint hasLowerPriority(char oper... | {
"AcceptedAnswerId": "55206",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T20:06:34.433",
"Id": "55165",
"Score": "2",
"Tags": [
"c"
],
"Title": "Priority checker for infix-to-postfix converter"
} | 55165 |
<p>I find the default Javascript extremely poor on useful functions. There are some nice libraries, but somehow I always need something I can't find. Currently, I'd need a method removing all matching properties from an object. And I really mean removing, not creating a <a href="https://stackoverflow.com/a/19316873/581... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T21:29:52.420",
"Id": "96627",
"Score": "0",
"body": "So, you're not asking about coding style or speed. What exactly do you want feedback on? There are no problems iterating or deleting properties in any browser. `Object.definePr... | [
{
"body": "<p>There are extraneous semicolons (null statements) in your code. Semicolons do not belong after function declarations and <code>for</code> loops.</p>\n\n<blockquote>\n <p>I'm extending the <code>Object.prototype</code> which should be fine.</p>\n</blockquote>\n\n<p>I would argue that it's not fine... | {
"AcceptedAnswerId": "55172",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T20:09:39.490",
"Id": "55166",
"Score": "4",
"Tags": [
"javascript",
"prototypal-class-design"
],
"Title": "Extending Object.prototype in JavaScript"
} | 55166 |
<p>Is there a better method for covering errors in my case? I am looking for best practice for now and future instances.</p>
<p>Foreseen errors that could arise:</p>
<ul>
<li>No attributes at all</li>
<li>Some attributes could be missing</li>
<li>Attribute value could be empty</li>
</ul>
<hr>
<pre><code>// converti... | [] | [
{
"body": "<p>I think it is cleaner to handle special cases early; your code winds up less indented.</p>\n\n<pre><code>// converting dom into array to use later\n$fields = $dom->getElementsByTagName($field);\n$arr['field'] = array();\n\nforeach ($fields as $field) {\n $attributes = isset($field->attribut... | {
"AcceptedAnswerId": "55168",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T20:10:44.457",
"Id": "55167",
"Score": "4",
"Tags": [
"php",
"error-handling"
],
"Title": "Checking empty object"
} | 55167 |
<p>I am a newbie and tried to find the laziest way to do a file upload using EmberJS, jQuery and formdata (IE10+). The code might look stupid, but it worked.</p>
<p>Can you please take a look and give some suggestions? Am I doing it wrong?</p>
<pre><code><script type="text/x-handlebars" data-template-name="posts"... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T20:28:21.677",
"Id": "55169",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html",
"ajax",
"ember.js"
],
"Title": "Ember.js file upload code"
} | 55169 |
<p>I wanted to share this and get some feedback. My goal was to be able to have an object with methods:</p>
<blockquote>
<pre><code>class Thing(object):
def __init__(self, data=123):
self.data = data
def add_one(self):
self.data += 1
def add_number(self, number):
self.data += num... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-12-18T22:44:06.080",
"Id": "212060",
"Score": "0",
"body": "It is probably a mistake to use an inheritance relationship between `Thing` and `MetaThing` in the first place. It's a \"`MetaThing` contains `Thing`s\" relationship, not a \"`M... | [
{
"body": "<p>Another way to do this would be to use <code>__getattr__()</code>.</p>\n\n<pre><code>class Wraps(object):\n def __init__(self, *args):\n self.things = args\n def __getattr__(self, item):\n def each(*args, **kwargs):\n for thing in self.things:\n getattr(thing, item)(*args, **kw... | {
"AcceptedAnswerId": "55173",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T20:50:35.350",
"Id": "55171",
"Score": "2",
"Tags": [
"python",
"inheritance",
"meta-programming"
],
"Title": "Using a decorator to apply an inherited method to all child objec... | 55171 |
<p>Im trying to draw a lot of fields image for my world generation, all is perfect 64 fps, but if i began to draw all the time the grass it became laggy, like 59 fps (something that musn't happen! :( ), i need help and some tricks to draw things in c# with more optimization :)</p>
<pre><code>int loadedChunks = 0;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T02:36:05.900",
"Id": "96641",
"Score": "0",
"body": "That's not a lot of code to go on. It looks like you can lift `xChunk * sizeChunk + CameraX` and `yChunk * sizeChunk + CameraY` out of the loop, however."
},
{
"ContentLic... | [
{
"body": "<h1>Naming</h1>\n\n<p>What is the difference between <code>xChunk</code> and <code>chunkX</code>? <code>yChunk</code> and <code>chunkY</code>? Choose names that will help, not hinder you.</p>\n\n<p>Don't skimp on letters. <code>size</code> is better than <code>siz</code>, <code>point</code> is better... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T02:20:40.250",
"Id": "55180",
"Score": "1",
"Tags": [
"c#",
"optimization",
"animation"
],
"Title": "Drawing multiple Images"
} | 55180 |
<p>Here's my attempt at a script that will take user input and produce a custom interactive eBay listing. This is definitely still in progress, but I wanted to post the code I have since I'm sure there will be awesome suggestions on how I can improve functionality and write less.</p>
<p><a href="http://jsfiddle.net/28... | [] | [
{
"body": "<p>TL;DR: Take a look at <a href=\"http://gruntjs.com/\" rel=\"nofollow noreferrer\">Grunt</a></p>\n<hr />\n<h1>Important points when writing code</h1>\n<p>Take a vacation for 2 weeks and after that, try editing that code. I bet you wouldn't feel as good as you did when you originally wrote that. Her... | {
"AcceptedAnswerId": "55576",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T04:06:31.070",
"Id": "55185",
"Score": "2",
"Tags": [
"javascript",
"beginner",
"jquery",
"ebay"
],
"Title": "eBay listing generator"
} | 55185 |
<p>play framework follows the model–view–controller (MVC) architectural pattern. It aims to optimize developer productivity by using convention over configuration, hot code reloading and display of errors in the browser.<br>
Support for the Scala programming language has been available since version 1.1 of the fra... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T04:20:40.713",
"Id": "55186",
"Score": "0",
"Tags": null,
"Title": null
} | 55186 |
Play is an open source web application framework, written in Scala and Java. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T04:20:40.713",
"Id": "55187",
"Score": "0",
"Tags": null,
"Title": null
} | 55187 |
<p>I need to assign a number to each <code>userId</code>. I think this is too much of a query for updating. Is it possible to reduce the number of queries, or is it okay?</p>
<pre><code>def newRanking(groupId: String) = {
DB.withConnection { implicit con =>
var rank: List[Int] = util.Random.shuffle(List... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T14:31:05.617",
"Id": "96705",
"Score": "1",
"body": "You already asked essentially the same question about putting SQL queries in a loop here: http://codereview.stackexchange.com/questions/54783/multiple-sql-anorm-query-in-scala-pla... | [
{
"body": "<p>As I'm sure you've noticed, executing any SQL query in a loop is a bad idea. It would be much better to formulate a statement that accomplishes the entire batch of changes at once.</p>\n\n<p>To achieve that goal, you'll need to combine several ideas:</p>\n\n<ul>\n<li><p>Shuffling using <a href=\"... | {
"AcceptedAnswerId": "55202",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T07:27:26.693",
"Id": "55194",
"Score": "0",
"Tags": [
"mysql",
"scala",
"shuffle"
],
"Title": "Updating MySQL with shuffled numbers between 1 and 50"
} | 55194 |
<p>I'm a new programmer, so any help is welcome. Preferably to make it faster, avoid heavy memory usage, and so on.</p>
<pre><code>#! /usr/bin/env python
"""
This module is a frame work for a Genetic Algorithm.
:param GenePool: See this documentation for how to use this module..
:type GenePool: GenePool
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T09:56:34.990",
"Id": "96672",
"Score": "1",
"body": "Is there a specific performance issue you've noticed? Have you tried anything to make it faster and/or reduce memory footprint? Any profiling? Do you have an example we can run?"
... | [
{
"body": "<p>One thing you should do is not place code you always want run at the lowest level in the file, you should place it in a function called <code>main()</code> and call <code>main()</code> with <code>if __name__ == \"__main__\":</code>. This will help you when you start creating modules and importing... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T08:21:53.637",
"Id": "55197",
"Score": "8",
"Tags": [
"python",
"algorithm",
"beginner",
"ai",
"bioinformatics"
],
"Title": "Genetic Algorithm in Python"
} | 55197 |
<p>I am trying a very simple method of getting the theme information via a theme.xml within each theme folder.</p>
<p><strong>What it should do:</strong></p>
<ul>
<li>Scan the theme directory ../themes</li>
<li>Return the names of all the theme folders (array)</li>
<li>Use the name of the theme folder returned to cre... | [] | [
{
"body": "<p>Yes you can move the output away from the code, however that's usually difficult to do with this type of procedural code. The code is extremely tightly bound, which makes separation harder than it should be!</p>\n\n<p>The two function you call are fine as they are. So lets focus on those for now.<... | {
"AcceptedAnswerId": "57606",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T08:58:13.757",
"Id": "55200",
"Score": "6",
"Tags": [
"php",
"xml"
],
"Title": "Themed Folder Classification"
} | 55200 |
<p><a href="/questions/tagged/playframework" class="post-tag" title="show questions tagged 'playframework'" rel="tag">playframework</a> includes a simple data access layer called Anorm ("<b>A</b>norm is <b>N</b>ot an <b>O</b>bject <b>R</b>elational <b>M</b>apper") that uses plain <a href="/questions/tagged/sql"... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T09:08:01.900",
"Id": "55203",
"Score": "0",
"Tags": null,
"Title": null
} | 55203 |
Anorm is a simple data access layer included in the Play Framework. It uses plain SQL to interact with the database and provides an API to parse and transform the resulting datasets. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T09:08:01.900",
"Id": "55204",
"Score": "0",
"Tags": null,
"Title": null
} | 55204 |
<p>I believe I have made the following data class quite decently, and I'd like a thorough review on it.</p>
<p>The code is built on Java 8 and uses the Builder and Serialization Proxy pattern, it is used to store results from a web service call, and the only certainty I have is that the organization id will be an inte... | [] | [
{
"body": "<p>This code is begging for an EnumMap as the data store, rather than the individual variables.</p>\n\n<p>Creating an Enum with values like:</p>\n\n<pre><code>public enum OrganizationField {ACCOUNT_NUMBER, ZIP_CODE, ....};\n</code></pre>\n\n<p>In your Organization you would have:</p>\n\n<pre><code>pr... | {
"AcceptedAnswerId": "55214",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T09:14:19.003",
"Id": "55205",
"Score": "10",
"Tags": [
"java",
"null",
"serialization"
],
"Title": "Organization data class"
} | 55205 |
<p>I have the following MySQL query which selects product details and whether the viewing user likes them. I feel like it could be more efficient and that there is a more practical approach than using a sub-query here.</p>
<p>Any suggestions?</p>
<pre><code>SELECT p.*,
pm.filename AS thumbnail,
(SE... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T10:53:14.603",
"Id": "96678",
"Score": "1",
"body": "To make life easier for reviewers, please add sufficient context to your question. The more you tell us about what your query does and the schema of your database table(s), the ea... | [
{
"body": "<p>More important than the performance, your code is <strong>very likely vulnerable to SQL Injection.</strong> (I can't say for sure without looking at your PHP code)</p>\n\n<p>If <code>$viewingUserId</code> or <code>$userId</code> is chosen by the user <strong>in any way</strong>, then you have a pr... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T09:59:48.283",
"Id": "55211",
"Score": "4",
"Tags": [
"php",
"sql",
"mysql"
],
"Title": "Did you like my product?"
} | 55211 |
<p>I wrote this piece of code to make any breakpoint to the users choice:</p>
<pre><code>@mixin breakpoint($media) {
$max-width: 0;
@if($media == 'phones') {
$max-width: $phone-medium;
} @else if ($media == 'monitors') {
$max-width: $screen-medium;
//etc etc etc
} @else if($media > 0) {
$ma... | [] | [
{
"body": "<p>Personally, I think it's better to make the breaks according to the content of the site, rather than to a fixed size.</p>\n\n<p>This is even more true nowadays with docens of different screen sizes for each type of device.</p>\n\n<p>You should make sure the site will always look good by making the... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T10:19:45.300",
"Id": "55213",
"Score": "2",
"Tags": [
"css",
"sass"
],
"Title": "Checking screen sizes for responsive site"
} | 55213 |
<p>I'm working on a socket application that will listen to incoming messages from about 400 devices. They all send a message at least once per minute. Now I have a working program and it has been running for a few days without problems as a test with about 10 devices, but I keep thinking I missed something and it could... | [] | [
{
"body": "<p>I got a few comments on your code. First of all, try to separate your UI code from your backend code.</p>\n\n<p>You should be using the <code>using</code> statement here </p>\n\n<pre><code>private void HandleClientComm(object client)\n{ \n var tcpClient = (TcpClient)client;\n using(var clien... | {
"AcceptedAnswerId": "55232",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T11:02:48.420",
"Id": "55215",
"Score": "2",
"Tags": [
"c#",
"entity-framework",
"winforms",
"socket"
],
"Title": "Silent Try_catch in high load socket server or not?"
} | 55215 |
<p>Could this code:</p>
<pre><code>var a = new StringBuilder();
var b = new StringBuilder();
var kvps = new List<KeyValuePair<Guid, object>>
{
new KeyValuePair<Guid, object>(Guid.NewGuid(), 1),
new KeyValuePair<Guid, object>(Guid.NewGuid(), "hello")
};
for (var c = 0; c < kvps.Count;... | [] | [
{
"body": "<p>Performance here will only matter if the input List is large. There are two things that can be done to make the output loop faster:</p>\n\n<ol>\n<li><p>initialize the starting capacity of the StringBuilder to match your expectations of what size it will need to be.</p>\n\n<p>In this case, you know... | {
"AcceptedAnswerId": "55223",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T13:55:05.437",
"Id": "55220",
"Score": "3",
"Tags": [
"c#",
"performance"
],
"Title": "Generating 2 comma-separated lists from list of key value pairs"
} | 55220 |
<p>I've got a tab menu and functions that change the tab's color on click, giving the clicked tab a different color from the others. The thing is, when I click one, I give it another <code>background-color</code> easily but I'm also setting all the other tabs <code>background-color</code>.</p>
<p>In my largest menu th... | [] | [
{
"body": "<p>I would suggest changing your html and giving all the tags some class like 'tag', then you'll be able to do something like:</p>\n\n<pre><code><button id=\"tab1\" class=\"tab\" onClick=\"changeColor(this.id)\">B1</button>\n<button id=\"tab2\" class=\"tab\" onClick=\"changeColor(this.... | {
"AcceptedAnswerId": "55222",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T13:56:10.323",
"Id": "55221",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Changing a menu tab's color on click"
} | 55221 |
<p>I've written the following code:</p>
<pre><code>{- ...
...
... -}
data Ellipsoid
data Halfplane
data Intersection
data PointSet s a where
Halfplane :: RealFrac a =>
a -> a -> a -> (a -> a -> Bool) -> a ->
PointSet Halfplane a
Ellipsoid :: Rea... | [] | [
{
"body": "<p>The expression</p>\n\n<pre><code>and . map ($ x) . map ($ y) . map ($ z) . map test $ ps\n</code></pre>\n\n<p>contains several <code>map</code> calls connected with <code>.</code>. But since <code>map f . map g === map (f . g)</code>, we can simplify it as</p>\n\n<pre><code>and . map (($ x) . ($ y... | {
"AcceptedAnswerId": "55296",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T15:10:34.943",
"Id": "55231",
"Score": "3",
"Tags": [
"haskell"
],
"Title": "Simplification of consecutive `map`s"
} | 55231 |
<p>For many days, I've been re-designing my application, applying some custom pattern and making our code looks like a framework. I have something like this for separate the business logic, from views:</p>
<pre><code> if(file_exists($route . $urlpara[0] . ".template.php")){
require_once($route . $urlpara[0]... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T16:37:47.320",
"Id": "96742",
"Score": "3",
"body": "Hard to say: there's not enough code to see if there's a clear separation of responsibilities. There seems to be little or no communication going back and forth between an alleged... | [
{
"body": "<p>what you have posted is orthogonal to MVC. MVC deals with user interfaces. It has later been reshaped many times to fit various platforms such as the web but the original ideas came out of Xerox some forty years ago and tryed to bridge the gap between the user and the model in the computer (the M)... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T15:40:33.963",
"Id": "55234",
"Score": "4",
"Tags": [
"php",
"design-patterns",
"mvc",
"url-routing"
],
"Title": "Would this be considered MVC?"
} | 55234 |
<p>I have written below class to manage <code>Memcache</code> keys.</p>
<p>My <code>Memcache</code> keys structure are like:</p>
<ul>
<li><code>product_details_#{product_id}</code> => <code>product_details_2</code></li>
<li><code>designer_info_#{designer_id}_#{type}</code> => <code>designer_info_10_2</code></li>
</ul... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T15:44:10.673",
"Id": "55235",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails",
"meta-programming"
],
"Title": "Memcache Keys Management Class"
} | 55235 |
<p>I have the following Matlab function:</p>
<pre><code>function [res] = a3_funct(x)
res = 0;
for i = 1:size(x,1)
res = res + abs(x(i))^(i+1);
end
end
</code></pre>
<p>It's emulating this equation:</p>
<p>\$f(x) = \sum_{i=1}^{n}|x_i|^{i+1}\$</p>
<p>Here is an example use:</p>
<pre><code>>>... | [] | [
{
"body": "<p>Vectorized approach:</p>\n\n<pre><code>res = sum(abs(x(:).'.^(2:numel(x)+1)))\n</code></pre>\n\n<p>Read more about vectorization techniques <a href=\"http://www.mathworks.in/help/matlab/matlab_prog/vectorization.html\" rel=\"noreferrer\">here</a>.</p>\n\n<p>Thus, your function would look like this... | {
"AcceptedAnswerId": "55239",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T16:05:27.583",
"Id": "55236",
"Score": "5",
"Tags": [
"beginner",
"matlab",
"vectorization"
],
"Title": "Vectorize Matlab sum"
} | 55236 |
<p>I wrote this class which is comparing some values, how can I improve its performance and maybe make it prettier?</p>
<p>You can see at the bottom what type of data it requires, also the array size can reach 100 000 elements.</p>
<p>As it is the class is working fine, but I would like to get a second opinion on how... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T19:33:13.383",
"Id": "96796",
"Score": "0",
"body": "Minor thing: \"data\" is plural (the singular form is \"datum\"), so writing \"datas\" is like writing \"objectses\""
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>I'm not usually harsh, but this code is a buggy mess. Sorry.</p>\n\n<p>We don't review broken code on CodeReview, but I just can't help myself. As I said in a comment, this code is so broken that it actually ends up <em>almost</em> working correctly.</p>\n\n<p>Well, except for the fact that <code>... | {
"AcceptedAnswerId": "55274",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T16:20:23.667",
"Id": "55237",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails",
"datetime"
],
"Title": "Better way of comparing integers"
} | 55237 |
<p>I am looking to improve the following query. </p>
<p>We are using EF6 (CodeFirst) and C# Lambda Expressions, and Repository/Unit of Work patterns. Also, we needed to restrict the query in a way that we could inner-query the entities so that the query will only retrieve a subset of the joined data, and found this <a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T17:49:07.663",
"Id": "96763",
"Score": "0",
"body": "Welcome to Code Review! You *do* realize that Entity Framework's `DbContext` *is* a unit-of-work, right? `DbSet<T>` *is* a repository, too... why make an abstraction of an abstrac... | [
{
"body": "<p>You should replace some of your <code>Selects</code> for <code>SelectMany</code>. Normally IEnumerable extensions can be coded without nesting them, in your case if you replace your \"grupoAcesso\" selction by chaining <code>SelectManys</code> you could write this:</p>\n\n<pre><code>private IEnume... | {
"AcceptedAnswerId": "56279",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T16:56:40.783",
"Id": "55241",
"Score": "10",
"Tags": [
"c#",
"entity-framework",
"lambda"
],
"Title": "EF6-Lambda Expressions deep big-tree query"
} | 55241 |
<p>I'm extremely new to C++ and am doing the exercises on the book <em>Accelerated C++</em>. Here is one of the exercises:</p>
<blockquote>
<p><strong>4-5.</strong> Write a function that reads words from an input stream and stores
them in a vector. Use that function both to write programs that count
the number o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T18:27:44.127",
"Id": "96776",
"Score": "0",
"body": "Have you been tought how to use a `std::map<>` yet? If so that makes counting the words trivial."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T18... | [
{
"body": "<ul>\n<li><p>Minor inconsistency here:</p>\n\n<blockquote>\n<pre><code>#include<string>\n</code></pre>\n</blockquote>\n\n<p>Add a space in between them, like all the others:</p>\n\n<pre><code>#include <string>\n</code></pre></li>\n<li><p>Just get rid of this:</p>\n\n<blockquote>\n<pre><co... | {
"AcceptedAnswerId": "55245",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T17:22:01.137",
"Id": "55244",
"Score": "10",
"Tags": [
"c++",
"beginner",
"c++11",
"io",
"vectors"
],
"Title": "Storing words from an input stream into a vector"
} | 55244 |
<p>I want to read the content of file then want to make few updates to content and then write that content to another file. I have created the code with node.js as follows.</p>
<pre><code>var filePath = path.join('public/index.html'),
exactFileName = path.basename(filePath),
outputDir = "output/";
function rea... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>there is really not much to optimize from a speed perspective. From a code organization perspective you should really investigate libraries that help with asynchronous coding.</p>\n\n<p>From a pure coding perspective, <code>fs.mkdirSyn</code> will ignore the callbac... | {
"AcceptedAnswerId": "55361",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T18:10:15.077",
"Id": "55249",
"Score": "4",
"Tags": [
"javascript",
"node.js",
"file-system",
"io"
],
"Title": "Optimize way of reading and writing file in node.js"
} | 55249 |
<p>I'm rather new to Java and to algorithms in general. I implemented the so called <a href="http://en.wikipedia.org/wiki/Connected-component_labeling#Two-pass" rel="nofollow noreferrer">Two-pass algorithm</a>, and want to know if there are improvements to my way of implementing it. What it does is it takes a matrix of... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T08:50:40.050",
"Id": "96898",
"Score": "0",
"body": "Technically initialization of the matrix doesn't count as a pass, so I would move `//First pass` to the beginning of the following for loop."
}
] | [
{
"body": "<p>Some small tips:</p>\n\n<ul>\n<li><p>Avoid calculations in a loop. Change <code>1000*1000</code> to a constant:</p>\n\n<pre><code>public static final int MILLION = 1000 * 1000;\n</code></pre></li>\n<li><p>Integer arrays have default value of zero when created, so your \"first pass\" could be arres... | {
"AcceptedAnswerId": "55255",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T18:11:02.817",
"Id": "55250",
"Score": "11",
"Tags": [
"java",
"algorithm",
"beginner",
"matrix"
],
"Title": "\"Two-pass algorithm\" implementation in Java"
} | 55250 |
<p>I'm using basic jQuery to render tab data. I was wondering if anybody could comment on how to refactor the <code>click()</code> event handlers, and any general guidance or advice.</p>
<p>Here's the code/output in <a href="http://jsfiddle.net/Jberczel/Q4zVH/" rel="nofollow noreferrer">jsFiddle</a>.</p>
<pre><code>... | [] | [
{
"body": "<p>You can simply put your common code in a <code>function</code></p>\n\n<pre><code>function giveItAName(htmlValue,self){\n\n $(\"#page\").empty().html(htmlValue);\n $(\"a\").removeClass(\"active\");\n $(self).addClass(\"active\");\n}\n</code></pre>\n\n<p>And call this <code>function</code> according... | {
"AcceptedAnswerId": "55271",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T18:42:55.067",
"Id": "55257",
"Score": "6",
"Tags": [
"javascript",
"jquery"
],
"Title": "Rendering tab data"
} | 55257 |
<p>I'm currently looking to optimize my aStar algorithm as my last run through took roughly a minute to generate one path. I've never had to optimize before as I've never run into performance issues, so I'm not sure where to even start with this one.</p>
<p><a href="http://pastebin.com/MbZtyQFu">http://pastebin.com/Mb... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T18:42:10.940",
"Id": "97220",
"Score": "3",
"body": "As for where to optimize - the answer for A* is almost always \"the heuristic\"."
}
] | [
{
"body": "<h2>Teach a Man to Fish</h2>\n\n<p>If you have a program that is running slower than you expect, and you want to know where it is slow, the right answer is to profile the code. There's a question at <a href=\"https://stackoverflow.com/questions/2267594/java-profiling-how-can-i-get-a-method-by-method... | {
"AcceptedAnswerId": "55279",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T18:48:01.240",
"Id": "55259",
"Score": "11",
"Tags": [
"java",
"optimization",
"android",
"pathfinding"
],
"Title": "Optimization of aStar in Java"
} | 55259 |
<p>Here is my implementation of the <a href="http://en.wikipedia.org/wiki/Euclidean_algorithm" rel="nofollow">Euclidean Algorithm</a>. My question is how to make it more "professional". It's working right, but isn't this too newbie?</p>
<pre><code>public class Euklideszi {
public int Euklideszi(int a, int b, bool... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T19:28:08.427",
"Id": "96795",
"Score": "2",
"body": "You could start with writing everything in English. While code in your own language may definitely be considered professional in some branches, it is not the way to go with the c... | [
{
"body": "<p>There are a couple of \"newbie\" things here, yes.</p>\n\n<ul>\n<li><p>Your method has an uppercase first character, it should be lower-case.</p></li>\n<li><p>Your method is not static, which means that an instance of the class has to be created just to use your method. You can make the method sta... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T19:22:18.463",
"Id": "55262",
"Score": "4",
"Tags": [
"java",
"algorithm",
"mathematics",
"logging"
],
"Title": "Is there a better version for verbosing the output of the eucl... | 55262 |
<p>My goal is to take any size number, and convert it to a string of smaller characters that represent the concatenation of the binary expansion of the number. To illustrate what I am talking about, here is an example using the number <code>4820</code>:</p>
<blockquote>
<pre><code>4820's binary: 0001001011010100 #... | [] | [
{
"body": "<p>Well, it's not a huge performance improvement, but at least it's a lot cleaner:</p>\n\n<pre><code>def to_chars2(number, length):\n bin_num = bin(number)[2:].zfill(length)\n return ''.join([chr(int(bin_num[s:s+8], 2)) for s in range(0, len(bin_num), 8)])\n</code></pre>\n\n<p>Benchmarks:</p>\n... | {
"AcceptedAnswerId": "55650",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T19:48:13.723",
"Id": "55263",
"Score": "2",
"Tags": [
"python",
"performance",
"strings",
"python-3.x",
"converting"
],
"Title": "Large number to many characters"
} | 55263 |
<p>Vectorization refers to a programming paradigm where the process of loop-based, scalar-oriented code is instead written using matrix and vector operations. Vectorization has the following benefits:</p>
<ul>
<li><p>Performance: Vectorized code has better performance regarding function calls and memory access, and as... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T20:14:46.540",
"Id": "55266",
"Score": "0",
"Tags": null,
"Title": null
} | 55266 |
Vectorization refers to a programming paradigm where functions operate on whole arrays in one go. Use this tag if your code contains vectorized operations | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T20:14:46.540",
"Id": "55267",
"Score": "0",
"Tags": null,
"Title": null
} | 55267 |
<p>I have been working on a small library of development utilities for some time now, incrementally improving and expanding it as I make use of it in other projects. I feel that it is fairly mature now; I've worked out enough bugs that I can say it is decently stable and I feel that it is time for a code review on what... | [] | [
{
"body": "<p>I've only looked (briefly) at the <code>cstring.h</code> part so far. I like it for the most part. It looks like it could help projects avoid the chaos and subtle error that often creep into <code>C</code> code that uses lots of character arrays.</p>\n\n<p>Suggestions:</p>\n\n<ul>\n<li>You seem t... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T21:15:20.823",
"Id": "55275",
"Score": "5",
"Tags": [
"c",
"library"
],
"Title": "C Development Utilities Library"
} | 55275 |
<p>Very similar to <a href="https://codereview.stackexchange.com/questions/51729/initializing-events-on-class">this question</a>, I'm curious about common patterns/best practices for handling events in coffeescript classes, particularly when you also need to call the event handlers immediately to initialize state.</p>
... | [] | [
{
"body": "<p>I'm only vaguely familiar with coffeescript, but it seems like the issue is not that you need to call the event handler on init, it's that you need to call the logic currently <em>residing</em> in your event handler. If you separate your logic into reusable pieces, you can call this other method t... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T22:45:28.337",
"Id": "55284",
"Score": "3",
"Tags": [
"jquery",
"coffeescript"
],
"Title": "Set up event on class and initialize state"
} | 55284 |
<p>I have the following solution for the Trip problem from Skiena's and Revilla's Programming Challenges (full problem description <a href="http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=110103&format=html" rel="nofollow">here</a>).</p>
<pre><code>#include <stdio.h>
double trun... | [] | [
{
"body": "<ul>\n<li><code>return (double)((int)(n*100.0)) / 100.0;</code> fails for values of <code>n</code> greater than 2.147483648E7 as product <code>n*100.0</code> would be larger than the maximum value of a 32-bit signed <code>int</code>. Use <code>floor()</code> instead. But that's <strike>probably</stri... | {
"AcceptedAnswerId": "55454",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T23:55:14.487",
"Id": "55288",
"Score": "2",
"Tags": [
"c",
"programming-challenge"
],
"Title": "Skiena's Programming Challenges: The Trip problem"
} | 55288 |
<p>I have created, in Django 1.6, a site for a school, where an applicant can get registered. It's a form that requests some information from the registrant and creates a random code for each applicant. That code is emailed to the provided address, and it is requested to be input in another form that appears right aft... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T13:21:22.327",
"Id": "96947",
"Score": "0",
"body": "One of the solutions I applied that botters me the most is the fact that I had to use to diferent forms in the same view function \"add_applicant\", and to identify those, I deter... | [
{
"body": "<p>One thing that concerns me about this approach is that <code>Applicant</code> is huge. I'd consider splitting this into a few different models. At the very least I'd imagine that I'd want to split out the details for a person and contact information:</p>\n\n<pre><code>class Person(models.Model):\n... | {
"AcceptedAnswerId": "71469",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T02:28:45.757",
"Id": "55290",
"Score": "7",
"Tags": [
"python",
"django"
],
"Title": "School applicant form"
} | 55290 |
<p>For a while I have been interested in seeing if some tasks work well when split across multiple threads.</p>
<p>On the one project I have been busy with I have been creating a lot of small utility apps, to do single tasks for me, so this morning while modifying one I thought I would give it a try.</p>
<p>What I wr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T10:17:57.927",
"Id": "96906",
"Score": "4",
"body": "Does that code even work? I'd expect it to crash if two tasks complete withing the same second."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T11:... | [
{
"body": "<p>I would do something like this:</p>\n\n<pre><code>private static void ExportDocTypes(IEnumerable<string> docTypes)\n{\n var queue = new ConcurrentQueue<string>(docTypes);\n var tasks = new List<Task>();\n\n for (byte i = 0; i < threadCount; i++) //threadCount is a co... | {
"AcceptedAnswerId": "55335",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T06:40:47.743",
"Id": "55299",
"Score": "40",
"Tags": [
"c#",
".net",
"multithreading"
],
"Title": "Exporting doc types using queues and multithreading"
} | 55299 |
<p>I am using "AndEngine" and I would like to know if I am following the best practice when I want to refresh the entity.</p>
<p>Let say, I have 2 sprites and I want change them into 2 another sprites.</p>
<p>I usually do it like this :</p>
<pre><code>class MainClass {
private Sprite sprite1;
private Sprite ... | [] | [
{
"body": "<p>I am not familiar with AndEngine, but here are some things that I saw:</p>\n\n<p>Inside your <code>refreshSprites</code> method you call <code>detachSelf</code> and <code>attachChild</code> in unsynchronized way. So either make sure this method is called from <code>updateThread</code> or make all ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T08:47:03.190",
"Id": "55306",
"Score": "5",
"Tags": [
"java",
"android",
"animation"
],
"Title": "Sprite is Refreshing"
} | 55306 |
<p>The problem is about finding the sum of all repeating groups from an integer array as explained below and <a href="http://codingbat.com/prob/p193817" rel="nofollow">here</a>.</p>
<p><strong>Problem statement:</strong></p>
<blockquote>
<p>Say that a "clump" in an array is a series of 2 or more adjacent
elements... | [] | [
{
"body": "<p>You can do the same with single loop. see below code :</p>\n\n<pre><code>public int countClumps(int[] nums) {\n int count=0;\n if(null!=nums && nums.length > 0)\n {\n final int len=nums.length;\n\n int currentInt = nums[0];//this is to store current element in loop, default is ... | {
"AcceptedAnswerId": "55313",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T09:56:59.037",
"Id": "55309",
"Score": "9",
"Tags": [
"java",
"programming-challenge"
],
"Title": "Finding the count of all repeats in an array of integers"
} | 55309 |
<p>I would like a review for this connection to RabbitMQ. I just developed it and seems to be working well, but I would like another set of eyes on it before putting this on the sever.</p>
<pre><code>package models
import com.rabbitmq.client.Connection
import com.rabbitmq.client.ConnectionFactory
import com.rabbitmq.... | [] | [
{
"body": "<p>Well, the first thing I would recommend is replacing all of those <code>println</code> statements with some kind of logging. In any kind of production environment, logging is something that needs more thought and care so that it is useful, without consuming resources unnecessarily. Or, if they're ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T10:17:56.177",
"Id": "55312",
"Score": "6",
"Tags": [
"scala",
"connection-pool",
"rabbitmq"
],
"Title": "Connecting to RabbitMQ"
} | 55312 |
<p>I am working on an XNA project, and since procedural generation is likely to be used, I wanted to eventually create a helper class to work with data to facilitate that.</p>
<p><strong>Design Goal:</strong></p>
<p>Originally, I wanted to generate and modify a heightmap in a simple but efficient manner. The most str... | [] | [
{
"body": "<p>I think you should use aggregation.</p>\n\n<p>It's either:</p>\n\n<pre><code>class Mesh<T> : ITransformable<T>\n{\n public Mesh(IGrid<T> grid, ....)\n {\n Grid = grid;\n ......\n }\n\n public IGrid<T> Grid { get; private set; }\n .....\n}\n</cod... | {
"AcceptedAnswerId": "55760",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T11:00:01.123",
"Id": "55314",
"Score": "5",
"Tags": [
"c#",
"inheritance",
"interface",
"xna"
],
"Title": "Interface for a transformable grid"
} | 55314 |
<p>This is a fairly straight forward question. I have a C# WPF MVVM application that call a C++ DLL to do some compilation/crunching. To update the UI C# application for progress updates I am using callback delegates. </p>
<pre><code>public static class Callbacks
{
public static ConsoleCallback ConsoleOutputCallba... | [] | [
{
"body": "<p>The TPL is unfortunately verbose at times. The only way I can think of to make it look \"nicer\" is to point <code>ConsoleOutputCallback</code> to a named method and delegate the creation of the <code>Task</code> to another method:</p>\n\n<pre><code>public static void MyMethod()\n{\n Callbacks.... | {
"AcceptedAnswerId": "55322",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T11:58:27.270",
"Id": "55317",
"Score": "3",
"Tags": [
"c#",
"multithreading",
"wpf",
"task-parallel-library"
],
"Title": "Cross Thread Access to Object in ViewModel"
} | 55317 |
<p>I have the following function that works fine. Is there a better way to do it and will this be efficient if I have 100+ rows returned from each table?</p>
<p><strong>The database</strong></p>
<p><strong>Tables</strong></p>
<ul>
<li><code>wcx_articles</code></li>
<li><code>wcx_videos</code></li>
<li><code>wcx_app... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T13:15:21.303",
"Id": "96945",
"Score": "1",
"body": "Updated my question with working code"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T23:50:44.380",
"Id": "97092",
"Score": "0",
"body... | [
{
"body": "<h3>SQL</h3>\n\n<p>If you want a count, ask for a count. Don't ask the server to send all the data for all the rows, just to have the client count the rows. (A few hundred rows is a trivial amount of data for a database to handle, but still, you should follow good practices.)</p>\n\n<pre class=\"la... | {
"AcceptedAnswerId": "55324",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T12:24:14.797",
"Id": "55318",
"Score": "5",
"Tags": [
"php",
"mysql"
],
"Title": "Conditional row count across 4 tables"
} | 55318 |
<p>I have two model classes as follows:</p>
<pre><code>class FileInfo < ActiveRecord::Base
STATUS = {:UNAPPROVED => 1, :APPROVED => 2, :PROCESSED => 3 }
attr_accessible :id, :status
validates :status, :inclusion => {:in => STATUS.values}
end
</code></pre>
<p>FileInfo has id and status fiel... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T12:37:35.523",
"Id": "55320",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails",
"active-record",
"sidekiq"
],
"Title": "Written worker using sidekiq for activerecord class"
} | 55320 |
<p>I created a classic snake game in the canvas element. I have not considered best practices when doing this, I just wanted to finish it first. Now it's time to improve the coding practice. You can help me out by mentioning bad practices, giving code improvements and suggesting anything else.</p>
<pre><code><!DO... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T14:41:24.807",
"Id": "96965",
"Score": "3",
"body": "I don't get a game over if the snake hits itself; only if it hits the walls. Makes it a little too easy :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "201... | [
{
"body": "<p>Some thoughts on your general code style (some points might depend on personal preference):</p>\n\n<ol>\n<li>I suggest splitting HTML/CSS/JS into different files</li>\n<li><p>Your use of indention and whitespaces is inconsistent</p>\n\n<pre><code>function launchFullscreen(element) {\n if(element.... | {
"AcceptedAnswerId": "55356",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T13:34:12.020",
"Id": "55323",
"Score": "16",
"Tags": [
"javascript",
"html5",
"canvas",
"snake-game"
],
"Title": "Snake game with canvas element code"
} | 55323 |
<p>I know the maximum array size is 6. So what is the best practice to declare an array?</p>
<p>In the following code I used it like this:</p>
<pre><code><!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var marks = new Array(6);
marks = [40, 100, 1, 5, 25, 10];
document.g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-27T09:48:07.730",
"Id": "97166",
"Score": "1",
"body": "Even if this gets reopened (which I voted for) this question is still off topic as of our [help/on-topic], namely: Best practices in general (that is, it's okay to ask \"Does this... | [
{
"body": "<p>Interesting question,</p>\n\n<p>first off, you are worrying about the wrong things. Even if the first approach <em>provides some better performance</em>, (which I think unlikely), it would be premature optimization.</p>\n\n<p>The right way would be simply:</p>\n\n<pre><code>var marks = [40, 100, 1... | {
"AcceptedAnswerId": "55453",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T14:09:53.373",
"Id": "55328",
"Score": "1",
"Tags": [
"javascript",
"performance",
"array"
],
"Title": "Declaring arrays knowing their maximum size"
} | 55328 |
<p>If the fractional part of the number is greater than 0.6, round up; if less, round down.
I need feedback about my code.</p>
<pre><code>public static double DivisionMethod(double a, double b)
{
double div = a / b;
double temp = Math.Floor(div);
double fractional = div - temp;
if (fractional ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T15:04:37.253",
"Id": "96968",
"Score": "5",
"body": "Did you mean \"if less *or equal* - round down\"?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T15:11:49.730",
"Id": "96969",
"Score": "3... | [
{
"body": "<p>First, you're calculating <code>Math.Floor(div)</code> twice. You have already stored it in temp (and why not give it a more clear name, like floor).</p>\n\n<p>Second, you don't need the fractional variable:</p>\n\n<pre><code>if (div - floor > 0.6) etc.\n</code></pre>\n\n<p>Third, <code>Math.Ce... | {
"AcceptedAnswerId": null,
"CommentCount": "14",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T14:57:25.590",
"Id": "55333",
"Score": "11",
"Tags": [
"c#",
"floating-point"
],
"Title": "Divide two numbers, then apply a custom rounding rule"
} | 55333 |
<p>I am a Python beginner and wrote a script which should run on a Raspberry PI as a UDP server. It reads and writes to a serial device and has to process and forward JSON strings.</p>
<p>Because there is relatively much functionality included and I don't like cross compiling, I was too lazy to write a C program but i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-07-19T09:47:52.357",
"Id": "322312",
"Score": "0",
"body": "why use debugging and logging? You can add a handler which outputs to `stdout`"
}
] | [
{
"body": "<p><strong>Style</strong></p>\n\n<ul>\n<li><p><code>init_serial</code> is quite hard to follow. It took me a while to realize that code in a nested try-except is not a retry. Factor out the identical code into a function. Also, there is no need to return a success status in a separate boolean: return... | {
"AcceptedAnswerId": "55354",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T15:19:45.907",
"Id": "55337",
"Score": "1",
"Tags": [
"python",
"multithreading",
"json",
"socket",
"serial-port"
],
"Title": "UDP server and JSON parser script"
} | 55337 |
<p>I've written this code to read CSV files written in a specific format. I would like to gather some feedback on where it could be improved. I'm trying to get into the Test-Driven-Development ideology so any way I could make the code play better with unit tests would be of particular interest to me.</p>
<p>An aspect ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-28T14:06:28.993",
"Id": "97410",
"Score": "1",
"body": "Have you considered using an existing library instead of reinventing the wheel?"
}
] | [
{
"body": "<p>Again just a few stylistic issues.</p>\n\n<ul>\n<li>Make it more LINQ-ish: Do all your list processing in one statement. Try to avoid converting between <code>List<></code>s, arrays, and <code>IEnumerable<></code>s unless you have to. Look for places where you're iterating over an enum... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T15:33:44.287",
"Id": "55339",
"Score": "23",
"Tags": [
"c#",
"parsing",
"csv"
],
"Title": "Parsing CSV to specific format"
} | 55339 |
<p>I am trying to do the following. I have a list of Custom objects:</p>
<pre><code>public class TestObject {
public int Id { get; set; }
public string Name { get; set; }
public bool First { get; set; }
public bool Last { get; set; }
}
</code></pre>
<p>I want to set the property First and Last to true at the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T16:06:37.707",
"Id": "96980",
"Score": "0",
"body": "If doing so wouldn't *invalidate* existing answers, it would probably be best to edit your question so as to include your *actual*, *real* code; you'd be surprised with what can c... | [
{
"body": "<p>The performance of your current code depends a little about the implementation of the list, but what I primarily would have done is to extract <code>first</code> and <code>last</code> to variables that get initialized once, not in each iteration.</p>\n\n<pre><code>var first = result.FirstOrDefault... | {
"AcceptedAnswerId": "55342",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T15:42:01.267",
"Id": "55340",
"Score": "10",
"Tags": [
"c#",
"linq"
],
"Title": "Update first and last item in List<T>"
} | 55340 |
<p><a href="http://www.rabbitmq.com" rel="nofollow">RabbitMQ</a> is open source message broker software that implements the <a href="http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol" rel="nofollow">Advanced Message Queuing Protocol</a> (AMQP), the open standard for business messaging. Written in Erlang, t... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T16:38:12.620",
"Id": "55344",
"Score": "0",
"Tags": null,
"Title": null
} | 55344 |
<h1>Problem Statement</h1>
<blockquote>
<p>James got hold of a love letter that his friend Harry has written for
his girlfriend. Being the prankster that James is, he decides to
meddle with it. He changes all the words in the letter into
palindromes.</p>
<p>While modifying the letters of the word, he foll... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T17:12:41.397",
"Id": "97016",
"Score": "4",
"body": "I do not speak Ruby but I guess there is a way to write this in a more concise/beautiful way. As an example, here's what I wrote in Python : `print sum((abs(ord(s[i]) - ord(s[-i-1... | [
{
"body": "<p>There is almost always a better way to loop in Ruby than actually using a loop. Unfortunately, I don't know Ruby well enough to say what that better way is.</p>\n\n<p>What I can say is that this line of code is a bit obtuse.</p>\n\n<pre><code>break if string.length % 2 == 0 ? i == (string.length/2... | {
"AcceptedAnswerId": "55374",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T16:51:51.577",
"Id": "55349",
"Score": "16",
"Tags": [
"beginner",
"ruby",
"programming-challenge",
"palindrome",
"edit-distance"
],
"Title": "The Love-Letter Mystery"
... | 55349 |
<p>I am trying to unit test a small class that I consider part of the "business-logic" layer of my project. It mostly just interact's with Doctrine's entity manager and a couple of entities with a many-to-many association. I'm finding that unit testing it while mocking out its dependencies is just ludicrous. Just th... | [] | [
{
"body": "<p>I decided that there was too much database access code in my UserPermissions class and split it into two classes. The first class is now much easier to mock and the second class is just a wrapper for a doctrine query, which is probably almost pointless to mock.</p>\n\n<pre><code>class UserPermiss... | {
"AcceptedAnswerId": "55381",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-26T18:26:42.047",
"Id": "55362",
"Score": "6",
"Tags": [
"php",
"unit-testing",
"doctrine",
"mocks"
],
"Title": "Ugly code unit testing with PHPUnit and Doctrine2 (an ORM)"
} | 55362 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.