body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>This PowerShell script works a bit like a one-way <code>rsync</code>; it's good enough for my Surface RT needs, anyway. However, seeing as this is my first PS script, and I was learning the very basics while working on it, I suspect I may have committed many crimes of fashion and/or formatting. Also, it's much, <em>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T04:35:03.803",
"Id": "94318",
"Score": "1",
"body": "Also, goodness me this syntax highlighter needs work."
}
] | [
{
"body": "<p>I haven't gone through your code in detail, but what I've seen looks fine. </p>\n\n<p>I notice you use initial caps for the keywords (e.g. <code>If</code> rather than <code>if</code>, <code>Else</code> rather than <code>else</code>). That doesn't really matter, but it's non-standard, and it makes ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T04:31:28.903",
"Id": "54125",
"Score": "6",
"Tags": [
"performance",
"file-system",
"powershell",
"network-file-transfer"
],
"Title": "A PowerShell script like one-way rsync b... | 54125 |
<p>I have implemented the following scenario for the Mediator pattern sample:</p>
<p><code>MailingListMediator</code>: Manages the subscription and send the mail back and forth. </p>
<ul>
<li><code>JavaMailingList</code> </li>
<li><code>SQLMailingList</code></li>
</ul>
<p>(Colleagues)<code>MailUsers</code>: They ... | [] | [
{
"body": "<p>I am not familiar with the Mediator pattern, but I think your code is not complex enough to make good use of the pattern. Take your <code>JavaMailingList</code> and <code>SQLMailingList</code>, what is the difference between those classes ? The value of <code>mailingListId</code>. The implementati... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T05:43:00.197",
"Id": "54129",
"Score": "5",
"Tags": [
"java",
"design-patterns",
"email",
"mediator"
],
"Title": "Use of mediator design pattern with mailing list implementati... | 54129 |
<p>I've adapted an Instagram widget from this <a href="http://www.refreshi.com/blog/share-instagram-photos-easily" rel="nofollow">example</a> so that it now appends 8 images to their respective IDs using an Instagram username. I want my widget implementation to be better and more efficient. I'm very new to this so I'm... | [] | [
{
"body": "<p>first thing one could spot is this duplications:</p>\n\n<pre><code>size = data.data[0].images.standard_resolution.url;\n $(\"#insta-1\").append(\"<a target='_blank' href='\" + data.data[0].link + \"'><img src='\" + size + \"'></img></a>\");\n size = data.d... | {
"AcceptedAnswerId": "54145",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T08:12:39.060",
"Id": "54136",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"json",
"ajax",
"instagram"
],
"Title": "Instagram widget feed function"
} | 54136 |
<p>This a solution for <a href="https://projecteuler.net/problem=185" rel="nofollow">Project Euler Problem 185</a>. It works fine for the example but slow for the problem statement. How can I improve its speed and efficiency?</p>
<pre><code>import itertools
from collections import defaultdict
def mrange(start, stop, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T11:23:18.437",
"Id": "94356",
"Score": "1",
"body": "These kind of programming problems are designed so that if you have the right time complexity they will be solvable reasonably quickly in any language. As there are 16 digits, the... | [
{
"body": "<p>Instead of recalling the range function for every iteration just call the range function once and save it outside of loop. This would allow you to store the list you are iterating over in memory instead.</p>\n\n<p>this recalculates a list for you len(x)+1 times (redundantly):</p>\n\n<pre><code>te... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T08:35:07.963",
"Id": "54138",
"Score": "7",
"Tags": [
"python",
"mathematics",
"programming-challenge",
"combinatorics"
],
"Title": "Improving efficiency of Project Euler 185 ... | 54138 |
<p>I've written a small script to benchmark our LAMP hosted servers that assess the performance based on three factors:</p>
<ol>
<li>Disk I/O</li>
<li>Database I/O (mysql)</li>
<li>Database I/O (sqlite)</li>
</ol>
<p>The logic is as follows:</p>
<ul>
<li>get the type of test performed using a querystring value.</li>... | [] | [
{
"body": "<p>I'm not to good at optimizing, so I don't think I'm qualified to touch on that aspect.</p>\n<h2>So, formatting I guess,</h2>\n<p>One thing I can say though, is that your code is <em>seriously lacking consistency</em>. Some assignments (<code>$mysqlserver = 'localhost';</code>) you place spaces aro... | {
"AcceptedAnswerId": "54680",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T08:40:24.033",
"Id": "54139",
"Score": "5",
"Tags": [
"php",
"mysql",
"linux",
"sqlite"
],
"Title": "Benchmarking our LAMP servers with this php script"
} | 54139 |
<p>I have written code to solve the following <a href="http://rosalind.info/problems/dna/">Rosalind problem</a>. This is my first time writing in C and I would like a review of my code, particularly in regard to correctness and performance.</p>
<pre><code>#include <stdio.h>
#include <string.h>
int main() {... | [] | [
{
"body": "<p>I am no C programmer but there are a few things that come to my eye:</p>\n\n<h2>Static size</h2>\n\n<p>You always read at most 1000 characters, what if the file size is much bigger? \nInstead you would loop trough the file, reading/processing it chunkwise.</p>\n\n<h2>Magic Number</h2>\n\n<p>Even i... | {
"AcceptedAnswerId": "54144",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T09:01:19.580",
"Id": "54142",
"Score": "11",
"Tags": [
"c",
"beginner",
"bioinformatics"
],
"Title": "Counting DNA nucleotides in C"
} | 54142 |
<p>I've wrote a very simple implementation of Deferred / Promise pattern (inspired by jQuery's <code>$.deferred</code>) for my tiny project (which does not use jQuery)</p>
<p>It can handle multiply <code>onSuccess</code> an <code>onFail</code> callbacks with result caching. Example in comments above the code.</p>
<pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T09:33:24.863",
"Id": "94339",
"Score": "0",
"body": "These things are not \"thenable\" and they don't integrate with other \"thenable\" things, so I don't think it's accurate to call them promises. Looks interesting, though. Will do... | [
{
"body": "<p>A few things caught my eye:</p>\n\n<ul>\n<li>You can call <code>resolve</code> <em>and</em> later call <code>reject</code> too - or the other way around, or call either one multiple times. It should only allow the first resolve/reject call to have an effect.</li>\n<li><code>status</code> might as ... | {
"AcceptedAnswerId": "54154",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T09:03:52.180",
"Id": "54143",
"Score": "2",
"Tags": [
"javascript",
"asynchronous"
],
"Title": "Simple Deferred / Promise pattern in JavaScript"
} | 54143 |
<p>I don't have a lot of experience writing libraries and just recently started thinking a lot about structure and patterns.</p>
<p>I wrote a tiny module manager based on the facade and mediator design patterns and very vaguely based on require.js / AMD and libraries using facade+mediator patterns like jQuery.</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T13:47:14.590",
"Id": "94380",
"Score": "0",
"body": "Why would you `privateMethod.apply(null,a[0])` rather than `privateMethod(a[0])`? Passing `null` as a context is pointless, IMO."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Odd question,</p>\n\n<ul>\n<li><code>arguments.callee</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments/callee\" rel=\"nofollow\">is considered obsolete</a>, it's use will trigger an error in strict mode</li>\n<li>On top you u... | {
"AcceptedAnswerId": "56657",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T11:40:42.853",
"Id": "54150",
"Score": "3",
"Tags": [
"javascript",
"design-patterns",
"modules"
],
"Title": "Decoupling with a self-descriptive mediator function"
} | 54150 |
<p>In my DAL currently I'm handling exceptions as follows. Is it in an acceptable level?</p>
<p>Note : I'm using MVP in this Winforms application.</p>
<pre><code> public bool InsertAccount(IBankAccount ba)
{
string selectStatement = @"IF NOT EXISTS (SELECT ac_no FROM BankAccount WHERE ac_no=@ac_no) BEG... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T17:52:17.580",
"Id": "94454",
"Score": "2",
"body": "Hi there. Adding a new block of code and asking for a second review on the revised code, is not the best way to get your revisions reviewed. We have a [process that works well](ht... | [
{
"body": "<p><strong>Short Answer:</strong> <br/>\nHaving a call to <code>MessageBox.Show()</code> in any DAL code is <em>A Bad Thing (TM)</em>.</p>\n\n<p><strong>Longer Answer:</strong> <br/>\nIn an ideal world, your DAL would not know anything about your presentation layer - not even that it is a Windows/Win... | {
"AcceptedAnswerId": "54156",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T12:29:00.383",
"Id": "54153",
"Score": "7",
"Tags": [
"c#",
".net",
"exception-handling",
"mvp"
],
"Title": "Proper handling of exceptions in MVP"
} | 54153 |
<p>In a question about reimplementing <code>strstr()</code>, I posted an <a href="https://codereview.stackexchange.com/a/54047/9357">answer</a>. I pointed out a need for const- and non-const versions of the function, and provided Implementation A below, which received criticism about the ugliness of the <code>const_ca... | [] | [
{
"body": "<p>I don't like casting away const on a const object.<br>\nThis opens you up to the possibility of maintenance errors.</p>\n\n<pre><code>const char *strstr(const char *input, const char *find)\n{\n return strstr(const_cast<char *>(input), find);\n}\n</code></pre>\n\n<p>Here you are assuming ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T13:06:20.370",
"Id": "54155",
"Score": "5",
"Tags": [
"c++",
"reinventing-the-wheel",
"template-meta-programming",
"comparative-review",
"overloading"
],
"Title": "Providi... | 54155 |
<p>Recently, I encountered an anomaly in the manner by which a worker thread was terminated. It prompted me to do some searching and I realized that I was constructing thread code in a haphazard manner. In hopes of beating this subject to death, I'd like some opinions, please.</p>
<p>The issue is real and serious; the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T01:28:37.570",
"Id": "94395",
"Score": "0",
"body": "Side note: `Join` inside `lock` looks absolutely wrong as it is not \"quick operation\" locks are normally used for."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>I think you definitely have a deadlock here with your use of <code>rapperEnd</code>. The main thread holds a lock on it while waiting for the worker threads to complete, and the worker threads need to acquire the lock in order to end. The problem is that the main thread holds the lock much longe... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T01:15:43.170",
"Id": "54163",
"Score": "3",
"Tags": [
"c#",
"multithreading",
"join",
"locking"
],
"Title": "Moonshot & `Thread.Abort` - dealing with the fallout"
} | 54163 |
<p>I've got this code in my <code>ApplicationHelper</code> file:</p>
<pre><code>def new_button
case controller_name
when 'cars'
"<li class='has-form'><a class='button' href='#{new_car_path}'>New Car</a></li>".html_safe
when 'trucks'
"<li class='has-form'><a class='button'... | [] | [
{
"body": "<p>You can use the name of your current controller to dynamically generate your buttons. Controllers names are plural by convention in Rails, so you will want to get the singular version of your controller name. </p>\n\n<pre><code>singular = controller_name.singularize # get the controller name &... | {
"AcceptedAnswerId": "54172",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T14:57:19.107",
"Id": "54167",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "How would you refactor this case statement?"
} | 54167 |
<p>Assume the following definition:</p>
<pre><code>public class DataPoint {
public DateTime Date { get; private set; }
public double Value { get; private set; }
public DataPoint(DateTime date, double value) { Date = date; Value = value; }
}
</code></pre>
<p>If <code>var points = ... //a date ordered list ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T22:30:41.133",
"Id": "94491",
"Score": "0",
"body": "I would use a foreach loop + a local var"
}
] | [
{
"body": "<p>In my opinion, the <code>Concat</code> part is what's throwing it off. There is a lesser utilized <code>Select</code> overload that provides access to the index, which could be used like so (ignoring the <code>DataPoint</code> part to make a minimal example):</p>\n\n<pre><code>double[] points = ne... | {
"AcceptedAnswerId": "54173",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T15:14:58.783",
"Id": "54168",
"Score": "6",
"Tags": [
"c#",
"linq"
],
"Title": "Simplify LINQ to Create Step Values"
} | 54168 |
<p>This is sort of a follow up to a previous question (<a href="https://codereview.stackexchange.com/q/43439/18427">Do I have any SQL leaks?</a>).</p>
<p>I have changed some things around and am working on a solution where I use Active Directory to gather information about the user rather than use the user table from ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T15:51:39.110",
"Id": "94417",
"Score": "6",
"body": "EEEEK!! Hungarian!!!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T15:52:34.140",
"Id": "94418",
"Score": "0",
"body": "IKR @Mat'sMug... | [
{
"body": "<p>It can be tough, but pretend you're not the developer who wrote this code and try to understand what it does by reading through it. At a quick glance some questions you might ask could be:</p>\n\n<ul>\n<li>What does <code>isValid</code> actually check the validity of?</li>\n<li>What is <code>strIn... | {
"AcceptedAnswerId": "54201",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T15:42:37.430",
"Id": "54174",
"Score": "8",
"Tags": [
"c#",
"validation",
"http",
"url"
],
"Title": "Checking URL validity"
} | 54174 |
<p>I'm a beginner Java student currently learning from <em>Absolute Java</em> 5<sup>th</sup> edition. I think I understand the content well but I am never sure of my style. This code is for a question after the second chapter on defining classes. I haven't learned arrays or recursion yet. </p>
<ul>
<li>Am I following ... | [] | [
{
"body": "<p>General Remark: You have developed a good sense of object oriented approach. Carry on with your good work...</p>\n\n<p>Specific comments:</p>\n\n<ol>\n<li>Change the name <code>FractionClass</code> to <code>Fraction</code></li>\n<li><p>You have defined the <code>toString()</code> method for your f... | {
"AcceptedAnswerId": "54182",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T16:04:38.130",
"Id": "54175",
"Score": "6",
"Tags": [
"java",
"beginner"
],
"Title": "Manipulating Common Fractions"
} | 54175 |
<p><a href="https://github.com/tomilov/quickhull/blob/master/include/quickhull.hpp" rel="nofollow noreferrer">Last version of library</a> (performance has been improved drastically since posting).</p>
<p>I tried to implement the <em>Quick Hull Algorithm</em> for computing the <strong>convex hull</strong> of a finite s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T14:28:26.817",
"Id": "94701",
"Score": "0",
"body": "My greater mistake is to calculate of point orientation relative to hyperplane (`det()` calculation `2/3*d<sup>3</sup>` for each point) instead of simple calculation of hyperplane... | [
{
"body": "<p>None of this exception is needed:</p>\n\n<pre><code>struct bad_geometry\n : std::exception\n{\n\n virtual\n ~bad_geometry() noexcept = default;\n\n bad_geometry() = default;\n\n explicit\n bad_geometry(const char * const _what)\n : what_(_what)\n { ; }\n\n explic... | {
"AcceptedAnswerId": "54208",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T16:35:49.780",
"Id": "54178",
"Score": "5",
"Tags": [
"c++",
"performance",
"algorithm",
"computational-geometry"
],
"Title": "Quick Hull Algorithm implementation for highe... | 54178 |
<p>I have a method in my controller (<code>GetAllPatients</code>/<code>EnrollmentQueue</code>) which does return the correct data (an array of <code>ViewModel</code>s). I'm new in Knockout.js, so it's hard for me to understand how to display this data correctly. Here is my HTML:</p>
<pre><code><table data-bind="vis... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T16:41:57.573",
"Id": "54179",
"Score": "2",
"Tags": [
"javascript",
"mvc",
"ajax",
"knockout.js"
],
"Title": "Correct usage of an MVC pattern in web applictaion"
} | 54179 |
<p>This is a follow up post of my early question "<a href="https://codereview.stackexchange.com/questions/54153/proper-handling-of-exceptions-in-mvp">Proper handling of exceptions in MVP</a>"</p>
<p>So based on the answers I re edited the post and now my exception handling code looks like this...</p>
<p><strong>DAL</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T18:15:04.097",
"Id": "94464",
"Score": "2",
"body": "Instead of catching a meaningful exception and throwing one with an unclear message, I'd just not catch `Exception` in your DAL. Let the exception propagate up the call stack unti... | [
{
"body": "<p>I can follow the reasoning behind the catch and rethrow even if I might not fully agree with it - without a fuller understanding of what you would like to achieve I will not try to offer an alternative.</p>\n\n<p>The only comments I can see at the moment are:</p>\n\n<p><strong>HouseKeeping</strong... | {
"AcceptedAnswerId": "54189",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T18:02:14.407",
"Id": "54186",
"Score": "4",
"Tags": [
"c#",
".net",
"exception-handling",
"mvp"
],
"Title": "Follow Up post: Proper handling of exceptions in MVP"
} | 54186 |
<p>The following example shows how to implement stack by creating user defined <code>push()</code> method for entering elements and <code>pop()</code> method for retrieving elements from the stack. </p>
<pre><code>public class MyStack {
private int maxSize;
private long[] stackArray;
private int top;
public M... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T18:30:06.873",
"Id": "94467",
"Score": "1",
"body": "What happen if I `pop` and the stack is empty ? What if I `push` and the stack was at `maxSize` ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T1... | [
{
"body": "<ul>\n<li>Your code is not thread-safe</li>\n<li>Why do you limit the size of the stack. Instead, you could use a <code>Vector</code> with the same logic, or a <code>Collections.synchronizedList()</code> of an Arraylist.</li>\n<li>And by the way, what's wrong with <code>java.util.Stack</code> (which ... | {
"AcceptedAnswerId": "54209",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T18:28:45.617",
"Id": "54187",
"Score": "3",
"Tags": [
"java",
"stack"
],
"Title": "How is my Java code for stack implementation?"
} | 54187 |
<p>I might have a potential memory leak with my custom control. Do I actually have one?</p>
<pre><code>public interface IAlertable : INotifyPropertyChanged { ... }
public sealed class AlertButton : Button
{
private static readonly DependencyPropertyKey HasAlertPropertyKey = DependencyProperty.RegisterReadOnly("Ha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-17T11:51:42.817",
"Id": "95060",
"Score": "2",
"body": "You are looking for the Weak Event Pattern, where subscribers to events only hold Weak References which allows the publisher of the event to be garbage collected."
}
] | [
{
"body": "<p>Yes, you are correct, in some cases <code>ICommand</code> can leak memory too! Usually it does not happen, because most implementations of <code>ICommand</code> either utilize <code>CommandManager</code> (which uses weak references) or do not care about <code>CanExecute</code> state and therefore ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T19:29:39.113",
"Id": "54191",
"Score": "4",
"Tags": [
"c#",
".net",
"memory-management",
"wpf",
"event-handling"
],
"Title": "Possible memory leak with WPF Custom Control?... | 54191 |
<p>This code will retrieve all records from the database if the id is null or return records by the available id. Is there a way to combine the query instead of having two separate queries?</p>
<pre><code>// retrieve standard orders
let retrieveStdOrders id =
if id = null then
query{
for row... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-18T18:20:13.607",
"Id": "95437",
"Score": "0",
"body": "Have a look at [F# query expressions and composability](http://fpish.net/blog/loic.denuziere/id/3508/2013924-f-query-expressions-and-composability)."
},
{
"ContentLicense"... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T19:41:17.840",
"Id": "54192",
"Score": "3",
"Tags": [
"f#"
],
"Title": "Retrieve records from the database based on a possible id"
} | 54192 |
<p>I have a method that returns a URL to send a user should they pass a login. My problem is two of these links are hard coded one of which is attempting to pass a variable to the model of that controller. My question is two fold:</p>
<p>A. Is this safe
B. Is there a better way to do this without hard-coding things ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T16:01:53.177",
"Id": "94576",
"Score": "0",
"body": "What is stopping anyone from \"saving\" the target URL for later/continued/unauthorized use?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T19:51:... | [
{
"body": "<p>You are correct in feeling uneasy about the hardcoded URLs: I would put them in a config file. </p>\n\n<p>By hardcoding them you will be forced to rebuild the project should you change to a different server while using a configuration file you can change it whenever you want and it will get picked... | {
"AcceptedAnswerId": "54200",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T20:38:20.800",
"Id": "54197",
"Score": "6",
"Tags": [
"c#",
"beginner",
"http"
],
"Title": "Method to determine redirect after login"
} | 54197 |
<p>I'm seeking a general review, but I'm particularly interested in style.</p>
<p>This program gets 2 lists of peptide to spectrum matches, so every spectrum title is linked to a list of 1 or 10 possible peptides and this program checks for an occurrence on both lists. If they do occur on both lists, on what rank of 1... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T22:32:58.023",
"Id": "94492",
"Score": "0",
"body": "I think this is a good case where comments would come in handy, as the problem domain is not too familiar to many people. Also, break individual classes into their own code blocks... | [
{
"body": "<p>Program to an interface. For instance, use <code>List<Object></code> instead of <code>ArrayList<Object></code>. Check out <a href=\"https://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface\">this question</a> for an explanation.</p>\n\n<p>Make your fields... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T21:10:15.987",
"Id": "54199",
"Score": "6",
"Tags": [
"java",
"bioinformatics"
],
"Title": "Comparing 2 lists of peptide to spectrum rankings generated by 2 different algorithms"
} | 54199 |
<p>I have a World Cup fixture app where people can guess the results of the matches. Everything is working great, but each time I update the ranking, it takes 20 minutes for just 3000 users. So there must be something really wrong with this.</p>
<p>These are the tables being used:</p>
<p><strong>Users</strong></p>
<... | [] | [
{
"body": "<p>You are doing a huge amount of work in the inner rankings table.</p>\n\n<p>The most important observations here are:</p>\n\n<ol>\n<li>you are doing a 'group by' on only the user_id column, but the actual columns that are not aggregated are many. This is a bad practice... each column that is not ag... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T22:28:39.700",
"Id": "54207",
"Score": "5",
"Tags": [
"optimization",
"sql",
"mysql"
],
"Title": "How can I optimize this SQL ranking generator query?"
} | 54207 |
<p>I'm extracting the version number from a file like <a href="https://github.com/arbfranklin/h2database/blob/master/src/main/org/h2/engine/Constants.java" rel="nofollow noreferrer">this one</a>. It works, but I find it clumsy and longer than probably needed.</p>
<p>I'd also appreciate some sanity checks as long as the... | [] | [
{
"body": "<p>Since you are only looking for a single occurrence of the variable in the file you could match the whole file at once. For example like this:</p>\n\n<pre><code>version = {->\n def text = file('src/main/org/h2/engine/Constants.java').text\n def extract = {name ->\n nameValue = t... | {
"AcceptedAnswerId": "54742",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T00:37:15.967",
"Id": "54219",
"Score": "4",
"Tags": [
"java",
"beginner",
"parsing",
"groovy",
"grails"
],
"Title": "Parsing version number from a Java source file"
} | 54219 |
<p>Is this intrusive pointer implementation correct? I tried to use the CRTP Pattern to avoid a virtual destructor in my class <code>ReferenceCounting</code> which provides the reference counter.</p>
<p>Is this efficient? </p>
<p>The following things I could not solve yet:</p>
<p>How can I make a conversion between... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T16:24:13.433",
"Id": "94580",
"Score": "0",
"body": "added some new code which is simpler and with some usefull comment to understand the assumptions, and what the functions should actually do"
}
] | [
{
"body": "<p>The copy and swap idiom is easier to write when pass by value.</p>\n\n<pre><code>IntrusivePtr& operator=(IntrusivePtr rhs) // Use pass by value to generate copy.\n{\n rhs.swap(*this);\n return *this;\n}\n</code></pre>\n\n<p>Doing it this way also gives the compiler better opportunities... | {
"AcceptedAnswerId": "54228",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T01:11:25.030",
"Id": "54220",
"Score": "2",
"Tags": [
"c++",
"design-patterns",
"c++11",
"template",
"polymorphism"
],
"Title": "Is this a meaningful Intrusive Pointer ... | 54220 |
<p>I'm looking for a better alternative to replace insert + gsub.</p>
<pre><code>hobbies = "Hobbies: \nsports (basketball, gym), foods (hamburger, steak, pasta), reading, movie, justfortesting((test1, test2), test3)"
print "\n\nBefore: \n\n" + hobbies
counter = 0
for i in 0...hobbies.length do
case hobbies[i]
... | [] | [
{
"body": "<p>How about:</p>\n\n<pre><code>hobbies = \"Hobbies: \\nsports (basketball, gym), foods (hamburger, steak, pasta), reading, movie, justfortesting((test1, test2), test3)\"\nprint \"\\n\\nBefore: \\n\\n\" + hobbies\n\ncounter = 0\nhobbies = hobbies.chars.map do |char|\n next \"\\n\" if char == ',' and... | {
"AcceptedAnswerId": "54224",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T04:00:57.940",
"Id": "54221",
"Score": "0",
"Tags": [
"ruby"
],
"Title": "Replace outside comma with newline"
} | 54221 |
<p>Recent JavaScript student here. I ran afoul of some weirdness with event listeners that led to my code being unresponsive. After some reading and tweaking, I arrived at a version that worked in JSFiddle, but not in the browser. I finally got it working in the browser, but now my code looks like this:</p>
<pre><code... | [] | [
{
"body": "<p>If you place your code in a script tag at the end of the body, right before the <code></body></code> tag, then the code can just be this:</p>\n\n<pre><code>document.getElementById('addChllng').addEventListener('click', function() {\n alert(\"This is a test alert.\");\n});\n</code></pre>\n... | {
"AcceptedAnswerId": "54234",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T06:54:33.807",
"Id": "54229",
"Score": "0",
"Tags": [
"javascript",
"event-handling"
],
"Title": "Does this function have to be nested?"
} | 54229 |
<p>I'm trying to calculate the smallest eigenvalue of the matrix A by using the "inverted exponentiation method" (see the code). I manage to find the smallest eigenvalue, but when I try to optimize the algorithm by using both the MATLAB functions sparse and lu it starts to iterate many more times! The matrix A is a big... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T14:54:07.010",
"Id": "94566",
"Score": "0",
"body": "The eigenvalues of a diagonal matrix are the unique values along the diagonal so why construct such a complex routine for a known case instead of just looping along the diagonal a... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T07:42:06.187",
"Id": "54232",
"Score": "1",
"Tags": [
"matrix",
"matlab"
],
"Title": "Why does lu-factorization make my program slower?"
} | 54232 |
<p>Do I still need to protect my code against SQL injection when I'm not using variables in SQL queries?</p>
<p>Is this code still vulnerable?:</p>
<pre><code>$result = mysqli_query($connect,"SELECT subsubcat_name FROM subsubcategories WHERE subcat_ID = 4");
while ($row=mysqli_fetch_array($result)){
echo $row['subsub... | [] | [
{
"body": "<p>it is not necessary for queries without external variable may have a protection against sql injection because the exploit is from a user or public inputed content only. </p>\n\n<p>Your example is a select query there is no variable from outside so it is OK. </p>\n",
"comments": [],
"meta_d... | {
"AcceptedAnswerId": "54246",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T09:27:34.913",
"Id": "54237",
"Score": "1",
"Tags": [
"php",
"mysqli",
"sql-injection"
],
"Title": "SQL Injection when not using variables"
} | 54237 |
<p>In a few weeks I need to give a workshop about JavaScript to colleagues. They do not have much experience with JavaScript so I will explain the basics of JavaScript. At the end of the day I want them to make a small game with the aspects learned during the day.</p>
<p>I was thinking of Rock Paper Scissors. Below yo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T12:03:04.823",
"Id": "94544",
"Score": "0",
"body": "The definition of the winningMap is very confusing. I suggest a different form of input: `var winningMap = {\"Rock\": \"Scissors\", Paper: \"Rock\", Scissors: \"Paper\"};`. It def... | [
{
"body": "<p><strong>The definition of the winningMap is very confusing.</strong> </p>\n\n<p>I suggest a different form of input: </p>\n\n<pre><code>var winningMap = {Rock: \"Scissors\", Paper: \"Rock\", Scissors: \"Paper\"}; \n</code></pre>\n\n<p>It defines which choice can be beaten by a specific selection. ... | {
"AcceptedAnswerId": "54244",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T11:14:15.503",
"Id": "54240",
"Score": "8",
"Tags": [
"javascript",
"jquery",
"game",
"rock-paper-scissors"
],
"Title": "Rock Paper Scissors in JavaScript"
} | 54240 |
<p>Following is a code snippet from MVP Win Forms application.</p>
<p>My DAL doesn't handle exceptions and it will be propagated up to the calling method in the presenter classes where the exception will be handled. </p>
<p>I'm using a single handler called <code>ExecutAction(Action action)</code> so I'm catching exc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T13:00:30.750",
"Id": "94554",
"Score": "1",
"body": "Consider looking into an aspect-oriented programming approach to exception handling. Castle's dynamic proxy is one lightweight library for this"
},
{
"ContentLicense": "CC... | [
{
"body": "<p>To avoid a discussion in comments I'll go ahead and make my comments an answer.</p>\n\n<p>I think this a much better than your original way. Instead of catching <code>Exception</code> in your DAL, you're allowing all exceptions to propagate up until you can properly handle them. Catching <code>Exc... | {
"AcceptedAnswerId": "54438",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T11:40:18.697",
"Id": "54241",
"Score": "3",
"Tags": [
"c#",
".net",
"exception-handling",
"mvp",
"lambda"
],
"Title": "Exception handling with expression lambda in Pres... | 54241 |
<p>I made a function in jQuery for my home-made grid system. When a <code>row</code> has too many <code>column</code>s in it, it removes the HTML code from that <code>row</code>.</p>
<p>Normally in my grid system it fits 12 columns in 1 row, but with the function this can easily be changed.</p>
<p>One column with the... | [] | [
{
"body": "<p>Things I pondered:</p>\n\n<ul>\n<li>What's with the underscores everywhere?</li>\n<li>Why not use regular jQuery convention and use <code>this</code> instead of <code>element</code> in your <code>each</code> iterator?</li>\n<li>What's the use-case for this? A regular user will never see the consol... | {
"AcceptedAnswerId": "54251",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T15:33:40.383",
"Id": "54249",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery grid-system - handing different row widths"
} | 54249 |
<p>I have two byte arrays that represent unsigned 256-bit values and I want to multiply them resulting into a new value. What is the fastest ways to do this in Java? And are there other factors I should take into account?</p>
<p>This is my current multiply-function:</p>
<pre><code>// two input values
// i.e. each 0x0... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T18:58:43.107",
"Id": "94595",
"Score": "0",
"body": "Multiplying two 32-byte numbers can produce a 64-byte value. Are the inputs actually limited to 128-bit?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-... | [
{
"body": "<p>Your code is somewhat hypothetical, in the example you give, it is 0 * 0, which will be pretty fast....</p>\n\n<p>Still, let's put things in to perspective. You are performing 10 million loops in 1.5 seconds. A modern Intel CPU runs at 3.9GHz. In 1.5 seconds, that's about 6billion cycles (5.85 bil... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T16:05:54.470",
"Id": "54250",
"Score": "6",
"Tags": [
"java",
"performance",
"array"
],
"Title": "Fastest way to multiply two byte arrays in Java"
} | 54250 |
<p>Don't pay attention to the menu being awful above 789px. The "theoretical" task was to support only tablets and smartphones and I didn't bother to make the menu look fine on other devices. Just review it below 789px of VW.</p>
<p>Here's a <a href="http://codepen.io/knitevision1/full/kGhce" rel="nofollow ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T17:17:19.247",
"Id": "94723",
"Score": "0",
"body": "\"How can I do this with less markup?\" is kinda borderline for CR, it really should belong on Stack Overflow."
}
] | [
{
"body": "<h1>Inappropriate use of markup</h1>\n\n<p>You're using paragraphs when you should be using heading tags (h1-h6) to markup your headlines (you also have a spelling error).</p>\n\n<pre><code><p class=\"section-subheader\">We'r Really Into Birds</p>\n</code></pre>\n\n<p>Should be:</p>\n\n<p... | {
"AcceptedAnswerId": "54316",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T16:26:47.167",
"Id": "54253",
"Score": "2",
"Tags": [
"html",
"css",
"html5",
"twitter-bootstrap"
],
"Title": "HTML & CSS code for small responsive test project based on Bo... | 54253 |
<p>I made a word counter. It works as long as there aren't any lone punctuation marks. How could it be improved? (Could it be made simpler? Are the comments detailed/clear enough? etc.) I know it's simple, but I don't want to develop bad habits early on.</p>
<pre><code>#prompt user to input a sentence
toCount = raw_in... | [] | [
{
"body": "<p>Here's one way to simplify it:</p>\n\n<pre><code>inp = raw_input(\"--- \")\n\nprint len(inp.split())\n</code></pre>\n\n<p>I'm not sure if you were unaware of this or if you were <a href=\"/questions/tagged/reinventing-the-wheel\" class=\"post-tag\" title=\"show questions tagged 'reinventing-th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T17:15:21.933",
"Id": "54254",
"Score": "4",
"Tags": [
"python",
"beginner",
"strings",
"python-2.x"
],
"Title": "Word counter script"
} | 54254 |
<p>I have a one function to calculate all the possible <code>widths</code> plus the <code>margins</code> for the gutters. </p>
<p>In this same function, the grid extensions such as the <code>pull</code>, <code>push</code>and <code>offset</code> functions are also calculated.</p>
<pre><code>@function calculate-one-col... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T20:31:01.230",
"Id": "94753",
"Score": "0",
"body": "How is this different from your previous question? http://codereview.stackexchange.com/questions/52360/sass-grid-system-improvements"
},
{
"ContentLicense": "CC BY-SA 3.0... | [
{
"body": "<p>Warning: I am far from an expert with Sass!</p>\n\n<p>I'll list a few things I think could use some re-factoring.</p>\n\n<hr>\n\n<p>We can DRY out your code. In the main function, I see <code>$each-column + $each-gutter</code> three times. Create a variable and assign the variable the sum.</p>\n\n... | {
"AcceptedAnswerId": "54975",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T17:21:32.497",
"Id": "54255",
"Score": "6",
"Tags": [
"css",
"sass"
],
"Title": "Grid column size calculation"
} | 54255 |
<p>I want to calculate the ratio of intersection between two intervals; the length of the intersection divided by the length of the shorter interval.</p>
<p>If two intervals do not intersect, the ratio is 0. If one interval is fully contained in the other, the ratio is 1, otherwise it is a number between 0 and 1.</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T20:15:17.477",
"Id": "94606",
"Score": "0",
"body": "One case missing from your examples is an interval that loops around and passes the lower bound. Is `(-10, 370)` equivalent to `(-10, 10)` or will it force a ratio of 1 for all ot... | [
{
"body": "<p>Algorithm wise it looks quite good but I feel you could benefit from the single responsibility principle.</p>\n\n<p>First thing that would get on my nerves would be passing the intervals in \"non atomic form\" e.g.:</p>\n\n<pre><code>double IntervalIntersectionRatio(double i1Start, double i1End, d... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T17:36:30.853",
"Id": "54257",
"Score": "15",
"Tags": [
"c#",
"algorithm",
"computational-geometry",
"interval"
],
"Title": "Calculate the intersection between two intervals on... | 54257 |
<p>I have a function that iterates through a block, tests each value against a given function and is placed in a block associated with the product of that function.</p>
<pre class="lang-none prettyprint-override"><code>CATEGORIZE items test
</code></pre>
<p>An example:</p>
<pre class="lang-none prettyprint-overrid... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T15:33:15.833",
"Id": "94708",
"Score": "0",
"body": "This is a hybrid function that works on both Rebol 2 and Rebol 3. Answers that reflect improvement on how the function works on Rebol 2, Rebol 3 or as hybrid are welcome!"
}
] | [
{
"body": "\n\n<p>It's a useful function, and exists in underscore.js as <a href=\"http://underscorejs.org/#groupBy\" rel=\"nofollow\">groupBy</a>. So I'd probably call it <code>group-by</code>. It might be useful to go function by function in underscore and use their names, possibly even putting them in the ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T17:50:07.093",
"Id": "54260",
"Score": "5",
"Tags": [
"sorting",
"rebol"
],
"Title": "Rebol Function to Categorize Items in a Block"
} | 54260 |
<p>I have the following MATLAB Code which I want to optimize.<br>
It's related to an image matrix (2D) which I want to filter.<br>
Though it is MATLAB code, the same problem would arise in C code.</p>
<p>The problem is that I'm trying to access neighbors of the pixel which might cause problems at the boundaries of the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:21:31.370",
"Id": "94905",
"Score": "0",
"body": "Why are you doing the `if(mod((iRowIdx + iColIdx), 2) == 0)` near the top? Is that part of the filter? Could you describe the filter in words?"
},
{
"ContentLicense": "C... | [
{
"body": "<h1>visiting black chess board squares</h1>\n\n<p>You might do a mod2 pre-calculation of <code>mod(iRowIdx + iColIdx, 2)</code> by creating a chess board boolean matrix before the loop, using matrix operations.</p>\n\n<p>But much better would be to step <code>iColIdx</code> by 2. And have <code>iRowI... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T18:51:49.733",
"Id": "54262",
"Score": "3",
"Tags": [
"performance",
"image",
"matrix",
"matlab"
],
"Title": "Avoiding Boundaries `if` Cases When Filtering Image Matrix"
} | 54262 |
<p>Whenever I needed something similar like a "Class" in JavaScript, I wrote it like this:</p>
<pre><code>function Point(x, y){
var self = this;
self.x = x;
self.y = y;
self.dist = function(){
return Math.sqrt( (self.x*self.x) + (self.y*self.y) );
}
}
var p = new Point(10, 20);
p.x = 30;
a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T19:31:45.377",
"Id": "94597",
"Score": "3",
"body": "This question seems offtopic, and there many duplicates on StackOveflow. Bottomline, the first one duplicates methods for each new instance, while the second one shares prototype ... | [
{
"body": "<ol>\n<li><p>Using prototype is useful for polymorphism. If you want to create another class, eg. <code>ColourfulPoint</code>, you can use this code:</p>\n\n<p><code>ColourfulPoint.prototype = Object.create(Point.prototype);</code></p>\n\n<p>to make your new class inherit all the methods of <code>Poi... | {
"AcceptedAnswerId": "54295",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T19:28:37.350",
"Id": "54263",
"Score": "0",
"Tags": [
"javascript",
"prototypal-class-design",
"typescript"
],
"Title": "Class-Definition Comparison"
} | 54263 |
<p>I wrote this program:</p>
<pre><code>#include <stdio.h>
#define printS for(i=0;s[i];i++){printf("%c",s[i]);}
int i;
char s[] = "Hello World!\n";
void main()
{
printS;
}
</code></pre>
<p>It outputs exactly what I want it to but I have no clue if this would be acceptable to use if I were working for a comp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T19:34:57.063",
"Id": "94598",
"Score": "7",
"body": "Curios why you would ask this. Why would you use a macro like that? IS there a reason for using that technique over a normal function?"
},
{
"ContentLicense": "CC BY-SA 3.... | [
{
"body": "<ul>\n<li><p>Although the C standard <em>can</em> allow <code>void main()</code> under certain implementations, it's best to use <code>int main()</code> whenever possible. See <a href=\"https://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c\">this</a> for more info on the retu... | {
"AcceptedAnswerId": "54265",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T19:28:57.253",
"Id": "54264",
"Score": "12",
"Tags": [
"c",
"beginner",
"io",
"macros"
],
"Title": "Validity of macro for printf() call in a corporate environment"
} | 54264 |
<p>I have to generate the unique key having a length of 8, which should be comprised of some set of characters:</p>
<blockquote>
<pre><code>{B,C,D,F,G,H,J,K,L,M,N,P,Q,R,S,T,V,W,X,Y,Z,2,3,4,5,6,7,8,9}
</code></pre>
</blockquote>
<p>Now I have written a program that will generate it, but I am not sure it will generate ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T20:51:39.127",
"Id": "94615",
"Score": "1",
"body": "Why an 8 character set? This problem has been solved in the way of GUIDs already. (Granted, they're larger and not 100% guaranteed of being unique, but I promise you it's a better... | [
{
"body": "<p>It looks from the data as if you do not need the numbers to be random, only unique. <br />\nA solution is to take the numbers from 1 to 1,000,000 but output them in base 29 using the allowed characters.</p>\n\n<pre><code>private static readonly char[] Values = {\n 'B', 'C', 'D', 'F', 'G', '... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T20:07:14.927",
"Id": "54268",
"Score": "7",
"Tags": [
"c#"
],
"Title": "Unique key having length of 8"
} | 54268 |
<p>For a homework assignment, I made a web page that has a text area. The user inputs some text, hits the analyse button, and the output is supposed to be a list of the frequency of words of a given number of characters.</p>
<p>For example, "one two three" would be two words of three characters and one word of five ch... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T20:28:37.813",
"Id": "94609",
"Score": "0",
"body": "Quick regexp tips: `\\w` is equivalent to `[A-Za-z0-9_]` and thus `\\d` is unnecessary. Did you intend to allow words with underscores? Any single-element grouping can be replaced... | [
{
"body": "<p>Here's a different approach, using the DOM instead of innerHTML, and using document fragments to append all at once and improve performance. Also you don't need that many regex, specially if you're copy/pasting them; splitting by any whitespace character and removing empty elements from the result... | {
"AcceptedAnswerId": "54275",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T20:08:21.923",
"Id": "54269",
"Score": "6",
"Tags": [
"javascript",
"strings",
"homework"
],
"Title": "Text Analysis web page"
} | 54269 |
<p>This was my first attempt at making a C++ calculator. The user basically inputs an expression (I'll use \$1+1*(9*(11-1))\$ as an example) and the program searches for and creates a vector for parentheses (which is a class I made which records its position in the string).</p>
<p>String:</p>
<blockquote>
<pre><code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T21:32:28.220",
"Id": "94625",
"Score": "1",
"body": "For anyone who intends to answer, I'm aware of the fact that the program doesn't check to see if the number of opening and closing parentheses are equal and that it doesn't suppor... | [
{
"body": "<p>There's a lot that can be reviewed here, but I'll mention some best-practices at a glance:</p>\n\n<p>Keep your indentation and whitespace consistent! You seem to be primarily using four spaces for indentation, but you don't do this everywhere. What's even odd is that the body of <code>evaluate()... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T21:02:57.697",
"Id": "54273",
"Score": "11",
"Tags": [
"c++",
"console",
"calculator",
"math-expression-eval"
],
"Title": "Simple C++ calculator which follows BOMDAS rules"
} | 54273 |
<p>In JavaScript, any function is basically an object on which you can call (<code>function(){}).toString()</code> to get it's underlying code as a string. </p>
<p>I'm working on a function aimed to do the job in PHP. The intended goal is to convert code from PHP into other languages, such as JavaScript. </p>
<p>It l... | [] | [
{
"body": "<blockquote>\n <p>It relies on the undocumented-yet class, ReflectionFunction</p>\n</blockquote>\n\n<p><code>ReflectionFunction</code> is <a href=\"http://php.net/manual/en/class.reflectionfunction.php\">not undocumented</a>.</p>\n\n<blockquote>\n <p>Fails if it can't read its own source files</p>\... | {
"AcceptedAnswerId": "54282",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-14T23:42:21.567",
"Id": "54278",
"Score": "5",
"Tags": [
"javascript",
"php",
"strings",
"functional-programming",
"converting"
],
"Title": "Converting any PHP function to... | 54278 |
<p>This tag is for code that aims to parse (and possibly evaluate) strings, lists, or streams that represent mathematical expressions, such as</p>
<pre><code>"1 + 1 / sqrt(x)"
</code></pre>
<p>Such expressions are typically meant to be interpreted according to the customary <a href="http://en.wikipedia.org/wiki/Order... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T05:49:31.263",
"Id": "54285",
"Score": "0",
"Tags": null,
"Title": null
} | 54285 |
Questions related to the parsing (and possibly the evaluation) of free-form mathematical expressions in strings, lists, or streams | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T05:49:31.263",
"Id": "54286",
"Score": "0",
"Tags": null,
"Title": null
} | 54286 |
<p>I'm trying to make my ASP.net Web API methods asynchronous. This method is in the Business Logic layer of my N-tier. I'm waiting for the result from my 1<sup>st</sup> task and use it on the 2<sup>nd</sup> task, but I think I'm doing it in a wrong way. Can you please give me advice or feedback regarding my code?</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T08:28:59.303",
"Id": "94673",
"Score": "0",
"body": "Given the addition of the Add to the question do you have a SaveChangesAsync method? Not sure what DAL you are using but there is one in Entity Framework"
},
{
"ContentLi... | [
{
"body": "<p>To me it seems like you are trying to make a async task for the sake of making it async to fit in with.</p>\n\n<blockquote>\n <p>I'm trying to make my ASP.net Web API methods asynchronous</p>\n</blockquote>\n\n<p>I don't see any reason for these pieces of code to be async. They aren't doing long... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T05:51:07.183",
"Id": "54287",
"Score": "2",
"Tags": [
"c#",
"asynchronous",
"async-await"
],
"Title": "Async method with multiple tasks"
} | 54287 |
<pre><code>import java.util.Arrays;
public class BinarySearch {
// this class should not be instantiated
private BinarySearch() { }
// searches for the integer key in the sorted array a[]
// @param key the search key
// @param a the array of integers, must be sorted in ascending order
// @return index o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T10:27:54.710",
"Id": "94683",
"Score": "1",
"body": "You should use javadoc comments on your methods."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T10:41:28.300",
"Id": "94684",
"Score": "2"... | [
{
"body": "<p>Your implentation can search integers, we expect to search in an array of any comparable objects.</p>\n\n<p>I think you have a bug if the element is not found. It will return 1 instead of -1 / throwing an exception. Add unit tests.</p>\n\n<p>Also, Java is now open source, you can compare your imp... | {
"AcceptedAnswerId": "54297",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T07:11:03.603",
"Id": "54290",
"Score": "1",
"Tags": [
"java",
"algorithm",
"reinventing-the-wheel",
"binary-search"
],
"Title": "Is this a reasonable binary search implemen... | 54290 |
<p>I'm using this code in an app that has hundreds of daily users. The code works, and passes all of the test cases I have.</p>
<p>Occasionally some users report a problem that I don't get right to the bottom of, and there is a possibility it is related to this PermaDict. Can you see anything I may have missed in ter... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-21T22:28:55.553",
"Id": "278384",
"Score": "2",
"body": "If these permadicts are shared across threads or users, you may have a problem with one thread or user stomping on the state of the other."
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>This is overall look quite good for me. I personally prefer <code>\"\"\"</code> for comments.</p>\n\n<hr>\n\n<h2>Dependency Injection</h2>\n\n<p>Problem I see with <code>PermaDict</code> is that it needs to know about <code>json/pickle/csv</code> <code>load</code> and <code>dump</code> methods. Th... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-06-15T07:20:30.883",
"Id": "54291",
"Score": "15",
"Tags": [
"python",
"hash-map"
],
"Title": "Persisted Dictionary Implementation"
} | 54291 |
<p>I have a Makefile that is used to automatically process some image files. The basic idea behind this is</p>
<ul>
<li>copy everything from <code>col-noborder</code> and <code>col-rewnew</code> to <code>col</code></li>
<li>use ImageMagick <code>convert</code> to copy the files from <code>col-addborder</code> to <code... | [] | [
{
"body": "<h2>Overview</h2>\n\n<p>As I understand it, you want use GNU Make to do…</p>\n\n<ul>\n<li><code>content/part?/raster/bw/*</code> — the ultimate goal\n<ul>\n<li><code>content/part?/raster/col/*</code> — a staging place before conversion to grayscale\n<ul>\n<li><code>content/part?/raster/col-addborder/... | {
"AcceptedAnswerId": "54299",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T07:30:15.113",
"Id": "54292",
"Score": "2",
"Tags": [
"image",
"makefile",
"make"
],
"Title": "Makefile for automatically processing image files"
} | 54292 |
<p>I have a function to load the resource identified by a <code><script></code> element's <code>src</code> attribute.</p>
<p>I need it to:</p>
<ul>
<li>Be as universal as possible.</li>
<li>Work on file-to-file requests (from <code>file://</code> to <code>file://</code>), if the browser allows to.</li>
</ul>
<... | [] | [
{
"body": "<p>The code looks well-formed. I'd like some comments though and maybe a bit of whitespace here and there.</p>\n\n<p>However, I think there's a good chance this will actually fail. <code>readystatechange</code> fires several times during the lifetime of an XHR object. But your code doesn't actually c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T07:37:55.070",
"Id": "54293",
"Score": "11",
"Tags": [
"javascript",
"html",
"ajax"
],
"Title": "Loading the resource identified by a script element's src attribute"
} | 54293 |
<p>I had asked earlier for <a href="https://codereview.stackexchange.com/questions/51645/adding-deleting-elements-as-per-autocomplete-results">review</a> of parts of my JS file <a href="https://codereview.stackexchange.com/questions/52742/adding-deleting-elements-as-per-autocomplete-results-updated">earlier</a> and <a ... | [] | [
{
"body": "<p>I guess people are not too keen on this. I will add my own two cents which came to my mind and which I have added to the code. If anyone is interested they can see the code at <a href=\"https://github.com/anshbansal/Bookmarker/tree/master/static/BookMarker/js\" rel=\"nofollow\">my github</a>.</p>\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T14:49:28.240",
"Id": "54306",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Personal Project for managing my Bookmarks - v2"
} | 54306 |
<p>I made a class that connects to my DB and inserts some values. Is it secure or how can I protect this further from injections? The object declaration will come from variables with POST from a form, after being validated, ofc. Just want to know if this is secure.</p>
<p>That, and also, should I make a method for eve... | [] | [
{
"body": "<h3>What you did well</h3>\n\n<ul>\n<li>Storing sensitive information, such as the database connection parameters, separately from the source code is a good idea.</li>\n<li>You used parameterized queries with placeholders, which are not vulnerable to SQL injection.</li>\n</ul>\n\n<h3>Things to work o... | {
"AcceptedAnswerId": "54318",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T16:24:33.650",
"Id": "54311",
"Score": "4",
"Tags": [
"php",
"sql",
"mysql",
"sql-injection"
],
"Title": "Injections and query"
} | 54311 |
<p>I often write different applications in C++ using different libraries, and sometimes it takes a lot of time to find where are the <code>*.dll</code> files to distribute. I use Dependency Walker but it still takes a lot of time to look in the GUI. I wrote a PowerShell script that will find all used libraries and do s... | [] | [
{
"body": "<p>You can replace all this:</p>\n\n<pre><code>function likeAnyOf($obj,$array)\n{\n foreach($item in $array) \n { \n if($obj -like $item) \n {\n return $item\n } \n }\n return $null\n}\n\n# ...\n\n$excluded = likeAnyOf $moduleParent (Resolve-Path $Exclude)\... | {
"AcceptedAnswerId": "54331",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T16:50:10.257",
"Id": "54315",
"Score": "6",
"Tags": [
"powershell"
],
"Title": "PowerShell script to automate the search of DLL files"
} | 54315 |
<p>This is my Cython code for an FDCT function (invoked <a href="https://github.com/fish2000/pylire/blob/master/pylire/process/color_layout.py#L168-170" rel="nofollow">here</a>):</p>
<pre><code>from __future__ import division
import numpy
cimport numpy
cimport cython
FLOAT64 = numpy.float64
ctypedef numpy.int_t INT... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-01T09:16:08.020",
"Id": "97881",
"Score": "3",
"body": "Can you explain why your goal is to \"match the output of the original Java code, warts and all\"? What is the underlying requirement here? What's wrong with [`scipy.fftpack.dct`]... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T20:55:44.273",
"Id": "54324",
"Score": "3",
"Tags": [
"python",
"numpy",
"cython",
"signal-processing"
],
"Title": "Cythonized version of FDCT (fast discrete cosine transform)... | 54324 |
<p>I did two methods to determine if an <code>unordered_set</code> is a subset of another <code>unordered_set</code>, using hashing, and the built-in <code>includes()</code>.</p>
<p>I want to see if using a hash function will improve the run time, but I've noticed that there is no really big different in their time, s... | [] | [
{
"body": "<p>I just have one nitpick, not related to your primary request.</p>\n\n<p>You don't need to declare these first:</p>\n\n<blockquote>\n<pre><code>float time1, time2;\n</code></pre>\n</blockquote>\n\n<p>Variables should be declared or initialized as close in scope as possible. This will ease maintena... | {
"AcceptedAnswerId": "54354",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T21:20:26.673",
"Id": "54326",
"Score": "6",
"Tags": [
"c++",
"performance",
"c++11",
"stl",
"set"
],
"Title": "Using includes() vs. hash function to check if an unorder... | 54326 |
<p>I wanted to have a way to be able to <code>static_cast</code> to the proper derived type pointer of a base class to simulate a virtual call. Here the virtual call is for a reference counting base class:</p>
<pre><code>template<typename TDerived> class ReferenceCounting
</code></pre>
<p>which should call ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T22:09:41.570",
"Id": "94765",
"Score": "0",
"body": "added compilable test code"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T23:32:34.087",
"Id": "94774",
"Score": "1",
"body": "This do... | [
{
"body": "<p>I have some causes for concern regarding this pattern.</p>\n\n<p>For example:</p>\n\n<pre><code>class C : public B {\n int* ptr;\n}\n</code></pre>\n\n<p>Forgetting to inject the CRTP parameter into a class that requires it will not give a compile error. It may not even give a run-time error. In... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T21:51:30.887",
"Id": "54328",
"Score": "10",
"Tags": [
"c++",
"design-patterns",
"inheritance",
"polymorphism",
"c++14"
],
"Title": "Static Multilevel Inheritance with CRT... | 54328 |
<p>Since one month, I'm learning Erlang and I like it so much.
Today, I wrote an algorithm to solve a problem.
Some time ago, I used two nested <code>for</code> loops in C# to solve it but, solving the same problem in Erlang, I asked myself if there is a better way to write something similar to the two nested <code>for... | [] | [
{
"body": "<p>In general, nested for loops translate well to <a href=\"http://en.wikibooks.org/wiki/Erlang_Programming/List_Comprehensions\" rel=\"nofollow\">list comprehensions</a>:</p>\n\n<pre><code>Prods = [I*J || I <- lists:seq(100,999), J <- lists:seq(100,999)]\n// Generates a list of products to per... | {
"AcceptedAnswerId": "54330",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T22:03:19.447",
"Id": "54329",
"Score": "3",
"Tags": [
"functional-programming",
"optimization",
"erlang"
],
"Title": "Is there a better way to write these two nested loops in E... | 54329 |
<p>The purpose of this is to prevent a re-entrant function call in a single thread, e.g. prevent the situation where <code>func()</code> calls <code>bar()</code> which calls <code>func()</code>.</p>
<p>This is currently not used in any multithreaded code (and does not plan to be).</p>
<pre><code>struct TranLock
{
sta... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T06:56:03.233",
"Id": "94799",
"Score": "0",
"body": "Why not just a static variable inside the function?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T07:17:06.860",
"Id": "94801",
"Score": ... | [
{
"body": "<p>The obvious problem with this is it will detect any function that uses <code>TranLock</code> calling any other function that also uses <code>TranLock</code> (since there is only a single global <code>count</code>). That is, if <code>func()</code> (which uses <code>TranLock</code>) calls <code>bar(... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T01:33:39.460",
"Id": "54333",
"Score": "6",
"Tags": [
"c++",
"c++11",
"locking"
],
"Title": "Prevent re-entrant function call in C++"
} | 54333 |
<p>I am new to programming, and am using Python to take wind data and simulate future wind profiles. The code as written takes a while to execute and I was hoping someone could suggest ways to make my code more efficient...</p>
<pre><code>from __future__ import division
import pandas as pd
import numpy as np
import ma... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T02:55:51.623",
"Id": "94786",
"Score": "0",
"body": "This is quite impressive for someone who's \"new to programming\"! Good job, I'm anxious for a good review"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "201... | [
{
"body": "<p>A couple of observations:</p>\n\n<p>You can factor out the initialisation step:</p>\n\n<pre><code>BV_5min = pd.Series(np.empty(length*4) * np.nan)\n...\n</code></pre>\n\n<p>To:</p>\n\n<pre><code>empty_array = np.empty(length*4)\nempty_array[:] = np.nan\n\nBV_5min = pd.Series(empty_array)\n...\nBV_... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T02:29:30.843",
"Id": "54337",
"Score": "7",
"Tags": [
"python",
"performance",
"beginner",
"numpy",
"simulation"
],
"Title": "Taking wind data and simulating future wind p... | 54337 |
<p>This code builds template .cpp, .c, .h and .java files based on a file name and #include, import lines provided at the command line. The file opens after creation.</p>
<p>I am looking for a review of this code and seeing if there is anything that can be more efficient. </p>
<pre><code>/* .cpp Example:
* templa... | [] | [
{
"body": "<ul>\n<li><p>Do not use <code>using namespace std;</code>, instead explicitly use <code>std::</code> where required. [<a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">Why is “using namespace std;” considered bad practice?</a>]</p></li>\n<li><p... | {
"AcceptedAnswerId": "54341",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T02:55:08.900",
"Id": "54339",
"Score": "16",
"Tags": [
"c++",
"template"
],
"Title": "Creating .cpp, .c, .h. and .java file templates"
} | 54339 |
<p>It's been a while since I've been properly grilled about my code.</p>
<p>I had this Idea which should probably never make it into production code but still I couldn't find anything seriously wrong with it at a glance...</p>
<p>All your comments are welcome.</p>
<pre><code>#ifndef BITFIELDMEMBER_H
#define BITFIELD... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-10-18T19:48:13.410",
"Id": "338271",
"Score": "0",
"body": "there's a blog post with the same code here http://blog.codef00.com/2014/12/06/portable-bitfields-using-c11/. Is this yours? It mentions UB, but does not specify where and what k... | [
{
"body": "<p>Your code is good, except for two methods : <code>operator unsigned() const</code> and <code>self_t& operator=(unsigned m)</code>. They are too complex, and by just looking at them, it is far from clear what they are doing.</p>\n\n<p>First, you can add new values to your enum :</p>\n\n<pre><co... | {
"AcceptedAnswerId": "54344",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T04:37:47.023",
"Id": "54342",
"Score": "10",
"Tags": [
"c++",
"template",
"bitwise"
],
"Title": "Template for endianness-free code, data always packed as BIG-Endian"
} | 54342 |
<p>So I have recently tried to load an image and save it, but remove all of a certain color. I'm running the program and it is running really slow, is there a more efficient way to edit an image? My code is pasted below, or at least all that is relevant.</p>
<pre><code>for x in range(50):
im = pygame.image.load("h... | [] | [
{
"body": "<p>You have a bug:</p>\n\n<pre><code>((im.get_size(), pygame.SRCALPHA)\n</code></pre>\n\n<p>You have one too many <code>(</code>'s.</p>\n\n<hr>\n\n<p>Where did the number 50 come from in the <code>range</code> call?</p>\n\n<p>Don't use magic numbers; set and use a variable, probably called <code>pict... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T05:15:53.450",
"Id": "54343",
"Score": "7",
"Tags": [
"python",
"performance",
"image",
"pygame"
],
"Title": "Editing Surfaces Removing Color"
} | 54343 |
<p>Let's say you have two lists of vectors:</p>
<pre><code>v1s = [a, b, c]
</code></pre>
<p></p>
<pre><code>v2s = [d, e, f]
</code></pre>
<p>I am interested in generating the following result: </p>
<blockquote>
<pre><code>angles = [angleBetween(a, d), angleBetween(b, e), angleBetween(c, f)]
</code></pre>
</blockqu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T07:11:38.667",
"Id": "94800",
"Score": "2",
"body": "Is the middle term `angleBetween(b, d)` or `angleBetween(b, e)`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T07:19:12.123",
"Id": "94802",
... | [
{
"body": "<p>Here's a way of packing the calculation into on call to <code>einsum</code>.</p>\n\n<pre><code>def findAnglesBetweenTwoVectors1(v1s, v2s):\n dot = np.einsum('ijk,ijk->ij',[v1s,v1s,v2s],[v2s,v1s,v2s])\n return np.arccos(dot[0,:]/(np.sqrt(dot[1,:])*np.sqrt(dot[2,:])))\n</code></pre>\n\n<p>f... | {
"AcceptedAnswerId": "54413",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T07:00:17.700",
"Id": "54347",
"Score": "7",
"Tags": [
"python",
"optimization",
"numpy",
"computational-geometry"
],
"Title": "Calculating \"element-wise\" the angles betwe... | 54347 |
<p>I have code that needs to exit gracefully. To simplify things, I am presenting an example based on the answer given <a href="https://stackoverflow.com/questions/18114560/python-catch-ctrl-c-command-prompt-really-want-to-quit-y-n-resume-executi">here</a>.</p>
<p>Since I need to handle a few signals, I thought of put... | [] | [
{
"body": "<p>You can avoid the global by passing the original handler as function parameter and binding it with a lambda in <code>set_signals</code>:</p>\n\n<pre><code>def exit_gracefully(signum, frame, original_sigint):\n#...\n\ndef set_signals():\n original_sigint = signal.getsignal(signal.SIGINT)\n bo... | {
"AcceptedAnswerId": "54350",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T07:33:05.143",
"Id": "54348",
"Score": "9",
"Tags": [
"python",
"scope"
],
"Title": "Handling signals in Python inside a function"
} | 54348 |
<p>I have two methods that are near-perfect duplicates. There is of course a code smell. The only thing that changes is the condition to increment a variable.</p>
<p>Language: Java7</p>
<pre><code>private int pathsDFS(int currentDepth, int maxDepth, Airports s, Airports e, Predicate predicate) {
int counter = 0;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T08:52:31.060",
"Id": "94814",
"Score": "0",
"body": "These methods are in the same class or in different classes?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T08:59:16.070",
"Id": "94816",
... | [
{
"body": "<p>Just add a parameter <code>boolean incrementOnAnyDepth</code> and in your if condition write</p>\n\n<pre><code>if ( x.getDestination() == e && (incrementOnAnyDepth || currentDepth == maxDepth) )\n{\n counter++;\n}`\n</code></pre>\n",
"comments": [
{
"ContentLicense": "... | {
"AcceptedAnswerId": "54359",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T08:05:54.417",
"Id": "54351",
"Score": "1",
"Tags": [
"java",
"design-patterns",
"depth-first-search"
],
"Title": "Code duplication for just an if condition"
} | 54351 |
<p>I am trying to write a jQuery Plugin from a piece of JS code I had written. What this plugin does is it converts a select box into a map of Australia where I can select individual states. It's working perfectly well. However, I'd like to know how I can write it with OOP principles like SOLID etc. can someone review... | [] | [
{
"body": "<p>This plugin looks like an attempt to reinvent <a href=\"http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.6\" rel=\"nofollow\">image maps</a> using a canvas. Most of this code could be eliminated in favour of techniques that were available in 1997.</p>\n",
"comments": [
{
... | {
"AcceptedAnswerId": "54360",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T09:02:14.833",
"Id": "54353",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"image",
"canvas"
],
"Title": "Writing my own jQuery plugin"
} | 54353 |
<p>I was tasked with creating a script to be able to rename some files and then move them into different folders based on a code in the filename.</p>
<pre><code>import os
import shutil
path = (r"C:\user\reports")
filelist = [ f for f in os.listdir(path) if f.endswith(".xml") ]
for f in filelist:
x = os.path.joi... | [] | [
{
"body": "<h2>Don't reinvent the wheel</h2>\n\n<p>For getting the files with a specific extension you should use <a href=\"https://docs.python.org/2/library/glob.html#glob.glob\"><code>glob</code></a>:</p>\n\n<pre><code>xmlFiles = glob.glob('*.xml')\n</code></pre>\n\n<p>(Note that this will work relative to th... | {
"AcceptedAnswerId": "54357",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T09:13:33.203",
"Id": "54355",
"Score": "5",
"Tags": [
"python",
"strings",
"python-2.x",
"file"
],
"Title": "Manipulating filenames using Python"
} | 54355 |
<p>I've wrote some code to create a grid of data, however depending on the size of the grid being drawn, IE8 shows a warning message about a long running script.</p>
<p>I've read that multiple appends are a slow way of drawing a table, so I'm trying to concatenate a string and append it once at the end. I've been usin... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T09:28:07.840",
"Id": "54356",
"Score": "1",
"Tags": [
"javascript",
"performance",
"jquery"
],
"Title": "Optimizing jQuery table building by replacing appends with string concat"
... | 54356 |
<p>The script creates a simple app with a GUI containing an input field and a button to select a folder. On startup a default value is set to the input field. If the user types a value or selects a folder, the new value is stored and validated. If validation fails, the input field value is appended with the error messa... | [] | [
{
"body": "<p>First off, the way you've named your functions is wrong, according to <a href=\"https://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a>. Functions and variables should be in <code>snake_case</code>, and classes should be in <code>CamelCase</code>.</p>\n\n<p>Secondly, rather than crea... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T10:17:44.657",
"Id": "54361",
"Score": "11",
"Tags": [
"python",
"design-patterns",
"mvc",
"file-system",
"tkinter"
],
"Title": "Creating an app for selecting a folder"
} | 54361 |
<p>I've written a piece of code which combines given letters in groups of <em>n</em> letters, and writes all the combinations in a text file. This is my first attempt and I wonder if there is an optimal way to do this.</p>
<pre><code>letter_input = raw_input(' Type in letters: ')
number_input = int(raw_input(' Letter... | [] | [
{
"body": "<p><strong>Don't use global variable</strong></p>\n\n<p>It make things hard to understand and to maintain. In your case, the simple way to do this is to feed your function <code>function()</code> the parameters it needs.</p>\n\n<pre><code>def function(letter_input, number_input, split_letters):\n</co... | {
"AcceptedAnswerId": "54365",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T10:21:14.523",
"Id": "54362",
"Score": "5",
"Tags": [
"python",
"optimization",
"iteration"
],
"Title": "Optimize iteration output to text file"
} | 54362 |
<p>Following is the string: (I'm getting that from config file so its not constant):</p>
<pre><code>string sequence = "Concat({ACCOUNT_NUM},substring(FormatDate(yyyyMMddHHmmss,DateNow())
,2,12), GetLast(GetNextSequence(seq_relation),1))";
</code></pre>
<p>It contains multiple custom methods and I want them somewhere ... | [] | [
{
"body": "<p>You can use a regular expression:</p>\n\n<pre><code>string[] names =\n Regex.Matches(sequence, @\"([A-Za-z_]\\w*)\\(\").Cast<Match>()\n .Select(m => m.Groups[1].Value).ToArray();\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | {
"AcceptedAnswerId": "54366",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T10:27:50.450",
"Id": "54363",
"Score": "1",
"Tags": [
"c#",
"array"
],
"Title": "Find part of string in array, replace entire row with that part of string if found"
} | 54363 |
<p>I've had a bit of help designing the header for a website here: <a href="http://jsfiddle.net/gxLt5/21/" rel="nofollow noreferrer">http://jsfiddle.net/gxLt5/21/</a></p>
<p>It looks and works exactly how I had hoped. That said, I do feel like the code is a bit grotty, and I'm sure there is a more elegant solution to ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-17T11:38:29.447",
"Id": "95053",
"Score": "1",
"body": "I don’t know if it’s just a placeholder, but the `alt` value \"logo\" is probably not appropriate."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-05T... | [
{
"body": "<p>First, I'm not sold on your use of <code><nav></code> as a header. You can assign an aria <code>role=banner</code> to it or replace it with the tag intended to be a <code><header></code>. I understand you're using your logo as a navigation link (e.g. home), however, you still have to m... | {
"AcceptedAnswerId": "56219",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T11:15:43.427",
"Id": "54368",
"Score": "2",
"Tags": [
"html",
"css"
],
"Title": "Website Navigation Bar - Potential code soup"
} | 54368 |
<p>I have this fiddle <a href="http://jsfiddle.net/L7zuT/" rel="nofollow">http://jsfiddle.net/L7zuT/</a> where I'm working on a small part of a big event program. The functionality is ok, the part of the problem would be the large JavaScript lines needed with the full event program. Is there any way to implement it wit... | [] | [
{
"body": "<p>I think selectors which are used at multiple places can be move at top and keep them in variable will optimize the code at certain level and increase speed. </p>\n\n<pre><code>var ipDM01 = $(\"input[name$='date_main01']\");\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T11:42:55.327",
"Id": "54370",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Optimize jQuery selectors code"
} | 54370 |
<p>Rationale: I often have the requirement to own object instances, while preserving polymorphic behavior (i.e. own the object and hold it by pointer, or reference).</p>
<p>This is usually expressed as a pointer (most of the times, <code>std::unique_ptr<T></code>), but when the pointer is stored in a <code>std::... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T12:16:43.817",
"Id": "94838",
"Score": "0",
"body": "I didn't read the code yet, but could you explain how it is different from `std::reference_wrapper`? :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-0... | [
{
"body": "<p>Sometimes you are not using <a href=\"http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers\" rel=\"nofollow\">universal references</a> in the right way (i.e. use always <code>std::forward</code> when passing them around and not <code>std::move</code>). Fix it in the implementati... | {
"AcceptedAnswerId": "54954",
"CommentCount": "19",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T11:44:23.343",
"Id": "54371",
"Score": "8",
"Tags": [
"c++",
"c++11",
"polymorphism"
],
"Title": "Polymorphic (owned) reference wrapper for class hierarchies"
} | 54371 |
<p>This is my solution to this question from <a href="https://www.hackerrank.com/challenges/sherlock-and-the-beast" rel="noreferrer">Hackerrank</a>.</p>
<blockquote>
<p>Given <em>N</em> (<= 100000), find the largest <em>N</em>-digit number such that:</p>
<ol>
<li>The number has only 3 and 5 as its digits.<... | [] | [
{
"body": "<p>In terms of improvements, a few obvious things. Generally, as with many Python questions here, I would suggest you read and implement <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">the Python Style Guide, PEP-0008</a>, particularly:</p>\n\n<ul>\n<li>Naming conventions (fu... | {
"AcceptedAnswerId": "54380",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T12:00:20.013",
"Id": "54373",
"Score": "16",
"Tags": [
"python",
"optimization",
"performance",
"programming-challenge"
],
"Title": "Sherlock and The Beast"
} | 54373 |
<p>I recently built a way to automagically dismiss <code>firstResponders</code> for an app I'm building. Is there a more efficient way to approach this?</p>
<pre><code>- (void)resignFieldStackRespondersExcept:(id)fieldException
{
for (id field in self.fieldStack) {
if ([field isKindOfClass:[fieldException ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-17T00:19:05.487",
"Id": "94976",
"Score": "0",
"body": "It's a bit unclear what you're trying to do. Is this a `UITextField` class? What is this exactly? Where does this code reside? And are these methods part of the Foundation cla... | [
{
"body": "<p>There's not really enough information or context here to make any sort of comment on the efficiency of this pair of methods, but it seems like this could simply be narrowed down into a single method.</p>\n\n<p>We're iterating through a collection so we can call <code>resignField:</code> on specifi... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T12:32:15.160",
"Id": "54375",
"Score": "3",
"Tags": [
"objective-c",
"ios",
"cocoa-touch"
],
"Title": "Class / Superclass / Specific class matching condition, can it be simpler?"
... | 54375 |
<p>I managed to make a perfectly even cross with <code>for</code> loops.</p>
<p>I'm trying to make this cross easier to code. I have to keep it with <code>for</code> loops, but it's too long to implement.</p>
<pre><code>public class CroixDemoAmmeliore {
public static void main(String args[]) {
int e = 5... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T21:12:37.320",
"Id": "94842",
"Score": "0",
"body": "When i formatted your code, i saw that `int l` is unused. Is that intentional, or it might be something problematic?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>First thing I would say is that you could reduce the number of variables you use. The iterator of a For loop, if instanced from outside the loop's context (as in your case), can be reused. Doing so you could already reduce the numbers of variables you use.</p>\n\n<p>I do not understand what you me... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-15T21:01:26.797",
"Id": "54376",
"Score": "3",
"Tags": [
"java",
"console",
"formatting"
],
"Title": "Java Cross with characters"
} | 54376 |
<p>What I would like to do is have a method call like:</p>
<pre><code>Database.Modify.InsertOrUpdate<ADDRESS>(address,
() =>
{
var result = ctx.ADDRESS.Where(o => o.JURIDICAL_ADDRESS == "Y")
.OrderByDescending(o => o.ID)
.FirstOrDefault();
return (result != null ? result.ID : 0);... | [] | [
{
"body": "<p>You rely <em>a lot</em> on static classes and helpers.</p>\n\n<blockquote>\n<pre><code>Database.Modify.InsertOrUpdate<ADDRESS>(address,\n() =>\n{\n var result = ctx.ADDRESS.Where(o => o.JURIDICAL_ADDRESS == \"Y\")\n .OrderByDescending(o => o.ID)\n .FirstOrDefault();... | {
"AcceptedAnswerId": "54401",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T13:07:04.050",
"Id": "54381",
"Score": "5",
"Tags": [
"c#",
"entity-framework",
"generics"
],
"Title": "Static Data Helper for an Oracle Backend"
} | 54381 |
<p>I have a search function on my website. In addition, elsewhere I have a place where users can submit categories for their posts. I want the categories to have an uppercase first letter and the rest lower case. I know there far more complex ways to secure a user input string, but do you think that as a fairly basic f... | [] | [
{
"body": "<p>Instead of trying to purify the category for the user, which may or may not have unexpected results, you should simply reject everything that does not conform to your level of standard, and let the user fix it:</p>\n\n<pre><code>function isValidCategoryName($string) {\n return preg_match(\"/^[A... | {
"AcceptedAnswerId": "54385",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T13:17:17.607",
"Id": "54382",
"Score": "2",
"Tags": [
"php",
"beginner",
"strings",
"security"
],
"Title": "String sanitisation function"
} | 54382 |
<p>I need a code review on my Abstract Factory pattern written in Java.</p>
<p>Find the two enums AnimalType.java and DietType.java below.</p>
<pre><code>package com.patterns.abstractfactory.three;
public enum AnimalType {
TERRESTRIAL("\nLeave on land and breath with lungs.\n"), AQUATIC("\nLeave in water and breath... | [] | [
{
"body": "<p>I didn't try to compile or run your code. These are my thoughts:</p>\n\n<p><strong>Important:</strong></p>\n\n<ol>\n<li>When you do the Abstract Factory pattern, there are two pieces: the factory and the thing that creates the factory. You need to have a separate class that has a static method <... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T14:03:30.860",
"Id": "54384",
"Score": "3",
"Tags": [
"java",
"design-patterns",
"abstract-factory"
],
"Title": "Abstract factory pattern implemented in Java"
} | 54384 |
<p>I have been struggling with a regular expression involving path names. Immediately, this is a bit troublesome, owing to the embedded / in the pattern, but braces to the rescue.</p>
<p>First the convention I have imposed:</p>
<p>Every path in the set looks like:</p>
<pre><code>/ifmxdev/files/file.0123
</code></p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T22:41:11.773",
"Id": "94852",
"Score": "4",
"body": "Just use `\\w` for that character class: `qr{/ifmxdev\\w*/files/file\\.\\d{4}};`. And don't forget to escape the period in the suffix. Finally, might want to add some anchors `^... | [
{
"body": "<p>It probably doesn't matter, but the first element of that path can be <code>ifmxdev______</code> or <code>ifmxdev_x_x_x</code> with that regex.</p>\n\n<p>I suggest you use use the Unicode property <code>alnum</code>, which is <code>[A-Za-z0-9]</code> - <code>\\w</code> without the underscore</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T22:39:00.330",
"Id": "54386",
"Score": "2",
"Tags": [
"regex",
"perl"
],
"Title": "Determine if a path matches a pattern"
} | 54386 |
<p>I've previously posted a <a href="https://codereview.stackexchange.com/questions/54099/complex-query-to-count-votes-with-a-redistribution-system">question about simplifying a query to count votes with a distribution system</a>. One of the contributors, @200_success, pointed out that it calculated the surplus redistr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:44:41.640",
"Id": "94921",
"Score": "0",
"body": "It's a shame that MySQL does not support Common Table Expressions. I do see you have many levels of nested `SELECT` statements which makes it difficult to interpret what the code ... | [
{
"body": "<p>It looks better, but I'm still going to recommend using a <a href=\"http://dev.mysql.com/doc/refman/5.0/en/user-variables.html\">variable</a> to replace this snippet. </p>\n\n<pre><code>SELECT FLOOR((COUNT(*) / (2 + 1)) + 1) threshold\nFROM votes\n</code></pre>\n\n<p>You could perhaps write a <a h... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T14:30:07.917",
"Id": "54388",
"Score": "6",
"Tags": [
"sql",
"mysql"
],
"Title": "Complex query to count votes with a redistribution system - follow-up"
} | 54388 |
<p>I'm pretty new to web development with JS and was wondering if anyone can tell me how I can improve my code. I just feel like when it comes to maintainability my code would be very difficult to update. Can someone advice on some best practices or maybe how they do it?</p>
<p><strong>JavaScript</strong></p>
<p>Here... | [] | [
{
"body": "<p>The code isn't bad. I think your taking the wrong approach though. Rendering HTML from JavaScript is ugly and as you mentioned, hard to maintain. I'd recommend looking into a client side templating solution such as Handlebars, Mustache, Dust, etc..</p>\n\n<p>This will allow you to write templates ... | {
"AcceptedAnswerId": "54398",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T14:35:46.453",
"Id": "54389",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"beginner",
"parsing"
],
"Title": "Getting data from the server via JSON callback and parsing ... | 54389 |
<p>I would like your comments on my code in C++ (C++98 + Boost) </p>
<p>I have written some code to use the functors with the <code>boost::range::for_each</code> algorithm.
My main problem was to add some "external" parameters to the <code>functor</code> that are not in the vector on which I am using a <code>for_each... | [] | [
{
"body": "<p>With C++11 and lambda, it will be more straightthrough. </p>\n\n<pre><code>for_each(vec.begin(), vec.end(), [&result](Person& person){\n if (NULL != result)\n {\n int age = person.getAge();\n\n if (age < AGE_LOW_LEVEL)\n {\n age += 2;\n }\n else if... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-13T09:20:08.020",
"Id": "54391",
"Score": "4",
"Tags": [
"c++",
"boost",
"lambda"
],
"Title": "Boost::range::for_each + functor"
} | 54391 |
<p>I recently started developing my first serious project in PHP, a MVC completely build by myself, which is quite a challenge, when being new to OOP.</p>
<p>So the main struggle of the whole project has, and is, my router. It's really important, so I want to have a... great?... router, that just works - but without c... | [] | [
{
"body": "<p>Unfortunately, this is a very large question to ask. So there will be gaps in my answer but i will answer it best i can using code where possible.</p>\n\n<p>You do not want to couple your router with the controllers. They both do different things. If you do combine them, you end up with a mess (as... | {
"AcceptedAnswerId": "54565",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T15:16:04.747",
"Id": "54399",
"Score": "8",
"Tags": [
"php",
"mvc",
"url-routing"
],
"Title": "PHP Router for MVC"
} | 54399 |
<p>The questions from <a href="http://www.hackerearth.com/problem/algorithm/exam-time-2/">hackerearth</a>:</p>
<blockquote>
<p>Geeko is in worry now because an exam is coming up and he has to know
what rank he can get on exams. So he goes back into the the school records
and finds the amazing pattern.</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T17:05:41.370",
"Id": "94879",
"Score": "1",
"body": "Welcome here! The indentation of your code seems a bit weird. It is because of the site or it is the way it appears in your favorite editor as well ?"
},
{
"ContentLicense... | [
{
"body": "<ol>\n<li>Give meaningful class names to your classes, e.g. \"relative\" does not seem to describe anything about the data type of the object. A more meaningful name could have been \"RankFinder\" in the context of your problem.</li>\n<li>Always stick to Hungarian notation while naming your classes a... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T16:59:03.927",
"Id": "54405",
"Score": "5",
"Tags": [
"java",
"optimization",
"performance",
"primes",
"programming-challenge"
],
"Title": "Calculating the ranks of classm... | 54405 |
<p>It's a string problem I have been making on <a href="https://www.hackerrank.com/challenges/string-similarity" rel="noreferrer">Hackerrank</a>. It is executing fine on all test cases except the last two. These last two test case are declaring it "Terminated due to time out". </p>
<p>C programs are allowed 2 seconds ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T17:31:06.463",
"Id": "94888",
"Score": "0",
"body": "The errors have gone away, so this has been reopened. Please remember to include *all* code so that others can compile and run it."
}
] | [
{
"body": "<p>The problem with the slow running time is due to the presence of two loops in your code. In this particular case, only one suffices. The following code should be fast enough to pass your benchmarking test.</p>\n\n<pre><code>#include <stdio.h>\n#include <string.h>\n#include <math.h&g... | {
"AcceptedAnswerId": "54411",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T17:01:31.803",
"Id": "54407",
"Score": "6",
"Tags": [
"optimization",
"performance",
"c",
"strings",
"programming-challenge"
],
"Title": "String self-similarity"
} | 54407 |
<p>I'm new to MVP. In a presenter I have following code. Here what am I trying is to create a list of <code>Model</code> objects (in this case <code>IAttendance</code> objects) and to show them on a <code>DataGridView</code> in the <code>View</code>.</p>
<p>Every time an attendance is entered on the View, <code>AddAtt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T20:13:50.637",
"Id": "94928",
"Score": "1",
"body": "Can you elaborate on why you copy the model before putting it in the `List`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-17T06:04:36.297",
"Id... | [
{
"body": "<p>At first glance, there seems to be something off in the structure.</p>\n\n<p>You wish to display a list of <code>IAttendance</code> objects on the screen. To me, this means that the Model is a list of <code>IAttendance</code> objects but the code shows only a single <code>IAttendance</code> instan... | {
"AcceptedAnswerId": "54484",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T17:46:32.920",
"Id": "54412",
"Score": "2",
"Tags": [
"c#",
".net",
"winforms",
"dependency-injection",
"mvp"
],
"Title": "Calling a copy constructor in Presenter to pr... | 54412 |
<p>I've written some JavaScript code:</p>
<pre><code> app.get('/offers/', function(req, res){
var funcGetOffers = utils.funcGetOffers;
var options = {top_sort: true};
funcGetOffers(function(offers){
res.render('offers', { offers:offers });
}, options);
});
app.get('/api/get_offers', functio... | [] | [
{
"body": "<p>You don't need the local <code>funcGetOffers</code> variable. Just call <code>util.funcGetOffers</code> directly.</p>\n\n<p>You may extract the <code>options</code> to a var outside the request handlers, since it's the same in both places.</p>\n\n<p>After that, there's not really any repetition le... | {
"AcceptedAnswerId": "54420",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T17:56:43.253",
"Id": "54414",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "Code seems repeated, except for the callback function"
} | 54414 |
<p>As part of an Academic project I wrote the following code, according to the algorithm (verbal). When I checked the rest of the article I notice that the efficiency should be \$O(n^2)\$ and I wrote \$O(n)\$.</p>
<p>I know that I didn't finish and that there is much to do. I'm putting my code and article here and w... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T18:39:42.037",
"Id": "94900",
"Score": "0",
"body": "That link is not working for me (server is taking too long to respond)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T20:49:42.443",
"Id": "94... | [
{
"body": "<ul>\n<li><p>Don't ever call <code>System.gc()</code>. It probably won't even do anything, and if it does, it will most likely be less efficient than what Java does by default.</p></li>\n<li><p>Don't use <code>Vector</code>, but <code>List</code> instead. <code>Vector</code> has been somewhat depre... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T18:17:11.593",
"Id": "54422",
"Score": "4",
"Tags": [
"java",
"algorithm",
"dynamic-programming"
],
"Title": "The Three-machine proportionate flow shop problem with unequal machin... | 54422 |
<p>To learn some <code>Data.Map</code> and <code>Control.Monad.State</code>, I have written the following code, which should count the occurrences of <code>Char8</code> in a given file.</p>
<pre class="lang-hs prettyprint-override"><code>module Main where
import Control.Monad.State
import qualified Data.Byt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-17T09:47:33.267",
"Id": "95034",
"Score": "0",
"body": "An important thing to learn with `Data.Map` and `Control.Monad.State` is that you should almost always use `Control.Monad.State.Strict` and `Data.Map.Strict` instead :)"
},
{
... | [
{
"body": "<p>If you're using \"Char8\", then it would make a lot of sense to me to write a simple histogram type function using a mutable attay in the ST monad, and then calculate the minimum and maximum values at the end; there's no need to do it as you go.</p>\n\n<pre><code>import Data.Vector.Unboxed.Mutable... | {
"AcceptedAnswerId": "54474",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:00:49.590",
"Id": "54424",
"Score": "2",
"Tags": [
"haskell",
"memory-management",
"state",
"hash-map"
],
"Title": "Counting occurrences of Char8s in a file"
} | 54424 |
<pre><code>char * reverse_string(const char *s1)
{
int count = 0;
char *output;
char *o;
while(*s1 != '\0')
s1++;
s1--;
output = new char[strlen(s1)];
o = output;
while(*s1)
*output++ = *s1--;
if(*s1 == '\0')
cout<<"yes";
return o;
}
int main()
{
const char *s1 = "hello world";
char *result;
resul... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T20:16:17.627",
"Id": "94931",
"Score": "0",
"body": "There are many cases of Undefined Behavior here."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T23:39:39.633",
"Id": "94973",
"Score": "1"... | [
{
"body": "<p>The code which you have pasted is prone to segmentation fault and the behaviour is unpredictable. Sometimes, you may get the output \"yes\" because of the way the memory manager allocates memory.\nThe unsafe operation in the code is due to the following loop.</p>\n\n<pre><code>while(*s1)\n*output+... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:30:13.373",
"Id": "54427",
"Score": "1",
"Tags": [
"c++",
"strings"
],
"Title": "Pointers and string reverse function implementation"
} | 54427 |
<p>During our internal code review process, my following code raised some eyebrows:</p>
<pre><code>public class MySuperUtil {
public static List<Long> updateAndSubtract(List<Long> first, List<Long> second) {
List<Long> updated = updatePlaceholdersWithLargestIds(second, first);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:34:08.000",
"Id": "94907",
"Score": "0",
"body": "Why can't you just add it in the JavaDoc?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:36:16.163",
"Id": "94911",
"Score": "1",
"... | [
{
"body": "<blockquote>\n<pre><code>public class MySuperUtil {\n public static List<Long> updateAndSubtract(List<Long> first, List<Long> second) {\n List<Long> updated = updatePlaceholdersWithLargestIds(second, first);\n Collection<?> difference = CollectionUtils.s... | {
"AcceptedAnswerId": "54473",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:33:15.837",
"Id": "54430",
"Score": "2",
"Tags": [
"java"
],
"Title": "Suggested parameter names for utility class function"
} | 54430 |
<p>I need to search through a string array to find every occurrence of "Parameters Table", and between each "Parameters Table" and the next, get another string from a specified index (that remains constant). I have been doing this like so:</p>
<pre><code>public List<string> findlistOfNames(string[] arrayToLookFo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:44:13.883",
"Id": "94920",
"Score": "0",
"body": "Can you get around it by not searching for the whole string?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:47:56.317",
"Id": "94924",
... | [
{
"body": "<pre><code>public static List<string> findlistOfNames(string[] arrayToLookForNames)\n{\n var indexes = arrayToLookForNames.Select((x, i) => new { x, i })\n .Where(x => x.x == \"Parameters Table\")\n .Select(x =>... | {
"AcceptedAnswerId": "54439",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T19:43:33.097",
"Id": "54431",
"Score": "5",
"Tags": [
"c#",
"performance",
"strings",
"search"
],
"Title": "Faster method to find data using search word?"
} | 54431 |
<p>I've got this here screen manager system and while it works rather well, I do worry on how practical it all is.</p>
<p>The application creates a screen manager class then enters a message loop which calls the update, render and handle input methods of the screen manager.</p>
<p>The screen manager has a vector cont... | [] | [
{
"body": "\n\n<p>I just happened to code my own StateMachine a week ago, which is similar to your ScreenManager, so here are my thoughts on the subject.</p>\n\n<p>A vector of state <em>can</em> work, but I think using a stack instead saves you the index management. Also, the stack would resize itself during bo... | {
"AcceptedAnswerId": "54447",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T20:16:04.890",
"Id": "54434",
"Score": "4",
"Tags": [
"c++"
],
"Title": "Screen manager and its screens having access over the screen manager"
} | 54434 |
<p>Using the VS2012 code analyzer i see the following code has a pretty low Maintainability Index(40) but i cant seem to think of a better way to design it. Does anyone have suggestions on cleaning this up? </p>
<p>This code is part of a search screen for a web app I'm developing. They have several text fields they ca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T20:30:02.253",
"Id": "94935",
"Score": "6",
"body": "I'm searching for `\"Robert'); DROP TABLE Students;--\"`, what do I get?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T20:32:33.160",
"Id": "... | [
{
"body": "<p>You are getting a \"low Maintainability Index(40)\" because you have no separation of concerns here.</p>\n\n<p>Your DAL and SQL Server queries are two totally different things, and then you speak of your Business Logic Layer.</p>\n\n<p>You should never create an entire query string in C#, VB, Pyth... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T20:19:57.530",
"Id": "54436",
"Score": "5",
"Tags": [
"sql",
"vb.net"
],
"Title": "User Search SQL Builder"
} | 54436 |
<p>WiX, the Windows Installer XML toolset, lets developers create installers for Windows Installer, the Windows installation engine.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-16T20:50:30.007",
"Id": "54441",
"Score": "0",
"Tags": null,
"Title": null
} | 54441 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.