body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<blockquote>
<p>Rewrite appropiate programs from earlier chapters and exercises with pointers instead of array indexing. Good posibilities include <code>getline</code>(Chapter 1 and 4), <code>atoi</code>, <code>itoa</code>, and their variants(Chapters 2, 3, and 4), <code>reverse</code>(Chapter 3), and <code>strindex<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T14:48:58.150",
"Id": "70198",
"Score": "0",
"body": "I think that this is the most relevant function that needs pr, the other ones are quite simple. If you want to see them: https://drive.google.com/folderview?id=0BwF4dzZ2k9NRVnl0ZU... | [
{
"body": "<p>The standard version of itoa takes a parameter named base (which you have assumed is 10).</p>\n\n<p>You probably don't need a second hidden function; this would do instead:</p>\n\n<pre><code>if (n < 0)\n{\n *s++ = '-';\n n = -n;\n}\n// ... itoa implementation continues here ...\n</code></... | {
"AcceptedAnswerId": "40975",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T14:38:27.517",
"Id": "40961",
"Score": "2",
"Tags": [
"c",
"beginner",
"pointers"
],
"Title": "Pointer version of itoa"
} | 40961 |
<p>I'm trying to use an object and persist it into the data base.</p>
<p>I created a class in the library's folder.</p>
<pre><code><?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Solicitud {
private $categoria;
private $consecutivo;
private $id;
private $mensaje;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T14:51:44.353",
"Id": "70200",
"Score": "0",
"body": "I realized that int the model I can use the get functions like `'id_category' => $soporte->getCategoria();`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "20... | [
{
"body": "<p>I would like to add something to @Dukeatcoding comment in the question. What is the point of passing the whole object? Thinking on it as a part of the main controller, you should only pass the data as an array to the model:</p>\n\n<pre><code>$data = array(\n 'id_user' => $usuario,\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T14:47:39.787",
"Id": "40963",
"Score": "1",
"Tags": [
"php",
"object-oriented",
"mvc",
"codeigniter"
],
"Title": "Passing an object to the view in CodeIgniter"
} | 40963 |
<p>Can anyone please help me to simplify this form validation script? It works great but I was just wondering if I can get some help to make it simpler. Your opinion on the approach I used below is also welcome (i.e it is good or bad practice/method). </p>
<pre><code><script type="text/javascript">
va... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T16:37:14.253",
"Id": "70224",
"Score": "1",
"body": "If that is meant to be jQuery plugin you are not wrapping it correctly into the jQuery namepsace. Could cause issues but its jsut precautin"
}
] | [
{
"body": "<p>This is already quite tight, I like it.</p>\n\n<p>There is one big thing that jumps out:</p>\n\n<pre><code>validator = this;\nvar currentmsg =this;\n</code></pre>\n\n<p>You are using <code>this</code>, and <code>validator</code> and <code>currentmsg</code> all really pointing to <code>this</code>,... | {
"AcceptedAnswerId": "41001",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T14:47:59.960",
"Id": "40964",
"Score": "6",
"Tags": [
"javascript",
"jquery",
"performance",
"html",
"validation"
],
"Title": "Simplifying this form validation script"
... | 40964 |
<p>This code works, but since I'm just learning Haskell I'm wondering if it could have been done in a more idiomatic way.</p>
<p>The main function is called <code>tokenize</code>, and it uses helper functions called <code>tokenizeOne</code> and <code>tokenizeSeveral</code>.</p>
<p>Here is the code:</p>
<pre><code>to... | [] | [
{
"body": "<p>Apart from general code layout I don't see much to improve - the only issue worth talking about is that you should never <em>ever</em> actually use something like <code>++ [ch]</code>. Your function is needlessly O(n²) for that reason alone. That might not sound like much here, but it is a good id... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T15:17:35.457",
"Id": "40968",
"Score": "3",
"Tags": [
"haskell"
],
"Title": "Split a string on spaces, accounting for backslash as escape character, in Haskell"
} | 40968 |
<p>I am using a combination of knockoutJS and jQuery. I have a number of jQuery plugins which perform particular re-usable functions, such as a numeric spinbox. </p>
<p>I have written a binding handler to allow me to bind an observable property to the spinbox, it looks like this:</p>
<pre><code>ko.bindingHandlers.spi... | [] | [
{
"body": "<p>I like your approach much better than using separate values.</p>\n\n<p>The code reads really well, I only have 1 minor suggestion.</p>\n\n<p>If you had a helper function like this:</p>\n\n<pre><code>function unwrapOrDefault( gift , defaultValue )\n{\n return gift === undefined ? defaultValue : ... | {
"AcceptedAnswerId": "47166",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T15:34:06.207",
"Id": "40970",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"knockout.js"
],
"Title": "knockout binding handler for custom components"
} | 40970 |
<p>I have a class that listens to a file event constantly and reads that json file once it's created and makes of it a mail report and an excel file. </p>
<p>Now, I made the properties that are used for both these tasks static so I could determine their values once from the json and easily access them from all methods... | [] | [
{
"body": "<ol>\n<li><p>Not only is it bad practice, I'd say it's <em>horrible</em> practice. Save yourself, or others which will be dealing with your code, some future headache and use <strong>as few static variables as possible, preferably none!</strong> <em>(The reason why I say this is horrible could have s... | {
"AcceptedAnswerId": "40989",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T15:55:02.813",
"Id": "40972",
"Score": "13",
"Tags": [
"c#",
"static"
],
"Title": "Non static class with static fields"
} | 40972 |
<p>This is my first project I am doing in VB.NET, and also my first <strong>real</strong> programming project. There is sensitive data, so I am utilizing Microsoft's Encryption/Decryption class (<code>clsCrypt</code>).</p>
<p>For optimization, quality and best practice standards, which code the 'best' way to retrieve... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T19:17:15.037",
"Id": "71324",
"Score": "0",
"body": "@Mark LaREZZA: In short, are you asking the best way to encrypt data from your app to SQL Server?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T1... | [
{
"body": "<p>Okay, best practices... </p>\n\n<p><strong>Data Access</strong></p>\n\n<p>Never do data access directly in the UI. Have a separate class file to do this. Best practice would suggest creating an interface for each 'aggregate root' (collection of classes that act as an integral whole). that you want... | {
"AcceptedAnswerId": "41542",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T16:07:28.703",
"Id": "40973",
"Score": "3",
"Tags": [
"sql",
"sql-server",
"vb.net",
"cryptography"
],
"Title": "Using SQL with encryption"
} | 40973 |
<p>I think my current structure is way too repetitive. I feel like I must be missing something that would easily make this sign up wizard work far better.</p>
<pre><code> <ol class="registerMeter">
<li class="progress-point" ng-click="wiz('step1')" ng-class="{active: step1.active, done: step1.done, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T01:29:01.870",
"Id": "70295",
"Score": "0",
"body": "You have a lot of booleans Are they all required? Could you instead check if values the user enters in the wizard exist (not null) instead of three boolean states?"
},
{
"... | [
{
"body": "<p>You can make this DRYer if you can assume that : </p>\n\n<ul>\n<li>You keep naming each step <code>stepx</code></li>\n<li>No other variables in <code>$scope</code> start with <code>step</code></li>\n</ul>\n\n<p>In that case you could use a function that sets in a first step the right scope active ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T16:11:09.277",
"Id": "40974",
"Score": "3",
"Tags": [
"javascript",
"angular.js"
],
"Title": "Sign-up wizard structure seems too repetitive"
} | 40974 |
<p>The code below finds the index of the lowest unique integer on each line of the file. The numbering starts at 1, and when there's no unique value, the <code>0</code> should be output.</p>
<p>The sample input looks like this:</p>
<pre><code>3 3 9 1 6 5 8 1 5 3
9 2 9 9 1 8 8 8 2 1 1
</code></pre>
<p>And the sample ... | [] | [
{
"body": "<p>First off, your usage of <code>alter</code> can easily be replaced by <code>insertWith</code>:</p>\n\n<pre><code>counts :: [(Int, Int)] -> IntMap [Int]\ncounts = foldr f empty\n where f (i,v) = insertWith (const (i:)) v [i]\n</code></pre>\n\n<p>You could also use <code>fromListWith</code>, whi... | {
"AcceptedAnswerId": "40998",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T16:33:04.057",
"Id": "40977",
"Score": "5",
"Tags": [
"haskell"
],
"Title": "Find index of lowest unique integer in each line of the file"
} | 40977 |
<p>I just wrote this and don't like how bulky it is, also given the fact I will have to add at least another <code>if</code> statement.</p>
<p>I was going to switch it to a case statement but wanted to check if there were even better ways to reduce the clutter.</p>
<pre><code>string emailLetterPath = Server.MapPath("... | [] | [
{
"body": "<blockquote>\n <p>I was going to switch it to a case statement but wanted to check if there were even better ways to reduce the clutter.</p>\n</blockquote>\n\n<p>You could load the mappings from job titles to emails into a (static) dictionary, and then do a dictionary look-up (using the default valu... | {
"AcceptedAnswerId": "40988",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T17:57:07.223",
"Id": "40982",
"Score": "3",
"Tags": [
"c#",
"asp.net"
],
"Title": "Job applicant email system"
} | 40982 |
<p>I have the following code and it's taking quite some time to run. I'm getting an <code>Out of Memory Exception</code> due to the high volume of answers there are. Is there any way I could speed it up?</p>
<pre><code>var controlStrings = answerControlStrings.Where(a => a.ControlN.Substring(a.ControlN.IndexOf('_'... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T18:29:31.030",
"Id": "70243",
"Score": "0",
"body": "Is this called in some kind of loop? How is this data used? It would be helpful if you gave us more context here. How many answers are there? Please give us more information!"
}... | [
{
"body": "<p>You're iterating through controlStrings 4 times (because you have 4 Where clauses).</p>\n\n<p>It might be better to rewrite this as a for loop:</p>\n\n<pre><code>foreach (var c in controlStrings)\n{\n var cultureN = c.CultureN;\n\n if (cultureN.Contains(\"cati\") && cultureN.Contains... | {
"AcceptedAnswerId": "40995",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T18:03:18.020",
"Id": "40984",
"Score": "1",
"Tags": [
"c#",
"performance",
"linq",
"hash-map"
],
"Title": "Making adding to a dictionary more efficient?"
} | 40984 |
<p>I'm implementing basic sorting algorithms to learn them, and coding, better. Criticisms and possible optimizations welcome.</p>
<pre><code>import unittest
import random
def merge_sort(seq):
"""Accepts a mutable sequence. Utilizes merge_sort to sort in place, return
a sorted sequence"""
if len(seq) == 1... | [] | [
{
"body": "<p>if you are looking for places to improve your code, i noticed that in this:</p>\n\n<pre><code> while i < len(left) and j < len(right):\n #if current left val is < current right val; assign to master list\n if left[i] < right[j]:\n seq[k] = left[i]\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T18:17:48.533",
"Id": "40986",
"Score": "8",
"Tags": [
"python",
"algorithm",
"beginner",
"sorting",
"mergesort"
],
"Title": "Merge Sort Algorithm in Python"
} | 40986 |
<p>It all works exactly as it should. It finds data from today, finds unique emails and puts them in an array. I then check the data again from today, against the emails to total up different values. Then output those values to a sheet.</p>
<p>I'm sure there might be better methods to do what I wish. Such as only go... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T20:12:07.740",
"Id": "70253",
"Score": "0",
"body": "A thought has struck me, I'll have to fill entire sheet white, and set font black before colouring ranges.\nOr sheet will end up all stripey as data changes."
}
] | [
{
"body": "<p>You keep repeating <code>if (values[counter][emailColumn -1] == names[i] &&</code> and <code>values[counter][findColumn -1]</code> , how about doing that just once ?</p>\n\n<p>You will end up with this more readable, faster code:</p>\n\n<pre><code>if (values[counter][emailColumn -1] == nam... | {
"AcceptedAnswerId": "41084",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T18:17:58.603",
"Id": "40987",
"Score": "4",
"Tags": [
"javascript",
"beginner",
"datetime",
"google-apps-script",
"google-sheets"
],
"Title": "Script for generating a r... | 40987 |
<p>Please review this code.</p>
<pre><code> import java.awt.*;
import javax.swing.*;
public class Snake_Ladder {
public static void main(String[] args) {
new Snake_Ladder();
}
public Snake_Ladder(){
int i;
JFrame frame = new JFrame();
JPanel pane = new JPanel();
GridLayout experimentLayout = new GridLayout(11,0)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T19:29:51.303",
"Id": "70249",
"Score": "3",
"body": "Close voters: Even though this question is asking for some feature to be added (which is off-topic), the current code does work and really **needs** to be reviewed! I think we sho... | [
{
"body": "<p>Unfortunately your question about \"How to...\" is off-topic for this site but I feel that your code really <strong>needs</strong> to be reviewed as there are some things that can be improved.</p>\n\n<ul>\n<li><p><strong>Don't import .*</strong> Only use the imports that you need. If you need to i... | {
"AcceptedAnswerId": "40994",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T19:02:08.720",
"Id": "40990",
"Score": "0",
"Tags": [
"java",
"swing",
"awt"
],
"Title": "A whole bunch of JButtons"
} | 40990 |
<p>I have the following function, intended to take standard dice notation (XdY+Z) and return a (sort of) random number based on the input. Are there any bugs/bad ideas/optimizable sections I am missing?</p>
<pre><code>function dieRoll(dice) {
if (/^[\d+]?d\d+[\+|\-]?\d*$/.test(dice) == false) { //Regex validate
... | [] | [
{
"body": "<p>You validate the input string against a regular expression, but then you manually parse it again the hard way. Instead, you should use parentheses within the regular expression to define capturing groups.</p>\n\n<p>I also think that your regular expression is not quite correct. Optional digits <... | {
"AcceptedAnswerId": "40996",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T19:28:21.307",
"Id": "40993",
"Score": "3",
"Tags": [
"javascript",
"performance",
"regex",
"random",
"dice"
],
"Title": "Dice notation roller in JavaScript"
} | 40993 |
<p>After programming in Haskell for a while, I've gotten attached to a functional style. This is clearly evident in the code for my genetic algorithm. </p>
<p>Could you provide me with some hints as to how I can make this code more <em>pythonic</em>? By that, I mean provide some method of organisation rather than th... | [] | [
{
"body": "<p>I have been facing the same issue for a few months, even though I didn't write that much functional code before switching. Please take my comments with a grain of salt even if I say \"do <strong>this</strong>\" instead of \"<strong>this</strong> might help but I'm not sure\".</p>\n\n<ul>\n<li><p>U... | {
"AcceptedAnswerId": "41062",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-02-05T21:35:04.773",
"Id": "41004",
"Score": "5",
"Tags": [
"python",
"data-visualization",
"genetic-algorithm"
],
"Title": "Genetic algorithm in Python that plots its evolution"
} | 41004 |
<p>I had a situation when I needed to move all array elements in circular fashion. When I say this, I mean:</p>
<pre><code>0 1 2 3
1 2 3 0
2 3 0 1
3 0 1 2
</code></pre>
<p>The array:</p>
<pre><code>var players = ["hash1","hash2","hash3","hash4"];
</code></pre>
<ul>
<li><code>Players</code> is the array that contain... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T21:38:02.823",
"Id": "70266",
"Score": "2",
"body": "Why not leave the data as-is and use `%`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T21:40:49.470",
"Id": "70267",
"Score": "0",
"... | [
{
"body": "<p>You should use <code>shift</code> and <code>push</code></p>\n\n<pre><code>function rotate( array , times ){\n while( times-- ){\n var temp = array.shift();\n array.push( temp )\n }\n}\n\n//Test\nvar players = ['Bob','John','Mack','Malachi'];\nrotate( players ,2 )\nconsole.log( players );\n... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T21:36:03.497",
"Id": "41006",
"Score": "14",
"Tags": [
"javascript",
"array"
],
"Title": "Rotating array members"
} | 41006 |
<p>I've done some reading about implementing AES256 and deriving a key from a password. If I understand correctly:</p>
<ul>
<li>I want to generate a new salt (for the key) and a new IV (for the encrypted message) for every new message. </li>
<li>It should also not be a problem sending the salt and the IV together with... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T21:50:10.150",
"Id": "70274",
"Score": "0",
"body": "Question - if you are limited to 256 bytes, why Base64 encode it? What is the protocol you are using on the 'internet', can it be a byte-stream?"
},
{
"ContentLicense": "C... | [
{
"body": "<p>A few, mostly minor notes:</p>\n\n<ol>\n<li>\n\n<pre><code>\"payload_here\".getBytes();\n</code></pre>\n\n<p><code>getBytes()</code> should have been called with a <code>Charset</code>. Otherwise it uses the platform's default charset which can vary from platform to platform and could result to da... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T21:39:48.440",
"Id": "41007",
"Score": "5",
"Tags": [
"java",
"cryptography"
],
"Title": "Encrypting a payload for transmission over HTTP. AES256 with PBKDF2"
} | 41007 |
<p>I've written an implementation of a dynamic array in C, but I'm not sure if my implementation is correct... This is what I'm worried about: if I add an element, will it remain in the collection? This problem has arisen from my (apparently) limited knowledge on void pointers. I haven't found any answers to my questio... | [] | [
{
"body": "<blockquote>\n <p>If I were to call this function with an element created on the stack (example below), would it continue to work for the entirety of the program's lifetime?</p>\n</blockquote>\n\n<p>No, it wouldn't:</p>\n\n<ul>\n<li>i is created on the stack</li>\n<li>pointer to i is saved in the li... | {
"AcceptedAnswerId": "41011",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T22:09:39.823",
"Id": "41009",
"Score": "3",
"Tags": [
"c",
"pointers"
],
"Title": "C dynamic array and pointers"
} | 41009 |
<p>I've implemented a common wrapper pattern I've seen for the .NET cache class using generics as follows:</p>
<pre><code>private static T CacheGet<T>(Func<T> refreashFunction, [CallerMemberName]string keyName = null)
{
if (HttpRuntime.Cache[keyName] == null)
HttpRuntime.Cache.Insert(keyName, r... | [] | [
{
"body": "<p>First of all, I think you misspelled <code>refresh</code> as <code>refreash</code>.</p>\n<p>Second, your usage can probably be simplified</p>\n<pre><code>CacheGet(AlotOfWork);\n</code></pre>\n<p>Finally, you might want to check if <code>refreshFunction</code> returns null and maybe log a warning t... | {
"AcceptedAnswerId": "41013",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T22:10:23.370",
"Id": "41010",
"Score": "10",
"Tags": [
"c#",
"generics",
"cache"
],
"Title": "Cache wrapper - Generics vs Dynamic"
} | 41010 |
<p>I created this testimonial on <a href="http://codepen.io/JGallardo/pen/zGyid" rel="noreferrer">CodePen</a></p>
<p><img src="https://i.stack.imgur.com/oUzbu.png" alt="current quote"></p>
<p>I am a bit skeptical about a few things in my HTML structure. For example, I typically see testimonials enclosed in <code><... | [] | [
{
"body": "<ul>\n<li><p>I would say that for it to be semantically accurate, the <code>author</code> should be a part of the <code>blockquote</code>, perhaps using a <code>footer</code>.</p></li>\n<li><p>You should include a <code>cite</code> attribute if the quote has a source.</p></li>\n<li><p>The quote conte... | {
"AcceptedAnswerId": "41022",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T23:21:05.483",
"Id": "41017",
"Score": "17",
"Tags": [
"html",
"css"
],
"Title": "Testimonial section with HTML tags"
} | 41017 |
<p>I tried to make a calculator in Java and have added some stuff. I'm a beginner and have learned yesterday how to make buttons.</p>
<pre><code>import java.awt.Dimension;
import javax.swing.*;
import java.awt.Toolkit;
import java.awt.event.*;
public class JavaCalculatorCopy extends JFrame{
JPanel Panel = new J... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T00:23:37.613",
"Id": "70292",
"Score": "3",
"body": "Note: Possible bug: `if(SecondValue.equals(\"\")|SecondValue.equals(\"-\"))`"
}
] | [
{
"body": "<p>This is more to tackle than would be easy to cover in a single answer.</p>\n\n<h2>Small items.</h2>\n\n<p>There are a couple of small items that are a problem.</p>\n\n<ul>\n<li><p>you are using capitalized names for variables.... this is against the coding style for Java. Variable names should alw... | {
"AcceptedAnswerId": "41031",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-05T23:46:33.453",
"Id": "41019",
"Score": "9",
"Tags": [
"java",
"beginner",
"swing",
"calculator"
],
"Title": "Java Calculator"
} | 41019 |
<p>I'm working on a directed study project with a professor of mine helping him build out a Django based website. The website is a historical account of the people, events, projects, and organization in the computer graphics industry.</p>
<p>Since the beginning of the project (way before I started working on it) my pr... | [] | [
{
"body": "<p>That's a lot of code, a small observation to start with:</p>\n\n<pre><code> var rangeMemo = {};\n var pubBuildRange = function(year, mod) {\n var result = rangeMemo[year], ..snip..;\n // If we haven't seen the given year yet then continue and find the range.\n if (!result) {\n ..sn... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T01:19:11.173",
"Id": "41021",
"Score": "2",
"Tags": [
"javascript",
"performance",
"datetime",
"sorting",
"d3.js"
],
"Title": "Approximating/Sorting groups of dates into b... | 41021 |
<p>I'm just starting to understand the Python syntax and I created a module that does what I wanted, but really slow.</p>
<p>Here are the stats of cProfile, top 10 ordered by <code>internal time</code>:</p>
<pre><code> ncalls tottime percall cumtime percall filename:lineno(function)
1291716 45.576 0.000 ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T10:50:01.310",
"Id": "70370",
"Score": "0",
"body": "Did you [profile](http://docs.python.org/2/library/profile.html)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T11:11:14.677",
"Id": "70371",... | [
{
"body": "<h3>1. Introduction</h3>\n\n<p>Thanks for running the profiler. As you can see from the output, most of the runtime is being spent in your <code>containing_tet</code> function.</p>\n\n<p>The first thing to say is that you have made this question unnecessarily difficult for us because your functions h... | {
"AcceptedAnswerId": "41089",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T01:37:26.583",
"Id": "41024",
"Score": "13",
"Tags": [
"python",
"performance",
"numpy",
"python-2.x",
"computational-geometry"
],
"Title": "Faster computation of baryc... | 41024 |
<p>This is my take at the current <a href="/questions/tagged/code-challenge" class="post-tag" title="show questions tagged 'code-challenge'" rel="tag">code-challenge</a>, <a href="https://codereview.meta.stackexchange.com/questions/1471/weekend-challenge-reboot">Ultimate Tic-Tac-Toe</a>, at least the <em>presen... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T17:28:55.997",
"Id": "71653",
"Score": "0",
"body": "Why do the large squares have double borders?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T23:39:37.040",
"Id": "71732",
"Score": "0",
... | [
{
"body": "<ol>\n<li><code><Setter Property=\"Border.Background\" Value=\"#AAF0F8FF\" /></code> - <code>Border.</code> prefix should be redundant, as you specify target type in <code>Style</code>.</li>\n<li><code><Image Source=\"{Binding Value.Value, Converter={local:CellValueImageConverter}}\" Stretch... | {
"AcceptedAnswerId": "41047",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T02:55:55.823",
"Id": "41026",
"Score": "10",
"Tags": [
"c#",
"game",
"wpf",
"xaml",
"community-challenge"
],
"Title": "TicTactics Presentation"
} | 41026 |
<p>I'm using meteor and angular. Since I can't add modules after the angular bootstrap, I made a workaround and somewhat not satisfied with the way it was coded.</p>
<p>How can I improve this?:</p>
<pre><code>(function() {
var controllers = ngMeteor.newControllers,
filters = ngMeteor.newFilters,
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T04:25:08.027",
"Id": "70313",
"Score": "0",
"body": "No dog-balls! Use `}());` instead of `})()` to remove ambiguity."
}
] | [
{
"body": "<p>Lets say you defined a module like so after the bootstrap:</p>\n\n<pre><code>myModule = angular.module('myModule',[]);\n</code></pre>\n\n<p>You can inject this module into ngMeteor after the bootstrap like so:</p>\n\n<pre><code>ngMeteor.requires.push('myModule');\n</code></pre>\n\n<p>You could eas... | {
"AcceptedAnswerId": "41064",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T02:59:16.140",
"Id": "41027",
"Score": "2",
"Tags": [
"javascript",
"angular.js",
"meteor"
],
"Title": "Angularjs Module Registration Structure"
} | 41027 |
<p><strong>I am having a huge brain fart with efficiency right now.</strong></p>
<p>The idea here is if I have a static <code>table</code> (unfortunately formatted this way with the data I've received), how would I appropriately <code>append</code> a <code>select option dropdown</code> with every value from the table ... | [] | [
{
"body": "<p>We can do some thing like this <a href=\"http://jsfiddle.net/z2V2p/11/\" rel=\"nofollow\">http://jsfiddle.net/z2V2p/11/</a></p>\n\n<pre><code><script>\n var dataArray = [];\n\n dataArray[0] = ['item','Item 1','Item2','Item3','Item4'];\n dataArray[1] = ['value','Value 1','Value 2','V... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T03:19:33.473",
"Id": "41028",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Append table cells to select boxes in indexed order"
} | 41028 |
<p>This is my take at the current <a href="/questions/tagged/code-challenge" class="post-tag" title="show questions tagged 'code-challenge'" rel="tag">code-challenge</a>, <a href="https://codereview.meta.stackexchange.com/questions/1471/weekend-challenge-reboot">Ultimate Tic-Tac-Toe</a>.</p>
<p>It all started ... | [] | [
{
"body": "<ol>\n<li><p>I can see some code duplication. For example this</p>\n\n<pre><code>private void BoardCellValueChanged(object sender, EventArgs e)\n{\n _winner = _evaluator.Evaluate(_cells, out _winningPositions);\n if (_winner != null)\n {\n OnCellValueChanged();\n }\n}\n</code></pre... | {
"AcceptedAnswerId": "41056",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T03:44:11.607",
"Id": "41029",
"Score": "10",
"Tags": [
"c#",
"game",
"community-challenge",
"tic-tac-toe"
],
"Title": "TicTactics GameBoard Logic"
} | 41029 |
<p>While I should probably be using Dependency Injection via <a href="http://www.ninject.org/">Ninject</a> or a similar project, I have been attempting to implement an abstract factory design that would provide me with the following easy to read and use syntax:</p>
<pre><code>UniversalFactory.Factory<IFoo>.Creat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T04:31:04.987",
"Id": "70315",
"Score": "0",
"body": "obligatory: http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T18:59:39.880",
"Id":... | [
{
"body": "<p>Well what you are trying to do is not strictly speaking an abstract factory. For it to be an abstract factory the use case should look like this:</p>\n\n<pre><code>UniversalFactory.Factory<IFoo> // client has no idea about IFactory<IFoo> implementation\n .Create(... par... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T03:57:56.637",
"Id": "41030",
"Score": "6",
"Tags": [
"c#",
"generics",
"factory-method"
],
"Title": "Abstract Factory Experiment"
} | 41030 |
<p>I've written a solution to <a href="http://projecteuler.net/problem=41">Euler 41</a>:</p>
<blockquote>
<p>We shall say that an n-digit number is pandigital if it makes use of
all the digits 1 to n exactly once. For example, 2143 is a 4-digit
pandigital and is also prime.</p>
<p>What is the largest n-digi... | [] | [
{
"body": "<p>I think this is a bit over engineered. Let's talk our way through the problem.</p>\n\n<ul>\n<li>By definition we know the highest pandigital number is 987654321.</li>\n<li>We need to loop through each odd number between 1 and 987654321.</li>\n<li><p>We need to test each number as a prime.\nHere's ... | {
"AcceptedAnswerId": "41048",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T06:02:50.177",
"Id": "41037",
"Score": "5",
"Tags": [
"javascript",
"project-euler",
"node.js",
"primes"
],
"Title": "Project Euler #41 - pandigital prime"
} | 41037 |
<p>This is my attempt at the <a href="https://codereview.meta.stackexchange.com/a/1472/23788">Ultimate Tic-Tac-Toe code challenge</a>.</p>
<p>It uses jQuery to build out the game grid and find the states of all the "buttons" (actually <code><div></code>s) when calculating whether or not someone has won an indivi... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>I would use the HTML 5 tags, they are cleaner and more appropriate:<br>\n <code><!DOCTYPE html></code><br>\n <code><html></code><br>\nYour code validates perfectly as HTML5</li>\n<li>The UI setup probably deserves it's own function</li>\n<li>The... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T06:03:52.010",
"Id": "41038",
"Score": "11",
"Tags": [
"javascript",
"jquery",
"html",
"css",
"community-challenge"
],
"Title": "Ultimate Tic-Tac-Toe Challenge"
} | 41038 |
<p>I am creating an application in Java that runs at scheduled intervals and it transfer files from one server to another server.</p>
<p>For <code>SFTP</code> I'm using <code>jSch</code>, and my server and file details came from Database.</p>
<p>My code is working fine but its performance is not good because I'm usin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T09:11:45.003",
"Id": "70354",
"Score": "0",
"body": "Do you connect and disconnect from the FTP each time in the loop? It looks like it? I can't tell because it seems you have 2 or 3 loops doing something."
},
{
"ContentLice... | [
{
"body": "<p>At face value it appears that there can be only one place where the major bottleneck is: the actual file transfer. Your code does the following:</p>\n\n<ul>\n<li>builds up a bunch of source files to copy</li>\n<li>creates a 'target' destination for the file copy</li>\n<li>goes through each source<... | {
"AcceptedAnswerId": "41063",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T07:42:18.710",
"Id": "41041",
"Score": "7",
"Tags": [
"java",
"optimization",
"performance",
"multithreading"
],
"Title": "Creating a thread for file transfer"
} | 41041 |
<p>I wrote Clojure code which takes named params and has to generate 2 .csv files as output.</p>
<p>Please review it.</p>
<pre><code>(ns my_cli_clojure.core
(:gen-class :main true))
(require '[clojure.data.csv :as csv]
'[clojure.java.io :as io]
'[me.raynes.fs :as fs]
'[clojure.tools.cli :refer [cli]... | [] | [
{
"body": "<p>Everything looked pretty good in general, until I got to the <code>(let [output_directory ...</code> part, then your indentation got all wonky! Part of the problem is that there are a couple of really long lines, and it's difficult to keep them short when you're nested so many layers deep into an ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T07:56:03.997",
"Id": "41042",
"Score": "4",
"Tags": [
"clojure",
"csv"
],
"Title": "Generating two .csv files from named parameters"
} | 41042 |
<p>Is there anything that can be done to improve this code? Even if its using a comepltey different technique.</p>
<p>This code gets a list of vanruns with rules, cutoff time and fittinging time offset. We pass in the date (either now or for future that works out the best vanrun time) We want the latest cutofftime in ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T12:23:46.133",
"Id": "70377",
"Score": "3",
"body": "Hello, and welcome to Code Review! Could you at least explain what the code does? Thanks!"
}
] | [
{
"body": "<p>There are somethings that I want to point out, that you are doing slightly wrong. </p>\n\n<ul>\n<li>The first one is the argument checking. Argument checking should always be the first thing you do in your code, unless it is an expensive operation or you can't do it in a straight forward manner. I... | {
"AcceptedAnswerId": "41071",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T11:39:42.243",
"Id": "41057",
"Score": "7",
"Tags": [
"c#"
],
"Title": "Figuring out delivery times"
} | 41057 |
<p>I'm preparing for an exam on C++, as part of my preparation I want to implement a generic map without using anything from the STD for educational purposes.</p>
<p>Before jumping into implementation of everything, I want to know that the skeleton for my Map is solid and I use templates and template inheritance corre... | [] | [
{
"body": "<p>Here are some small things you could di in order to improve your design:</p>\n\n<ul>\n<li>First of all, you have a typo: you wrote <code>Map::Iiterator begin();</code> instead of <code>Map::Iterator begin();</code>.</li>\n<li>You use <code>KeyType</code> and <code>DataType</code> but do not even d... | {
"AcceptedAnswerId": "41654",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T11:49:48.867",
"Id": "41059",
"Score": "6",
"Tags": [
"c++",
"c++11",
"template"
],
"Title": "Template data types implementation"
} | 41059 |
<p>Generally, UI code is painful and full of kludges (at least, mine was like that). Recently I have decided to put an end to it and try to learn how to write good and reusable UI code. </p>
<p>So here is the pattern (in a general sense of word) I came up with when subclassing UIViews: </p>
<ol>
<li>Subviews are prop... | [] | [
{
"body": "<p>The first thing that stands out to me immediately is the lack of <code>@required</code>/<code>@optional</code> in the <code>@protocol</code>.</p>\n\n<p>This is mostly a readability thing, but you should certainly mark each of your methods to make your intent explicit. Once you've done this, inter... | {
"AcceptedAnswerId": "42101",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T13:51:25.837",
"Id": "41066",
"Score": "5",
"Tags": [
"objective-c",
"ios",
"gui",
"cocoa-touch"
],
"Title": "UIView subclass"
} | 41066 |
<p>I've been a procedural PHP programmer for a long time but I'm getting to learn OOP and would like some advice. I'm designing a class which currently is composed mainly of simple getters/setters, but I'm not quite sure if I'm designing my class in the best way possible.</p>
<p>The getters require accessing a databas... | [] | [
{
"body": "<p>OOP is definitely the way to go. The best advise I can offer is to read the book \"Clean Code\" by Uncle Bob. The code there is in Java but all principles apply equally to any other language.</p>\n\n<p>I would definitely abstract the DB interface so I can use for any other database, even if you do... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T13:54:10.703",
"Id": "41067",
"Score": "3",
"Tags": [
"php",
"object-oriented"
],
"Title": "PHP class design with methods requiring database access"
} | 41067 |
<p>Would it be better to convert the array in the following code to</p>
<pre><code>$langs = array("en", "de", "fr");
</code></pre>
<p>and then reusing the values for both <code>$folder</code> and <code>$flag</code>? If so, how then would my foreach (or maybe a while?) loop be written?</p>
<pre><code><?php
$la... | [] | [
{
"body": "<p>You can definitely simplify this, as the only part of each element of <code>$langs</code> that changes is the two-letter language code. Something like this would work:</p>\n\n<pre><code><?php\n$langs = array(\n \"en\",\n \"de\",\n \"fr\"\n);\n$self = $_SERVER['REQUEST_URI'];\n$patte... | {
"AcceptedAnswerId": "41079",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T15:14:52.833",
"Id": "41075",
"Score": "4",
"Tags": [
"php",
"array"
],
"Title": "Simplifying an associative array()"
} | 41075 |
<p>This is another entry for <a href="https://codereview.meta.stackexchange.com/a/1472/34757">The Ultimate Tic-Tac-Toe</a> review.</p>
<p>My design criteria were:</p>
<ul>
<li>A DLL which encapsulates the data, i.e. the game state</li>
<li>Don't include the GUI, nor the decision-making (game-playing) logic</li>
<li>B... | [] | [
{
"body": "<p>Here's a bug:</p>\n\n<ul>\n<li>Someone can play on an already-won quadrant (is this allowed by the rules?).</li>\n<li>If they play on an empty space of an already-won quadrant they can 'win again' i.e. trigger the Recalculate logic and potentially get a different Winner.</li>\n</ul>\n\n<hr>\n\n<p>... | {
"AcceptedAnswerId": "41080",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T15:43:36.987",
"Id": "41078",
"Score": "16",
"Tags": [
"c#",
"game",
"community-challenge"
],
"Title": "Ultimate Tic-Tac-Toe data model"
} | 41078 |
<p>I recently got rejected at a job interview for submitting this:</p>
<p><a href="https://bitbucket.org/gnerr/password-validator" rel="nofollow">https://bitbucket.org/gnerr/password-validator</a></p>
<p>The interviewer asked for a password validation library that was configurable via Spring, with the following defau... | [] | [
{
"body": "<p>Putting this as an anwer, because it took a while to find it:</p>\n\n<p>I took your code, and put it through some tests..... I made the tests up based on the 'rules'. This is the sort of thing any interviewer will do:</p>\n\n<pre><code>public static void main(String[] args) {\n String[] positiv... | {
"AcceptedAnswerId": "41085",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T16:35:14.043",
"Id": "41082",
"Score": "8",
"Tags": [
"java",
"interview-questions",
"validation",
"dependency-injection",
"spring"
],
"Title": "Spring password validat... | 41082 |
<p>Runs smoothly, however valgrind is showing "possibly lost: 544 bytes in 2 blocks".
This is my first time doing a lot of things here so I might be making multiple mistakes. </p>
<p>Please let me know if anything needs to be fixed, or if I should just do something completely different for whatever reason.</p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T18:11:17.743",
"Id": "70455",
"Score": "5",
"body": "ASCII art comments? That just repeat the names of the functions? Argh, my eyes..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T18:58:59.430",
... | [
{
"body": "<h1>Things you did well</h1>\n\n<ul>\n<li><p>Nicely formatted, easy to read.</p></li>\n<li><p>Use of <code>typedef</code> with structures.</p></li>\n</ul>\n\n<h1>Things you could improve</h1>\n\n<h3>Preprocessor:</h3>\n\n<ul>\n<li><p>Since <code>SDL.h</code> isn't one of your own pre-defined header f... | {
"AcceptedAnswerId": "44635",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T17:32:38.853",
"Id": "41086",
"Score": "12",
"Tags": [
"c",
"lock-free",
"atomic",
"audio"
],
"Title": "Play some sine waves with SDL2"
} | 41086 |
<p>I am practicing for interviews and I tried solving the problem on my own and got a solution. I was wondering how can I improve the performance and memory on this program?</p>
<p>The problem performs addition on linked list nodes. The nodes are <code>1s->10s->100s->...</code>. The goal of this program is t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T18:25:04.427",
"Id": "70459",
"Score": "0",
"body": "What is your `LinkedListNode` implementation? Could you provide a runnable example? I didn't really understand your explanation completely."
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>I believe you are missing the point of the exercise - instead of 'decoding' the input numbers, and then 're-encoding' the output number - you are supposed to iteratively get to the answer by going over the nodes of both lists:</p>\n\n<pre><code>public static LinkedListNode addLists(LinkedListNode ... | {
"AcceptedAnswerId": "41096",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T18:15:43.483",
"Id": "41090",
"Score": "11",
"Tags": [
"java",
"performance",
"linked-list",
"memory-management"
],
"Title": "Linked list arithmetic"
} | 41090 |
<p>I have tried to write a function like <code>memcpy</code>. It copies <code>sizeof(long)</code> bytes at a time.</p>
<p>What surprised me is how inefficient it is. It's just 17% more efficient than the naivest implementation with <code>-O3</code>. With optimizations off it's a lot faster than the naivest, so perhaps... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-05-23T21:54:55.220",
"Id": "311900",
"Score": "0",
"body": "I think it should be noted that in the Internet, this very code has been presented as an example of a not obvious UB. See http://blog.regehr.org/archives/1307 , especially sectio... | [
{
"body": "<p>The last time I saw source for a C run-time-library implementation of <code>memcpy</code> (Microsoft's compiler in the 1990s), it used the algorithm you describe: but it was written in assembly. It might (my memory is uncertain) have used <code>rep movsd</code> in the inner loop.</p>\n\n<p>Your co... | {
"AcceptedAnswerId": "41099",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T18:28:50.233",
"Id": "41094",
"Score": "7",
"Tags": [
"c",
"performance",
"reinventing-the-wheel"
],
"Title": "memcpy() implementation"
} | 41094 |
<p>I have created a script for going a multiple select option in Angular without using a <code>select</code> box that you have to hold control in order to select multiple items.</p>
<p>Demo: <a href="http://jsfiddle.net/qwertynl/xfw9f/" rel="nofollow">http://jsfiddle.net/qwertynl/xfw9f/</a></p>
<p><a href="https://gi... | [] | [
{
"body": "<p>I really like your code, I only have 2 minor observations:</p>\n\n<ul>\n<li><p>I understand the part where <code>default</code> has the default items. I am not sure that after initialization you should keep referring to the <code>default</code> variable ( from a naming perspective ), maybe call it... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T18:30:53.147",
"Id": "41095",
"Score": "6",
"Tags": [
"javascript",
"angular.js"
],
"Title": "Angular JS Switcharoo multiple select module"
} | 41095 |
<p>I tried to make the code for implementation of first-come first-serve job scheduling algorithm as used by operating systems.</p>
<p>How can I make it better?</p>
<p>I am using turbo C++ compiler</p>
<pre><code>#include<conio.h>
#include<iostream.h>
#include<dos.h>
struct process//contains inform... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T20:06:54.190",
"Id": "70499",
"Score": "0",
"body": "Did you mean to tag this as [c]? This hardly looks like [c++] (except for `cin` and `cout`)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T20:10... | [
{
"body": "<p>I think this question would actually benefit from both a C review (just change the <code>cout</code>'s to <code>printf</code>, etc) and a C++ review since you seem to be using a very C-orientated programming style. </p>\n\n<p>This post will be a C++ review.<br>\nPlease note that the Turbo C++ com... | {
"AcceptedAnswerId": "41122",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T19:24:29.973",
"Id": "41101",
"Score": "11",
"Tags": [
"c++",
"queue"
],
"Title": "First-come first-serve job scheduling algorithm"
} | 41101 |
<p>A week ago, I have asked how to <a href="https://codereview.stackexchange.com/questions/40964/simplifying-this-form-validation-script/41001?noredirect=1#41001">simplify a form validation</a>. From the answers, the code now is improved. Can anyone please share their opinion on the approach used below and advise me ... | [] | [
{
"body": "<ul>\n<li><p>I'd almost always rather use object literals <code>{}</code> than <code>new Object()</code> for this. Much less verbose and easier to read.</p>\n\n<pre><code>var errorMessage = {\n required : \"This field can not be empty\",\n email : \"Please enter a valid email address\",\n n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T19:47:11.193",
"Id": "41103",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html",
"form"
],
"Title": "Simplifying this form validation script - version 2"
} | 41103 |
<p><strong>Related tag: <a href="/questions/tagged/fun" class="post-tag" title="show questions tagged 'fun'" rel="tag">fun</a></strong></p>
<p>It all started with a small group of CR addicts that were discussing questions in <a href="https://chat.stackexchange.com/rooms/8595/the-2nd-monitor">The 2nd Monitor</a... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-02-06T20:08:32.557",
"Id": "41106",
"Score": "0",
"Tags": null,
"Title": null
} | 41106 |
Reviewing code is fun! Use this tag to identify your post as an entry to the current community challenge. See the Community Bulletin, or browse the CR Meta site for more info. Typically you should also tag community-challenge questions with the [game] tag as well. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-02-06T20:08:32.557",
"Id": "41107",
"Score": "0",
"Tags": null,
"Title": null
} | 41107 |
<p>I have the following code which I have written due to the fact the Microsoft's Sanitizer is now to aggressive.</p>
<p>What I'm trying to do is as follows.</p>
<ol>
<li>Create a whitelist of HTML tags I want to keep</li>
<li>After the tags have been converted, run the text through the sanitizer and remove any tags ... | [] | [
{
"body": "<p>You could simplify the declaration of the tags you want to keep, as it is very structured:</p>\n\n<pre><code>var whitelist = new List<string>(new string[] { \"p\", \"h1\", \"br\" });\n\nforeach (var w in whitelist) {\n txt = txt.Replace(\"<\" + w + \">\", \"&lt;\" + w + \"&gt;... | {
"AcceptedAnswerId": "41163",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T21:17:19.447",
"Id": "41111",
"Score": "2",
"Tags": [
"c#",
"regex"
],
"Title": "Whitelist HTML tags Microsoft Sanitizer and custom Regex"
} | 41111 |
<p>I've got some pretty simple validation that I'm working on, but it seems like I'm repeating myself a bunch of times. There has to be a better way of doing this. I'm simply checking if there is a value filled in for specific fields and apply a color if the value isn't filled in. There are also other areas where the v... | [] | [
{
"body": "<p>Yup, you can iterate the input fields. For this sort of thing you should also be using classes, instead of inline CSS. Using jQuery <code>.each</code> and <code>.togggleClass</code> you can create something like this: </p>\n\n<pre><code>function validate () {\n\n $('#form input').each(function ()... | {
"AcceptedAnswerId": "41114",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T21:22:23.390",
"Id": "41112",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Checking for a value on selectors"
} | 41112 |
<p>I wrote this code to clean up some of the space on our file server. We've got 15 years of legacy data that nobody accesses or changes or cares about that we have to keep regardless. I'd rather have it not sitting on our main file server so that I don't have to add an additional TB to it annually. This script goes th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T22:44:31.643",
"Id": "71192",
"Score": "0",
"body": "Well, on the off chance that someone wants to use this code, or looks at it later I've updated it to address a few of the issues that we experienced while running this. You'll als... | [
{
"body": "<p>Not bad at all. Nice to see functions but perhaps you have too many.</p>\n\n<p>Do you really need this as a function? </p>\n\n<pre><code>function DeleteFIle($File){\n del $file.fullname \n}\n</code></pre>\n\n<p>This function is listed twice but is only called once. It could have probably stayed... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T21:24:50.937",
"Id": "41113",
"Score": "5",
"Tags": [
"beginner",
"windows",
"powershell"
],
"Title": "Script which migrates files to secondary storage and symlinks them"
} | 41113 |
<p>I wrote this prototype after reading the Wikipedia article on hooking. I didn't bother to read any of the code examples listed there because, well, I just didn't. I don't have a good excuse.</p>
<p>The documentation in this file should tell you enough about its purpose and intended usage. I'm looking for a confi... | [] | [
{
"body": "<p>This appears to be an implementation of something akin to the <a href=\"http://en.wikipedia.org/wiki/Observer_pattern\" rel=\"nofollow\">observer pattern</a>. Your implementation is straightforward enough, but there are two things that jump out at me.</p>\n\n<p>First, I'm surprised that this invol... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T21:38:59.740",
"Id": "41115",
"Score": "6",
"Tags": [
"python",
"python-3.x",
"callback",
"meta-programming"
],
"Title": "Hooking with Python3 Decorators"
} | 41115 |
<p>I am creating a blog concept with this layout on <a href="http://codepen.io/JGallardo/pen/tfFCL" rel="nofollow noreferrer">CodePen</a></p>
<p><img src="https://i.stack.imgur.com/ML3eu.png" alt="screenshot"></p>
<p>Here is my current code in development</p>
<pre><code><article class="post">
<h2>Skati... | [] | [
{
"body": "<p>Your <code>img</code> is missing the <a href=\"http://www.w3.org/TR/2013/CR-html5-20130806/embedded-content-0.html#alt\" rel=\"nofollow\"><code>alt</code> attribute</a>.</p>\n\n<hr>\n\n<pre><code><a href=\"#\" class=\"readMore\">\n <i class=\"fa fa-list-ul\"></i>\n</a>\n</... | {
"AcceptedAnswerId": "41124",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T22:34:42.410",
"Id": "41118",
"Score": "5",
"Tags": [
"html",
"meteor",
"mustache"
],
"Title": "Review of HTML markup for this blog concept"
} | 41118 |
<p>Recently I am working on batch to make a very simple command line interface.</p>
<p>The code looks like this:</p>
<pre><code>@echo off
echo Simple command-line interface
echo.
:input.get
set /p input="COMMAND\>"
set input5=%input:~0,5%
if "%input%"=="something" goto something
if "%input5%"=="echo " goto echo
:... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T06:06:24.650",
"Id": "70572",
"Score": "0",
"body": "I'd change 'if \"%input5%\"==\"echo \" goto echo' to 'if not \"%input5%\"==\"echo \" goto input.err', and create an input.err subroutine that prompts the user to try again. What y... | [
{
"body": "<p>You can use a FOR /F to parse out the command from the arguments.</p>\n\n<p>I would define a variable containing a delimited list of all valid commands. Then you can use simple search and replace to validate whether the user entered command is valid.</p>\n\n<p>Addition of a new command is as easy ... | {
"AcceptedAnswerId": "41184",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T00:44:09.023",
"Id": "41121",
"Score": "6",
"Tags": [
"batch"
],
"Title": "Making a .bat batch command-line interface"
} | 41121 |
<p>I've tried to take the shortest, simplest path to a C# solution to the <a href="https://codereview.meta.stackexchange.com/questions/1471/weekend-challenge-reboot">Ultimate Tic-Tac-Toe challenge</a>. This implementation plays in the console. I admit the game logic could be hived off into a separate method, but I'm ... | [] | [
{
"body": "<p>This doesn't strike me as particularly readable, although it is definitely succinct. Here are a few of the things I noticed that I think could be improved:</p>\n<ul>\n<li><p>The name <code>Min()</code> for a method that determines if someone has filled a row is very confusing.</p>\n</li>\n<li><p><... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T01:10:45.140",
"Id": "41123",
"Score": "14",
"Tags": [
"c#",
"game",
"tic-tac-toe",
"community-challenge"
],
"Title": "Tic-Tactics implementation"
} | 41123 |
<p>Instead of creating an Admin_Controller or MY_Controller I was going to try and just try out all my controllers on requirements that are needed per controller. I know this may seem like additional work but then after which I want to go back and fix it all. I wanted to know how my login looks as of right now?</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T12:42:55.110",
"Id": "70927",
"Score": "1",
"body": "Heres a comment.. maybe the up votes are indicative that the code looks fine and no one sees a real problem here, and like wise no one sees a point in commenting cause it look fin... | [
{
"body": "<ol>\n<li><p>Formatting is not consistent:</p>\n\n<blockquote>\n<pre><code>$this -> load -> model('user_login_model', 'login');\n$user_id = $this->session->userdata('user_id');\n</code></pre>\n</blockquote>\n\n<p>Sometimes there are spaces around <code>-></code>, sometimes aren't.</p><... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T03:34:05.230",
"Id": "41127",
"Score": "5",
"Tags": [
"php",
"codeigniter",
"authentication"
],
"Title": "Codeigniter Login Controller"
} | 41127 |
<ol>
<li><p>I saw somewhere on here that it helps reduce spam by adding a dummy input field that you hide with <code>display: none</code>, and like if it's filled out, then it's obviously a bot sending the message. Well, I did something kind of like that but initially set it to <code>= 0</code>. So if it's not <code>0<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T14:14:33.617",
"Id": "70612",
"Score": "0",
"body": "1. I don't think this will be particularly effective security. I wouldn't be surprised if automated tools simply recognize hidden fields and not touch them. You might want to look... | [
{
"body": "<p>Right, I'll be adding to this answer later on, but for a kick-off, here's a few quick remarks/considerations:</p>\n\n<p><strong>On the hidden input fields</strong><br>\nAs Martijn said in his comment: most bots will probably parse the DOM, and filter out those fields that are marked as required (l... | {
"AcceptedAnswerId": "41318",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T03:45:18.013",
"Id": "41129",
"Score": "12",
"Tags": [
"php",
"beginner",
"security",
"form",
"session"
],
"Title": "PHP form with bot deterrent"
} | 41129 |
<p>I have created an MS Excel type of grid in jQuery. I want to learn best practices and I need your comments for more optimized code.</p>
<p>Please review the code and offer your suggestions.</p>
<p><a href="http://jsfiddle.net/ananddeepsingh/pdfrN/" rel="nofollow">Demo</a></p>
<p><strong>jQuery:</strong></p>
<p... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>The column and row count should be a parameter/variable/default</li>\n<li>The namespace <code>JS.training</code> seems like overkill, I doubt anybody would ever use 2 libraries for showing datagrids ;)</li>\n<li><p>The following could use extraction of the patter... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T04:44:32.557",
"Id": "41130",
"Score": "10",
"Tags": [
"javascript",
"jquery",
"css",
"excel"
],
"Title": "MS Excel type of grid in jQuery"
} | 41130 |
<p>This maze has multiple entry points, and quite obviously multiple exits. The entry or exit is not provided at input. Of the multiple sources and destinations, any single path from any source to any destination should be returned. The path need not be the optimal or shortest path.</p>
<p>I'm looking for code opti... | [] | [
{
"body": "<p>Here are a few comments about the style. You'll find comments about the algorithm itself at the end.</p>\n\n<p><strong>Naming</strong></p>\n\n<p>The <code>3</code> at the end of the class names is a bit awkward.</p>\n\n<p>The same kind of things are sometimes called <code>x</code>, <code>dx</code>... | {
"AcceptedAnswerId": "41140",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T06:31:18.770",
"Id": "41133",
"Score": "10",
"Tags": [
"java",
"pathfinding"
],
"Title": "Find a path through a maze"
} | 41133 |
<p>Please review the following code:</p>
<pre><code>static int md5_encode(const char * input_md5 , char * output , int size)
{
// checking pre-requisits //
if( output == NULL || input_md5 == NULL || size == 0)
{
printf( "main.cpp:md5_encode() error check for the prerequisites. \n");
exit(0);
}
int... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T21:10:48.440",
"Id": "70682",
"Score": "0",
"body": "You tagged your question as [tag:c], and the code is written in C style. Yet, curiously, the code mentions `main.cpp`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creatio... | [
{
"body": "<p>I'm not familiar with the \"ucuc format\", or what such an output format could be useful for. A <a href=\"https://www.google.com/search?q=md5+ucuc+format\" rel=\"nofollow noreferrer\">Google search for <code>md5 ucuc format</code></a> shows this question itself as the only relevant hit.</p>\n\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T06:35:54.400",
"Id": "41134",
"Score": "5",
"Tags": [
"c",
"memory-management"
],
"Title": "Input memory buffer exceeding situation handling"
} | 41134 |
<p>I am working on a micro project: a Haskell DSL for describing circuits.
(You can find the code <a href="https://github.com/j-rock/hCircuit/blob/master/src/Alu.hs" rel="nofollow">here</a>)</p>
<p>I'm pretty happy with everything so far, but there is an ugly function <code>alu32</code>:</p>
<pre><code> alu32 c0 c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T10:03:02.753",
"Id": "70590",
"Score": "0",
"body": "You could do something like `results = (aluc (head a) (head b) c0) :: zipWith3 (\\x y z -> aluc x y (snd z)) (tail a) (tail b) results` then `map fst results` I haven't tried this... | [
{
"body": "<blockquote>\n <p>Can anyone suggest a more idiomatic way of representing this? </p>\n</blockquote>\n\n<p>The equations for the ALU have the form</p>\n\n<pre><code>(out !! i, cout !! i) = aluc (a !! i) (b !! i) (cout !! (i - 1))\n</code></pre>\n\n<p>so we should be able to express all of the equatio... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T06:56:30.200",
"Id": "41135",
"Score": "3",
"Tags": [
"haskell",
"dsl"
],
"Title": "DSL for describing circuits"
} | 41135 |
<p>In <code>JUnit 3</code>, I cannot tell <code>JUnit</code> what type of exception is expected. In <code>JUnit 4</code>, the declaration <code>@Test(expected=NullPointerException.class)</code> does it.</p>
<p>But, unfortunately in <code>Android development</code>, I can use only <code>JUnit 3</code>. So I wrote this ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T10:12:13.933",
"Id": "70591",
"Score": "2",
"body": "The message for the case if it is was *not* thrown should be clearer, including something like \"Expected exception X, but was not thrown\"."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>I have <a href=\"https://github.com/hunterhacker/jdom/blob/master/test/src/java/org/jdom2/test/util/UnitTestUtil.java#L305\" rel=\"nofollow\">been though this loop before</a>. I chose to do things in a slightly different way to you, in that instead of creating a Runnable, I instead add a try/catch... | {
"AcceptedAnswerId": "41145",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T10:06:45.047",
"Id": "41141",
"Score": "4",
"Tags": [
"java",
"android",
"exception-handling"
],
"Title": "Simple helper method for JUnit3 tests"
} | 41141 |
<p>I'm trying to develop code to filter my e-mail with <code>JavaMail</code>, but I doubt it's the best way of doing this. And I want to collect all messages without attachment.</p>
<pre><code>package service.forkinjoin;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T12:15:22.847",
"Id": "70604",
"Score": "0",
"body": "There is no fork/join, or even Executor code in here... nothing multi-threaded at all.... except a call to `invokeAll(...)`, but there is no `invokeAll` method here. Where is your... | [
{
"body": "<p>In order to correctly work in parallel, you must follow the <a href=\"http://en.wikipedia.org/wiki/Actor_model\" rel=\"nofollow noreferrer\">Actor Model</a>, which basically says that each iteration should not share memory when doing their work. In your code, you pass a <code>List<Message></... | {
"AcceptedAnswerId": "41252",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T11:15:18.910",
"Id": "41143",
"Score": "2",
"Tags": [
"java",
"multithreading",
"email"
],
"Title": "Filter email with JavaMail"
} | 41143 |
<p>I'm working on a small command line application in c# where data is read from a CSV file along with a query and KNN is calculated for the query based on the data.</p>
<p>My problem isn't the algorithm at all, I understand it. Im having difficulty working with my code though. I think it's down to bad planning.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T14:02:12.997",
"Id": "70611",
"Score": "1",
"body": "To get you right, your code is basically working?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T14:40:05.550",
"Id": "70614",
"Score": "0... | [
{
"body": "<ol>\n<li><p>As others mentioned in comments, you should follow <a href=\"http://msdn.microsoft.com/en-us/library/ms229043\" rel=\"nofollow\">the .Net naming guidelines</a>. It will make your code consistent with all other .Net code.</p></li>\n<li><p>Try to avoid abbreviated names like <code>KNN</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T13:30:28.137",
"Id": "41146",
"Score": "4",
"Tags": [
"c#",
"csv",
"statistics"
],
"Title": "Averages and standard deviations for a Knn application"
} | 41146 |
<pre><code>#include <stdio.h>
#include <stdint.h>
#include <assert.h>
typedef uint8_t byte;
typedef struct
{
byte i, j;
byte S[256];
} Rc4State;
void swap(byte *a, byte *b)
{
byte temp = *a;
*a = *b;
*b = temp;
}
/*Initialization & initial permutation
also initialize i&... | [] | [
{
"body": "<p>From top to bottom…</p>\n\n<ul>\n<li><code>#include <stdio.h></code> appears to be left over from development, and can be removed.</li>\n<li><code>swap()</code> is not part of your library's interface, and should be declared <code>static</code>.</li>\n<li>To give your library a sense of unit... | {
"AcceptedAnswerId": "41169",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T14:05:46.077",
"Id": "41148",
"Score": "8",
"Tags": [
"c",
"cryptography"
],
"Title": "RC4 implementation in C"
} | 41148 |
<p>Suppose I have the array:</p>
<pre><code>double[] arrayToCut = new double[100];
for(int i = 0 ; i < 100 ; ++i) {
arrayToCut[i] = Math.random();
}
</code></pre>
<p>My objective is to end up with two arrays, <code>firstArray</code> and <code>secondArray</code>. <code>firstArray</code> is equal to (for example... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T15:49:33.233",
"Id": "70621",
"Score": "1",
"body": "see: http://stackoverflow.com/questions/1100371/grabbing-a-segment-of-an-array-in-java"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T17:54:29.047... | [
{
"body": "<p>I am pretty sure you can use <code>copyOfRange(double[] original, int from, int to)</code> from <code>java.util.Arrays</code>. @Rolfl said, and I quote : <em>It is recommended practice to use Arrays.copyOf instead of System.arraycopy().</em></p>\n\n<p>If you need to cut up the million+ array for p... | {
"AcceptedAnswerId": "41154",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T14:25:23.427",
"Id": "41151",
"Score": "8",
"Tags": [
"java",
"performance",
"array"
],
"Title": "Fastest way to cut an array into two arrays at a particular index"
} | 41151 |
<p>I have 2 tables as below:</p>
<p>Downtime</p>
<p><img src="https://i.stack.imgur.com/7YdFT.jpg" alt="enter image description here"></p>
<p>DowntimeCode</p>
<p><img src="https://i.stack.imgur.com/27LDb.jpg" alt="enter image description here"></p>
<p>I am then doing this to get the Description field from the Down... | [] | [
{
"body": "<p>I don't understand your <code>for</code> and <code>foreach</code> loops - you always return from the first iteration!</p>\n\n<p>What's wrong with this code?:</p>\n\n<pre><code>public string TopCodeForToday(string line)\n{\n var date = DateTime.Now;\n\n using (var db = new PillowContext())\n ... | {
"AcceptedAnswerId": "41164",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T14:40:32.340",
"Id": "41156",
"Score": "6",
"Tags": [
"c#",
"linq",
"error-handling"
],
"Title": "Optimising and error handling Linq query"
} | 41156 |
<p>I am brand new to C++ and am working with the Arduino micro controller. The project I've been working on for my university requires me to write code to do the following:</p>
<blockquote>
<ul>
<li><p>If the ultrasonic sensor detects a distance within a certain range, output HIGH to activate an electric motor</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T17:14:35.180",
"Id": "70629",
"Score": "0",
"body": "what kind of average do you want? there is the running average: this reading + next reading / 2, or it's the framed average: sum of last x readings / x - these will prbably be the... | [
{
"body": "<ul>\n<li><p>As per C++ naming convention, only user-defined types and macros in C++ are capitalized. Your constants, global variable, and functions should start with a lowercase letter.</p></li>\n<li><p>Since your constants are similar, you can group them into an <a href=\"http://www.cprogramming.c... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T16:08:02.490",
"Id": "41160",
"Score": "4",
"Tags": [
"c++",
"beginner",
"arduino"
],
"Title": "Arduino based ultrasonic sensor program, output HIGH to control electric motor"
} | 41160 |
<p>Aim: To have only one of each character on the Return string:</p>
<pre><code>Public Shared Function CheckForDuplicates(ByVal vCharCheck As String) As String
Dim vDeDuplicated As String = ""
Dim i As Integer
For i = 1 To vCharCheck.Length ' Count length of string
'vDeDuplicate is blank to star... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T17:41:48.340",
"Id": "70639",
"Score": "1",
"body": "I think we are missing some code, some of this doesn't make sense, how is `vCharCheck` determined/populated? where do you assign a value to `vDeDuplicated`?"
},
{
"Conte... | [
{
"body": "<p>you should change the code around a little bit so that if the string is empty it will exit the code before hitting the loop. and you should use a <code>foreach</code> instead of a <code>for</code>\nand get rid of all the Mid stuff</p>\n\n<pre><code>For Each Character As Char In vCharCheck\n If... | {
"AcceptedAnswerId": "41265",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T17:01:26.243",
"Id": "41165",
"Score": "6",
"Tags": [
"strings",
"vb.net"
],
"Title": "Creating new string with only distinct letters"
} | 41165 |
<p>So I developed some code as part of a larger project. I came upon a problem with how to match paragraphs, and wasn't sure how to proceed, so I asked on Stack Overflow <a href="https://stackoverflow.com/questions/21466890/paragraph-matching-python">here</a>. You can find an in-depth description of my problem there ... | [] | [
{
"body": "<p>A few tips for leaner code:</p>\n\n<ul>\n<li><p>Use <code>enumerate</code> while iterating when you need the index, to avoid the sequential search and extra verbosity of <code>orParas.index(orPara)</code>. For example the last loop becomes</p>\n\n<pre><code>for orIndex, orPara in enumerate(orParas... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T17:16:16.023",
"Id": "41167",
"Score": "4",
"Tags": [
"python",
"python-2.x"
],
"Title": "Paragraph Matching in Python"
} | 41167 |
<p>One of the books I'm currently reading to learn C# asked me to write a method that takes an integer between 1 and 99999 and displays each number in that integer in a sequence, separating each digit by 2 spaces.</p>
<p>For example: the int <code>87564</code> would be written to the console as <code>8 7 5 6 4</code>.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T18:30:34.740",
"Id": "70658",
"Score": "1",
"body": "Welcome to CR! This small snippet makes your post very focused on the specific problem you're trying to solve (which isn't *bad* in itself). You'd probably get a more thorough rev... | [
{
"body": "<p>Your method is lying. Not only it's <em>displaying the digits</em>, performing every <code>Console.Write</code> operation that needs to happen, it's also performing the \"digit-splitting\" logic.</p>\n\n<p>It's more work than what its name says. For a simple coding exercise it's without consequenc... | {
"AcceptedAnswerId": "41186",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T18:21:07.157",
"Id": "41174",
"Score": "19",
"Tags": [
"c#",
"recursion",
"integer"
],
"Title": "Displaying each number of an integer in a sequence"
} | 41174 |
<p>I want to draw the table like this:</p>
<blockquote>
<pre class="lang-none prettyprint-override"><code>6³ = 3³ + 4³ + 5³
9³ = 1³ + 6³ + 8³
12³ = 6³ + 8³ + 10³
18³ = 2³ + 12³ + 16³
18³ = 9³ + 12³ + 15³
19³ = 3³ + 10³ + 18³
20³ = 7³ + 14³ + 17³
.....
100³ = 35³ + 70³ + 85³
</code></pre>
</blockquote>
<p>I've tri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T22:14:54.543",
"Id": "70691",
"Score": "0",
"body": "Have you tried *not* using precalculated values?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T16:33:52.430",
"Id": "70743",
"Score": "2"... | [
{
"body": "<p>I would make a few changes for readability:</p>\n\n<ul>\n<li>Rename:\n<ul>\n<li><code>$p3a</code> → <code>$cubes</code></li>\n<li><code>$numlist</code> → <code>$cubeRoots</code></li>\n</ul></li>\n<li>Hard-code <code>$tnum</code>. It's not going to vary anyway, since it wasn't a parameter.</li>\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T20:38:02.057",
"Id": "41179",
"Score": "9",
"Tags": [
"php",
"algorithm",
"performance",
"mathematics"
],
"Title": "Draw the table like 6³ = 3³ + 4³ + 5³ to 100³ = 35³ + 70³ +... | 41179 |
<p>If one does not know tilt maze then the game looks like <a href="http://www.mathsisfun.com/games/tilt-maze.html" rel="nofollow">this</a>. Basically one can travel in 4 directions North, East, South and West, but this travel's endpoint is the furthest <em>non-obstructed</em> block. If solution has multiple routes, th... | [] | [
{
"body": "<h1>hashCode implementation</h1>\n<p>Your <code>hashCode</code> method leaves some things to be desired.</p>\n<p>The more often a hashCode is unique, the better. Even though your <code>CoordinateTiltMaze</code> class fulfills the equals & hashCode contract, your if an object has the hashCode <cod... | {
"AcceptedAnswerId": "41190",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T23:34:00.470",
"Id": "41187",
"Score": "4",
"Tags": [
"java",
"algorithm",
"pathfinding"
],
"Title": "Tilt maze solution"
} | 41187 |
<p>In order to complete one of my assignment I needed to include a quicksort so I was wondering if this is correct and acceptable. </p>
<p>The code: </p>
<pre><code> private ArrayList<String> sort(ArrayList<String> ar, int lo, int hi){
if (lo < hi){
int splitPoint = partition(ar,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T00:00:32.407",
"Id": "70694",
"Score": "1",
"body": "Have you tested your code anything?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T00:38:21.827",
"Id": "70696",
"Score": "0",
"body":... | [
{
"body": "<p>Those are pure functions that don't access any instance variables. You can therefore make them <code>static</code>.</p>\n\n<p>You could use generics more generically. Your code should work with any <code>List</code>, as long as it supports an <a href=\"http://docs.oracle.com/javase/7/docs/api/ja... | {
"AcceptedAnswerId": "41196",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T23:46:57.257",
"Id": "41189",
"Score": "7",
"Tags": [
"java",
"algorithm",
"sorting",
"quick-sort"
],
"Title": "Is this quicksort efficient and acceptable?"
} | 41189 |
<p>I am trying to create simple registration form with Backbone. I need to validate fields on blur, and whole form on submit.</p>
<p><strong>HTML:</strong></p>
<pre><code><form>
<div><input name="name" type="text" placeholder="Name"/></div>
<div><input name="surname" ... | [] | [
{
"body": "<p>I don't know too much about backbone, but here are my tips, i don't like, why?</p>\n\n<p>1 - This is ugly: app.__definitions.models.Signup, i don't like to use globals, you should avoid it, and \"Signup\" what? your app i suppose but if you've another \"sign up\" in your app what you would call it... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-07T21:13:00.383",
"Id": "41192",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"backbone.js"
],
"Title": "Simple registration form with Backbone"
} | 41192 |
<p>I have been working for weeks on a "BookViewer" AngularJS directive. I would like to write some blog posts on the lessons I learned in writing the directive. Before doing this I would like to ask for some feedback on how I wrote the directive. I ran into a lot trouble, learned a lot, but in the end I am quite happy ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T00:46:44.130",
"Id": "41195",
"Score": "1",
"Tags": [
"angular.js",
"typescript"
],
"Title": "AngularJS bookviewer directive written with Typescript and Angular-ui bootstrap"
} | 41195 |
<p>To download the tool and for usage instructions, see <a href="https://codereview.stackexchange.com/questions/41225/follow-up-to-tool-for-posting-code-review-questions">the follow up to this question</a></p>
<hr>
<h1>Description</h1>
<p>I have realized that there's a whole bunch of code I want to have reviewed, bu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T13:06:00.740",
"Id": "70729",
"Score": "0",
"body": "This question now has a follow-up: http://codereview.stackexchange.com/questions/41225/follow-up-to-tool-for-posting-code-review-questions"
}
] | [
{
"body": "<p>I would encourage you to produce more explicit output, particularly with the filenames. If I wanted to reverse the process and scrape the code into files on my machine, using a Python script such as the following…</p>\n\n<pre class=\"lang-python prettyprint-override\"><code>import json\nfrom lxml... | {
"AcceptedAnswerId": "41210",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T01:42:26.610",
"Id": "41198",
"Score": "45",
"Tags": [
"java",
"swing",
"formatting",
"stackexchange"
],
"Title": "Tool for creating CodeReview questions"
} | 41198 |
<p>I looking over some old code, I had written the function below with a C-style for-loop iterating over a count variable. I then fixed it up with new knowledge, but still am suspicious that there is even a better way to do this.</p>
<p>The function should behave like so:</p>
<pre><code>>>> join_list(['a'])
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T10:28:01.173",
"Id": "70723",
"Score": "0",
"body": "There's no docstring!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T17:34:58.543",
"Id": "70751",
"Score": "0",
"body": "To be fair I... | [
{
"body": "<p>Looks pretty good. The only problem I can see is that you're not doing a check to make sure the list is not empty: if it is, then you'll try to access <code>my_list[-1]</code> in the final <code>else</code> clause, which will raise an <code>IndexError</code>.</p>\n\n<p>Hence, I'd simply add a chec... | {
"AcceptedAnswerId": "41200",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T02:21:48.463",
"Id": "41199",
"Score": "11",
"Tags": [
"python",
"strings"
],
"Title": "Is there a simpler way to make an English-readable list from strings in a tuple?"
} | 41199 |
<p><strong>What I'm doing?</strong></p>
<p>I'm creating a member-list where initially only the names are visible. Clicking the names reveals the member information. This is done with jQuery by adding/removing classes.</p>
<p>I left out the CSS with the transitions for this review. </p>
<p><strong>HTML:</strong></p>
... | [] | [
{
"body": "<p>You're double-wrapping elements in jQuery. <code>blContent</code> and <code>blCurrentContent</code> are already jQuery objects, so doing <code>$(blContent)</code> isn't necessary. It's common practice to prefix jQuery collections with a dollar sign <code>$</code>.</p>\n\n<p>Other than that your co... | {
"AcceptedAnswerId": "41237",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T08:37:21.943",
"Id": "41207",
"Score": "10",
"Tags": [
"javascript",
"jquery",
"beginner",
"html"
],
"Title": "Member list reveals member information on click (#1)"
} | 41207 |
<p>This is a comment system that I wrote, is it secure?</p>
<pre><code><!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<?PHP
//Turn off error reporting (Not Necessary)
error_reporting(E_ALL ^ E_NOTICE);
//Connect to t... | [] | [
{
"body": "<p>One of the most common mistakes for PHP programmers is that they don't seem to have been looking at the big red box in the documentation for <a href=\"http://www.php.net/mysql_query\" rel=\"nofollow noreferrer\">mysql_query</a>, neither have they seen one of the many comments on Stack Overflow poi... | {
"AcceptedAnswerId": "41249",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T09:11:43.057",
"Id": "41209",
"Score": "8",
"Tags": [
"php",
"html",
"security"
],
"Title": "Simple comment system"
} | 41209 |
<p>I have this function in this <a href="http://jsfiddle.net/saadshahd/3smGz/">fiddle</a></p>
<p><strong>JavaScript:</strong></p>
<pre><code>var newsTicker = function (ele) {
var eles = ele.find('ul li'),
indexEle = 0,
dataEle = ele.find('.ticker-post'),
rotateChars = function (title) {
... | [] | [
{
"body": "<p>The HTML markup should be semantic, such that it degrades gracefully in the absence of JavaScript:</p>\n\n<pre><code><ul>\n <li><a href=\"#1\">No 10 armed police arrested over hardcore pornography</a></li>\n <li><a href=\"#2\">EDF extends life of UK nucl... | {
"AcceptedAnswerId": "41224",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T10:01:02.700",
"Id": "41215",
"Score": "10",
"Tags": [
"javascript",
"jquery"
],
"Title": "Create news ticker animation"
} | 41215 |
<p>This is my code to check if a string C is an interleaving of Strings A and B. Please suggests optimizations, and where I can improve.</p>
<pre><code>#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include ... | [] | [
{
"body": "<p>I would rewrite this part of code</p>\n\n<pre><code>if(c[k]==a[i]&&c[k]!=b[j])\n return isInterleaved(a,b,c,i-1,j,k-1);\nelse if(c[k]==b[j]&&c[k]!=a[i])\n return isInterleaved(a,b,c,i,j-1,k-1);\nelse if(c[k]==a[i]&&c[k]==b[j])\n return isInterleaved(a,b,c,i-1,j,k-1... | {
"AcceptedAnswerId": "41222",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T10:24:32.193",
"Id": "41217",
"Score": "2",
"Tags": [
"c++",
"c",
"algorithm",
"strings",
"recursion"
],
"Title": "To check if a string C is an interleaving of A and B ... | 41217 |
<p>This is my adapter class, to create a custom <code>listView</code> with three <code>radiobuttons</code>:</p>
<pre><code>public class Attendancelist_customadapter extends ArrayAdapter {
///needs two arraylists - one for the peopledetails, and one for the attendance status. read from file. passed to this.
///... | [] | [
{
"body": "<p>This is your lucky day, there is an \"easier\" way to do this. First, we create a custom <strong>inner</strong> class: (put this code inside your current class, just like you would do with a method)</p>\n\n<pre><code>private class MyCheckedChange implements CompoundButton.OnCheckedChangeListener {... | {
"AcceptedAnswerId": "41219",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T10:53:09.637",
"Id": "41218",
"Score": "4",
"Tags": [
"java",
"android"
],
"Title": "Radio ListView onCheckedChangeListener?"
} | 41218 |
<p>I am using building REST services for file upload on the server. Here is some code of that</p>
<pre><code>[OprationContract]
[WebInvoke(Method = "POST", UriTemplate = "UploadFile/{fileName}")]
public string UploadFile(string fileName, Stream fileStream)
{
string filePath = serverDirectory + "\\" + fileName;
usi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T15:01:40.867",
"Id": "70735",
"Score": "0",
"body": "This code won't compile, your method isn't returning anything."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T15:07:12.180",
"Id": "70736",
... | [
{
"body": "<p>The lines of code inside your UploadFile method look optimal to me.</p>\n\n<p>Perhaps the problem is that your Stream contents are being fully buffered before they're being delivered.</p>\n\n<p>I've no experience with this myself, but\n<a href=\"http://msdn.microsoft.com/en-us/library/ms789010.asp... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T11:23:58.763",
"Id": "41220",
"Score": "1",
"Tags": [
"c#",
"file",
"web-services"
],
"Title": "Best practice to upload files on server using Rest Service"
} | 41220 |
<h1>Description</h1>
<p>This is a follow-up question to <a href="https://codereview.stackexchange.com/questions/41198/tool-for-creating-code-review-questions">Tool for creating CodeReview questions</a>.</p>
<p>Things that has changed include:</p>
<ul>
<li>Removed replacing four spaces with one tab, all tabs and all ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-05-26T17:06:45.663",
"Id": "427315",
"Score": "0",
"body": "Are there templates on StackExchange how to structure questions/answers?"
}
] | [
{
"body": "<h2>General</h2>\n\n<p>Now that you have such neat postings, the answers are going to need to be neater too.</p>\n\n<h2>GUI Bugs</h2>\n\n<p>When I run the GUI, it does not let me select directories from the File Browser. It also starts in the 'Documents' directory, and it would be better to do one of... | {
"AcceptedAnswerId": "41246",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T13:01:54.403",
"Id": "41225",
"Score": "25",
"Tags": [
"java",
"swing",
"file-system",
"formatting",
"stackexchange"
],
"Title": "Follow-up to tool for posting CodeRevi... | 41225 |
<p><a href="http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm" rel="nofollow">KMP algorithm</a> is for searching and matching string with a given pattern. The most important part is to build a table for the pattern then move a proper step rather than just one step increment. </p>
<p>In my code ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T17:03:24.527",
"Id": "70747",
"Score": "0",
"body": "If `if (charPattern[j] == charSubstring[j])` is true, you never advance the `i`..... and loop infinitely. Closing off-topic."
}
] | [
{
"body": "<p>It is very hard to read your code, since you use single letter variables (<code>x</code>, <code>s</code>, <code>l</code>... etc.).</p>\n\n<p>Some more general concerns: <code>x</code> is a class member, initialized in its declaration, overriden in the <code>Main</code> method (without the initial ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T15:09:32.230",
"Id": "41229",
"Score": "0",
"Tags": [
"c#",
"algorithm"
],
"Title": "Moving steps in KMP algorithm"
} | 41229 |
<p>One of my classes regularly triggers one of two asynchronous operations: a "turn on" and a "turn off" that each take about a second. I'm using this method below to make sure that they don't run simultaneously. It doesn't seem very elegant to me. Is there some better way to do this? I'm using .NET 4.0, but I would li... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T16:31:51.073",
"Id": "70741",
"Score": "0",
"body": "If you submit new tasks faster than they can be executed, is it necessary that they execute in the order they were submitted in?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>First, some notes about your code:</p>\n\n<ul>\n<li>Using <code>Task</code>s that are first created and later started usually doesn't make much sense. To represent some work to be done, just use a delegate.</li>\n<li><a href=\"http://blogs.msdn.com/b/pfxteam/archive/2012/03/25/10287435.aspx\" rel=... | {
"AcceptedAnswerId": "41233",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T15:25:04.503",
"Id": "41230",
"Score": "3",
"Tags": [
"c#",
".net",
"task-parallel-library"
],
"Title": "Run control tasks asynchronously using TPL"
} | 41230 |
<p>This script scrapes recent articles on bitcoin, does sentiment analysis, and does some mock trading based on the sentiment of the articles. I'm looking for advice on code style, and I would love to learn how to write beautiful Ruby.</p>
<pre><code>require 'coinbase'
require 'sanitize'
require 'cgi'
require 'htmlen... | [] | [
{
"body": "<p>The <code>@</code> variable prefix should only be used inside a class to denote instance variables. That said, for a script like this, you might like to wrap all the logic in a class (or rather a module since you don't need multiple instances).</p>\n\n<p>Use string interpolation. So instead of</p>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T16:32:59.923",
"Id": "41234",
"Score": "5",
"Tags": [
"ruby",
"datetime",
"web-scraping"
],
"Title": "Scraping and analyzing recent articles on bitcoin"
} | 41234 |
<p>For the past four years I've attended a private school which requires its students to wear ties. I've found that it's far easier to figure out what combination of shirt, pants, and tie that go together the night before, as it can sometimes be a tedious process. To make this process simpler, I had the idea to create ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T23:09:01.237",
"Id": "70795",
"Score": "0",
"body": "Could you post a jsfiddle demo to test?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T00:34:23.297",
"Id": "70801",
"Score": "0",
"bo... | [
{
"body": "<p>Nice idea. I really like what you've done, but some of your implementation can definitely be improved. Let's start with the JSON.</p>\n\n<ul>\n<li><p>Some of those arrays are not needed. You wrap each <code>clothes</code> item in <code>[]</code>, there's no need for this as there's just one item i... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T17:17:17.660",
"Id": "41238",
"Score": "36",
"Tags": [
"javascript",
"jquery",
"json",
"random"
],
"Title": "Random clothes generator"
} | 41238 |
<p>Using Rails 3.2, I have the following:</p>
<pre><code>g = Geocoder.search(address)
# if no address found, geocode with latitude and longitude
if g.empty?
g = Geocoder.search(latitude, longitude)
if g.empty?
log.info "Geocode failed for #{latitude}, #{longitude}"
end
else
---save---
end
</code></pre>
<... | [] | [
{
"body": "<p>Nesting your <code>if</code>s is unnecessary, and flatting them will look better:</p>\n\n<pre><code>g = Geocoder.search(address)\n\n# if no address found, geocode with latitude and longitude\nif g.empty?\n g = Geocoder.search(latitude, longitude)\nend\n\nif g.empty?\n log.info \"Geocode failed... | {
"AcceptedAnswerId": "41251",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T17:55:01.163",
"Id": "41241",
"Score": "6",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Nested trial and error in if-else condition"
} | 41241 |
<p>This is in preparation for a competition that only allows C++03.</p>
<pre><code>// Neighbor index plus weight of edge connecting this vertex with neighbor
struct NeighborWeight
{
Index neighbor;
Distance weight;
};
// Represents adjacency information for a single vertex (contains all
// neighbors and weight... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T18:19:46.367",
"Id": "70867",
"Score": "0",
"body": "*competition that only allows C++03* you should have entered this before 2011. By now the language standard has moved on."
}
] | [
{
"body": "<p>I'll address some minor things (unrelated to efficiency, at least):</p>\n\n<ul>\n<li><p>The comments describing the <em>algorithm</em> could be at the very top so that the code in between isn't missed. Any comments describing the <em>functions</em> or the <code>typedef</code>s can stay above them... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T21:12:56.297",
"Id": "41254",
"Score": "5",
"Tags": [
"c++",
"graph",
"contest-problem",
"c++03"
],
"Title": "Dijkstra's and Prim's algorithms: correctness/efficiency"
} | 41254 |
<p>iMacros is a program that is used for writing scripts for Internet macros, which automatically perform tasks. </p>
<p>Javascript is mainly affiliated with this in writing scripts with iMacros.</p>
<p>For a full guide <a href="http://wiki.imacros.net/Main_Page" rel="nofollow">go here</a></p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T22:36:56.570",
"Id": "41257",
"Score": "0",
"Tags": null,
"Title": null
} | 41257 |
iMacros is a Firefox Add-On that is used for making web macros. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-08T22:36:56.570",
"Id": "41258",
"Score": "0",
"Tags": null,
"Title": null
} | 41258 |
<p>Given a set of 2 dimensional points, it returns the two nearest points. If more pairs have the same min-distance between them, then an arbitrary choice is made. This program expects the points to be sorted on the x-axis. If not, input is unpredictable.</p>
<p>I'm looking for code review, optimizations and best pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T00:32:40.947",
"Id": "70800",
"Score": "3",
"body": "Quick tip: You don't need the *actual* distances A-B and A-C to determine whether B or C is closer to A--just the *relative* distances. Drop the call to `sqrt` to shave off a few ... | [
{
"body": "<p>The <code>main()</code> method could be replaced with automatized JUnit tests to avoid <a href=\"http://xunitpatterns.com/Manual%20Intervention.html#Manual%20Result%20Verification\" rel=\"nofollow\">manual result verification</a>. You could also have more test methods which help <a href=\"http://x... | {
"AcceptedAnswerId": "41268",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T00:16:47.707",
"Id": "41259",
"Score": "4",
"Tags": [
"java",
"algorithm",
"clustering"
],
"Title": "Nearest pair of points"
} | 41259 |
<p>I decided to work on putting together an Arena-style (very basic) text-based RPG as a way to help myself learn Python. Unfortunately, after about 1,000 lines of pieced-together code, I realize that I've been doing myself a *dis*service by reenforcing poor practices, and by going line-by-line, my inefficiency is mul... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T02:45:04.843",
"Id": "70807",
"Score": "0",
"body": "If someone wants to point me to the proper location to use, I would be happy to post the uncut version and link it. The post here limits me to 30k characters, despite the scrollb... | [
{
"body": "<p>The primary problem I see is that your functions try to do everything from start to finish. For example <code>fightRound</code> knows all about the different kinds of weapons and armor and chances of critical hits and what effect these all have on the damage. It would benefit greatly being separat... | {
"AcceptedAnswerId": "41294",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T01:44:13.323",
"Id": "41264",
"Score": "10",
"Tags": [
"python",
"classes",
"library",
"python-2.x"
],
"Title": "Shortcuts and imports for large RPG basic code"
} | 41264 |
<p>Is there anything that I could have done better in this code?</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Quotes</title>
<style>
body { color: #333; font: 20px georgia; }
em { color: #555; font-size: 90%; }
</style>
</head>
<bod... | [] | [
{
"body": "<p>I think your code looks pretty good already. It follows conventions and your indentation and variable names are precise. There's not much to review.</p>\n\n<p>But if you're targeting modern browsers (IE9+) I would suggest a different approach using <code>map</code> and would separate the random lo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T05:05:35.833",
"Id": "41269",
"Score": "11",
"Tags": [
"javascript",
"html",
"array"
],
"Title": "Displaying random quotes from an array"
} | 41269 |
<p>I'm writing a parser for HTTP Authorization header (see <a href="https://www.rfc-editor.org/rfc/rfc2616#section-14.8" rel="nofollow noreferrer">RFC2616#14.8</a> and <a href="https://www.rfc-editor.org/rfc/rfc2617#section-1.2" rel="nofollow noreferrer">RFC2617#1.2</a>). <strong>Note that I explicitly don't care about... | [] | [
{
"body": "<p>Going through your specific questions, I have the following suggestions:</p>\n\n<ol>\n<li><em>Should you write a 'real' parser?</em> - Depends. Parsers can be complicated, and they make assumptions. Regardless, you have <strong>already</strong> written your own parser, and it is 'real'.</li>\n<li>... | {
"AcceptedAnswerId": "41293",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T05:20:34.973",
"Id": "41270",
"Score": "7",
"Tags": [
"java",
"parsing",
"regex",
"http"
],
"Title": "HTTP Authorization header parser"
} | 41270 |
<p>My boss needs me to embed the MD5 digest in a file path, but the problem is MD5 contains escape characters.</p>
<p>I've already taught about a <code>uc%duc%d...</code> format, but it also makes lengthy file names. In Linux it's not a problem since the Linux kernel could handle them.</p>
<pre><code>char * uc_encode... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T18:09:23.043",
"Id": "70864",
"Score": "0",
"body": "MD5 is a number. Convert the number into a string that is the ASCII representation of the number. Note: Usually this is done as hex number. If you make sure it is 0 padded it shou... | [
{
"body": "<p>MD5 is simply a 128 bit number.</p>\n\n<p>Convert the number into a string that is the ASCII representation of the number. Note: Usually this is done as hex number. If you make sure it is 0 padded it will be 32 characters long (as each 8 bits is converted into two hex digits). </p>\n\n<p>This is h... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T05:52:24.470",
"Id": "41272",
"Score": "7",
"Tags": [
"c",
"cryptography"
],
"Title": "Embed MD5 digest in a directory path name"
} | 41272 |
<p>I am new to linq to objects in C#. I have the following query which works adequately. Is there someway to reduce or rewrite this query using joins or something else? </p>
<pre><code>var query =
from container in containers
let items = container.GetItems()
from itemA in items
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T00:01:09.170",
"Id": "70883",
"Score": "3",
"body": "It looks like [join](http://code.msdn.microsoft.com/LINQ-Join-Operators-dabef4e9) might be possible. It might be easier to answer this question if you posted a complete program: e... | [
{
"body": "<p>After a <em>lot</em> of setup, I arrived at this:</p>\n\n<pre><code>var extensionMethodQuery =\n from container in containers\n let items = container.GetItems()\n select items.GetItemDerivedTagItems\n (items.SelectInterestingItemTags()).FirstOrDefault();\n</code></pre>\n\n<p>Your o... | {
"AcceptedAnswerId": "41600",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T06:14:39.107",
"Id": "41273",
"Score": "8",
"Tags": [
"c#",
"linq"
],
"Title": "Reduce or improve Linq query with nested from-where clauses"
} | 41273 |
<p>Requesting code review, best practices, optimizations for this solution to the <a href="http://en.wikipedia.org/wiki/Tower_of_Hanoi" rel="nofollow">Tower of Hanoi problem</a>.</p>
<pre><code>final class PlatePair {
private final String source;
private final String destination;
public PlatePair (String... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T13:59:58.153",
"Id": "70838",
"Score": "0",
"body": "I love towers of Hanoi :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T15:07:12.687",
"Id": "70842",
"Score": "1",
"body": "Downvoti... | [
{
"body": "<p>While your solution appears to work, and I cannot see any bugs, there are a number of best-practices that you are not employing in your solution. It is alsmost as if your code works by coincidence, rather than by design. There are a number of things that look like desperate attempts to make it wor... | {
"AcceptedAnswerId": "41287",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T06:26:29.107",
"Id": "41275",
"Score": "7",
"Tags": [
"java",
"algorithm",
"game",
"recursion",
"tower-of-hanoi"
],
"Title": "Tower of Hanoi solver"
} | 41275 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.