body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I need to implement the dynamic programming algorithm for the travelling salesman problem. My input is a text file with first line indicates the number of cities. Each city is a point in the plane, and each subsequent line indicates the x- and y-coordinates of a single city. The distance between two cities is define... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T16:47:17.853",
"Id": "52095",
"Score": "0",
"body": "what is `A` and what is `B`. then Why are you using `Double.POSITIVE_INFINITY` it looks like you are assigning a value of infinity to a lot of members in both of those arrays."
... | [
{
"body": "<p>The optimization I have used so far is storing subproblems of size m and size m-1 in HashMaps separately including only subsets with 1st vertex. E.g. For m = 1, there is only {1} subset. The keys of this HashMap are BitSets as used to represent subsets. I also used Gosper's Hack to get the next su... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T15:52:56.503",
"Id": "32574",
"Score": "3",
"Tags": [
"java",
"algorithm",
"traveling-salesman"
],
"Title": "Calculating Travelling Salesman - memory consumption and speed"
} | 32574 |
<p>In effort to be more effective and productive with terminals I have started building a bash script. It is for handling the bash history of concurrently running terminals, archiving old commands, and dynamically loading bash history profiles. </p>
<p>Most current development is going to be found at <a href="https://... | [] | [
{
"body": "<p>First of all,\nyou've got to give different names to <code>bashory</code> and <code>bastory</code>...\nI was very confused while reading the code,\nat first I thought it was a typo,\nit took me a while to realize they are different things.\nTo avoid confusion,\nit would be better to give them dist... | {
"AcceptedAnswerId": "60497",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T15:58:40.220",
"Id": "32575",
"Score": "5",
"Tags": [
"bash",
"shell"
],
"Title": "Project Bashory - Bash History"
} | 32575 |
<p>In my Repository class:</p>
<pre><code>public class DeliveryRepository : IDeliveryRepository
{
private readonly List<Delivery> deliveries = new List<Delivery>();
public Delivery Add(Delivery item)
{
if (item == null)
{
throw new ArgumentNullException("item");
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T19:48:52.250",
"Id": "52106",
"Score": "2",
"body": "I think it's preference and also what decisions your programming team has made in regards to the tools available. I personally like the second one, 3rd then first one however I'v... | [
{
"body": "<p>If you are addressing Code Contracts specifically then you should adopt a programming style that reinforces exception handling policy in release build, i.e. whether you require argument validation at runtime and whether Code Contracts will be part of release build or not.</p>\n\n<p>I suggest takin... | {
"AcceptedAnswerId": "32579",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T19:03:45.430",
"Id": "32576",
"Score": "1",
"Tags": [
"c#",
"design-patterns",
"comparative-review",
"null"
],
"Title": "Checking for null in delivery functions"
} | 32576 |
<p>I have a classes for working with a web service (Windows Phone 8 app). My main question is about the thread-safety of the solutions. I think there will be problems with a static class <code>GYApi</code>. After all, static classes aren't inherently thread safe. But not only in a static class. </p>
<p>If synchroniza... | [] | [
{
"body": "<ol>\n<li>I don't see any reason why <code>PostRequester</code> should be a singleton, just make it a static class.</li>\n<li>Since <code>PostRequester</code> doesn't contain any fields, you don't have to worry about its thread-safety. Unless you forgot to include those, because I don't see where <co... | {
"AcceptedAnswerId": "32587",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T20:39:57.580",
"Id": "32578",
"Score": "1",
"Tags": [
"c#",
".net",
"thread-safety",
"asynchronous",
"synchronization"
],
"Title": "Windows Phone 8 web service app clas... | 32578 |
<p>I am learning C++ and have been trying to create an event system for use in a small game. This will be the mechanism by which game entities communicate. I would be eternally grateful if someone with experience could critique my code. Running through it myself, I'm a little concerned about the use of Runtime Type Inf... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T21:53:20.627",
"Id": "32586",
"Score": "6",
"Tags": [
"c++",
"c++11",
"event-handling",
"boost",
"type-safety"
],
"Title": "Event system using callback functions in C++"
} | 32586 |
<p>My function calculates days elapsed from the current date. Input is fixed. I will get vector.</p>
<p>Please comment on this.</p>
<pre><code>static bool daysElapsed(const std::vector<char>& vec,int& val)
{
std::string str(vec.begin(),vec.end());
char *pos;// whose value is set by the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T07:25:36.453",
"Id": "52123",
"Score": "1",
"body": "One thing I notice is that the `vec` parameter can be a `const&` since it's not modified in the function. Alongside that, `cbegin()` and `cend()` can instead be used for `str`."
... | [
{
"body": "<p>It's weird to take a <code>std::vector<char></code> instead of a <code>std::string</code>. If you must take a <code>std::vector<char></code>, then make two overloaded versions of the function, where the vector variant calls the string variant.</p>\n\n<p>You never use the <code>val</co... | {
"AcceptedAnswerId": "32596",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T06:47:51.373",
"Id": "32593",
"Score": "4",
"Tags": [
"c++",
"datetime"
],
"Title": "Day elapsed since today from a given date"
} | 32593 |
<p>I have an object for which I wish to modify a property if a condition is met, else leave it virginal.</p>
<p>I find my current code to be very repetitive and would instead like to use a more succinct form, but am unsure of how to lambda-fy it or at least tell it to <code>pass</code> if condition not met:</p>
<pre>... | [] | [
{
"body": "<p>You can use</p>\n\n<pre><code>my_object.unique_id = my_object.unique_id or 'TBC'\n</code></pre>\n\n<p>Otherwise, stop worrying about having to repeat a variable name, which is not what people typically mean when they talk about DRY. Variable names are often repeated when you do in-place manipulati... | {
"AcceptedAnswerId": "32598",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T07:54:07.270",
"Id": "32595",
"Score": "1",
"Tags": [
"python"
],
"Title": "DRY version of this one line if/else for property's existence"
} | 32595 |
<p>This is a pretty big undertaking for me with my basic skills, and I was kind of flying blind. It's basic in its intent: get a bunch of case info from a helpdesk app and put it into a database. There are >10k records, so I had to overcome some pagination challenges. It works, and I would love your opinions regarding ... | [] | [
{
"body": "<p>Your code doesn't seem to be the complete module (e.g. <code>get_clean_id()</code> is referred to but not defined or imported, and I don't know what <code>desk_auth.session</code> does), so I won't try and understand the whole thing. I'll stick to comments about the general coding style.</p>\n\n<p... | {
"AcceptedAnswerId": "32647",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T18:59:48.693",
"Id": "32605",
"Score": "0",
"Tags": [
"python",
"mysql"
],
"Title": "API request and database insert"
} | 32605 |
<p>Is this the correct implementation of Heap Sort using Java? How can it be improved further?</p>
<pre><code>import java.util.Arrays;
public class HeapSort {
public static int heapSize;
public static int LEFT(int i)
{
//returns left index of a zero index based array
return 2*i+1;
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T23:22:09.167",
"Id": "52153",
"Score": "1",
"body": "Constant values are generally UPPERCASE. By convention, method names are camelCase and class names are PascalCase (aka TitleCase)."
}
] | [
{
"body": "<p>As everyone has immediately pointed out, please stick with the <code>namingConventions</code> for methods and parameter names.</p>\n\n<p>Your code is not object oriented, as Java code should be. One sign is that you are using <code>static</code> functions everywhere. Another hint is that the nam... | {
"AcceptedAnswerId": "32628",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T19:22:31.967",
"Id": "32606",
"Score": "8",
"Tags": [
"java",
"sorting",
"heap"
],
"Title": "Implementation of Heap Sort"
} | 32606 |
<p>Please tell me what you think. Is my code bad?</p>
<p>Function checking</p>
<pre><code>#-*- coding: utf-8 -*-
import re
import unittest
def email_check(mail): # E-mail as argument func
compil = re.compile(r"""
^([-a-z0-9_]+
((?![.][.])|([.]))
((["]["])|(["][!:,]+["]))?
... | [] | [
{
"body": "<p>If you are compiling your regular expression there is no improvement if you do this inside your method, move your regular expression declaration outside the method so it will not be compile it again every time you call 'email_check'</p>\n\n<p>In the line where you do <code>length = mail.split('@')... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T20:12:08.230",
"Id": "32607",
"Score": "1",
"Tags": [
"python",
"unit-testing",
"regex"
],
"Title": "Checking name E-mail and unit-test"
} | 32607 |
<p>Which of the following is better code:</p>
<pre><code>div#style1{
}
</code></pre>
<p>or </p>
<pre><code>#style1{
}
</code></pre>
<p>Also, should the element type be specified for classes or not?</p>
| [] | [
{
"body": "<p>It depends what you mean by \"better\".</p>\n\n<p>Because of <a href=\"https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Writing_efficient_CSS#How_the_Style_System_Matches_Rules\" rel=\"nofollow\">the way the style system matches rules</a>, <code>#style1</code> is faster than <code>div#style1... | {
"AcceptedAnswerId": "32614",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T21:25:10.303",
"Id": "32609",
"Score": "0",
"Tags": [
"css",
"dom"
],
"Title": "CSS Styling: Should I specify the element type?"
} | 32609 |
<p>I have a large number of images that were named in a odd way and because of that, when they're displayed in a file browser, they're completely out of order. However, since they weren't named in a completely random manner, I can use regex to properly rename them, once I understand all the subpatterns that went into i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T21:33:45.200",
"Id": "52145",
"Score": "1",
"body": "This code is simple, explicit and clear. You can rewrite this to be shorter with a dictionary or use `map` or a comprehension on name with a function that handles with a single le... | [
{
"body": "<p>This will make your example work in the same way you intended to.</p>\n\n<pre><code>patterns = []\npatterns.append(lambda x: 'A' if x.isalpha() else x)\npatterns.append(lambda x: '0' if x.isdigit() else x)\n\ndef get_pattern(name):\n for pattern in patterns:\n name = map(pattern, name)\n... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T21:31:20.840",
"Id": "32610",
"Score": "1",
"Tags": [
"python",
"validation"
],
"Title": "Verifying patterns of various filenames"
} | 32610 |
<p>I'm building a game. It is going well at the moment, but I'm not quite happy with my code because is not working the way I want to, due my low knowledge of C#. I was wondering if you guys could help me out to improve it by giving me some ideas and tips.</p>
<p>This is how I'm checking if the user has completed th... | [] | [
{
"body": "<ol>\n<li><p>In your <code>ReadStar1</code> method I assume your forgot the brackets around the <code>if (readtxt == \"star1\")</code> block? Right now you always collapse visibility of <code>star1_1</code>.</p></li>\n<li><p>Your <code>ReadStar1</code> and <code>ReadStar2</code> methods share lot of ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T22:31:44.353",
"Id": "32612",
"Score": "0",
"Tags": [
"c#",
"game"
],
"Title": "How to improve my game?"
} | 32612 |
<p>Recently I decided VB6's <code>Collection</code> wasn't enough for my needs, so I decided to implement something like C#'s <code>List<T></code>. Here's the class that resulted, I'd like to know if the implementation could be made better /more efficient, especially with <code>Insert</code> and <code>Sort</code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T18:02:19.333",
"Id": "52600",
"Score": "0",
"body": "I think `Add()` should take a `ParamArray` and call `AddArray()`, so `AddValues()` could be removed as redundant, just like `Remove()` does. ...And I'm probably missing a `RemoveA... | [
{
"body": "\n\n<pre class=\"lang-vb prettyprint-override\"><code>Public Function ToString() As String\n'Returns a string that represents the current List object.\n\n ToString = StringFormat(\"{0}<{1}>\", TypeName(Me), _\n Coalesce(this.ItemTypeName, \"Variant\"))\... | {
"AcceptedAnswerId": "32907",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T01:22:58.897",
"Id": "32618",
"Score": "49",
"Tags": [
"collections",
"vba",
"type-safety",
"vb6"
],
"Title": "List<T> implementation for VB6/VBA"
} | 32618 |
<p>I was able to complete the problem, but I would like to improve my code and make it more idiomatic. </p>
<p>Here is the challenge description:</p>
<blockquote>
<p>Problem 7 - 10001st prime</p>
<p>By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th >prime is 13.
What is ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T19:46:35.630",
"Id": "52673",
"Score": "0",
"body": "This [question on Stack Overflow](http://stackoverflow.com/questions/4629734/the-sieve-of-eratosthenes-in-f) is a great reference on implementing this."
}
] | [
{
"body": "<blockquote>\n <p>One of the major problem I would like to address is performance.</p>\n</blockquote>\n\n<p>When thinking about performance, the first question you should ask yourself is: could I use a better algorithm? Turns out there <em>are</em> better <a href=\"https://en.wikipedia.org/wiki/Gene... | {
"AcceptedAnswerId": "32633",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T01:45:15.927",
"Id": "32619",
"Score": "2",
"Tags": [
"project-euler",
"primes",
"f#"
],
"Title": "Project Euler Problem 7: Find 10001st prime number"
} | 32619 |
<p>I am working through some of the exercises at Coberbyte. The instructions for this exercise are to replace every letter in a string with the letter following it in the alphabet (i.e., c becomes d, z becomes a), then capitalize every vowel in this new string (a, e, i, o, u) and finally return this modified string.</p... | [] | [
{
"body": "<ol>\n<li><p>No, not really. There are other ways, but nothing that is simpler or faster.</p></li>\n<li><p>Yes, you can handle the <code>z</code>, the space and the vowels as one case, and the other characters by adding the character code:</p>\n\n<pre><code>for (var i = 0; i<txt.length; i++){\n ... | {
"AcceptedAnswerId": "32625",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T01:59:12.223",
"Id": "32620",
"Score": "6",
"Tags": [
"javascript",
"programming-challenge",
"caesar-cipher"
],
"Title": "Replacing every letter in a string with the letter fol... | 32620 |
<p>Okay code reviewers, I need you to make my <code>FizzBuzz</code> code even better. Any suggestions for improvement, optimizations, etc.</p>
<pre><code>public final class FizzBuzz {
private FizzBuzz() {};
/**
* comparisons for a multiple of 3 = 2
* comparisons for a multiple of 5 = 2
* compa... | [] | [
{
"body": "<p>In both versions, your policy on printing newlines is inconsistent. With <code>fizzBuzzBetter()</code>, all of your cases are mutually exclusive, so they should all be <code>System.out.println(...)</code> calls, and there is no need to prepend <code>\"\\n\"</code>.</p>\n\n<p>Your <code>fizzBuzzBa... | {
"AcceptedAnswerId": "32634",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T07:52:35.703",
"Id": "32627",
"Score": "3",
"Tags": [
"java",
"fizzbuzz"
],
"Title": "Code review request for fizz buzz"
} | 32627 |
<p>The following is the current iteration of a gaussian blur approximation code I am using.</p>
<p>A typical naive convolution operation is <code>O(N*M)</code>, where N is the number of image pixels, and M is the number of kernel pixels.</p>
<p>I am using three tricks to avoid this penalty:</p>
<ol>
<li>3 iterations... | [] | [
{
"body": "<p>Gaussian blurs can also be split into a horizontal and vertical pass without loss of precision. It's actually one of the characteristics which makes them so popular. You may find that using several box-blur passes in each direction is actually slower than a single gaussian-blur pass in each direct... | {
"AcceptedAnswerId": "32636",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T09:42:24.053",
"Id": "32630",
"Score": "1",
"Tags": [
"c++",
"sse",
"image"
],
"Title": "SSE Intrinsics Gaussian Blur Approximation"
} | 32630 |
<p>I have an object like this</p>
<pre><code>initialize : {
method : function() {
this.__. //--> do another thing
... //--> so many
this.__.params. //--> do another thing
... //--> so many
}
}
</code></pre>
<p>and the method of this object call by anoth... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T11:58:06.187",
"Id": "52193",
"Score": "1",
"body": "If I understand correctly, you have another object which is calling `method` as if it were its own method (and therefore `this` references the other object). I'm assuming that sin... | [
{
"body": "<p>Not much to review ;)</p>\n\n<ul>\n<li>As @Dave mentioned, <code>__</code> is a bit of an odd named, for sure it does not give away what it does</li>\n<li>You might consider storing <code>__.params</code> separately in <code>this.parameters</code> or <code>this.options</code></li>\n</ul>\n\n<p>I w... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T11:47:45.297",
"Id": "32637",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Define local variable in function?"
} | 32637 |
<p>I am thinking about how to split my website into smaller reusable apps. I've finally figured out something and need your opinion. </p>
<p>My main problem was that each app uses <code>Profile</code> model. This is of course a snippet of my work with the most important parts.</p>
<pre><code># App Userdata
class Ba... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T01:00:02.747",
"Id": "52218",
"Score": "0",
"body": "Why don't you just use BaseProfile? None of your other classes seem to add anything."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T02:02:45.633",... | [
{
"body": "<p>It depends really on how you will use those models.\nFor example if you always, always get question object then find the answers that belong to it. there is no point adding profile relation with answers models and keep it to questions only.</p>\n\n<p>If in rare cases (not in loops) you might deal ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T13:33:40.063",
"Id": "32641",
"Score": "1",
"Tags": [
"python",
"django"
],
"Title": "Split Django into apps"
} | 32641 |
<p>I have a project in school. This is the game that I've created, but I need to make some improvements. I put a <code>swing.timer</code> inside the action event to create a score/time decrements effects. But, I have a problem because there is a textfield inside the frame and I can't type any words there because of t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T13:46:27.513",
"Id": "52201",
"Score": "0",
"body": "Hi Jave-Newbie! This site is dedicated to providing reviews and improvements to code which already works. If you need help finding errors/fixing code, head to [StackOverflow](http... | [
{
"body": "<p>I'm not going to go through all of this code since it's like 800 lines and would take me all day, but I can give you some good general tips just by glancing at it.</p>\n\n<ul>\n<li>Choose better variable names. Things like <code>next07</code>, <code>next08</code>, [...], and <code>p80</code>, <co... | {
"AcceptedAnswerId": "32645",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T13:37:50.613",
"Id": "32642",
"Score": "2",
"Tags": [
"java",
"swing"
],
"Title": "Improving my \"Guess Who?\" game"
} | 32642 |
<p>I need to build a football team. Every player has his performance described by an integer. The greater the number, the more effective the player is. Every team should be solid. If one of the players plays much better than all others, then other team members will dislike him, and the team will not be solid. Thus, the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T07:51:52.653",
"Id": "52246",
"Score": "0",
"body": "Is `randomPartition()` only used for returning an `int`, or is the modified vector used after the call? If the latter, then you *may* benefit from passing `input` by `const&` and... | [
{
"body": "<p>Just some design things:</p>\n\n<ul>\n<li><p>You're using C libraries:</p>\n\n<pre><code>#include <stdlib.h> // should be <cstdlib>\n#include <time.h> // should be <ctime>\n</code></pre></li>\n<li><p>I'd recommend defining <code>Team</code>'s <code>public</code> members o... | {
"AcceptedAnswerId": "32659",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T15:44:25.033",
"Id": "32644",
"Score": "2",
"Tags": [
"c++",
"optimization",
"algorithm"
],
"Title": "Optimize the algorithm for choosing a football team"
} | 32644 |
<p>I created a function that compares an array of letters to the alphabet, and returns the letters that are <em>not</em> in the original array.</p>
<p>While this works, it looks somewhat clumsy to me, but I don't know what I'm looking for to improve the code...Is there a way to make it more elegant? Perhaps getting ri... | [] | [
{
"body": "<p>You're mixing up two different ways of doing this. The old-fashioned way involves looping through the alphabet and pushing the letters not present into an array:</p>\n\n<pre><code>function getLettersNotInContent2(letters) {\n var alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'... | {
"AcceptedAnswerId": "32654",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T20:58:16.557",
"Id": "32653",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Improving a JavaScript filtering function"
} | 32653 |
<p>This is my attempt at creating a database schema for a Minecraft logging plugin. I'm by no means a SQL expert, so suggestions would be greatly appreciated.</p>
<pre><code>--
-- Table structure for table `actions`
--
DROP TABLE IF EXISTS `actions`;
CREATE TABLE IF NOT EXISTS `actions` (
`id` tinyint(3) unsigned N... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T06:20:22.847",
"Id": "52243",
"Score": "0",
"body": "The `AUTO_INCREMENT=33` in the actors table seems odd."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T13:26:16.920",
"Id": "52262",
"Score... | [
{
"body": "<p>Your Table Declarations are a little redundant with the <code>DROP TABLE</code> if it exists and then <code>CREATE TABLE</code> if it doesn't exist.</p>\n\n<p>The SQL Engine is going to do an extra search to see if the table exists when we already know that if it existed it was dropped.</p>\n\n<pr... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T22:08:48.340",
"Id": "32655",
"Score": "3",
"Tags": [
"sql",
"mysql",
"minecraft"
],
"Title": "Database schema for a Minecraft logging plugin"
} | 32655 |
<p>Here is the code I wrote for my mother's dental office. It fulfills these tasks:</p>
<ul>
<li>determines whether a tooth is anterior or posterior</li>
<li>determines if the patient needs a filling</li>
<li>sets up a later appointment</li>
</ul>
<p>My issue is with cleaning the code to increase readability, becaus... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T21:09:46.977",
"Id": "52219",
"Score": "0",
"body": "Use functions or maybe a `switch` statement."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T21:10:05.573",
"Id": "52220",
"Score": "7",
... | [
{
"body": "<p>Just for starters, the tooth number determines whether it is posterior or anterior. Put that into a function that could use a <code>std::map<int, bool></code>. In the function, validate that the input is greater than 0 and less than 33. Or, look it up in the map and make sure you found it. I... | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T21:08:46.063",
"Id": "32656",
"Score": "3",
"Tags": [
"c++",
"beginner"
],
"Title": "Dental office program"
} | 32656 |
<p>I am working on some code which checks whether or not to unlink a file on the basis of the class:</p>
<pre><code>File.unlink(file.path) if file.is_a? File
</code></pre>
<p>I think it would be more idiomatic to check whether the object responds to the <code>unlink</code> message:</p>
<pre><code>File.unlink(file.pa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T03:00:16.743",
"Id": "52235",
"Score": "0",
"body": "I love my static type checker."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-22T07:25:05.567",
"Id": "52879",
"Score": "0",
"body": "can... | [
{
"body": "<p>Given that on some file systems a directory is simply a File with special attributes (or to put it another way a <em>specialized file</em>), does it really matter? Unlink it if it can be unlinked if that is what you want to do. If it can't be unlinked, why would you bother? And why would you ca... | {
"AcceptedAnswerId": "32663",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T02:32:20.470",
"Id": "32662",
"Score": "4",
"Tags": [
"ruby"
],
"Title": "is_a? vs respond_to?"
} | 32662 |
<p>I have an optimization issue and I'm not sure if I can improve the overall speed of my function.</p>
<p>The function <code>draw_w</code> is my actual implementation that gives me the right update for my vector <code>w</code>. You can see that the code is running for 1000 iterations in 9s.
I had a first implementati... | [] | [
{
"body": "<p>At least with your test <code>X</code>, <code>draw_x_fw</code> works with 2 calls. The rows of <code>X</code> fall into two groups, each with a unique set of columns. I don't know if that's a structural part of the problem, or just a random characteristic your chosen test.</p>\n\n<pre><code> ... | {
"AcceptedAnswerId": "33709",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T04:18:57.017",
"Id": "32664",
"Score": "1",
"Tags": [
"python",
"optimization",
"numpy"
],
"Title": "NumPy Scipy optimization"
} | 32664 |
<p>A friend of mine needs a scraper that reads product titles, prices and pictures from eBay and saves them to an Excel-ready .csv file. The program reads product pages into a list and then loops through it to get the relevant data, which it then saves to a .csv file.</p>
<pre><code>import pdb
import time
import urlli... | [] | [
{
"body": "<h2>First things first</h2>\n\n<p>When your scripts start to grow unruly like this it is usually a good idea to try and break them down into their component parts and compartmentalize functionality. I'm going to go through just a couple parts of your script with a few ideas that might help to 'modula... | {
"AcceptedAnswerId": "32853",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T07:09:11.863",
"Id": "32667",
"Score": "6",
"Tags": [
"python",
"beginner",
"web-scraping",
"beautifulsoup",
"ebay"
],
"Title": "eBay scraper with BeautifulSoup"
} | 32667 |
<p><strong>Background:</strong></p>
<p>I was working on a project were I needed to write some rules for text-processing. After working on this project for a couple of days and implementing some rules, I realized I needed to determine the order of the rules. No problem; we have topological sorting to help. But then I r... | [] | [
{
"body": "<p>This code is not ready for review, as it's not working—it visits some rules more than once. If you need help writing a <a href=\"http://en.wikipedia.org/wiki/Topological_sort\" rel=\"nofollow\">topological sort algorithm</a>, Stack Overflow is the right place, not Code Review.</p>\n\n<p>But I'll m... | {
"AcceptedAnswerId": "32672",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T08:18:10.203",
"Id": "32668",
"Score": "1",
"Tags": [
"python",
"generator",
"graph",
"depth-first-search"
],
"Title": "DFS algorithm with generators"
} | 32668 |
<p>The code below just senses when the network is available and enables/disables a button on the UI. If I am registered to the <code>NetworkAvailability</code> event for the life of the program, will it cause a memory leak? I heard it might but didn't understand why.</p>
<pre><code>System.Net.NetworkInformation.Networ... | [] | [
{
"body": "<p>Well, if it's for the life of the program as you say, then no. When the program ends, all memory will be released.</p>\n\n<p>Second, this all looks like one class. So root references will be removed when the class is GC'd and no memory leak will occur.</p>\n\n<p>Lastly, write</p>\n\n<pre><code> ... | {
"AcceptedAnswerId": "32671",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T11:50:49.660",
"Id": "32670",
"Score": "2",
"Tags": [
"c#",
"memory-management",
"event-handling"
],
"Title": "Sensing when a network is available"
} | 32670 |
<p>I wrote the method below, and was wondering whether a better way exists/best practice tips</p>
<pre><code>_objectIsDefined = function (obj, path) {
if (typeof path !== 'undefined') {
// if we have been given a specific object path then recursively search it
var pathSplit = path.split("."),
scope = u... | [] | [
{
"body": "<p>First of all, what you are doing is not recursive (self-calling). It's iterative (looping).</p>\n\n<p>And here's a shorter version of it:</p>\n\n<pre><code>_objectIsDefined = function (obj, path) {\n\n if (!obj) return false; // no object, return false\n if (obj && !path) retur... | {
"AcceptedAnswerId": "32675",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T13:29:58.860",
"Id": "32674",
"Score": "0",
"Tags": [
"javascript",
"recursion"
],
"Title": "Javascript recursive object is defined test"
} | 32674 |
<p>I've already reduced it and have tried making the main code <code>is_divisible=</code>, followed directly by the <code>(2...).each...</code> code, but that didn't work.</p>
<p>Any suggestions on reducing the size of this code? I have tests for other methods that use the code (so I know if changes are working) but n... | [] | [
{
"body": "<pre><code> def self.divisible?(n)\n is_divisible= false\n (2...n).each do |divisor|\n division=n/divisor\n if n== divisor*division\n is_divisible= true\n end \n end \n is_divisible\n end \n</code></pre>\n\n<p>since you're returning a flag just after computing it, ... | {
"AcceptedAnswerId": "32680",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T16:54:30.240",
"Id": "32676",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Determining if a number is divisible"
} | 32676 |
<p>After trying a couple of parsers, such as <a href="http://www.microsoft.com/en-us/download/details.aspx?id=24659" rel="nofollow">Log Parser 2.2</a>, I ended up writing a small utility that supposedly parses the following information onto an object:</p>
<p>(from DirectX Caps Viewer, truncated)</p>
<pre><code>Direct... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T17:02:17.817",
"Id": "52271",
"Score": "1",
"body": "Yes, this question is on-topic."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T21:57:03.467",
"Id": "52332",
"Score": "0",
"body": "Wh... | [
{
"body": "<p>Your usage of whitespaces in regex patterns threw me off, I think they should be captured with <code>\\s</code>.</p>\n\n<p>Also your object model doesn't seem to reflect the file's format. I see this:</p>\n\n<ul>\n<li><p><code>GraphicAdapter</code></p>\n\n<ul>\n<li><code>.Driver</code> (=\"aticfx3... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T16:57:53.400",
"Id": "32677",
"Score": "2",
"Tags": [
"c#",
"parsing"
],
"Title": "Parsing a text file containing device information"
} | 32677 |
<p>I'm making a very basic user system, and this is what I have so far:</p>
<pre><code><?php
/* The class for constructing any user's information
*/
class User {
protected $userId, $email, $userGroup;
protected function getEmail() {
return $this->email;
}
pr... | [] | [
{
"body": "<p>I didn't change much.\nI think you're correct in having getters as well as methods such as 'canViewPage'.\nThe Methods 'canViewPage' and 'hasPermissions' are just wrappers around the 'UserGroup' class, the logic is in 'UserGroup'. It makes sense to create wrappers around 'UserGroup', for example i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T17:32:28.287",
"Id": "32681",
"Score": "2",
"Tags": [
"php",
"classes",
"pdo"
],
"Title": "User system using PDO"
} | 32681 |
<p>I am working on an online ordering form and am looking for some advice about my jQuery. I am re-developing the code base for this ordering form and improving what was created by a web design group years ago. The existing form uses Javascript to dynamically generate a new line of item information when the starts ty... | [] | [
{
"body": "<p>You could always clean it up using jQuery tmpl</p>\n\n<p><a href=\"https://github.com/BorisMoore/jquery-tmpl\" rel=\"nofollow\">https://github.com/BorisMoore/jquery-tmpl</a></p>\n\n<p>You would just define the HTML of the templates, and then you could add them to the rows.</p>\n",
"comments": ... | {
"AcceptedAnswerId": "32683",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T17:36:57.640",
"Id": "32682",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"html",
"dom"
],
"Title": "Creating chunks of HTML with jQuery"
} | 32682 |
<p>How can I shorten this class method (currently 10 lines long)?</p>
<pre><code>class DoubleSeries
def self.generate_sequences(seq1_start, seq2_start, seq1_step, seq2_step, iterations)
seq1,seq2=seq1_start,seq2_start
result=[]
(1..iterations).each do
result << seq1 << seq2
seq1+=... | [] | [
{
"body": "<p>You could a number of different things. For instance, using ranges and a couple of Array methods, I get this:</p>\n\n<pre><code>class DoubleSeries\n def self.generate_sequences(seq1_start, seq2_start, seq1_step, seq2_step, iterations)\n seq1_end = seq1_start + iterations * seq1_step\n seq2_... | {
"AcceptedAnswerId": "32702",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T18:18:40.153",
"Id": "32684",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Double series sequences"
} | 32684 |
<p>I have two functions to find the number of factors of a given number.
I was wondering which one will be more efficient to use?</p>
<pre><code>def nu_of_factors2(n):
return len(set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
</code></pre>
<hr>
<pre><co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T19:44:34.523",
"Id": "52283",
"Score": "0",
"body": "Benchmark? Likely the latter will give better performance, if you change add to a variable increment and put in a special case for square numbers."
},
{
"ContentLicense": ... | [
{
"body": "<p>Both algorithms appear to be <code>O(sqrt(n))</code>, so there isn't anything to choose between them in terms of algorithmic complexity. The only significant difference I see is between a one-off conversion from list to set and a series of calls to <code>add()</code>. I would guess that the former... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T19:33:52.173",
"Id": "32686",
"Score": "2",
"Tags": [
"python",
"optimization",
"algorithm"
],
"Title": "\"Finding number of factors\" efficiency"
} | 32686 |
<p>This code is for a program that needs to add thousands of strings to memory while it's running and these strings will be used until the end of execution. So the memory for these strings will be freed only in the end.</p>
<p>First I tested calling <code>malloc</code> for every new string and have used Valgrind to be... | [] | [
{
"body": "<ol>\n<li><p>I know it's kind of standard to do this in C land but you should spell things like this <code>if((result = malloc(default_sizes[i])))</code> out as:</p>\n\n<pre><code>result = malloc(default_sizes[i]);\nif (result != NULL)\n{\n}\n</code></pre>\n\n<p>Yes it's one line of code more but the... | {
"AcceptedAnswerId": "32704",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T21:50:28.200",
"Id": "32689",
"Score": "4",
"Tags": [
"c",
"memory-management"
],
"Title": "Memory management for small allocations"
} | 32689 |
<p>I've recently just started with AngularJS and the best way for me to learn is to get some criticism to find out how I can do things better. I did a small project that calls a third party API and shows a bit of the return data.</p>
<p><strong>HTML</strong></p>
<pre><code> <body ng-controller="Album">
<... | [] | [
{
"body": "<p>Some pointers:</p>\n\n<ul>\n<li><p>Move <code>$http.get</code> out of the controller to a <a href=\"http://docs.angularjs.org/guide/dev_guide.services.creating_services\" rel=\"nofollow\">service</a>. Stuff that is not presentation logic should not be in your controller.</p></li>\n<li><p><code>get... | {
"AcceptedAnswerId": "32691",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T23:27:25.973",
"Id": "32690",
"Score": "3",
"Tags": [
"javascript",
"html",
"angular.js"
],
"Title": "Retrieving album artist info from third party API"
} | 32690 |
<p>Regarding re-usability, is this OK? What might go wrong? What would be a better design? Performance-related issues and any other comments are welcome.</p>
<pre><code>package sample.library.dao.util;
import java.io.Serializable;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowire... | [] | [
{
"body": "<p>What about having generic abstract dao class which will contain these methods? You will most likely have to create some concrete dao classes anyway to have specific methods. \nWe are using this approach in our projects (behind JPA facade)</p>\n\n<pre><code>public abstract class AbstractJpaDao<T... | {
"AcceptedAnswerId": "32697",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T02:04:38.237",
"Id": "32693",
"Score": "2",
"Tags": [
"java",
"generics",
"hibernate"
],
"Title": "Using generic methods for basic crud operations"
} | 32693 |
<p>I wrote this looping Caesar cipher with a default key. I'd love for some input on how I could make this operate better/more effectively.</p>
<pre><code>#Et Tu, Brute? [Caesar's Cipher]
#loops?
#Determine type of cipher...
doLoop=("y")
while doLoop==("y"):
#yep. loops.
det=input("Enter N for number or C for ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T23:58:42.383",
"Id": "52291",
"Score": "0",
"body": "what's wrong with it now?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T00:01:07.543",
"Id": "52292",
"Score": "3",
"body": "But I ca... | [
{
"body": "<p>Python strings have a <a href=\"http://docs.python.org/3/library/stdtypes.html#str.translate\" rel=\"nofollow\"><code>translate</code></a> method that applies a substitution cipher. There is also a function <a href=\"http://docs.python.org/3/library/stdtypes.html#str.maketrans\" rel=\"nofollow\"><... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-14T23:53:10.253",
"Id": "32694",
"Score": "7",
"Tags": [
"python",
"caesar-cipher"
],
"Title": "Caesar cipher in Python"
} | 32694 |
<p>I saw a tutorial from a site where it showed the use of <code>ArrayBlockingQueue</code> as a thread-safe concurrent data-structure . Just for learning purposes , i tried to build something similar using synchronized and wait-notify methods in java. I'm really very new to <code>java.util.concurrent</code> and i'm hop... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T18:41:46.560",
"Id": "52324",
"Score": "0",
"body": "For learning purposes, read more code written by qualified programmers. Sources of main java libraries, including ArrayBlockingQueue, are available. But very often that code is ov... | [
{
"body": "<p>This line is unsafe:</p>\n\n<p><code>int loc = r.nextInt(list.size());</code></p>\n\n<p>an error is raised if <code>list.size()</code> is <code>0</code>.</p>\n\n<p>Your code implements some very strange producer consumer behaviour, especially the random value at the consumer without any waiting ti... | {
"AcceptedAnswerId": "32724",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T12:04:03.170",
"Id": "32709",
"Score": "1",
"Tags": [
"java",
"multithreading",
"concurrency"
],
"Title": "Producer-Consumer using low level synchronization"
} | 32709 |
<p>Here is a slightly modified challenge from Coderbyte:</p>
<p>Determine if a given string is an acceptable. The str parameter will be composed of + and = symbols with several letters between them (ie. ++d+===+c++==a) and for the string to be true each letter must be surrounded by a + symbol. So the string to the lef... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T23:54:17.963",
"Id": "52337",
"Score": "0",
"body": "The problem statement is not precise. \"Each letter must be surrounded by a `+` symbol\" — does that mean _immediately_ surrounded, or would `+ab+` be acceptable? Is it acceptable... | [
{
"body": "<p>Your version is actually not that bad but could be simplified slightly and wrapped in a function. You could use <code>charAt</code> to get the character from a string instead of splitting the string. You don't need the initial check on the first and last characters; you can just do these as part o... | {
"AcceptedAnswerId": "32716",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T13:59:40.447",
"Id": "32712",
"Score": "1",
"Tags": [
"javascript",
"regex",
"programming-challenge"
],
"Title": "Trying to improve my javascript code in this simple challenge ... | 32712 |
<p>I'm whitelisting the input data to an LDAP/AD search on 'sn' (=surname). The purpose is to stop penetration attacks through the app and into the LDAP servers (i.e. no brackets, please).</p>
<pre><code>// whitelist input data.
string partialName = Regex.Replace(partialName, "[^. a-zA-Z-']", string.Empty);
</code></p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-08T18:37:12.227",
"Id": "54744",
"Score": "0",
"body": "You should be able to use asterisks as long as you encode them when issuing the request. See [allowing asterisk in URL](http://stackoverflow.com/a/5994766/1148384) and [HttpServe... | [
{
"body": "<p>Don't ever make assumptions of what to allow or disallow based on what you have seen in your experience. Always consult the specification, which is, in this case, <a href=\"https://www.rfc-editor.org/rfc/rfc4515#section-3\" rel=\"nofollow noreferrer\">RFC 4515 Sec 3</a>. The spec will tell you w... | {
"AcceptedAnswerId": "32729",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T15:16:26.763",
"Id": "32714",
"Score": "1",
"Tags": [
"c#",
"lookup",
"ldap"
],
"Title": "Whitelist input data for a lookup by name"
} | 32714 |
<p>I'm trying to get better at Python and would like a critique.</p>
<p>Problem statement:</p>
<blockquote>
<p>Accept a 2D grid containing 1's and 0's (1 being mine locations) and
print a <em>solved sum</em> grid (the way the final grid would show upon
completion of a minesweeper game with all the neighbor sums... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T17:19:56.007",
"Id": "52315",
"Score": "1",
"body": "take a look at numpy and strides"
}
] | [
{
"body": "<p>One idea ... in your getSummedMap function, you could put all the +1, -1, 0's in a list of 2-tuples and get the Sum with one for loop, e.g. ...</p>\n\n<pre><code>neighbor_incs = [(-1, 0), (1, 0), (0, 1), (0, -1), # Top + Bottom + Left + right\n (-1, -1), (1, -1), (1, 1), (-1, 1), ... | {
"AcceptedAnswerId": "32815",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T15:17:20.220",
"Id": "32715",
"Score": "5",
"Tags": [
"python",
"minesweeper"
],
"Title": "Minesweeper grid representation + calculating neighbor-sums"
} | 32715 |
<p>I have a data frame called <code>data</code> with lots of columns, and <code>Country</code> is one of them.</p>
<p>I created a new logical column called <code>train</code>, which is true when the row belongs to the train set and false otherwise. The data frame is already sampled.</p>
<p>Now I want to be sure that... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-11T17:15:37.910",
"Id": "56954",
"Score": "1",
"body": "As `data` is also the name of a function in the core `utils` package, it is not good practice to use it for the name of an object."
}
] | [
{
"body": "<p>I would do:</p>\n\n<pre><code>with(data, length(intersect(Country[train], Country[!train])) == 0)\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T00:30:21.923",
"Id": "32732",
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T16:48:02.697",
"Id": "32717",
"Score": "3",
"Tags": [
"r"
],
"Title": "Check column values are in different sets"
} | 32717 |
<p>I'm using bootstrap 3.0 to display a tooltip (this example isn't specific to boot-strap) where the html inside the tooltip is fed from an AJAX call. In the future I want to be able to use the same element to fire different AJAX calls (something like fire a different AJAX call if the shift+click was used). To make ... | [] | [
{
"body": "<p>Your <code>setPlacement</code> method returns the \"correct\" data because whatever <code>d</code> is in your data object you receive from <code>Service.asmx/GetDrugs</code> is compared to be greater than 4. If it is then it will set the tooltip placement of the <code>$('#click')</code> element to... | {
"AcceptedAnswerId": "32927",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T19:22:18.790",
"Id": "32723",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Using objects to make state with AJAX functions as properties"
} | 32723 |
<p>Here is another challenge from Coderbyte. I found this one challenging, although not quite as much as the previous two I've posted. Based on the feedback I received on my earlier posts, I structured this solution as a function. It is probably better than my previous solutions but still could be improved.</p>
<p>In ... | [] | [
{
"body": "<p>I would recommend using a <a href=\"http://en.wikipedia.org/wiki/Regular_expression\" rel=\"nofollow\">regular expression</a>. Regex is designed for solving pattern matching and string manipulation problems. Although it can look esoteric and terse it is well worth the effort to learn since it is ... | {
"AcceptedAnswerId": "32781",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T01:38:27.230",
"Id": "32735",
"Score": "3",
"Tags": [
"javascript",
"strings",
"programming-challenge"
],
"Title": "Testing distance between characters in a string"
} | 32735 |
<p>This is a class/method that manages files being written to and read from. I have a lot of code, and it grew as I tried to get it to work properly. Is there a better way to write this (i.e. trim the fat) or is it written properly?</p>
<pre><code>import java.io.*;
public class DataBase {
public static String getExte... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T20:34:31.673",
"Id": "52416",
"Score": "0",
"body": "Utility classes tend to be an anti-pattern. http://c2.com/cgi/wiki?AntiPattern"
}
] | [
{
"body": "<p>First of all name your variables properly. Name of the variable should describe what it is, but <code>f</code> is just a random letter not a name for variable.</p>\n\n<p>Consider using logger instead of printing to sout.</p>\n\n<p>Stream closing should go to the <a href=\"http://docs.oracle.com/ja... | {
"AcceptedAnswerId": "32744",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T01:47:03.247",
"Id": "32736",
"Score": "3",
"Tags": [
"java",
"io"
],
"Title": "Is this file I/O utility efficient or is there a lot of fat?"
} | 32736 |
<p>I've been writing classic ASP.NET web services for a while now, and this is my first time writing a PHP based web service. I'm rather new to PHP as well.</p>
<p>In ASP.NET, you directly call the web method that you wish to be executed, but I'm not sure if PHP has a similar functionality. </p>
<p>Instead I'm callin... | [] | [
{
"body": "<p>First I would like to say, congratulations on stepping out of the Microsoft bubble!</p>\n\n<p>To begin, most PHP functions are very similar (if not exactly the same) to their linux counterparts. Some of them even just directly call their linux counterparts and return the result. You don't have to... | {
"AcceptedAnswerId": "32771",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T04:09:40.543",
"Id": "32738",
"Score": "1",
"Tags": [
"javascript",
"php",
"jquery",
"ajax",
"web-services"
],
"Title": "PHP \"web service\" and jQuery ajax"
} | 32738 |
<p>I'm working on a code where it converts shoe sizes and distance.</p>
<p>I require help making it "nicer" because I feel like it is a little messy. I was thinking about maybe making an enum to hold the distances and then using that enum to figure out how to convert it, but I'm looking for someone to just look at my ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-04-26T18:25:45.770",
"Id": "159345",
"Score": "0",
"body": "The code is broken because of all the fall-throughs in `convertDistance`."
}
] | [
{
"body": "<p>I would separate calculations of shoe sizes and distances into separate classes. It is called <a href=\"http://en.wikipedia.org/wiki/Single_responsibility_principle\" rel=\"nofollow\">SRP</a></p>\n\n<p>Name your variables properly <code>String g</code> is just a random letter not a name for a vari... | {
"AcceptedAnswerId": "32877",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T04:39:09.703",
"Id": "32740",
"Score": "0",
"Tags": [
"java",
"android",
"converting"
],
"Title": "Converting shoe sizes and distance"
} | 32740 |
<p>The question is probably quite simple, but I would like to hear what drawbacks we will have with our code.</p>
<p>So, we had a simple implementation and interface for it:</p>
<pre><code>public interface ISettings
{
bool IsOnline { get; set; }
}
public class Settings : ISettings
{
public bool IsOnline { ge... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T13:05:21.007",
"Id": "52361",
"Score": "34",
"body": "It is sheer waste of effort maintaining two properties and invitation to future bugs when you forget to set either of the properties in tandem."
},
{
"ContentLicense": "C... | [
{
"body": "<p>Just a quick note: a <code>Status</code> (or <code>ConnectionStatus</code>) enum with <code>ONLINE</code> and <code>OFFLINE</code> values would be more readable here.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T14:40:05.353",
... | {
"AcceptedAnswerId": "32748",
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T07:11:56.307",
"Id": "32743",
"Score": "86",
"Tags": [
"c#",
"properties"
],
"Title": "Mutually exclusive properties"
} | 32743 |
<p>Below is the code I have written for counting perfect squares between a given lower and upper bound.</p>
<p>I am using the following concept to solve this:</p>
<blockquote>
<p>Starting with 1, there are \$\sqrt{m}\$ square numbers up to and including \$m\$.</p>
</blockquote>
<pre><code>public static int CountPe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T17:00:34.663",
"Id": "52401",
"Score": "0",
"body": "you are over thinking this one."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T17:02:02.140",
"Id": "52402",
"Score": "0",
"body": "yo... | [
{
"body": "<p>If <code>A</code> was not included in the observed range, you wouldn't need the <code>if (A == sqrtA * sqrtA)</code> part, right? So, let's use that: instead of checking the range <code>{A,A+1,...,B}</code>, check the range <code>{A-1,A,...,B}</code>. Since you're working with integers, the two ar... | {
"AcceptedAnswerId": "32755",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T10:02:05.783",
"Id": "32751",
"Score": "4",
"Tags": [
"c#",
"mathematics"
],
"Title": "Counting perfect squares"
} | 32751 |
<p>I made a method that finds synonyms to words using thesaurus.com and I'm looking for comments and feedback to it. In what ways can I improve it, both when it comes to speed, security, reliability (regardless of how "reliable" it is to rely on a third-party website for look-ups), etc.</p>
<pre><code> /// <summ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T05:18:23.063",
"Id": "52454",
"Score": "0",
"body": "I believe that HttpWebRequest gets the entire response, so a possible improvement would be to use sockets to read the data directly and then stop when finished."
}
] | [
{
"body": "<p>You're doing things the hard way. By that I mean, why build a web crawler for this? Is it a requirement that you only use thesaurus.com? There are several quality thesaurus services out there with APIs that you could utilize.</p>\n\n<p>I've never used any of them, but a quick web search and ... | {
"AcceptedAnswerId": "32770",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T12:28:05.760",
"Id": "32756",
"Score": "1",
"Tags": [
"c#",
"parsing"
],
"Title": "Parse and extract synonym data from a website"
} | 32756 |
<blockquote>
<p>Implement a coin jar in C#. The coin jar will only accept US coinage
and has a volume of 32 fluid ounces. Additionally, the jar has a
counter to keep track of the total amount of money collected and has
the ability to reset the count back to $0.00.</p>
</blockquote>
<p>I received the question a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T13:28:33.717",
"Id": "52362",
"Score": "0",
"body": "Have you already submitted this?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T14:38:25.523",
"Id": "52367",
"Score": "1",
"body": "y... | [
{
"body": "<p>Personally, I would just do away with a lot of the code. That would include most interfaces and most classes, as they don't really do anything towards solving the task at hand.</p>\n\n<p>Anyway, you have two classes that use integer storage internally, but only expose the value as a double, so the... | {
"AcceptedAnswerId": "32759",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T12:50:54.700",
"Id": "32757",
"Score": "4",
"Tags": [
"c#",
"interview-questions"
],
"Title": "Implementation of a coin jar"
} | 32757 |
<p>The question is about sorting alphanumeric string in a "more natural" order. Source: Marc LeBrun's "Sordid Sort" <a href="http://fxpt.com/wp-content/uploads/2012/01/quiz.pdf" rel="nofollow">Computist Quiz</a></p>
<blockquote>
<p>Often a system string comparison sorts alphanumeric data “unnaturally”, as with these... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T19:39:16.707",
"Id": "52373",
"Score": "5",
"body": "When did SO turn into a combination of [codereview.se] and [codegolf.se]"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T19:49:24.217",
"Id": "... | [
{
"body": "<p>You can use a <a href=\"http://en.wikipedia.org/wiki/Schwartzian_transform\" rel=\"nofollow\">Schwartzian Transform</a>:</p>\n\n<pre><code>use strict;\nuse warnings;\n\nmy @data=qw(File1 AFile10 afile10 file10 10 File11 File10 File2 File3 File3A\n File3X File4 File5 File6 File12 File8 File... | {
"AcceptedAnswerId": "32763",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-15T19:22:10.197",
"Id": "32761",
"Score": "2",
"Tags": [
"regex",
"perl",
"sorting"
],
"Title": "How do you \"sordid sort\" alphanumeric strings?"
} | 32761 |
<p>I'm working on a page where a user can create new records, but not all values are required. When creating the SqlCommand with potentially null values, I'm wondering what's the best way, from a code readability standpoint, to check if there's any valid/useful information in a given field. If there is, add that inform... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T22:08:41.013",
"Id": "52429",
"Score": "0",
"body": "From a readability standpoint, Entity Framework wins - do you *have to* do this with a SqlCommand?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T... | [
{
"body": "<p>I personally prefer your 3rd example</p>\n\n<pre><code>Object addressParam = \n String.IsNullOrEmpty(Address.Text) ?\n (Object) DBNull.Value :\n (Object) Address.Text;\n\n comm.Parameters.AddWithValue(\"@Address\", addressParam);\n</code></pre>\n\n<p>It easily reads that you are evaluatin... | {
"AcceptedAnswerId": "32766",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T15:25:45.367",
"Id": "32764",
"Score": "3",
"Tags": [
"c#",
"validation"
],
"Title": "Dealing with non-required user input"
} | 32764 |
<p>Is this implementation of binary search correct? Any special or edge cases that I missed out? Maybe it should be optimized for elements that are less than the first element of the array or greater than the last element?</p>
<pre><code>bool binarySearch (int* array, int arraySize, int element)
{
if ( arraySize =... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T15:42:08.257",
"Id": "52390",
"Score": "1",
"body": "Seeing as this is C++, I'd recommend an `std::array` or `std::vector`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T16:31:44.993",
"Id": "52... | [
{
"body": "<p>I believe it works correctly, but I'm not enthused about the style.</p>\n\n<p>A few points in no particular order:</p>\n\n<p>Array indices should be <code>size_t</code> rather than <code>int</code>.</p>\n\n<p>I really dislike loops of the form:</p>\n\n<pre><code>while (true) {\n if (something) ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T15:36:11.070",
"Id": "32765",
"Score": "6",
"Tags": [
"c++",
"c",
"search",
"binary-search"
],
"Title": "Is this implementation of binary search correct?"
} | 32765 |
<p>Does this code create sufficiently hard-to-guess session tokens, assuming the server and client are communicating over HTTPS?</p>
<p><strong>Take 2</strong> <em>(thanks to <a href="https://crypto.stackexchange.com/a/11098/1674">this crypto.SE answer</a>)</em>:</p>
<pre><code>(ql:quickload (list :ironclad :cl-base6... | [] | [
{
"body": "<p>Your question doesn't give enough information about exactly what you want to do to know if this might work in your case. The most important answer is simple though: \"don't do that; use a web framework instead\". Session management should almost always be done in the standard way of your framew... | {
"AcceptedAnswerId": "51688",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T16:10:55.997",
"Id": "32769",
"Score": "10",
"Tags": [
"security",
"common-lisp"
],
"Title": "Generating hard to guess session tokens"
} | 32769 |
<p><strong>Abstract</strong></p>
<p>I have little C/C++ skills. I've learned programming mainly with Java, and so I chose C++ (targeting C++11) as the language to learn better. In my current C++ project, I have to use the <a href="http://www.pell.portland.or.us/~orc/Code/discount/" rel="nofollow noreferrer">discount<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T15:26:47.887",
"Id": "52471",
"Score": "0",
"body": "One `const` could save you a lot of head-ache. In the function `MMIOT *mkd_string(char *string, int size, int flags);` is `char *string` modified/changed in this function at all?"... | [
{
"body": "<ol>\n<li>If <code>mkd_string</code> accepts a <code>const char*</code>, then you are better off using a <code>std::string</code> and its method <code>c_str()</code> to pass the value to the function. Otherwise your solution is correct.</li>\n<li><p>Yes. See this <a href=\"https://stackoverflow.com/q... | {
"AcceptedAnswerId": "32810",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T18:51:00.983",
"Id": "32776",
"Score": "8",
"Tags": [
"c++",
"c",
"c++11",
"library"
],
"Title": "Usage of a C library in a C++ project (std::string char array conversion)"... | 32776 |
<p>I have a <code>List</code>, and I have to delete one item from the list when I find it. I am using the code below to do that:</p>
<pre><code>Iterator<MyClass> iter = flist.iterator();
while (iter.hasNext()) {
Long deletedFiId = iter.next().getId();
if (deletedFiId.equals(fiId)) {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T20:20:07.127",
"Id": "52414",
"Score": "1",
"body": "Calling `iter.next()` on an `Iterator<Object>` should return an `Object`. How do you call `.getId()` on an `Object`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>The two methods are functionally identical.\nThe first method is faster to execute.\nThe first method is clearer for someone who doesn't know the code.</p>\n\n<p>Unless there's an \"else\" you need (that is, logic to execute if the item can't be found), I can't think of a reason to prefer the seco... | {
"AcceptedAnswerId": "32778",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T19:06:06.163",
"Id": "32777",
"Score": "3",
"Tags": [
"java",
"iterator"
],
"Title": "Remove item from a list, which (of the 2) methods is better?"
} | 32777 |
<p>This is an assignment that I have already turned in. It works great, but I was wondering if there are any flaws in the code, or how to write it in a more pythonic way.</p>
<pre><code>import random
tie = 0
pcWon = 0
playerWon = 0
# Displays program information, starts main play loop, after main loop is executed (us... | [] | [
{
"body": "<pre><code>def playerMenu():\n print('Select a choice: \\n\\n\\t [1]: Rock \\n\\t [2]: Paper \\n\\t [3]: Scissors \\n\\t [4]: Quit\\n')\n menuSelect = input('Enter menu selection: ')\n while menuSelect not in ['1','2','3','4']:\n print(menuSelect, 'is not a valid option. Please use 1-... | {
"AcceptedAnswerId": "32836",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T19:40:00.290",
"Id": "32779",
"Score": "4",
"Tags": [
"python",
"game",
"python-3.x",
"rock-paper-scissors"
],
"Title": "Rock, Paper, Scissors game assignment"
} | 32779 |
<p>So, this is a ton of code, but that's what I came up with for an efficient and extendable implementation of the A* search algorithm.</p>
<p>The first four classes can be seen as interfaces to show the user what the interface looks like. (Is this a good way of doing that?) I can also provide examples if needed or wa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T05:17:42.300",
"Id": "52453",
"Score": "0",
"body": "This *is* a lot of code. Would you be interested in putting on github and making a link? That might make it easier for people to recommend changes/improvements, too."
},
{
... | [
{
"body": "<ol>\n<li><p>You write, \"The [abstract] classes can be seen as interfaces to show the user what the interface looks like.\" But none of these abstract classes have any documentation, so how are people expected to figure out how to use them? I mean, in some cases we might be able to figure it out by ... | {
"AcceptedAnswerId": "32925",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T20:34:24.387",
"Id": "32783",
"Score": "2",
"Tags": [
"python",
"performance",
"algorithm",
"a-star"
],
"Title": "A* search algorithm: classes"
} | 32783 |
<p><strong>SQL Server 2008 R2 + .NET 4.5:</strong></p>
<p>I have the following metadata table:</p>
<pre><code>CREATE TABLE [dbo].[Metadata](
[Id] [uniqueidentifier] NOT NULL,
[ContentId] [uniqueidentifier] NOT NULL,
[ContentType] [varchar](50) NOT NULL,
[ContentDate] [datetime] NOT NULL,
[MetaName... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-31T19:02:04.473",
"Id": "53843",
"Score": "0",
"body": "[dba.stackexchange.com](http://dba.stackexchange.com) may be a better fit for this."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-01T14:38:23.437",
... | [
{
"body": "<p>I came up with a solution, if someone has any better suggestions or any way to optimize my solution, I'm open to giving the answer to them.</p>\n\n<p>Since I needed the full value of MetaValue to match the filter, and MetaValue was not indexable because it was so big, my solution was to hash MetaV... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T23:48:40.390",
"Id": "32788",
"Score": "1",
"Tags": [
"c#",
"performance",
"entity-framework",
"sql-server"
],
"Title": "Metadata query performance optimization"
} | 32788 |
<p>I have an expandable list view:</p>
<pre><code>public class ExListViewAdapter extends BaseExpandableListAdapter {
private Context context;
private ExpandableListView exv;
private String[] sportList;
private final int AVAILABLE = 3;
private String[][] childList = {
{ "Fifa Net Wi... | [] | [
{
"body": "<h2>Data Sources</h2>\n\n<p>You have three different sources of your data....</p>\n\n<ol>\n<li><code>sportList</code> is an array of the group values, and it is pulled from <code>R.array.sportsCategories</code>.</li>\n<li><code>private final int AVAILABLE = 3;</code> is a constant defined in the clas... | {
"AcceptedAnswerId": "44455",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T03:18:37.703",
"Id": "32793",
"Score": "4",
"Tags": [
"java",
"optimization",
"android"
],
"Title": "Shorten/optimize an ExpandableListView"
} | 32793 |
<p>I wrote a D implementation of the nul2pfb utility from <a href="http://www.dwheeler.com/essays/filenames-in-shell.html" rel="nofollow">here</a>, as the link to the source code was broken and I wanted to try to learn D. I noticed that it was rather slow (could barely keep up with the find -print0 that was passing it ... | [] | [
{
"body": "<p>Do <code>write</code> and <code>writef</code> automatically buffer writes? If not I bet that's your problem.</p>\n\n<p>One suggestion I do have that you could try is using a <a href=\"http://dlang.org/statement.html#FinalSwitchStatement\" rel=\"nofollow\">final switch statement</a>. It would requi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T04:30:17.307",
"Id": "32795",
"Score": "0",
"Tags": [
"optimization",
"performance",
"strings",
"converting",
"d"
],
"Title": "Null-delimited to printf %b converter"
} | 32795 |
<p>Code in Java but should be readable also for c#...</p>
<p>Let's assume I have a class with some reference types. Example:</p>
<pre><code>class MyClass {
private int uniqueId;
private double doubleValue;
private MyReferenceType refType1;
// ...
public MyClass(int id, double doubleValue, MyReferenceT... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T18:01:52.897",
"Id": "52499",
"Score": "0",
"body": "If you have control over `MyReferenceType`, a third option is to make it immutable."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T10:54:15.780",
... | [
{
"body": "<p>Basically I use option 1. The usage of constructor is initialize the properties and creating an object in memory. Value types sets the default values (int = 0 etc), reference types sets null. If you want use own default values, you must use own constructor. This is option 1 in your post. In my... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T08:52:10.860",
"Id": "32802",
"Score": "4",
"Tags": [
"c#",
"java",
"constructor",
"reference"
],
"Title": "Reference type and constructors"
} | 32802 |
<p>I've made a small skeleton for a larger project that will include cross-platform multithreading (by using Boost) and thread-safe random numbers (by using GNU scientific libraries and mutexes). My goal is to run a simulation (probably over 100,000 loops) in which each thread will utilize a random number and read fro... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T13:37:09.730",
"Id": "70327",
"Score": "0",
"body": "If you want, look at `boost::thread_group` to create threads (instead of `vector<boost::thread>`)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T... | [
{
"body": "<p><strong><code>boost::thread_group</code> is the way to go</strong>. The part you might be missing to control the number of threads is <code>boost::io_service</code>.</p>\n\n<pre><code>boost::thread_group m_thread_group;\nboost::asio::io_service m_io_service;\nstd::auto_ptr<boost::asio::io_servi... | {
"AcceptedAnswerId": "32821",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T13:23:46.983",
"Id": "32817",
"Score": "8",
"Tags": [
"c++",
"multithreading",
"boost"
],
"Title": "Multithreading C++ loop"
} | 32817 |
<p>I've been implementing functional linked lists in different languages, just as a learning exercise. I'm looking for feedback in general: code correctness, best practices, design patterns; everything you think about this. Is it bad code? Where can it be improved?</p>
<pre><code>/**
*
* Constructing Linked Lists
*
* ... | [] | [
{
"body": "<p>Your code runs into a lot of problems because it chooses a weird value for <code>Nil</code>, and because it fails to check for that value. What is the correct result for <code>head(lst())</code>? <code>\"N\"</code>, <code>Nil</code>, or a type error?</p>\n\n<p>Because <code>\"Nil\" === \"Nil\"</co... | {
"AcceptedAnswerId": "32829",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T15:34:41.187",
"Id": "32822",
"Score": "4",
"Tags": [
"javascript",
"linked-list",
"functional-programming",
"immutability"
],
"Title": "Functional linked list"
} | 32822 |
<p>I am trying to implement a distinct counter to detect if all tasks that is added to the <code>ThreadPool</code> has completed and want to use it as a barrier. So, when a function that is added to the <code>ThreadPool</code> is completed, <code>workDone</code> will be called, and count will be decreased. The main thr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T14:57:11.277",
"Id": "52475",
"Score": "0",
"body": "FYI - there is a [codereview.se] Stack Exchange site that you might get better answers on. You could flag your question to be migrated there (click the \"flag\" link and choose ot... | [
{
"body": "<h1>Update</h1>\n\n<p>OP has since updated question so this answer makes no sense any more WRT question asked!! Those edits have also been lost in migration from stack overflow it seems.</p>\n\n<p>Purely from a concurrency perspective and not commenting on if the design is fit for purpose:</p>\n\n<hr... | {
"AcceptedAnswerId": "32824",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T14:33:15.730",
"Id": "32823",
"Score": "3",
"Tags": [
"c#"
],
"Title": "What is the potential risk with this code?"
} | 32823 |
<p>I'm trying to design a generic caching system that takes keyed items and allows either read-only or read-write access to a cached version of it. The read-only backing interface is:</p>
<pre><code>public interface IReadableItem<TKey>
{
TKey Key { get; }
}
</code></pre>
<p>However, I need to be able to dynam... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T16:17:14.183",
"Id": "52489",
"Score": "0",
"body": "Why don't you have a third interface `IKeyItem<TKey>` which declares the key. Your interfaces would then be `IReadableItem<TKey> : IKeyItem<TKey>` and `IWriteableItem<TKey> : IKey... | [
{
"body": "<p>What I would do is to use inheritance, but have only setter in <code>IWritableItem</code>:</p>\n\n<pre><code>public interface IReadableItem<TKey>\n{\n TKey Key { get; }\n}\n\npublic interface IWritableItem<TKey> : IReadableItem<TKey>\n{\n new TKey Key { set; }\n}\n</code></... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T16:05:00.747",
"Id": "32826",
"Score": "3",
"Tags": [
"c#",
"inheritance",
"interface"
],
"Title": "How to deal with interface inheritance and common properties?"
} | 32826 |
<p>Given a list which can can contain elements as well as lists, write an iterator to flatten a nested list. Please make this code better and suggest any improvements.</p>
<pre><code>public class FlattenIterator implements Iterator {
private final Stack<Iterator> iteratorStack;
private Object next;
... | [] | [
{
"body": "<p>Your code can end up with StackOverflow exception when you add self reference to the list.</p>\n\n<pre><code>List list = new ArrayList();\nlist.add(list);\nFlattenIterator flattenIterator = new FlattenIterator(list);\nwhile (flattenIterator.hasNext()) {\n // do something\n}\n</code></pre>\n",
... | {
"AcceptedAnswerId": "32832",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-17T16:07:30.513",
"Id": "32827",
"Score": "6",
"Tags": [
"java",
"algorithm",
"iterator"
],
"Title": "Flatten iterator for nested list"
} | 32827 |
<p>So, I made a console interface. It prompts users with several options they can enter. 1 for the first option, 2 for the second option, etc. Using the switch statement, each option will bring them to a different screen. Now, after any of the options are entered and the users are brought to a particular screen, how do... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-02T00:10:39.100",
"Id": "52516",
"Score": "1",
"body": "Just slap a `do while (true)` around the whole thing and replace your `goto`s with `break`s."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-02T00:11:... | [
{
"body": "<p>I'm unsure if the posted code is exactly what's intended functionally, but the following would do the equivalent:</p>\n\n<pre><code>do\n{\n printf(\"Enter 1 for the First Screen\\n\");\n printf(\"Enter 2 for the Second Screen\\n\");\n printf(\"Enter 3 for the Third Screen\\n\\n\");\n\n ... | {
"AcceptedAnswerId": "32839",
"CommentCount": "15",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-02T00:08:12.983",
"Id": "32838",
"Score": "1",
"Tags": [
"c"
],
"Title": "Acceptable Use of the goto Statement?"
} | 32838 |
<p>Wouldn't it be better to always pass parameters by reference to avoid creating unnecessary copies? </p>
<pre><code>#include <iostream>
void deliver(const std::string& message){
std::cout << message;
}
void say(const std::string message){
std::cout << message;
}
int main(){
std:... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T01:30:07.757",
"Id": "52538",
"Score": "2",
"body": "In situations like this you likely also want to make it a const. so void deliver(const std::string &message)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2... | [
{
"body": "<p>Generally, the \"order\" of what you want to pass by looks like this for user-defined classes (ignoring C++11, for the moment):</p>\n\n<ol>\n<li><p>Pass by <code>const&</code>. This should be the default way of passing\nparameters. </p></li>\n<li><p>Pass by <code>&</code>. If you need to m... | {
"AcceptedAnswerId": "32847",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T01:25:04.843",
"Id": "32842",
"Score": "6",
"Tags": [
"c++",
"reference"
],
"Title": "Passing parameters by reference"
} | 32842 |
<p>I have a MVC design for a GUI Java program. I was wondering if:</p>
<ol>
<li><p>Someone could either comment the code to help me out in understanding what I am doing better.</p></li>
<li><p>Help me fix newbie mistakes to make this program function better.</p></li>
</ol>
<p>This program asks the user for some info... | [] | [
{
"body": "<p>This methods should not be in a model\n<code>public CreditCard(JTextField cardNumber)</code>\n<code>public Destination(JRadioButton chicago, JRadioButton newYork, JRadioButton seattle, JRadioButton sanFransisco, JTextField name, JTextField phone)</code>\nClasses in model layers should be aware onl... | {
"AcceptedAnswerId": "32852",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T02:10:37.733",
"Id": "32844",
"Score": "2",
"Tags": [
"java",
"mvc"
],
"Title": "Java MVC and code example"
} | 32844 |
<p>Code reviewers, I request you review the code and suggest all tips for improvement.</p>
<pre><code>public class LRU<K, V> {
private final Map<K, Entry<K, V>> map;
private Entry<K, V> eldest;
private final int lruSize;
public LRU (int lruSize) {
if (lruSize <= 0) ... | [] | [
{
"body": "<p>The first thing I had to do when seeing your code was looking up “<em>LRU</em>”. Apparently it stands for “<em>Least Recently Used</em>”, something to do with caching.</p>\n\n<p>In your constructor, you initialize the <code>map</code>. This could also be done at the point of declaration:</p>\n\n<p... | {
"AcceptedAnswerId": "32867",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T03:22:12.787",
"Id": "32849",
"Score": "4",
"Tags": [
"java",
"algorithm",
"cache"
],
"Title": "Design LRU cache interview questions"
} | 32849 |
<p>I am new to C, and this is my first attempt at creating a linked list.</p>
<p>If anyone has a minute and could point out any errors or bad practices in this small linked list program, it would be really helpful.</p>
<p><strong>note:</strong>
I'm using the <code>get_choice</code> function to run a loop to either de... | [] | [
{
"body": "<p>I was never a fan of a \"fake first element\"-approach. And here is why:</p>\n\n<pre><code>Begin...\nEnter 1 to delete, 2 to insert, 3 to locate, 4 to print_all, or 0 to quit: 2\nEnter value: 17\nInserting 17...\nEnter 1 to delete, 2 to insert, 3 to locate, 4 to print_all, or 0 to quit: 3\nEnter v... | {
"AcceptedAnswerId": "32858",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T06:14:11.410",
"Id": "32854",
"Score": "0",
"Tags": [
"beginner",
"c",
"linked-list"
],
"Title": "A linked-list implementation"
} | 32854 |
<p>I have found <a href="https://crackstation.net/hashing-security.htm">a password hashing article and an implementation</a>.</p>
<p>Is this code secure if I increase the salt to 64 bytes, hash key size to 128 bytes and the iterations to 10000? Are there vulnerabilities or incorrectly implemented sections in this code... | [] | [
{
"body": "<ol>\n<li>Number of iterations is pretty low. Since .NET's PBKDF2 implementation is very slow, you can't afford a good number of iterations. But even with it, 20000 should be affordable for server side hashing. For client side hashing you can go much higher.</li>\n<li><p>You're outputting more than t... | {
"AcceptedAnswerId": "32864",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T07:42:13.157",
"Id": "32856",
"Score": "17",
"Tags": [
"c#",
".net",
"security",
"cryptography"
],
"Title": "Secure password hashing"
} | 32856 |
<p>Many of you might have come to the point and wished to have a Peek for IEnumerator and IEnumerator. I tried to implement it by cheating a bit and looking up the next element before the actual MoveNext call. So I ended up with some kind of wrapper.</p>
<p>First of the extensions to convert default enumerators:</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T08:25:55.487",
"Id": "52553",
"Score": "1",
"body": "While I applaud the effort, I doubt its usage, when and why would you want or need to peek without just iterating?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [
{
"body": "<p>Not really sure what your question is but I have something you might want to think about, Maybe <code>Peek()</code> shouldn't throw an exception when it's out of bounds or has <code>Status.Ending == status || Status.Ended == status</code>, but instead return a null object so you can check the valu... | {
"AcceptedAnswerId": "33011",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T08:06:36.487",
"Id": "32857",
"Score": "5",
"Tags": [
"c#"
],
"Title": "Implementing Peek to IEnumerator and IEnumerator<T>"
} | 32857 |
<p>I cache the data and use local database in my Windows Phone app. The algorithm is very simple:</p>
<ol>
<li>Get data from DB and show in UI</li>
<li>Get data from a web service and show in UI</li>
<li>Update data in DB from the web service</li>
</ol>
<p>Some data need to be saved in DB, and some do not need to.</p... | [] | [
{
"body": "<p>Let's go over the basics first!</p>\n\n<p>The indentation is quite a mess. But I suppose that might be related to the SE formatting. Otherwise, you should make your indentation coherent. Stuff like : </p>\n\n<pre><code>public interface IGYDataAccess\n {\n void GetUserInfo(Action<GYUse... | {
"AcceptedAnswerId": "114049",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T11:31:00.190",
"Id": "32863",
"Score": "5",
"Tags": [
"c#",
"design-patterns",
".net",
"cache"
],
"Title": "Architecture to cache data"
} | 32863 |
<p>I am trying to create a new object with nested value pairs. My initial challenge is that I have a huge object containing lots of junk data, and I'd like to strip away the value pairs that I do not need as well as renaming certain values. Performance is vital as this will iterate over thousands of items. I assume tha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T00:15:59.357",
"Id": "52620",
"Score": "0",
"body": "What is the source of your data?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T00:16:21.653",
"Id": "52621",
"Score": "0",
"body": "I... | [
{
"body": "<h1>New Object != Better Performance</h1>\n\n<p>First of all, your notion of \"new object is faster\" isn't \"right\" all the time. This might be trivial for smaller objects, but for thousands of records and possibly nested objects, this isn't right.</p>\n\n<p>Though you do create lesser code by reco... | {
"AcceptedAnswerId": "32898",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T12:10:30.547",
"Id": "32865",
"Score": "1",
"Tags": [
"javascript",
"performance"
],
"Title": "Create nested named object using variables as key"
} | 32865 |
<p>I have an <code>enum</code> like the following:</p>
<pre><code>enum MeasurementBandwidth
{
Hz1 = 1,
Hz3 = 3,
Hz10 = 10,
...
}
</code></pre>
<p>But I do not like the <code>Hz1</code>, and <code>1Hz</code> is not valid as it starts with a number.</p>
<p>Does anyone have an idea how to solve this "mo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T13:42:12.930",
"Id": "52579",
"Score": "1",
"body": "I'm not sure this should be an enum in the first place."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T13:45:41.930",
"Id": "52580",
"Scor... | [
{
"body": "<p>if you really want it to be <code>1Hz</code> you could put an Underscore(<code>_</code>) in front of the variable name. I know that I like to use an underscore(<code>_</code>) in front of the variable to denote a private variable. but that might not be the norm anymore. there is no way to make... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T13:36:54.043",
"Id": "32868",
"Score": "5",
"Tags": [
"c#",
"enum"
],
"Title": "Alternative to starting enum values with a number"
} | 32868 |
<p>I have written the below code where the server is getting requests from clients on a socket and creating a thread per client. Each client thread is then writing to a file which is common to all the threads. The file has been <code>open</code>ed when main starts, so the same <code>fd</code> is being used by each thre... | [] | [
{
"body": "<p>There is no reason to use <code>flock</code> <strong>and</strong> a mutex, unless you are sharing\nwith another process (as opposed to thread). I would just use the mutex and\nremember to check the return values from the <code>pthread_*</code> and <code>write</code> calls.</p>\n\n<p>Some other c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T14:10:56.267",
"Id": "32871",
"Score": "2",
"Tags": [
"c",
"locking",
"socket",
"file",
"server"
],
"Title": "File locking between server threads"
} | 32871 |
<p>I'm trying to code a simple and scalable PHP framework for my own use. Could you please offer some critiques or mandatory improvements for these two classes?</p>
<pre><code><!-- language: PHP -->
<?php
class Xmysqli extends mysqli
{
public function __construct($dataDB = array())
{
global ... | [] | [
{
"body": "<p>Sorry, but I would not use this class. Please check the <a href=\"http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29\" rel=\"nofollow\">SOLID</a> design.</p>\n\n<ol>\n<li><p>Instead of passing an array in the xmysqli construct and expecting some array keys, I would just pass the varia... | {
"AcceptedAnswerId": "33059",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T14:59:03.560",
"Id": "32872",
"Score": "3",
"Tags": [
"php",
"mysqli"
],
"Title": "Scalable database abstraction class"
} | 32872 |
<p>Is there any way to reduce this?</p>
<pre><code>//vars
defaultTextColor="#444"
correct = "#99CC00"
incorrect = "#FF4719"
answer1value = "1"
answer2value = "3"
totalquestions= "5"
//tap on the words
$(function() {
$("#word1a").click(function() {
$("#word1b").css("text-decoration", "... | [] | [
{
"body": "<ul>\n<li><p>You should be using CSS with style sheets, not by setting all styles on the elements directly. You can switch the styles for a certain element by applying and unapplying a specific class.</p></li>\n<li><p>Your naming scheme suggests that you want more complex data structures, e.g. an arr... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T14:59:50.703",
"Id": "32873",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"quiz"
],
"Title": "jQuery word quiz using local storage"
} | 32873 |
<p>I have a PHP script on my server that validates a form and sends the form to a CRM and an email address that I specify. In order to send the form data to my specified email, the script must include a valid email account and the account password. Basically, this script with an email address and password is sitting on... | [] | [
{
"body": "<p>If you are asking about the password being inside the server side code, that shouldn't be a security issue, because this information doesn't leave the server.</p>\n\n<p>I don't see a Security issue there.</p>\n\n<p>PHP Code is Never available to Client Side. so anything that you write in the code... | {
"AcceptedAnswerId": "32880",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T15:07:30.150",
"Id": "32874",
"Score": "2",
"Tags": [
"php",
"security",
"email"
],
"Title": "Email script security"
} | 32874 |
<p>I have the following interface:</p>
<pre><code>struct IFilter
{
virtual enterClass(ClassData&, int recursiveLevel) = 0;
virtual enterStructure(ClassData&, int recursiveLevel) = 0;
virtual enterVariable(ClassData&, int recursiveLevel) = 0;
virtual enterFunction(ClassData&, int recursi... | [] | [
{
"body": "<p>I'm not sure what your question is about <code>recursiveLevel</code>, but printing only when <code>recursiveLevel == 0</code> seems like pretty weird behaviour to me. If you only care about the outermost level of your data structure, then why even bother recursing?</p>\n\n<p>I'm also puzzled by w... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T20:05:23.417",
"Id": "32889",
"Score": "1",
"Tags": [
"c++",
"inheritance"
],
"Title": "Parent implementation different to child implementation"
} | 32889 |
<p><strong>EDIT:</strong> The full source code in question can be found <a href="http://code.google.com/p/gene-nation/source/browse/" rel="nofollow">here</a>.</p>
<p>Is this code reasonably safe against dead/livelocks, and if not, how can I fix it?</p>
<ul>
<li>I know processes are usually recommended over threads fo... | [] | [
{
"body": "<ol>\n<li>\"reasonably safe against deadlocks\" is a strange expression :)</li>\n<li><strike>In <code>ThreadsnQueues</code> the <code>if func is not None:</code> can be turned into an <code>else</code>.</strike></li>\n<li>Your code in <code>ThreadScore</code> indicates that some exceptions might be e... | {
"AcceptedAnswerId": "32922",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-18T21:03:37.493",
"Id": "32890",
"Score": "5",
"Tags": [
"python",
"multithreading",
"thread-safety"
],
"Title": "Is this code thread-safe?"
} | 32890 |
<p>I am creating a simple Boxing sim engine and have got things working fairly well. A few months ago I was instructed to avoid copy and pasting code and to try and "conserve my logic".</p>
<p>Anyways, I feel I have done a fairly good job overall but there is one area (posted below) that I feel definitely has room for... | [] | [
{
"body": "<p>Assuming that each <code>Boxer</code> object has a <code>.name</code> attribute…</p>\n\n<pre><code>BOXERS = [None, JS, MJ, SR]\nfor i in range(1, len(BOXERS)):\n print(\"%d) %s\" % (i, BOXERS[i].name))\nboxer1 = BOXERS[int(input(\"Choose a fighter: \"))]\nboxer2 = BOXERS[int(input(\"Choose his ... | {
"AcceptedAnswerId": "32905",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T00:10:32.220",
"Id": "32894",
"Score": "2",
"Tags": [
"python",
"python-3.x"
],
"Title": "Checking user input for boxing sim engine"
} | 32894 |
<p>Below is the code I would like some help with. I'm just trying to understand if there a better way to use getters and setters. Can someone fill me in on the correct way to use them if there is a textfield, <code>JRadioButton</code> set that I am trying to get info from?</p>
<pre><code>//This class sets gets all t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T00:59:32.717",
"Id": "52622",
"Score": "1",
"body": "Just a note about useful comments: `//Constructor with no arguments` isn't one. `//Parameterless constructor required for xyz` is more informative."
}
] | [
{
"body": "<p>Your getters and setters would be for fields of the class, not passed in. I'll use your two simplest ones as examples for you to work from.</p>\n\n<pre><code>public String getCustName(JTextField name){\n return name.getText();\n}\n\npublic String getPhoneNum(JTextField phone){\n return phon... | {
"AcceptedAnswerId": "32896",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T00:52:03.163",
"Id": "32895",
"Score": "1",
"Tags": [
"java"
],
"Title": "Java getters and setters"
} | 32895 |
<p><a href="http://en.wikipedia.org/wiki/FASTQ_format" rel="noreferrer">FASTQ</a> is a notoriously bad format. This is because it uses the same <code>@</code> character for the id line as it does for quality scores. Deciding what is a quality score and what is an id is a tricky endeavor with many pitfalls.</p>
<p>I'd ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-28T05:07:21.470",
"Id": "53437",
"Score": "0",
"body": "Thanks Jamal for adding the bioinformatics tag, I did not have enough karma for that!"
}
] | [
{
"body": "<p>I have not tried to debug your code, but it seems pretty typical for a simple ad hoc parser - a state machine, implemented with if-statements and state variables (those you give None at the beginning).</p>\n\n<p>I do not know if you are writing one-time script or a part of larger system, but if yo... | {
"AcceptedAnswerId": "33061",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T02:14:57.220",
"Id": "32897",
"Score": "5",
"Tags": [
"python",
"parsing",
"bioinformatics"
],
"Title": "Efficient parsing of FASTQ"
} | 32897 |
<p>I have the following code working on a WordPress plugin. But there's no WP issue, the matter is:<br>
<em>can I trust <strong><code>@get_headers</code></strong> to perform most of times?</em></p>
<pre><code>public function enqueue()
{
$http = is_ssl() ? 'https:' : 'http:';
$url = "$http//netdna.bootstrapcdn.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-13T13:04:40.793",
"Id": "57129",
"Score": "1",
"body": "Hitting another server on a page request just to check if the CDN is available seems like bad design to me. I would do this check client side in javascript, and if the file is 404... | [
{
"body": "<p>In my experience <em>no</em>, using <code>curl</code> is much better an reliable. I use the following code in one of my projects, this always works (and allows redirects, if you don't want to set <code>CURLOPT_MAXREDIRS</code> to <code>0</code>).</p>\n\n<pre><code><?php\n\n/**\n * Check if the ... | {
"AcceptedAnswerId": "35287",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T02:54:01.937",
"Id": "32900",
"Score": "1",
"Tags": [
"php"
],
"Title": "Checking if a CDN file is available"
} | 32900 |
<p>I have this (working) code:</p>
<pre><code>class CalendarDay
attr_accessor :from_month, :to_month, :year
def self.line_of_day_numbers(month,year,start,offset)
@line=''
@offset=offset
finish = (start+6)-@offset
self.first_line_padding(start)
start-= @offset
self.day_numbers(month,year,s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T04:15:11.313",
"Id": "52630",
"Score": "0",
"body": "If the behavior in the `first_line_padding` can change, why not offer to yield a block?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T13:49:31.93... | [
{
"body": "<p>It looks like you want to create some helper functions as class methods. If you do that, you probably want to use class variables (e.g. @@a) rather than instance variables. I would like to suggest what I think may be a better way. </p>\n\n<p>First, convert the instance variables you created with... | {
"AcceptedAnswerId": "32951",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T03:02:15.873",
"Id": "32901",
"Score": "2",
"Tags": [
"ruby",
"datetime",
"rspec"
],
"Title": "Displaying the calenday day"
} | 32901 |
<p>Bioinformatics is an interdisciplinary field that develops methods and software tools for understanding biological data. As an interdisciplinary field of science, bioinformatics combines computer science, statistics, mathematics, and engineering to analyze and interpret biological data. Bioinformatics has been used ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T03:54:29.090",
"Id": "32903",
"Score": "0",
"Tags": null,
"Title": null
} | 32903 |
Bioinformatics is the use of software tools to analyse biological data. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T03:54:29.090",
"Id": "32904",
"Score": "0",
"Tags": null,
"Title": null
} | 32904 |
<p>This tag is used by the system on questions that have had all of their other tags removed.</p>
<p>All questions in the system must have at least one tag. Normally, it is not possible to submit new or edited questions that do not have tags; the system will reject the submission until a valid tag is applied.</p>
<p>... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T06:38:10.173",
"Id": "32908",
"Score": "0",
"Tags": null,
"Title": null
} | 32908 |
DO NOT USE THIS TAG! This is a special tag that is designed to be used only by the system, on questions that have had all of their other tags removed. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T06:38:10.173",
"Id": "32909",
"Score": "0",
"Tags": null,
"Title": null
} | 32909 |
<p>In the <code>_form</code> partial I have a rather complicated logic which builds necessary options for input fields:</p>
<pre><code>- input_html_params = dynamic_settings_select_options('#service-settings', settings_aps_instance_services_path(parent))
= simple_form_for [:aps, parent, resource] do |f|
= f.input :... | [] | [
{
"body": "<p>You should be able to use a <a href=\"https://github.com/plataformatec/simple_form#custom-inputs\" rel=\"nofollow noreferrer\">Simple Form Custom Input</a>.</p>\n\n<p>As I don't know Simple Form well enough, I don't know if you can access the routes from a custom input class. </p>\n\n<p>If not, se... | {
"AcceptedAnswerId": "35231",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T09:00:53.323",
"Id": "32912",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails",
"form"
],
"Title": "Building options for input fields"
} | 32912 |
<p>Here is my code:</p>
<pre><code> public void findMiddlePos() {
int pos = 1;
Node pointerOne = first;
Node pointerTwo = first;
while(pointerOne.next.next != null) {
pointerOne = pointerOne.next.next;
pointerTwo = pointerTwo.next;
pos++;
}
System.out.println("The mid... | [] | [
{
"body": "<p>I'm no Java programmer, so this merely regards the algorithm.</p>\n\n<pre><code>while(pointerOne.next.next != null) {\n pointerOne = pointerOne.next.next;\n pointerTwo = pointerTwo.next;\n pos++;\n}\n</code></pre>\n\n<p>What happens if <code>pointerOne.next</code> is <code>null</code>? I'... | {
"AcceptedAnswerId": "32919",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T11:03:25.493",
"Id": "32914",
"Score": "2",
"Tags": [
"java",
"algorithm",
"linked-list"
],
"Title": "Finding the middle element of Singly Linked List"
} | 32914 |
<p>I'm just putting together a small project, checking to see if this would be the fastest/cleanest way to write out a function that grabs the 3 latest vital signs. </p>
<p><strong>Edit:</strong> I am thinking <code>GetRecentVitalSigns</code> should be in the domain model.</p>
<p>Also, if I wanted to grab all the vit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-20T18:39:30.893",
"Id": "52729",
"Score": "1",
"body": "could `Allergies` be an `enum` instead of string? I can see there being hundreds of elements, but IMHO type safety, intelisense, and avoiding string gotchas (CaSe, typos) wins out... | [
{
"body": "<blockquote>\n<p>I would just call the VitalSigns list, but I was thinking I could make that as private and create a GetAllVitalSigns, but that seems redundant.</p>\n</blockquote>\n<p>That depends on what you want the users of your class to allow. As it is, any user can modify everything about the co... | {
"AcceptedAnswerId": "32920",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-19T12:33:42.853",
"Id": "32916",
"Score": "6",
"Tags": [
"c#",
"linq",
"datetime"
],
"Title": "Function for obtaining the 3 latest patient vital signs"
} | 32916 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.