body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Over at Stack Overflow I asked <a href="https://stackoverflow.com/questions/22923873/search-filesystem-via-perl-script-while-ignoring-remote-mounts">how to scan a local filesystem ignoring all remote mount points</a>. I only really wanted a push in the right direction and received it. After clacking away on my keybo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T07:38:32.367",
"Id": "81454",
"Score": "2",
"body": "Tips on optimization and general code-quality are things you'll get from this site. However, wether or not this code fulfills your requirements is, IMO, part of _your_ job (develo... | [
{
"body": "<h3>Processing mount points</h3>\n\n<p>This can be improved in many ways:</p>\n\n<blockquote>\n<pre><code># Compile a list of mountpoints that need to be scanned\nmy @mounts;\nopen MT, \"<${MTAB}\" or die \"Cannot open ${MTAB}, $!\";\n\n# We only want the local mountpoints\nwhile (<MT>) {\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T05:22:01.460",
"Id": "46611",
"Score": "3",
"Tags": [
"perl",
"file-system",
"linux"
],
"Title": "Finding world-writable files in local directories only"
} | 46611 |
<p>I am formally a PHP/C# developer and I am new to C. I need you to help to correct my coding with C.</p>
<p>I have a kind of following pieces of HTTP user data string.</p>
<pre><code>char *userData = "=GET /ad26908aa2e811e3855e0a22f2d2d906_8.jpg HTTP/1.1..Host: distilleryimage10.ak.instagram.com..Connection: keep-a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T07:02:00.390",
"Id": "81450",
"Score": "0",
"body": "You (potentially, depending on which branches are taken) use `malloc` twice but never `free` anything."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04... | [
{
"body": "<p>Let's start by making this code just a lot easier to read (to my eye at least). I'd change:</p>\n\n<pre><code>const char str_GET[] = \"GET\";\n</code></pre>\n\n<p>This statement, without the <code>const</code> keyword would take a constant char array (string), and <em>copy</em> it to <code>s... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T06:34:35.607",
"Id": "46616",
"Score": "1",
"Tags": [
"c",
"memory-management"
],
"Title": "Capture and assign portions of char array to a struct"
} | 46616 |
<p>Please review the following code:</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char *some_text = "THIS IS SOME ARBITRARY TEXT FOR TESTING THE STRLEN AND COPY FUNCTIONS";
char *test = malloc(strlen(some_text) + 1);
strncpy(test, some_text... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T08:15:34.850",
"Id": "81457",
"Score": "0",
"body": "Is that Valgrind's cryptic way of complaining that you didn't check whether `malloc()` returned `NULL`?"
}
] | [
{
"body": "<p>Some general remarks to your code:</p>\n\n<ol>\n<li>You should store the string length as a variable rather than calling it multiple times.</li>\n<li>If you do <code>strncpy(test, some_text, strlen(some_text) + 1)</code> you can get rid of the <code>strcat</code> as <code>strncpy</code> will padd ... | {
"AcceptedAnswerId": "46621",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T07:21:07.090",
"Id": "46619",
"Score": "7",
"Tags": [
"c",
"strings",
"memory-management"
],
"Title": "Conditional jump or move depends on uninitialised value"
} | 46619 |
<p>I need to seed a database with user data.</p>
<p>When trying to write records to a file using sqlite3 with node, I tried writing the logic in a naive manner, without any error checks - but it was failing with numerous SQLITE_BUSY database locked errors.</p>
<p>Then I added code to retry in case of an error, but wa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T12:36:44.820",
"Id": "81503",
"Score": "2",
"body": "I would simply generate a file with `INSERT` statements in Node. Then upload that file straight into your SQLITE database. I do not believe that your approach is meant for ETL."
... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>The constructor could use some rework:</p>\n\n<ul>\n<li>You are not using any of the parameters, you might as well not declare them</li>\n<li>It would be cleaner to just send <code>task</code> to <code>registerUserWithAPI</code> since it has almost all the inf... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T07:28:44.817",
"Id": "46620",
"Score": "3",
"Tags": [
"javascript",
"performance",
"node.js",
"error-handling",
"sqlite"
],
"Title": "Seeding a file with fake records - do... | 46620 |
<p>Please let me know a better approach to solve below problem:</p>
<p><strong>Problem:</strong> Vertically arrange the words in a string and print on console.</p>
<p><strong>Sample Input:</strong></p>
<blockquote>
<pre><code>Hello Jack
</code></pre>
</blockquote>
<p><strong>Output:</strong></p>
<blockquote>
<pre>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T10:36:27.270",
"Id": "81471",
"Score": "0",
"body": "Not an answer, but an idea: In the end you are requesting the \"zip\" function, which exist in several functional programming languages. Java also got functional elements with the... | [
{
"body": "<ol>\n<li><p>Looking at this code:</p>\n\n<pre><code>if(strTemp.length() > maxWordLen)\n maxWordLen = strTemp.length();\n</code></pre>\n\n<p>This could be reduced to: </p>\n\n<pre><code>maxWordLen = Math.max(maxWordLen,strTemp.length());\n</code></pre></li>\n<li><p>Inline the incrementation... | {
"AcceptedAnswerId": "46626",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T09:23:47.027",
"Id": "46624",
"Score": "10",
"Tags": [
"java",
"strings",
"console",
"formatting"
],
"Title": "Vertically placing the words in a string"
} | 46624 |
<pre><code>int kth_smallest_number(int A[], int n, int k){
/*kth smallest number is smaller than pr equal to n-k numbers in A*/
int smaller_than_count;
int i,j;
for(i=0; i<n; i++){
/*Check whether the number A[i] satisfies
the condition*/
smaller_than_count = 0;
for(j=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T11:26:45.073",
"Id": "81480",
"Score": "0",
"body": "i have the feeling that your code didn't come out the way you wrote it, is that correct? For more help see [markdown help](http://codereview.stackexchange.com/help/formatting#code... | [
{
"body": "<p><strong>The compiler is your friend</strong></p>\n\n<p>Activate all warnings and you'll get pretty good hints :</p>\n\n<pre><code>selection.c: In function ‘kth_smallest_number’:\nselection.c:17:1: warning: control reaches end of non-void function [-Wreturn-type]\n }\n ^\n</code></pre>\n\n<p><stron... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T11:21:33.563",
"Id": "46632",
"Score": "4",
"Tags": [
"c",
"algorithm"
],
"Title": "A function that finds the kth smallest integer in array A (unsorted), of size n"
} | 46632 |
<p>I have code which I need to refactor in order to use in many places. So I tried some solutions but always ending with repeated and messy code. So, I decided to ask what possible best solutions are.</p>
<p>This code is used for calculating sale price in e-commerce project. My goal is to put some code in method which... | [] | [
{
"body": "<p>you have no comments in your code - you need some with any code, but especially something like this. Start by extracting the individual functions (you may find this easier once you've added comments); for example:</p>\n\n<pre><code>private void DiscountNotZero()\n{\n product.SalePrice = _produ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T11:49:15.137",
"Id": "46634",
"Score": "8",
"Tags": [
"c#"
],
"Title": "E-Commerce 'sale price' calculator"
} | 46634 |
<p>I just finished writing a flat-file DB class for PHP which supports selecting, updating, inserting and deleting. </p>
<p>I was wondering if there are any ways to make it faster or if I'm doing anything the wrong way.</p>
<pre><code><?php
class FlatDB {
private static $field_deliemeter = "\t";
private st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T13:17:53.310",
"Id": "81518",
"Score": "0",
"body": "Please explain as to the purpose of this class seeing that there are MANY db wrappers that are already efficient and optimized such as Eloquent and other framework's packagegist"
... | [
{
"body": "<p>So, let's say you build a website that uses this class for storing data.</p>\n\n<p>Then, one evening, you and I both visit the website at the same time. We both hit the button that opens the table and reads the data into memory. Now there are two copies of the data in memory -- one in the page you... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T12:15:50.007",
"Id": "46635",
"Score": "4",
"Tags": [
"php",
"classes",
"database",
"crud"
],
"Title": "Flat-file DB with CRUD"
} | 46635 |
<p>I have a <code>DataService</code>, which should talk to the server and store vars (for complicated calls, for example).</p>
<p>Last time, I ended up with this approach (for the example, I'm working with a list): </p>
<ul>
<li><code>GetList()</code> - returns cached data (just a property) </li>
<li><p><code>SetList... | [] | [
{
"body": "<p><strong>Style</strong> </p>\n\n<p>It won't hurt you and makes your code less error prone, if you would use braces <code>{}</code> also for single <code>if</code> statements. </p>\n\n<p>Commented code (<code>// if (isoSettings.Contains(propertyName)) isoSettings.Remove(propertyName);</code>) shou... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T12:42:33.977",
"Id": "46637",
"Score": "1",
"Tags": [
"c#",
"windows",
"windows-phone",
"windows-phone-7"
],
"Title": "DataService data storage"
} | 46637 |
<p>I'm new to this pattern and I see arguments online about different implementations. I have the following code and it seems fine to me, <strong>but I'm wondering if having to pass the DBContext into the constructor would cause any issues down the line?</strong> I'm using this with EntityFramework (RECORD_TYPE is a ta... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-07T21:53:56.607",
"Id": "81506",
"Score": "0",
"body": "you might want to read this: http://www.wekeroad.com/2014/03/04/repositories-and-unitofwork-are-not-a-good-idea/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>In my opinion using the repository pattern is absolutely fine, for a number of reasons, not limited to:</p>\n\n<ol>\n<li>It enables unit testing</li>\n<li>Allows you to change EF for a another DB technology</li>\n</ol>\n\n<p>The detail that you have to be careful of using the base class is that yo... | {
"AcceptedAnswerId": "47996",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-07T21:45:16.460",
"Id": "46639",
"Score": "3",
"Tags": [
"c#",
"design-patterns",
"entity-framework"
],
"Title": "Implementing the Repository Pattern"
} | 46639 |
<p>I've been working on a Sudoku solver as an introduction to the Java programming language. I know there's a bunch of ways to program a Sudoku solver, including a brute force/recursive approach and a logical approach. I've chosen the logical approach to start out to keep things simple.</p>
<p>This program solves Sudo... | [] | [
{
"body": "<p><strong>Quitting an application</strong></p>\n\n<blockquote>\n<pre><code>if ( incomingPuzzle.length() != 81 )\n{\n System.out.println(\"Invalid Sudoku puzzle syntax. Should be 81 numbers.\");\n System.exit(1);\n}\n</code></pre>\n</blockquote>\n\n<p>This is not a good way to quit an applicati... | {
"AcceptedAnswerId": "46645",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T13:00:33.893",
"Id": "46640",
"Score": "14",
"Tags": [
"java",
"beginner",
"sudoku"
],
"Title": "Logical Sudoku Solver in Java"
} | 46640 |
<p>I have an array of length <em>n</em> that contains numbers from 0 to <em>n</em>-1 in random order.
I now want to "inverse" this array to one that where index <em>i</em> corresponds to the location of <em>i</em> in the source array.</p>
<p><strong>Example</strong></p>
<pre><code>Source_Array = {2,0,1}
</code></pre>... | [] | [
{
"body": "<p>Unfortunately I don't really know visual basic but I think that you will find it easy to grasp the idea (and implement it in any language) of the following java code:</p>\n\n<pre><code>int[] source = new int[]{2,0,1};\nint[] dest = new int[source.length];\nfor (int i = 0; i < source.length; i +... | {
"AcceptedAnswerId": "46649",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T15:08:26.230",
"Id": "46647",
"Score": "6",
"Tags": [
"optimization",
"performance",
"array",
"linq",
"vb.net"
],
"Title": "Inversion of an array that contains indices"... | 46647 |
<p>I am applying to a university to study Computational Linguistics, and as I read, it would be recommended to have a background in Artificial Intelligence.</p>
<p>The Admission board asked me to prepare a portfolio of my works, and I am considering to add this solution to the portfolio.</p>
<p>I have been lazy to de... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T17:38:39.470",
"Id": "81569",
"Score": "3",
"body": "Re ethics: this game encourages cheating. I very much like the idea of placing additional barriers to guide the robot. This game requires creative thinking, but it's not good mate... | [
{
"body": "<p>From a quick review:</p>\n\n<ul>\n<li>As @Amon said, I would not use this for your portfolio, especially if you are cheating</li>\n<li>You have 0 comments in your code, even for a fake AI that is not good enough</li>\n<li>Instead of all the <code>if</code>s and <code>else</code> I would build a ru... | {
"AcceptedAnswerId": "46673",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T15:42:14.547",
"Id": "46650",
"Score": "15",
"Tags": [
"javascript",
"game",
"interview-questions",
"pathfinding",
"ai"
],
"Title": "Is my AI solution to Untrusted Game... | 46650 |
<p>I am trying to implement a custom ApiClient in Python, using requests.
The way it does authentication is by:</p>
<ol>
<li><p>login(username, password) -> get back a token if valid, http error code if not</p></li>
<li><p>set the token in <code>{'Authorization': token}</code> header and use that header for all endpoi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T16:39:25.993",
"Id": "81557",
"Score": "0",
"body": "the email-password will obviously not be hard coded"
}
] | [
{
"body": "<p>I don't have time to do a thorough review, but here are some comments based on a casual reading.</p>\n\n<ul>\n<li><p>In <code>read_file_contents</code>, the function returns <code>None</code> if the file doesn’t exist. I’d suggest modifying this to print or return an explicit message to that effec... | {
"AcceptedAnswerId": "46653",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T16:20:45.363",
"Id": "46652",
"Score": "7",
"Tags": [
"python",
"http",
"authentication"
],
"Title": "Python auth using requests"
} | 46652 |
<p>This query produces the results I want. </p>
<p>Is there a less wordy or more effective way to write <a href="http://sqlfiddle.com/#!4/9d4bb/50" rel="nofollow">this query</a>?</p>
<pre><code>Criteria:
1. Vendor in detail record must have a record in TRANSEFFECTIVE
2. Get the most recent (begin_frame) record from T... | [] | [
{
"body": "<p>Well, I think I broke SQLFiddle... Just for clarity's sake, I'd refactor the subqueries... that's the best way I know to do step-wise development and refinement. I know my subquery names suck - they should be descriptive. I would also strip out un-necessary column names -- or in my case, commen... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T17:44:03.127",
"Id": "46657",
"Score": "1",
"Tags": [
"sql",
"oracle"
],
"Title": "SQL double nested query"
} | 46657 |
<p>I am looking for a review on the following code which is for this <a href="http://www.codechef.com/APRIL14/problems/ADIGIT/" rel="nofollow">question</a>. I am looking for a general review of the code. I am specifically also looking for advice on how to make this code run more efficiently.</p>
<pre><code>import java... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T19:37:46.033",
"Id": "81601",
"Score": "2",
"body": "This looks like it is a C program. It's not bad in itself, but you probably don't want to write something like this for a Java job interview."
}
] | [
{
"body": "<p><strong>Naming Conventions</strong><br>\nVariables in java should be <code>camelCase</code>, meaning they should start with a small letter.</p>\n\n<p><strong>Meaningful names</strong><br>\nSomeone reading your code doesn't stand a chance in hell to understand what you are trying to do without actu... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T17:51:03.900",
"Id": "46658",
"Score": "6",
"Tags": [
"java",
"performance",
"programming-challenge"
],
"Title": "\"Chef and Digits\" Java solution"
} | 46658 |
<p>I decided to write a program to test music theory, and, while it would've been much easier for me to make it elegant and perfect in Java, I thought I'd take the opportunity to get more familiar with Python.</p>
<p>Below is the full script. It simply prints a staff in treble of bass clef with a note somewhere and a... | [] | [
{
"body": "<p><em>Warning for other reviewers : <a href=\"https://docs.python.org/2/library/functions.html#input\">input</a> and <a href=\"https://docs.python.org/3.4/library/functions.html#input\">input</a> are different depending on the version of Python you are using. This is about Python 3.</em></p>\n\n<hr>... | {
"AcceptedAnswerId": "46741",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T18:46:30.267",
"Id": "46665",
"Score": "8",
"Tags": [
"python",
"object-oriented",
"python-3.x",
"quiz",
"music"
],
"Title": "Python script to test music sight reading"... | 46665 |
<p>Can someone help me refactor this to be more optimized? Performance seems to be very optimal, but I think more can be squeezed from it.</p>
<pre><code><?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class o7th_Model extends CI_Model {
private $msg = '';
private $cu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T19:46:19.640",
"Id": "82206",
"Score": "0",
"body": "I guess no comments or answers is a good thing?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-05T18:04:58.390",
"Id": "86044",
"Score": "0",... | [
{
"body": "<p>The only thing that I can see at a quick glance is that you need to give your variables more meaningful names so that when you come back on these later you will know exactly what their purpose in life is. </p>\n\n<p>I will take another look later.</p>\n",
"comments": [
{
"Conten... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T20:10:45.817",
"Id": "46669",
"Score": "1",
"Tags": [
"php",
"optimization",
"performance",
"php5",
"codeigniter"
],
"Title": "Codeigniter ActiveRecord Wrapper Model"
} | 46669 |
<p>I've been studying PHP for a while now and decided to dive into OOP. Most of my code was a mess and I've begun to refactor much of the website to OOP; however, I'm having an issue with redundancy in my class functions. Below is a my Tracking.class.php file, which is responsible for returning arrays based on the fu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T21:32:52.313",
"Id": "81614",
"Score": "1",
"body": "Going from Precedural to OOP is an interesting journey which I took also - so my eyes are burning - but then again once upon a time I did the exact same quote you did. If none of ... | [
{
"body": "<p>I will apologize for the lack of formatting and using your code segments as straight example - but as I re-read your code I see my old self a whole lot and I don't consider myself any level near some of the coders here.</p>\n\n<p>However one important aspect to improvement is obviously trial and e... | {
"AcceptedAnswerId": "46684",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T20:26:45.490",
"Id": "46670",
"Score": "4",
"Tags": [
"php",
"optimization",
"object-oriented",
"design-patterns",
"pdo"
],
"Title": "Redunancy Issues in PHP Class"
} | 46670 |
<p>How could this template class <code>ThreadPool</code> be improved?</p>
<p>I use Boost queue to keep <code>std::function</code>'s numbers from <code>std::array</code>(simple hashing) from which I can later retrieve the <code>std::function</code>'s objects to execute them with <code>operator()</code>.
It's not possi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T02:11:21.983",
"Id": "81651",
"Score": "0",
"body": "Can you please at least add good indentation. Currently its nearly impossible to read."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T09:18:41.200... | [
{
"body": "<p>Just some stylistic things that stick out to me:</p>\n\n<ul>\n<li><p>I think it's a bit cumbersome to have all of this:</p>\n\n<pre><code>using std::cout ; using std::cin; using std::endl;\nusing std::mutex; using std::atomic;\nusing std::array; using std::function;\n</code></pre>\n\n<p>You're als... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T20:41:41.520",
"Id": "46672",
"Score": "5",
"Tags": [
"c++",
"multithreading",
"c++11",
"lock-free"
],
"Title": "Lockfree ThreadPool implementation"
} | 46672 |
<p>Suppose the following example unit test for an ASP.NET MVC controller:</p>
<pre><code>[Test]
public void Delete_Will_Redirect_To_Index_1()
{
bookRepository.Add(someBook);
var result = booksController.Delete(someBook.Id) as RedirectToRouteResult;
Assert.That(result, Is.Not.Null);
Assert.That(result.R... | [] | [
{
"body": "<p>You could make a strong argument that you need 2 tests.</p>\n\n<p>General theory has a unit test (as opposed to an integration test) containing only one assert, see e.g. <a href=\"https://softwareengineering.stackexchange.com/questions/7823/is-it-ok-to-have-multiple-asserts-in-a-single-unit-test\"... | {
"AcceptedAnswerId": "46683",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T21:30:28.987",
"Id": "46676",
"Score": "8",
"Tags": [
"c#",
"unit-testing"
],
"Title": "Unit tests: to cast or not to cast?"
} | 46676 |
<p>I am writing a stochastic simulation for a <a href="http://www.stat.berkeley.edu/~aldous/Networks/lec4.pdf" rel="nofollow">Yule process</a>:</p>
<p>If you start with a certain number of bins each containing a random number of balls, you add another ball to an existing bin with a probability that is proportional to ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T16:52:55.903",
"Id": "81622",
"Score": "2",
"body": "Questions directly about implementation of algorithms in specific languages generally belong on StackOverflow. I've flagged this for migration, so hopefully it will be moved to th... | [
{
"body": "<p>This is really an algorithms question. For example, consider this loop:</p>\n\n<pre><code>for(ii=0;ii<desval;ii++)/*Evaluate the probability total cutoffs*/\n{\n ptot[ii]=array_sum(p,ii);\n}\n</code></pre>\n\n<p>why are you calling array_sum() every time through this loop when the only thing... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T16:33:55.493",
"Id": "46677",
"Score": "1",
"Tags": [
"c",
"array",
"simulation"
],
"Title": "Adding very large arrays"
} | 46677 |
<p>If I need to obfuscate an iPhone password that is hardcode (Oauth Client Identifier and Client Secret), would this be a way to do it?</p>
<pre><code>NSString *a = @"a";
NSString *b = @"b";
NSString *c = @"c";
NSString *d = @"d";
NSString *e = @"e";
NSString *f = @"f";
NSString *g = @"g";
NSString *h = @"h";
NSStrin... | [] | [
{
"body": "<p>A slightly better option that takes a little more effort up front but saves a lot of time in the long run, and makes the code more readable (and the obfuscated word harder to crack) would be to follow this pattern...</p>\n\n<p>First, create an <code>NSString</code> class category and fill that cat... | {
"AcceptedAnswerId": "46689",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T23:40:59.670",
"Id": "46685",
"Score": "6",
"Tags": [
"security",
"objective-c",
"ios"
],
"Title": "Obfuscating iPhone Password"
} | 46685 |
<p>This was a question asked to me before setting up an interview.<br>
You are given a game board that contains a four by four (4x4) array of pieces. The pieces can be one of six shapes and can be one of six colors. </p>
<p>If the board contains 4 pieces of the same shape and same color, the board contains a winning p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T01:05:53.400",
"Id": "81644",
"Score": "0",
"body": "This question appears to be off-topic because it isn't asking for anything."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T01:17:12.770",
"Id"... | [
{
"body": "<p>Another method would be to check the board as each piece is added. This has an advantage of real time checking, but requires looping through the whole board. Also you could use a <code>Dictionary<Piece, int></code> to keep track of which pieces are added and check that instead of the board ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-08T23:55:13.210",
"Id": "46686",
"Score": "3",
"Tags": [
"c#",
"interview-questions"
],
"Title": "Winning Pattern Detection"
} | 46686 |
<p>So, I have the boundaries of every states in the US, from the google map KML file.</p>
<p>This KML file is actually a XML file.</p>
<p>I'm converting this file to a JS file compatible with google map in order to draw polygons on my map.</p>
<p>Here is an excerpt from <a href="https://gist.github.com/anonymous/698... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T03:04:32.567",
"Id": "81653",
"Score": "1",
"body": "I've created the [tag:geospatial] tag instead, as it has broader applicability. The combination of [tag:xml] and [tag:geospatial] should turn up some KML-related questions."
},
... | [
{
"body": "<p>I'd suggest <a href=\"http://nokogiri.org/\" rel=\"nofollow\">Nokogiri</a> for parsing the KML/XML. It's a more full-featured library, which makes things easier. For instance, you can get rid of all those long lines of <code>[:symbol][0][:another_symbol][0]...</code> (or maybe xmlsimple is brillia... | {
"AcceptedAnswerId": "46692",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T00:10:53.633",
"Id": "46688",
"Score": "5",
"Tags": [
"javascript",
"ruby",
"parsing",
"xml",
"geospatial"
],
"Title": "Converting KML/XML to Javascript"
} | 46688 |
<p>I wrote the following <code>split</code> function. It takes a <code>list</code>, an <code>element</code> and an <code>Ordering (LT, GT, EQ)</code>. For <code>LT</code>, the list will filter out all items that are >= the element argument.</p>
<pre><code>split' :: (Ord a) => [a] -> a -> Ordering -> [a]
sp... | [] | [
{
"body": "<p>Your <code>split'</code> could be simplified using <code>filter</code>.</p>\n\n<pre><code>split' :: (Ord a) => [a] -> a -> Ordering -> [a]\nsplit' list value cmp = filter (\\x -> compare x value == cmp) list\n</code></pre>\n\n<p>I think that the order of arguments to <code>split'</c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T03:13:07.030",
"Id": "46693",
"Score": "3",
"Tags": [
"haskell"
],
"Title": "Splitting a List"
} | 46693 |
<p>This is a piece of code I am working on to reuse in a few places on various websites. It is used to capture name and email addresses for people interesting in registering for something, we want to add them a newsletter...So here is the scripts/CSS/HTML and it feels clunky. And maybe others might have some input on... | [] | [
{
"body": "<blockquote>\n <p>This is a piece of code I am working on to reuse in a few places on various websites</p>\n</blockquote>\n\n<p>This line alone tells me that it's a drop-in script. And that alone makes me tell you to <em>skip jQuery altogether</em>. Never assume a website uses jQuery. Also, not all ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T03:39:36.967",
"Id": "46695",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html",
"css"
],
"Title": "Interupt redirect to catch potential newsletter signup"
} | 46695 |
<p>I created this small Python calculator after abstaining from writing code for a while now. I would love seasoned programmers input.</p>
<pre><code>#!/usr/bin/env python
" A Simple calculator "
class Calculator(object):
""" Example input:
expression: (12+4)*2^4-(10-3*(15/5))
steps:
1) c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T06:51:52.940",
"Id": "81674",
"Score": "2",
"body": "I also once wrote a Python calculator: `calculate = lambda x:eval(x)`. Works like a charm."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T08:02:13... | [
{
"body": "<p>Use actual comments for comments. All of those strings are kept by the interpreter. If you have to use a string as a documentation item then you should use the triple quote variety.</p>\n\n<p>Use full words or at least standard abbreviations. 'EXIT_PE' <-- no one else knows what this is. The pr... | {
"AcceptedAnswerId": "46702",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T05:12:29.980",
"Id": "46698",
"Score": "8",
"Tags": [
"python",
"calculator"
],
"Title": "Small Python calculator"
} | 46698 |
<p>Here is a question I tried from the Codility train website:</p>
<blockquote>
<p>A small frog wants to get to the other side of the road. The frog is
currently located at position X and wants to get to a position greater
than or equal to Y. The small frog always jumps a fixed distance, D.
Count the minimal n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T06:15:24.977",
"Id": "81669",
"Score": "5",
"body": "One word hint: \"division\"."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-07-03T15:15:45.013",
"Id": "250015",
"Score": "0",
"body": "This... | [
{
"body": "<p>Maybe you should try something like:</p>\n\n<pre><code>public class Frog {\n public static int solution(int x, int y, int d) {\n return (int) Math.ceil((y - x) / (float)d);\n }\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T05:40:17.123",
"Id": "46699",
"Score": "15",
"Tags": [
"java",
"programming-challenge"
],
"Title": "Codility Frog Jump - Count minimal number of jumps from position X to Y"
} | 46699 |
<p>As I understand, the constructor chaining can be applied to cases when we have some common data to initialize. I have 3 constructors that accept 3 different types of arguments and have some common data. I'm not sure if I can do constructor chaining.</p>
<pre><code>public class RStandart
{
private readonly SqlCo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T06:23:14.617",
"Id": "81670",
"Score": "0",
"body": "What are you doing with `_requestData` after forging it in the constructor? And with `_objConn`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T06... | [
{
"body": "<p>You can use constructor chaining on the first two constructors but the last one differs a lot.</p>\n\n<p>What i think is more important is that you give the RStandart class a lot of knowledge and responsibility to setup the RequestData class. Are you sure this class needs to know how to initializ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T05:57:15.537",
"Id": "46701",
"Score": "3",
"Tags": [
"c#"
],
"Title": "3 constructors that accept 3 different types of arguments"
} | 46701 |
<p>I have this method in my service layer </p>
<pre><code> public ModuleResponse GetModules(ModuleRequest request)
{
var response = new ModuleResponse(request.RequestId);
try
{
response.Modules = Mapper.ToDataTransferObjects(ModuleDao.GetModules());
return respons... | [] | [
{
"body": "<p>In my opinion No. There is hardly any behaviour at all. As soon you say \"I have this method in my service layer\" it make it much more obvious. Service layer provide communication and pretty much should orchestrate things. That's it. </p>\n\n<p>Note that Unit tests are good but have it unnecessar... | {
"AcceptedAnswerId": "46712",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T10:01:34.930",
"Id": "46709",
"Score": "2",
"Tags": [
"c#",
".net",
"unit-testing"
],
"Title": "Unnecessary unit test?"
} | 46709 |
<p>This is piece of code is using to download images. Can somebody tell me how to optimize this code to decrease download time for each image?</p>
<pre><code> URL url;
HttpURLConnection connection = null;
InputStream input = null;
System.setProperty("http.keepAlive", "true");
try... | [] | [
{
"body": "<h3>Resources:</h3>\n<p>You should really use try-with-resources:</p>\n<pre><code>URL url = new URL(urlstring);\nSystem.setProperty("http.keepAlive","true");\ntry(HTTPUrlConnection connection = (HTTPUrlConnection) url.openConnection()){\n connection.setConnectTimeout(HTTP_CONN... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T10:39:09.673",
"Id": "46711",
"Score": "5",
"Tags": [
"java",
"android",
"http"
],
"Title": "Decrease Image downloading time with HttpURLConnection"
} | 46711 |
<p>I need to extract some metrics from ManagedBeans and store the collected metrics in an object bean.</p>
<p>The object bean is defined with member variables to hold the metrics. In this case, is it right to extend the ObjectBean and write the extractor class?</p>
<p>For example:</p>
<pre><code>class ThreadMetricsB... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T04:42:03.207",
"Id": "81876",
"Score": "1",
"body": "@palacsint that was a typo mistake. Now I have corrected."
}
] | [
{
"body": "<ol>\n<li><p>I would declare variables on separate lines.</p>\n\n<blockquote>\n<pre><code>private long liveCount, daemonCount;\n</code></pre>\n</blockquote>\n\n<p>From <em>Code Complete, 2nd Edition</em>, p761:</p>\n\n<blockquote>\n <p><strong>Use only one data declaration per line</strong></p>\n \... | {
"AcceptedAnswerId": "46949",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T12:21:11.480",
"Id": "46717",
"Score": "3",
"Tags": [
"java",
"design-patterns"
],
"Title": "Is it correct to extend a bean class and write a class which holds logic to populate th... | 46717 |
<p>I need to re-wrap a text so that it fits a given width, font and DC. The result needs to be an array of lines. I use the following code:</p>
<pre><code>private struct SplitInfo
{
public string Word;
public string SplitChar;
public override string ToString()
{
return Word;
}
}
private ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T23:36:30.180",
"Id": "81833",
"Score": "0",
"body": "I was just wondering if the width of a rendered word can calculated from the sum of the letters that make it up, if do you could cache one the size of each letter. If not an exact... | [
{
"body": "<p>First, I'd like to say that your code is written very well, and is quite readable.</p>\n\n<p>As for your question - your code runs <code>MeasureString</code> at least once per word in your text. Since a line should be (quite) longer than a single word, I think you can reduce the number of calls su... | {
"AcceptedAnswerId": "46736",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T12:22:08.480",
"Id": "46718",
"Score": "6",
"Tags": [
"c#",
"performance",
"winforms"
],
"Title": "Can calculation of word wrapping be made notably faster?"
} | 46718 |
<p>I'm relatively new to JavaScript OOP and would like to know the best practice when doing a simple object such as a Model.</p>
<p>Here's a piece of code representing class named <code>Child</code>:</p>
<p>What I'm asking for is:</p>
<ol>
<li>The usage of this (and the weak reference I'm doing which I name self)</l... | [] | [
{
"body": "<p>For your questions:</p>\n\n<ul>\n<li>The usage of <code>this</code> : In my mind, unless you are using closures, do not use <code>self = this</code>, so only keep it in <code>getMissions</code></li>\n<li>Functions in <code>prototype</code> <- Good stuff</li>\n<li>Function <> JSON, is an odd ... | {
"AcceptedAnswerId": "46721",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T12:23:51.847",
"Id": "46719",
"Score": "7",
"Tags": [
"javascript",
"object-oriented"
],
"Title": "Basic JavaScript OOP model object"
} | 46719 |
<p>I've since come up with an improved version, which isn't technically lock-free, but might be as close as you can get <a href="https://codereview.stackexchange.com/questions/47606/nearly-lock-free-job-queue-of-dynamic-size-multiple-read-write">(nearly) lock-free job queue of dynamic size (multiple read/write)</a></p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T13:54:51.387",
"Id": "81732",
"Score": "0",
"body": "at least one issue was pointed out in the original thread: http://stackoverflow.com/a/22963691/1078274 another issue I have since identified is the fact that there can be race con... | [
{
"body": "<p>Herb Sutter has written a series of articles about lock-free queues: </p>\n\n<ul>\n<li><p><a href=\"http://www.drdobbs.com/cpp/lock-free-code-a-false-sense-of-security/210600279\" rel=\"nofollow\">\"Lock-Free Code: A False Sense of Security\"</a>:\nexplaining why STL containers are not suitable fo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T13:06:13.523",
"Id": "46722",
"Score": "5",
"Tags": [
"c++",
"c++11",
"lock-free",
"atomic"
],
"Title": "lock-free job queue without size restriction (multiple read/write)"
} | 46722 |
<p>I've started working on a script that turns sections with headings into a tabbed interface.</p>
<p>The repo is at <a href="https://github.com/derekjohnson/tabs" rel="nofollow">https://github.com/derekjohnson/tabs</a> and a demo at <a href="http://derekjohnson.github.io/tabs/" rel="nofollow">http://derekjohnson.gith... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>In general, impressive code</li>\n<li><p>The bottom part of your code is too stretched vertically, this:</p>\n\n<pre><code> /* Insert the tabs into the DOM\n ========================================================================== */\n\n tabs.append... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T13:59:35.830",
"Id": "46727",
"Score": "4",
"Tags": [
"javascript",
"dom"
],
"Title": "Accessible tabbed UI"
} | 46727 |
<h3>Notes</h3>
<p>I'm working my way through SICP, and as I got very confused by the section on folds, I decided to try to implement foldr in scheme and javascript to understand how it works differently with immutable and mutable variables.</p>
<p>I'm mostly looking for advice on whether or not what I've done makes s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T15:00:38.820",
"Id": "81748",
"Score": "1",
"body": "In the future, it'd be nice if you could post this as two separate questions: One about the Scheme implementation, and one about the the JS (and link from one to the other, for th... | [
{
"body": "<p>I can only speak to the JS code - which looks pretty good, by the way... except:</p>\n\n<p><em>You're modifying the array you're folding.</em> In fact, you're truncating it completely due to your use of <code>shift</code>. So your function has destructive side-effects. After the fold, you have you... | {
"AcceptedAnswerId": "46732",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T14:52:07.390",
"Id": "46729",
"Score": "7",
"Tags": [
"javascript",
"scheme",
"sicp",
"higher-order-functions"
],
"Title": "My first accumulators"
} | 46729 |
<p>This is my first attempt at a jQuery plugin, which is a simple modal window. I'm keen for feedback of whether I've got the principle correct, the usability of the plugin and any improvements that could be made.</p>
<p>Here is a working <a href="http://jsbin.com/bagiqaru/3" rel="nofollow">JSBin</a>.</p>
<p><strong... | [] | [
{
"body": "<p>To avoid a lot of issues in the future I can recommend writing your plugin in <code>\"use strict\";</code> mode. \nNext improvement could be using variables at the beginning of your function to make it faster and cache values. For instance: </p>\n\n<pre><code>$.fn.modalise = function( options ) {\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T16:46:19.173",
"Id": "46737",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"css",
"plugin"
],
"Title": "jQuery Modal Plugin"
} | 46737 |
<p>I made a C++ container of an ordered list of integers, that, in order to save space, I save as ranges:</p>
<p>For example, the list \$ \{1,2,3,5,6,7,8,9,20\} \$ is saved in memory as \$ \{(1,3), (5,9), (20,20)\} \$.</p>
<p>I have doubts of the iterator used to show all the numbers that are include on one list is r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T17:17:18.943",
"Id": "81785",
"Score": "1",
"body": "If the iterator is not there to change the contents of the container then just make it a const iterator."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-... | [
{
"body": "<p>A fairly minor point, but I'm not a huge fan of using <code>enable_if</code> here. For example, if we declare a <code>RangeList<double></code>, we'll get the following as errors:</p>\n\n<blockquote>\n <p>range_iter.cpp: In function 'int main()':</p>\n \n <p>range_iter.cpp:53:21: error: no... | {
"AcceptedAnswerId": "46769",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T17:10:16.133",
"Id": "46739",
"Score": "8",
"Tags": [
"c++",
"c++11",
"integer",
"container",
"interval"
],
"Title": "Container for list of ranges"
} | 46739 |
<p>As the title says, the objective is to free a binary tree without using the stack or allocating memory.<br>
This was required for a kernel module where resources were limited.</p>
<p>Result has a complexity of \$ O \left( n \right) \$.</p>
<pre><code>template<typename T>
struct Node
{
T data;
Nod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T17:58:59.693",
"Id": "81788",
"Score": "0",
"body": "This looks mostly C-ish. Using `unique_ptr` and the like would be more idiomatic and exception safe, but as you are in a kernel environment, exceptions are not allowed and your re... | [
{
"body": "<h1>function missing templates</h1>\n\n<p>I'm sure you're aware, but the functions need the same templating as the <code>Node</code> such that <code>void freeTree(Node* t)</code> becomes:</p>\n\n<pre><code>template<typename T>\nvoid freeTree(Node<T>* t)\n</code></pre>\n\n<h1>slight reduct... | {
"AcceptedAnswerId": "46822",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T17:45:45.777",
"Id": "46740",
"Score": "14",
"Tags": [
"c++",
"memory-management",
"tree",
"kernel"
],
"Title": "Free a binary tree without using recursion or allocating me... | 46740 |
<p>I have this code below for autocomplete feature of several inputTextbox. The input box also share same class".wikiInput". When user typed something in either of them, a relevant autocomplete dropdown box should show up. Instead of hard code one by one. How do I optimize them into a simpler format. Note the <strong>l... | [] | [
{
"body": "<p>Quick answer: Use arguments.</p>\n\n<pre><code>function initAutocomplete(selector, lookup) {\n $(selector).autocomplete({\n deferRequestBy: 0,\n autoSelectFirst: true,\n lookup: lookup,\n onSelect: function (value, data) {\n cdSubjectInput.val(value.value);\n $(\".wikiSubmit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T18:11:27.923",
"Id": "46742",
"Score": "1",
"Tags": [
"javascript",
"optimization",
"jquery",
"array"
],
"Title": "Optimize jQuery code includes autocomplete function for diff... | 46742 |
<p>I am trying a stack implementation using an array. I want to know if this approach is OK or if there is a logical problem. This program is working fine.</p>
<pre><code>#include <stdio.h>
#define MAXSIZE 5
struct stack /* Structure definition for stack */
{
int stk[MAXSIZE];
int top;
} s;... | [] | [
{
"body": "<p>There is no <em>logical</em> issue to what you are doing, as indeed that is a stack and does what a stack needs to do. </p>\n\n<p>One thing you may want to consider though is that a fixed size array is typically not the manner in which stacks are implemented. For as to why, consider the case where... | {
"AcceptedAnswerId": "46764",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T20:16:27.970",
"Id": "46748",
"Score": "7",
"Tags": [
"c",
"array",
"stack"
],
"Title": "Stack implementation using an array"
} | 46748 |
<p>I have two statements that look like this: </p>
<pre><code>$('table tr td:nth-child(' + columnNumber + ')').toggle();
$('table tr th:nth-child(' + columnNumber + ')').toggle();
</code></pre>
<p>Is there a way to combine these two statements? </p>
| [] | [
{
"body": "<p>A comma.</p>\n\n<pre><code>$('table tr td:nth-child(' + rowNumber + '), table tr th:nth-child(' + rowNumber + ')').toggle();\n</code></pre>\n\n<p>jQuery's selectors are the same as CSS (with some stuff added here and there), so all the usual CSS selector rules apply:</p>\n\n<pre><code>$(\"div, h1\... | {
"AcceptedAnswerId": "46750",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T20:18:32.083",
"Id": "46749",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "consolidate table td and th query"
} | 46749 |
<p>I was <a href="https://stackoverflow.com/questions/22949027/nested-replace-js/22949369">inspired</a> to write a BBCode to HTML converter as I'm currently learning functional programming. I wanted achieve functional cohesion. <a href="http://jsfiddle.net/kN3nD/4/" rel="nofollow noreferrer"><strong>jsFiddle</strong></... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T22:13:27.277",
"Id": "81829",
"Score": "0",
"body": "Just had a thought, if this is converting a long string of bbCode, it would have to recurse many times. However, if I recurse over the ruleSets, it would only recurse by the numbe... | [
{
"body": "<ol>\n<li><p>Overall, it's interesting, but quite hard to read. The indentation is kinda funky, and it would be easier to parse with all those ternary branches. For instance, this:</p>\n\n<pre><code>var htmlTemplate = (isClosing ? rules[key].map(function(rule) { \n ... | {
"AcceptedAnswerId": "46981",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T20:30:53.087",
"Id": "46751",
"Score": "6",
"Tags": [
"javascript",
"strings",
"functional-programming",
"regex",
"converting"
],
"Title": "BBCode to HTML converter usi... | 46751 |
<p>I'm new when it comes to Java and programming in general, but I feel I have a decent grasp on a lot of the fundamentals.</p>
<p>I've created this "random planet generator" that is virtually useless aside from minimal entertainment, but I've created it to help solidify what I've been learning. I'm not asking for cod... | [] | [
{
"body": "<p>Opening and closing both files for every name is very inefficient and is almost certainly the cause of the slow performance. A better bet would be to open both files once, outside the loop, and pass them into the function where the seek can be done.</p>\n\n<p>Alternatively, open both files once, r... | {
"AcceptedAnswerId": "46761",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T21:21:35.563",
"Id": "46754",
"Score": "16",
"Tags": [
"java",
"performance",
"beginner"
],
"Title": "Planetary Nomenclature"
} | 46754 |
<p>This is my solution for <a href="https://projecteuler.net/problem=26" rel="nofollow">problem 26 from Project Euler</a>:</p>
<pre><code>"""Find the value of d < 1000 for which
1/d contains the longest recurring cycle
in its decimal fraction part."""
from timeit import default_timer as timer
import math
from de... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T12:09:59.233",
"Id": "82100",
"Score": "0",
"body": "You shouldn't update the code you've written as it makes the answers irrelevant. Please rollback your change and if you really want to, add the new code precising explicitely that... | [
{
"body": "<p>You don't have to define your own <code>gcd</code> function: it <a href=\"https://docs.python.org/3.4/library/fractions.html#fractions.gcd\">already exists</a> in the <code>fractions</code> module of the standard library. And actually, it works with any integer type. Therefore, you can rewrite <co... | {
"AcceptedAnswerId": "46827",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T21:45:22.733",
"Id": "46759",
"Score": "9",
"Tags": [
"python",
"python-2.x",
"programming-challenge"
],
"Title": "Rendition of Project Euler 26 - reciprocal cycles"
} | 46759 |
<p>This is a revised version of an AI for the game <a href="http://gabrielecirulli.github.io/2048/" rel="nofollow noreferrer">2048</a>, written in Haskell.</p>
<p>Link to original thread: <a href="https://codereview.stackexchange.com/questions/46493/poor-ai-for-2048-written-in-haskell">Poor AI for 2048 written in Hask... | [] | [
{
"body": "<p>I am unfortunately no performance guru, but will take a stab at this as I repeatedly had to make programs faster, and there are no answer yet.</p>\n\n<p>A nitpick : I would have used a type synonym for <code>Grid</code> and <code>Row</code> :</p>\n\n<pre><code>type Grid = [Int]\ntype Row = [Int]\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-09T21:57:51.163",
"Id": "46760",
"Score": "5",
"Tags": [
"haskell",
"ai"
],
"Title": "Revised: AI for 2048 in Haskell"
} | 46760 |
<p>Most of you already know me, please be brutal, and treat this code as if it was written at a top tech interview company.</p>
<p><strong>Question:</strong></p>
<blockquote>
<p>Given a binary tree and a sum, find all root-to-leaf paths where each
path's sum equals the given sum.</p>
<p>For example: Given th... | [] | [
{
"body": "<p>There are a few things that could be better:</p>\n\n<ul>\n<li>You should make it generic.</li>\n<li>Personally, I think you should use an array to store the children, even if there are only two; it can make it a lot more DRY.</li>\n</ul>\n",
"comments": [
{
"ContentLicense": "CC ... | {
"AcceptedAnswerId": "46767",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T00:15:49.983",
"Id": "46765",
"Score": "6",
"Tags": [
"java",
"algorithm",
"interview-questions",
"tree"
],
"Title": "Find the sum along root-to-leaf paths of a tree"
} | 46765 |
<p><strong>What I'm trying to do:</strong></p>
<ol>
<li><p>Get user input for Google Play App page. </p>
<p>e.g. <a href="https://play.google.com/store/apps/details?id=jp.scn.android" rel="nofollow">https://play.google.com/store/apps/details?id=jp.scn.android</a></p></li>
<li><p>Scrape 100 reviews from Google Play A... | [] | [
{
"body": "<p>Use scraping as last resort. <em>I suggest you find available APIs for that</em>. It's more robust, and easy to work with. One issue with scraping is that it fetches the static HTML generated by the url. You can't fetch what is loaded via JS. Although there are ways to do it, it's just adds too m... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T03:04:01.203",
"Id": "46774",
"Score": "4",
"Tags": [
"javascript",
"json"
],
"Title": "Scraping reviews from Google Play using JavaScript"
} | 46774 |
<p>I have written a piece of code for removing duplicated values from a string. Any suggestions on improvements?</p>
<pre><code>public static String removeDuplicate(String s)
{
char [] temp = s.toCharArray();
int length =temp.length;
for (int i=0;i<length;i++)
{
for (int j = i+1; j<lengt... | [] | [
{
"body": "<h2>Style</h2>\n<p>Java Code-style conventions put:</p>\n<ul>\n<li>the <code>{</code> brace at the end of the line that introduces the compound statement block, not on the next line.</li>\n<li>spaces between variables and operators: <code>for (int i=0;i<length;i++)</code></li>\n</ul>\n<p>Your code... | {
"AcceptedAnswerId": "46789",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T04:03:57.627",
"Id": "46777",
"Score": "11",
"Tags": [
"java",
"strings"
],
"Title": "Eliminate duplicates from strings"
} | 46777 |
<p>I'm doing some research for a meta post on <a href="http://gardening.stackexchange.com">Gardening.SE</a> (where I'm a pro tempore moderator). I'm using the Stack Exchange Data Explorer (SEDE) to find information about first time users who post questions in our [identification] tag, and how they subsequently interact... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T04:37:33.490",
"Id": "81875",
"Score": "2",
"body": "Hey, and welcome to CR... we have a long history of messing with SEDE too."
}
] | [
{
"body": "<p>Half of the tricks with optimizing SQL is knowing the database schema.</p>\n\n<p>The schema documentation can be found in this Meta post: <a href=\"https://meta.stackexchange.com/questions/2677/database-schema-documentation-for-the-public-data-dump-and-sede\">Database schema documentation for the ... | {
"AcceptedAnswerId": "46782",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T04:34:57.747",
"Id": "46780",
"Score": "6",
"Tags": [
"optimization",
"sql",
"sql-server",
"t-sql",
"stackexchange"
],
"Title": "SEDE query to find users with exactly o... | 46780 |
<p>I have a backup script which should backup a folder and send it to email. This should be done once a day. As this is on my laptop which is not online 24/7 I need to check that I am online and can send email. For this script I have an entry in crontab running every 2 hours.</p>
<p>Because the folder is a really impo... | [] | [
{
"body": "<p>This is an incomplete answer; I'd just like to contribute more comments than easily fit in an actual comment.</p>\n\n<ol>\n<li><p>Consider replacing <code>PASS=\"mysecretpasswordiwontwritehere\"</code> with <code>PASS=`cat mysecretpassword.file`</code> and moving your password into that file. Then... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T07:33:38.307",
"Id": "46786",
"Score": "7",
"Tags": [
"beginner",
"bash",
"cryptography",
"email",
"openssl"
],
"Title": "Encrypt and backup folder to email daily, when on... | 46786 |
<p>I am working in an inherited code (as in "everybody related to it left before I arrived at the job and left no documentation") and I have noticed an strange pattern.</p>
<p>Almost(*) each <code>Struts</code> (Struts 1.3.8) method that is invoked begins with a code such as</p>
<pre><code>public ActionForward myMeth... | [] | [
{
"body": "<p>I don't believe there's any good use-case for this code. I know it makes for a boring answer, but sometimes the correct thing really is simple and boring. As you say, the Struts framework should always redirect to the appropriate method and fail entirely otherwise.</p>\n\n<p>Even the scant lines... | {
"AcceptedAnswerId": "46920",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T08:12:27.330",
"Id": "46788",
"Score": "2",
"Tags": [
"java"
],
"Title": "Inherited code checking Struts method name"
} | 46788 |
<p>I have been developing this plugin architecture, mostly for fun and education, its a simple WinForm with some plugin logic and two plugins, i want to know if there is a better way of doing it. </p>
<p>Form1.cs</p>
<pre><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.... | [] | [
{
"body": "<p>You should use an interface instead of an abstract class:</p>\n\n<pre><code>public interface IPlugin {\n void Start();\n void Stop();\n}\n</code></pre>\n\n<p>There are many reasons for this, as detailed in <a href=\"https://stackoverflow.com/questions/56867/interface-vs-base-class\">https://... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T09:19:55.433",
"Id": "46790",
"Score": "4",
"Tags": [
"c#",
"winforms"
],
"Title": "WinForm plugin architecture"
} | 46790 |
<p>I've written it for an assessment. It works but my assessment also requires a peer to review it in terms of how it could be improved, how it rates as a piece of JavaScript, etc, any comments would be appreciated (I don't know anyone else to ask).</p>
<p>As a bit of background this is JavaScript written to be embedd... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T10:28:15.527",
"Id": "81904",
"Score": "0",
"body": "`document.getElementById` may not work on all of the js enabled browsers. See e.g. this Q/A: http://stackoverflow.com/questions/4069982/document-getelementbyid-vs-jquery"
},
{... | [
{
"body": "<ol>\n<li><p>In JavaScript, it's generally a good idea to use the brace-on-same-line style, i.e.</p>\n\n<pre><code>if( ... ) {\n ...\n} else {\n ...\n}\n</code></pre>\n\n<p>because of javascript's policy of <a href=\"http://inimino.org/~inimino/blog/javascript_semicolons\" rel=\"nofollow\">automati... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T09:51:05.030",
"Id": "46793",
"Score": "6",
"Tags": [
"javascript"
],
"Title": "Balancing Accounts Daily"
} | 46793 |
<p>Consider a method (let's call it <code>IsPrimeHybrid</code>) which calls at least two methods (let's call them <code>IsPrimeNaive</code> and <code>IsPrimeBySearch</code>) that calculate an identical result using different approaches and the outer method returns the result when any of the inner methods finishes.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T10:28:49.097",
"Id": "81905",
"Score": "1",
"body": "The code looks ok, but I am a little confused by your objectives. If your intention is to find which method is faster, maybe a classic benchmark (lots of iterations, not competiti... | [
{
"body": "<p>Edit: since the question is already using Tasks, it is better to use Cancellation tokens instead of ManualResetEvents. Also there is no need to explicitly create a Mutex, in C# we can use lock() on any shared Object for this. I am including source code at the bottom.</p>\n\n<p>It would be quite wa... | {
"AcceptedAnswerId": "46804",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T09:53:47.693",
"Id": "46794",
"Score": "12",
"Tags": [
"c#",
"multithreading"
],
"Title": "Returning the result of whichever method finishes first"
} | 46794 |
<p>This is my constructor to transform an Outlook contact into a Dynamics CRM contact:</p>
<pre><code>public Contact(ContactItem contactItem)
{
LogicalName = EntityLogicalName;
FirstName = contactItem.FirstName;
LastName = contactItem.LastName;
//if no last name, use the first name
if (String.IsNul... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T11:50:44.590",
"Id": "81914",
"Score": "3",
"body": "You should avoid pre-mature optimization at the expense of readability until it's absolutely required. Then you should measure to see what your really slow parts are and address t... | [
{
"body": "<ol>\n<li><p>You could create a helper function with a loop:</p>\n\n<pre><code>public string getFirstNonNullOrEmpty(params string[] names) {\n foreach (string name in names) {\n if (String.IsNullOrEmpty(name)) {\n continue;\n }\n return name;\n }\n return @\"N... | {
"AcceptedAnswerId": "46799",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T11:13:27.960",
"Id": "46797",
"Score": "10",
"Tags": [
"c#",
"performance"
],
"Title": "Constructor to transform an Outlook contact into a Dynamics CRM contact"
} | 46797 |
<p>I have a <code>Timer</code> class executing a function in a specified interval:</p>
<pre><code>#include <chrono>
#include <functional>
#include <future>
#include <iostream>
#include <list>
#include <mutex>
#include <thread>
using namespace std;
// Timer
// =====
template... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T14:20:18.760",
"Id": "81942",
"Score": "2",
"body": "Please, never edit the question code on Code Review: it generally invalidates the answers (and here, it was actually the case)."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Kudos! This is on the whole a well-written class, and you appear to have written code that is correct in the face of asynchronicity, which is quite difficult!</p>\n\n<hr>\n\n<p>To start with, I think <code>Timer</code> is a misleading name for this class. When I think of a timer, I think of a cloc... | {
"AcceptedAnswerId": "46815",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T12:35:53.580",
"Id": "46807",
"Score": "7",
"Tags": [
"c++",
"c++11",
"timer"
],
"Title": "Timer utilizing std::future"
} | 46807 |
<p>This is my first attempt at creating a game in Haskell, and I would greatly appreciate some feedback.</p>
<p>Here is <code>Main.hs</code>:</p>
<pre><code>module Main where
import Deck
import Data.List
import System.Random
import Control.Monad.State
-- |'main' is the entry point for the program. This function wi... | [] | [
{
"body": "<p>I am not a Haskell programmer but I can't help suggest an improvement for <code>possiblePoints</code>. That much repetition hurt my eyes. :)</p>\n\n<pre><code>-- first factor out the mapping from a card to its value(s)\npossibleValues :: Card -> [Int]\npossibleValues card\n | card == Ace = [... | {
"AcceptedAnswerId": "47134",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T13:28:15.120",
"Id": "46809",
"Score": "14",
"Tags": [
"game",
"haskell",
"playing-cards"
],
"Title": "Blackjack in Haskell"
} | 46809 |
<p>I have this code that compares all version numbers of servers. (The version numbers are stored in an XML file) Before the code would compare the current version number with the previous. This caused some problems because in the cluster of servers, one has a different version number than the rest. If my code happened... | [] | [
{
"body": "<p>Before anything, I reckon you should have a look at <a href=\"http://legacy.python.org/dev/peps/pep-0008/\">PEP 8</a> which is the usual Style Guide for Python Code. Among other things, your names for variables and functions does not follow the <code>lowercase_with_words_separated_by_underscores</... | {
"AcceptedAnswerId": "46817",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T13:54:44.203",
"Id": "46812",
"Score": "8",
"Tags": [
"python",
"performance",
"xml",
"python-2.x"
],
"Title": "Comparing Server Version Number History"
} | 46812 |
<p>I'm crawling Flickr for data for my university research project. However it's very slow and I'm not sure what it is exactly. It could be the <code>FileWriter</code> slowing it down. Any advice on speeding it up?</p>
<pre><code>try {
String userID = file.getUserIDFromList(i);
System.out.println(i + "." + ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T15:01:29.453",
"Id": "81948",
"Score": "2",
"body": "Your code is broken, buggy, or confusing. Why do you have just one URL `urlString` defined as `\"https://api.flickr.com/services/rest/?method=flickr.people.getPublicGroups&api_key... | [
{
"body": "<p>There are a number of things going on here, but it boils down to <a href=\"http://en.wikipedia.org/wiki/Amdahl%27s_law\" rel=\"nofollow\">Amdahl's Law</a>.</p>\n\n<p>I am going to take a stab at some guessing here, but I expect my numbers to be in the right ballparks. Your code does:</p>\n\n<ul>\n... | {
"AcceptedAnswerId": "46821",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T14:36:16.503",
"Id": "46816",
"Score": "6",
"Tags": [
"java",
"performance",
"parsing",
"xml"
],
"Title": "Extraction of data from Flickr"
} | 46816 |
<p>I have 2 vectors of Facebook-like pages which are represented by an ID from 2 different users. I want to verify the number of liked pages that are similar between these 2 users.</p>
<p>This is my algorithm that I am using right now, which is basically a search into all rows and columns of a matrix:</p>
<pre><code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-02-13T01:40:06.283",
"Id": "145524",
"Score": "1",
"body": "Here at Code Review, we like to review **the full code**. Looking at your code, you write `//do something`, which shows that you did not post the full code, therefore making it o... | [
{
"body": "<p>Your algorithm is O(<em>n</em><sup>2</sup>), which is inefficient. Use an <a href=\"https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableSet_Class/Reference/NSMutableSet.html\" rel=\"nofollow\"><code>NSMutableSet</code></a> to compute the intersection ... | {
"AcceptedAnswerId": "46858",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T15:39:21.300",
"Id": "46823",
"Score": "3",
"Tags": [
"algorithm",
"objective-c",
"matrix",
"facebook"
],
"Title": "Search/match algorithm between 2 vectors"
} | 46823 |
<p>In my Python application, I am using Tarjan's algorithm to compute strongly connected components. Unfortunately, it shows up under profiling as one of the top functions in my application (at least under cPython, I haven't figured out how to profile under Pypy yet). </p>
<p>I've looked at the code, but I don't see a... | [] | [
{
"body": "<ul>\n<li><p>You iterate twice over the children in both branches. Avoid that by combining these lines</p>\n\n<pre><code>children = [child for child in getChildren(current) if child not in removed]\nstack.extend((child, 0) for child in children)\n</code></pre>\n\n<p>to</p>\n\n<pre><code>stack.extend(... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T17:36:28.817",
"Id": "46832",
"Score": "5",
"Tags": [
"python",
"performance",
"python-2.x",
"graph"
],
"Title": "Strongly connected components algorithm"
} | 46832 |
<p>I am building a Tic Tac Toe game with AngularJS and making it online playable with AngularFire. The Tic Tac Toe logic is all there so this question concerns Angularfire a little bit more. I want to be able to match a user with an opponent as well as delete inactive games.</p>
<p>I have done my homework and at this... | [] | [
{
"body": "<p>I am not an angular expert, but this </p>\n\n<pre><code>var piece;\nif(returnedData.oIsAvailable == true) {\n piece = 'x';\n}\nelse {\n piece = 'o';\n}\n$scope.myPiece = {\n val:piece\n};\n</code></pre>\n\n<p>could be </p>\n\n<pre><code>$scope.myPiece = {\n val: returnedData.oIsAvailab... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T17:45:33.150",
"Id": "46833",
"Score": "5",
"Tags": [
"javascript",
"game",
"angular.js",
"api",
"promise"
],
"Title": "AngularFire Tic Tac Toe Game"
} | 46833 |
<p>I have the below class which moves the AI towards the given plant, this works well however it feels really messy.</p>
<p>Any input as to a better way to lay out the logic would be really grateful, the logic follows the idea that we will take the x and y positions of the AI from the plants position, if the values ar... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T21:29:56.577",
"Id": "81993",
"Score": "2",
"body": "Is your position always \"1 + 30x\", for some x? I think this is a decision that could eventually lead to off-by-one errors; generally, if you have a width of 720 points, it is be... | [
{
"body": "<p>Pre-computing the possible moves, and reducing the conditionals to a simple mathematical expression is a nice way to solve problems like this.</p>\n\n<p>Your code also suffers from repeating blocks, and duplicated logic: DRY - Don't Repeat Yourself.</p>\n\n<p>Solve that by doing function extractio... | {
"AcceptedAnswerId": "46847",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T18:18:07.520",
"Id": "46834",
"Score": "24",
"Tags": [
"java",
"coordinate-system"
],
"Title": "Refining AI movement logic"
} | 46834 |
<pre><code>/*The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
*/
#include <iostream>
#include <vector>
using namespace std;
int main(){
//We will be storing the primes as bool in a vector.
vector<bool>primes(2000000,true);
// This is the ... | [] | [
{
"body": "<p>There are three relatively simple improvements you can make, that should be relatively trivial to implement.</p>\n\n<ol>\n<li><p>treat 2 as a special prime:</p>\n\n<ul>\n<li><p>Change initializer of <code>total</code>:</p>\n\n<pre><code>long long total = 2;\n</code></pre></li>\n<li><p>Change step ... | {
"AcceptedAnswerId": "46859",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T18:23:53.717",
"Id": "46835",
"Score": "12",
"Tags": [
"c++",
"primes",
"programming-challenge"
],
"Title": "Project Euler Problem 10 - Sum of primes < 2mil"
} | 46835 |
<p>I'm making some changes to a JavaScript plugin on a site I've been made steward over. This main plugin has it's own sub-plugins and I'm trying to make certain aspects modular. </p>
<p>Currently, I'm attempting to make a reusable modal window that the sub-plugins ferry data to. This main plugin uses extensive use of... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>your code is fairly easy to follow, JsHint cannot find anything serious to complain about.</p>\n\n<p>Since you have a <code>validate</code> function, I would also create a <code>callback</code> function this way your call to <code>openModal</code> could be </p>\n\n<... | {
"AcceptedAnswerId": "46904",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T19:29:36.317",
"Id": "46840",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"regex",
"plugin",
"scope"
],
"Title": "Communicating between plugins whilst maintaining c... | 46840 |
<p>Trying to learn shell sort, I kinda understood what wikipedia was trying to say, but I wanted a bit of confirmation, so I went on youtube, <a href="https://www.youtube.com/watch?v=IlRyO9dXsYE" rel="nofollow">here</a>, but this code does not work and does not look like what I read on wikipedia. I go to hi's website j... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T19:44:24.977",
"Id": "81975",
"Score": "2",
"body": "Just thought I'd mention your brackets are Java-style. Not to start any Holy Wars, but C#-style curly braces go on the next line ;)"
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>First, the good points: your code is quite cleanly written. Although some may argue over the naming convention(s) you've chosen, your names are reasonable, readable, and you do seem to have followed the naming convention fairly consistently.</p>\n\n<p>At least if I'm reading it correctly, yes, thi... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T19:31:34.730",
"Id": "46841",
"Score": "4",
"Tags": [
"c#",
"sorting"
],
"Title": "Is this Shell sort?"
} | 46841 |
<p>A few months ago I put up a <a href="https://codereview.stackexchange.com/questions/38452/python-port-scanner">port scanner for review</a>. Now, I've updated it with some new Python knowledge and integraing the feedback I got.</p>
<p>Some things I specifically think might be wrong with it or feel clunky to me:</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T06:28:07.460",
"Id": "82055",
"Score": "1",
"body": "[Follow-up question here](http://codereview.stackexchange.com/q/46866/9357)"
}
] | [
{
"body": "<p>You're opening a lot of sockets but not closing them. Those are likely file descriptor leaks. (Whether or not it actually leaks depends on the garbage collector's behaviour.)</p>\n\n<p>If you're using <code>concurrent.futures.ThreadPoolExecutor</code> for the multithreaded version, then you shou... | {
"AcceptedAnswerId": "46845",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T19:35:22.063",
"Id": "46842",
"Score": "5",
"Tags": [
"python",
"python-3.x",
"networking",
"concurrency"
],
"Title": "Python Port Scanner 2.0"
} | 46842 |
<p>I've put together a simple application in order for me to learn sqlite and OOP in PHP. The application basically outputs two random words, e.g. "Angry Badger", from two database tables, one called Animals & the other named Adjectives. At present both tables contain the same columns (but could change in future).<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T13:11:25.473",
"Id": "82106",
"Score": "0",
"body": "Just a quick suggestion: you can use Registry pattern for db connections in order to avoid passing it to the __construct(). Here is an example: https://bitbucket.org/t1gor/strateg... | [
{
"body": "<p>Extract an abstract base class <code>AbstractWordTable</code> that implements the better-named interface <code>WordTable</code> by moving all code that's duplicated between <code>Adjective</code> and <code>Animal</code> (all but the table and column names). This is a major step in the DRY directio... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T19:44:48.397",
"Id": "46844",
"Score": "4",
"Tags": [
"php",
"object-oriented"
],
"Title": "Reduce similar methods via pattern?"
} | 46844 |
<p>Quite a specific question can the below code be made more clearer / pythonic in any way.</p>
<p>Essentially based on the condition of the string <code>x((len(x) / 3) - 1)</code>, I use this to extract out parts of the string.</p>
<pre><code>def split_string(x):
splitted_string = [x[counter*3:(counter*3)+3] for... | [] | [
{
"body": "<p>For integer division, use the <code>//</code> operator. <a href=\"https://stackoverflow.com/a/183870/1157100\">In Python 3, <code>/</code> will do floating-point division.</a></p>\n\n<p>The task could be more succinctly accomplished using <a href=\"https://docs.python.org/2/library/re.html#re.fin... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T20:59:14.590",
"Id": "46849",
"Score": "4",
"Tags": [
"python",
"strings"
],
"Title": "Can this list comprehension be made more pythonic?"
} | 46849 |
<p>I have some PHP code where I use variable functions to call the right function. I need to build a chart array (for example), and the chart array that comes out has a fixed format. But the data that goes into the chart or table comes from varying places in the underlying objects.</p>
<p>An example:</p>
<pre><code>p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T22:24:44.690",
"Id": "82010",
"Score": "0",
"body": "Welcome to Code Review! To make life easier for reviewers, please add sufficient context to your question. The more you tell us about what your actual code does and what the purpo... | [
{
"body": "<p>I agree, it does feel dirty to compute the function name like that.</p>\n\n<p>A typical way to do dynamic dispatching is using polymorphism. You could formalize the mechanism for determining which function to call by making some property-extracting objects:</p>\n\n<pre><code>abstract class Proper... | {
"AcceptedAnswerId": "46862",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T22:11:49.600",
"Id": "46855",
"Score": "6",
"Tags": [
"php",
"design-patterns"
],
"Title": "Calling functions with variable functions"
} | 46855 |
<p>I've recently been asked to make some emergency changes to a legacy application written in VB.NET. I come from a C# background so am not overly familiar with this language, though there are enough similarities for me to get by.</p>
<p>The current code has no separation of concerns (e.g. DAL code is written in the ... | [] | [
{
"body": "<p>This looks really good and clean to me as well, but I too come from a C# Background.</p>\n\n<p>I think there are only a couple of things missing that I would personally like to see myself.</p>\n\n<ol>\n<li>Error Handling</li>\n<li>Constructor</li>\n</ol>\n\n<p>there is only one thing that I would ... | {
"AcceptedAnswerId": "46857",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T22:15:24.283",
"Id": "46856",
"Score": "8",
"Tags": [
"sql-server",
"vb.net"
],
"Title": "Database access class using VB.NET"
} | 46856 |
<p>I have written code to send a simple email submission form to a sql table so that I can manage the data. I would like feedback on whether or not the code that I have written is efficient and secure. I have a config file that defines constants for database credentials.</p>
<p>HTML FORM</p>
<pre><code><form metho... | [] | [
{
"body": "<p>You could possibly move the database include before the server checks and sets the <code>$_POST</code> variable, as it would not be needed if the database is unable to connect.</p>\n\n<p>I notice there is no sanitization of the email variable. <a href=\"https://stackoverflow.com/questions/17103318... | {
"AcceptedAnswerId": "46865",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-10T23:54:21.213",
"Id": "46860",
"Score": "2",
"Tags": [
"php",
"html",
"sql"
],
"Title": "Submit form data to MYSQL table with PHP execute"
} | 46860 |
<p>An optimisation question:</p>
<p>Currently I have entities stored in text files in the following format:</p>
<pre><code>Attribute1,Attribute2,Attribute3
Value1-1,Value1-2,Value1-3
Value2-1,Value2-2,Value2-3
Value3-1,Value3-2,Value3-3
</code></pre>
<p>And convert it into a 2D array in the following format:</p>
<p... | [] | [
{
"body": "<p>PHP provides functions to <a href=\"http://uk1.php.net/manual/en/function.fgetcsv.php\" rel=\"nofollow\">parse CSV files</a> and <a href=\"http://uk1.php.net/manual/en/function.str-getcsv.php\" rel=\"nofollow\">strings</a> line-by-line.</p>\n\n<pre><code>$file = ...\n$headers = fgetcsv($file);\n$l... | {
"AcceptedAnswerId": "46871",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T00:42:32.367",
"Id": "46864",
"Score": "2",
"Tags": [
"php",
"array"
],
"Title": "Assigning array keys based on the values of another array"
} | 46864 |
<p>I made lots of changes to the script presented in <a href="https://codereview.stackexchange.com/questions/46842/python-port-scanner-2-0">my previous question</a>. I was tempted to edit that one with the new code, but it would invalidate @200_success's helpful answer. It was also disallowed <a href="https://coderev... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T06:27:33.233",
"Id": "82054",
"Score": "12",
"body": "Asking a new question is the right thing to do!"
}
] | [
{
"body": "<p>Trying to connect to TCP port 80 in order to check whether the DNS lookup succeeds is overkill. You should just call <a href=\"https://stackoverflow.com/a/2805413/1157100\"><code>socket.gethostbyname()</code></a>.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"Co... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T01:18:54.203",
"Id": "46866",
"Score": "12",
"Tags": [
"python",
"python-3.x",
"networking",
"concurrency"
],
"Title": "Python Port Scanner 2.1"
} | 46866 |
<p>I recently self-taught myself MySQL as quickly as possible because it was needed for a project that I'm working on. Now that I've got some time I've been working on improving some thrown together SQL procedures. I've already done a few things, like logic improvements and removal of sub-queries, but I'm wondering if ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T01:44:35.880",
"Id": "82026",
"Score": "0",
"body": "are `playerid` and `userID` in the same table? are you looking to see if they are in the same row?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11... | [
{
"body": "<p>the first thing that I see here is that it is going to be hard to read because you don't use standard ... \"notation\" like indentation and new lines for each column you are selecting in a SELECT statement. all of this is going to matter when you are going to be returning to the code to read it ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T01:28:17.403",
"Id": "46867",
"Score": "8",
"Tags": [
"mysql",
"sql"
],
"Title": "Bad practices in this procedure to calculate player statistics?"
} | 46867 |
<pre><code>#include <stdio.h>
#include <stdlib.h>
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define MAGENTA "\x1b[35m"
#define CYAN "\x1b[36m"
#define RESET "\x1b[0m"
int main () {
int n1 = 1, n2 = 0, i = 0, limit = 0, neg = 0, pos ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-12T02:09:14.490",
"Id": "82272",
"Score": "5",
"body": "-1 Please provide the problem description and your desired level of review at a bare minimum. Questions solely comprising \"Code!\" merit only \"You posted some code which probabl... | [
{
"body": "<h1>Things you could improve</h1>\n\n<h3>Using Headers</h3>\n\n<ul>\n<li><p>Right now you are defining some items at the top of your source file.</p>\n\n<blockquote>\n<pre><code>#define RED \"\\x1b[31m\"\n#define GREEN \"\\x1b[32m\"\n#define YELLOW \"\\x1b[33m\"\n#define BLUE \"\\x1b[34m\"\... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T04:39:12.063",
"Id": "46880",
"Score": "6",
"Tags": [
"c",
"console",
"fibonacci-sequence"
],
"Title": "Basic Fibonacci sequence in C"
} | 46880 |
<p>I have this uniform cost search that I created to solve Project Euler Questions 18 and 67. It takes the numbers in the txt file, places them into a two dimensional list, and then traverses them in a uniform cost search (that I hoped was a kind of implementation of an a* search). It looks like this:</p>
<pre><code>f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T07:06:54.593",
"Id": "82061",
"Score": "0",
"body": "It could be helpful to include a link to details of an a* search so that people who aren't familiar with this algorithm can help you. I know there is Google and Wikipedia, but if ... | [
{
"body": "<p>You mentioned in the comments that the size of the triangle is hard-coded into the code. The very first thing you should do is make this a variable which you declare at the start of your code. (In many other languages, this would be a constant). You also use the number 100 in line 5. If this is su... | {
"AcceptedAnswerId": "46890",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T05:06:55.193",
"Id": "46883",
"Score": "3",
"Tags": [
"python",
"optimization",
"recursion",
"programming-challenge",
"pathfinding"
],
"Title": "Recursive uniform cost ... | 46883 |
<p>I would like to put the following design to your consideration. This is the pattern I use to follow when I'm building a Model and Data Access Layer for an MVC Application (using Entity Framework 5). I'm looking for any advises about how to improve me design (feel free to provide a new one) because I feel that it can... | [] | [
{
"body": "<p>I've used this kind of approach myself in the past and it's worked well. However lately I've been considering whether it's overkill. Considering Entity framework is already following the repository and unit of work pattern you are essentially just adding the same pattern over the same pattern an... | {
"AcceptedAnswerId": "46898",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T05:23:02.637",
"Id": "46884",
"Score": "5",
"Tags": [
"c#",
"entity-framework",
"asp.net-mvc-4"
],
"Title": "Model Design for MVC4 Applications using Entity Framework Code Firs... | 46884 |
<p>I have a MySQL table with a very large data. What I need is to find and separate duplicates from the unique rows</p>
<p>Let's say this is my table:</p>
<pre><code>indx, data_lname, data_fname, data_mname, data_dob, data_mobile
</code></pre>
<p>What I'm doing right now is selecting all the rows in one query and t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T06:23:20.590",
"Id": "82051",
"Score": "0",
"body": "It is working but it takes a lot of time to complete, say 1 hour for about 20k records. What im thinking is if there is another way of doing this that yields faster results. the... | [
{
"body": "<p>You should <strong>never run a query in a loop,</strong> especially a loop where the number of queries issued scales with the size of the data. There is almost always a way to formulate the SQL such that you get the results you want with a small, fixed number of queries.</p>\n\n<p>In your case, y... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T06:12:43.193",
"Id": "46886",
"Score": "5",
"Tags": [
"beginner",
"mysql",
"vb.net"
],
"Title": "Separating Duplicates from Uniques"
} | 46886 |
<p>The following is a small class I extended MySQLi with. I'm going to use this in my upcoming projects, but my main reason to do this class is learning, so I would like to submit this for your review, tell me if there are any bugs or improvements to be made.</p>
<p>NOTES:</p>
<ol>
<li><p>I know about prepared state... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T07:46:28.767",
"Id": "82070",
"Score": "3",
"body": "First thing I notice is a lack of sanitization. You seem to be passing the arguments into the SQL string straight up. Can you supply some examples of your usage in a theoretical p... | [
{
"body": "<p>I'm not a PHP programmer so I will only address what I see from your use of MySQLi:</p>\n\n<pre><code>public function update($table,$data,$where)\n {\n $extracted = $this -> append($data);\n $this -> query(\"UPDATE \".$table.\" SET \".$extracted.\" WHERE \".$where);\n ... | {
"AcceptedAnswerId": "51355",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T06:16:43.570",
"Id": "46887",
"Score": "5",
"Tags": [
"object-oriented",
"php5",
"database",
"mysqli"
],
"Title": "My database class extends MySQLi"
} | 46887 |
<p>Given a postfix expression, construct an expression tree. Looking code code review, optimizations and best practices.</p>
<pre><code>public class ExpressionTree {
private final String postfix;
private TreeNode root;
/**
* Takes in a valid postfix expression and later its used to construct the exp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T15:14:07.290",
"Id": "82153",
"Score": "1",
"body": "It way not be part of your problem definition, but the infix notation you currently output is ambiguous. You should consider adding brackets: `\"ABC+*D/\"` => `\"((A*(B+C))/D)\"`"... | [
{
"body": "<p><strong>Make your structs immutable</strong><br>\n<code>TreeNode</code> is a helper structure, with public members, which is fine, but you better make them <code>final</code>, so you know they won't be changed after the object is created.</p>\n\n<p><strong>Choose your validations</strong><br>\nDon... | {
"AcceptedAnswerId": "46897",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T09:00:18.427",
"Id": "46894",
"Score": "5",
"Tags": [
"java",
"algorithm",
"tree"
],
"Title": "Expression tree creation from postfix expression"
} | 46894 |
<p>I have an abstract class that represents data request. The request is in XML format. There are a few classes that derive from abstract class and they do similar things.</p>
<p>Some basic XML operations such as create XML document, write the elements and attributes of XML document and so on are implemented as method... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T10:30:56.527",
"Id": "82091",
"Score": "4",
"body": "The word `Load` is certainly inappropriate since you actually mean `Add` or `Append`."
}
] | [
{
"body": "<blockquote>\n<pre><code>public abstract class MWRequest\n{\n public static string WebServiceURL = \"url\";\n protected XmlDocument xmlDoc = new XmlDocument();\n\n protected MWRequest()\n {\n xmlDoc.LoadXml(\"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?><request/>\... | {
"AcceptedAnswerId": "46933",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T09:44:40.690",
"Id": "46896",
"Score": "9",
"Tags": [
"c#"
],
"Title": "Refactoring class methods to helper class?"
} | 46896 |
<p>I am coding a web based solution which consists of <em>N</em> number of tiers, these are:</p>
<ul>
<li>UI</li>
<li>Web API</li>
<li>Business</li>
</ul>
<p>The question I have is related to validation, repository and CRUD operations. I am adopting the command / query pattern whereby I have my repositories for <stro... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T11:39:30.770",
"Id": "82097",
"Score": "0",
"body": "Are you using an ORM layer like Entity-Framework?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T13:18:56.287",
"Id": "82108",
"Score": "0... | [
{
"body": "<p>I'll address your separate classes for the queries first. I definitely see where you're coming from with this approach and I can dig it, but it gives too much duplication as it is.</p>\n\n<p>I assume you'll have more entities than just <code>Addresses</code> so using your approach, you would have ... | {
"AcceptedAnswerId": "46917",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T10:55:11.917",
"Id": "46899",
"Score": "5",
"Tags": [
"c#",
"validation"
],
"Title": "Amalgamation of the repository and command / query pattern"
} | 46899 |
<p>Please give thoughts and optimization tips on my thread library. </p>
<p><strong>Update 1 :</strong> I have renamed the different method types.</p>
<pre><code>unit AgThread13;
interface
uses
SysUtils, Classes, Windows, Rtti;
type
{$SCOPEDENUMS ON$}
TAgCallType = ( Direct, Synchronize, Queue );
TAgThr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T12:52:57.643",
"Id": "82102",
"Score": "0",
"body": "What's with the Identifier{1,2,3}? Is there really nothing that differentiates those enough for them to warrant their own names?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T11:53:53.660",
"Id": "46902",
"Score": "2",
"Tags": [
"optimization",
"multithreading",
"delphi"
],
"Title": "Optimizing a thread library"
} | 46902 |
<p>Say I have an array with 60 elements, and I want to select 40 elements from this array. The subset should consist of elements with evenly spaced indices. In theory I would need to select every 1.5th point, which is obviously not possible.</p>
<p>I tried doing it with a recursive function, kind of a divide & con... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T14:15:29.963",
"Id": "82133",
"Score": "4",
"body": "This question appears to be off-topic because it is about altering a core functionality of the code, and therefore the code is not considered to be \"working\" (as in \"working as... | [
{
"body": "<p>change all of your integer values to <code>Float</code> variables, for a start. since I assume that you want a Decimal representation for numbers in between two numbers.</p>\n\n<p>if that is not the case and you actually want to select every other number, then you should use a <code>for</code> cod... | {
"AcceptedAnswerId": "46929",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T13:04:59.063",
"Id": "46905",
"Score": "3",
"Tags": [
"array",
"vb.net"
],
"Title": "Select evenly spaced subset from array"
} | 46905 |
<p>I was going through the Project Euler problem #3 and made a program to solve it. The problem is as follows:</p>
<blockquote>
<p>The prime factors of 13195 are 5, 7, 13 and 29. What is the largest
prime factor of the number 600851475143 ?</p>
</blockquote>
<p>My code is as follows:</p>
<pre><code>#include<i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T20:28:54.927",
"Id": "82218",
"Score": "0",
"body": "what do you know about all of the factors you are testing above the square root of n?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-12T01:36:24.873"... | [
{
"body": "<p>This is absolutely fine. By calling only one function in <code>main</code> and letting it handle what it has been asked for, you are achieving the concept of <a href=\"http://en.wikipedia.org/wiki/Abstraction_%28computer_science%29\" rel=\"nofollow\">abstraction</a>, leaving out the unnecessary cr... | {
"AcceptedAnswerId": "46914",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T13:08:32.500",
"Id": "46906",
"Score": "15",
"Tags": [
"c++",
"design-patterns",
"primes",
"programming-challenge"
],
"Title": "Project Euler #3 - largest prime factor"
} | 46906 |
<p>Imagine I have code like this in (it's about the concept; this is example code):</p>
<pre><code># models.py
from django.db import models
class Monster(models.Model):
x = models.FloatField()
y = models.FloatField()
def use_unique_ability(self, target):
''' different monsters types will implement... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T13:50:30.127",
"Id": "82125",
"Score": "0",
"body": "I remove the notice about being off-topic. IMO, having two version of the same code tend to be opiniated, reviewing one version could be better (in fact you could probably have tw... | [
{
"body": "<p>What you want is inheritance as a <a href=\"https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models\" rel=\"nofollow\">proxy model</a>.</p>\n\n<p>In your subclasses, use the following Meta option:</p>\n\n<pre><code>class SlimyMonster(Monster):\n class Meta:\n proxy = True\n\... | {
"AcceptedAnswerId": "47557",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T13:18:25.010",
"Id": "46907",
"Score": "1",
"Tags": [
"python",
"django",
"import"
],
"Title": "Django models: different methods on each instance?"
} | 46907 |
<p>I am working on a price slider that is for a Java environment. It is working correctly but I would like to optimise it as much as possible. Any tips/advice?</p>
<pre><code><div class="wrap">
<div class="range"></div>
<div class="amount min-amount left"></div>
<div class=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-12T10:15:37.190",
"Id": "82300",
"Score": "0",
"body": "Can you put up a demo. I can't seem to get it working."
}
] | [
{
"body": "<p>From a once over;</p>\n\n<ul>\n<li>You are assigning a class to hidden input elements, that does not make sense. Assign an <code>id</code> instead, selection on <code>id</code> is much faster.</li>\n<li><code>ui.values[0]</code> and <code>ui.values[1]</code> use magic sonstants, you should use nam... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T13:36:08.957",
"Id": "46915",
"Score": "4",
"Tags": [
"javascript",
"optimization",
"jquery-ui"
],
"Title": "Price Slider using jQuery UI working in Java environment to be optimis... | 46915 |
<p>Let's compare the following code:</p>
<p>1)</p>
<pre><code>public class MyClass
{
private object syncRoot;
public MyClass()
{
this.syncRoot = new object();
}
...
}
</code></pre>
<p>2)</p>
<pre><code>public class MyClass
{
private object syncRoot = new object();
public MyCla... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T18:53:07.000",
"Id": "82194",
"Score": "0",
"body": "That logger is not consistent with the other fields. Even if you don't inject it (which is a mistake!), since the others are initialized in the constructor, it should also be. `sy... | [
{
"body": "<p>There are no differences between your two options. There are a few remarks we can make about though:</p>\n\n<h1>Consistency</h1>\n\n<p>Keep everything consistent. There are a few reasons to change it up (for example: you can do inline initialization all the time and only initialize those in the co... | {
"AcceptedAnswerId": "46925",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T14:09:21.930",
"Id": "46918",
"Score": "7",
"Tags": [
"c#",
"constructor"
],
"Title": "What is the advantage/disadvantage of using default initializer for private fields?"
} | 46918 |
<p>I was having a hard time with bug <a href="https://logstash.jira.com/browse/LOGSTASH-665" rel="nofollow">logstash#665</a>. Hope they will fix it some day, but sparc/solaris support is probably not on top of their priority list. For further reference, original error is:</p>
<pre><code>NotImplementedError: stat.st_de... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-15T04:59:29.643",
"Id": "82701",
"Score": "0",
"body": "Just to be clear — the bug is that `File::Stat.new('/etc/hosts').dev_minor` would cause JRuby to crash with a `NotImplementedError`?"
},
{
"ContentLicense": "CC BY-SA 3.0"... | [
{
"body": "<p>In Unix filesystems, an inode is a number that uniquely identifies a file within the filesystem. (More strictly speaking, an inode is a data structure that holds metadata about a file within the filesystem; each inode is assigned an inode number, and the number is all you care about unless you're... | {
"AcceptedAnswerId": "47211",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T14:18:43.200",
"Id": "46922",
"Score": "5",
"Tags": [
"ruby",
"file-system",
"solaris"
],
"Title": "Need reviews for impacts of dirty bug fix"
} | 46922 |
<p><a href="http://mochajs.org/" rel="nofollow">Mocha</a> is a feature-rich JavaScript test framework running on node.js and the browser. Mocha allows you to use any assertion library you want, if it throws an error, it will work! This means you can utilize libraries such as <a href="https://github.com/shouldjs/should.... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T14:19:39.327",
"Id": "46923",
"Score": "0",
"Tags": null,
"Title": null
} | 46923 |
<p>I'm experimenting with angular directives, and as a proof of concept I wanted to create a basic tab control. I'd like to know if anything can be changed to be more fluid, or if I'm doing things "right".</p>
<p>Live Example: <a href="http://jsfiddle.net/6wa2x/">http://jsfiddle.net/6wa2x/</a></p>
<p>HTML (with embed... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>It seems both <code><tab name=\"FirstTab\" id=\"Tab1\"></code> and <code><tab ng-repeat=\"tab in tabs\" name=\"{{tab.name}}\" id=\"{{tab.id}}\" selected=\"{{ $index == 1 }}\"></code> will share the id <code>Tab1</code>, that's not good</p></li>\n<l... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T14:27:18.567",
"Id": "46927",
"Score": "7",
"Tags": [
"javascript",
"angular.js"
],
"Title": "AngularJS Tab Control"
} | 46927 |
<p>The purpose of the below code is to build a shape based on the user input, specifically:</p>
<ol>
<li>Prompt the user to enter a shape - either a triangle or a square</li>
<li>Determine which "texture" to use for the shape - currently set at <code>#</code>'s for squares, <code>*</code>'s for triangles</li>
<li>Buil... | [] | [
{
"body": "<p>Ok, so... there's <em>a lot</em> to talk about here. I've simply gone through it line by line, and added comments. So prepare for a pretty long review.</p>\n\n<p>As for the indentation, the reason it's different when you paste it here is probably that you're still using <em>tabs</em>. It should be... | {
"AcceptedAnswerId": "46951",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T14:28:27.763",
"Id": "46928",
"Score": "6",
"Tags": [
"beginner",
"ruby",
"formatting"
],
"Title": "Building shape based on user input"
} | 46928 |
<p>The following code achieves what I require, reading 10000 rows at a time:</p>
<pre><code>var query = repository.Subscribers.ToList().Skip(numberToSkip).Take(numberInBatch);
</code></pre>
<p>Is there an alternative which will make this faster?</p>
<p>Here's the full code:</p>
<pre><code>protected static string Co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-12T03:15:42.347",
"Id": "82280",
"Score": "0",
"body": "A simple way to speed up the `Skip().Take()` LINQ expression is to use `GetRange()` instead. I learnt that the hard way!"
}
] | [
{
"body": "<p>I would first suggest <a href=\"http://msdn.microsoft.com/en-US/data/dn469464\">logging the database operation</a> to see what SQL is executed. EF may not be running the SQL you think it is.</p>\n\n<p><strong>The red flag I see is that you call ToList before the Skip and Take.</strong> Generally... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T16:31:51.380",
"Id": "46940",
"Score": "6",
"Tags": [
"c#",
"performance",
"entity-framework"
],
"Title": "Entity Framework Skip and Take too slow"
} | 46940 |
<p>For full disclosure: this is an assignment for my programming class and I just want tips or advice on some of the code.</p>
<p>Assignment details just for background information purposes:</p>
<blockquote>
<p>Write a program that will read a number 1-100 from the user, and the
name of a data file, and will tell... | [] | [
{
"body": "<ul>\n<li><p>Despite what you may have been taught, you should not get into the habit of using <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\"><code>using namespace std</code></a>, especially when you start writing larger programs.</p></li>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T17:41:35.527",
"Id": "46946",
"Score": "9",
"Tags": [
"c++",
"homework",
"file",
"stream"
],
"Title": "User input and reading contents of file"
} | 46946 |
<p>I tried making a class that handles my header and footer of my site. It looks like a mess, because I like to preserve the indentations as is.</p>
<p>But I'm wondering if there maybe is an even cleaner or better way of writing this class?</p>
<pre><code><?php
class HeadFoot {
protected $title,
... | [] | [
{
"body": "<h1>Separation of Concerns</h1>\n\n<p>You should implement <a href=\"http://en.wikipedia.org/wiki/Separation_of_concerns\" rel=\"nofollow\">Separation of Concerns</a>. In your case, don't mix logic with your view. Follow basic MVC, where M (model) is the data source, V (view) is where your HTML is, a... | {
"AcceptedAnswerId": "46956",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T18:21:38.117",
"Id": "46950",
"Score": "1",
"Tags": [
"php",
"object-oriented",
"html",
"php5"
],
"Title": "Class that handles header and footer includes looks like a mess"... | 46950 |
<p>I've been reviewing my previous projects for the last few days. I've found that I never return an error from any of my methods. I always throw exceptions. I googled about exceptions vs errors and I feel like I should return an error if there's an error.</p>
<p>Please consider my service class from my previous proje... | [] | [
{
"body": "<p>Well, I'd say that, apart from one or two things, you're going about it in exactly the right way.<br>\nA class, and all of its methods process data. If the data supplied poses an exceptional problem (ie, the data is invalid), then an Exception has to be thrown back to the code that passed that dat... | {
"AcceptedAnswerId": "47131",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-11T18:54:19.573",
"Id": "46952",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"exception",
"error-handling"
],
"Title": "Throw exception in favor of an error?"
} | 46952 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.