body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I'm new to ReactJs and trying to figure out the preferred style. I also have tried it enough to realize that I'm not a fan of jsx and prefer how React looks when written in coffeescript.</p>
<p>This is a very simple control (eventually will be a series of controls). It contains a select element and a button. When a... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T03:46:50.843",
"Id": "55653",
"Score": "3",
"Tags": [
"coffeescript",
"react.js"
],
"Title": "Create component with select+button"
} | 55653 |
<p>I've started learning C++ and I wanted to ask you to take a look at my linked list implementation and give comments what's wrong with. It compiles and runs fine, but I am curious about const correctness, proper use of pointers/references, etc., so feel free to go super tough on me!</p>
<p>I've read about these conc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T19:26:49.823",
"Id": "97785",
"Score": "1",
"body": "I would also recommend using sentinels on your list. It makes the code easier to write as you don't need to special case them empty list (As there is always a sentinel)."
}
] | [
{
"body": "<p>Your <code>Node</code> implementation is atypical of a common implementation. A node is really just a part of the linked list and just needs two data members: its data and a pointer to the next node (and a pointer to the previous node for a doubly-linked list). It does not need its own member fu... | {
"AcceptedAnswerId": "55659",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T03:59:26.203",
"Id": "55655",
"Score": "11",
"Tags": [
"c++",
"beginner",
"c++11",
"linked-list"
],
"Title": "Linked list implementation correctness"
} | 55655 |
<p>There's a part in my page where you can add, edit or delete school details, and it wasn't supposed to save entries to the database until the user hits <kbd>Enter</kbd>, so I save all data in an object first.</p>
<p>My object looks like this:</p>
<pre><code>schooldetails : {
"1": {
"school_ctr":"schoolctr_1",... | [] | [
{
"body": "<p>Indeed there is! Use <strong><a href=\"http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php\">prepared statements</a></strong> instead of manually escaping and inserting into your query!</p>\n\n<blockquote>\n <p><a href=\"http://bit.ly/phpmsql\"><strong>Please, don't use <code>m... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T06:51:08.320",
"Id": "55664",
"Score": "1",
"Tags": [
"php",
"object"
],
"Title": "More efficient way to loop through an object"
} | 55664 |
<h3>Some context</h3>
<p>I've been tasked with supplying an escaping function to arbitrary CSS values that are entered through a form. The goals and caveats are:</p>
<ul>
<li>I know it's bad practice to let users input CSS. Deal with it.</li>
<li>Data will be injected either to a <code>style</code> attribute, or to a... | [] | [
{
"body": "<p>There's not much to say. Overall, the code is small and quite readable.</p>\n\n<p>Just a small nitpick:</p>\n\n<pre><code>if (getUTF8CharCode($currChar) < 256 && //Character value is less than 256\n !preg_match(\"/^\\w$/\", $currChar) && //Character is not alphanumeric (under... | {
"AcceptedAnswerId": "55678",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T08:25:49.047",
"Id": "55667",
"Score": "7",
"Tags": [
"php",
"css",
"security",
"utf-8",
"escaping"
],
"Title": "Functions to escape CSS rules in PHP"
} | 55667 |
<p>I would like to add some capabilities to the server. Firstly, it should accept and handle connections with multiple clients, so that there are no mixups between clients. Secondly, there should be some very basic JDBC connectivity: serialize a result set as a List, and then, as requested pop from the list and send ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T09:21:52.167",
"Id": "97678",
"Score": "1",
"body": "While I would love to learn Log4J or a similar testing framework => Log4J is **not** a testing framework, it's a logging framework. http://junit.org/ is a testing framework."
}
... | [
{
"body": "<h1>Using imports:</h1>\n<blockquote>\n<pre><code>catch(java.net.SocketException se) { /* [...] */\nthrows java.net.SocketException { /* [...] */\n</code></pre>\n</blockquote>\n<p>fully qualifying these is unnecessary:</p>\n<pre><code>import java.net.SocketException;\n\ncatch(SocketException se) { /*... | {
"AcceptedAnswerId": "55673",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T08:26:32.667",
"Id": "55668",
"Score": "4",
"Tags": [
"java",
"database",
"io",
"server",
"client"
],
"Title": "How do I add JDBC and Queue functionality to a simple se... | 55668 |
<p>I building a very simple price tracker web app. I am using MongoDB with pymongo. The user will enter the URL of the product he wishes to track and the desired amount, when the price goes below this amount, he should get an alert. It doesn't matter how many products he is tracking, I will send the alert when price ch... | [] | [
{
"body": "<p>You should create a function that returns all the subscribers for a product:</p>\n\n<pre><code>def get_subscribers(product, current_price):\n tracker_document = db.trackers.find_one({'product_id': product['_id']})\n\n subscribers = set()\n for user_id, desired_price in tracker_document['s... | {
"AcceptedAnswerId": "55692",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T09:57:46.317",
"Id": "55674",
"Score": "5",
"Tags": [
"python",
"optimization",
"performance",
"mongodb",
"pymongo"
],
"Title": "E-commerce product price tracker"
} | 55674 |
<p><strong>Aim:</strong> To Assess if one, or more, examples of a value exists in a Database in the quickest time as I only needs a True/False result.</p>
<p>The variable is Alphanumeric.</p>
<p><strong>Question:</strong> Is this the quickest and best way to do this?</p>
<pre><code>Public Function PrcCheckIfValueExi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T07:33:12.563",
"Id": "97872",
"Score": "0",
"body": "Why does the code return Booleans when the signature suggests it should return a string?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T13:07:38.7... | [
{
"body": "<ol>\n<li>This code is open to <a href=\"http://xkcd.com/327/\">injection</a>. Consider\nwhat happens if I pass <code>sometext'; Drop Table TblTable; --</code> into\nthat variable. Use a proper parameterized query instead.</li>\n<li>The SQL statement itself is about as efficient as it can be to my\nk... | {
"AcceptedAnswerId": "55687",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T11:29:40.860",
"Id": "55679",
"Score": "10",
"Tags": [
".net",
"sql",
"vb.net"
],
"Title": "Find if value exists using SQL True/False Return"
} | 55679 |
<p>I use a thread to read from a UDP socket. Afterwards the string gets parsed.
In another thread I send to every connected client via this socket. I would like to keep latency and resources for running the script as low as possible. </p>
<p>It would be nice to add a time-out.</p>
<p>Every attempt to read should be ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T16:59:52.217",
"Id": "97761",
"Score": "0",
"body": "[Context](http://codereview.stackexchange.com/q/55337/9357)"
}
] | [
{
"body": "<p>I would instead use a single thread for both tasks and employ an <code>epoll</code> selector on the sockets with a certain timeout. To the best of my knowledge, this is more or less what popular networking frameworks (e.g., NodeJS, Nginx, Lighttpd, etc.) do. I always found waiting on a socket for ... | {
"AcceptedAnswerId": "55685",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T11:43:15.897",
"Id": "55680",
"Score": "2",
"Tags": [
"python",
"socket"
],
"Title": "Adding a timeout to an UDP socket server"
} | 55680 |
<p>I have the following function that checks if a number is prime:</p>
<pre><code>def is_prime(n):
""" Is n prime? """
if n < 2:
return False
if n in (2, 3):
return True
if n % 2 == 0 or n % 3 == 0:
return False
limit = int(math.sqrt(n))
divisor = 5
while div... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T03:18:24.530",
"Id": "97846",
"Score": "0",
"body": "If you want to save time you may want to use a faster, probabilistic test, like Baillie-PSW or Miller-Rabin for larger inputs (usually you quickly check for divisibility by some s... | [
{
"body": "<p>Your code looks nice, seems to follow PEP 8 and has docstrings. I don't have much to say about it but here are a few changes to make it look more pythonic.</p>\n\n<p>The <code>while</code> loop can be rewritten using a <code>for</code> loop with <code>range</code> (or <code>xrange</code>).</p>\n\n... | {
"AcceptedAnswerId": "55694",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T13:40:33.740",
"Id": "55691",
"Score": "10",
"Tags": [
"python",
"primes"
],
"Title": "Is_prime check in Python: can this be more pythonic?"
} | 55691 |
<p>I've recently started writing a tic-tac-toe game (following the Odin project) and am trying to write a class to hold the board game.</p>
<p>What I'm not sure about, is that the board class holds all the data related to the board in a variable called <code>@board</code>. Now after thinking about it I decided that th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T15:01:21.497",
"Id": "97722",
"Score": "1",
"body": "Please post your `Game` class as well."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T15:25:23.183",
"Id": "97739",
"Score": "0",
"bod... | [
{
"body": "<p>Yes, your <code>board.board</code> has a code smell, but it is hard to say what to do without knowing <code>Game</code>.</p>\n\n<p>Actually <code>Board#board</code> is an array. I would recommend to add methods to <code>Board</code> that allow you to use the instance of <code>Board</code> instead ... | {
"AcceptedAnswerId": "55712",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T14:03:37.007",
"Id": "55693",
"Score": "0",
"Tags": [
"object-oriented",
"ruby",
"game",
"tic-tac-toe"
],
"Title": "Cleaning up a class that contains the object it represen... | 55693 |
<p>I want to resize an image with good quality, and the most important thing is having less weight for an image so that webpages will load it faster.</p>
<p>I am using the below method for this. Please check it out, if it is proper or let me know if it needs any modifications. If there is a better method than this, th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T10:48:18.170",
"Id": "97703",
"Score": "0",
"body": "Does it work? Then it's OK."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T10:54:44.377",
"Id": "97704",
"Score": "0",
"body": "@CodeC... | [
{
"body": "<ul>\n<li>Variable type choice. Why do you use <code>Int16</code> and <code>float</code>? Most likely you'll be running on a 32-bit or 64-bit machine, and even the 32-bit machines will be optimized for math operations using <code>double</code>. I know you don't need perfect accuracy, but using the sm... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-29T10:33:33.830",
"Id": "55698",
"Score": "5",
"Tags": [
"c#",
"image"
],
"Title": "Resize image with good quality and less weight"
} | 55698 |
<p>We had a situation where it was necessary that a script only be running in one process at a time.</p>
<p>The solution was to make a "LockByProcess" class that checks a database for an existing process, and kill it if requested, or prevent the new process from starting if not.</p>
<p>Is there a better way to do thi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T15:15:02.147",
"Id": "97733",
"Score": "0",
"body": "find all the running processes using a shell command: `exec(sprintf('ps -A | grep %s', __FILE__), $out, $status);` process the `$out` array and handle situation accordingly. That'... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T14:40:03.463",
"Id": "55700",
"Score": "1",
"Tags": [
"php",
"locking",
"child-process"
],
"Title": "Lock a process in PHP"
} | 55700 |
<p>My code takes 143.023 seconds for extracting nodes from a road network of city like Göteborg in Sweden. Please check it out if I can optimize it.</p>
<pre><code># -*- coding: utf-8 -*-
import arcpy
from Class import loading_layer
import time
def node_extraction(network_input):
time_start=time.time()
node... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T14:53:17.243",
"Id": "97716",
"Score": "0",
"body": "Welcome to CodeReview.SE! Would you be able to provide you info so that we can test your script (sample input, command to run, etc) ?"
},
{
"ContentLicense": "CC BY-SA 3.0... | [
{
"body": "<h2>Performance:</h2>\n\n<pre><code>if start_list in list_of_existing_nodes:\n point_index=list_of_existing_nodes.index(start_list)\n nodes_list[point_index][1].append(feature[\"FID\"])\n</code></pre>\n\n<p>This is not an efficient way to update an existing element. The fact that you want to lo... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T14:41:05.067",
"Id": "55701",
"Score": "7",
"Tags": [
"python",
"graph",
"geospatial",
"arcpy"
],
"Title": "Extracting nodes from a road network"
} | 55701 |
<p>I have three models which look like this:</p>
<pre><code>class Post < ActiveRecord::Base
belongs_to :user, :counter_cache => :count_post
has_many :likes
end
class User < ActiveRecord::Base
has_many :posts
has_many :likes
end
class Like < ActiveRecord::Base
belongs_to :user
belongs_to :post... | [] | [
{
"body": "<p>Have you created an index for <code>likes.post_id</code>? Note also that you can simplify that method by using <a href=\"http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many\" rel=\"nofollow\">has_many</a> with the option <code>through</code> and <a href=\"http://apidock.com/r... | {
"AcceptedAnswerId": "55723",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T16:57:41.080",
"Id": "55715",
"Score": "4",
"Tags": [
"performance",
"ruby",
"ruby-on-rails"
],
"Title": "Better way of checking if the current user already like a post"
} | 55715 |
<p>As part of an assignment for my intro Java class (please bear with my beginner skill set), I'm working on a program for which a Die object class is used to play a Yahtzee game. An overview of the directions are as follows:</p>
<blockquote>
<p>The program should give an introduction of what it is going to do, ask
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T17:21:44.477",
"Id": "97765",
"Score": "4",
"body": "Welcome to Code Review, this is an excellent question you have posted here! Everything a reviewer could possibly ask for!"
}
] | [
{
"body": "<p>Before I criticize your code, I must say this is really a good piece of code and you're heading in a good direction. There is some really good stuff and all the following comments are just to make it better. </p>\n\n<h2>rollDice</h2>\n\n<p>Like @toto2 said, this method could be better. I'll add a ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T17:06:58.530",
"Id": "55716",
"Score": "16",
"Tags": [
"java",
"beginner",
"game",
"homework",
"dice"
],
"Title": "Yahtzee game (using arrays and object classes)"
} | 55716 |
<p>I want to calculate the nearest cosine neighbors of a vector using the rows of a matrix, and have been testing the performance of a few Python functions for doing this. </p>
<pre><code>def cos_loop_spatial(matrix, vector):
"""
Calculating pairwise cosine distance using a common for loop with the numpy cosin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T17:23:35.647",
"Id": "97766",
"Score": "0",
"body": "What was your test case?"
}
] | [
{
"body": "<ol>\n<li><p>Your code does not run: there are missing <code>import</code> statements:</p>\n\n<pre><code>import numpy as np\nimport scipy.spatial.distance\n</code></pre></li>\n<li><p>Your algorithms compute different results, so some of them must be wrong!</p>\n\n<pre><code>>>> vector = np.a... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T17:18:40.883",
"Id": "55717",
"Score": "10",
"Tags": [
"python",
"numpy"
],
"Title": "Efficient numpy cosine distance calculation"
} | 55717 |
<p>Reverse a doubly linkedlist. Looking for code review, optimizations and best practices.</p>
<pre><code>public class ReverseDoublyLinkedList<T> implements Iterable<T> {
private Node<T> first;
private Node<T> last;
private int size;
public ReverseDoublyLinkedList() { };
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T20:38:56.750",
"Id": "97794",
"Score": "4",
"body": "A doubly-linked list, by definition, can be traversed in either direction. What purpose is served by swapping `left` and `right` that wouldn't be served better and more efficient... | [
{
"body": "<p>The name <code>ReverseDoublyLinkedList</code> is not so good. Just stick to <code>DoublyLinkedList</code>.</p>\n\n<p>It would make more sense if the <code>reverse</code> method returned a new instance of the list. Actually, I would have defined a static method that takes a list and return a reve... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T19:37:14.610",
"Id": "55727",
"Score": "0",
"Tags": [
"java",
"linked-list"
],
"Title": "Reverse a doubly linkedlist"
} | 55727 |
<p>Like everyone, I use <code>ListView</code>s in a lot of apps. And I pretty much always end up making a custom Adapter. Yet 90% of my custom adapters end up doing the same thing (mapping directly from an <code>ArrayList</code> or array) with <code>getView()</code> overridden to update the views. I hate rewriting t... | [] | [
{
"body": "<p>It looks good, few comments though:</p>\n\n<ul>\n<li><p>OOP is all about implementation hiding, so make sure you hide as much as possible.By default, instance variables are <code>package private</code>, which is the case for your variables.</p>\n\n<pre><code>Activity ctx;\nArrayList<ModelType&g... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T19:53:31.277",
"Id": "55728",
"Score": "3",
"Tags": [
"java",
"android"
],
"Title": "A generic MVC ArrayAdapter class"
} | 55728 |
<p>I recently started using the Builder pattern in one of my projects.</p>
<p>Below is my builder class -</p>
<pre><code>public final class DataKey {
private final long userId;
private final String uuid;
private final String deviceId;
private final int clientId;
private final long timeout;
pr... | [] | [
{
"body": "<p>My first comment is there is duplication in your createURL(). I find that as duplication is reduced, new abstractions start to avail themselves.. Or I just end up with code that's simpler and easier to read. Here's my take on your createURL():</p>\n\n<pre><code>public String createURL() {\n Str... | {
"AcceptedAnswerId": "55816",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T20:57:15.143",
"Id": "55730",
"Score": "1",
"Tags": [
"java",
"optimization",
"enum",
"url"
],
"Title": "Making a URL by prioritizing the keys if multiple keys are present ... | 55730 |
<h2>Secondary Review</h2>
<p><strong>Changes:</strong></p>
<p>I recently requested a review: <a href="https://codereview.stackexchange.com/questions/55531/script-to-convert-shift-spacebar-into-four-spaces-on-se">Script to convert Shift + Spacebar into four spaces on SE</a>. After accepting suggestions and improvement... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T21:49:47.937",
"Id": "97801",
"Score": "0",
"body": "I think current title is too similar to the first review request on this code. The code is very different, but the purpose is generally the same. Suggestions on title edit?"
},
... | [
{
"body": "<p>This answer is not a full review, but just a minor tweak.</p>\n<p>So you go by <code>Shift+Space</code> to indent, and <code>Ctrl+Shift+Space</code> to outdent. That's really weird. Take a moment to observe what <code>Shift</code> actually does in common keyboard shortcuts:</p>\n<h1>Page Scrolling... | {
"AcceptedAnswerId": "57539",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T21:48:39.130",
"Id": "55733",
"Score": "9",
"Tags": [
"javascript",
"jquery",
"stackexchange"
],
"Title": "Script to convert Shift + Spacebar into four spaces on SE - Second Im... | 55733 |
<p>I extended <code>NumberPicker</code> with several methods needed in my application. When I came to defining a <code>OnValueChangeListener</code> this is how I did it:</p>
<pre><code>import android.widget.NumberPicker;
interface ValueChangeCallback {
public void execute(RemListView list, int oldVal, int newVal)... | [] | [
{
"body": "<p>I think you have missed the point with the NumberPicker here. There is no need to add in a new level of abstraction for your application.</p>\n\n<p>Right now your 'calling' code needs to implement a <code>ValueChangeCallback</code> class, and call <code>setValueChangeCallback(callback)</code>. The... | {
"AcceptedAnswerId": "55877",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T21:54:10.233",
"Id": "55734",
"Score": "6",
"Tags": [
"java",
"android"
],
"Title": "Passing listener to customized extended View in Android"
} | 55734 |
<p>I've posted a revised version of this <a href="https://codereview.stackexchange.com/questions/56477/revised-job-queue-for-strategy-game">here</a>.</p>
<p>I posted about this basic problem a while ago, and I got the recommendation to move the code for managing the Jobs of my game to another class. I have been worki... | [] | [
{
"body": "<blockquote>\n <p>This all seem pretty complicated, but is it too complicated? Or rather, is it too complicated to understand, or more complicated than it needs to be?</p>\n</blockquote>\n\n<p>My answer? I don't know. Maybe. I mean, you're trying to do complicated stuff, so of course the code is ... | {
"AcceptedAnswerId": "55836",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T22:18:27.830",
"Id": "55735",
"Score": "5",
"Tags": [
"object-oriented",
"game",
"objective-c",
"queue"
],
"Title": "Job Queue for Strategy Game"
} | 55735 |
<p>I was reading Joshua Blochs "Effective Java 2nd edition" item 29, which describes how to create Heterogeneous containers, in the end of chapter he wrote:</p>
<blockquote>
<p>A Class object used in this fashion is called a type token. You can
also use a custom key type. For example, you could have a DatabaseRow
... | [] | [
{
"body": "<p>There are two things I would like to point out here.</p>\n\n<ol>\n<li><p>There is no need to do the cast on the <code>putColumn</code> call. The method signature is: <code>public <T> void putColumn(Column<T> type, T instance) {</code> so we know that instance is of type <code>T</code> ... | {
"AcceptedAnswerId": "55739",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T22:29:15.737",
"Id": "55737",
"Score": "5",
"Tags": [
"java"
],
"Title": "Typesafe heterogeneous container"
} | 55737 |
<p>I have written this code for an Edx course called CS50x (a beginner course).</p>
<p>This problem set required me to write a program which:</p>
<ul>
<li>loaded a dictionary into some sort of data structure (I choose to implement a trie) and which could take an input text and search for misspellings</li>
<li>uses a fi... | [] | [
{
"body": "<ul>\n<li><p>Naming</p>\n\n<p>Many names in your program are not very meaningful. <code>check</code> can mean anything. In your context it means that the word is known, valid, correct (pick one), so the function shall be named along the lines of <code>isWordKnown</code>. Pretty much the same can be s... | {
"AcceptedAnswerId": "55763",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T00:09:42.170",
"Id": "55743",
"Score": "5",
"Tags": [
"performance",
"c",
"beginner",
"hash-map",
"trie"
],
"Title": "Spell Check and Trie implementation"
} | 55743 |
<p>Google Apps Script is a JavaScript cloud scripting language for automating tasks across Google products and third party services. </p>
<h3>Useful links:</h3>
<ul>
<li><a href="https://developers.google.com/apps-script/" rel="nofollow noreferrer">Developer Documentation</a> - and sidebar has links to issues tracker... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T01:27:54.283",
"Id": "55748",
"Score": "0",
"Tags": null,
"Title": null
} | 55748 |
Google Apps Script is a JavaScript cloud scripting language for automating tasks across Google products and third party services. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T01:27:54.283",
"Id": "55749",
"Score": "0",
"Tags": null,
"Title": null
} | 55749 |
<p>This is my first solo Objective-C program... it does the complicated task of displaying a button and counting how many times it's been pressed. It retains that count (along with the last time it was pressed) between uses of the app. I have a few specific questions, but eagerly await any and all feedback.</p>
<ol>... | [] | [
{
"body": "<p>The first thing that needs to be addressed is the try-catch block.</p>\n\n<p>Without (for now) addressing whether or not you're taking the best approach for this sort of persistent data, the fact of the matter here is that there's not a single exception that your try-catch block is going to catch.... | {
"AcceptedAnswerId": "55832",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T02:07:36.043",
"Id": "55750",
"Score": "10",
"Tags": [
"objective-c",
"ios"
],
"Title": "First simple program; counting button presses"
} | 55750 |
<p>Working through <a href="http://learnyouahaskell.com/functionally-solving-problems" rel="nofollow">Learn You a Haskell</a>, I made a <code>Reverse Polish Notation</code> calculator.</p>
<p>Please critique it.</p>
<pre><code>-- LYAH uses `(Num a) => String -> a` as the signature
solveRPN :: String -> Doubl... | [] | [
{
"body": "<p>Using <code>foldl</code> is the right idea, I think. <code>(\\acc x -> foldingFunction acc x)</code> is a useless lambda, which could just be written as <code>foldingFunction</code>. The fact that it's a folding function is evident from the fact that you passed it to <code>foldl</code>; you c... | {
"AcceptedAnswerId": "55771",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T02:20:07.403",
"Id": "55752",
"Score": "6",
"Tags": [
"haskell",
"reinventing-the-wheel",
"math-expression-eval",
"calculator"
],
"Title": "Reverse Polish Notation Calculat... | 55752 |
<p>I recently started using Builder pattern in one of my projects and I am trying to add some sort of validations on my Builder class. I have already <a href="https://codereview.stackexchange.com/q/55585">asked a question,</a> got some feedback and incorporated it into my code.</p>
<p>Below is my builder class -</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T06:47:06.560",
"Id": "97867",
"Score": "0",
"body": "@Vogel612 Thanks for edit Vogel. I will make sure that next time to add that as well."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T08:16:24.630"... | [
{
"body": "<h2>Flags and Flag-flags:</h2>\n\n<p>Everytime your Variable name includes flag, there should be a flag raised in your head. You then should go back and either extract a method or a class.</p>\n\n<p>Usually a flag means you are trying to do two different things in one method and that's something you ... | {
"AcceptedAnswerId": "55768",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T02:21:48.630",
"Id": "55754",
"Score": "7",
"Tags": [
"java",
"optimization",
"enum"
],
"Title": "Validating multiple keys in the builder class based on the rules"
} | 55754 |
<p>So, another challenge from my professor. I've finished it, but wanted to get some feedback, and see how other people might work this problem.</p>
<blockquote>
<p>Assume you have a string, such as "Hello 34215 World 5620 From 384 Bloomington"</p>
<p>Use list comprehension to separate the words from the number... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T23:42:38.023",
"Id": "97841",
"Score": "0",
"body": "`\"\".join(x for x in s if not x.isdigit()) +\" | \"+ \"\".join(sorted(x for x in s if x.isdigit() ))`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-... | [
{
"body": "<p><a href=\"https://codereview.stackexchange.com/users/42080/padraic-cunningham\">Padraic Cunningham</a> nailed the shortest form in his comment:</p>\n\n<pre><code>\" \".join(x for x in s.split() if not x.isdigit()) + \" | \" + \"\".join(sorted(x for x in s if x.isdigit()))\n</code></pre>\n\n<p>Expl... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-30T23:23:21.207",
"Id": "55756",
"Score": "2",
"Tags": [
"python",
"strings",
"integer"
],
"Title": "Tough List Comprehension Split Letters and Numbers"
} | 55756 |
<p>I have a spreadsheet, called "To Do", with set of percentages in column <code>E</code> and importance levels in column <code>A</code>:</p>
<p><img src="https://i.stack.imgur.com/opbWZ.png" alt="screenshot depicting the spreadsheet with the data"></p>
<p>On another spreadsheet, I'm entering a formula to calculate t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T15:04:38.543",
"Id": "97943",
"Score": "1",
"body": "Ask Google to add `SUMIFS()` / `COUNTIFS()` / `AVERAGEIF()` ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T15:33:56.173",
"Id": "97949",
... | [
{
"body": "<p><strong>Use a pivot</strong></p>\n\n<p>Your approach works, and I'll give you that. I feel you are overcomplicating something that is, on the whole, quite simple. Instead of using numbers 1-10,000 to define priority, why not use a simple method like numbers <code>{1,2,3,4,5,6,7,8,9}</code> and jus... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T04:44:21.453",
"Id": "55759",
"Score": "12",
"Tags": [
"excel",
"google-sheets"
],
"Title": "Averaging a set of percentages between certain important levels"
} | 55759 |
<p>Here is the link to the problem <a href="https://open.kattis.com/problems/peragrams">Peragrams</a>.</p>
<blockquote>
<p><strong>Peragrams</strong>: If a word is an anagram of at least one palindrome, we call it a Peragram. </p>
<p><strong>Problem</strong>: Given a string, find the minimum number of letters y... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T05:25:38.803",
"Id": "97862",
"Score": "1",
"body": "Input 2: abb, Output 2: 0. Surely that's not right."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T05:28:08.820",
"Id": "97863",
"Score": ... | [
{
"body": "<p>The approach you are taking is to remove letters until at most one of them has an odd count. Once you realise that, the solution becomes obvious:</p>\n\n<pre><code>from collections import Counter\n\ns = input() # don't call your own variable 'str'\n\nc = Counter(s)\n\nodds = [None for n in c.value... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T04:58:13.713",
"Id": "55761",
"Score": "5",
"Tags": [
"python",
"algorithm",
"python-3.x",
"programming-challenge",
"palindrome"
],
"Title": "Minimum number of letters rem... | 55761 |
<p>This is for <a href="http://projecteuler.net/problem=30">Project Euler #30</a>:</p>
<blockquote>
<p>Surprisingly there are only three numbers that can be written as the
sum of fourth powers of their digits:</p>
<p>\$1634 = 1^4 + 6^4 + 3^4 + 4^4\$<br>
\$8208 = 8^4 + 2^4 + 0^4 + 8^4\$<br>
\$9474 = 9^... | [] | [
{
"body": "<p>Here is a little simpler way to write your code:</p>\n\n<pre><code>list = (2..1_000_000).select do |num|\n num.to_s.chars.map {|digit| digit.to_i ** 5}.inject(:+) == num\nend\n</code></pre>\n\n<ol>\n<li><p>Using map twice is not big issue here, you operate on small collection and memory is not an... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T05:09:47.693",
"Id": "55762",
"Score": "6",
"Tags": [
"ruby",
"programming-challenge"
],
"Title": "Project Euler code evaluation - digit fifth powers"
} | 55762 |
<p>I need to find all paths from a given graph. I can do that for now, however my recursive code is not efficient and my graphs are very complicated, hence I need a better algorithm.</p>
<pre><code>def findLeaves(gdict):
# takes graph and find its leaf nodes
leaves = []
for endNode in gdict.iterkeys():
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T07:53:54.800",
"Id": "97873",
"Score": "0",
"body": "Welcome to CodeReview! Can you please tell us more about how we are suppose to run your code ? Trying to put your functions and you data in a script to run it, I first get differe... | [
{
"body": "<h3>1. Introduction</h3>\n\n<p>Your goal (if I understand correctly, of generating all the execution paths in a state transition graph for a Java thread and then using those execution paths to test the code) seems unrealistic to me.</p>\n\n<p>Even in an acyclic graph (or with the condition that you m... | {
"AcceptedAnswerId": "56423",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T07:20:38.147",
"Id": "55767",
"Score": "10",
"Tags": [
"python",
"algorithm",
"graph"
],
"Title": "Finding all paths from a given graph"
} | 55767 |
<p>I have the following two queries:</p>
<pre><code>res=session.query(t_marketing_mailing_stats_tbl).filter(
t_marketing_mailing_stats_tbl.c.mailing_id==mid)
res_t=session.query(t_marketing_time_stat_tbl).filter(
t_marketing_time_stat_tbl.c.mailing_id==mid)
try:
return res.one() + res_t.one()
except NoRe... | [] | [
{
"body": "<p>Your basic problem is you want to combine...erm, join... similar data from your database. There are a couple different angles we can take to solve this problem:</p>\n\n<ol>\n<li>We could do as you are, but a more simple way.</li>\n<li>We can let the database do the work.</li>\n</ol>\n\n<p>The seco... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T08:18:37.107",
"Id": "55769",
"Score": "3",
"Tags": [
"python",
"sqlalchemy"
],
"Title": "Joining two KeyedTuple objects in SQLAlchemy"
} | 55769 |
<p>Is there any way to optimize this stored procedure? Maybe something instead of so many joins? It takes some time to execute. Maybe there are other options that I could look into?</p>
<pre><code> SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [stimulator].[GetLastMessages2]
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T10:00:07.653",
"Id": "97890",
"Score": "2",
"body": "Welcome to Code Review! To make life easier for reviewers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of d... | [
{
"body": "<p>A couple of things to think about while writing your query....</p>\n\n<h2>Variable Naming</h2>\n\n<pre><code>ALTER PROCEDURE [stimulator].[GetLastMessages2]\n @serviceId bigint,\n @stimulatorId int,\n @from datetime,\n @to datetime,\n @atLeast int = null,\n @lessThan int = null,\... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T09:41:08.503",
"Id": "55774",
"Score": "11",
"Tags": [
"sql",
"sql-server",
"stored-procedure"
],
"Title": "Speeding up a stored procedure"
} | 55774 |
<p>I am trying to grasp the concept of delegates and protocols in Swift. So I have implemented my own <code>PlayableMedia</code> protocol with two concrete classes <code>BlueRayMedia</code> and <code>DVDMedia</code> like so:</p>
<pre><code>protocol PlayableMedia {
func play()
func stop()
}
class BlueRayMedia:... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T12:09:25.583",
"Id": "97905",
"Score": "0",
"body": "You current code doesn't really need protocols and delegates; you could (and should) do all of it with regular inheritance. Besides, it seems backwards that `didStartPlaying` gets... | [
{
"body": "<p>This is a straight-forward protocol conformance. Whether this is really a delegation pattern is perhaps a little bit more subjective, but again, seems to adhere to Apple's view (<a href=\"https://developer.apple.com/library/ios/documentation/general/conceptual/DevPedia-CocoaCore/Delegation.html\" ... | {
"AcceptedAnswerId": "55840",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T09:55:44.273",
"Id": "55775",
"Score": "8",
"Tags": [
"design-patterns",
"delegates",
"swift"
],
"Title": "Is this a correct use of using protocols and delegate pattern in Swif... | 55775 |
<p>I'm iterating through two lists to find matching objects. The objects have two string properties, <code>Id1</code> and <code>Id2</code> below. If <code>Id1</code> is not <code>null</code>, empty or whitespace, I want to use it to find a matching object in the other list. Otherwise I want to make use of <code>Id2</co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T11:08:37.353",
"Id": "97898",
"Score": "0",
"body": "It isn't very clear to me what you're attempting to do but I feel like this can be greatly simplified with a few lines of LINQ. Can you give some sample input/output so I can add ... | [
{
"body": "<p>Let's start refactoring!</p>\n\n<pre><code>foreach (Product p2 in productList1)\n{ \n Product match = productList2.FirstOrDefault(p =>\n {\n string pId = p.Id1.NullIfEmptyOrWhiteSpace() ??\n p.Id2.NullIfEmptyOrWhiteSpace();\n\n string p2Id = p2.Id1.NullIf... | {
"AcceptedAnswerId": "55781",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T10:52:00.023",
"Id": "55778",
"Score": "7",
"Tags": [
"c#",
"null"
],
"Title": "Getting matching items in lists based on nullable properties"
} | 55778 |
<p>Some time ago, <a href="https://codereview.stackexchange.com/questions/47949/optimizing-sudoku-solver-in-c">this question</a> was posed, asking for help in optimizing a Sudoku solver implemented in C++. </p>
<p>I decided to reimplement the code using C++11, but without guessing. That is, this Sudoku solver does <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T13:17:56.447",
"Id": "97920",
"Score": "3",
"body": "I really wish there was more detail about how the rows, cols and ssquare arrays were structured, the numbers do not make sense to me.... more comments?"
},
{
"ContentLicen... | [
{
"body": "<p>The solving rules for Sudoku are very symmetrical. You can usually apply the same rule to row/col/block and this is seen in your initial solution block where you call <code>doPairElimination()</code> and <code>doOnlyInNine()</code> both three times.</p>\n<p>It might be easier to read if you genera... | {
"AcceptedAnswerId": "55812",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T11:32:51.803",
"Id": "55780",
"Score": "27",
"Tags": [
"c++",
"c++11",
"sudoku",
"community-challenge",
"rags-to-riches"
],
"Title": "Sudoku solver in C++"
} | 55780 |
<p>I'm using <a href="https://code.google.com/p/guava-libraries/" rel="nofollow">Google Guava</a> 17.0 library. I have a class named <code>AroundBust</code> containing only two properties <code>id</code> of type <code>Integer</code> and <code>size</code> of type <code>BigDecimal</code>.</p>
<p>This class is instantiat... | [] | [
{
"body": "<p>Code smell: you are doing the same thing over and over again, with different instances of the same variable type.</p>\n\n<pre><code> if(idValue!=null) {\n entireList=idValue.sortedCopy(entireList);\n } else if(valueId!=null) {\n entireList=valueI... | {
"AcceptedAnswerId": "55791",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T11:46:03.437",
"Id": "55782",
"Score": "11",
"Tags": [
"java",
"sorting",
"collections",
"guava",
"jsf"
],
"Title": "Efficient way of sorting a List based on multiple p... | 55782 |
<p>To review my use of multiprocessing, I don't think it is at all necessary to understand the algorithm, but it's the scrypt key-derivation function.</p>
<p>This uses <code>hashlib.pbkdf2_hmac</code> which was added in Python 3.4. To run it using earlier versions, you can paste in <code>pbkdf2_hmac</code> <a href="ht... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T17:12:39.917",
"Id": "97977",
"Score": "0",
"body": "What was wrong with [`scrypt`](https://pypi.python.org/pypi/scrypt)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T19:53:30.133",
"Id": "9800... | [
{
"body": "<p>I was able to shave some milliseconds off by moving the <code>struct.pack</code> call inside the <code>map</code> calls, which let me get rid of the explicit loop:</p>\n\n<pre><code>def smix_mp(args):\n B, r, N = args\n B = list(B)\n XY = [0] * (64 * r)\n V = [0] * (32 * r * N)\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T12:03:10.757",
"Id": "55784",
"Score": "5",
"Tags": [
"python",
"performance",
"algorithm",
"cryptography",
"multiprocessing"
],
"Title": "Parallelizing scrypt key-derivat... | 55784 |
<p>This program is to return a number one at a time from a given input list of numbers, with a frequency proportional to probability/fraction associated with each number.</p>
<p>I know it could be made a generator function. But if I have to do it inside a class, can you please suggest improvements to this code, partic... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T13:07:29.373",
"Id": "97916",
"Score": "2",
"body": "Welcome to CodeReview.SE! Can you give us a simple example to know how to use your code ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T13:42:11.... | [
{
"body": "<p>Frankly, it seems unnecessary to have any custom exceptions (and if you keep them, they should all have <a href=\"http://legacy.python.org/dev/peps/pep-0008/#exception-names\" rel=\"nofollow\">PEP-8-compliant names</a>). All of the custom exceptions could just be <a href=\"https://docs.python.org/... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T12:12:54.337",
"Id": "55786",
"Score": "5",
"Tags": [
"python",
"mathematics",
"error-handling"
],
"Title": "Outputting Fractions"
} | 55786 |
<p>For full information read, the meta-post on it: <a href="https://codereview.meta.stackexchange.com/questions/2038/let-the-cr-games-begin">Let the CR Games begin!</a></p>
<h1>Rules:</h1>
<ul>
<li>The original code can be taken from <strong>any Stack Exchange site</strong>.</li>
<li>Your question must <strong>includ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T12:39:12.937",
"Id": "55787",
"Score": "0",
"Tags": null,
"Title": null
} | 55787 |
Rags-To-Riches is the tag of choice for entries to the corresponding CR-Game as proposed on meta. Questions tagged with this tag are polished Stack Exchange posts asking for a review. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T12:39:12.937",
"Id": "55788",
"Score": "0",
"Tags": null,
"Title": null
} | 55788 |
<p>I have implemented a producer consumer problem,
following the resources below:</p>
<ul>
<li><a href="http://docs.oracle.com/cd/E18752_01/html/816-5137/sync-11157.html" rel="nofollow noreferrer">Oracle doc</a></li>
<li><a href="http://www.csee.wvu.edu/~jdm/classes/cs550/notes/tech/mutex/pc-sem.html" rel="nofollow no... | [] | [
{
"body": "<h3>1. Bugs</h3>\n\n<ol>\n<li><p>It doesn't work! On OS X 10.9.4, with Clang/LLVM, when I run it, I get the output:</p>\n\n<pre class=\"lang-none prettyprint-override\"><code>Producer Thread Created\nConsumer Thread Created\n</code></pre>\n\n<p>... and then it hangs. Here's an LLDB session:</p>\n\n<p... | {
"AcceptedAnswerId": "56182",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T13:39:49.767",
"Id": "55792",
"Score": "5",
"Tags": [
"c",
"multithreading",
"pthreads"
],
"Title": "Consumer-Producer Problem: POSIX Thread"
} | 55792 |
<p><em>Follow-up posted here: <a href="https://codereview.stackexchange.com/questions/55801/refactor-this-method-to-a-cleaner-state-continued">Refactor this method to a cleaner state (continued)</a></em></p>
<p>I am refactoring a legacy application. I DO NOT have the ability to change the <code>Permissions</code>, <co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T14:30:06.250",
"Id": "97935",
"Score": "3",
"body": "What is up with the `IsNotNull` method call in there? Why not just `return (parent != null) ? ...` ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-0... | [
{
"body": "<p>I would put: </p>\n\n<pre><code>var ListItems = new List<ListItem>();\n//Yes this is silly since statusReturn is never used\nvar statusReturn = _Permissions.GetReportsForUserGroupName(userGroup, ref ListItems);\n</code></pre>\n\n<p>in a method that just returns the list. So you are isolati... | {
"AcceptedAnswerId": "55797",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T14:24:17.697",
"Id": "55795",
"Score": "7",
"Tags": [
"c#"
],
"Title": "Refactor a legacy application to a less-unwieldy state"
} | 55795 |
<p>This is continued from here:</p>
<p><a href="https://codereview.stackexchange.com/questions/55795/refactor-a-legacy-application-to-a-less-unwieldy-state">Refactor a legacy application to a less-unwieldy state</a></p>
<p>I am refactoring a legacy application. I DO NOT have the ability to change the <code>Permission... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T16:06:51.090",
"Id": "97960",
"Score": "0",
"body": "Can you comment it to explain what it's supposed to do now? It looks like you're transforming a list into a tree but it's not clear what the rules are. It's confusing that you k... | [
{
"body": "<p>you should move </p>\n\n<pre><code>child.Children.Add(grandChild);\n</code></pre>\n\n<p>outside of your if statements like so:</p>\n\n<pre><code> foreach (var item in gmcListItems)\n {\n var customerReport = (CustomerReport) item.dataObject;\n var grandChild = AssembleGrandChil... | {
"AcceptedAnswerId": "55954",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T15:39:41.533",
"Id": "55801",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Refactoring this legacy application to a cleaner state (continued)"
} | 55801 |
<p>I'm writing an utility audio plugin that specializes in "fullscreen" (the window is freely resizable) visualization of audio, like spectrograms, oscilloscopes and in this instance, a vectorscope. For those who doesn't know, a vectorscope is a coordinate system where each sample in an audiostream maps the coordinates... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T16:27:43.993",
"Id": "97970",
"Score": "1",
"body": "Why are you plotting pixels yourself instead of just specifying the line and letting the graphics card do it for you?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>Here are some suggestions: </p>\n\n<p><strong>Double Buffering</strong><br>\nDraw into one buffer (bitmap, etc) while the graphics processor is processing the other. When the graphics processor is finished, switch buffers. Use more buffers as necessary to accommodate speed differences. </p>\n\... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T15:41:18.723",
"Id": "55802",
"Score": "5",
"Tags": [
"c++",
"optimization",
"graphics"
],
"Title": "First time graphics - bad performance in software rendering"
} | 55802 |
<p>I have written a small container class which groups a 3D position, a normal vector and a texture coordinate into one object. It uses the <a href="http://glm.g-truc.net/0.9.4/index.html" rel="nofollow">glm</a> library for the actual data types (vec2 and vec3). This class is named <code>Vertex</code>. Here is the sour... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T16:13:03.997",
"Id": "97963",
"Score": "0",
"body": "You should also indent the entire contents of the namespaces."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T18:24:27.423",
"Id": "97991",
... | [
{
"body": "<ul>\n<li><p>Both <code>std::istream</code> and <code>std::ostream</code> are actually <em>not</em> defined in <code><iostream></code>, despite the fact that they look similar. They're respectively defined in <code><istream></code> and <code><ostream></code>.</p>\n\n<p>You should i... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T16:06:55.957",
"Id": "55803",
"Score": "5",
"Tags": [
"c++",
"beginner",
"c++11",
"io",
"serialization"
],
"Title": "Reading and writing binary data in C++"
} | 55803 |
<p>I have put together a naive implementation of a VB6/VBA parser, and I'd like to see if the CR community sees the same things as I see can be improved with this code, before I start refactoring.</p>
<p>I've never written a parser, so this naive implementation is naive in all senses: I wanted to push it as far as I c... | [] | [
{
"body": "<p>Couple of things I would do to the <code>AttributeParser</code> abstract factory:</p>\n\n<ol>\n<li><p>Bring the creation of the <code>Regex</code> out of the <code>Parse</code> method since it is the same each call.</p></li>\n<li><p>The <code>if..else</code> each with a <code>return</code> in it i... | {
"AcceptedAnswerId": "55833",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T16:28:31.290",
"Id": "55805",
"Score": "22",
"Tags": [
"c#",
"parsing",
"reinventing-the-wheel"
],
"Title": "Look 'ma, I can read code"
} | 55805 |
<p>I wanted to make a dynamic <code>select</code> statement from this year to 10 years. This gets the job done, but I feel like it's a little much.</p>
<pre><code> form_dropdown('year', array_combine(range(date('Y'), date('Y')+10), range(date('Y'), date('Y')+10)), set_value('year'));
</code></pre>
<p>Specifically, is... | [] | [
{
"body": "<p>In order to get the output that you wanted, using <code>array_combine</code> will most likely be your best bet. You can simplify your statements pretty easily because variables are you friends:</p>\n\n<pre><code>$current_year = date('Y');\n$date_range = range($current_year, $current_year+10);\n\nf... | {
"AcceptedAnswerId": "55807",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T16:34:44.183",
"Id": "55806",
"Score": "5",
"Tags": [
"php",
"array",
"datetime"
],
"Title": "Dynamic array of Years"
} | 55806 |
<p>I have a form that allows the user to select a server. This will execute the exact same query just on a different server.</p>
<pre><code>private void QueryButton_Click(object sender, EventArgs e)
{
switch (this.FindByComboBox.SelectedIndex)
{
case 0:
ByTargetVDN();
break;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T22:14:41.977",
"Id": "98032",
"Score": "1",
"body": "If you're running the same query, just on a different server, why are you filling separate datasets (In your working code)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<pre><code>if (this.ValueTextBox.Text.Length > 0)\n{\n value = Convert.ToInt32(this.ValueTextBox.Text);\n}\n</code></pre>\n\n<p>This will throw a <code>nullpointerexception</code> if <code>Text</code> is <code>null</code>, use <code>TryParse</code> instead</p>\n\n<pre><code>int value;\nbool res... | {
"AcceptedAnswerId": "55821",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T21:11:59.530",
"Id": "55819",
"Score": "2",
"Tags": [
"c#",
"beginner",
"winforms"
],
"Title": "Two Datasets Same Query"
} | 55819 |
<p>I am using this script to get the admin pages via this query string <code>?page=</code> once the admin is logged in.</p>
<p>Just needing a review, opinions</p>
<p><strong>Function:</strong></p>
<pre><code>// GET PAGE FROM QUERY STRING
public function page_select($page) {
$ext = '.php';
$file = 'pages/'.$p... | [] | [
{
"body": "<p>I can't say much on the functionality, but I got a small comment on your if-statements:</p>\n<h3>Be consistent:</h3>\n<p>In your "Function" you have the blocks clearly cut out (linebreak & indention), In your "index.php" they are inlined.</p>\n<p>I suggest you <strong>alway... | {
"AcceptedAnswerId": "55854",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T21:55:43.633",
"Id": "55822",
"Score": "1",
"Tags": [
"php"
],
"Title": "Admin page select function"
} | 55822 |
<p>I was searching for a pseudo-random number generator for C# and stumbled upon <a href="http://msdn.microsoft.com/en-us/magazine/cc163367.aspx" rel="nofollow noreferrer">Tales from the CryptoRandom</a> by Stephen Toub and Shawn Farkas, so I tried to implement a variation of their code.</p>
<p>The main difference wit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T07:45:41.283",
"Id": "98076",
"Score": "0",
"body": "A reason to have the class/methods be non-static is to support unit testing. If you have a class that is using the random numbers generated by this class and want to check that i... | [
{
"body": "<p>Your code is buggy in the range it pulls from the <code>Sample()</code> method. The easiest way to describe this bug is with the code: <code>public static int GetInt32(int minimum, int maximum)</code>. For example, if I run:</p>\n\n<pre><code>GetInt32(0, 1)\n</code></pre>\n\n<p>I would expect 0 ha... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T22:13:16.317",
"Id": "55824",
"Score": "4",
"Tags": [
"c#",
"random"
],
"Title": "Pseudo-random number generator implementation check"
} | 55824 |
<p>In QML, a user interface is specified as a tree of objects with properties. The language is part of Qt Quick and mainly aimed at creating mobile device interfaces.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T22:56:47.877",
"Id": "55826",
"Score": "0",
"Tags": null,
"Title": null
} | 55826 |
QML (Qt Meta-Object Language) is a declarative language designed to describe the user interface of a program. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T22:56:47.877",
"Id": "55827",
"Score": "0",
"Tags": null,
"Title": null
} | 55827 |
<p>Fixed point arithmetic uses a set number of decimal places to do calculations, instead of a variable amount (floating point). Instead of representing numbers using the IEEE mantissa-and-exponent format, numbers are represented as integers and bit shifted when necessary.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T22:59:04.443",
"Id": "55828",
"Score": "0",
"Tags": null,
"Title": null
} | 55828 |
Fixed point arithmetic is done using a set number of decimal places. It can be faster and is more precise than floating-point. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T22:59:04.443",
"Id": "55829",
"Score": "0",
"Tags": null,
"Title": null
} | 55829 |
<p>From <a href="http://en.wikipedia.org/wiki/Multiprocessing" rel="nofollow">Wikipedia</a>:</p>
<blockquote>
<p>Multiprocessing is the use of two or more central processing units
(CPUs) within a single computer system. The term also refers to the
ability of a system to support more than one processor and/or the... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T23:02:15.857",
"Id": "55830",
"Score": "0",
"Tags": null,
"Title": null
} | 55830 |
Multiprocessing is the use of two or more central processing units (CPUs) within a single computer system. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T23:02:15.857",
"Id": "55831",
"Score": "0",
"Tags": null,
"Title": null
} | 55831 |
<p>This is my second linked list implementation for review. I rewritten pretty much all of <a href="https://codereview.stackexchange.com/questions/55655/linked-list-implementation-correctness">this</a> and have added iterators, sentinels and The Rule of Five.</p>
<p>Please let me know what's wrong with it; I am still... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T03:24:45.183",
"Id": "98062",
"Score": "0",
"body": "I would recommend using (e.g.) `this->size` instead of just `size`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T03:56:29.257",
"Id": "98065"... | [
{
"body": "<ul>\n<li><code>operator!=</code> <strong>must</strong> be defined as a negation of <code>operator==</code>.</li>\n<li>A (non-random-access) forward iterator shall not define an <code>operator+</code>. <code>std::advance</code> does the job.</li>\n<li>I don't think that <code>operator++</code> can be... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T23:56:01.123",
"Id": "55834",
"Score": "9",
"Tags": [
"c++",
"beginner",
"c++11",
"linked-list",
"iterator"
],
"Title": "Linked list with iterators"
} | 55834 |
<p>I wrote this little JavaScript function that starts with the number 1 and continually either adds 5 or multiplies by 3. This function tries to find a sequence of additions and multiplications that find that number. </p>
<p>Keep in mind, this function does not necessarily find the shortest sequence of operations.</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T08:57:03.017",
"Id": "98081",
"Score": "0",
"body": "Your code contains an invalid test and your test contains an exact copy of your code. Is this intended/your real code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creatio... | [
{
"body": "<p>This question is a bit related to <a href=\"https://codereview.stackexchange.com/questions/49418/determining-if-an-answer-can-be-generated/49441\">a previous question</a>. I will give you the same advice I did to the asker of the previous question.</p>\n<h3>Work from the other direction.</h3>\n<p>... | {
"AcceptedAnswerId": "55868",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T00:53:24.413",
"Id": "55838",
"Score": "10",
"Tags": [
"javascript"
],
"Title": "Find sequence by adding 5 or multiplying by 3"
} | 55838 |
<p>I'm attempting this <a href="https://www.hackerrank.com/challenges/building-a-list" rel="nofollow">code challenge</a>.</p>
<p>Here's my code modified to handle one simple example test case:</p>
<pre><code>string = "bcdefghij"
l = string.size
result = []
permutations = string.split('').permutation.to_a
l.times d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T20:41:06.833",
"Id": "98295",
"Score": "3",
"body": "A 2200x speedup... not bad :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T23:35:24.307",
"Id": "98337",
"Score": "0",
"body": "Plea... | [
{
"body": "<p>It's inefficient because you're doing a lot of work to create a factorial <code>l</code>, iterating over it l times, each time REDOING all the work of sorting and joining each permutation, and then throwing away most of the results!</p>\n\n<p>Here are some suggestions:</p>\n\n<ul>\n<li>You don't n... | {
"AcceptedAnswerId": "55858",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T01:32:37.463",
"Id": "55839",
"Score": "3",
"Tags": [
"performance",
"ruby",
"programming-challenge"
],
"Title": "Building a list - why is this code inefficient?"
} | 55839 |
<p>I have created this regular expression to validate usernames which I need in my projects:</p>
<pre class="lang-none prettyprint-override"><code>^(?=.{3,32}$)(?!.*[._-]{2})(?!.*[0-9]{5,})[a-z](?:[\w]*|[a-z\d\.]*|[a-z\d-]*)[a-z0-9]$
</code></pre>
<p>It works just fine. But I'm wondering if there is any improvement a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T02:32:13.337",
"Id": "98057",
"Score": "5",
"body": "Do you *have* to solve this problem with a regex only? Although it might be possible to solve this with a regex, it seems like a lot of work and the result is pretty much unreadab... | [
{
"body": "<p>I would very strongly recommend against using a regular expression for this. There is no clear mapping between the list of requirements you posted and the code.</p>\n\n<p>Imagine another developer looking at this. Are they able to deduce the list of requirements? Given the list of requirements, ar... | {
"AcceptedAnswerId": "55842",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T02:21:42.197",
"Id": "55841",
"Score": "8",
"Tags": [
"c#",
"optimization",
"regex"
],
"Title": "Optimizing and improving a username regex"
} | 55841 |
<p>Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree. </p>
<blockquote>
<p>Given tree: </p>
<pre><code> a
/ \
b c
/ \ / \
d e f g
/ \ / \ / \ / \
h i j k l m n o
</code></pre>
<p>Modified tree:</p>
<pre><code> ... | [] | [
{
"body": "<h2>Documentation</h2>\n\n<p>The first thing that comes to my mind is your doc sentences like this one:</p>\n\n<blockquote>\n <p>Constructs a binary tree in order of elements in an array.</p>\n</blockquote>\n\n<p>Rather than <em>an array</em>, I'd be more specific and use <em>the specified array</em... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T06:39:43.060",
"Id": "55850",
"Score": "8",
"Tags": [
"java",
"algorithm",
"tree"
],
"Title": "Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree"
} | 55850 |
<p>I have some code that reads an email from a text file, parses the text, removes some lines (the 'cc' and 'to' lines) and then finds the line numbers of various phrases (e.g. "Regards", "Thanks") and then removes all the text for the lines after the first phrase found.</p>
<p>It works fine, but is not generic enough... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T12:53:29.580",
"Id": "98116",
"Score": "0",
"body": "Can you please post an example input/output to clarify the problem? Should everything after the first \"regards\" (or \"thanks\", etc) be cut off?"
}
] | [
{
"body": "<p>First of all, you have one too many parentheses and are missing some variable declarations, so let's fix that up.</p>\n\n<pre><code>var emailText = \"\";\nforeach (List<string> list in groups)\n{\n IEnumerable<string> lines3 = list.Where(line => !line.StartsWith(\"Cc:\", StringCo... | {
"AcceptedAnswerId": "55944",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T06:58:59.233",
"Id": "55852",
"Score": "1",
"Tags": [
"c#",
"parsing",
"linq",
"email"
],
"Title": "Making an email text-parser generic using PredicateBuilder"
} | 55852 |
<p>I am wondering what the best way to update multiple records with Entity Framework is.
This is how I normally do it, and it does work:</p>
<pre><code> private static void SetNcprpCodesAsComplete(string[] ncprpCodes)
{
using (var ent = new Data.Entities())
{
var query = from ba in e... | [] | [
{
"body": "<p>This is the usual way how to update properties in EF, and in your case, I'd say it seems the only proper way. You can surely attach and update - but then you'll loose all other properties in your entity. To sum up - if you'd need to update one property in entities, you'll need to do SELECT (your q... | {
"AcceptedAnswerId": "55865",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T09:20:13.683",
"Id": "55861",
"Score": "9",
"Tags": [
"c#",
".net",
"entity-framework"
],
"Title": "Update multiple records with Entity Framwork"
} | 55861 |
<p>I'm fine with <strong>any</strong> sort of answer that helps better my code -- I'm not necessarily looking for a full refactor. I have a script that converts input (IPv4 address, submask, cidr, etc.) into usable information to subnet networks.</p>
<p>If you need any more info <a href="https://github.com/EricLagerg... | [] | [
{
"body": "<p>A few notes until someone who knows JavaScript comes along...</p>\n\n<ul>\n<li><code>function val()</code> is a pretty bad name for a function. Functions should always have a descriptive name in a verb-noun form. </li>\n<li><code>// Just declaring some variables.</code> is a useless comment. Comme... | {
"AcceptedAnswerId": "55869",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T09:22:01.620",
"Id": "55862",
"Score": "4",
"Tags": [
"javascript",
"optimization"
],
"Title": "Subnetting calculator"
} | 55862 |
<p>I'm developing a Windows Service that receives data from somewhere and saves it to DB one time per 5 minutes. The Service is multithreaded and I actually got problems when several threads saved data at same minute (no thread sync was implemented).</p>
<p>Now I've implemented it and am looking for code-review and op... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-04T16:16:22.513",
"Id": "98728",
"Score": "0",
"body": "How exactly are you running `TimerTick`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T09:44:00.037",
"Id": "99118",
"Score": "0",
"b... | [
{
"body": "<p>In your code, the only way to have two threads update that value simultaneously is if <code>TimeTick</code> gets invoked twice in a very short amount of time. Given a sane value for your time interval, this can't happen. And if it can, you would typically use a <code>Monitor</code> and quickly e... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T09:23:33.413",
"Id": "55863",
"Score": "3",
"Tags": [
"c#",
"multithreading",
"datetime",
"windows"
],
"Title": "Usage of Interlocked.CompareExchange for deciding whether a pr... | 55863 |
<p>I have to store various <a href="http://www.w3.org/TR/html5/syntax.html#named-character-references" rel="nofollow">HTML named character references</a> for the following purposes:</p>
<ol>
<li><p>Escaping special characters <code>myStringBuilder.Replace("À", WebHelper.Agrave)</code></p></li>
<li><p>Insert spaces in ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-04T16:13:07.230",
"Id": "98726",
"Score": "1",
"body": "Calling ` ` just “space” is confusing. It's not the normal space, it's a [non-breaking space](https://en.wikipedia.org/wiki/Non-breaking_space)."
}
] | [
{
"body": "<p>Why not just use the <a href=\"http://msdn.microsoft.com/en-us/library/ms525347%28v=vs.90%29.aspx\" rel=\"nofollow\">Server.HtmlEncode</a> function? </p>\n\n<p>Here is a brief description of what it does:</p>\n\n<blockquote>\n <p>Any ASCII code character whose code is greater-than or equal to 0x... | {
"AcceptedAnswerId": "55937",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T10:01:44.450",
"Id": "55864",
"Score": "2",
"Tags": [
"c#",
"html",
".net"
],
"Title": "Avoid redundancy of HTML entities in .NET framework"
} | 55864 |
<p>I am trying to solve <a href="http://www.codechef.com/problems/MSTICK/" rel="nofollow">this problem</a></p>
<blockquote>
<p>Chef Ceil has some matchsticks in his kitchen. </p>
<p><strong>Detail of matchsticks:</strong></p>
<p>There are N matchsticks in total. They are numbered from to 0 to N-1
inclusi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-03T09:33:39.563",
"Id": "98418",
"Score": "0",
"body": "Have you tried profiling your code? Could you post the results of a profiling?"
}
] | [
{
"body": "<p>There are some optimizations that may help</p>\n\n<ol>\n<li><p>You are passing input vector by assignment (as <code>tl A</code>) to <code>query()</code> and <code>build_segment_tree()</code>. By doing this you are essentially copying the whole vector (of size \\$O(10^5)\\$ in worst case) in each r... | {
"AcceptedAnswerId": "55960",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T10:57:16.253",
"Id": "55866",
"Score": "6",
"Tags": [
"c++",
"c++11",
"programming-challenge",
"time-limit-exceeded"
],
"Title": "Time Limit Exceeded with Segment Tree data... | 55866 |
<p>This is just a little hobby project I've been working on. I've been using it to learn/improve my knowledge of C++. </p>
<p>The program generate Norwegian personal-numbers (11 digits) for males born a given year. It works just fine, but I'd like some input on how to improve the code. For now I have a basic class str... | [] | [
{
"body": "<h3>Comment on C++ interface:</h3>\n\n<p>You are doing work outside of ID that belongs as part of the class:</p>\n\n<pre><code>ID generator;\n\nfor(int i = 0; i < DATE_LENGTH; i++){\n *(generator.getDate() + i) = int(dateString[i]-'0');\n}\n\ngenerator.setYear(1900 + (*(generator.getDate() + 4)... | {
"AcceptedAnswerId": "55876",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T12:03:32.860",
"Id": "55870",
"Score": "3",
"Tags": [
"c++",
"classes",
"datetime"
],
"Title": "Generate the Norwegian equivalent to social security numbers"
} | 55870 |
<p>Coming from a Java background, this is my first JavaScript-only game. I'm looking for some advice on what to improve.</p>
<p>Also, I'm having trouble when it comes to program design. Sometimes I don't know if I should write class-like code or just plain functions. How does one go about deciding on this?</p>
<p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T12:28:11.677",
"Id": "98112",
"Score": "0",
"body": "Welcome to Code Review! This is a nice first question."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T15:54:28.307",
"Id": "98167",
"Score... | [
{
"body": "<p>Nice job. I have only a few minor improvements to offer, mostly because I also came from the Java/C++/C# world and wrote a game to learn JavaScript, and I know what I did wrong.</p>\n\n<blockquote>\n <p>Sometimes I don't know if I should write class-like code or just plain functions. How does on... | {
"AcceptedAnswerId": "56396",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T12:19:05.087",
"Id": "55873",
"Score": "7",
"Tags": [
"javascript",
"game",
"design-patterns",
"snake-game"
],
"Title": "Basic snake game"
} | 55873 |
<p>I want to build the markup below by iterating on an array of objects. The structure of the object is also listed below. I need some tips on how to make it clean.</p>
<p>Markup I want to build: </p>
<pre><code><!--the markup I want to build-->
<div class="pull-left col-xs-4">
<div class="thu... | [] | [
{
"body": "<p>There are several problems in your code:</p>\n\n<hr>\n\n<p>What is <code>r.price</code>?</p>\n\n<hr>\n\n<p><code>h5[\"innerHTML\" || \"textContent\"] = obj.name</code> makes no sense. You could just a well write <code>h5[\"innerHTML\"] = obj.name</code>. Your code won't test if such properties exi... | {
"AcceptedAnswerId": "55882",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T12:41:15.853",
"Id": "55874",
"Score": "3",
"Tags": [
"javascript",
"design-patterns",
"html",
"dom"
],
"Title": "DOM building using DocumentFragment"
} | 55874 |
<p>I would like to get some feedback from the community regarding a plugin I recently moved from requiring jQuery to a stand alone JS implementation. It is meant to handle browser communication protocols such as XHR, XDR, WS & WSS without a lot of fuss.</p>
<p>The project can also be found @ <a href="https://githu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-03T14:57:50.070",
"Id": "98488",
"Score": "0",
"body": "I have applied the suggestions, removed some unnecessary functionality while adding some needed functionality which can be seen on the project page @ https://github.com/jas-/comm.... | [
{
"body": "<p>Interesting question,</p>\n\n<p>2 upfront general notes first:</p>\n\n<ul>\n<li>Run your code through JsHint.com, there are a ton of little things you could fix</li>\n<li>Run your code through a beautifier, there are a ton of inconsistencies</li>\n</ul>\n\n<p>Also, consider the following</p>\n\n<u... | {
"AcceptedAnswerId": "55910",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T14:01:30.273",
"Id": "55881",
"Score": "4",
"Tags": [
"javascript",
"ajax",
"plugin",
"websocket"
],
"Title": "Plugin for communication protocols in browser(s)"
} | 55881 |
<p>I'm new to C++ (about 4 weeks with no prior programming experience in other languages) and am writing a program that's <em>supposed</em> to do the following:</p>
<ul>
<li>Define an array of 100 sequential numbers of type <code>float</code>.</li>
<li>Define an array of 20 Fibonacci numbers of type <code>int</code>.<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T15:42:01.543",
"Id": "98163",
"Score": "10",
"body": "Welcome to CodeReview! This is a good question, thank you for taking the time to form it so that we can help show you the proper coding styles and techniques. We all look forwa... | [
{
"body": "<p>Your code is generally correct, but your calculation of the standard deviation is inefficient.</p>\n\n<pre><code>for (int i = 0; i < SIZE_OF_GENERIC_ARRAY; i++)\n{\n tempSum += pow((Array[i] - mean(Array, SIZE_OF_GENERIC_ARRAY)), 2);\n}\n</code></pre>\n\n<p>This will call the <code>mean</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T14:19:36.757",
"Id": "55883",
"Score": "32",
"Tags": [
"c++",
"beginner",
"fibonacci-sequence",
"statistics",
"overloading"
],
"Title": "Standardly deviated Fibonacci"
} | 55883 |
<p>The following code should solve these issues:</p>
<ol>
<li>Handle namespaces;</li>
<li>Be a class factory from Pojos</li>
<li>Be a object factory</li>
<li>Create a class with inheritance capabilities from a POJO using <a href="http://ejohn.org/blog/simple-javascript-inheritance/" rel="nofollow">john resig inherita... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T14:36:33.473",
"Id": "55887",
"Score": "2",
"Tags": [
"javascript",
"node.js",
"inheritance",
"namespaces"
],
"Title": "Namespace handling and inheritance managing with Node.j... | 55887 |
<p>I have a server that cannot be connected to from the internet, but I need to get some info to it. I have another server that can, so I have a simple passthru script that I want to see if you all think is secure.</p>
<p>Basically, you hit <a href="http://example.com/domain=subdomain1&url=it/myscript.php" rel="no... | [] | [
{
"body": "<p>Your code looks nice, but it could be improved upon:</p>\n\n<ol>\n<li><p><code>$domain != '' ? '.' : ''</code>; With ternaries in PHP, if you don't need one of two results, you can reverse the if condition and use <code>?:</code>.</p>\n\n<pre><code>$domain == '' ?: '.'\n</code></pre></li>\n<li><p>... | {
"AcceptedAnswerId": "95629",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T14:44:55.490",
"Id": "55889",
"Score": "1",
"Tags": [
"php",
"http",
"curl"
],
"Title": "DMZ passthru script"
} | 55889 |
<p>I'm trying to calculate what time a certain time in a time zone is today, so I can schedule something to happen at that time in that time zone. </p>
<p>I've got a table with what I have termed the Nominal Time, which is stored as a <code>datetimeoffset</code> with an arbitrary date, as the only parts I care about i... | [] | [
{
"body": "<h1><strong>Formatting</strong></h1>\n\n<p>First off, I reformatted your code to make it easier to read. When writing SQL it is best to be consistent with capitalization, and using indenting makes it much easier to read. So here is your code in my (personally preferred) format, including SQL keywords... | {
"AcceptedAnswerId": "55917",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T15:25:13.190",
"Id": "55892",
"Score": "6",
"Tags": [
"sql",
"datetime",
"sql-server",
"t-sql"
],
"Title": "Calculating a time in a time zone from multiple dates in SQL"
} | 55892 |
<p>I am trying to generate a dataset from a query that has a <code>where</code> statement. If the user passes a value additional things need to be added to the <code>where</code> statement. Is this the best way to go about this?</p>
<pre><code>class TableAdapters
{
public class FindScriptByTargetVDN
{
... | [] | [
{
"body": "<p>Seems like a reasonable approach. It's similar to one that I've used when building a query completely from an XML file, except I used parameters rather than adding in the string.</p>\n\n<pre><code>selectString = string.Format(\"{0} WHERE {1}='{2}' {3};\",\n selectString,\n ... | {
"AcceptedAnswerId": "55915",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T15:29:25.860",
"Id": "55893",
"Score": "8",
"Tags": [
"c#",
"beginner",
".net",
"winforms",
".net-datatable"
],
"Title": "Dataset with optional addition to where statem... | 55893 |
<p>I maintain a VBA process that prints a large number of PDFs. It was <em>awful</em> when I inherited it and I've been making improvements over time, but I'm a bit stuck on this one. There are at least 4 functions with this exact same code used to check to see if the program has been initialized properly. They could a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T15:45:44.437",
"Id": "98164",
"Score": "0",
"body": "Is the main code in a class module?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T15:46:43.663",
"Id": "98165",
"Score": "0",
"body":... | [
{
"body": "<p>your Main code is split into two functions right now, which only differ in the logic inside the nested if statement, you should do the if statement and initializing outside the function and just </p>\n\n<pre><code>If Not isInit Then\n initialize\nEnd If\nIf rootDir <> \"\" And mCycle <... | {
"AcceptedAnswerId": "55898",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T15:38:32.650",
"Id": "55896",
"Score": "6",
"Tags": [
"design-patterns",
"vba"
],
"Title": "DRYing up an initialization pattern"
} | 55896 |
<p>During breaks, I find myself playing Emerald version a lot and was tired of having to use the school's slow wifi to access the internet. I wrote a scraper to obtain cheat codes and send them to my psp device. I couldn't come up with a better way of removing the extra whitespace. Any areas I could improve on?</p>
<p... | [] | [
{
"body": "<p>I presume you are mostly after getting rid of <code>egrep</code>, so <code>sed</code> command to remove empty lines:</p>\n\n<pre><code>'/^[[:space:]]*$/d'\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T19:55:12.753",
... | {
"AcceptedAnswerId": "55925",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T15:57:41.933",
"Id": "55897",
"Score": "3",
"Tags": [
"regex",
"bash",
"web-scraping"
],
"Title": "Cheat Code Scraper"
} | 55897 |
<p>I'm a C++ programmer learning Java in preparation for an OOP class this fall. That being said, Java is fairly new to me so I'd love to hear feedback on how to improve this code.</p>
<p>A few notes:</p>
<ul>
<li>Code works as expected and is ported from my C++ equivalent code I wrote some time ago.</li>
<li>Not all... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T20:22:38.343",
"Id": "98286",
"Score": "0",
"body": "You say this is a doubly linked *circular* list, but none of your behaviors take advantage of the fact that it's circular. What you're doing here could be achieved just as well w... | [
{
"body": "<h2>Java style convention</h2>\n<p>One of the first thing you should do when working in a new language is to look at style convention. You used C++ convention and not the Java one. Class name should be PascalCase and method name should be camelCase. Unless it's a constant, you should not use <code>_<... | {
"AcceptedAnswerId": "55904",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T16:03:21.710",
"Id": "55899",
"Score": "11",
"Tags": [
"java",
"linked-list",
"circular-list"
],
"Title": "Doubly-Linked Circular Linked List"
} | 55899 |
<p>I have a Python script that creates a diff of two images using PIL. That part works fine. Now I need to find an efficient way to count all the non-black pixels (which represent parts of the two images that are different). The diff image is in RGB mode.</p>
<p>My initial cut was something like this:</p>
<pre><code>... | [] | [
{
"body": "<p>Here's your implementation using <a href=\"http://pillow.readthedocs.org/en/latest/\" rel=\"noreferrer\">Pillow</a>:</p>\n\n<pre><code>def count_nonblack_pil(img):\n \"\"\"Return the number of pixels in img that are not black.\n img must be a PIL.Image object in mode RGB.\n\n \"\"\"\n ... | {
"AcceptedAnswerId": "56101",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T16:13:36.747",
"Id": "55902",
"Score": "10",
"Tags": [
"python",
"image"
],
"Title": "Fastest way to count non-zero pixels using Python and Pillow"
} | 55902 |
<p>My first ASP.NET MVC 6 / jQuery web site - the site header has a "Change Language" selector (named <code>LanguagePicker</code>) - this is actually placed in a _Layout view, a container shared by all views. </p>
<p>When users change the language, I need to save that in the db, and reload current page, with language ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T17:51:27.670",
"Id": "98195",
"Score": "0",
"body": "Have you considered simply using [an html form](http://www.w3schools.com/html/html_forms.asp) without jquery?"
}
] | [
{
"body": "<p>To get the current page you could use this (as long as the javascript is in your layout file or other view, this will not work if in an external js file):</p>\n\n<p><code><%= Request.Url.PathAndQuery %></code> </p>\n\n<p>I would suggest using ajax to call an api that returns json with a succ... | {
"AcceptedAnswerId": "55930",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T16:30:37.860",
"Id": "55903",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"asp.net-mvc"
],
"Title": "Send parameter to server and reload page"
} | 55903 |
<p>I'm building an in house query tool. The main form has a drop down which allows the user to select how they want to find scripts, and a drop down for what server they want to run the query on. There is also a text box to allow the user to populate a specific value which can be left blank. I think I did pretty well... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T20:02:13.447",
"Id": "98272",
"Score": "1",
"body": "I always cringe a little bit when I see raw SQL being concatenated. Your code becomes ripe for SQL injection attacks."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<ul>\n<li>I assume it's your style to refer to class members using \"<code>this.</code>\". That's not the usual way to do things but it is acceptable.</li>\n<li>It also seems to be your style to capitalize the names of the UI elements. Again, not the usual style but not horrible (it does confuse the ... | {
"AcceptedAnswerId": "55931",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T17:09:33.353",
"Id": "55906",
"Score": "4",
"Tags": [
"c#",
".net",
"winforms",
".net-datatable"
],
"Title": "Populating DataGrids"
} | 55906 |
<p>I have these two methods which are generating two different xml files whose header section is same and detail section varies. The root node is different for both xml files. Here I have two methods written, one for each. I want to optimize the code by avoiding the duplication of code in these two methods. Can you ple... | [] | [
{
"body": "<p>You need to look at what's common to both methods:</p>\n\n<pre><code>StringBuilder builder = new StringBuilder();\nusing (StringWriter stringWriter = new StringWriter(builder))\n{\n using (XmlWriter writer = XmlWriter.Create(stringWriter))\n {\n writer.WriteStartDocument();\n w... | {
"AcceptedAnswerId": "55912",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T17:26:04.890",
"Id": "55908",
"Score": "5",
"Tags": [
"c#",
"xml"
],
"Title": "How to avoid duplication in my document writer?"
} | 55908 |
<p>After reading the same <a href="https://stackoverflow.com/questions/24528168/">question</a> on SO about how to bold a word in a label for the nth time today, I decided to write a formatted Label. </p>
<p>At first I toyed with the idea of writing a MarkDown clone (again), but I really wanted a rather lightweight Lab... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T20:06:52.690",
"Id": "98276",
"Score": "0",
"body": "@Simon: May I ask if is is ok to change/improve the code according to the suggestions? I wouldn't want to mess up anybody's efforts but I want to make progress.. Is there a recomm... | [
{
"body": "<p><strong>Code Improvements</strong> </p>\n\n<p>I personally feel the paint function is a little long, it would be nice to break it into some sub functions. One could initialize the properties, one to draw the parts that calls sub functions to draw each type of part separately, and final one to adj... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T18:39:13.323",
"Id": "55916",
"Score": "13",
"Tags": [
"c#",
"formatting"
],
"Title": "Lightweight rich link Label"
} | 55916 |
<p>I have a code similar to this:</p>
<pre><code>public class PlayerRound {
private final List<Strip> playerStrips = new ArrayList<>();
public boolean addStrip(final Strip aStrip) {
// ...
if (playerStrips.contains(aStrip)) {
playerStrips.set(playerStrips.indexOf(aStrip... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T19:28:52.017",
"Id": "98247",
"Score": "0",
"body": "It'll throw an exception if doesn't contain `aStrip` which might interrupt your program flow"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T19:32:... | [
{
"body": "<p>No, that code is totally useless. <strong>Unless....</strong></p>\n\n<hr>\n\n<h3>Same element twice</h3>\n\n<p>As it is a List, what happens if it contains the element twice?</p>\n\n<p>Let's say we have a List containing two elements of the type <code>Strip</code>:</p>\n\n<pre><code>stripA, stripB... | {
"AcceptedAnswerId": "55924",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T19:17:15.077",
"Id": "55920",
"Score": "3",
"Tags": [
"java"
],
"Title": "Does setting the same element in a list does something at all?"
} | 55920 |
<p>I posted my first attempt at this <a href="https://codereview.stackexchange.com/questions/55185/javascript-ebay-listing-generator/55576?noredirect=1#comment98071_55576">here</a>. It's an app that generates both a preview of an interactive eBay listing, as well as the raw code which the user can copy and paste into t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T19:53:56.880",
"Id": "98263",
"Score": "0",
"body": "It looks already a million times better, way to go!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-03T01:44:17.717",
"Id": "98352",
"Score": ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T19:39:58.877",
"Id": "55926",
"Score": "2",
"Tags": [
"javascript",
"html",
"ajax",
"ebay"
],
"Title": "eBay listing generator - revised"
} | 55926 |
<p>I'm solving the coin change problem having target of <em>n</em> and upper bound as <em>n</em>.</p>
<p>Also the maximum number of coins is 10.</p>
<p>For example. if the target is 11. then the possible outcomes are -</p>
<blockquote>
<pre><code>11
10,1
9,2
9,1,1
....
....
....
2,1,1,1,1,1,1,1,1,1
</code></pre>
</b... | [] | [
{
"body": "<p>I'm really struggling to read your code, but I'm trying to take a crack at it. In the mean time, here are some things about your code in general – not about the algorithm you use.</p>\n\n<p><strong>Static fields.</strong> You do not want to use static fields for <code>bl</code>, <code>ex</code> et... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T19:45:09.290",
"Id": "55927",
"Score": "2",
"Tags": [
"java",
"optimization",
"algorithm",
"recursion"
],
"Title": "Solving the coin change algorithm using 10 coins"
} | 55927 |
<p>I think I got the implementation right, but I'm a bit unsure if this implementation will do fine in terms of space (stack) because I'm doing a <code>foldRight</code>. Would I want to use <code>foldLeft</code> if e.g. I wanted to execute <code>flatMap</code> on a large list? Also, any other suggestion for improvement... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T19:46:05.900",
"Id": "55928",
"Score": "1",
"Tags": [
"beginner",
"scala"
],
"Title": "Elementary foldMap implementation"
} | 55928 |
<p>As a sample of dialects and teaching myself <code>parse</code> with <code>block!</code> values, I wrote the following dice dialect with the following grammar:</p>
<pre><code>[
word!
|
integer! word!
]
</code></pre>
<p>Where the word!s are defined as integers (<code>d10: 10</code>) so an expression of th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T20:50:36.353",
"Id": "98298",
"Score": "2",
"body": "Welcome to Code Review! Even though I understand squat of your code (as I don't speak rebol), it seems like you understand what this site is about. Welcome!"
}
] | [
{
"body": "<p>To first answer your question about the die/1, you are using COPY to get a range of multiple values out of the source block. You probably want SET to get a single value:</p>\n\n<pre><code>>> parse [d12] [copy die word! (probe die)]\n[d12]\n== true\n\n>> parse [d12] [set die word! (pro... | {
"AcceptedAnswerId": "55938",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T20:22:48.030",
"Id": "55929",
"Score": "8",
"Tags": [
"parsing",
"rebol",
"dice"
],
"Title": "Dice Calculation Dialect"
} | 55929 |
Relative Expression Based Object Language, or REBOL, is cross-platform and is based on symbolic processing and denotational semantics. It's powered by relative expressions called dialects. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T21:05:07.967",
"Id": "55933",
"Score": "0",
"Tags": null,
"Title": null
} | 55933 |
<p>I am writing a copy paste detector using <a href="http://esprima.org/">esprima.js</a> and <a href="https://gist.github.com/konijn/2d2737b0f86792e27b32">Hmm</a>.</p>
<p>This particular function checks a number of sequences and reduces them.
Due to the parsing I might have 2 sequences with the same piece of text, if ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T21:19:34.200",
"Id": "98306",
"Score": "1",
"body": "Please describe the desired algorithm in more detail and show before/after examples."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T21:28:19.307",... | [
{
"body": "<p>It looks like you could use <code>reduce</code> to your advantage, and extracting a function to merge two sequences. (Edit: messed up 1st version; this should be better)</p>\n\n<pre><code>Tokens.prototype.reduceSequences = function () {\n // source and destination seem like slightly better names\... | {
"AcceptedAnswerId": "57427",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T21:05:14.890",
"Id": "55934",
"Score": "8",
"Tags": [
"javascript",
"parsing"
],
"Title": "Reduce duplicate sequences"
} | 55934 |
<p>Given a linked list of 0s, 1s and 2s, sort it. Looking for code review, optimizations and best practices</p>
<pre><code>public final class SortZeroesOnesTwos {
private Node first;
private Node last;
private int size;
public SortZeroesOnesTwos(List<Integer> items) {
for (Integer item ... | [] | [
{
"body": "<p>The mash-up you continue to have with Objects and primitives is something that is easy to resolve, yet you don't. Is there some reason I am missing why it is important to convert your data to an Integer Object before converting it back to an int?</p>\n\n<blockquote>\n<pre><code>public void add(Int... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T21:16:03.493",
"Id": "55936",
"Score": "2",
"Tags": [
"java",
"linked-list"
],
"Title": "Sort a linkedlist with 3 elements 0, 1 and 2"
} | 55936 |
<p>I have implemented a CSV reader. I think I did pretty well. Since CSV is a loosely defined format to begin with I decided to allow some malformations, like anything but a delimiter after an enclosed value.</p>
<p>Maybe someone could point out improvements to this class, I would be happy to know them.</p>
<pre><cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T22:14:57.287",
"Id": "98315",
"Score": "0",
"body": "Can I ask why you didn't just import microsoft.visualbasic.fileio and use the native textfieldparser class?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "20... | [
{
"body": "<p>First of all, GOTOs are evil. You should never touch them, as Dijkstra said, <a href=\"http://en.wikipedia.org/wiki/Considered_harmful\">go To Statement Considered Harmful</a>. </p>\n\n<p>Dont forget to dispose your <code>StreamReader</code>, you can implement <code>IDisposable</code> to dispose i... | {
"AcceptedAnswerId": null,
"CommentCount": "17",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-02T21:53:57.667",
"Id": "55939",
"Score": "2",
"Tags": [
"c#",
"parsing",
"csv"
],
"Title": "CSV reader and parser"
} | 55939 |
<p>I'm new to Ruby, but not to programming. I just need a simple script that, given a text file, will pull out around 10% of the lines at random. Below is what I came up with based upon a Python script I wrote. What do I need to do differently to make it more Ruby-like?</p>
<pre><code>prng = Random.new
File.open('... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T20:59:35.033",
"Id": "101767",
"Score": "0",
"body": "\"...pull out around 10% of the lines at random\" will not do. You must define precisely what that means. You could say, for example, 8%-12% of the lines, but that still doesn'... | [
{
"body": "<p>Here's my shot at it:</p>\n\n<pre><code>File.open('english-words-partial.txt', 'w') do |file|\n File.foreach('english-words-full.txt') do |line|\n file.puts(line) if rand(10) == 0\n end\nend\n</code></pre>\n\n<p>In Ruby, you can add an if statement to the end of a line, to conditional... | {
"AcceptedAnswerId": "55957",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-03T01:47:54.377",
"Id": "55946",
"Score": "6",
"Tags": [
"beginner",
"ruby",
"random",
"file"
],
"Title": "Generate random 10% of file to be used in testing with Ruby"
} | 55946 |
<p>The point of the script below is to read in the 10th column which is the total number of minutes a runner took to finish the marathon and convert it into form of "hours:minutes:seconds". Is there a better way?</p>
<pre><code>require 'csv'
File.open('bostonmarathon-2012-results.txt', 'w') { |f|
skip = true
C... | [] | [
{
"body": "<p>I'm really not a ruby programmer, but using a boolean <code>skip</code> to skip the header seems really a weird way to me. That solution add an <code>if</code> to your that will only be needed once a variable use only once too. </p>\n\n<p>I'm sure there is a way to skip header of the file without ... | {
"AcceptedAnswerId": "55971",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-03T01:53:34.113",
"Id": "55948",
"Score": "9",
"Tags": [
"beginner",
"ruby",
"datetime",
"converting",
"csv"
],
"Title": "Convert total minutes into \"Hours:minute:seconds... | 55948 |
<p>This is a very simple <code>for</code> loop, but I find it very, complex-looking. I hope you can give me some insight on how it may be improved.</p>
<pre><code>int Tindex = 0;
int16_t Test[960];
int TestSize = SampleSize / 2; //Test is 16Bit, Half size of 32bit
int TestChannels = 2; //Stereo
float copy = 0; //Used... | [] | [
{
"body": "<p>Does this code actually work? I haven't figured out what it's supposed to do yet, so I can't be sure.</p>\n\n<p>This looks wrong to me:</p>\n\n<pre><code>bool left = true; //Only use Left Channel\nbool MixMono = true; //MixMono has priority over left\nif (MixMono || left) //Change the approprite ... | {
"AcceptedAnswerId": "55997",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-03T02:04:32.557",
"Id": "55949",
"Score": "4",
"Tags": [
"c++",
"audio"
],
"Title": "For-loop for mixing audio (left channel, stereo to mono)"
} | 55949 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.