body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I'm fairly new to Objective-C. The app I'm trying to make, is using the foursquare API to list up places that is close by. I've re-written this app more times than I care to admit, because I feel the implementation get messier the bigger the app gets. I take that as a sign that my basic code structure is in need of ... | [] | [
{
"body": "<p>Right now this is just a quick answer with some first impressions I notice before I get to work. I'll edit and improve this answer later.</p>\n\n<p>First of all, I don't like what's going on in your <code>init</code> method. We're wasting time initializing a handful of strings to literal values.... | {
"AcceptedAnswerId": "49721",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-12T22:15:12.523",
"Id": "49572",
"Score": "5",
"Tags": [
"beginner",
"objective-c",
"ios"
],
"Title": "App for listing places close by - building up models"
} | 49572 |
<p>I have written a partition function in Python (<code>my_partition_adv</code>). I have written this one after reading a similar function from a website. The version of the partition function from the website is also given below (<code>parititon_inplace</code>).</p>
<p>As I am a beginner in Python, I want to know t... | [] | [
{
"body": "<p>These two functions are doing somewhat different tasks. The first one partitions a subrange of a list; the second one may only partition an entire list.</p>\n\n<p>The use of <code>enumerate</code> is not justified in the first loop (<code>index</code> is not being used at all), and is quite suspic... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-12T22:57:58.830",
"Id": "49576",
"Score": "3",
"Tags": [
"python",
"beginner",
"python-2.x",
"comparative-review"
],
"Title": "Comparing two partition functions in Python"
} | 49576 |
<p>I was needed a SET-like data structure written in pure C for some university class, so I've implemented a simple one - the <a href="http://en.wikipedia.org/wiki/Treap">Treap</a> (or cartesian tree).</p>
<p>Please check if everything is okay (actually, I'm not sure that there isn't a memory leak there).</p>
<p>cart... | [] | [
{
"body": "<ul>\n<li><p>It's preferred to only call <code>srand()</code> once in <code>main()</code>. It's easier to maintain in this way as it'll avoid the possibility of calling <code>srand()</code> multiple times, which will give you the same random value with <code>rand()</code> each time. It should only ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-12T23:38:05.543",
"Id": "49582",
"Score": "7",
"Tags": [
"c",
"tree"
],
"Title": "Treap implementation in C"
} | 49582 |
<p>I'm in the process of creating a program that can model points, vectors, lines and segments. I have the classes built and confirmed to be working correctly. The classes are built to handle multiple dimensions, so as an example, the same point class is used for R1, R2, R3, ... Rn.</p>
<p>The issue that I am dealing ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-12T23:57:54.577",
"Id": "87203",
"Score": "1",
"body": "I'm not sure this is on topic for code review as this seems more like a work in progress from what you're describing."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>Okay, I'll throw in a review. The part more directly addressing your question is at the end</p>\n\n<p><strong>Naming</strong></p>\n\n<ul>\n<li><p>Usually in C# you will see PascalCase used for public members. For private members, it's a bit more varied, but _camelCase (note the prefixed underscore... | {
"AcceptedAnswerId": "49593",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-12T23:53:28.130",
"Id": "49585",
"Score": "4",
"Tags": [
"c#",
"exception-handling"
],
"Title": "Exceptions or something else?"
} | 49585 |
<p>I am learning how to implement a basic undirected graph and perform a depth first traversal.</p>
<p>Please critique my code for correctness, best practices, security, and any other comments that may be helpful.</p>
<p><strong>Graph.h:</strong></p>
<pre><code>#include <vector>
/*****************************... | [] | [
{
"body": "<p>This looks pretty clean. I have several things to address:</p>\n\n<ul>\n<li><p>No need to assign a member in the constructor body:</p>\n\n<pre><code>Vertex::Vertex() {visited = false;}\n</code></pre>\n\n<p>For this, prefer an initializer list:</p>\n\n<pre><code>Vertex::Vertex() : visited(false) {... | {
"AcceptedAnswerId": "49609",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T02:27:52.860",
"Id": "49595",
"Score": "8",
"Tags": [
"c++",
"homework",
"graph",
"depth-first-search"
],
"Title": "Depth First Traversal of a Graph"
} | 49595 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow">Learn You a Haskell</a> shows the <code>lines</code> function:</p>
<blockquote>
<p>It takes a string and returns every line of that string in a separate list.</p>
</blockquote>
<p>Example:</p>
<blockquote>
<pre><code>>lines' "HELLO\... | [] | [
{
"body": "<ol>\n<li><p>What happens when a string ends in a newline? <code>lines \"\\n\"</code> ⇒ <code>[\"\"]</code>, but <code>lines' \"\\n\"</code> ⇒ <code>[\"\", \"\"]</code>.</p></li>\n<li><p><code>ys</code> could have a more informative name. <code>line</code>?</p></li>\n<li><p><del>When you find yoursel... | {
"AcceptedAnswerId": "49603",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T02:56:56.567",
"Id": "49596",
"Score": "1",
"Tags": [
"haskell",
"reinventing-the-wheel"
],
"Title": "Implementing Haskell#lines"
} | 49596 |
<p>So I've been working on AI for a Tower Building simulation game for quite a few days, and I think the code would really benefit from review. I'm a hobbyist programmer, but I really care about doing things properly so don't be afraid to be harsh. I want to learn.</p>
<p>The basic idea of the job management system... | [] | [
{
"body": "<p>I think that <code>DTCharacter</code> object shouldn't know about the world size. You should create some <code>DTWorld</code> class and <code>DTCharacter</code> object should be added to this world. <code>DTCharacter</code> should have and reference to the world and should asking if there is possi... | {
"AcceptedAnswerId": "49770",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T03:59:26.670",
"Id": "49602",
"Score": "4",
"Tags": [
"game",
"objective-c",
"queue",
"simulation",
"ai"
],
"Title": "Worker AI and Job Queue Management for Simulation ... | 49602 |
<blockquote>
<p><strong>Question:</strong> To find the maximum number of consecutive zeros in a given
array.</p>
<p><strong>Example:</strong></p>
<p><strong>Input:</strong> \${1, 2, 0, 0, 2, 4, 0, 2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 0}\$</p>
<p><strong>Output:</strong> "Maximum number of consecutive ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T07:08:10.317",
"Id": "87232",
"Score": "0",
"body": "Suggestion, put `if (tempLength > maxLength) { maxLength = tempLength; }` in the else statement."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T07... | [
{
"body": "<p>Just a few short comments on your code:</p>\n\n<h3>Separation of concerns:</h3>\n\n<p>You should separate functionality into different parts. Currently your main method does everything. For small applications like this, that may not be a problem, but as soon as you have larger applications, it bec... | {
"AcceptedAnswerId": "49612",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T06:45:57.220",
"Id": "49610",
"Score": "18",
"Tags": [
"java"
],
"Title": "Find the maximum number of consecutive zeros in an array"
} | 49610 |
<p>For a school project, I am creating a text-based adventure game in C++. I have shown my code to my teacher and he is stating my code is not entirely logical in sequence and that I should make my <code>if</code> statements inside functions because there are so many. I need help as to know how to make these changes.<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T08:36:16.040",
"Id": "87245",
"Score": "3",
"body": "you shoudl probably have a decision class/method that contains the switch logic, the actual implementation of the logic in the decision should be in its own methods (and perhaps e... | [
{
"body": "<p>I agree with your teacher that breaking the code into functions will help the readability of your code. </p>\n\n<p>For example, put the code, for the result of each decision, in its own function.</p>\n\n<pre><code>cout << \"1. Go West\" << endl;\n...\n\nif (choice2 == 1) {\n go_west... | {
"AcceptedAnswerId": "49636",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T08:18:03.330",
"Id": "49614",
"Score": "25",
"Tags": [
"c++",
"console",
"adventure-game"
],
"Title": "Text-based adventure game with too many conditional statements"
} | 49614 |
<p>I developed this tickets booking system recently to showcase HTML5 features. I would like you to review it from the UI/UX perspective. Also if there is something more that I can add.</p>
<p>Is it good enough?</p>
<p><strong>JS/HTML5/CSS3:</strong></p>
<p><div class="snippet" data-lang="js" data-hide="false">
<di... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T10:36:41.177",
"Id": "96142",
"Score": "0",
"body": "It seems quite good but you even can make your code more optimized and with nice look UI by using Bootstrap CSS. You can find it here\n[Bootstrap](http://getbootstrap.com/)"
}
] | [
{
"body": "<h2>UX (User Experience)</h2>\n\n<p>I'll start with a few possible improvements to the User Experience functionality.</p>\n\n<ol>\n<li><p>In order to offer the best possible interface you have to provide the same or similar experience in all browsers, simply listing something isn't supported, in my m... | {
"AcceptedAnswerId": "54972",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T10:14:25.227",
"Id": "49623",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"css",
"html5",
"jquery-ui"
],
"Title": "Movie tickets booking system (Frontend only)"
} | 49623 |
<p>I am currently learning angular.js.</p>
<p>The following is an example I came up with. The goal:</p>
<ul>
<li>An editor for a dict, the dict format is: {key: [type, data]}</li>
<li>A view of the same data</li>
<li>The "type" should be validated. I use two types: "string" (can be anything) and "greeting" (a string ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T10:51:10.520",
"Id": "87258",
"Score": "0",
"body": "Welcome to Code Review! I find your question a little bit unclear. How does it work at the moment? Is there some desired feature you want but have problems implementing?"
},
{... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T10:22:09.430",
"Id": "49624",
"Score": "2",
"Tags": [
"javascript",
"html",
"angular.js"
],
"Title": "AngularJS with global data and \"service\" / using $watch on $rootScope"
} | 49624 |
<p>I use the jQuery Calendar with an underscore template and I wanted to put <code><li></code> tags around each week. This does the trick, but it's awful.</p>
<pre><code><% _.each(days, function(day, index) { %>
<% if ( index % 7 == 0 && index != 0) { %></li><% } %>
<%... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>you could definitely place the last <code>if</code> outside of the <code>_.each()</code>, this would be faster ( fewer <code>if</code>s ) and cleaner.</p>\n\n<p>I would also place the first <code><li></code> outside of the loop and then merge the 2 remaining <... | {
"AcceptedAnswerId": "49629",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T11:22:55.850",
"Id": "49627",
"Score": "6",
"Tags": [
"javascript",
"jquery",
"datetime",
"underscore.js"
],
"Title": "Seven days a week"
} | 49627 |
<p>I've created a pagination class in PHP. I've made it so it doesn't rely upon a database. Am I doing this correctly? is there anything you can suggest I improve?</p>
<pre><code><?php namespace Acme\Foo\Pagination;
class Pagination
{
public $perPage;
public $currentPage;
public $data;
public f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T13:24:27.040",
"Id": "87271",
"Score": "2",
"body": "_Never_ trust the network: `$_GET['page']` can be anything, at the very least, in your `setCurrentPage` method, cast its value to an integer"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T12:38:28.167",
"Id": "49630",
"Score": "1",
"Tags": [
"php",
"pagination"
],
"Title": "Pagination that doesn't rely on a database"
} | 49630 |
<p>In <a href="https://stackoverflow.com/questions/23563395/jquery-scrollto-and-hide-an-element">this post</a>, I asked how to scroll to an element and hide another via jQuery.</p>
<p>In my main javascript file I've made a script, but I'm not sure if it's correct. Can you tell me if this is a good way to do it, or if ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T21:07:19.937",
"Id": "98302",
"Score": "0",
"body": "Can you provide a jsfiddle for this one too?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T14:09:09.160",
"Id": "49639",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "scrollTo and hide element code improvements"
} | 49639 |
<p>The following code is ran when the user presses a button to generate a log file based on the date selected. The <code>DatePicker</code> has a restrictive selected date range of the last 2 weeks including that same day. If the user leaves the page open for more than one day (very common), they will however be able to... | [] | [
{
"body": "<ol>\n<li><p>I would store the result of <code>mSelectedData.getTime()</code> into a variable. It will save one method call and remove duplicate code.</p></li>\n<li><p>The line that resets the data range seems a tad out of place; however, I am not sure about the rest of your implementation, so this m... | {
"AcceptedAnswerId": "49653",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T15:23:24.300",
"Id": "49644",
"Score": "9",
"Tags": [
"datetime",
"logging",
"interval",
"actionscript-3",
"flex"
],
"Title": "Date range validation"
} | 49644 |
<p>I'm using Anemone to Spider a website, I am then using a set of rules specific to that website, to find certain parameters. </p>
<p>I feel like it's simple enough, but any attempt I make to save the products into arrays looks very messy.</p>
<p>the Rules are different for each site (the script is simply grabbing s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T08:15:40.077",
"Id": "87465",
"Score": "0",
"body": "Woops, well it is working code. at the moment though it simply displays the page url of product pages. I need it to store the rule data"
},
{
"ContentLicense": "CC BY-SA 3... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T15:51:56.497",
"Id": "49647",
"Score": "1",
"Tags": [
"ruby",
"array",
"ruby-on-rails",
"web-scraping"
],
"Title": "scraping and saving using Arrays or Objects"
} | 49647 |
<p>For context, I have a <code>SourceControlSystem</code> factory class that detects if a user is using Git, SVN, or another source control system and returns an object to interact with that source control system. The implementation is <a href="https://github.com/whitesmith/rubycritic/blob/master/lib/rubycritic/source_... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T17:41:45.527",
"Id": "87335",
"Score": "0",
"body": "I don't see the two places where you call `SourceControlSystem.create`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T17:51:04.747",
"Id": "8... | [
{
"body": "<blockquote>\n <p>Do you consider this to be a problem or not?</p>\n</blockquote>\n\n<p>This is good design! You make the state and the dependencies of your classes explicit. Imagine another developer needs to work with your code. He immediatly sees \"oh, this <code>turbulence</code> needs access to... | {
"AcceptedAnswerId": "49651",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T16:06:30.323",
"Id": "49649",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Avoid passing variable from class to class"
} | 49649 |
<p>I have a MVC framework, and I am struggling with the following dynamic menu code.</p>
<p>A menu is pretty much HTML, so technically it should reside in the View, but the dynamic part is driven by PHP and a config class that holds all the menu items.</p>
<ol>
<li><p>Where would I place this class? (model layer, vie... | [] | [
{
"body": "<p>Ok, firstly, you never want HTML in your controller. Always keep your output in your view, your application flow in the controller and your business logic in the model. Otherwise, this breaks separation of concerns (SoC). See <a href=\"https://stackoverflow.com/questions/1376643/mvc-separation-of-... | {
"AcceptedAnswerId": "49654",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T16:41:36.120",
"Id": "49650",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"mvc"
],
"Title": "How to re-factor dynamic menu code to OOP in a MVC framework?"
} | 49650 |
<p>I'm writing a function which gets two strings and a number <code>k</code> as an input, and outputs a string with length <code>k</code> which is present in both strings. I want to do this using the function <code>hash_sequence()</code>.</p>
<p>I need my code to be as efficient as possible because my inputs are very... | [] | [
{
"body": "<p>One easy thing you might do is switch from <code>range</code> to <code>xrange</code> -- <code>xrange</code> is a generator, while <code>range</code> constructs the entire iterable in memory.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA... | {
"AcceptedAnswerId": "49661",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T17:15:30.880",
"Id": "49655",
"Score": "2",
"Tags": [
"python",
"strings",
"python-3.x",
"hash-map"
],
"Title": "How can I optimize this hash string function?"
} | 49655 |
<p>I was wondering what I can do to increase the performance of this program. The algorithm is pretty slow right now but I was wondering what I can do to increase the efficiency of this program. I used lists instead of strings to avoid immutable string concatenation.</p>
<p>This program should compress strings by the... | [] | [
{
"body": "<p>The following code performs twice as fast as your code does on my machine, both for short strings (e.g. your example) and longer strings.</p>\n\n<pre><code>def compressBetter(string):\n last = string[0]\n result = []\n count = 1\n for c in string[1:]:\n if c == last:\n ... | {
"AcceptedAnswerId": "49663",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T17:55:45.127",
"Id": "49658",
"Score": "0",
"Tags": [
"python",
"strings",
"compression"
],
"Title": "Increase efficiency of basic string compressor"
} | 49658 |
<p>I have a RequestsExtensions class with two functions for sending GET/POST requests.</p>
<pre><code>using System;
using System.Net;
using System.Text;
public static class RequestsExtensions
{
/// <summary>
/// Sending POST request.
/// </summary>
/// <param nam... | [] | [
{
"body": "<p>First off your methods are not extension methods as the name <code>RequestsExtensions</code> would indicate. Not sure if this intentional or. If you want to make them true extension methods then I'd consider passing the <code>Url</code> parameter as <code>Uri</code> rather than as <code>string</co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T20:23:52.797",
"Id": "49671",
"Score": "8",
"Tags": [
"c#",
"asp.net"
],
"Title": "Sending GET/POST requests in .NET"
} | 49671 |
<p>Here's a (hopefully) better shared pointer than the previous one. The improvement is that now it should also accept function and lambda objects. Should work fine with threads.</p>
<pre><code>#pragma once
#ifndef LIGHTPTR_HPP
# define LIGHTPTR_HPP
#include <cassert>
#include <atomic>
#include <memo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T21:33:28.027",
"Id": "87382",
"Score": "0",
"body": "Just a comment: Must you be so free with vertical space?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T21:35:01.963",
"Id": "87383",
"Sco... | [
{
"body": "<p>Lets the obligatory (<strong>this is not a good idea</strong>) out of the way.</p>\n\n<p>I don't like you cramming all the code together into a single header definition. It makes it hard to see the interface. Yes the standard library do it this way but they are so heavily documented that they don'... | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T20:28:22.753",
"Id": "49672",
"Score": "1",
"Tags": [
"c++",
"c++11",
"smart-pointers"
],
"Title": "One more shared pointer"
} | 49672 |
<p>My website is poorly coded.</p>
<p>The structure is pretty simple:</p>
<ul>
<li>A RewriteRule redirects /.... to /index.php?page=$1</li>
<li>mypages/page.php contains the page content and actions (model controller and view glued together...)</li>
<li>index.php wrap the demanded page into a theme (basically include... | [] | [
{
"body": "<p>The first 'problem' I notice is what I call a roocky mistake (been there, done that) is the way you route a request.</p>\n\n<p>If a person requests <code>?page=mypage.php</code> you check or that file exists if so, you include it.\nthis means that your filesystem is hardcoded with your routing. Ev... | {
"AcceptedAnswerId": "49743",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T21:08:59.183",
"Id": "49675",
"Score": "2",
"Tags": [
"php",
"mvc",
"api"
],
"Title": "Member restricted game with API"
} | 49675 |
<p>This is a complete rewrite of the code posted for review <a href="https://codereview.stackexchange.com/questions/49409/python-barcode-generator">in this question</a>. The question is identical.</p>
<pre><code>def render(digits):
'''This function converts its input, a string of decimal digits, into a
barcode... | [] | [
{
"body": "<p>Normally I would just make this a comment, but I don't have enough rep here yet to do so. I haven't really done any Python at all, however this did catch my attention:</p>\n\n<blockquote>\n <p>The input string must not contain an odd number of digits.</p>\n</blockquote>\n\n<p>But there's no check... | {
"AcceptedAnswerId": "49728",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-05-13T21:39:09.530",
"Id": "49680",
"Score": "6",
"Tags": [
"python",
"interview-questions",
"svg"
],
"Title": "Python Barcode Generator v2"
} | 49680 |
<p>I have to work with C-style functions which return <code>ERROR_SUCCESS</code> when successful or an error code when not. I want my code to be nice and neat and easy to read but I am not sure I like what I have.</p>
<p>Option one:</p>
<pre><code>int Foo()
{
int result = Init();
if (result == ERROR_SUCCESS)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T13:39:55.350",
"Id": "87510",
"Score": "1",
"body": "Naming your function `Foo()` makes this borderline hypothetical code. Hypothetical code would be off-topic for Code Review, but I've allowed the question to stay open since `Init(... | [
{
"body": "<p>Do your early returns properly, and there will be no more to tweak:</p>\n\n<pre><code>int Foo()\n{\n int result;\n if((result = Init()))\n return result;\n if((result = SetTemperature( 30 )))\n return result;\n return SetVoltage( 5 );\n}\n</code></pre>\n\n<p>Using the ext... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T21:47:11.413",
"Id": "49681",
"Score": "6",
"Tags": [
"c++",
"error-handling",
"comparative-review"
],
"Title": "Checking errors from a series of function calls"
} | 49681 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow noreferrer">Learn You a Haskell</a> demonstrates the <code>break</code> function:</p>
<blockquote>
<p>breaks it when the predicate is first true.</p>
</blockquote>
<p>Example:</p>
<pre><code>-- ghci> break (==4) [1,2,3,4,5,6,7]
-- ... | [] | [
{
"body": "<p>The first <code>[]</code> case is unnecessary, since <code>break''</code> already handles empty lists.</p>\n\n<p><code>g</code> is unnecessary, since <code>f</code> is in scope.</p>\n\n<p><code>break''</code> has two nearly identical base cases, which could be combined into one (you may need to us... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T00:00:39.723",
"Id": "49687",
"Score": "2",
"Tags": [
"haskell",
"reinventing-the-wheel"
],
"Title": "Implementing Haskell#break"
} | 49687 |
<p>I'm attempting this simple HackerRank <a href="https://www.hackerrank.com/challenges/countingsort3" rel="nofollow">counting sort problem</a> but testcase #3, which has 100,000 test cases, is timing out. </p>
<p>Is there something particularly inefficient about this code? </p>
<pre><code>input = []
$stdin.each do |... | [] | [
{
"body": "<p><code>arr.count(j)</code> scans the array, so it takes linear time. Doing it once for each element of <code>arr.uniq</code> takes quadratic time. Doing it 100 times doesn't help either. :)</p>\n\n<p>The <code>arr.uniq.each</code> loop is unnecessary, though (as is the call to <code>uniq</code>). T... | {
"AcceptedAnswerId": "49707",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T00:51:28.210",
"Id": "49689",
"Score": "3",
"Tags": [
"performance",
"ruby",
"programming-challenge",
"sorting",
"time-limit-exceeded"
],
"Title": "Speed up counting so... | 49689 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow">Learn You a Haskell</a> shows the <code>words</code> function.</p>
<blockquote>
<p>words and unwords are for splitting a line of text into words or
joining a list of words into a text</p>
</blockquote>
<p>Example:</p>
<blockquote>
<p... | [] | [
{
"body": "<p><code>words</code> treats any whitespace as a separator, not just spaces. Use <code>Data.Char.isSpace</code>.</p>\n\n<p>It's fine otherwise.</p>\n\n<p>When reimplementing the standard library, you can exploit the standard version as a reference implementation to compare your version to:</p>\n\n<pr... | {
"AcceptedAnswerId": "49696",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T00:53:33.587",
"Id": "49690",
"Score": "2",
"Tags": [
"haskell",
"reinventing-the-wheel"
],
"Title": "Implementing Haskell#words"
} | 49690 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules">Learn You a Haskell</a> explains the <code>unwords</code> function.</p>
<blockquote>
<p>$unwords ["hey","there","mate"]<br>
"hey there mate"</p>
</blockquote>
<p>Here's my implementation.</p>
<pre><code>unwords' :: [String] -> String
unwords' ... | [] | [
{
"body": "<p>The <code>otherwise</code> case is redundant.</p>\n\n<pre><code>unwords' :: [String] -> String\nunwords' [] = []\nunwords' (x:xs) = x ++ \" \" ++ unwords' xs\n</code></pre>\n\n<p>To use a fold but not get the extra space, use <code>foldr1</code>:</p>\n\n<pre><code>unwords'' :: [String] -> St... | {
"AcceptedAnswerId": "49697",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T01:26:39.263",
"Id": "49693",
"Score": "6",
"Tags": [
"haskell",
"reinventing-the-wheel"
],
"Title": "Implementing Haskell's `unwords`"
} | 49693 |
<p>Please review code quality and give me shortcuts or optimization tips as well as corrections.</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Clean HTML Code</title>
</head>
<body>
<p><textarea id="code" cols="80" rows="15" autofocu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T05:44:56.513",
"Id": "87450",
"Score": "1",
"body": "I don’t know what this would be used for, but if it were for cleaning input by untrusted users, it is *woefully* inadequate. An example, and this is just the start: `<script>alert... | [
{
"body": "<p>First of all, <a href=\"https://stackoverflow.com/a/1732454/575527\">you can't parse HTML with regex</a>. RegEx is totally the wrong person for the job. Your code there assumes that the input HTML is properly formatted. If given broken HTML, you code won't even stand a chance. I suggest you use a ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T05:40:00.997",
"Id": "49706",
"Score": "2",
"Tags": [
"javascript",
"html"
],
"Title": "HTML cleaner in JavaScript"
} | 49706 |
<p>Here are all the threads write the log file. I want to know if the below script is fine, if it needs any modifications, and whether I am utilising threads properly to execute this code quickly.</p>
<pre><code>open(LOG,"+>","log.txt")or die "cant open the file";
my $file_total= scalar @listOfFiles;
my $di... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T09:49:58.963",
"Id": "87478",
"Score": "0",
"body": "I have some huge amount of document say 1 million.so iam collecting all the 1 million filenames and stored in the listOfFiles array.And dividing the array index based on no of thr... | [
{
"body": "<p>You can atomically write to a file if you are working with a threadsafe queue.</p>\n\n<pre><code>#!/usr/bin/env perl\n\nuse warnings FATAL => 'all';\nuse strict;\nuse Time::HiRes qw(time nanosleep);\nuse threads;\nuse Thread::Queue;\n\nmy $logQ = Thread::Queue->new();\n\nmy $consumer = threa... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-05-14T06:10:17.393",
"Id": "49708",
"Score": "3",
"Tags": [
"multithreading",
"logging",
"perl"
],
"Title": "Writing a log file with threads"
} | 49708 |
<p>I am a tyro with OOCSS and think I bit off more than I can chew in creating a dropdown bubble for a menu item.</p>
<p>I removed as much element specific code as I could, but still think I don't quite have it down. </p>
<p>I know my class names are all messed up, but I'm really just messing around right now.</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-30T21:06:42.313",
"Id": "90270",
"Score": "1",
"body": "you should add the HTML to this Question, I think that it would help us understand more of what is going on with the CSS"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creat... | [
{
"body": "<p>To be honest I don't quite understand what you are asking in your question, so I'll just do a general review:</p>\n\n<p>You said your class names are temporary (you should only be posting \"finished\" code here), however currently they are very confusing because they are all very generic or don't ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T06:41:42.647",
"Id": "49710",
"Score": "5",
"Tags": [
"css"
],
"Title": "Dropdown bubble for a menu item"
} | 49710 |
<p>Since you can't use regular expressions in Maxcript is there a better way to capitailse a string that may contain whitespace.</p>
<p>The script below works fine; but I can't help feeling that I'm missing a trick here. Any tips?
</p>
<pre><code>function capitaliseName str =
(
theName = ""
str = toLower str... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T08:22:11.637",
"Id": "49713",
"Score": "1",
"Tags": [
"strings",
"maxscript"
],
"Title": "String capitalisation in Maxscript"
} | 49713 |
<p><a href="http://wiki.cgsociety.org/index.php/Maxscript" rel="nofollow">MAXScript</a> is the built-in scripting language for Autodesk 3ds Max and Autodesk 3ds Max Design.</p>
<p>See <a href="http://docs.autodesk.com/3DSMAX/14/ENU/MAXScript%20Help%202012/" rel="nofollow">MAXScript documentation for 3ds Max 2012</a>.<... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T08:51:08.787",
"Id": "49714",
"Score": "0",
"Tags": null,
"Title": null
} | 49714 |
MAXScript is the scripting language for Autodesk 3D Studio MAX | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T08:51:08.787",
"Id": "49715",
"Score": "0",
"Tags": null,
"Title": null
} | 49715 |
<p>I have changed a lot from my original code that I posted about a week ago, you can see that here:</p>
<p><a href="https://codereview.stackexchange.com/questions/49460/guild-wars-knights-dragons">Guild Wars: Knights & Dragons</a></p>
<p>Now what I need to know is if I improve this code further. Any help is grea... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>This:</p>\n\n<pre><code>$(\"#menu\").children(\"div\").slice(1,7).addClass(\"menuitems\");\n</code></pre>\n\n<p>should have been set in the HTML, I see no good reason to do this with JavaScript. If you insist on doing it in JavaScript, have <code>1</code> and ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T09:18:16.543",
"Id": "49718",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html",
"css"
],
"Title": "Guild Wars: Knights & Dragons - Version 2"
} | 49718 |
<p>I would like to know if my java db class is enough protected against hackers. (I'm currently developing an Android application). I protect it with a infos.properties file which contains every information that I need.</p>
<pre><code>final class DB {
static final String DRIVER;
static final String URL;
static final... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T18:39:03.977",
"Id": "87572",
"Score": "5",
"body": "Its never secure. Ever."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T18:53:39.660",
"Id": "87575",
"Score": "0",
"body": "Besides wh... | [
{
"body": "<p>If possible I would try to avoid a method like <code>doQuery(String query)</code>. If someone manages to manipulate the <code>query</code> this becomes a classical <em>injection</em> problem.</p>\n\n<p>If you do not need the flexibility to make any kind of db requests, use prepared statements for ... | {
"AcceptedAnswerId": "49722",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T11:37:11.213",
"Id": "49720",
"Score": "8",
"Tags": [
"java",
"sql",
"security"
],
"Title": "Is my Java SQL connection secure from hackers?"
} | 49720 |
<p>I've been working on what is essentially my first proper attempt at making a useful PHP wrapper class for the Wordpress Settings API. It works great so far and I plan to add more methods as I go so that I eventually build up a class that can be used in pretty much any situation.</p>
<p>As this is my first proper PH... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-19T17:15:01.017",
"Id": "88285",
"Score": "1",
"body": "Looks great to me. One thing I'd change, just to make it cleaner - IMO. In the `displayOptionsPage()` function `$activeTab = isset($_GET['tab']) ? $_GET['tab'] : strtolower( str_r... | [
{
"body": "<p>your first function should use a <code>switch</code> statement instead of a complex <code>if then</code> statement.</p>\n\n<pre><code> foreach ( $this->pages as $page )\n {\n if ($page['type']=='menu')\n {\n add_menu_page(\n __( $page['title'] ),\n ... | {
"AcceptedAnswerId": "51232",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T12:21:05.403",
"Id": "49724",
"Score": "12",
"Tags": [
"php",
"wordpress"
],
"Title": "First attempt - Wordpress PHP Settings API wrapper"
} | 49724 |
<p>I am creating a function for sanitising user inputs and user inputted data outputs.</p>
<p>Please offer advise on any improvements which could be made:</p>
<pre><code>function cleanse($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\... | [] | [
{
"body": "<p>Personally I tend to work with a white-list of characters.</p>\n\n<p>So instead of sanitizing and removing bad stuf, I simply only accept good stuff.<br>\ne.g. <code>[0-9]+</code> when validating an age field</p>\n\n<p>This approach is less error prone because you don't have to think of all the ba... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T13:33:39.317",
"Id": "49729",
"Score": "2",
"Tags": [
"php"
],
"Title": "Sanitising user inputs and user inputted data outputs"
} | 49729 |
<pre><code>data = ['HTTP/1.1 200 OK', 'CACHE-CONTROL: max-age=1810', 'DATE: Wed, 14 May 2014 12:15:19 GMT', 'EXT:', 'LOCATION: http://192.168.94.57:9000/DeviceDescription.xml', 'SERVER: Windows NT/5.0, UPnP/1.0, pvConnect UPnP SDK/1.0', 'ST: uuid:7076436f-6e65-1063-8074-78542e239ff5', 'USN: uuid:7076436f-6e65-1063-8074... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T14:07:14.220",
"Id": "87513",
"Score": "4",
"body": "I cannot understand how a split and a small array like that can take too much time. Have you use some sort of profiling to make sure that this part is the problem?"
},
{
"... | [
{
"body": "<p>With such a small input it should be lightning fast. Anyway, shouldn't you break after finding the element? I'd write:</p>\n\n<pre><code>xmllink = next(s.split(\":\", 1)[1].strip() for s in data if s.startswith(\"LOCATION:\")\n</code></pre>\n",
"comments": [
{
"ContentLicense": "... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T13:52:32.657",
"Id": "49732",
"Score": "6",
"Tags": [
"python",
"performance",
"strings",
"python-2.x",
"search"
],
"Title": "Search string in a list"
} | 49732 |
<p>This is code written for use inside a 3rd party application to pull information from an XML and insert into a word document, I don't know all the mechanics of the fun process of inserting the information into the word document (inside the 3rd party application) so some questions you might have for me are going to b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T15:29:55.410",
"Id": "87529",
"Score": "0",
"body": "I removed a Declaration that was redundant."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T13:16:42.947",
"Id": "87682",
"Score": "0",
... | [
{
"body": "<p>A few remarks:</p>\n\n<h3>Variables:</h3>\n\n<p>I personally like declaring my Variables with a Type (the little safety needs to be used..). And while we're at it, I don't like having lists named as <code>items</code></p>\n\n<p>Thus I <em>personally</em>(more emphasis) would rather do:</p>\n\n<pre... | {
"AcceptedAnswerId": "49738",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T15:17:00.793",
"Id": "49737",
"Score": "6",
"Tags": [
"vbscript"
],
"Title": "Pulling information from XML to insert into Word Document inside 3rd party application"
} | 49737 |
<p>I have to clone some Entity, then I wrote this piece of code.</p>
<pre><code>public override object Clone()
{
var CloneUser = base.Clone() as FMSUser;
CloneUser.Username = this.Username;
CloneUser.IsEnabled = this.IsEnabled;
CloneUser.IsNeedPasswordReset = this.IsNeedPasswordReset;
CloneUser.LastName = t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T16:25:43.827",
"Id": "87541",
"Score": "0",
"body": "I have to agree with your coworker, his code leaves construction logic inside a constructor. Now this question isn't quite on-topic for this site, it's mostly opinion-based. Perha... | [
{
"body": "<p>You're not listing your base class, but because of the override and the method's signature in the derived type, I'm assuming something like this:</p>\n\n<pre><code>public abstract class EntityBase : ICloneable\n{\n //...\n public abstract object Clone();\n}\n</code></pre>\n\n<p>Here's what <a ... | {
"AcceptedAnswerId": "49747",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T15:35:00.697",
"Id": "49739",
"Score": "6",
"Tags": [
"c#",
".net"
],
"Title": "Good way to clone an object"
} | 49739 |
<p>Task from <a href="http://codingbat.com/prob/p167025" rel="nofollow">CodingBat</a>:</p>
<blockquote>
<p>Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a 13 also do not count.</p>
</block... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T16:54:25.113",
"Id": "87548",
"Score": "1",
"body": "http://stackoverflow.com/questions/21303224/iterate-over-all-pairs-of-consecutive-items-from-a-given-list could interest you. I whave no time to write a proper answer but you coul... | [
{
"body": "<p>For the record, I think your original answer is quite clean and readable. My only suggestion would be to consider using <code>if not (predicate): (do something)</code>, as opposed to <code>if (predicate): pass; else: (do something)</code>:</p>\n\n<pre><code>def sum13(nums):\n sum = 0\n for i... | {
"AcceptedAnswerId": "49748",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T16:37:15.603",
"Id": "49744",
"Score": "7",
"Tags": [
"python",
"array",
"programming-challenge"
],
"Title": "Python address index +1 with list comprehension"
} | 49744 |
<p>I am trying to implement a HTTP Server in Java, I want the server to use a persistent connection per thread for request and response. After some research on Google, this is how my program looks like. It runs fine without any exceptions but I am unable to tell if it is doing what I want it to do, that is connection p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T18:19:12.523",
"Id": "87562",
"Score": "0",
"body": "Do you have some restrictions about the Java version or something else ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T19:25:19.663",
"Id": "... | [
{
"body": "<p>I do not believe this code is doing what you expect... and, some of the more important parts of the code are not included here.</p>\n\n<p>There are a number of standard models that are used in Java to run Network-based servers. Your code does not follow any pattern I am familiar with.</p>\n\n<p>Fi... | {
"AcceptedAnswerId": "50938",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T17:05:54.257",
"Id": "49746",
"Score": "6",
"Tags": [
"java",
"multithreading",
"http",
"servlets"
],
"Title": "Implement HTTP Server with persistent connection"
} | 49746 |
<p>I want to build a function which finds the longest substring that is common between two large strings. I want to do this using the first two functions.
I'm running it on very large strings (containing more than million characters) and it's taking a lot of time. How can I optimize the function <code>findlongest</code... | [] | [
{
"body": "<p>One big problem is that when you reach the longest common sequence and are ready to return, you <strong>re-run</strong> the previous iteration <strong>twice</strong>. Variables are your friends:</p>\n\n<pre><code>def find_longest(string1, string2):\n longest_seq = None\n\n for i in range(1, ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T18:35:35.240",
"Id": "49752",
"Score": "2",
"Tags": [
"python",
"performance",
"strings"
],
"Title": "Finding the longest substring in common with two large strings"
} | 49752 |
<p>Following is the code I wrote to download the information of different items in a page.</p>
<p>I have one main website which has links to different items. I parse this main page to get the list. This is handled by the <code>Items</code> class. </p>
<p>I also parse these each of the links in the list using the <cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-11-13T07:59:02.147",
"Id": "127313",
"Score": "0",
"body": "As far as styling is concerned, I would suggest you go through. https://google-styleguide.googlecode.com/svn/trunk/pyguide.html?showone=Naming#Naming. function_name are usually s... | [
{
"body": "<p>The general style for naming in Python is <code>snake_case</code> for functions and variables, and <code>PascalCase</code> for classes. You should also have two blank lines between top-level functions/classes/code blocks, not, an arbitrary amount. You have a few other style violations. To fix thes... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T18:44:09.323",
"Id": "49754",
"Score": "3",
"Tags": [
"python",
"parsing",
"error-handling",
"logging",
"web-scraping"
],
"Title": "Parsing a website"
} | 49754 |
<p>I have an implementation of an optimization algorithm called the <a href="http://en.wikipedia.org/wiki/CMA-ES">Covariance Matrix Adaptation Evolutionary Strategy (CMA-ES)</a>. I am using this algorithm to optimize the position of wind turbines inside a wind farm, but if I place more than a certain number of turbines... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-12-20T04:32:38.937",
"Id": "135015",
"Score": "0",
"body": "Could you provide test code that invokes the above in a way that you expect reproduces the memory issue?"
}
] | [
{
"body": "<ol>\n<li><p>First off, style. Your code is... not very well styled. You have <em>many</em> <a href=\"https://www.python.org/dev/peps/pep-0008/\" rel=\"noreferrer\">PEP8</a> violations. Here's a list of those violations.</p>\n\n<ol>\n<li>You have no space between operators/variable declarations. You ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T19:29:24.003",
"Id": "49759",
"Score": "12",
"Tags": [
"python",
"optimization",
"performance",
"array",
"memory-management"
],
"Title": "Using the CMA-ES algorithm to opt... | 49759 |
<p>I've built a simple chat server/client on Node.js and socket.io that I would like reviewed. My main concern is making the chat.js (client) running as cleanly as possible (OO) and streamlining data back and forth so I can add client monitoring (updated list of connected users) features down the line without issue.</p... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>There is no need to set <code>views</code> or <code>view engine</code> for the server part, you are not using it</li>\n<li>Be careful about polluting the global namespace, variables like <code>welcome</code>, <code>join</code> and <code>leaving</code> should be d... | {
"AcceptedAnswerId": "49835",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T20:02:02.467",
"Id": "49761",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"node.js",
"chat",
"socket.io"
],
"Title": "Node.js chat service"
} | 49761 |
<p>This is a follow up question to the one I asked <a href="https://codereview.stackexchange.com/questions/49459/merge-sort-algorithm-implementation-using-c">a couple of days ago</a>.</p>
<hr>
<p>I reviewed the suggestions & did some research (specifically, read relevant info on CLRS). The new version is 3 times ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T21:45:00.403",
"Id": "87606",
"Score": "0",
"body": "Like the @tinstaafl said, your code is unreadable, not everyone has the ability to read other people's mind. Please edit this and I'll comment.."
},
{
"ContentLicense": "C... | [
{
"body": "<p>The first thing I would suggest is using better names for your variables. It's very hard for someone else looking at or using your code to determine what those variables are supposed to represent.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "C... | {
"AcceptedAnswerId": "49773",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T20:07:32.247",
"Id": "49762",
"Score": "2",
"Tags": [
"c++",
"algorithm",
"c++11",
"sorting",
"mergesort"
],
"Title": "Merge sort algorithm implementation using C++ (re... | 49762 |
<p>I have the following diagram (did this only to ask here, it's obviously missing details):</p>
<p><img src="https://i.stack.imgur.com/cNStG.png" alt="CLass Diagram"></p>
<p>From the diagram you can see I have to check if all sensors in an environment are respecting the established conditions, but I'm not comfortabl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T21:17:53.857",
"Id": "87600",
"Score": "0",
"body": "It the part you dislike that all three classes store the conditions, instead of just `Environ`? Do the other two know their environment, so they can use its conditions?"
},
{
... | [
{
"body": "<p>The idea with objects is they maintain the data that they own. Try to avoid having the object hold onto other data just because it uses it. This makes later refactoring harder.\nBelow is a sketch of what the <code>process</code> chain might look like.</p>\n\n<pre><code>class Sensor(object):\n d... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T20:52:24.367",
"Id": "49763",
"Score": "0",
"Tags": [
"python",
"object-oriented",
"design-patterns"
],
"Title": "Checking sensors in an environment"
} | 49763 |
<p>It is not always possible to simplify program design by strictly managing the lifetimes of objects. If two objects have unpredictable lifetimes, but one of them needs to refer to the other, a simple pointer or reference is a segmentation fault waiting to happen.</p>
<p>The approach that I tried first was to have bo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T22:09:53.257",
"Id": "87609",
"Score": "2",
"body": "Aye. But look at `make_shared`, it is potentialy more eficient"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T22:21:11.243",
"Id": "87610",
... | [
{
"body": "<p>I think using a bit of dynamic allocation <code>std::shared_ptr</code> and <code>std::weak_ptr</code> makes sense as they provide a solid implementation of the tracking behaviour you need.</p>\n\n<p>Your original though has a nice property of not using any dynamic allocation.\nIf the tracking logi... | {
"AcceptedAnswerId": "56798",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T21:52:14.147",
"Id": "49769",
"Score": "2",
"Tags": [
"c++",
"c++11"
],
"Title": "Approach for one class to safely refer to another, with both having unknown lifetimes"
} | 49769 |
<p>I am using JUnit, Hibernate and Spring Framework. I wrote a simple test to test whether entity was updated correctly or not.</p>
<p>Is this correct way to test if entity was updated? Could it be done better?</p>
<pre><code>@Test
public void testUpdated(){
ConfirmationEntity confirmationEntity = confirmationDao... | [] | [
{
"body": "<p>This test, on its own, is not enough. Additionally, the test is called <code>testUpdated</code>, but it does not actually test that the value is updated.</p>\n\n<p>What it does is:</p>\n\n<ul>\n<li>find an object based on a key value</li>\n<li>it modifies some non-key content</li>\n<li>it 'persist... | {
"AcceptedAnswerId": "49774",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T22:26:37.987",
"Id": "49771",
"Score": "5",
"Tags": [
"java",
"junit"
],
"Title": "JUnit Assert.assertSame"
} | 49771 |
<p>Though I can achieve most ends via a series of conditionals and arithmetic, especially when iterating over or comparing arrays I frequently hear of much more efficient implementations.</p>
<p>Hailing from PHP, I am accustomed to having <code>array_merge()</code> accessible; this JS function is different in that key... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T22:59:33.890",
"Id": "87611",
"Score": "0",
"body": "What is `forbid_flags` in your function? I don't see it defined anywhere and why not just use an `if` statement if there's only one arm to your conditional?"
},
{
"Conten... | [
{
"body": "<p>Interesting question,</p>\n\n<p>there is no faster approach that I know of, in essence, your approach mimics jQuery's <code>$.extend()</code> source code. Except that your code does not clone parameters which might bring you trouble.</p>\n\n<p>I think your code might be messed up, or you might not... | {
"AcceptedAnswerId": "49819",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T22:38:18.893",
"Id": "49772",
"Score": "4",
"Tags": [
"javascript",
"optimization",
"array"
],
"Title": "Computationally efficient way of comparing and merging like object keys... | 49772 |
<p>I'm learning MATLAB (still trying to "think in vectors") and have the following piece of code:</p>
<pre><code>stats = regionprops(bwconncomp(mask), 'all');
% find the object nearest our nucleus
smallest_dist = flintmax;
location = [cell_x, cell_y];
for j = 1:numel(stats)
stat = stats(j);
dist = pdist([loca... | [] | [
{
"body": "<p>I think this comes pretty close. The use of arrayfun() or other *fun()-Operations is very often better than for loops.</p>\n\n<p>Your code was not working out of the box. Thus, I created code, which is directly executable:</p>\n\n<pre><code>function minimalExample()\n target.x = 10;\n target... | {
"AcceptedAnswerId": "51772",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T23:06:03.503",
"Id": "49776",
"Score": "3",
"Tags": [
"matlab"
],
"Title": "Using the Return Value of a Function to Select an Element in a Struct Array"
} | 49776 |
<p>This my implementation of the <a href="http://en.wikipedia.org/wiki/Merge_sort" rel="nofollow">Merge Sorting Algorithm</a>:</p>
<pre><code>def merge(series1, series2):
output = []
while series1 != [] or series2 != []:
if series1 == []:
output.append(series2[0])
series2.pop(0)... | [] | [
{
"body": "<p>In merge you are doing list comparison (<code>series1 != []</code> or <code>series2 != []</code>). This is expensive. You can avoid this by storing the length of two list beforehand and using that value to detect when to come out of the loop.</p>\n\n<p>Also by using a small trick you can avoid usi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T23:28:39.070",
"Id": "49777",
"Score": "3",
"Tags": [
"python",
"algorithm",
"sorting",
"mergesort"
],
"Title": "Merge Sorting in Python"
} | 49777 |
<blockquote>
<p>Implement an iterator (generic) which skips an element if it is equal to the previous element. e.g: AAABBCCCCD, produces ABCD.</p>
</blockquote>
<p>Please suggest improvements.</p>
<pre><code>import java.util.Iterator;
public class DeDupIterator implements Iterator {
E next = null;
Iterator<E&g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T00:03:49.097",
"Id": "87618",
"Score": "0",
"body": "Your code looks .... incomplete ... missing the `<E>` generic type declarations for the class?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T00:2... | [
{
"body": "<p><strong>Generic Types</strong></p>\n\n<p>You appear to have copied this from inside another class, or something, because you are missing the Generic type for the iterator <code><E></code>. Also, assuming you get that right, there is no need to do the explicit cast inside the code.. the follo... | {
"AcceptedAnswerId": "49789",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-14T23:56:20.067",
"Id": "49778",
"Score": "4",
"Tags": [
"java",
"iterator"
],
"Title": "A deduplicating iterator"
} | 49778 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow">Learn You a Haskell</a> shows the <code>delete</code> function.</p>
<blockquote>
<p>delete: deletes first occurrence of item</p>
</blockquote>
<pre><code>ghci> delete 'h' "hey there ghang!"
"ey there ghang!"
</code></pre>
<p>Pleas... | [] | [
{
"body": "<p>I think you're overcomplicating this a bit. Something like <code>delete</code> certainly shouldn't need <code>reverse</code> or <code>++</code> to implement.</p>\n\n<p>For the initial list, there are two cases - it either contains an element, or is empty. That much exists in your code. The empty c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T00:08:45.443",
"Id": "49779",
"Score": "3",
"Tags": [
"haskell",
"reinventing-the-wheel"
],
"Title": "Implementing Haskell's `delete`"
} | 49779 |
<p>This is supposed to be an evolutionary algorithmic program, and I'm not sure if it does what it's supposed to do.</p>
<p>It is supposed to take a random list of numbers (containing at least one 5), and over many generations, increase the probability of 5's reproducing, thus having the 5's eventually taking over the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T15:21:24.747",
"Id": "87865",
"Score": "0",
"body": "It would be preferred to post your new code as a new follow-up question. We no longer encourage extended reviews of newer code in the same question."
},
{
"ContentLicense... | [
{
"body": "<p>The formatting of your code is a bit unusual : no line break between classes, line breaks in the middle of the functions, local variable names starting with an upper-case letter, etc. To be fair, your code does't even run on my setup because of the <code>Fitness</code> variable.</p>\n\n<p>A few to... | {
"AcceptedAnswerId": "50917",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T00:09:38.190",
"Id": "49780",
"Score": "5",
"Tags": [
"python",
"random",
"simulation"
],
"Title": "Change random list of numbers into all 5's using simple evolution simulation... | 49780 |
<p>I have not yet seen an implementation of the observer pattern in Python which satisfies the following criteria:</p>
<ol>
<li>A thing which is observed should not keep its observers alive if all other references to those observers disappear.</li>
<li>Adding and removing observers should be pythonic. For example, if ... | [] | [
{
"body": "<p>I like your code: its quite interesting. While reviewing, I was hoping to see if there was a better way if keeping track of the instances of each <code>ObservableMethod</code> or if we could combine the <code>ObservableMethod</code> and <code>ObservableMethodDescriptor</code> classes. However, I c... | {
"AcceptedAnswerId": "51221",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T00:18:23.710",
"Id": "49782",
"Score": "7",
"Tags": [
"python",
"design-patterns"
],
"Title": "Observer pattern implementation without subclassing"
} | 49782 |
<p>Learn You a Haskell presents the <code>\\</code> function.</p>
<blockquote>
<p>\\ is the list difference function. It acts like a set difference,
basically. For every element in the right-hand list, it removes a
matching element in the left one.</p>
</blockquote>
<p>Example:</p>
<pre><code>ghci> [1..10] ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T09:19:19.310",
"Id": "87656",
"Score": "2",
"body": "`(\\\\)` is not in the [Haskell 98 standard prelude](http://www.haskell.org/onlinereport/prelude-index.html). Do you mean [`(\\\\)` in `Data.List`](http://www.haskell.org/ghc/docs... | [
{
"body": "<p>I find that to be a very succinct, readable definition. I probably would have written it too. Unfortunately it's wrong!</p>\n\n<p>One of the more tedious requirements of beautiful code is that it be correct, so let's set up some really quick testing using QuickCheck. Since you've been reimplementi... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T00:22:44.643",
"Id": "49783",
"Score": "2",
"Tags": [
"haskell",
"reinventing-the-wheel"
],
"Title": "Implementing Haskell's \\\\ (Set Difference)"
} | 49783 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow">Learn You a Haskell</a> shows the <code>union</code> function:</p>
<blockquote>
<p>union also acts like a function on sets. It returns the union of two
lists. It pretty much goes over every element in the second list and
appends it t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T08:16:55.423",
"Id": "87643",
"Score": "2",
"body": "This is wrong, but not for any good reason. `union`'s behavior is weird. The key is in that last sentence of the quote, what it elides is that duplicates are *not* removed from th... | [
{
"body": "<p>The formatting of your code is broken, so I've reproduced it here for clarity.</p>\n\n<pre><code>union' :: (Eq a) => [a] -> [a] -> [a]\nunion' xs ys = xs ++ union'' ys xs\n where union'' [] _ = []\n union'' (a:as) first = if (a `elem` first) then union'' as first else ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T00:30:46.353",
"Id": "49784",
"Score": "1",
"Tags": [
"haskell",
"reinventing-the-wheel"
],
"Title": "Implementing Haskell's `union`"
} | 49784 |
<p>This is a Python module I made to search the Rotten Tomatoes movie API. It caches the search results in a SQLite database. </p>
<p>What improvements can I make to the cache system? Is there a better way to store the results of the API search?</p>
<p>Is there a better way to communicate with the API?</p>
<pre><c... | [] | [
{
"body": "<p>It's a pretty nice script! (You should open-source it, I would use it.)</p>\n\n<h2>Prepared statements</h2>\n\n<p>You should use prepared statements in your queries. It's not only easier to write, it's also more efficient. For example:</p>\n\n<pre><code>def get(self, search_query, page_number):\n ... | {
"AcceptedAnswerId": "49885",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T00:34:15.953",
"Id": "49785",
"Score": "6",
"Tags": [
"python",
"cache"
],
"Title": "Using the Rotten Tomatoes API"
} | 49785 |
<p>I am trying to implement a Doctor/patient scheduling system. It would be great if someone can review my code and suggest how I can improve it further. I would like to know how to have a date-based calendar for this. I also want some idea on how to protect a patient record data from one doctor to another.</p>
<p>On... | [] | [
{
"body": "<p>Instead of defining 16 time slots I would recommend you to use datetime module to create a list of time slots. You should also store 'date' along with time. Datetime module provides functions for easy and quick time comparisons.</p>\n\n<p>The following declarations are redundant:</p>\n\n<pre><code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T00:55:49.200",
"Id": "49786",
"Score": "4",
"Tags": [
"python",
"object-oriented"
],
"Title": "Doctor/Patient Reservation Scheduling"
} | 49786 |
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow">Learn You a Haskell</a> shows the <code>insert</code> function.</p>
<blockquote>
<p>insert takes an element and a list of elements that can be sorted and
inserts it into the last position where it's still less than or equal
to the ne... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T08:05:09.337",
"Id": "87642",
"Score": "0",
"body": "Looks good! I'd use guards in place of an `if`, but that's a stylistic choice. If you ignore the overloading and micro-optimizations, that's the way [Data.List defines `insert`](h... | [
{
"body": "<p>Your version is fine. As bisserlis mentioned, guards would probably look nicer.</p>\n\n<p>I find the following more readable, but of course it has worse performance:</p>\n\n<pre><code>insert' x ys = let (small, big) = span (< x) ys \n in small ++ [x] ++ big\n</code></pre>\n",
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T02:47:26.593",
"Id": "49791",
"Score": "3",
"Tags": [
"haskell",
"reinventing-the-wheel"
],
"Title": "Implementing Haskell's `insert`"
} | 49791 |
<p>I have a number of JSON files to combine and output as a single CSV (to load into R), with each JSON file at about 1.5GB. While doing a trial on 4-5 JSON files at 250MB each, the code works when I only use 2-3 files but chokes when the total file sizes get larger.</p>
<p>I'm running Python version 2.7.6 (default, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T05:23:22.123",
"Id": "87629",
"Score": "0",
"body": "Hi there, welcome to Code Review. We do review of code that has to work. If this code works for smaller JSON files please change title and body in how to improve to larger files."... | [
{
"body": "<p>You're storing lots of results in lists, which could be streamed instead. Fortunately, using generators, you can make this ‘streaming’ relatively easy without changing too much of the structure of your code. Essentially, put each ‘step’ into a function, and then rather than <code>append</code>ing ... | {
"AcceptedAnswerId": "49794",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T02:51:14.317",
"Id": "49792",
"Score": "6",
"Tags": [
"python",
"optimization",
"memory-management",
"csv",
"iteration"
],
"Title": "MemoryError in Python while combini... | 49792 |
<p>Can anyone help make this perform faster?</p>
<pre><code>import numpy as np
from scipy import signal
d0 = np.random.random_integers(10, 12, (5,5))
d1 = np.random.random_integers(1, 3, (5,5))
d2 = np.random.random_integers(4, 6, (5,5))
d3 = np.random.random_integers(7, 9, (5,5))
d4 = np.random.random_integers(1, 3,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T15:54:56.970",
"Id": "87750",
"Score": "0",
"body": "Why do you need that particular output shape?"
}
] | [
{
"body": "<p>Note: this only works if there are exactly two minima in each row.</p>\n\n<p>You can avoid the loop by computing minima along axis 1 of the <code>data</code> array.</p>\n\n<pre><code>minima = signal.argrelmin(data, axis=1)\nminimas = list(data[minima].reshape(-1,2))\n</code></pre>\n",
"comment... | {
"AcceptedAnswerId": "49806",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T05:06:05.350",
"Id": "49799",
"Score": "4",
"Tags": [
"python",
"performance",
"numpy"
],
"Title": "Calculating minima values for each column of given data"
} | 49799 |
<p>I recently implemented the RDP polygon approximation algorithm in Python and I'm skeptical of whether or not I implemented it correctly of with the greatest efficiency. The algorithm runs in around 0.0003 seconds for a polygon with 30 points on my computer (an Intel Core i5 with 3.8 GHz of RAM), so I'm worried about... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T08:42:55.530",
"Id": "87648",
"Score": "0",
"body": "You probably forgot to close your parenthesis at the end of your `print`s at the end of your program. Which version of Python are you using?"
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>You can simplify your <code>distance</code> function with the function <a href=\"https://docs.python.org/3.4/library/math.html#math.hypot\" rel=\"nofollow\"><code>math.hypot(x, y)</code></a>:</p>\n\n<pre><code>dx = v2[0] - v1[0]\ndy = v2[1] - v1[1]\nreturn math.hypot(dx, dy)\n</code></pre>\n\n<p><... | {
"AcceptedAnswerId": "49816",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T08:24:09.643",
"Id": "49809",
"Score": "9",
"Tags": [
"python",
"optimization",
"algorithm",
"python-3.x",
"computational-geometry"
],
"Title": "Python implementation o... | 49809 |
<p><strong>Tetromino class:</strong></p>
<pre><code>class Tetromino(object):
def __init__(self, board, matrix, type, color, x=0, y=None, updateinterval=FRAMERATE, queue=0):
self.matrix = matrix
self.type = type
self.board = board
self.color = color
self.updateinterval = upda... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T09:04:23.163",
"Id": "87653",
"Score": "1",
"body": "Why not just let the code speak for itself? Instead of a long explanation of the design, put the code to be reviewed in the question. (You've included _some_ code, but not nearly ... | [
{
"body": "<p>I have a few comments on your OOP design.</p>\n\n<p>Your <code>Tetromino</code> class is way too full of functionality, or in other words, bloated. On one hand, it stores the basic info of location, type etc, but at the same time it is responsible for events, drawing, and collision detection. That... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-05-15T08:41:47.790",
"Id": "49812",
"Score": "9",
"Tags": [
"python",
"object-oriented",
"game",
"pygame",
"tetris"
],
"Title": "Tetris clone written in Python/Pygame"
} | 49812 |
<p>I have been given a change to rewrite an old framework we use, and to implement the repository and unit of work patterns, but in an attempt to not rewriting all queries I have ended up with a weird combination of Linq queries and Linq lambdas.</p>
<p>I was hoping someone could explain to me a better way of doing th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T17:28:32.453",
"Id": "87759",
"Score": "0",
"body": "What you do will depend largely on whether `Get()` defers execution. If it forces execution prior to return, you may want to pass the filter expression so it is included as part ... | [
{
"body": "<p>There is a reason why you can write LINQ queries using the query syntax or the method syntax: sometimes one is better and sometimes it's the other one.</p>\n\n<p>So, when you're writing a new query, use the syntax that suits your query better. This usually means method syntax for simpler queries (... | {
"AcceptedAnswerId": "49821",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T10:52:35.833",
"Id": "49814",
"Score": "2",
"Tags": [
"c#",
"performance",
"linq",
"lambda"
],
"Title": "Mixing Linq queries and Linq lambdas"
} | 49814 |
<p>I just implemented code to add two ints together as strings and I'm sure my method is inferior. I've looked up other methods too but I'd appreciate criticisms specific to my code. I really want to make sure I don't develop bad habits in C++ and I think leveraging the knowledge of brighter individuals than myself on ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:23:19.793",
"Id": "87773",
"Score": "0",
"body": "Surely C++ has a real big-int library..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:24:54.020",
"Id": "87774",
"Score": "0",
"b... | [
{
"body": "<p>Some basic C++ advice:</p>\n\n<ul>\n<li><p><a href=\"https://stackoverflow.com/q/1452721/1364752\">Don't use <code>using namespace std;</code></a>. It leads to namespace pollution: it you use another library, you may import names in the global namespace that may clash with those in the <code>std</... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T11:45:20.293",
"Id": "49817",
"Score": "3",
"Tags": [
"c++"
],
"Title": "Adding two numbers as strings from a textfile"
} | 49817 |
<p>I am using Hibernate 4 and Spring Framework 4. I wrote a simple test to check whether object was persisted or not.</p>
<p>All set values in confirmationEntity are required.</p>
<p>In this test I relly on that, that after a new object is persisted, then it is given a new id automatically.</p>
<p>Is this correct wa... | [] | [
{
"body": "<p>I'm going to assume that you have a standard DAO setup so you should try the following.</p>\n\n<pre><code>@Test\npublic void testCreated(){\n ConfirmationTypeEntity confirmationTypeEntity = confirmationTypeDao.find(1L);\n UserEntity userEntity = userDao.find(1L);\n\n ConfirmationEntity co... | {
"AcceptedAnswerId": "49905",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T11:49:28.550",
"Id": "49818",
"Score": "2",
"Tags": [
"java",
"hibernate",
"junit"
],
"Title": "JUnit - Test whether object was persisted or not"
} | 49818 |
<p>This is what I have which is mostly based on code I've found on Stack Overflow. How good is it? Can you suggest better implementation?</p>
<pre><code>#pragma once
#include <mutex>
#include <condition_variable>
#include <deque>
template <typename T>
class BlockingQueue
{
private:
std::m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-04-28T17:01:36.553",
"Id": "159696",
"Score": "0",
"body": "i completely replaced this queue with two - boost spsc and tbb concurrent_bounded_queue."
}
] | [
{
"body": "<p>Overall the code looks functional to me. Everytime you pop it will wait on the condition variable if the queue is empty. Everytime you push, a notification will be sent to any thread waiting in the pop method because the queue is empty and let it know that the queue is not empty anymore. I can't s... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T12:32:03.797",
"Id": "49820",
"Score": "9",
"Tags": [
"c++",
"multithreading",
"c++11",
"queue"
],
"Title": "Thread-safe queue"
} | 49820 |
<p><strong>Follow up to <a href="https://codereview.stackexchange.com/q/49737/18427">This Question</a></strong></p>
<hr>
<p>I took some very good advice and changed my code around a little bit and eliminated some <code>If</code> statements.</p>
<p>I am not retrieving very much information but it looks so skinny now.... | [] | [
{
"body": "<p>I see one point that seems almost obvious enough that I'm worried I might be missing something. A <code>For Each</code> is \"smart\" enough that its body isn't executed at all for an empty collection, so you can eliminate the test for the list having a length of 0:</p>\n\n<pre><code>Dim phoneNode\... | {
"AcceptedAnswerId": "49829",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T13:15:47.240",
"Id": "49824",
"Score": "4",
"Tags": [
"vbscript"
],
"Title": "Still pulling information from XML to insert into Word Document inside 3rd party application"
} | 49824 |
<p>I am doing a project where I am analyzing a group of Tweets. </p>
<p>What I need to do is find the occurrence of each individual word. I am fairly new to Redis, so I am not quite sure that my solution is optimal. I am storing a key value pair for each word. The key is a word, and the value is the occurrence count. ... | [] | [
{
"body": "<p>Your code is alright, really. However, by your using redis, I suspect you're after a fast way to store tiny bits of data. The varname <code>$cache</code> somewhat confirms my suspicion.<br>\nIf this is the case, your using <code>lrange</code> might not be the best choice, nor is <code>exists</cod... | {
"AcceptedAnswerId": "50924",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T13:33:41.490",
"Id": "49825",
"Score": "1",
"Tags": [
"php",
"cache",
"redis"
],
"Title": "Using Redis to store word occurences"
} | 49825 |
<p>I have the following SQL query which takes ~3 seconds to run, maybe ~4. This populates a consultants table with their expected payments for the month.</p>
<p>Unfortunately, the page only loads when this query is finished. Is there any way to make it quicker? </p>
<p>Is there anything you notice that I could do bet... | [] | [
{
"body": "<p>you are doing a lot of <code>CONVERT</code>ing in this query. </p>\n\n<p>Instead of converting the Date variables inside the <code>WHERE</code> clause you should do that before you even start the query, otherwise you are running this convert for every row in the <code>SELECT</code> because the W... | {
"AcceptedAnswerId": "49828",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T13:34:57.500",
"Id": "49826",
"Score": "5",
"Tags": [
"performance",
"sql",
"datetime",
"sql-server"
],
"Title": "Query of consultants and their expected payments for the m... | 49826 |
<p>Below is a function from a driver that I wrote for and I2C temperature sensor.
The function takes as input the name of the bus and the device's bus address, reads it's status register, and then reports the status verbosely. (It also returns a values of interest, but that's not important now). </p>
<p>I have two qu... | [] | [
{
"body": "<p>I you wanted to take an OOP approach, you could create a class and then hide a lot of the repeated code in a single method:</p>\n\n<pre><code>class Bit():\n ''' Simple class that holds values associated with a given bit. '''\n def __init__(self, val, status_msg, true_val, false_val):\n ... | {
"AcceptedAnswerId": "49873",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T15:25:15.623",
"Id": "49840",
"Score": "5",
"Tags": [
"python",
"strings",
"python-2.x"
],
"Title": "Readability in creation of a long output string"
} | 49840 |
<p>On my application I use this method to store and to output the data. I would like to know if it is safely and correct.</p>
<pre><code>##store the data###
//sanitize
function clean($testo)
{
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$testo = $purifier->pur... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-12T15:44:38.957",
"Id": "87726",
"Score": "1",
"body": "`mysql` is deprecated. Instead use `PDO` or `mysqli`: http://www.php.net/manual/en/intro.mysql.php"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-12T... | [
{
"body": "<p>To \"Safely\" store data, please don't use <code>mysql_*</code> functions. Use <code>PDO</code> or <code>mysqli</code>.</p>\n\n<p>Also, use <code>PreparedStatements</code> wherever you use \"<code>where</code>\" clause in queries. That will protect you against injection.</p>\n\n<p><a href=\"http:/... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-12T15:43:32.183",
"Id": "49841",
"Score": "0",
"Tags": [
"php",
"mysql"
],
"Title": "Safely storing and output data"
} | 49841 |
<p>We have recently started working in ASP.NET and starting a simple CRUD Web application in ASP.Net. Here is the approach we are following to connect to DB. </p>
<p>Connection.cs</p>
<pre><code>public class Connection
{
public SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CWConnec... | [] | [
{
"body": "<p>If you run CheckOpenConnection() on a connection that is already open, you will get an error with this code.</p>\n\n<p>Your code closes the connection if it is open, and then return true - as if it was open. This will result in an error. Don't close the connection if your method called CheckOpenCo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-13T11:20:33.297",
"Id": "49843",
"Score": "2",
"Tags": [
"c#",
"asp.net",
"ado.net"
],
"Title": "Database connection approach"
} | 49843 |
<p>This is my code for finding the nearest city within a certain radius. I am not sure, is my code is OK or is it wrong? Please review and offer suggestions on my code.</p>
<pre><code><?
//Suppose,I have selected a city and fetch the selected city's lat and long and radius
//in to this page.
$file_handle = fopen("... | [] | [
{
"body": "<p>I din't check your math, because in any case the code doesn't do what it claims to do. The returned points are not within the given <em>distance</em> of the center, but belong to some square-like area.</p>\n\n<p>To calculate a distance as the crow flies, notice that a cosine of the angular distanc... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T16:27:50.413",
"Id": "49852",
"Score": "5",
"Tags": [
"php",
"csv",
"geospatial"
],
"Title": "Finding nearest city from a center place (latitude and longitude) with radius in mile... | 49852 |
<p>I have an initial list that contains: 1,2,3,4,5,6,7 I want to create an array of StringBuffer that contains only 3 items per element as StringBuffer(String):</p>
<pre><code>1,2,3
4,5,6
7
</code></pre>
<p>Initially I resolved this problem as in the following example, but I don't want to use another list to do that:... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T17:30:45.153",
"Id": "87761",
"Score": "2",
"body": "Hi, and welcome to Code Review. This code does not do what your description says it should do. I don't see an Array of `StringBuffer[]` and I don't see anything that makes the out... | [
{
"body": "<h1>StringBuffer</h1>\n\n<p>The first thing that comes to mind is the fact that you're using a <code>StringBuffer</code> instead of a <code>StringBuilder</code>. A <code>StringBuffer</code> is synchronized which means it has the additional overhead that comes with it. Unless you are doing this in a m... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T17:26:08.840",
"Id": "49858",
"Score": "0",
"Tags": [
"java"
],
"Title": "Build an Array of StringBuffer with x elements from a List of n elements"
} | 49858 |
<p>I am using the code below to capitalize words in a string. I do not want conjunction words capitalized, but always want the first character in the string to be capitalized no matter what the word is. Is this the most optimized way of accomplishing this? How could this be improved? </p>
<pre><code>xText = queryForHe... | [] | [
{
"body": "<p>You could drastically shorten your If statements by extracting them to a function. Furthermore I nowhere see, that you actually change the case for <code>xWord</code>. That also makes the assignment at the start of your loop useless. Your code then changes to: </p>\n\n<pre><code>for each item in x... | {
"AcceptedAnswerId": "49863",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T17:34:21.210",
"Id": "49859",
"Score": "3",
"Tags": [
"strings",
"vbscript",
"asp-classic"
],
"Title": "Capitalize string except for conjunction words"
} | 49859 |
<p>I'd like my code to be solid and good. That's why I want someone a little more experienced to give me some feedback so I can improve. Here is the code for a simple stop watch that I created. I feel the code is a bit clumpy and big so that's why I want to get feedback on how to make it more efficient.</p>
<p><a hre... | [] | [
{
"body": "<p>Hmmm.... this is a big one. Right, let's break this review in to five sections:</p>\n<ol>\n<li>Code Style</li>\n<li>Threads</li>\n<li>Class Hierarchy</li>\n<li>Swing</li>\n<li>Performance....</li>\n</ol>\n<h1>Code Style</h1>\n<p>This is a laundry-list of things. I'm not going to explain them all, ... | {
"AcceptedAnswerId": "49897",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:04:56.933",
"Id": "49864",
"Score": "7",
"Tags": [
"java",
"beginner",
"datetime",
"swing",
"timer"
],
"Title": "Simple stop watch"
} | 49864 |
<p>I've a lot of code blocks that hide/show some block.</p>
<pre><code>$('#Back').on('click', function () {
$('#FormRow').hide();
$('#TableRow').show();
});
$('#AddLanguageShow').on('click', function () {
$('#FormRow').show();
$("#TableRow").hide();
});
$('table').on('click', 'button.edit', function... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:21:53.423",
"Id": "87772",
"Score": "2",
"body": "Can you provide us more code, it is not clear why you would show or hide stuff right now."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T19:09:11.... | [
{
"body": "<p>Extract the duplicated code to a function:</p>\n\n<pre><code>function showOneHideOther(elToShow, elToHide) {\n $(elToShow).show();\n $(elToHide).hide();\n}\n</code></pre>\n\n<p>You can reuse the function anyplace now:</p>\n\n<pre><code>$('#Back').on('click', function() {\n showOneHideOthe... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:14:24.153",
"Id": "49865",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"event-handling"
],
"Title": "Lots of click handlers that hide one element and show another"
} | 49865 |
<p>I have this script to pull data out of the Filepicker API internal. It's mostly reverse-engineering and the code seems to be ugly to me. How can this be improved?</p>
<pre><code>yesterday = (Time.now - 1.day).to_i
start_date = "08/08/2013".to_time.to_i
url = URI.parse("https://developers.inkfilepicker.com/login/")... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T10:31:58.053",
"Id": "88744",
"Score": "0",
"body": "no feedback...?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T17:44:42.597",
"Id": "88840",
"Score": "0",
"body": "Sorry! I've been f... | [
{
"body": "<p>Looks pretty good. Some notes:</p>\n\n<ul>\n<li><code>(Time.now - 1.day)</code> -> <code>1.day.ago</code></li>\n<li><code>\"08/08/2013\".to_time</code>: I'd be in doubt \"is that day/month or month/day?\". An alternative to avoid problems with the parsing format: <code>Time.new(2013, 8, 8)</code><... | {
"AcceptedAnswerId": "49891",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:39:33.543",
"Id": "49867",
"Score": "5",
"Tags": [
"ruby",
"ruby-on-rails",
"curl",
"web-scraping"
],
"Title": "Reverse-engineering with Filepicker API"
} | 49867 |
<p>I have recently been asked to do a test prior to an interview to test my C# skills. I am fairly new to C# (6 months) and I think this showed with me producing an overly complex answer to their questions.</p>
<p>I will post the 3 questions below as well as my answers. Please can someone give me a better solution to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:47:41.797",
"Id": "87778",
"Score": "2",
"body": "For question 1, you might want to take a look at the many [tag:fizzbuzz] implementations and reviews on this site ;)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>Just some general remarks:</p>\n\n<ol>\n<li><p>Question 1 is just a derivative of the classic FizzBuzz but using different words as mentioned in the comments.</p></li>\n<li><p>None of the questions actually require you to store all the number. You are wasting a lot of space but storing them all an... | {
"AcceptedAnswerId": "51054",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:43:11.763",
"Id": "49868",
"Score": "3",
"Tags": [
"c#",
"linq",
"delegates"
],
"Title": "Test questions - Number Generator, Linq, Delegates, Sequences"
} | 49868 |
<p>I'm working on a parsing engine as part of a personal project, and I'd like to expose certain .NET APIs to the parsed environment. I put together a very simple tagged union that allowed me to nest types, and put together a few functions that built up a tree of namespaces. Before going further, I decided I needed to ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T21:08:20.713",
"Id": "87802",
"Score": "0",
"body": "What is your motivation for doing this? The built-in reflection APIs already provide a graph of types and members (e.g. `Type` has members for accessing methods, properties, and f... | [
{
"body": "<pre><code>type Node\n</code></pre>\n\n<p>I agree with you that this is too weakly typed.</p>\n\n<hr>\n\n<pre><code>type Lvl1\nand Lvl2\nand Lvl3\n</code></pre>\n\n<p>I don't like the naming here. The name <code>Lvl2</code> doesn't really say much. Better names would be something like <code>Namespace... | {
"AcceptedAnswerId": "50942",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:48:03.060",
"Id": "49869",
"Score": "2",
"Tags": [
"f#"
],
"Title": "Organizing types/namespaces within tree"
} | 49869 |
<p>I was curious which way is generally preferred, or if there is even a preference, given these two options:</p>
<pre><code>$.ajax({
url: '../Component/GetSearchFilters',
success: function (response) {
console.log("Outer scope:", this);
}.bind(this)
});
</code></pre>
<p>If I was inside of a funct... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-09-15T17:32:12.190",
"Id": "191700",
"Score": "0",
"body": "While this question was originally closed as \"unclear\" (presumably for lack of context), it should be noted that by today's standards it would be closed as \"hypothetical\" cod... | [
{
"body": "<p>Things that would favor <code>var self = this;</code></p>\n\n<ul>\n<li><p><a href=\"https://kangax.github.io/compat-table/es5/\"><code>bind</code> isn't supported in IE8 and Safari5</a>. If you aim to build a library or code that supports legacy browsers, then <code>var self = this</code> would be... | {
"AcceptedAnswerId": "49876",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T18:58:01.027",
"Id": "49872",
"Score": "52",
"Tags": [
"javascript"
],
"Title": "Using var self = this or .bind(this)?"
} | 49872 |
<p>I'm trying to rewrite this:</p>
<pre><code>def flatten(lst):
flat = []
for x in lst:
if hasattr(x, '__iter__') and not isinstance(x, basestring):
flat.extend(flatten(x))
else:
flat.append(x)
return flat
In [21]: a=[1, [2, 3, 4, [5, 6]], 7]
In [22]: flatten(a)
O... | [] | [
{
"body": "<p>You can use the compiler module </p>\n\n<pre><code>from compiler.ast import flatten\n\n>>> flatten([1,[2,3])\n>>> [1,2,3]\n</code></pre>\n\n<p>I hope this helps</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T13:05:2... | {
"AcceptedAnswerId": "49882",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T19:11:05.057",
"Id": "49877",
"Score": "4",
"Tags": [
"python",
"recursion",
"iterator",
"lazy"
],
"Title": "Recursive flatten with lazy evaluation iterator"
} | 49877 |
<p>I've got a minimal implementation (under 2k minified) of the <a href="https://github.com/amdjs/amdjs-api/blob/master/AMD.md">Asynchronous Module Definition</a> API. So far it handles all of the required stuff (I think; it passes the relevant <a href="https://github.com/amdjs/amdjs-tests">unit tests</a>, anyway), and... | [] | [
{
"body": "<p>This code is good</p>\n\n<ul>\n<li>JsHint only found 1 unused variable and 1 missing semicolon</li>\n<li>I grokked most of the code after the first read</li>\n<li>Well named variables/functions</li>\n<li>well commented (I am not a big fan of the auto doc comments, but to each their own)</li>\n<li>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T19:25:46.617",
"Id": "49879",
"Score": "6",
"Tags": [
"javascript",
"asynchronous",
"modules"
],
"Title": "Minimal but complete AMD implementation"
} | 49879 |
<p>I am using the code below to capitalize a string properly. I would like to know if there is a better way to code the surname portion, as the way it stands now can become very bloated depending on how many surnames I plan on adding.</p>
<p>This is a follow up to: <a href="https://codereview.stackexchange.com/questio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T21:33:46.340",
"Id": "87804",
"Score": "0",
"body": "this is a really good question. what if you have something like `O'`neill or other prefixes as well?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-... | [
{
"body": "<p>If you are going to create a list of the last names it will get very big, but you would have a list of the names so you could instead </p>\n\n<pre><code>surnames.Add(\"McDonald\")\n</code></pre>\n\n<p>And then </p>\n\n<pre><code>else\n foreach name in surnames\n if lcase(item) = lcase(na... | {
"AcceptedAnswerId": "49890",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T19:47:59.977",
"Id": "49884",
"Score": "4",
"Tags": [
"vbscript",
"asp-classic"
],
"Title": "Proper capitalization for surname like McDonald"
} | 49884 |
<p>It is not always possible to simplify program design by strictly managing the lifetimes of objects. If two objects have unpredictable lifetimes, but one of them needs to refer to the other, a simple pointer or reference is a segmentation fault waiting to happen.</p>
<hr>
<p>One solution would be to allocate the ob... | [] | [
{
"body": "<ul>\n<li><p>To \"answer\" this comment:</p>\n\n<blockquote>\n<pre><code>#include <memory> //required for placement new?\n</code></pre>\n</blockquote>\n\n<p>No, that library isn't required for basic uses of <code>new</code> (it's a keyword). However, a feature such as <code>std::nothrow<... | {
"AcceptedAnswerId": "94947",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T21:00:14.727",
"Id": "49888",
"Score": "7",
"Tags": [
"c++",
"c++11",
"memory-management",
"template",
"container"
],
"Title": "Associative container that produces a un... | 49888 |
<p>I wrote a small program that aims to take some data from the MongoDB database and put them in the RabbitMQ queue.</p>
<p>I tried to use only promise style but I am a beginner in JavaScript. Could you please help me to improve my first draft?</p>
<pre><code>var mongo = require('mongod');
var amqp = require('amqplib... | [] | [
{
"body": "<p>You have some magic strings:</p>\n\n<pre><code>return amqp.connect('amqp://localhost')\n</code></pre>\n\n<p></p>\n\n<pre><code>this.mongo.db = mongo('mongodb://127.0.0.1:27017/test', ['test']);\n</code></pre>\n\n<p>These strings should be kept in a high scope variable, so that you can easily maint... | {
"AcceptedAnswerId": "51442",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T22:07:23.957",
"Id": "49892",
"Score": "11",
"Tags": [
"javascript",
"node.js",
"promise",
"mongodb",
"rabbitmq"
],
"Title": "NodeJS broker between MongoDB and RabbitMQ... | 49892 |
<p>Lazy evaluation refers to a variety of concepts that seek to avoid evaluation
of an expression unless its value is needed, and to share the results of evaluation of an expression among all uses thereof, so that no expression need
be evaluated more than once.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T23:42:46.070",
"Id": "49895",
"Score": "0",
"Tags": null,
"Title": null
} | 49895 |
Lazy evaluation refers to a variety of concepts that seek to avoid evaluation of an expression unless its value is needed, and to share the results of evaluation of an expression among all uses of its, so that no expression need be evaluated more than once. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-15T23:42:46.070",
"Id": "49896",
"Score": "0",
"Tags": null,
"Title": null
} | 49896 |
<p>Someone says that my PHP code is vulnerable to XSS. I asked them what I should do to fix it, but now they don't want to help.</p>
<pre><code>$action=$_REQUEST['action'];
/* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T01:43:11.793",
"Id": "87821",
"Score": "0",
"body": "This probably isn't what they were referring to, but also consider what would happen if `$_REQUEST['name']` and/or `$_REQUEST['email']` contained newlines. Also, you may want to c... | [
{
"body": "<p>Short version: Yes.</p>\n\n<p>Long version:</p>\n\n<ul>\n<li><a href=\"https://security.stackexchange.com/q/12568/36190\">If the recepient opens the email using a browser</a>.</li>\n<li>You only guard your inputs using empty checks.\n\n<ul>\n<li>You didn't check for malicious scripts. One can easi... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T01:33:01.323",
"Id": "49901",
"Score": "3",
"Tags": [
"php",
"security",
"email"
],
"Title": "PHP form-to-email script"
} | 49901 |
<p>I designed this layout in Balsamiq for my <code>ProfileActivity</code>and I tried to replicate it. The screen on the left fits the correct proportions, whereas the screen on the right has a stretched out view of all the content in the activity.</p>
<p><img src="https://i.stack.imgur.com/XGVyA.png" alt="Balsamiq moc... | [] | [
{
"body": "<h2>Overusing RelativeLayout</h2>\n\n<p>Yes, you're overusing it a bit:</p>\n\n<ul>\n<li><p>Many times you wrap a single view inside <code>RelativeLayout</code>. Try to remove those wrappers.</p></li>\n<li><p>There seem to be an unnecessary layer of <code>RelativeLayout</code> around the box with POS... | {
"AcceptedAnswerId": "50908",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T04:19:32.653",
"Id": "49903",
"Score": "4",
"Tags": [
"android",
"xml"
],
"Title": "First attempt at designing a 'ProfileActivity'"
} | 49903 |
<p>Taking inspiration from <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.1">SICP Exercise 2.1</a>, I decided to implement a module in Haskell for rational numbers.</p>
<p>Some of my concerns include:</p>
<ul>
<li>Is this idiomatic Haskell?</li>
<li>Besides <code>Num</code>, <code>Eq</c... | [] | [
{
"body": "<p>Not too bad.</p>\n\n<ol>\n<li>You do not export Rational' from the module so no outside code can make one directly</li>\n<li><code>numer</code> and <code>denom</code> will conflict with a similar function name in any other code which imports your module. Perhaps <code>rational'Numer</code> and <co... | {
"AcceptedAnswerId": "50946",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T06:05:36.387",
"Id": "49907",
"Score": "6",
"Tags": [
"beginner",
"haskell",
"modules",
"rational-numbers"
],
"Title": "Module representing rational numbers"
} | 49907 |
<p>I have to extract <code>friendlyName</code> from the XML document.</p>
<p>Here's my current solution:</p>
<pre><code>root = ElementTree.fromstring(urllib2.urlopen(XMLLocation).read())
for child in root.iter('{urn:schemas-upnp-org:device-1-0}friendlyName'):
return child.text
</code></pre>
<p>Is there a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-01-10T02:46:54.767",
"Id": "287324",
"Score": "0",
"body": "This page contains the following errors: error on line 18 at column 20: Namespace prefix sec on ProductCap is not defined\nBelow is a rendering of the page up to the first error.... | [
{
"body": "<p>I am going to assume you are using Python's <a href=\"https://docs.python.org/2/library/xml.etree.elementtree.html\" rel=\"nofollow\">built-in XML library</a>. </p>\n\n<p>There are some <a href=\"https://docs.python.org/2/library/xml.etree.elementtree.html#supported-xpath-syntax\" rel=\"nofollow\"... | {
"AcceptedAnswerId": "51132",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-05-16T12:56:33.167",
"Id": "50909",
"Score": "4",
"Tags": [
"python",
"parsing",
"xml",
"python-2.x",
"namespaces"
],
"Title": "Extracting the text of a specific XML node"
} | 50909 |
<p>I created a user defined literal <code>_c</code> to convert an "integer" literal into an <a href="http://en.cppreference.com/w/cpp/types/integral_constant" rel="nofollow"><code>std::integral_constant</code></a>. Basically, the goal is to allow users to write <code>std::integral_constant</code> instances without the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T17:19:39.693",
"Id": "88004",
"Score": "2",
"body": "Maybe it would be more idiomatic if the type of the literal adjusted to the size of the number, just like for ordinary integer literals. The whole idea can also be simplified by u... | [
{
"body": "<h3>Usage of \"fat\" templates</h3>\n\n<p>I would try to avoid using full-blown class templates when there's an elegant alternative solution with alias templates or <code>constexpr</code> functions. Note that I didn't measure this, so take it with a grain of salt: lightweight constexpr functions and ... | {
"AcceptedAnswerId": "51576",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T13:10:07.330",
"Id": "50910",
"Score": "11",
"Tags": [
"c++",
"c++11",
"template-meta-programming",
"constant-expression"
],
"Title": "User defined literal for std::integra... | 50910 |
<p>Please tell me how I could have done this better. The code is <a href="https://github.com/fidepus/YAWP" rel="nofollow" title="here on Github">here on Github</a>.</p>
<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Write some message on the display.
# This project uses https://github.com/dbrgn/RPLCD.
# su... | [] | [
{
"body": "<h2>Basic Structure</h2>\n\n<p>I would recommend creating an <code>Elements</code> class.</p>\n\n<pre><code>class Elements():\n def __init__(self, day='', date='', low='', high='', weather=''):\n self.day = day\n self.date = date\n self.low = low\n self.high = high\n ... | {
"AcceptedAnswerId": "50916",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T13:10:59.910",
"Id": "50911",
"Score": "10",
"Tags": [
"python",
"beginner",
"raspberry-pi"
],
"Title": "Weather station for a Raspberry Pi"
} | 50911 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.