body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<pre><code>SELECT TOP 1 l.ID
FROM Leads l
WHERE
l.ID NOT IN (SELECT LeadID FROM LeadFollowups)
AND l.ID NOT IN (SELECT LeadID FROM LeadsWorking)
AND l.ID NOT IN (SELECT LeadID FROM LeadsDead)
AND l.ID NOT IN (SELECT LeadID FROM LeadHolds)
AND l.ID >= (RAND() * (SELECT MAX(ID) FROM Leads))... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T16:57:45.923",
"Id": "73719",
"Score": "1",
"body": "what does `l.ID >= (RAND() * (SELECT MAX(ID) FROM Leads))` and why do you need this?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T17:04:49.210",... | [
{
"body": "<blockquote>\n <p>My query is pretty quick now, but as this grows is NOT IN the most efficient solution for this?</p>\n</blockquote>\n\n<p>I expect it would be quicker if you had an indexed <code>Status</code> field in the <code>Leads</code> table (so that records in the <code>LeadsDead</code> table... | {
"AcceptedAnswerId": "42791",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T16:50:25.743",
"Id": "42781",
"Score": "8",
"Tags": [
"optimization",
"sql",
"sql-server",
"random"
],
"Title": "WHERE NOT IN SQL Performance"
} | 42781 |
<p>I'm working on this method in Java, which is giving me the factors of a number. I'll be using this method a lot, and I was wondering if there isn't a better way of doing it. Like, with just one loop. Although this code works great and it returns what I expect, I just want to know if there's a better workaround.</p>
... | [] | [
{
"body": "<ol>\n<li><p>Apache Commons Math has a similar function: <a href=\"http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/primes/Primes.html#primeFactors%28int%29\" rel=\"nofollow\"><code>Primes.primeFactors()</code></a></p>\n\n<pre><code>Primes.primeFactors(288)\n</code></pre... | {
"AcceptedAnswerId": "42787",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T17:38:08.020",
"Id": "42786",
"Score": "11",
"Tags": [
"java",
"algorithm",
"primes"
],
"Title": "Factorizing integers"
} | 42786 |
<p>I made a program in Python and wanted it to be faster, so I wrote it on C# because it's compiled. To my surprise, the Python program is much faster. I guess there is something wrong with my C# code, but it is pretty simple and straightforward, so I don't know. They are structured about the same way.</p>
<p><strong>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T18:45:22.620",
"Id": "73745",
"Score": "3",
"body": "I guess I had better get back to typing up some Macbeth!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T22:50:13.617",
"Id": "73813",
"Sco... | [
{
"body": "<p>In your python code you use a character array as your <code>guess</code>. In your C# code you build a <code>StringBuffer</code> instead. Try using a <code>char[]</code> instead.</p>\n\n<p>Since you are on Code Review - I'll also give some thoughts about your code:</p>\n\n<p><strong>Naming Conventi... | {
"AcceptedAnswerId": "42796",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T18:08:47.077",
"Id": "42792",
"Score": "28",
"Tags": [
"c#",
"python",
"performance",
"strings",
"validation"
],
"Title": "Matching a generated string of random letters... | 42792 |
<p>I have a need to read properties from soapUI using groovy and writing them to Excel. I initially had a <a href="https://stackoverflow.com/questions/21935285/how-to-write-data-to-excel-using-scriptom-in-groovy">problem with writing to Excel</a>, but I was able to solve that. Now I want to know if my solution is corre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T23:16:17.990",
"Id": "73975",
"Score": "1",
"body": "Is there a hard requirement to read/write in xsl/xslx format? For instance, Excel can read/write data in CSV format, which is FAR easier to work with, IMO."
},
{
"ContentL... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T18:35:57.453",
"Id": "42794",
"Score": "2",
"Tags": [
"excel",
"groovy"
],
"Title": "Code to write data to Excel"
} | 42794 |
<p>I needed to impose on a Python method the following locking semantics: the method can only be run by one thread at a time. If thread B tries to run the method while it is already being run by thread A, then thread B immediately receives a return value of <code>None</code>.</p>
<p>I wrote the following decorator to ... | [] | [
{
"body": "<p>I think this will work fine and it's very close to how I would write it myself.</p>\n\n<p>A few small things come to mind:</p>\n\n<ul>\n<li><p>There's no documentation of any kind that explains what the semantics are, and they're not explicit either (the return None if the lock isn't acquired is e... | {
"AcceptedAnswerId": "42807",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T19:52:35.600",
"Id": "42802",
"Score": "8",
"Tags": [
"python",
"concurrency"
],
"Title": "A non-blocking lock decorator in Python"
} | 42802 |
<p>As request of Simon's comment:</p>
<p><strong>Direction.java</strong></p>
<pre><code>package net.woopa.dungeon.datatypes;
import java.util.Random;
public enum Direction {
NORTH, EAST, SOUTH, WEST;
private static Random rnd = new Random();
static public Direction randomDirection() {
return Di... | [] | [
{
"body": "<p>It is better to replace </p>\n\n<pre><code>return Direction.values()[rnd.nextInt(4)];\n</code></pre>\n\n<p>with something like</p>\n\n<pre><code>return Direction.values()[rnd.nextInt(Direction.values().length)];\n</code></pre>\n\n<p>for it to not break if you decide to add something like <code>NOR... | {
"AcceptedAnswerId": "42828",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T21:56:22.967",
"Id": "42817",
"Score": "14",
"Tags": [
"java",
"enum"
],
"Title": "Direction enum class"
} | 42817 |
<p>I've just finished writing my first game: a clone of the classic Pong game for Linux and Mac only. You will need SDL 2.0, SDL_ttf 2.0 and SDL_Mixer 2.0 to compile it. The complete project can be found <a href="https://github.com/chaficnajjar/pong">here</a>.</p>
<p>My experience with C++ and game development in gene... | [] | [
{
"body": "<p><strong>Global variables</strong></p>\n\n<p>You have <em>many</em> global variables, which is very bad. In general, global variables should be avoided as they can be modified anywhere in the program and at any time. This especially makes debugging difficult as you won't be able to keep track of ... | {
"AcceptedAnswerId": "42826",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-25T23:08:54.317",
"Id": "42823",
"Score": "22",
"Tags": [
"c++",
"game",
"c++11",
"sdl"
],
"Title": "Pong game using SDL 2.0"
} | 42823 |
<p>So I've got a jquery project where I'm using an external class that has callback style events. Meaning, it has an "onSave" property that takes one function. However, I need to more than one other component to hook into it.</p>
<p>What I've settled on for now, goes like this:</p>
<pre><code>var saveCallbacks = $.Ca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T04:16:43.723",
"Id": "73822",
"Score": "0",
"body": "Is confusing how you add a reference of an object to itself. What is the external class you are using? I created a gist once of a JS class that facilitates the creation of jQuery ... | [
{
"body": "<p>I think what you need is a global <a href=\"http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern\" rel=\"nofollow\">pub-sub facility</a>. Modules you have subscribe to certain events. These subscriptions (functions) get executed when that event is published, usually with data. </p>\n\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T02:03:58.337",
"Id": "42833",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"callback"
],
"Title": "Using jquery Callbacks.fire method as a event handler"
} | 42833 |
<pre><code>#include <stdio.h>
#include <stdlib.h>
struct Stack {
int value;
int is_empty;
struct Stack *next;
};
int pop(struct Stack **stack) {
if ((*stack)->is_empty == 1) {
printf("Stack is empty!\n");
abort(); // not sure what this does
} else {
int value = (*stack)->value;... | [] | [
{
"body": "<h1>Things you did well:</h1>\n\n<ul>\n<li><p>Overall the code looks very nice and well organized.</p></li>\n<li><p>You used comments well.</p></li>\n</ul>\n\n<h1>Things you could improve:</h1>\n\n<h3>Syntax:</h3>\n\n<ul>\n<li><p><code>typedef</code> your <code>struct</code>s.</p>\n\n<blockquote>\n<p... | {
"AcceptedAnswerId": "42835",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T02:43:07.830",
"Id": "42834",
"Score": "7",
"Tags": [
"c",
"stack",
"integer"
],
"Title": "Int stack implementation"
} | 42834 |
<p>Single app which listen to multiple RabbitMQ queue and process the message. This is working fine but not sure this implementation is right one or I am missing something.</p>
<p>Implementation is inspired from this answer <a href="https://stackoverflow.com/a/21847234/37571">https://stackoverflow.com/a/21847234/37571... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T13:20:00.330",
"Id": "73879",
"Score": "0",
"body": "Does it work? Why do you think it might not be right?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T14:21:51.753",
"Id": "73889",
"Score"... | [
{
"body": "<pre><code>public async Task<bool> Process(Core.MessageInfo MessageItem)\n{\n //Start new task to process the message\n bool _ProcessedResult = await Task<bool>.Factory.StartNew(() => MessageProcesser(MessageItem), CancellationToken.None, TaskCreationOptions.LongRunning, TaskSche... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T03:05:31.157",
"Id": "42836",
"Score": "8",
"Tags": [
"c#",
"task-parallel-library",
"async-await"
],
"Title": "Listen to multiple RabbitMQ queue by task and process the message"
... | 42836 |
<p>If this is my class:</p>
<pre><code>class Something
{
UUID id;
// Other members
}
</code></pre>
<p>Given a <code>List<Something> things</code> and I want to get a <code>List<UUID> ids</code>, this is what I usually do:</p>
<pre><code>List<UUID> ids = new ArrayList<UUID>
for(Somethi... | [] | [
{
"body": "<p>When I have encountered this type of problem, it typically involves creating some ugly code in your method to do that iteration. In essense, there is no way to do things any differently, you <em>have</em> to iterate, and collect the UUID's (but, you could wait for Java8 and do lambdas ..).</p>\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T06:33:27.567",
"Id": "42842",
"Score": "3",
"Tags": [
"java",
"lambda"
],
"Title": "Elegant way of making a List of an attribute from a list of objects containing that attribute"
} | 42842 |
<p>I wrote a simple cython script to optimize the collections.Counter of a dictionary counter and the python zip implementation (the main input is a list of tuples). Is there a way to speed it up?</p>
<pre><code>%%cython --annotate
cimport cython
import numpy as np
cimport numpy as np
from collections import defaultdi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T08:25:57.217",
"Id": "73841",
"Score": "0",
"body": "Welcome to Code Review! Could you please run a profiler on your code to see what's slow? See the [Cython profiling tutorial](http://docs.cython.org/src/tutorial/profiling_tutorial... | [
{
"body": "<p>You don't give us much context for this problem, so it's unclear to me exactly what you are trying to achieve. But in your example, you have a pair of NumPy arrays containing integers in the range 0–2, and you seem to want to count the number of occurrences of each pair of values.</p>\n\n<p>So I s... | {
"AcceptedAnswerId": "42901",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T07:26:47.283",
"Id": "42846",
"Score": "3",
"Tags": [
"python",
"optimization",
"numpy",
"cython"
],
"Title": "Speedup cython dictionary counter"
} | 42846 |
<p><a href="http://oj.leetcode.com/problems/binary-tree-level-order-traversal/" rel="nofollow">Level traverse binary tree question</a>:</p>
<blockquote>
<p>Given a binary tree, return the level order traversal of its nodes'
values. (ie, from left to right, level by level).</p>
<p>For example:</p>
<p>Gi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T06:04:48.547",
"Id": "89557",
"Score": "0",
"body": "first of all it is not broken, it just didn't deal with boundary condition correctly. secondly this code is already written, you can run through the `full sample` link."
}
] | [
{
"body": "<p>I don't see why \"DFS\" should appear in your code. The challenge is to perform a breadth-first traversal. The typical way to implement a breadth-first traversal is to use a queue.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T06:... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T08:31:07.437",
"Id": "42848",
"Score": "2",
"Tags": [
"c++",
"algorithm",
"c++11",
"tree",
"programming-challenge"
],
"Title": "Level-traverse a binary tree"
} | 42848 |
<p>I have this portion of code and I would like to know if I did it right, what changes could be done to optimize and make it better, and if I used the all the tags the right way. For the moment, the CSS part is not really done since I have few bugs on the height of each column.</p>
<pre><code><div class="shop-gri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T15:23:58.293",
"Id": "73903",
"Score": "0",
"body": "Having empty `alt`s is a code smell."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T06:47:55.480",
"Id": "74021",
"Score": "1",
"body"... | [
{
"body": "<p>Don’t use <code>i</code> for font icons. Use <code>span</code> instead (like you did with <code>.thumb-screen</code>). The <a href=\"https://codereview.stackexchange.com/a/41124/16414\"><code>i</code> element is not appropriate</a> for such purposes.</p>\n\n<p>In any case, you should offer alterna... | {
"AcceptedAnswerId": "42936",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T08:46:09.550",
"Id": "42849",
"Score": "4",
"Tags": [
"html",
"html5"
],
"Title": "Product grid for a online catalog"
} | 42849 |
<p>In my code I have a base type which is OnlinePaymentTransaction:</p>
<pre><code>public abstract class OnlinePaymentTransaction
{
public abstract void Complete( PaymentGatewayCallbackArgs args );
}
</code></pre>
<p>The problem I am having is that each class that inherits from this base class require different ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T11:52:25.187",
"Id": "73867",
"Score": "1",
"body": "What does complete do that means its a method on the model? ie. Why isn't there a separate logic object that makes the decision/s on how the model has changed?"
},
{
"Cont... | [
{
"body": "<p>Darn, at first glance this looked like a simple solution but you ruled out constructor injection.</p>\n\n<p>The only suggestion I can come up with is to have a class that inherits from the same interface, DOES have the constructor injection is built up and added to the main object as a composite o... | {
"AcceptedAnswerId": "42892",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T09:38:42.067",
"Id": "42851",
"Score": "3",
"Tags": [
"c#",
"dependency-injection"
],
"Title": "Dependency on overridden method"
} | 42851 |
<p>I am trying to cache the entirety of streams from Twitch.TV public API with the following code. It is successful but takes almost a full minute to execute so I am wondering if it's my code or just the speed of the API delivery. In any case, because it is my first PHP script (and really, I'm new in general), I am cer... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T10:19:00.963",
"Id": "73856",
"Score": "0",
"body": "I believe I also need to consider the fact that, while my script is collecting data, the live data might update and my universe of discord might become fragmented with duplicates ... | [
{
"body": "<p>At a glance I'd be almost certain that the network requests are your bottleneck here.</p>\n\n<p>If you think of the difference between some code interpreted and run locally vs instantiating a network connection, sending the request, waiting for their servers to run <em>their</em> code and the netw... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T10:16:54.313",
"Id": "42852",
"Score": "0",
"Tags": [
"php"
],
"Title": "Build a local cache of all streams from Twitch.TV API"
} | 42852 |
<p>I have about 11 singleton-esque classes divided over a dozen files:</p>
<p>the first file is one that gathers all singleton definitions and makes them callable on a request scope:</p>
<pre><code>public sealed partial class ExpertiseverslagEngine
{
readonly IOrganizationService _oService;
readonly XrmServic... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T18:18:06.910",
"Id": "73918",
"Score": "0",
"body": "Got [ReSharper](http://www.jetbrains.com/resharper/)?"
}
] | [
{
"body": "<p><em>Extracting an interface</em> essentially boils down to taking the signatures for all public members, making them part of the interface you're extracting, and then making the type implement the interface you've extracted.</p>\n\n<p>Tools like <a href=\"http://www.jetbrains.com/resharper/\" rel=... | {
"AcceptedAnswerId": "42887",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T10:48:01.193",
"Id": "42854",
"Score": "6",
"Tags": [
"c#",
"interface"
],
"Title": "How do I extract interfaces from existing similar classes?"
} | 42854 |
<p>After reading a lot of documents, I wrote this object pooling code. Can anyone help me to improve this code? I am lagging in validating the object, confirming whether I can reuse it or not.</p>
<pre><code>/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package iac... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T12:52:27.280",
"Id": "73874",
"Score": "0",
"body": "`ObjectPool<MyObject> pool = new ObjectPool<MyObject>(); pool.create(MyObject.class); Object obj = pool.checkOut(MyObject.class);` returns `null`. Does it work? How? Could you pro... | [
{
"body": "<p>The choices of classes and other design patterns that you have made indicate to me that the books/tutorials you have been reading are pretty old. There are a number of things in your code which are almost ten years out of date in the Java 'world'.</p>\n\n<p>Also, you are only showing us half of yo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T12:19:16.443",
"Id": "42862",
"Score": "2",
"Tags": [
"java",
"beginner",
"synchronization"
],
"Title": "Reusing objects using a generic object pool"
} | 42862 |
<p>I have implemented a customized UTF-8 encoding mechanism. The code works fine, but I have a lot of concerns regarding the code.</p>
<pre><code>public class Utf8Encoding {
public static void main(String[] args) {
byte [] arr = new byte[1000];
int iStr = 95000; // or > 65535, as till 65... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T13:49:14.670",
"Id": "73885",
"Score": "1",
"body": "Is there a particular reason why you're reinventing the wheel instead of using the UTF-8 encoder and decoder in the standard API?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<h3>Handling of supplementary characters</h3>\n\n<p>No, your code does not handle supplementary characters correctly. A string encoded in UTF-8 <a href=\"http://en.wikipedia.org/wiki/UTF-8#Invalid_code_points\" rel=\"nofollow noreferrer\">must not contain high and low surrogate halves</a>. Instead,... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T12:23:43.483",
"Id": "42863",
"Score": "10",
"Tags": [
"java",
"reinventing-the-wheel",
"utf-8"
],
"Title": "Customised Java UTF-8"
} | 42863 |
<p>I am working on a project in which I have three box (as of now) and each box will have some color of balls, so I am storing the input in a <code>Map</code> of <code>String</code> and <code>List</code> of <code>String</code> as shown below:</p>
<pre><code>Map<String, List<String>> boxBallMap = new Linked... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T14:39:36.443",
"Id": "73893",
"Score": "0",
"body": "I'm not sure I understand the requirements, say on top of your sample input I have `{box4=[blue,blue]}` what would the expected output be? It would be nice if you also added some ... | [
{
"body": "<p>First of all, save some manual checking work and make your <a href=\"http://xunitpatterns.com/Goals%20of%20Test%20Automation.html\" rel=\"nofollow\">test self-checking</a> with JUnit and Google Guava:</p>\n\n<pre><code>import static com.google.common.collect.Lists.newArrayList;\nimport static org.... | {
"AcceptedAnswerId": "42888",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T13:36:49.500",
"Id": "42871",
"Score": "2",
"Tags": [
"java",
"optimization",
"algorithm"
],
"Title": "Generating balls and box combinations depending on set rules"
} | 42871 |
<p>In the below code I should highlight countries on the map based on the category of the country in which there are 2 different type of countries (issuing office and selected countries). Based on the country type I have to highlight that country on the map. Let us not worry about map code.</p>
<p>There is a checkbo... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>This:<br></p>\n\n<pre><code> /*\n * semicolon sepearated list of countryName will be avaialabe via selection module\n * we have to replace ; with , so that we iterate over the list\n */\n countryName = replaceAll(\";\", \",\", countryName);... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T14:18:19.180",
"Id": "42873",
"Score": "6",
"Tags": [
"javascript",
"optimization",
"algorithm",
"dojo"
],
"Title": "Highlight countries based on category"
} | 42873 |
<p>I need to improve the performance of a function that calculates the integral of a two-dimensional <a href="https://en.wikipedia.org/wiki/Kernel_density_estimation" rel="nofollow noreferrer">kernel density estimate</a> (obtained using the function <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.sta... | [] | [
{
"body": "<blockquote>\n<p>I am never forget the day I first meet the great Lobachevsky.\nIn one word he told me secret of success in NumPy:\nVectorize!</p>\n<p>Vectorize!<br>\nIn every loop inspect your <code>i</code>'s<br>\nRemember why the good Lord made your eyes!<br>\nSo don't shade your eyes,<br>\nBut ve... | {
"AcceptedAnswerId": "42919",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T15:16:35.413",
"Id": "42876",
"Score": "6",
"Tags": [
"python",
"performance",
"numpy",
"statistics"
],
"Title": "Improve performance of Gaussian kernel function evaluation... | 42876 |
<p>When an API has a 'next' feature, I use the following pattern to obtain all the results:</p>
<pre><code>/** Obtains a list of channels followed by a user */
function get_follows(username, callback) {
var channels = [];
function handler(data) {
if (!data || data.follows.length == 0) {
cal... | [] | [
{
"body": "<p>I like your code, and would use it myself, some thoughts:</p>\n\n<ul>\n<li><p>I assume you declare <code>url</code> next to <code>JSON.load</code> because you want to declare it close to where you use it. I would still recommend using 1 comma separated list of variables on the top.</p></li>\n<li><... | {
"AcceptedAnswerId": "42881",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T15:47:31.957",
"Id": "42878",
"Score": "7",
"Tags": [
"javascript",
"ajax",
"json",
"callback",
"http"
],
"Title": "Requesting Resources Until Exhaustion"
} | 42878 |
<p>I got a piece of Java code using Hadoop to calculate min, max, average and variance on a large dataset made of (index value) couples separated by a newline:</p>
<pre><code>0 11839923.64831265
1 5710431.90800272
</code></pre>
<p>It's compiled locally and run on a remote distributed HDFS instance by a sh script.</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-02T00:10:50.460",
"Id": "74510",
"Score": "0",
"body": "How large is your dataset? Unless it can't fit on a typical hard-drive, I would re-examine whether you even need to MR."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creati... | [
{
"body": "<p>I'm not familiar with Hadoop, take my advice with care.</p>\n\n<ol>\n<li><p>Are you sure that the following is precise enough?</p>\n\n<pre><code>double count = 0d; // should be an int, but anyway...\n</code></pre>\n\n<p>Consider the following:</p>\n\n<pre><code>final double original = 123456789123... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T18:10:12.157",
"Id": "42885",
"Score": "8",
"Tags": [
"java",
"performance",
"statistics",
"hadoop",
"mapreduce"
],
"Title": "Calculate min, max, average, and variance on ... | 42885 |
<p>I have a <code>Queue</code> that needs to try to process when anything updates in it (add, remove or update).</p>
<p>However, I don't want any of the callers to wait while the processing is happening (either for the processing to happen or while the processing is happening).</p>
<p>This is what I came up with:</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T20:58:24.397",
"Id": "73938",
"Score": "3",
"body": "Welcome to CR! Quick question: to the best of your knowledge, does the code work as expected? (just to make sure)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<blockquote>\n<p>The thread that calls it will likely be the UI Thread.</p>\n</blockquote>\n<p>You're invoking <code>Task.WaitAll</code> which waits for the processing to finish.</p>\n<p>However you said, "... I don't want any of the callers to wait while the processing is happening (either for ... | {
"AcceptedAnswerId": "42911",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T20:30:45.850",
"Id": "42893",
"Score": "10",
"Tags": [
"c#",
"task-parallel-library",
"async-await"
],
"Title": "Async Queue Processing"
} | 42893 |
<p>A JavaScript library that could be described as jQuery plus jQuery UI plus some features from Underscore.js</p>
<p>Dojo Toolkit is an open source modular JavaScript library designed to ease the rapid development of cross-platform, JavaScript/Ajax-based applications and web sites. It is dual-licensed under the BSD L... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T20:32:13.753",
"Id": "42894",
"Score": "0",
"Tags": null,
"Title": null
} | 42894 |
A JavaScript library that could be described as jQuery plus jQuery UI plus some features from Underscore.js | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T20:32:13.753",
"Id": "42895",
"Score": "0",
"Tags": null,
"Title": null
} | 42895 |
<p>I have implemented a simulation program that runs LRU and another web caching algorithm called Sliding Window LFU. I want to compare them both in terms of the hit rate and their run time. SW-LFU works fine, but it takes FOREVER to run! I really can't figure why, since I used many tricks and ideas to keep the effort ... | [] | [
{
"body": "<p>I appreciate that this is non-trivial code and I can see why you would like to have lots of comments, but code like below is probably taking it a bit too far:</p>\n\n<pre><code>// else\nelse {\n\n// increase score by 1\nreqCount += 1;\n</code></pre>\n\n<p>Especially in the second example, if you n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T21:02:45.873",
"Id": "42898",
"Score": "3",
"Tags": [
"java",
"performance",
"hash-map",
"cache",
"complexity"
],
"Title": "LFU-like web caching replacement algorithm"
} | 42898 |
<p>The task (<a href="https://cw.felk.cvut.cz/courses/a4b33alg/task.php?task=orcharddivision" rel="nofollow">from this site</a>) is to create a program that will solve a problem where a matrix (size n * n), which contains integers, is to be divided into four parts, the sums of which are as close to each other as possib... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T21:24:05.417",
"Id": "73947",
"Score": "0",
"body": "Could you include the link to the problem?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T21:25:43.173",
"Id": "73949",
"Score": "1",
... | [
{
"body": "<p>You definitely should use a <code>BufferedReader</code>. Take a look at the <a href=\"https://github.com/Abrackadabra/omni/blob/master/coding/java/src/io/InputReader.java\" rel=\"nofollow\">class</a> I use when I am solving problems of this kind.</p>\n\n<p>Besides, your reading subroutine works in... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T21:19:23.867",
"Id": "42900",
"Score": "5",
"Tags": [
"java",
"performance",
"matrix"
],
"Title": "Orchard Partitioning in to close-to-equal sectors"
} | 42900 |
<p>I recieve a number n and then recieve n*n integers, representing a matrix, or an array of [n][n]. I want to create an array [n][n], where every cell contains the sum of all cells "left and above" from the original array, while not creating the array, just using the values.
For example, the cell [5][7], will contain ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T23:04:08.737",
"Id": "73970",
"Score": "0",
"body": "The first array in input using the scanner. The first number is the size of the array, which will be input."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "20... | [
{
"body": "<p>This is an interesting problem. I think your solution will be possible and much, much faster if you <a href=\"http://en.wikipedia.org/wiki/Memoization\">use memoization</a>. This is the process where you remember your previous calculations and reuse them in your current calculations.</p>\n\n<p>So,... | {
"AcceptedAnswerId": "42912",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-26T22:47:26.493",
"Id": "42906",
"Score": "3",
"Tags": [
"java"
],
"Title": "Partial sums of two dimensional array"
} | 42906 |
<p>I have written this class that will write a <code>JTable</code> to a tab delimited file so that it can be opened in Excel. It works great, but is there any way to make it better or have it directly open in Excel without having to go through the import screens all of the time? How can I tidy up this code to work or o... | [] | [
{
"body": "<p>Most of the issues with this code are stylistic and violations of Java conventions rather than functional.</p>\n\n<pre><code>public class excel {\n</code></pre>\n\n<p>Class names should always be capitalized (e.g., <code>public class Excel</code>). Your class should probably also be named more de... | {
"AcceptedAnswerId": "43233",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T00:18:42.083",
"Id": "42914",
"Score": "5",
"Tags": [
"java",
"excel"
],
"Title": "Writing a JTable to a tab delimited file"
} | 42914 |
<blockquote>
<p>Given a number, this program would find "all permutations of the pairs that add to squares" from 1 to number.</p>
<p>E.g: Given an input number of 16, one of the possible answers would be:</p>
<pre><code>8:1:15:10:6:3:13:12:4:5:11:14:2:7:9:16
</code></pre>
<p>and its reverse.</p>
</blockquo... | [] | [
{
"body": "<p>Since you don't seem to be concerned with the order of any of the collections of objects you use, only membership in those collections, <code>Set</code> is probably the better <code>Collection</code> to use, instead of <code>List</code>. I imagine that <code>Set.contains</code> is going to be mor... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T01:42:04.647",
"Id": "42918",
"Score": "1",
"Tags": [
"java",
"algorithm",
"backtracking"
],
"Title": "All permutations of the pairs that add to squares"
} | 42918 |
<p>I'm looking for a design pattern or suggestions that can help refactor my code into something a bit less repetitive. I have a method that has several sequential steps (10-15) that if any of them fail must record detail about the failure to a log and rollback all previous portions of the transaction. The example is b... | [] | [
{
"body": "<p>Much of that needs to be there. You could modify things to use a single try-catch though:</p>\n\n<pre><code> var undoLog = new Stack<Action>();\n var errorContainer = new ErrorContainer{ message = \"Unknown error\", enumResult = EnumResult.UnknownError };\n\n try\n {\n err... | {
"AcceptedAnswerId": "42930",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T02:48:41.907",
"Id": "42920",
"Score": "10",
"Tags": [
"c#",
"error-handling",
"stack"
],
"Title": "Making an atomic transaction out of several operations"
} | 42920 |
<p>I have written the following Google Spreadsheet script that attempts to loop through all selected cells and then update the value so that it adds an indent, by adding</p>
<pre><code>=CONCAT(REPT( CHAR( 160 ), 5),"' + value[row] + '")
</code></pre>
<p>around the value.</p>
<p>Is there a better way to achieve this?... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>there is clearly a lack in the Google Script API to indent cells..</p>\n\n<p>Still, I find the <code>CONCAT</code> approach ugly, if one wants to indent 2 times, the formula will be:</p>\n\n<pre><code>=CONCAT(REPT( CHAR( 160 ), 5),\"=CONCAT(REPT( CHAR( 160 ), 5),\"'... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T02:56:17.713",
"Id": "42922",
"Score": "3",
"Tags": [
"google-apps-script",
"google-sheets"
],
"Title": "Looping through selected cells to indent text"
} | 42922 |
<p>Bidi, short for Bi-directional text is text containing text in both text directionalities, both right-to-left (RTL or dextrosinistral) and left-to-right (LTR or sinistrodextral). It generally involves text containing different types of alphabets, but may also refer to boustrophedon, which is changing text directiona... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T03:52:03.290",
"Id": "42924",
"Score": "0",
"Tags": null,
"Title": null
} | 42924 |
Bidi, short for Bi-directional text is text containing text in both text directionalities, both right-to-left (RTL or dextrosinistral) and left-to-right (LTR or sinistrodextral). It generally involves text containing different types of alphabets, but may also refer to boustrophedon, which is changing text directionalit... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T03:52:03.290",
"Id": "42925",
"Score": "0",
"Tags": null,
"Title": null
} | 42925 |
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct Node NODE;
struct Node {
int value;
int is_leaf;
struct Node *right;
struct Node *left;
};
NODE *new_leaf(void) {
NODE *leaf = malloc(sizeof(NODE));
assert(leaf);
leaf->is_leaf = 1;
leaf->valu... | [] | [
{
"body": "<p>Firstly, in C, <code>ALL_CAPS</code> is generally used only for macros. Hence, I wouldn't use the name <code>NODE</code> as a <code>typedef</code> for your <code>struct node</code>, but instead something like <code>typedef struct Node node_type;</code>. Further, generally C is written using <code>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T05:30:38.200",
"Id": "42931",
"Score": "5",
"Tags": [
"c",
"memory-management",
"tree",
"binary-search"
],
"Title": "Binary Search Tree implementation"
} | 42931 |
<blockquote>
<p>Write a program in Java that takes a positive integer and prints out all ways to multiply smaller integers that equal the original number, without repeating sets of factors. In other words, if your output contains 4 * 3, you should not print out 3 * 4 again as that would be a repeating set. Note tha... | [] | [
{
"body": "<pre><code>public static void printFactors(int number) {\n if (number <= 0) {\n</code></pre>\n\n<p>You should include the number into the exception's text.</p>\n\n<pre><code> throw new IllegalArgumentException(\"The number should be greater than 0.\");\n }\n printFactorsList(number, number +... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T08:40:14.330",
"Id": "42939",
"Score": "4",
"Tags": [
"java",
"algorithm",
"primes",
"combinatorics"
],
"Title": "Prints out all ways to multiply smaller integers that equal t... | 42939 |
<p>Are all these steps correct and necessary?</p>
<pre><code><?php
if (isset($_SESSION['userID'])) {
$userID = $_SESSION['userID'];
$stmt = $mysqli->prepare(
"SELECT usergroup, firstname FROM tbl_users WHERE userID = ? ");
$stmt->bind_param('i', $userID);
$stmt->execute();
$stmt... | [] | [
{
"body": "<p>More or less, they are... I was using <a href=\"http://de3.php.net/manual/en/mysqli-stmt.get-result.php\" rel=\"nofollow\"><code>get_result</code></a> and fetching object more often, but if you want to have the results bound directly to variables, your code is what you need.</p>\n\n<p>By the way, ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T11:24:49.043",
"Id": "42950",
"Score": "3",
"Tags": [
"php",
"mysqli"
],
"Title": "Are all these steps necessary with prepared statement?"
} | 42950 |
<p>How secure is this encryption?
Secondly, is there something I could do to "turn it up a notch" and make it 'more' secure?</p>
<pre><code>Imports System.Security.Cryptography
Public Class clsCrypt
Private TripleDES As New TripleDESCryptoServiceProvider
'create and return the key and initialization vector hash
Pri... | [] | [
{
"body": "<p>Some issues:</p>\n\n<ol>\n<li>No MAC => say hello to padding oracles. This is fatal flaw that allows decryption of the message in many usage scenarios (when there is an active attacker).</li>\n<li>You use CBC mode with constant IV. A new IV must be chosen for each message. It should be unpredictab... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T13:11:01.067",
"Id": "42954",
"Score": "1",
"Tags": [
"security",
"vb.net",
"cryptography"
],
"Title": "How can this Encryption Class be more secure?"
} | 42954 |
<p>I am developing a UI Application for a very simple phone app, the UI is based entirely on the state of Call in a container provided to me by a third party library. </p>
<p>Below is a sample Call object that I am working with;</p>
<pre><code>public class Call {
private boolean isTannoyCall;
private long cal... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T15:21:57.083",
"Id": "74070",
"Score": "0",
"body": "Minor issues in your post that you could fix : I would add the language to your question and there is one code block that is missing a bracket in the formatted block. Except for t... | [
{
"body": "<p>It seems <a href=\"http://c2.com/cgi/wiki?DataEnvy\" rel=\"nofollow\">data</a>/<a href=\"http://c2.com/cgi/wiki?FeatureEnvySmell\" rel=\"nofollow\">feature</a> envy. Move the boolean conditions to the <code>Call</code> object:</p>\n\n<pre><code>public class Call {\n ...\n\n public boolean is... | {
"AcceptedAnswerId": "42959",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T13:21:55.403",
"Id": "42955",
"Score": "4",
"Tags": [
"java",
"design-patterns"
],
"Title": "How to make business logic code maintainable when working with multiple states?"
} | 42955 |
<p>Below is my implementation of templated <code>Node</code> and <code>LinkedList</code> classes. I would really appreciate it if someone would give me pointers on what I can improve.</p>
<pre><code>//LinkedList with SumLists()
#include <iostream>
#include <set>
using namespace std;
template<class T&... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T15:58:36.970",
"Id": "74308",
"Score": "1",
"body": "By the way, you can remove `#include <set>` since it's used nowhere in the code."
}
] | [
{
"body": "<p>Some observations:</p>\n\n<p>Your data should (probably) be private. Otherwise, an enterprising developer will do this:</p>\n\n<pre><code>LinkedList<int> l;\n// naively delete contents of l\ndelete l.head;\n</code></pre>\n\n<p><code>Node</code> is an implementation detail of the list. It mak... | {
"AcceptedAnswerId": "42966",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T13:43:11.207",
"Id": "42958",
"Score": "33",
"Tags": [
"c++",
"linked-list"
],
"Title": "LinkedList with Node implementation"
} | 42958 |
<p>Basically I have taken over a project and found a table that has the following video and video title fields in it (why they didn't create a separate linked table is beyond me):</p>
<pre><code>[VIDEOURL]
[VIDEOTITLE]
[COUKVIDEO1URL]
[COUKVIDEO2URL]
[COUKVIDEO3URL]
[COUKVIDEO4URL]
[COUKVIDEO1TITLE]
[COUKVIDEO2TITLE]
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T16:34:18.327",
"Id": "74084",
"Score": "3",
"body": "this schema makes me shiver.."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T18:39:56.337",
"Id": "74099",
"Score": "0",
"body": "Can ... | [
{
"body": "<p>There is no telling how the database will optimize the query plan for this, but I would expect that the best query plan would involve applying the predicates to the tables before the union is done. Doing a UNION of multiple small result sets would be more efficient than doing a union on large sets... | {
"AcceptedAnswerId": "42972",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T16:30:12.703",
"Id": "42967",
"Score": "4",
"Tags": [
"sql",
"sql-server"
],
"Title": "Best way to get two columns from a table"
} | 42967 |
<p>The problem was pretty straightforward and used two simple algorithms from our examples; the one for computing the sum, and the one for counting matches. The array for the problem wasn't provided, but you can easily write a method around it without actually having it, since she gave us the name and type of the array... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T17:08:53.733",
"Id": "74089",
"Score": "2",
"body": "there is no point in the review, if you do not post the code you actually consider best! You should apply the refactorings you propose in your question itself and edit your questi... | [
{
"body": "<ol>\n<li><p>From <em>Steve McConnell</em>, <em>Code Complete 2nd Edition</em>, <em>31.2 Layout Techniques</em>, p737:</p>\n\n<blockquote>\n <p>Using blank lines is a way to indicate how a program is organized. You can use them\n to divide groups of related statements into paragraphs, to separate r... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T16:54:49.733",
"Id": "42968",
"Score": "2",
"Tags": [
"java",
"array"
],
"Title": "Computing sum and counting matches in an array"
} | 42968 |
<p>I have some code which works fine. First, it checks that dates format are valid and then, checks that first date is lower than second date. I had to use free input text and custom validator because multiple date formats are supported such as quarter number (2014 Q1) etc.</p>
<p>But I find my code too long for what ... | [] | [
{
"body": "<p>What jumps me most about this code is that all you do is in 2 functions.</p>\n\n<p>consider moving your \"parsing\" operations to separate functions, one for validating the format required for parsing and one for the actual parsing:</p>\n\n<pre><code>function isValidQuarterInput(datestring){\n r... | {
"AcceptedAnswerId": "42971",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T16:56:59.033",
"Id": "42969",
"Score": "5",
"Tags": [
"javascript",
"datetime",
"validation"
],
"Title": "Date range validator"
} | 42969 |
<p>I am working through Kernighan and Ritchie to brush up on my C skills, so I thought I would invite critiques of my code.</p>
<p>Here is my Hex-to-int function:</p>
<pre><code>int htoi(char *str, unsigned long long *result)
{
int c;
int i;
int msnibble;
int digits;
const int nibbles[] = {'\x0','... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T20:13:45.760",
"Id": "74105",
"Score": "1",
"body": "Welcome to Code Review. Seems like you've understood exactly what we are about. I assume \"htoi\" = \"Hex to int conversion\"?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Your indentation is messy (non-standard and not uniform).</p>\n\n<p>If the 2nd character is 'x' or'X' you don't also assert that the 1st character is '0'.</p>\n\n<p>You don't signal an error if the input string has zero length.</p>\n\n<p>I doubt you need <code>\\</code> at the end of the lines of ... | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T20:11:12.567",
"Id": "42976",
"Score": "15",
"Tags": [
"c",
"converting",
"reinventing-the-wheel"
],
"Title": "Hexadecimal to integer conversion function"
} | 42976 |
<p>I have been working on a project and I'm actually refactoring some code. I have encountered myself with lots of foreach and if statements, which could be easily replace with LINQ.</p>
<p>But I have this code snippet, that I wonder how I could make it more functional style.</p>
<pre><code>foreach (var notification ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T20:44:12.267",
"Id": "74117",
"Score": "0",
"body": "What type `notifications` have? What type notification ID have?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T20:45:11.050",
"Id": "74119",
... | [
{
"body": "<p>LINQ isn't a silver bullet. It stands for Language-INtegrated-<strong>Query</strong>, which allows <strong>querying</strong> objects.</p>\n\n<p>Querying objects isn't something that's supposed to have side-effects. However this is precisely what you loop's body is doing.</p>\n\n<p>Therefore, refac... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T20:37:40.317",
"Id": "42977",
"Score": "10",
"Tags": [
"c#",
"linq",
"email"
],
"Title": "Refactor foreach statement to LINQ"
} | 42977 |
<p>Here is the code for the <code>CString</code> class that I created.</p>
<pre><code>public class CString {
public String reverse(String s) {
char[] array = new char[s.length()];
array = s.toCharArray();
for(int i=0; i<array.length/2; i++) {
char tmp = array[i];
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T21:24:45.063",
"Id": "74128",
"Score": "6",
"body": "Have you not checked for bugs yourself? We are not a debugging service. We review working code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T2... | [
{
"body": "<p>The code appears to be functionally correct, although you could simply choose to use a <code>StringBuffer.reverse()</code>. There is some discussion of this <a href=\"https://stackoverflow.com/questions/2439141/what-is-the-most-efficient-algorithm-for-reversing-a-string-in-java\">here</a>.</p>\n\n... | {
"AcceptedAnswerId": "42985",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T21:20:59.407",
"Id": "42981",
"Score": "26",
"Tags": [
"java",
"strings",
"array"
],
"Title": "Reverse a String in Java"
} | 42981 |
<p>I have \$k\$ sorted <code>List</code>s, each of size \$n\$. Currently I have hard-coded 5 sorted <code>List</code>s each of size 3, but in general that is configurable. </p>
<p>I would like to search for single element in each of the \$k\$ <code>List</code>s (or its predecessor, if it doesn't exist).</p>
<p>Obviou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T02:00:13.320",
"Id": "74167",
"Score": "0",
"body": "Question: In your text you say: *I would like to search for single element in each of the k Lists (or its predecessor, if it doesn't exist).* but in your code you get the `*succes... | [
{
"body": "<p>I think you have some misguided assumptions here.</p>\n\n<p>For a start, what you have now is not \\$O(k \\log(n))\\$, it first scans and sorts all the data in to the tree, which is a \\$O(N \\log(N))\\$ operation, where \\$N\\$ is the cumulative data size (sum of input-array sizes). Then, the che... | {
"AcceptedAnswerId": "42988",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T21:25:23.543",
"Id": "42982",
"Score": "11",
"Tags": [
"java",
"optimization",
"performance",
"algorithm",
"search"
],
"Title": "Finding an element in multiple sorted l... | 42982 |
<p>In this assignment, I'm supposed to split a string using <code>strtok</code>. (The assignment consists of the comment and the function definition; I fill in the function body.)</p>
<p>It works as far as I've tested. But it seems a little ugly to me. Perhaps it's my Java background, but somehow this just doesn't fee... | [] | [
{
"body": "<p>The key point in tokenizing strings is that</p>\n\n<blockquote>\n <p>The number of resulting token would not be known in prior</p>\n</blockquote>\n\n<p>One good approach is the one you have followed,</p>\n\n<ul>\n<li>Allocate some memory</li>\n<li>Use it</li>\n<li>Allocate more if needed</li>\n</... | {
"AcceptedAnswerId": "43149",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T22:23:11.993",
"Id": "42990",
"Score": "8",
"Tags": [
"c",
"strings",
"memory-management"
],
"Title": "Tokenizing string using strtok"
} | 42990 |
<p>I am now writing a small bash script that updates an Intel NIC driver to the latest version from the official website. Is there any way to improve\simplify the script? I want to avoid a lot of "if...else" stuff. Helpful tips will be appreciated!</p>
<pre><code>#! /bin/bash
DRV_PKG_NAME="e1000e-3.0.4.tar.gz"
DRV_PK... | [] | [
{
"body": "<p>Here is simplified version of the script:</p>\n\n<pre><code>#! /bin/bash\n\nDRV_PKG_NAME=\"e1000e-3.0.4.tar.gz\"\nDRV_PKG_URL=\"http://downloadmirror.intel.com/15817/eng/e1000e-3.0.4.tar.gz\"\nERR_LOG=\"err.log\"\n\n# Redirecting all stderr \nexec 2>$ERR_LOG\n\n# Function declaration\nerror_act... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T23:09:36.803",
"Id": "42991",
"Score": "12",
"Tags": [
"bash",
"linux",
"shell"
],
"Title": "Bash script that updates Intel e1000e driver"
} | 42991 |
<p>I have an ASP.NET MVC 5 web application using the repository pattern, and I have several controllers that need to call my <code>_loggingService</code> (queries audit logs) to get the last updated information for certain pages, not all pages.</p>
<p>I want to abstract this method into a common place, so that I don't... | [] | [
{
"body": "<p>Well, my first attempt is to suggest injecting a mapper into the controllers you want to do this for (assuming you are using a DI framework. If not anyone of the popular choices out there will meet your needs. AutoMapper, Unity, Autofaq etc).</p>\n\n<pre><code>public interface IMap<TTarget, T... | {
"AcceptedAnswerId": "43003",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T23:18:48.527",
"Id": "42995",
"Score": "3",
"Tags": [
"c#",
"unit-testing",
"asp.net-mvc-5"
],
"Title": "Web application using the repository pattern"
} | 42995 |
<p>The below code is for printing level-by-level in a binary tree:</p>
<pre><code>//level order printing
public static void levelOrderPrint(Node root){
Queue<Node> que = new LinkedList<Node>();
Node mark = new Node(0);
if(root != null){
que.add(root);
que.add(mark);
}
wh... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T00:12:06.337",
"Id": "74165",
"Score": "3",
"body": "Hi and welcome to Code Review! To the best of your knowledge does this code works ? We won't review your code if you think there is bug in it, but if you think all your code works... | [
{
"body": "<p>This is good code.</p>\n\n<h2>General</h2>\n\n<p>While it does what it says it will do, here is one beef I have with it, but it's a small one:</p>\n\n<blockquote>\n<pre><code> Node temp = que.poll();\n if(temp != mark)\n System.out.print(temp.key);\n</code></pre>\n</blockquote>\n\n<p>No b... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T23:46:17.117",
"Id": "42997",
"Score": "3",
"Tags": [
"java",
"algorithm",
"tree"
],
"Title": "Printing the values on each level of a Binary Tree"
} | 42997 |
<p>Things I can think of include integer overflow, if the input type is int, etc. But other than that, what do you think is wrong with this code, design-wise, style-wise, and also in terms of other edge/corner cases?</p>
<p><strong>binaryheap.h</strong></p>
<pre><code>#ifndef INCLUDE_BINARYHEAP_H_
#define INCLUDE_BIN... | [] | [
{
"body": "<p>Since you seem to be tryingy to mimic the style of STL containers (at least, that's what your comments say), there are several things you could improve:</p>\n\n<h2>STL containers subtypes</h2>\n\n<p>Most of the STL containers have subtypes. I am pretty sure that some parts of the standard library ... | {
"AcceptedAnswerId": "43050",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T01:10:53.933",
"Id": "42999",
"Score": "15",
"Tags": [
"c++",
"stl",
"heap"
],
"Title": "Implementation of binary heap in C++"
} | 42999 |
<p>The following is an <code>TaskScheduler</code> that always run tasks in a thread it maintains.
When created, a name of the thread was specified. Once you schedule the first task, until it is been <code>Dispose</code>ed, a thread will be created and wait for tasks to execute.</p>
<p>The reason of this class is that ... | [] | [
{
"body": "<p>Not exactly a review, but since you are asking for simpler way... The simpler way is to run your tasks via dispatcher. Just run it on background thread:</p>\n\n<pre><code>_thread = new Thread(() =>\n {\n _dispatcher = Dispatcher.CurrentDispatcher;\n ... | {
"AcceptedAnswerId": "43957",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T01:13:08.547",
"Id": "43000",
"Score": "22",
"Tags": [
"c#",
"multithreading",
"thread-safety",
"task-parallel-library"
],
"Title": "A TaskScheduler that always run tasks i... | 43000 |
<p>I build phone apps and I use JSON a lot in my APIs. The problem is sometimes I don't know how to format the JSON data.</p>
<p>For example, an iOS <code>UITableView</code> takes <code>NSArray</code> as datasource.</p>
<pre><code>{
"contact_id": [
"455",
"464"
],
"contact_name": [
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T03:12:52.187",
"Id": "74179",
"Score": "0",
"body": "While I prefer the second approach, I don't know what is \"unsafe\" about the first. One reason to advise against the first is that you have to remember if you ever modify one you... | [
{
"body": "<p>Keep related data together.</p>\n\n<ul>\n<li>Does your application need a list of contacts? Keep each contact intact with the second approach. Merging data to create and pass a single contact takes work and is error-prone. </li>\n<li>Does it need a list of contact IDs? Do the same or return just t... | {
"AcceptedAnswerId": "43073",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T02:53:14.710",
"Id": "43004",
"Score": "4",
"Tags": [
"objective-c",
"json"
],
"Title": "Array of Objects or Array of arrays?"
} | 43004 |
<p>I was asked this interview question recently. I was able to come up with this which runs in <span class="math-container">\$O(k \log n)\$</span>.</p>
<blockquote>
<p>Given k <= n sorted arrays each of size n, there exists a data structure requiring <span class="math-container">\$O(kn)\$</span> preprocessing tim... | [] | [
{
"body": "<p><span class=\"math-container\">\\$O(k + \\log n)\\$</span> seems highly suspect to me. For large values of <span class=\"math-container\">\\$n\\$</span> this is equivalent to <span class=\"math-container\">\\$O(\\log n)\\$</span> while for small values it's equivalent to <span class=\"math-contain... | {
"AcceptedAnswerId": "43014",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-02-28T03:23:48.890",
"Id": "43006",
"Score": "9",
"Tags": [
"java",
"algorithm",
"interview-questions",
"search"
],
"Title": "Extracting elements from multiple sorted lists effic... | 43006 |
<p>I'm working on extending the functionality of a photo gallery by adding a thumbnail display, I have multiple if statements set up to adjust the position of the thumbnails. Obviously this is not ideal, I'm trying to put my head around how to use a for loop to iterate the width multiplier and curSlide position.</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T03:51:14.567",
"Id": "74192",
"Score": "0",
"body": "How does `curSlide` change over time in this code? It looks quite fixed, and I suspect you omitted the looping code calling this function. Please provide enough context to advise ... | [
{
"body": "<p>Because you have nice, predictable ranges, you don't need a loop at all. Just do a little math.</p>\n\n<pre><code>var thumbGalwidth = 795;\n\nvar n = Math.floor(((currSlide || 1)-1) / 5);\n\njQuery('#view-all-container').css('margin-left', '-' + thumbGalwidth*n + 'px');\n</code></pre>\n\n<hr>\n\n<... | {
"AcceptedAnswerId": "43009",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T03:40:13.753",
"Id": "43007",
"Score": "5",
"Tags": [
"javascript",
"jquery"
],
"Title": "Repositioning images in a gallery based on the current image"
} | 43007 |
<p>I've written a function that works fine, but being new to jQuery, I'd like some reviews on writing this more cleanly. Anything advice would help; just trying to learn!</p>
<pre><code>function displayContent() {
var $link1 = $('.row.nav li a.bio');
var $link2 = $('.row.nav li a.stylist');
var $link3 = $('.row.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T04:06:06.680",
"Id": "74196",
"Score": "0",
"body": "When you say `// same code here` does that mean that both of those handlers are identical?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T04:11:01... | [
{
"body": "<p>Using <code>$(this)</code> is very helpful in situations where you have similar/same code. The way it works, is if say you have a class <code>.general</code> , which 50 different div's on the page all have that class. But lets say, if a user clicks on any one of those 50 div's , you want ONLY tha... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T04:00:03.897",
"Id": "43010",
"Score": "7",
"Tags": [
"javascript",
"jquery",
"beginner"
],
"Title": "Removeclass addclass multiple selectors optimization"
} | 43010 |
<p>I am using Netty embedded within Grails to process and display incoming SNMP messages. Since Netty 4 doesn't come with a built-in <code>ChannelExecutionHandler</code> I had to make my own and would like some feedback on it.</p>
<pre><code>package org.ciscotalk.common.netty;
import io.netty.buffer.ByteBuf;
import i... | [] | [
{
"body": "<p>So your code/concept looks functional to me. There are some comments though... and they are a bit scattered, forgive me....</p>\n\n<h2>Threads</h2>\n\n<p>You use the <code>Executors</code> class to create three ExecutorServices. Each of these services create threads that <a href=\"http://docs.orac... | {
"AcceptedAnswerId": "43146",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T04:55:09.333",
"Id": "43015",
"Score": "6",
"Tags": [
"java",
"multithreading",
"networking",
"concurrency"
],
"Title": "Producer/Consumer implementation"
} | 43015 |
<p>The following Java code reads lines from an input text file and will output the entry that has the highest number in field-2 to an output file:</p>
<p><strong>INPUT:</strong></p>
<blockquote>
<p>William J. Clinton 6 Q1124 <br>
42nd President of the United States 6 Q1124 <br>
Bill Clinton,6,Q1124 <br>
Bill ... | [] | [
{
"body": "<p>I'm far from a Java expert, but a few things jumped out at me</p>\n\n<hr>\n\n<p>You forgot to close the reader (<code>br</code>).</p>\n\n<hr>\n\n<p>Do not close the streams inside of the try. What happens if an exception gets thrown before the close commands are reached? You need a <code>finally</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T05:24:31.323",
"Id": "43017",
"Score": "5",
"Tags": [
"java"
],
"Title": "Read line and combine duplicate entries based on one of the fields"
} | 43017 |
<p>Header file:</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct linked_list linked_list;
typedef struct cons cons;
void append(cons *cons, int value);
void linked_list_append(linked_list *ll, int value);
int size(linked_list *ll);
void insert_after(cons *c, ... | [] | [
{
"body": "<p>Several things that stick out to me at a glance:</p>\n\n<ul>\n<li><p>What is <code>cons</code>? Don't you mean <code>Node</code>? At first I thought it was just a short form of constructor, but it appears to be corresponding to a node.</p></li>\n<li><p>I'd strongly recommend using a different va... | {
"AcceptedAnswerId": "43040",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T05:34:57.200",
"Id": "43018",
"Score": "4",
"Tags": [
"c",
"linked-list",
"memory-management",
"interface"
],
"Title": "Singly linked list implementation in C"
} | 43018 |
<p>I have the following code for the <em>Rock, Paper, Scissor</em> game. The code works fine in Python 2.7. Are there other more concise, more readable, or more pythonic ways of solving this problem in Python? </p>
<pre><code>player1 = raw_input ("?")
player2 = raw_input ("?")
if (player1 == 'rock' and player2 == 'sc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T12:28:52.853",
"Id": "74276",
"Score": "0",
"body": "What’s wrong with it? It seems to work as expected for me."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T13:03:07.233",
"Id": "74280",
"S... | [
{
"body": "<p>Here are some suggestions:</p>\n\n<ul>\n<li><p>We have three <code>if</code> statements that end in <code>\"Tie\"</code>. We could take all three conditions at once (<code>(player1 == 'scissors' and player2 == 'scissors') or ...</code>), or we could notice that we want the two players to have pick... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T06:10:19.927",
"Id": "43024",
"Score": "3",
"Tags": [
"python",
"game",
"rock-paper-scissors"
],
"Title": "Use if/else/elif conditionals to write a basic Rock Paper Scissors game"... | 43024 |
<p>Review this code.</p>
<pre><code>mode = "PARALLE"
try:
if mode == "PARALLEL":
# some code - this will not raise ValueError
elif mode == "SERIES":
# some code
else:
raise ValueError("Error: Invalid mode")
except ValueError, Argument:
print Argument
phase = "inverte"
try:
if phas... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T06:44:05.200",
"Id": "74225",
"Score": "0",
"body": "Do you expect `# some code` to raise `ValueError` sometimes?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T06:54:13.993",
"Id": "74226",
... | [
{
"body": "<h2>Enums and typos</h2>\n\n<pre><code>mode = \"PARALLE\"\n</code></pre>\n\n<p>Typo! To avoid this, you should use a variable: <code>PARALLEL = 1</code> or <code>PARALLEL = 'PARALLEL'</code> and <code>mode = PARALLEL</code>. Any typo will then be catched by Python when running the program. The upperc... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T06:19:01.753",
"Id": "43026",
"Score": "-1",
"Tags": [
"python",
"python-2.x",
"error-handling"
],
"Title": "Use of multiple value errors in Python"
} | 43026 |
<p>Call from my index.php to function <code>get_data($curr_date)</code> goes from here</p>
<pre><code>case "events" :
$curr_date = $_POST['current_date'];
if ( $eid = get_data($curr_date) )
{
$result = array( "success"=>tru... | [] | [
{
"body": "<p>Maybe it's better to return error in JSON (if FAIL constant isn't JSON yet)</p>\n\n<pre><code>echo json_encode(array('result' => false));\n</code></pre>\n\n<p>instead of</p>\n\n<pre><code>echo FAIL;\n</code></pre>\n\n<p>or return HTTP error code</p>\n\n<pre><code>header('HTTP/1.1 500 Internal S... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T07:07:49.453",
"Id": "43028",
"Score": "2",
"Tags": [
"php",
"json"
],
"Title": "Return JSON array through PHP"
} | 43028 |
<p>I have a Ruby code segment which I need to DRY up. Can it be done without meta programming?</p>
<pre><code>def disable_attribute
statement1
@response = Client::Service.disable_attribute(
param1: param1value,
param2: param2value
)
statement2
end
def enable_attribute
statement1
@response = Cli... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T09:26:06.720",
"Id": "74247",
"Score": "0",
"body": "those methods have no arguments for the attribute that's being updated?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T13:03:44.970",
"Id": "7... | [
{
"body": "<p>How about:</p>\n\n<pre><code>def toggle_attribute\n statement1\n @response = yield(\n param1: param1value,\n param2: param2value\n )\n statement2\nend\n\ndef disable_attribute\n toggle_attribute { |params| Client::Service.disable_attribute(params) }\nend\n\ndef enable_attribute\n toggl... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T07:45:09.293",
"Id": "43031",
"Score": "4",
"Tags": [
"ruby"
],
"Title": "Ruby methods to enable and disable attributes"
} | 43031 |
<p>I wrote this function as part of interview practice. This method removes a character from a given string.</p>
<p>I was wondering how I could make this code more efficient when it comes to runtime/space. I think my code is O(n) and I'm not sure if I can increase the efficiency. However, perhaps using things such as ... | [] | [
{
"body": "<p>Learn from existing implementations, they usually have solutions to corner cases, common pitfalls and performance bottlenecks. For example, Apache Commons Lang <a href=\"http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html\"><code>StringUtils</code></a> a... | {
"AcceptedAnswerId": "43034",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T07:54:44.230",
"Id": "43032",
"Score": "8",
"Tags": [
"java",
"beginner",
"performance",
"strings",
"memory-management"
],
"Title": "Increase performance of removing ch... | 43032 |
<p>This is an algorithm I'm trying to optimize. I was trying to use openMP without any success.</p>
<p>I know the code is long but most of it is params init.</p>
<p>Please try to explain why I need to change any line of code. I want to learn. I also wish to understand if using openMP is the best way for matrix base... | [] | [
{
"body": "<p>I would have placed this as a comment, but it's too long.</p>\n\n<p>Here are some observations to make the code shorter and manageable:</p>\n\n<blockquote>\n <p>I know the code is long but most of it is params init</p>\n</blockquote>\n\n<p>The code is not only long, but also repetitive in some ca... | {
"AcceptedAnswerId": "43054",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T08:11:12.253",
"Id": "43033",
"Score": "1",
"Tags": [
"c++",
"optimization",
"matrix"
],
"Title": "Performance with C++ algorithm"
} | 43033 |
<p>I made a PHP mailer script does the basic validation of fields, return errors, else submit if all is good. But it also has a honeypot field that is not required to be filled in (I'm assuming by hiding it using CSS a spambot will fill in the field anyway). If the field is not empty, it opens a text file and writes/a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T16:52:03.223",
"Id": "74322",
"Score": "0",
"body": "You have some mismatched double quotes. Please recheck your code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T11:58:47.683",
"Id": "74426",... | [
{
"body": "<p>There are no security vulnerabilities per se present, as far as I can see (however, <a href=\"https://codereview.stackexchange.com/a/43091/21609\">200_success did find one rather important one</a>). But if you're security-conscious, you would probably want to practice <em>defensive programming</em... | {
"AcceptedAnswerId": "43045",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T09:14:43.987",
"Id": "43037",
"Score": "26",
"Tags": [
"php",
"beginner",
"security",
"email"
],
"Title": "Are there any open vulnerabilities in this mailer script?"
} | 43037 |
<pre><code>import java.util.*;
import java.io.*;
public class Player
{
Scanner read;
PrintWriter write;
private String playerid;
private int playerscore;
int x = 0;
ArrayList<String> n = new ArrayList<String>();
ArrayList<Integer> s = new ArrayLis... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T10:16:14.700",
"Id": "74252",
"Score": "2",
"body": "This is technically working code (I assume - haven't tried it) but you are still asking \"How to add both player's score\". This should be in StackOverflow since your program does... | [
{
"body": "<p>This is my code review. I added new class ScoringEngine please look on it. There can be made more but you have to specify what you want to achieve. I added some comments in classes.</p>\n\n<pre><code>public class Player // implements Comparable<Player> there is no need to implement that int... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T10:04:41.577",
"Id": "43043",
"Score": "2",
"Tags": [
"java"
],
"Title": "High score list - adding info from two players"
} | 43043 |
<p>I have built the following code to download stock data from Yahoo Finance. The plan is to then use the built-in <code>pandas</code> functions to calculate metrics from this data that will then be used as features for classification. I also try to calculate whether or not the asset performed better, worse, or equal t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T12:52:33.003",
"Id": "74278",
"Score": "0",
"body": "I'm not all that familiar with the `pandas` package, but I believe `getWinners` should be more aptly named `getWinnersAndLosers` since it doesn't just filter out the losers."
},... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T11:49:16.627",
"Id": "43052",
"Score": "1",
"Tags": [
"python",
"beginner",
"pandas"
],
"Title": "Generate features for future ML analysis of asset returns"
} | 43052 |
<p>I've refactored the string calculator kata as much as I could and tried to maintain single responsibility. Is there anything I could factor differently? The specs can be reviewed <a href="http://osherove.com/tdd-kata-1/" rel="nofollow">here</a>.</p>
<pre><code>module StringCalculator
def self.add(string)
stri... | [] | [
{
"body": "<p>I think your code is pretty good. The main opportunity for improved clarity I saw was to consolidate your validation code into one place. In your code, validations are sprinkled across various methods, so that you are mixing the responsibility of \"validation\" and \"work\". </p>\n\n<p>Here's a... | {
"AcceptedAnswerId": "43159",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T13:21:57.290",
"Id": "43057",
"Score": "2",
"Tags": [
"ruby",
"calculator"
],
"Title": "Refactoring a String Calculator"
} | 43057 |
<p>I'm trying to reduce the complexity of some methods, and I'm not exactly sure what approach to take. I'm currently building a PHP wrapper for a REST API, and the main problematic class is here:</p>
<p><a href="https://github.com/petrepatrasc/blizzard-starcraft-api/blob/master/Service/ApiService.php">https://github.... | [] | [
{
"body": "<p>You could remove some duplication with a <code>getPortraitValue</code> function:</p>\n\n<pre><code>function getPortraitValue($apiData, $key) {\n $portrait = $apiData['portrait'];\n if (isset($portrait[$key])) {\n return $portrait[$key];\n }\n return null;\n}\n\n$portrait = new P... | {
"AcceptedAnswerId": "43060",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T13:24:48.243",
"Id": "43058",
"Score": "5",
"Tags": [
"php",
"optimization",
"api",
"complexity"
],
"Title": "Reducing complexity of method"
} | 43058 |
<p>I have some PHP code I'm working on which contains 2 queries and I need to set extra conditions for 2 out of 3 view options and one less query for 1 out of 3 view options.</p>
<p>Basically, I'm rendering a history list of shows with three options ALL | PRO | UPCOMING. The ALL option should include both queries and ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T14:34:53.687",
"Id": "74298",
"Score": "0",
"body": "Welcome to Code Review! Are you asking code to be written ? Here at Code Review, we are reviewing working and complete code. If you need help to code something this is not the goo... | [
{
"body": "<p>(What's curious is that you are setting <code>$view = 'all'</code>, and then immediately testing if it's set to <code>'upcoming'</code> or <code>'pro'</code>, I don't see any where else that <code>$view</code> is being assigned a value.)</p>\n\n<p>But, with that issue aside, it took me a bit to fi... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T14:05:50.960",
"Id": "43063",
"Score": "2",
"Tags": [
"php",
"mysql"
],
"Title": "Rendering a history list of shows with different options"
} | 43063 |
<p>Things that I'm not sure about:</p>
<ol>
<li>Whether this works in all use cases - alongside routing and within templates etc</li>
<li>Am I polluting the scope with all these variables? This seems to be the easiest way to do unit tests - or should I be passing the vars into the function? Some ( documentHeight, USer... | [] | [
{
"body": "<p>Nice work!<br/>\nI presume the complicated way of getting the right element measurements is to cater for many browsers, won't comment on that.</p>\n\n<ul>\n<li><p>I would add some comments on the nature of the 'magic number' \n<code>scope.triggerOffset = 150;</code> or, better, encapsulate it away... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T14:37:11.437",
"Id": "43064",
"Score": "6",
"Tags": [
"javascript",
"angular.js",
"modules"
],
"Title": "Improvements to an Angular ScrollSpy module"
} | 43064 |
<p>For several months I'm working with JavaScript and <code>THREE.JS</code> library. Firstly I dislike the prototype-based programming because I have to work a lot of with class-oriented languages, where any class is represented as the type and there is a strict separation between declaration and behavior of program de... | [] | [
{
"body": "<p>All in all, that is some pretty impressive code, I only have some minor comments.</p>\n\n<ul>\n<li><p>Instead of returning -1, I would suggest to simply throw a</p>\n\n<pre><code>new Exception('informative message')\n</code></pre></li>\n<li><p>This :</p>\n\n<pre><code>GC3D.Cube.prototype.setPositi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T15:25:09.880",
"Id": "43068",
"Score": "2",
"Tags": [
"javascript",
"object-oriented",
"prototypal-class-design"
],
"Title": "Prototype OO-style of my THREE.JS application"
} | 43068 |
<p>Is there a better way to do this kind of array combination with a PHP native function like <code>array_combine</code>? I'm trying to improve my skills, and at certain points I note that I am using too many nested <code>foreach</code> for almost everything. </p>
<p><strong>Using PHP 5.4</strong></p>
<pre><code> ... | [] | [
{
"body": "<p>Using <a href=\"http://us1.php.net/manual/en/function.in-array.php\" rel=\"nofollow\">in_array</a> can be droped one <code>foreach</code></p>\n\n<pre><code>$result = array();\nforeach ($array['Permission'] as $key => $value) {\n if (in_array($key, $array['Moduleid'])) {\n $result[$key] = $... | {
"AcceptedAnswerId": "43108",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T15:41:42.980",
"Id": "43070",
"Score": "2",
"Tags": [
"php",
"array",
"php5"
],
"Title": "Is there a better way to combine these arrays?"
} | 43070 |
<p>In reviewing code in our application, I see a tension between what makes a convenient design for methods accessing database data versus coding to ensure that the JDBC resource objects are closed properly.</p>
<p>An example problem:</p>
<pre><code>// Application.java: Singleton class for objects which want to execu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-04T13:56:07.500",
"Id": "74953",
"Score": "0",
"body": "`if (LOG.isDebugEnabled()) {` and `if (Log4jUtils.isDebugLevel(LOG)) {` looks like they checked the same thing, but they are not the same, is there a difference ? Do you really ne... | [
{
"body": "<p>JDBC has always been a PITA when it comes to handling/closing resources.</p>\n\n<p>One of the big advancements in the past while has been the advent of ConnectionPools and abstraction layers.... If you are inside a framwork like tomcat, or WebSphere, these are built in. Otherwise you can use thing... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T15:45:42.307",
"Id": "43072",
"Score": "3",
"Tags": [
"java",
"jdbc"
],
"Title": "Design considerations for classes/methods using JDBC to ensure resources closed correctly"
} | 43072 |
<p>I have the following key value pair in an array, and am trying to extract and load them into a collection.</p>
<p>The below code is working but it can be optimized using Linq:</p>
<pre><code>string _data = "Website=url:www.site1.com,isdefault:true,url:www.site2.com,isdefault:true";
List<WebSiteAddress> _web... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T16:27:41.053",
"Id": "74316",
"Score": "0",
"body": "There's some discussion about where this belongs. Someone (not the OP) migrated/copied it here from [StackOverflow](http://stackoverflow.com/questions/22100017/how-to-get-the-spli... | [
{
"body": "<h3>Naming</h3>\n<p>I don't get the <code>_</code> underscore prefix. This typically identifies a <em>private field</em> (albeit controversial). I'm pretty sure there's a consensus about simple <code>camelCasing</code> for local identifiers.</p>\n<p>The name <code>_websiteList</code> is a bad one, fo... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T16:08:51.360",
"Id": "43074",
"Score": "3",
"Tags": [
"c#",
"strings",
"array",
"linq"
],
"Title": "How to get the Split value from collection?"
} | 43074 |
<p>I wrote a program for one of my Object Oriented Programming in Java classes(Program 2) and I got docked off because my method was too long, which I'm not complaining about.</p>
<p>I got the note: "Modularize more, method too long."</p>
<p>I was wondering what any of you more experienced programmers would do to sim... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T16:30:54.673",
"Id": "74318",
"Score": "0",
"body": "Crossposted from: http://stackoverflow.com/questions/22100184/how-to-modularize-more-efficiently"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T16... | [
{
"body": "<p>\" wondering what any of you ... would do to simplify/shorten my code...\"</p>\n\n<p>How about you use Switch statements rather than those cumbersome cascade of if/else statements? That should make it cleaner and more readable. </p>\n\n<p>Something like</p>\n\n<pre><code>switch(input) { \n cas... | {
"AcceptedAnswerId": "43079",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T16:16:51.000",
"Id": "43075",
"Score": "11",
"Tags": [
"java"
],
"Title": "Modularize more efficiently in an if/else setup"
} | 43075 |
<p>I validate this program for</p>
<pre><code>Non numeric inputs
x/0 type fractions
0/0 and 0/y type fractions
x/1 and x/x type fractions
-x/-y and x/-y type fractions
</code></pre>
<p>I'd appreciate it if someone can look at this code and tell where I can improve this coding. I'd also like to know about other vali... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-03T08:35:20.143",
"Id": "74691",
"Score": "0",
"body": "You say you validate for 5 cases. They beg to be automated tests."
}
] | [
{
"body": "<p>There are several things that can be improved in your code, I will point out some of them here.</p>\n\n<h3>Polymorphism</h3>\n\n<p>Your Addition/Subtraction/Multiplication/Division classes has a lot in common. You should use polymorphism and inheritance to use them better. You can make an abstract... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T18:29:47.083",
"Id": "43084",
"Score": "12",
"Tags": [
"java",
"calculator",
"rational-numbers"
],
"Title": "Java Fraction Calculator"
} | 43084 |
<p>This is the requirement I have (from the book: Cracking the Coding Interview)</p>
<blockquote>
<p>Imagine you have a call center with three levels of employees: fresher, technical lead (TL), and product manager (PM). There can be multiple employees, but only one TL or PM. An incoming telephone call must be allo... | [] | [
{
"body": "<p>Overall, code is easy to read.</p>\n\n<p>A few minor nit-picky items.</p>\n\n<p>Try not us use <code>booleans</code>, use <code>enums</code> instead.</p>\n\n<p>i.e. </p>\n\n<pre><code>public enum EmployeeStatus {\n OnCall,\n Available \n}\n</code></pre>\n\n<p>This allows you to add mo... | {
"AcceptedAnswerId": "43093",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T18:50:50.533",
"Id": "43087",
"Score": "23",
"Tags": [
"java",
"object-oriented",
"beginner",
"interview-questions",
"inheritance"
],
"Title": "Modelling a Call Center"... | 43087 |
<p>Some time ago I made my simple game loop, so here's the code:</p>
<pre><code>public class Game {
private final int TARGET_FPS = 60;
/** optimal waiting time in milliseconds */
private final long OPTIMAL_TIME = 1000 / TARGET_FPS;
/** last Frame time */
private long lastFrame;
private int fp... | [] | [
{
"body": "<p>I would expect that your loop will run at 62.5 FPS based on the code you have.... but with some variation on timers and rounding-down, I would expect that to drop slightly to 61 FPS occasionally.</p>\n\n<p>This would reflect your results where you see between 61 and 62 FPS.</p>\n\n<p>Why?</p>\n\n<... | {
"AcceptedAnswerId": "43090",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T18:55:45.937",
"Id": "43088",
"Score": "5",
"Tags": [
"java",
"game"
],
"Title": "Game Loop and FPS"
} | 43088 |
<p>I've been considering the pro's and con's between implementing my page objects with privately backed properties and lazily instantiating them or just returning new instances every time and am curious what other people think is the best practice.</p>
<p>For example, I could have something like;</p>
<pre><code> p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T20:43:22.090",
"Id": "74352",
"Score": "0",
"body": "Can you explain why this is considered too opinion based? You could easily provide data to support a design decision and it's codereview... is there any code review that isn't opi... | [
{
"body": "<p>That all really depends on one thing and one thing only:</p>\n\n<p><strong>How costly</strong> is the <code>_driver.FindElement(By.Id(\"Title\"));</code> operation?</p>\n\n<p>Secondly... OK then, maybe two things: <strong>How often</strong> do you plan on calling this method?</p>\n\n<p>If the oper... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T19:37:01.677",
"Id": "43094",
"Score": "-1",
"Tags": [
"c#"
],
"Title": "lazy instantiation and instance lifetimes in POM"
} | 43094 |
<p>I'm using jQuery's <code>.get()</code> method to load content from external HTML files into my main index file. I created 25 different functions, function <code>videoLoad1()</code>, function <code>videoLoad2()</code> etc, for the 25 videos that I'm loading separately when its corresponding link is clicked. The conte... | [] | [
{
"body": "<p>When you say </p>\n\n<blockquote>\n <p>I created 25 different functions for the 25 videos that I'm loading separately when its corresponding link is clicked. </p>\n</blockquote>\n\n<p>Does that mean you have multiple <code>function videoLoad#() {</code> ? </p>\n\n<p>I think this will help: </p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T19:54:53.430",
"Id": "43096",
"Score": "3",
"Tags": [
"javascript",
"beginner",
"jquery",
"html",
"ajax"
],
"Title": "Loading content from external HTML files"
} | 43096 |
<p>Currently I have a binary tree template setup where my main is using it with strings to make a question/answer game. I'm using a knowledge base that works as an interface to the binary tree that main uses. My code seems to work fine inserting/rearranging nodes as necessary but I think my design is pretty bad.</p>
<... | [] | [
{
"body": "<p>First of all, I'd rewrite the constructors to use member initialization lists instead of assignment in the body of the ctor (where possible). For example, Node's ctor could become:</p>\n\n<pre><code>Node(T& data) : data(data), lChild(nullptr), rChild(nullptr) { }\n</code></pre>\n\n<p>Your dest... | {
"AcceptedAnswerId": "43213",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T22:46:04.077",
"Id": "43101",
"Score": "5",
"Tags": [
"c++",
"object-oriented",
"c++11",
"tree"
],
"Title": "Binary tree/knowledge base design"
} | 43101 |
<p>I'm trying to implement a bunch of sorting algorithms in JavaScript, and I can't figure out why my shell sort is so slow. It's 6x slower than my merge sort, and only slightly faster than my insertion sort. I've seen another implementation online, but I'm more focused on making it clear and readable (as I have a blog... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T01:23:11.157",
"Id": "74389",
"Score": "2",
"body": "The `while` test should be `j >= gapSize` to keep from checking negative indices with `j - gapSize`, but that should barely make a dent in the speed."
},
{
"ContentLicense... | [
{
"body": "<p>@David Harkness sent my search in the right direction. As it is, the insertion sort portion is only going through one round for each gap, rather than walking up each round, so it's not actually going for more than one round, and most of the sorting isn't done until the gap is 1. When I start fixin... | {
"AcceptedAnswerId": "43117",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T23:40:49.057",
"Id": "43104",
"Score": "7",
"Tags": [
"javascript",
"algorithm",
"performance",
"sorting"
],
"Title": "How can I speed up my shell sort?"
} | 43104 |
<p>I got really tired of having this code in all of my classes and methods:</p>
<pre><code>public class SomeClass {
private static final Logger LOGGER = Logger.getLogger(SomeClass.class);
//...
public int someMethod() {
final String methodName = "someMethod()";
LOGGER.debug("Entering " ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T01:00:48.077",
"Id": "74384",
"Score": "0",
"body": "Is there a reason you picked that over just giving the method a different name?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T01:03:35.203",
... | [
{
"body": "<p>I have been through this loop (quite recently, actually), for a rather large project in a very commercial environment.</p>\n\n<p>Frankly, it's not sustainable.</p>\n\n<p>Let me run through some of the issues:</p>\n\n<ul>\n<li>getStackTrace() is not just slow, it is molasses, and it affects all thr... | {
"AcceptedAnswerId": "43139",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T00:42:36.957",
"Id": "43106",
"Score": "8",
"Tags": [
"java",
"design-patterns",
"logging"
],
"Title": "Overloading various logging methods"
} | 43106 |
<p>I have a few <code>if</code>, <code>else</code>-<code>if</code>, <code>else</code> clauses. The only different thing in the context of these clauses is my LINQ query, one clause has <code>StartsWith</code>, one clause has <code>Contains</code>, and the other does a simple match. Is there a way to have all of this ... | [] | [
{
"body": "<p>This should be more simplified and more clear, now we make the query to the devices context first, then we get the result, instead of repeating the same thing three times. Remember, always use <code>using</code> when dealing with objects that inherits <code>IDisposable</code>:</p>\n\n<pre><code>us... | {
"AcceptedAnswerId": "43114",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T01:57:13.653",
"Id": "43109",
"Score": "2",
"Tags": [
"c#",
"beginner",
"asp.net-mvc-4",
"asp.net-mvc"
],
"Title": "How can I simplify these if/else clauses?"
} | 43109 |
<p>I want to have a caching class to cache different types. I want each type to be cached in a different <code>MemoryCache</code> but in a generic way.</p>
<p>Am I doing it right? </p>
<pre><code>internal static class RecordsCache
{
private static Dictionary<string, ObjectCache> cacheStore;
static priv... | [] | [
{
"body": "<p>From my point of view, everything is well coded.</p>\n\n<p>Just some personal preference here:</p>\n\n<ol>\n<li><p>I would provide 1 more <code>Set<T></code> method which accepts a func as input instead of <code>List<T></code>:</p>\n\n<pre><code>public static void Set(string userId, in... | {
"AcceptedAnswerId": "43123",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T02:08:32.370",
"Id": "43111",
"Score": "4",
"Tags": [
"c#",
"cache"
],
"Title": "Generic MemoryCache class"
} | 43111 |
<p>I have a signup form in which the user has to enter the email address and after some quick asynchronous processing at the backend I have to tell the user that whether the email address is already registered or not.</p>
<p>Below is a sample example of the JSP page that I have created,</p>
<pre><code><input type=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T03:24:08.183",
"Id": "74407",
"Score": "1",
"body": "If you know that it is not advisable, why are you doing it in the first place ? Even if it does not have a direct interaction with the client, it is still in the view component. W... | [
{
"body": "<ol>\n<li><p>I've never used that <code>sql:setDataSource</code> JSTL tag but <a href=\"http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/sql/setDataSource.html\" rel=\"nofollow noreferrer\">the documentation is not promising</a>:</p>\n\n<blockquote>\n <p>Creates a simple DataSource suitable onl... | {
"AcceptedAnswerId": "43130",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T02:43:02.957",
"Id": "43115",
"Score": "5",
"Tags": [
"sql",
"mvc",
"ajax",
"jsp"
],
"Title": "Is it advisable to integrate SQL statements in the JSP pages that are not dis... | 43115 |
<p>I wanted to play around with the following idea:</p>
<blockquote>
<p>Give a paragraph, I wanted to find out the relative frequency of usage
of each of the five vowels. I wanted to plot a pie chart depicting
this.</p>
</blockquote>
<p>Here is my code:</p>
<pre><code>from sys import stdin
from re import sub
i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-02T11:57:00.577",
"Id": "74560",
"Score": "0",
"body": "Note that with the `autopct` option, the chart computes percentages automatically."
}
] | [
{
"body": "<p>I strongly advise against <code>CamelCase</code> for your variable names – consider <code>snake_case</code> instead. Why? Because consistency with existing Python code.</p>\n\n<p>I also suggest better spacing around your operators, e.g. <code>x == vowel</code> instead of <code>x==Vowel</code> and ... | {
"AcceptedAnswerId": "43127",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T05:32:22.090",
"Id": "43118",
"Score": "3",
"Tags": [
"python"
],
"Title": "Plotting Frequency of Vowels in a Paragraph"
} | 43118 |
<p>Earlier I posted a question about <a href="https://codereview.stackexchange.com/questions/42332/model-simulation-using-java-annotations">model simulation</a>, now I have code for model 'spatial' representation. My model consists of moving parts that can perform actions and each part occupies space within the model.<... | [] | [
{
"body": "<p>You have some broad-spectrum questions....</p>\n\n<ul>\n<li><p>If JGraph supports the features you need, then absolutely, you should use it.</p>\n\n<p>Writing code is fun, and challenging, and all those things.... but, at some point you have to maintain it. Maintaining code becomes tedious, especi... | {
"AcceptedAnswerId": "43133",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T08:55:37.843",
"Id": "43124",
"Score": "6",
"Tags": [
"java",
"algorithm"
],
"Title": "Model spatial representation"
} | 43124 |
<p>I previously attempted to make a C++ vector <a href="https://codereview.stackexchange.com/questions/42297/c-vector-implementation">here</a>, yet it was not very successful. Now I have made a basic reimplementation of it, so I'm checking that it is fine, and that I will not have to re make it again.</p>
<p>Note: I a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-04T17:54:58.137",
"Id": "75023",
"Score": "0",
"body": "Where are your test cases? And please, carefully check signatures of all members against 23.3.6 of [the draft Standard](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n37... | [
{
"body": "<p>You're still using leading underscores. Why?? They're reserved.</p>\n\n<p>Methods like size should be const:</p>\n\n<pre><code>size_type size() const\n{\n return __size;\n}\n</code></pre>\n\n<p>The <code>empty</code> method should return <code>size() == 0</code>, not <code>!__data</code>.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T12:49:39.403",
"Id": "43136",
"Score": "4",
"Tags": [
"c++",
"reinventing-the-wheel",
"vectors"
],
"Title": "Reimplementation of C++ vector"
} | 43136 |
<p>Do you see any inefficient parts with the following code? On internet I see 30 ms for 100.000 integers but I can sort 100.000 integers in 300ms. The data is random. I am using late 2013 macbook pro so I don't expect a 10x slowdown from CPU, but who knows.</p>
<pre><code>void mergesort2(int* list, int begin, int end... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T06:09:24.637",
"Id": "99096",
"Score": "0",
"body": "You have a memory allocation bug: you allocate with `operator new[]` but delete with `operator delete`. You should clean up `tmplist` with `delete [] tmplist;`"
}
] | [
{
"body": "<p>Few things here...</p>\n\n<ul>\n<li><p>the format of your input parameters is inconvenient. You should probably just replace the <code>begin</code> and <code>end</code> parameters with a single <code>size</code>. The method can then be called as:</p>\n\n<pre><code>mergesort2(list, middle, tmplist)... | {
"AcceptedAnswerId": "43143",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T13:46:31.267",
"Id": "43138",
"Score": "7",
"Tags": [
"c++",
"performance",
"sorting",
"mergesort"
],
"Title": "MergeSort performance"
} | 43138 |
<blockquote>
<p>Write the program <code>tail</code>, which prints the last <code>n</code> lines of its input. By default, <code>n</code> is 10, let us say, but it can be changed by an optional argument, si that
<code>tail -n</code>
prints the last <code>n</code> lines. The program should behave rationally no ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T17:00:40.893",
"Id": "74468",
"Score": "0",
"body": "I can't really help you on that, but limiting the line size to 100 chars is a mistake in my opinion."
}
] | [
{
"body": "<p>I don't think the program meets the requirements (i.e. "behave rationally no matter how unresonable the input") because it fails if the line size is greater than LINESIZE.</p>\n<p>To behave rationally it would perhaps, ideally:</p>\n<ul>\n<li>At least detect if a line is "too large&... | {
"AcceptedAnswerId": "43164",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T15:06:46.610",
"Id": "43142",
"Score": "12",
"Tags": [
"c",
"beginner",
"queue",
"pointers"
],
"Title": "Tail implementation in C"
} | 43142 |
<p>This is the situation :
the table order has a column with ID AUTO INCREMENT but (there is always a but)<br>
i can't use it because i don't want number order 1234567 after 5 years but i want 1/2014 , 1/2015 etc etc.
For doing this i have created this columns into the table :</p>
<pre><code>ID AUTO INCREMENT <--- ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T18:02:18.197",
"Id": "74475",
"Score": "0",
"body": "It would be more helpful if you included your database table schema."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T18:45:30.000",
"Id": "7447... | [
{
"body": "<pre><code>$query_Recordset4 = \"SELECT MAX(IDyear) AS maxyear FROM order\";\n</code></pre>\n\n<p>Whenever you need to postfix the name of a variable, class or anything else with number because you already used that name...you're doing it wrong. Either your function does too much and should be split ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T16:41:39.013",
"Id": "43147",
"Score": "2",
"Tags": [
"php",
"mysqli"
],
"Title": "Workaround for have 2 column with pseudo AUTO INCREMENT"
} | 43147 |
<p>I am writing a wrapper to Eigen QR for my personal use and I am wondering if there are any memory leaks or undocumented behavior in my implementation, especially in the function <code>get_QR()</code>.</p>
<p>The answer is as expected. This is related to my previous question <a href="https://stackoverflow.com/questi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T18:19:21.597",
"Id": "74477",
"Score": "1",
"body": "You mean apart from using `malloc` in C++ code?"
}
] | [
{
"body": "<p>First check that there are the enough command line parameters</p>\n\n<pre><code>// If there are not enough parameters\n//\n// If there are no parameters passed then\n// Then argv[1] is NULL\n// argv[2] is random\n int m = atoi(argv[1]);\n int n = atoi(argv[2]);\n</code><... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T16:45:00.397",
"Id": "43148",
"Score": "5",
"Tags": [
"c++",
"memory-management",
"matrix",
"eigen"
],
"Title": "Are there any memory issues with this Eigen QR wrapper?"
} | 43148 |
<p>I have recently adapted the popular <a href="http://leanmodal.finelysliced.com.au/" rel="nofollow">leanmodal</a> plugin (with permission). Being "intermediate" with JS (need to learn more), I was wondering if anyone would like to review my code for efficiency.</p>
<ul>
<li><strong>jQuery & JS</strong> - bad pra... | [] | [
{
"body": "<h1>Messy code?</h1>\n\n<p>Nah! It really depends on the developer. But I highly suggest you follow certain conventions for clean code, especially the parts regarding indentation, one-liners etc. There are quick tools online for cleaning up code, like JSBeautifier. There are also formatters for code,... | {
"AcceptedAnswerId": "43162",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T17:41:15.027",
"Id": "43155",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "Leanmodel plugin"
} | 43155 |
<p>I have code that works perfectly, but it uses too much memory.</p>
<p>Essentially this code takes an input file (lets call it an index, that is 2 column tab-separated) that searches in a second input file (lets call it data, that is 4-column tab separated) for a corresponding term in the 1st column which it then re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-02T10:20:41.747",
"Id": "74558",
"Score": "1",
"body": "Why does `anaconda` become `art` in the example? The index maps it to `anm`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-02T12:26:39.237",
"Id... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-01T18:08:21.363",
"Id": "43156",
"Score": "1",
"Tags": [
"python",
"optimization",
"memory-management",
"python-2.x"
],
"Title": "Optimize Python script for memory which opens an... | 43156 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.