body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I have overrode Rails' <code>ActionDispatch::Routing::RouteSet::Dispatcher.controller_reference</code> method to check if a controller exists by checking for the required constants and then creating them based upon a controller with the same name in the <code>Generic</code> namespace. </p>
<p>The problem w/ my code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-26T15:05:12.613",
"Id": "84652",
"Score": "0",
"body": "you can use `const_defined?` instead of the begin/rescue, the rest looks just fine... :-)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2018-02-09T14:07:17.... | [
{
"body": "<p>Disclaimer: this should be a comment, my reputation at the moment does not allow me to comment your question</p>\n\n<p>What about exploiting <code>const_missing</code>? \n<a href=\"https://apidock.com/ruby/Module/const_missing\" rel=\"nofollow noreferrer\">https://apidock.com/ruby/Module/const_mis... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-17T13:15:31.320",
"Id": "26294",
"Score": "8",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Dynamic Controller Creation in Rails"
} | 26294 |
<p>2 months ago, I wrote a chrome extension called <a href="https://chrome.google.com/webstore/detail/hotfix/bfmckmhcljhakgkngnfjhmmffaabdafi?hl=en" rel="nofollow">hotfix</a>. I recently went back to look over the code and it made me cringe a bit. I refactored it a little, but before I get knee deep in it, I would like... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-17T14:34:00.060",
"Id": "40720",
"Score": "0",
"body": "The first thing I usually recommend is having separate files... If you don't want to leak globals and stuff, you can use tools like browserify. I've already [made an extension](ht... | [
{
"body": "<p>A few things in no particular order:</p>\n\n<ul>\n<li>You should re-organize your code. Pick a design pattern and stick to it. If you can't find one that you like, you could probably make a hybrid one. I would say the <a href=\"http://www.yuiblog.com/blog/2007/06/12/module-pattern/\" rel=\"nofollo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-17T14:06:55.797",
"Id": "26296",
"Score": "2",
"Tags": [
"javascript",
"git",
"google-chrome"
],
"Title": "Chrome extension that lets you push changes from Chrome Developer Tools dir... | 26296 |
<p>I understand .NET very well until Principles of OOP come into view, so I guess we can say very little. So to work on this, I am making a console app that will catalog my digital media to a MySQL database. I've been working on this for a few days. It's not done but I also don't want to get to far ahead and find out t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-17T16:22:09.500",
"Id": "40734",
"Score": "0",
"body": "Have you considered using an ORM, like Entity Framework? Also, you didn't have to include all that code if you want feedback about the `using`."
},
{
"ContentLicense": "CC... | [
{
"body": "<p>Initial formatting suggestions:</p>\n\n<ol>\n<li>Class members should be <code>camelCase</code>, or _camelCase with an _ in front of them.</li>\n<li>No need to keep empty constructors around your code. They are put in by default by the compiler.</li>\n<li>For non-static classes, initialize class ... | {
"AcceptedAnswerId": "26307",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-17T15:45:25.143",
"Id": "26303",
"Score": "2",
"Tags": [
"c#",
".net",
"mysql"
],
"Title": "Cataloging digital media to a MySQL database"
} | 26303 |
<p>I am creating an "explosion" of circle sprites from the character with this code, and I was wondering if there is a more effective way to do such things, because this just seems too stupid.
(This is cocos2d)</p>
<pre><code>int tileSize = 29;
explosionLenght += 1;
if (explosionLenght >= 7)
{
explosionLenght ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-17T21:32:30.013",
"Id": "40747",
"Score": "0",
"body": "You could replace the enumerated variables by an array, e.g. `CCSprint **circles`. The giant `if`-cascades can be replaced by a loop from `2` to `explosionLength`; bound checking ... | [
{
"body": "<p>For someone who of some weird reason needs to do the same thing, here's the code I ended up using. </p>\n\n<pre><code> -(void)explosionFromPoint:(CGPoint)explosionPoint withSprite:(CCSprite*)sprite;\n{\n //int \n explosionLenght += 1;\n if (explosionLenght >= 7) //Just for testing p... | {
"AcceptedAnswerId": "26666",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-17T20:07:25.437",
"Id": "26311",
"Score": "2",
"Tags": [
"optimization",
"c",
"objective-c",
"ios"
],
"Title": "Creating an expanding CCSprite cluster"
} | 26311 |
<p>I have been trying to figure out a way to optimize the solving of ODEs in Python but haven't been able to achieve this goal. I tried getting help via a bounty on SO using Cython but nothing came of that. </p>
<p>The code below isn't too slow but it is an example of code I tend to run a lot. Some of the code I us... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T19:24:08.477",
"Id": "40859",
"Score": "0",
"body": "Check out PyDSTool written by my good friend Rob Clewley. His code is better optimized than the MATLAB and vetted for almost 4-5 years now. It has been started while he was postdo... | [
{
"body": "<p>I would manually \"eliminate common sub-expressions\" in the <code>deriv</code>:</p>\n\n<pre><code>def deriv(u, dt):\n norm1 = np.sqrt(((u[0] + pi2 * r12) ** 2 + u[1] ** 2) ** 3)\n norm2 = np.sqrt(((u[0] - pi1 * r12) ** 2 + u[1] ** 2) ** 3)\n return [u[3], # dotu[0] = u[3] ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T00:30:48.493",
"Id": "26314",
"Score": "6",
"Tags": [
"python",
"optimization",
"performance"
],
"Title": "How do I optimize the solving of ODEs?"
} | 26314 |
<p>I recently came across a lecture on DFA. I tried to use it to determine whether a given 'search string' is found in the 'input string'. Please tell me if there is a better way.</p>
<pre><code>(display "Enter input string")
(define input-str (read-line (current-input-port)))
(display "Enter Search Str... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-05-18T05:35:30.567",
"Id": "26316",
"Score": "2",
"Tags": [
"strings",
"search",
"scheme",
"state-machine"
],
"Title": "String matching"
} | 26316 |
<p>I am new to PHP and put this contact page together using the w3Schools.com example as a guide along with a couple other sources. As far as I can tell, it works fine, but before I put it up on my page I would like to know if there is any potential for abuse. Any feedback is appreciated.</p>
<pre><code><!DOCTYPE h... | [] | [
{
"body": "<p>In case anyone else is interested I was able to increase the security somewhat. After some research, I think that I have made it more secure, from spammers, at least. I implemented a <a href=\"http://www.phpcaptcha.org\" rel=\"nofollow\">captcha by Securimage</a>. It was pretty simple to use and I... | {
"AcceptedAnswerId": "26419",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T05:44:39.863",
"Id": "26317",
"Score": "2",
"Tags": [
"php",
"security"
],
"Title": "Is this PHP Email Form Secure from injections or other abuses?"
} | 26317 |
<p>My site consists of a lot of asynchronous calls, and because of this a lot of content is dynamically added to the page. For this section of code I've dynamically added tabs to a page and need to create the selected tab section. This function is fired when a tab is clicked (note that <code>$devices_page</code> is a p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-19T14:12:52.933",
"Id": "40799",
"Score": "0",
"body": "Check out knockout.js. It provides data (JSON) binding to an existing markup template (HTML). This will remove your need to manually generate as much markup."
}
] | [
{
"body": "<p>If you don't need the data as JSON, you could just have the server send you the table markup. Then just inject it straight into the page using <a href=\"http://api.jquery.com/load/\" rel=\"nofollow\"><code>.load()</code></a></p>\n\n<p>Alternatively, if you want JSON data, or can't/won't mess with ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T08:58:34.840",
"Id": "26319",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "How can I improve my code which dynamically populates a section of a page?"
} | 26319 |
<p>I'm writing a <a href="https://github.com/tarrsalah/jdk-manager" rel="nofollow">bash script</a> to manage multiple <code>JDKs</code>, the script is very simple, you have to choose a directory when you store all the jdk's, and the script maintain a <code>symlink</code> to the current <code>jdk'. The</code>JAVA_HOME<... | [] | [
{
"body": "<p>Let's see:</p>\n\n<ul>\n<li>There's no need to use <code>return</code> in the last statement of a function. By default, the return code of the last command is returned anyway.</li>\n<li>Using backticks for evaluation is deprecated - you should use <code>$(command args)</code> instead. It is also m... | {
"AcceptedAnswerId": "26708",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T12:52:15.130",
"Id": "26320",
"Score": "2",
"Tags": [
"bash",
"linux",
"shell",
"unix"
],
"Title": "Bash script to manage multiple Java Development Kits installations"
} | 26320 |
<p>I wrote a C++ <a href="http://en.wikipedia.org/wiki/Parsing_expression_grammar" rel="nofollow">PEG</a> packrat parser generator and would love to get some feedback on the code and/or syntax. I currently use the <code><<</code> operator for defining grammar expressions and linking the handler functions that are... | [] | [
{
"body": "<pre><code>void op(parser::info &lhs,parser::info &rhs,parser::info &r,const std::string &op){\n</code></pre>\n\n<p>I think I'd prefer a more descriptive name than <code>r</code> here. I'm guessing it's intended to stand for \"result\", in which case I think I'd prefer to just name it... | {
"AcceptedAnswerId": "43952",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T16:11:00.363",
"Id": "26324",
"Score": "10",
"Tags": [
"c++",
"parsing"
],
"Title": "A C++ PEG parser generator"
} | 26324 |
<p>I have written this code to sort a list of numbers, in increasing order. </p>
<p>It is a combination of quick sort, insertion sort, and merge sort. I make the first element of the list a pivot, then I go through the list. If a number is less than or equal to the pivot, I "insert" the number in its <strong>appropria... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T17:33:29.600",
"Id": "26326",
"Score": "4",
"Tags": [
"sorting",
"lisp",
"scheme",
"racket"
],
"Title": "Quick Insert Merge Sort"
} | 26326 |
<p>Depending on your directory structure you may have name spaced class files in different directories (that isn't really part of the structure, i.e. lib/ or core/).</p>
<p>Symfony ClassLoader is awesome, but I wanted something lightweight. That just solves the problem above, so inspired by other frameworks implementa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-16T20:14:03.567",
"Id": "42699",
"Score": "0",
"body": "please define \"lightweight\""
}
] | [
{
"body": "<p>One minor improvement would avoid an extra string concatenation while looping over the directories.</p>\n\n<pre><code>public function loadClass($class)\n{\n $class = str_replace(array('\\\\', '_'), DIRECTORY_SEPARATOR, $class). '.php';\n\n if ($class[0] != DIRECTORY_SEPARATOR) {\n $cl... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T18:21:13.020",
"Id": "26327",
"Score": "5",
"Tags": [
"php"
],
"Title": "Autoloader class"
} | 26327 |
<p>I'm trying to solve a SPOJ problem, which is code SAMER08A at <a href="http://www.spoj.com/problems/SAMER08A/" rel="nofollow">this</a> link.</p>
<p>The problem is that when I ran my code in my IDE with all the examples given in the problem, the code works perfectly. But when running it in SPOJ, it exceeds the time... | [] | [
{
"body": "<p>Here's a partial/basic structured implementation of the problem. It works for the first two cases, but the last case comes back twice as large. I saw this question on SO and thought your version was highly over complicated and probably inefficient due to data structure choices. There isn't any rea... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T18:24:21.367",
"Id": "26328",
"Score": "7",
"Tags": [
"c++",
"optimization",
"graph"
],
"Title": "Find almost-shortest path more efficiently"
} | 26328 |
<p>I am in the process of rewriting in C all the data structures that I learned about a few years ago to increase my understanding of data structures and the C language. The first one I'm doing is singly-linked-lists, and so I'm designing an API for them. I haven't written any of the implementation yet, but I want to g... | [] | [
{
"body": "<p>You say \"A <code>struct sllist</code> is has one sentinel field that contains a pointer to\nthe sentinel node:\" - does this mean that there is an empty node separate from\nthe <code>sllist</code> instance acting as a 'sentinel'? If so, this would seem unnecessary.\nAnd unless <code>struct sllis... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T23:51:56.163",
"Id": "26331",
"Score": "2",
"Tags": [
"c",
"api",
"linked-list"
],
"Title": "Designing function prototypes for a singly-linked list API in C"
} | 26331 |
<p>I am extracting data from a text file. Some of the lines from which I want to extract the data consist of a text description with single spaces, followed by a multiple-space gap preceding four fields containing the data, each separated by multiple spaces. A field might either contain the indicator "N/A" or else it w... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T11:14:36.623",
"Id": "40784",
"Score": "2",
"body": "Can you provide sample input and expected output ? Also a single improvement to make your regex *shorter* would be to use `\\d` instead of `[0-9]`."
},
{
"ContentLicense":... | [
{
"body": "<p>Splitting is much better solution than regex, as someone already mentioned.</p>\n\n<pre><code>my $line = \"197 (82.8%) N/A 30 (12.6%) N/A\";\nmy $result = \n join \",\",\n map {\n tr|()%||d;\n $_ eq \"N/A\" ? qw(NA NA) : $_;\n }\n split /\\s+/, ... | {
"AcceptedAnswerId": "26335",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-18T11:10:39.810",
"Id": "26333",
"Score": "2",
"Tags": [
"regex",
"perl"
],
"Title": "Trying to improve a working regex"
} | 26333 |
<p>Every <code>Account</code> has its owner who is <code>Person</code> The bank has list of owners. I am not sure if my destructors are right and <code>delete bank</code> will delete all elements of <code>list<Account*>* v</code> nad the list itself. Please help.</p>
<pre><code>#include <iostream>
#include... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-19T13:02:24.657",
"Id": "40797",
"Score": "0",
"body": "No, it's wrong. But why on earth are you using a pointer to a `list`?"
}
] | [
{
"body": "<p>Deleting the vector will only delete the pointers in the vector, not the things to which they point.</p>\n\n<p>You need to iterate though the vector deleting the accounts before deleting the vector.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-19T12:46:26.037",
"Id": "26339",
"Score": "0",
"Tags": [
"c++"
],
"Title": "Does my classes contain right destructors"
} | 26339 |
<p>I'm making a WordPress plugin that obfuscates the real file URL and forces the download of one of this 3 types of URL: </p>
<ul>
<li>Local: <code>http://example.com/wp-content/custom/filename.zip</code></li>
<li>Dropbox: <code>https://www.dropbox.com/s/DBOX-KEY/filename.zip?dl=1</code></li>
<li>Google Drive: <code>... | [] | [
{
"body": "<p>The server is fetching the contents of the URL and then sending it to the user. Unless you accidentally output the URL, via an error or similar, there is no way the user could see it. The server is effectively sitting between them and the remote server.</p>\n\n<p>If you can, it would probably be b... | {
"AcceptedAnswerId": "26421",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-19T18:01:51.350",
"Id": "26343",
"Score": "1",
"Tags": [
"php",
"security",
"url",
"plugin"
],
"Title": "WordPress plugin for obfuscating a file URL"
} | 26343 |
<p>I wrote some piece of code which reads and write multiple data structures on a file
using C++. I would be grateful to get your feedback on what you think about the code (it works at least when I tested). Thanks. </p>
<pre><code>#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstr... | [] | [
{
"body": "<p>The trouble with writing binary blobs is that they lead to brittle storage.</p>\n\n<p>The stored objects have a tendency to break over time as the assumptions you make about the hardware no longer hold true (in this case that the <code>sizeof(int)</code> is constant and the endianess of <code>int<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-19T20:12:22.463",
"Id": "26344",
"Score": "5",
"Tags": [
"c++",
"file"
],
"Title": "Writing/reading data structure to a file using C++"
} | 26344 |
<blockquote>
<p><strong>Note #2</strong>: This was a post from a while back. Although the top rated answer is <em>useful</em> (generally), I'm looking for something more specific to this issue including routing / architecture. I've even tried a bounty, which failed. As I don't have enough rep to keep adding bounties, I... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T10:26:29.650",
"Id": "40813",
"Score": "0",
"body": "Split it up in more functions."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T10:32:07.020",
"Id": "40815",
"Score": "0",
"body": "Tha... | [
{
"body": "<p>The first thing I notice is that you are using the superglobals directly in your class. Normally you want to inject a request object into the class which contains all the info about the request.</p>\n\n<p>The next thing I notice is the use of static methods, e.g.:</p>\n\n<pre><code>\\Models\\Sessi... | {
"AcceptedAnswerId": "26360",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-19T20:46:08.460",
"Id": "26345",
"Score": "3",
"Tags": [
"php",
"mvc",
"url-routing"
],
"Title": "PHP MVC - Custom Routing Mechanism"
} | 26345 |
<p><a href="http://projecteuler.net/problem=5" rel="nofollow">Project Euler problem 5</a> asks:</p>
<blockquote>
<p>What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?</p>
</blockquote>
<p>I'm learning Ruby by going through Project Euler problems, and though I got the f... | [] | [
{
"body": "<p>Definitely your code looks like C directly translated to Ruby. Let's refactor the first two methods:</p>\n\n<pre><code>def prime?(n)\n (2..n-1).none? { |x| n % x == 0 }\nend\n\ndef primes_upto(n)\n (2..n-1).select { |x| prime?(x) }\nend\n</code></pre>\n\n<p>Of course <code>prime?</code> should b... | {
"AcceptedAnswerId": "26347",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-19T21:35:40.960",
"Id": "26346",
"Score": "4",
"Tags": [
"ruby",
"project-euler"
],
"Title": "Lowest Common Multiple of 1 to n in Ruby"
} | 26346 |
<p>The idea behind this is mainly educational but I might even consider using it in reality if turns out to be good. Here's my first try at implementing smart pointers:</p>
<pre><code>template<typename T>
class smart_pointer{
T* pointer;
std::size_t *refs;
void clear(){
if (!--*refs){
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-03-27T07:58:48.420",
"Id": "153257",
"Score": "0",
"body": "I have a question regarding incrementing the count. what if the smart pointer sp was originally pointed to something else, and you do a sp=sp1. In this case you need to decrease ... | [
{
"body": "<blockquote>\n <p>So the idea behind this is mainly educational...</p>\n</blockquote>\n\n<p>Cool. Always good to try and understand how things work under the covers.</p>\n\n<blockquote>\n <p>...but I might even consider using it in reality if turns out to be good.</p>\n</blockquote>\n\n<p>Please re... | {
"AcceptedAnswerId": "26356",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T02:34:14.580",
"Id": "26353",
"Score": "27",
"Tags": [
"c++",
"memory-management",
"pointers",
"boost"
],
"Title": "Efficient smart pointer implementation in C++"
} | 26353 |
<p>I'm relatively new to jQuery and am trying to learn best practices/design patterns with JavaScript. Came across <a href="http://addyosmani.com/resources/essentialjsdesignpatterns/book/" rel="nofollow">this link</a> and decided to try and put it to something useful.</p>
<p>So far I've made a notifications menu dropd... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>Review your comments, some of them just take up space and are not very valuable:</p>\n\n<pre><code>// update scrollbar\n$el.tinyscrollbar_update();\n</code></pre></li>\n<li>Indentation ( this might be because of copy pasting ) is off in your code, making it ha... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T03:27:06.717",
"Id": "26355",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"design-patterns"
],
"Title": "Notifications dropdown with TinyScroll"
} | 26355 |
<p>I have a producer consumer that simulates the interaction of threads controlling a hardware device. </p>
<p>I have 1 thread controlling the device, 1 thread reading, and 1 thread outputting. The read is synchronous on the thread while the controlling is asynchronous. </p>
<p>My producer is the thread controlling ... | [] | [
{
"body": "<p>I have some minor things to point out:</p>\n\n<ul>\n<li><p>There is not a <em>single</em> empty line in this code, and this essentially looks like globals, functions, and comments stacked on top of each other. You should have each type separated so that the code is easier to read (especially with... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T05:33:57.927",
"Id": "26357",
"Score": "8",
"Tags": [
"c++",
"performance",
"design-patterns",
"multithreading",
"c++11"
],
"Title": "Producer consumer that simulates the ... | 26357 |
<p>I have a simple task: </p>
<blockquote>
<p>Given a sequence of real numbers, replace all of its members larger
than Z by Z and count the number of replacements.</p>
</blockquote>
<p>I solved this task using Scala, but my code looks like imperative-style code. I want to make my code more functional. How can I r... | [] | [
{
"body": "<p>Let's split this up a bit; firstly, let's put the sequence filling code in its own function:</p>\n\n<pre><code>def populateSequence(length: Int): IndexedSeq[Double] = {\n for {\n i <- 1 to length\n _ = println(\"Enter sequence item ? \" + i)\n item = readDouble()\n } yield item\n}\n<... | {
"AcceptedAnswerId": "26366",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T12:11:01.103",
"Id": "26362",
"Score": "3",
"Tags": [
"functional-programming",
"scala"
],
"Title": "Replacing a sequence of real numbers with another sequence"
} | 26362 |
<p>To generate faces of a Minecraft-like world from a three dimensional array, I developed the following meshing algorithm. The faces are given vertices and indices. A vertex consists of a position in space, a normal vector and a texture coordinate. Indices point to vertices to consecutively define faces.</p>
<p>Those... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T13:50:39.070",
"Id": "40831",
"Score": "0",
"body": "I'm confused, I may be missing something here but why did you feel you needed the `goto` in the first place? I see only one use and its use precedes the block it is skipping. Coul... | [
{
"body": "<p>First of all, the way you're formatting your code is horribly confusing.</p>\n\n<pre><code>if(Inside(neigh, ivec3(0), ivec3(SIZE) - 1))\n if(data[neigh.x][neigh.y][neigh.z])\n goto skip;\n\n{\n ...\n}\n</code></pre>\n\n<p>The block here looks a lot like it's in the <code>if</code> con... | {
"AcceptedAnswerId": "26448",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T12:28:15.503",
"Id": "26363",
"Score": "3",
"Tags": [
"c++",
"algorithm",
"minecraft"
],
"Title": "Meshing algorithm for generating faces in Minecraft"
} | 26363 |
<p>I'm using sql server and I'm trying to update certain columns in a table but before it updates the data, I want to insert the data into another table.</p>
<p>This is my code</p>
<pre><code>declare @table1 table (Id int, Name varchar(100))
declare @temp table (Id int, Name varchar(100), CreatedOn datetime default ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T19:19:34.180",
"Id": "40945",
"Score": "0",
"body": "Is this happening on a set schedule, or every time the data is being updated?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T16:33:35.643",
"I... | [
{
"body": "<p>You don't need to change anything as long as the code performs what you need. If you want to insert records to another table on <em>every</em> update (and not only in this place) you should probably take a look at <a href=\"http://msdn.microsoft.com/en-us/library/ms189799.aspx\" rel=\"nofollow\">t... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T12:28:28.760",
"Id": "26364",
"Score": "2",
"Tags": [
"sql",
"sql-server"
],
"Title": "Archiving data while running update statement"
} | 26364 |
<p>I wrote the following code to read a config file line by line and split each line into 2 parts and store them separately. The split is done on the basis of a delimiter <code>=</code>:</p>
<pre><code>std::ifstream configfile(path_string.c_str());
std::string line;
std::vector<std::string> linesOfConfigFile;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T15:10:54.080",
"Id": "40839",
"Score": "1",
"body": "Have you tried asking him?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T07:01:42.770",
"Id": "40874",
"Score": "1",
"body": "As an a... | [
{
"body": "<blockquote>\n <p>I wrote the following code to read a config file line by line and split each line into 2 parts and store them separately.</p>\n</blockquote>\n\n<p>So there are two parts on each line, the stuff before the <code>=</code>, which is stored as a <code>string</code>, and the stuff after... | {
"AcceptedAnswerId": "26372",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T13:41:14.470",
"Id": "26368",
"Score": "2",
"Tags": [
"c++",
"strings"
],
"Title": "Splitting and storing config file lines"
} | 26368 |
<p>I've dabbled with PHP for a couple of years, I can generally get what I need done and I've been teaching myself PDO. The problem is I want to set it up with classes but i'm not really sure how to. </p>
<p>Below is my code, which takes data from a form, does some rough checking to see if the email is right and the f... | [] | [
{
"body": "<p>I know you're asking for \"a basic connection class\", but you really need a few classes. Currently, your code has all of these (tightly-coupled) responsibilities:</p>\n\n<ul>\n<li>Database access</li>\n<li>Error reporting</li>\n<li>Form validation</li>\n<li>Data persistence</li>\n<li>And I assume... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T15:08:42.190",
"Id": "26374",
"Score": "3",
"Tags": [
"php",
"classes",
"pdo"
],
"Title": "How do I refactor this basic form handler"
} | 26374 |
<p>I'm learning Scala and functional programming. Can I make it more functional?</p>
<pre><code>class Student(val firstname: String, val lastname: String) {
override def toString: String = firstname + " " + lastname
}
class ClassRoom {
var rows: List[Array[Student]] = List[Array[Student]]()
var total: Int = _
... | [] | [
{
"body": "<p>A couple of small things to start.</p>\n\n<pre><code>var rows: List[Array[Student]] = List[Array[Student]]()\n</code></pre>\n\n<p>This line can be simplified slightly by doing this instead:</p>\n\n<pre><code>var rows: List[Array[Student]] = List.empty\n</code></pre>\n\n<p>Unless you are caching th... | {
"AcceptedAnswerId": "26389",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T16:34:36.563",
"Id": "26376",
"Score": "3",
"Tags": [
"functional-programming",
"scala"
],
"Title": "Adding students to rows in a classroom"
} | 26376 |
<p>I want to write my database access code for a Snap application in a way that makes the queries easy to test from the <code>ghci</code> repl, while also working within the Snap context. My solution so far is to define a HasPostgres instance for IO and to write all my DB access functions following the pattern of <code... | [] | [
{
"body": "<p>Yes, this looks good to me. I've done exactly the same thing to facilitate debugging in my projects. However, I would recommend that you put the IO instance in some special module where all your debugging code lives. You really do not want instances like this making their way into any other cod... | {
"AcceptedAnswerId": "26439",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T16:02:27.627",
"Id": "26378",
"Score": "5",
"Tags": [
"haskell",
"postgresql",
"snap-framework"
],
"Title": "HasPostgres instance for IO with Snap framework"
} | 26378 |
<p>I've wrote this script to fetch and format content from my DB. It also counts how many result there are and separates them into pages. I'm barely learning PHP and MySQL so I don't know much about performance.</p>
<pre><code>function fetch_content($section, $subsection, &$count, $page = 0){
$section = substr... | [] | [
{
"body": "<p>I would make a single file with the MySQL server connection, so you can use the same connection in other functions, etc..</p>\n\n<p>Also you should pass string variables directly.</p>\n\n<pre><code>$stmt->prepare(\"SELECT COUNT(*) AS count FROM public $selection\");\n</code></pre>\n\n<p>Did yo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T20:01:40.330",
"Id": "26381",
"Score": "3",
"Tags": [
"php",
"sql",
"pdo"
],
"Title": "Fetching and formatting content from a database"
} | 26381 |
<p>How do you guys think I can improve the code for collision detection on my website <a href="http://asteroidfield.eu5.org" rel="nofollow">asteroidfield.eu5.org</a>? The current code is </p>
<pre><code>var dx = Math.abs(c1.getcx() - c2.getcx());
var dy = Math.abs(c1.getcy() - c2.getcy());
var dist = Math.sqrt((dx * d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T19:38:29.993",
"Id": "40947",
"Score": "0",
"body": "Was it running too slowly? How fast you detect a collision between two objects is not as important as being able to deal with thousands of them. In your case you do not have too m... | [
{
"body": "<p>One thing you can improve on is the getting of the absolute value. In some browsers, bitwise absolute is faster than <code>Math.abs</code>. <a href=\"http://jsperf.com/absolute-value-speed/3\" rel=\"nofollow\">But it depends on the browser's implementation</a>.</p>\n\n<pre><code>//bitwise absolute... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T20:06:01.023",
"Id": "26382",
"Score": "4",
"Tags": [
"javascript",
"html5",
"collision",
"canvas"
],
"Title": "Collision detection accuracy"
} | 26382 |
<p>I need to speed up this code: it creates a multilinear function. I considered the below methods but no idea which with the largest benefit.</p>
<ul>
<li>replacing dummy variables with things such as anonymous functions</li>
<li>having all code in the same file (my instructor's hint)</li>
<li>improving the looping: ... | [] | [
{
"body": "<p>You should be able to prevent casting to a string 100 times.</p>\n\n<p>First create all strings in a cell array, then just loop over the strings.</p>\n\n<hr>\n\n<p>Though it does not show up on the profiler, this looks higly dubious:</p>\n\n<pre><code>i=num2str(i)\nubs_str(i)=i/100;\n</code></pre>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T20:48:50.550",
"Id": "26385",
"Score": "1",
"Tags": [
"optimization",
"functional-programming",
"matlab"
],
"Title": "Speeding up repetitive initialisation with structured data?"
... | 26385 |
<p>I am unit testing this role provider. I have a few asserts in the code for my test. I am sure there are more test I could preform. Does anyone have any suggestions for more test for this role of the membership provider?</p>
<pre><code>[TestMethod]
public void TestDeleteUserAccess()
{
try
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T11:48:22.263",
"Id": "40890",
"Score": "0",
"body": "You are not doing unit testing here. Do you want to do unit test or do you want to test that `AsaMembershipProvider` implements `MembershipProvider` correctly? In any case you are... | [
{
"body": "<p>I am going to suggest a few improvements.</p>\n\n<p>Most of the principles for code quality apply just as well to test code as it does to production code:\nYour tests should follow <strong>Single Responsibility Principle</strong>. A test should ascertain one feature; such that any change or discov... | {
"AcceptedAnswerId": "26468",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T21:58:37.007",
"Id": "26388",
"Score": "4",
"Tags": [
"c#",
"unit-testing"
],
"Title": "Unit test provider roles"
} | 26388 |
<p>I want to adopt good coding habits now. the below code was written under tight constraints. We don't do assignment post mortems in class to discuss "real world" best practices -- we just get letter grades with little or no feedback. What are some examples of good questions I can ask myself to determine when code t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T01:42:07.620",
"Id": "40868",
"Score": "6",
"body": "well i know the program constraints limited you to only having 1 method. Real world says that is a bad habbit to have. Even worse is they want you to use the main method... Ugh my... | [
{
"body": "<p>There are a number of things you want to ask yourself. The first is, \"in the real world, do these requirements make sense?\". In this case, the answer is an emphatic \"No\". </p>\n\n<blockquote>\n <p>other than main(), use only one function -- <code>dice_roll()</code>. all calculations are inlin... | {
"AcceptedAnswerId": "26399",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T23:59:32.307",
"Id": "26395",
"Score": "16",
"Tags": [
"c++",
"game"
],
"Title": "Simulating craps games"
} | 26395 |
<p>I just have a somewhat simple question on coding practices. I have never written a large application before and I am currently working on building a game engine in JavaScript. The part that confuses me is what the best method of organization is in this particular case.</p>
<p>I have my base engine class, <code>Engi... | [] | [
{
"body": "<p>First of all, it's a bit surprising that you roll your own <code>EntityList</code>. I would expect an normal array to be more efficient and natural, at least when starting.</p>\n\n<p>A good mindset when thinking about coupling between parts of your code is to think about the specific problem of te... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T00:32:32.290",
"Id": "26396",
"Score": "4",
"Tags": [
"javascript",
"object-oriented",
"graphics",
"entity-component-system"
],
"Title": "Game engine utilizing a custom graphi... | 26396 |
<pre><code>def _getCallerLogger():
caller = inspect.currentframe().f_back.f_back
name = "{}-{}".format(caller.f_globals['__name__'], caller.f_code.co_name )
logger = logging.getLogger(name)
return logger
log = lambda msg : _getCallerLogger().debug(msg)
info = lambda msg: _getCallerLogger().info(msg)
wa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T12:20:50.793",
"Id": "40891",
"Score": "1",
"body": "why not `log = _getCallerLogger().debug`? why dont' you set the logger in a variable instead of creating a new one 5 times?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>The logging module already supplies a function name to log messages. If you want to include the function name in your log message just set the appropriate formatter with <code>%(funcName)s</code> in the format string on your log handler with: <a href=\"http://docs.python.org/2/library/logging.htm... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T03:40:28.697",
"Id": "26400",
"Score": "3",
"Tags": [
"python",
"logging"
],
"Title": "Any side effects from this Python logging code?"
} | 26400 |
<p>I was asked to do a code review for the following block of code. It implemented a bug fix to prevent some values being added to some drop down lists depending on the user's domain, in an ASP.NET WebForms app. The three lines adding items to the lists were from the pre-bug-fix code (not part of the fix), so I didn't ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T08:53:38.673",
"Id": "40877",
"Score": "1",
"body": "What does `Utils.GetUserDomain()` do when it's passed `null` or principal without a domain? Wouldn't it make sense to change that?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Disclaimer: I'm not too familiar with C#.</p>\n\n<p>The modified form has expressions that are a little too complex for me, but either would be ok. My only comment is that the initial comment line is screaming for some notice:</p>\n\n<pre><code>// Only add corporate AD domain if the user is a memb... | {
"AcceptedAnswerId": "26435",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T04:30:52.757",
"Id": "26401",
"Score": "10",
"Tags": [
"c#"
],
"Title": "Is the new version of this code more difficult to read and understand than the original? How can it be improved... | 26401 |
<p>This is the second submission for Code Review for this project, but since the API changed considerably I felt it should not be attached to the original post. To see the original post and comment see <a href="https://codereview.stackexchange.com/questions/26268/potential-problems-with-this-templating-technique">Poten... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T05:44:18.380",
"Id": "26403",
"Score": "1",
"Tags": [
"php",
"template"
],
"Title": "Templating engine that uses closures to eliminate iterative includes"
} | 26403 |
<p>I am a huge proponent of self-documenting code (when at all possible). I prefer to have code be self evident by the very nature of the names of the variables, methods, etc.</p>
<p>For instance:</p>
<pre><code>if (TheSky.IsBlue && TheGrass.IsGreen)
BeHappy();
</code></pre>
<p>I have run into a situati... | [] | [
{
"body": "<p>I would call this method <code>AcquireTimeSlot</code> or similar, since the main action here is actually capturing a timely-limited resource. Result of the method specifies whether resource has been acquired or not. You may also call it <code>TryAcquireTimeSlot</code> to highlight the fact that ac... | {
"AcceptedAnswerId": "26413",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T07:12:39.620",
"Id": "26407",
"Score": "5",
"Tags": [
"c#"
],
"Title": "Function that tests and mutates"
} | 26407 |
<p>I am required to read the following text from a keyboard (<code>stdin</code>). Please note that it will be entered by the user from the keyboard in this format only.</p>
<pre><code> #the total size of physical memory (units are B, KB, MB, GB)
512MB 2 #the following are memory allocations
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T07:51:37.037",
"Id": "40875",
"Score": "0",
"body": "Also i am required to make it whitespace compatible. What it means is that input can be entered in one line as well. like two allocations in one line. Which i dont think i have ta... | [
{
"body": "<ul>\n<li><p>With this much code, you definitely should avoid using <code>using namespace std</code>. More info about that can be found <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">here</a>.</p></li>\n<li><p>You have <em>a lot</em> of glo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T07:47:17.030",
"Id": "26410",
"Score": "5",
"Tags": [
"c++",
"strings",
"stream"
],
"Title": "Reading input from keyboard"
} | 26410 |
<p>Is there a safer/ more readable way of using this code?
I gotta translate this code into a better , safer and more readable sample of code and get my onclick to work.(its currently called from another thread then what it is created from.)</p>
<pre><code>public class TemperaturePresenter
{
MainView _view;
/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T12:23:20.030",
"Id": "40892",
"Score": "0",
"body": "Safer, yes: you should be wrapping all creations of objects which implement `IDisposable` in a `using` statement. For example, `Stream`."
},
{
"ContentLicense": "CC BY-SA ... | [
{
"body": "<p>Well, at first glance, i think it should be:</p>\n\n<ul>\n<li><p>Constructor shouldn't have any logic other than initialization. Any I/O, Threads .... operations would be better to start in custom method. So, in your case i will write:</p>\n\n<p>public TemperaturePresenter(){\n _view = new Main... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T09:40:38.017",
"Id": "26415",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Is there a safer/ more readable way of using this code?"
} | 26415 |
<p>I am attempting to develop an XML schema (XSD) to represent a set of unit tests for some code. (Specifically, I am testing Oracle PL/SQL stored procedures.)</p>
<p>I would like to have something that represents:</p>
<ul>
<li>the procedure itself</li>
<li>the data used for each test (both arguments to be supplied t... | [] | [
{
"body": "<ul>\n<li>I would move <code>PackageName</code> and <code>Name</code> elements of the <code>AbstractProcedureType</code> to attributes.</li>\n<li>I don't think you need an <code>AbstractProcedureType</code>, just have a <code>ProcedureType</code> and <code>FunctionType</code> derived from it.</li>\n<... | {
"AcceptedAnswerId": "26423",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T11:25:48.857",
"Id": "26418",
"Score": "3",
"Tags": [
"unit-testing",
"xml",
"oracle",
"plsql",
"xsd"
],
"Title": "XML schema for Database Unit Tests"
} | 26418 |
<p>I'm working on an application, which tracks expenses. I have users, and each user can create his categories for the expenses (like Food, Bills, Transport, Drinks, Clothes) and then create expenses - each expense has one category (OneToMany relationship).</p>
<p>For example, the expense Banana is in the category Foo... | [] | [
{
"body": "<p>IMO this is great, it's nicely normalised. You're separating things logically into models.</p>\n\n<p>The only thing that's puzzling me is...what is your 'Month' entity for? None of your other Entities reference it?</p>\n\n<p>I don't know if:</p>\n\n<pre><code>/**\n * @ORM\\OneToMany(targetEntity=\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T11:51:40.950",
"Id": "26420",
"Score": "1",
"Tags": [
"php",
"database",
"doctrine",
"symfony2"
],
"Title": "Database \"design\" using Symfony2 and Doctrine2"
} | 26420 |
<p>Doing database access in ViewModel is generally considered a bad practice. However, when you have a <code><select></code> in your view, you need to populate it using the ViewBag or the ViewModel (I prefer the ViewModel). This leads to the following code:</p>
<pre><code>public class NewUserViewModel
{
publ... | [] | [
{
"body": "<p>Yes I think its bad practise because you have introduced both complexity and dependencies when it simply isn't necessary. Its going to make your unit testing more difficult than it needs to be and it isn't the intended purpose of the your view models.</p>\n\n<p>Just create a private method in your... | {
"AcceptedAnswerId": "32226",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T12:53:16.450",
"Id": "26422",
"Score": "5",
"Tags": [
"c#",
"asp.net-mvc-4",
"dependency-injection"
],
"Title": "Select list items in ViewModel fetched using a Repository"
} | 26422 |
<p>I'm quite new to javaScript and jQuery and wrote the following function to creat some dynamic tabs. I'd be very interested to know how professional programmers would improve this code.</p>
<p><a href="http://jsfiddle.net/8pLbt/" rel="nofollow">jsFiddle</a></p>
<p><strong>JavaScript</strong></p>
<pre><code>$(docum... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T14:03:31.093",
"Id": "40904",
"Score": "1",
"body": "Try not to write `== true`, it’s not a useful comparison."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T15:23:31.083",
"Id": "40920",
"Sc... | [
{
"body": "<ul>\n<li>I wouldn't change the entire code, but for performance you could compress the code.\n<a href=\"http://closure-compiler.appspot.com/\" rel=\"nofollow\">Closure compiler</a><br></li>\n<li>For a better UI I prefer twitters bootstrap (a sliding plugin included).\n<a href=\"http://twitter.github... | {
"AcceptedAnswerId": "26434",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T13:20:42.887",
"Id": "26424",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "How to improve this jQuery code for tabs"
} | 26424 |
<p>This method changes all URLs in the string into an HTML link. The goal is to not mutate the string passed in, which I believe is a good practice.</p>
<p>The <code>new_string</code> code in this method does not seem idiomatic.</p>
<pre><code>def autolink_string string
return if string.nil?
return '' if stri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T14:27:17.257",
"Id": "40911",
"Score": "1",
"body": "This method needs some polishing indeed, but are you aware that there are gems for this task? https://github.com/tenderlove/rails_autolink"
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<p>You can use <code>gsub!</code> and block directly with a clone.</p>\n\n<pre><code>def autolink_string str\n unless str.empty?\n regex = /(\\S+\\.(com|net|org|edu|gov)(\\/\\S+)?)/\n str.clone.gsub!(regex) do |match|\n \"<a href='http://#{ match }'>#{ match }</a>\"\n end |... | {
"AcceptedAnswerId": "26443",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T14:02:11.880",
"Id": "26427",
"Score": "3",
"Tags": [
"strings",
"ruby",
"url"
],
"Title": "Changing URLs into HTML links"
} | 26427 |
<p>I wrote the following code as a way of plucking data from a n-depth JavaScript object.
It works a charm and even appends the parents of the the found item.</p>
<p>I was just wondering if you guys had any ideas on making it better.</p>
<pre><code>//#region function recursiveFind
function recursiveFind(data, key, ch... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T20:13:02.913",
"Id": "52109",
"Score": "0",
"body": "You you add an example of use?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T19:52:52.447",
"Id": "62148",
"Score": "0",
"body": "Are... | [
{
"body": "<p><strong>Overal</strong></p>\n\n<p>I think the code looks too busy just to find a key/value match in an object tree-structure, it took a while to figure out which part(s) bothered me.</p>\n\n<p><strong>Doing it twice</strong></p>\n\n<p>You are doing the matching twice, once with <code>(data[key] ==... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T15:29:46.237",
"Id": "26436",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"recursion",
"search"
],
"Title": "Recursive find function in JavaScript / jQuery"
} | 26436 |
<p>I've created the following model for an academic project, and I'm wondering if this is a sensible way to manage a model:</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Se... | [] | [
{
"body": "<p>This smells slightly odd to me. Why would the class of customers know about what customers are actually participating in the model at the moment? Is there a need to even have knowledge of all the customers in the model overall? (Even in a simulation, you'd have that knowledge as part of the harnes... | {
"AcceptedAnswerId": "26438",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T20:23:19.670",
"Id": "26437",
"Score": "2",
"Tags": [
"c#",
"design-patterns",
".net"
],
"Title": "Is this a sensible way to implement a model?"
} | 26437 |
<p>I made a template pipe and filters to replace an old pipe and filters implementation that used inheritance and had a very heavy base class.</p>
<pre><code>#include <iostream>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <list>
template <typename Data>
class pipelin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-04-22T12:20:47.923",
"Id": "306342",
"Score": "0",
"body": "The answers really depend on what C++ standard you have access to. With C++11, you could throw boost away."
}
] | [
{
"body": "<ul>\n<li><p>As <code>run()</code> is several lines long, it should be defined outside the class. Anything defined inside is automatically inlined.</p></li>\n<li><p>Depending on the size of <code>data</code> when passing by value, it may be best to pass it to <code>run()</code> by <code>const&</... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T16:50:05.600",
"Id": "26444",
"Score": "7",
"Tags": [
"c++",
"template",
"inheritance",
"boost"
],
"Title": "Generic pipe and filters"
} | 26444 |
<p>I want to run a background job on my web server to do some database maintenance. I am looking at using <code>APScheduler</code> to do this.</p>
<p>I am planning on running the below code in a separate process to my main web server. I don't really want to tie the code to my web server.</p>
<p>Question: Is using <co... | [] | [
{
"body": "<p><code>while True: pass</code> will consume 100 % of one CPU which is not something you want. I'm not familiar with APScheduler, but a quick look into <a href=\"http://pythonhosted.org/APScheduler/#scheduler-configuration-options\" rel=\"nofollow\">the docs</a> reveals a <code>daemonic</code> optio... | {
"AcceptedAnswerId": "26462",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T16:59:37.047",
"Id": "26445",
"Score": "2",
"Tags": [
"python"
],
"Title": "Leaving an APScheduler in a while True loop"
} | 26445 |
<p>I am learning how to use the module unittest for test-driven development. Below is a simple yet practical example of an issue I will have many times: one single problem (e.g. an Abstract Data Type (ADT) describing a Data Type and an Operator on it), and various Data Structures (DS) implementing this ADT; in this cas... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T06:13:33.810",
"Id": "40979",
"Score": "0",
"body": "(I corrected the bonus question, please make sure I understood you correctly!)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T09:07:56.330",
"... | [
{
"body": "<p>Embrace Python's simplicity! This is a dynamic language, we care less about inheritance and complex data models and focus more on the actual problem. Of course, it has its drawbacks, but that's how it works.</p>\n\n<p>The answer your question: <strong>no, in Python, we wouldn't derive classes and ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T17:15:56.767",
"Id": "26446",
"Score": "2",
"Tags": [
"python",
"unit-testing"
],
"Title": "Generic test serie for various solutions to the same algorithmic problem"
} | 26446 |
<p>I am teaching myself Ruby and Ruby-on-rails, as part of this regimen I thought it would be a good idea to do some Ruby quiz exercises and so I started with the <a href="https://github.com/mathie/solitaire_cipher/blob/master/README.rdoc" rel="nofollow">solitaire cipher</a>. The basic functionality of decoding a prop... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T19:14:06.233",
"Id": "40944",
"Score": "3",
"body": "IMO it's not imperative vs OOP (*typical* OOP is imperative) but procedural vs OOP. My answer is: yes, you have to do it more OO and, specially, more modular (this `decode` is hum... | [
{
"body": "<p>Some notes on your code:</p>\n\n<ul>\n<li><code>alphaHash = Hash.new</code>, <code>each</code>, <code>delete</code>, <code>+=</code>, ...: This shows that you think in imperative terms (init, update, remove, insert, destroy, change, ...), in Ruby is more idiomatic a functional style (see <a href=\... | {
"AcceptedAnswerId": "26611",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T19:03:27.007",
"Id": "26449",
"Score": "4",
"Tags": [
"ruby"
],
"Title": "Is my solitaire cipher too imperative for an Object Oriented language like Ruby?"
} | 26449 |
<p>I have implemented a doubly linked list in C++. I have tested it and everything works as expected, but I am not sure if my copy constructor and assignment operator perform a deep copy.</p>
<ol>
<li>Can someone tell whether I am doing a shallow or deep copy?</li>
<li>Just by looking at my code, does my destructor se... | [] | [
{
"body": "<p>Use the copy and swap idium for assignment operator:</p>\n\n<pre><code>template <typename T>\nlist<T>& list<T>::operator= (const list &l)\n{\n if (this != &l) {\n removeAll();\n copyAll(l);\n }\n return *this;\n}\n\n// Easier to write as \ntempl... | {
"AcceptedAnswerId": "26456",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-21T20:11:14.710",
"Id": "26451",
"Score": "9",
"Tags": [
"c++",
"c++11",
"linked-list",
"memory-management"
],
"Title": "Copy constructor and assignment operator for doubly li... | 26451 |
<p>I just finished (re)reading <em>Clean Code</em>, and one of the ideas I learned was the SRP. However, I am not quite sure on what defines a "Single Responsibility." In the piece of code below, I have a <code>Note</code> class which I think may be doing too many things; it stores pitch and length, and converts these ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T10:55:57.677",
"Id": "40992",
"Score": "1",
"body": "Here's a nice article that made practical SRP much clearer for me: https://sites.google.com/site/unclebobconsultingllc/one-thing-extract-till-you-drop Be sure to check the article... | [
{
"body": "<p>Although you put the three classes into one file, they are already three classes. So you already split the responsibility. Translating a float to a length is one \"responsibility\" and translating the pitch to a name is another. Seen from this angle everything is fine.</p>\n\n<p>SRP is a heuristic... | {
"AcceptedAnswerId": "26464",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T08:14:14.503",
"Id": "26460",
"Score": "5",
"Tags": [
"java",
"music"
],
"Title": "Note class for managing information on various musical notes"
} | 26460 |
<p>I have a solution to the puzzle at <a href="https://kattis.csc.kth.se/problem?id=codes" rel="nofollow">https://kattis.csc.kth.se/problem?id=codes</a>.
What can I do to make my algorithm much much faster? What the algorithm does is take an N×K matrix and search for the minimum distance — that is, the least number of ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T06:33:38.233",
"Id": "41069",
"Score": "0",
"body": "Can you give an example matrix and desired output?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T10:09:40.820",
"Id": "41081",
"Score": "... | [
{
"body": "<p>I would consider use the <code>Eigen</code> library for matrix stuff. It is already optimized for that.</p>\n\n<p>Next consider using higher level contains instead of plan arrays. <code>std::vector</code> is a good choice. For a quick example of how <code>std::vector</code> will improve the run ti... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T08:17:08.317",
"Id": "26461",
"Score": "5",
"Tags": [
"c++",
"optimization",
"bitwise",
"edit-distance"
],
"Title": "Speed up a program to find the minimum Hamming distance"
} | 26461 |
<p>I've made a program that goes through your download directory (or any other directory; you just have to change the path) and finds the files that matches your query then asks you to rename or remove the file of your choice.</p>
<p>I'd like to know how to make my program shorter.</p>
<pre><code>#include <stdio.h... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T14:46:22.450",
"Id": "41004",
"Score": "2",
"body": "We'll only be able to answer if you show us the working code, as mentioned in the [faq#im-confused-what-questions-are-on-topic-for-this-site]. Otherwise, your question will be clo... | [
{
"body": "<p>This code has too many issues to go through in detail. Here are some that\nstand out.</p>\n\n<p>Firstly, compiling the code leads to a page of warnings that you should have\ncaught yourself. Code such as</p>\n\n<pre><code>char fileNameContainer[SIZE] , entery[SIZE] , ans[3] , ansN[3] ...\n...\na... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T13:37:18.047",
"Id": "26470",
"Score": "2",
"Tags": [
"optimization",
"c",
"algorithm",
"search",
"file"
],
"Title": "Use search query to find and modify files in director... | 26470 |
<p>I need a global data in my application. My application uses several threads to access and add items to my global variable. The global variable is a <code>ConcurrentDictionary</code> I choose to ensure data is added to the variable. What do you think about my approach?</p>
<pre><code>public class GlobalData
{
pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T14:51:36.920",
"Id": "41005",
"Score": "1",
"body": "Why do you think you need shared data? What are the threads doing with it? You have separate `Add` and `Get` methods, which means, dollars to dimes, you have a race condition."
... | [
{
"body": "<p>Yes, it can:</p>\n\n<ol>\n<li>First, you are mixing statics and non-statics in a confusing way. Please seperate those.</li>\n<li>A singleton should only be created once. Your class does not have a constructor, so it can be initialized everywhere. Give your class a private constructor. This why, on... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T14:21:29.170",
"Id": "26472",
"Score": "3",
"Tags": [
"c#",
"singleton"
],
"Title": "Global data singleton"
} | 26472 |
<p>In my program I read several information's about the system. I read each categories like CPU, memory, services, software and so on with a own thread. The main program have to wait for the longest thread.</p>
<p>To implement this, I use <code>LINQ</code> and the <code>Join</code> function from <code>Thread</code>.</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T14:57:36.083",
"Id": "41006",
"Score": "0",
"body": "Which .NET version are you using? Are these `Mainboard`, `CentralProcessingUnit` and `DeviceService` classes written by you or came from 3rd-party library?"
},
{
"ContentL... | [
{
"body": "<p>It's better to use new asynchronous API since it provides more features for combining asynchronous tasks. </p>\n\n<p>Ideally <code>Mainboard</code>, <code>CentralProcessingUnit</code> and <code>DeviceService</code> should expose asynchronous API if a certain operation is not trivial, so (as you me... | {
"AcceptedAnswerId": "26478",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T14:50:20.357",
"Id": "26474",
"Score": "1",
"Tags": [
"c#",
"linq",
"multithreading"
],
"Title": "Optimize Implementation - Wait for all threads using LINQ"
} | 26474 |
<p>I'm relatively new to bash scripting, and I'm wondering how I've done on this. Basically it's a script where if I'm in a github or bitbucket repository in my terminal, I can type <code>browse-repository</code> to open it up in the browser. I can also type something like <code>browse-repository issues</code> to visit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T17:21:11.910",
"Id": "71132",
"Score": "0",
"body": "I saved your script and made it executable, and from a github Repository, i executed it but nothing happens.."
}
] | [
{
"body": "<p>Some things:</p>\n\n<ul>\n<li>You don't need the <code>function</code> keyword to define a function.</li>\n<li>You can combine <code>sed</code> commands by separating them by <code>;</code>: <code>sed 's/\\.git//;s/https:\\/\\///;s/ssh:\\/\\///;s/git:\\/\\///;s/git@//'</code></li>\n<li>This can be... | {
"AcceptedAnswerId": "26705",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T15:35:57.170",
"Id": "26479",
"Score": "4",
"Tags": [
"bash"
],
"Title": "Simple bash script for opening a repository in the browser from the command line"
} | 26479 |
<p>I've developed <a href="https://gist.github.com/vi/5628320" rel="nofollow">a script</a> to set up an encrypted tunnel between two Linux hosts, using <code>iproute2</code>, <code>ssh</code> and <code>setkey</code>.
The goal is to allow setting up ad-hoc secure tunnels with minimum of setup and dependencies.</p>
<p>M... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T15:03:09.673",
"Id": "41099",
"Score": "0",
"body": "Note: filed [a bug](https://bugzilla.kernel.org/show_bug.cgi?id=58691) reproduced with this script."
}
] | [
{
"body": "<ul>\n<li>As far as I can tell, it checks if you provide too many options, but it doesn't check if you provide too few. This should be done before trying to do anything with <code>SRC</code> and <code>DST</code>. <code>set -o errexit -o nounset</code> as the first line would be prudent.\n<ul>\n<li><c... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T16:30:43.520",
"Id": "26480",
"Score": "3",
"Tags": [
"security",
"bash",
"linux",
"networking"
],
"Title": "Simple IPSec/tunnel setup script"
} | 26480 |
<p>I am walking through a sample MVC4 ASP.NET tutorial available on PluralSight.com, by Scott Allen. I am in a section #5, Working with Data (part 2), "Listing Reviews".</p>
<p>This application has a database of restaurant reviews. I'm following a section right now in which Scott shows how to add links in t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T18:28:10.597",
"Id": "41027",
"Score": "0",
"body": "I'm not sure if your question fits here, because you're not actually asking for a review of your code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05... | [
{
"body": "<p>EF will not create a wrapper around the <code>Restaurant</code> class! Instead it will derive from your <code>Restaurant</code> class and it will override that property (<code>public ICollection<RestaurantReview> Reviews</code>) because it needs to create a proxy or navigation property inste... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T16:55:42.647",
"Id": "26481",
"Score": "2",
"Tags": [
"c#",
"performance",
"asp.net",
"entity-framework",
"asp.net-mvc-4"
],
"Title": "Making a property virtual to cause E... | 26481 |
<p>As an exercise, I've written quicksort algorithm in C using pointers. Please comment and help me find the cases where it breaks (if any).</p>
<pre><code>void qsort(int *, int, int);
void swap(int *, int *);
void qsort(int *v, int left, int right)
{
int i, *last;
if (right <= left)
return;
l... | [] | [
{
"body": "<p>I'd make right an exclusive instead of inclusive upper bound, that is write <code>i < right</code> instead of <code>i <= right</code> and <code>last - v</code> instead of <code>last - v - 1</code>.</p>\n\n<p>This has the advantage of making the base call <code>qsort(v, 0, length)</code> inst... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T18:00:29.367",
"Id": "26483",
"Score": "4",
"Tags": [
"c",
"algorithm",
"array",
"sorting",
"quick-sort"
],
"Title": "Quicksort using pointers"
} | 26483 |
<p>I made a class to perform tasks concurrently and have implemented it. From appearances and testing, everything seems to work. How can I improve this? I understand this is somewhat a broad question, so please let me know how I should narrow it down.</p>
<p>Here is the pseudocode:</p>
<p>The general idea is a single... | [] | [
{
"body": "<p><code>SwingWorker</code> comes with all the control features you try to emulate here. It already uses an <code>ExecutorService</code> under the hood. I'm not sure why you want to increase the maximum pool size, but given that the code does not compile as given, makes me suspect you did not decide ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T18:12:06.343",
"Id": "26484",
"Score": "2",
"Tags": [
"java",
"concurrency"
],
"Title": "Performing tasks concurrently"
} | 26484 |
<p>I have written a caching wrapper class for ConcurrentDictionary. Basically it has a timer that checks if items are expired and removes them. Since ConcurrentDictionary does not have RemoveAll method that takes a predicate as a parameter, it has to decide which ones are expired first, then remove them. The problem is... | [] | [
{
"body": "<p>First of all I'd suggest to remove <em>expired</em> business-logic from UI <code>event handler</code> (looks like <code>CheckExpiredItems</code> method belongs to some UI class). </p>\n\n<p>If you are focusing on some concurrent logic you can create your own collection class, having inner member o... | {
"AcceptedAnswerId": "26521",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T19:06:32.367",
"Id": "26488",
"Score": "8",
"Tags": [
"c#",
".net",
"multithreading",
"thread-safety"
],
"Title": "Correct way to delete elements from a ConcurrentDictionar... | 26488 |
<p>I'm new to Android. I was wondering if anyone had any suggestions. It's basically an <code>AsyncTask</code> to get a remote JSON array and put it into a native array.</p>
<p>Would be very grateful for suggestions.</p>
<pre><code>package com.example.test2;
import java.io.BufferedReader;
import java.io.IOException;... | [] | [
{
"body": "<p>Don't open a resource in one place and close it in another. Keep the opening and closing of a resource localized to the same function (if you open it, you close it). This makes it easier to spot potential resource leaks.</p>\n\n<p>For example, an <code>InputStream</code> is being opened in <code>d... | {
"AcceptedAnswerId": "26576",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T19:17:46.643",
"Id": "26489",
"Score": "4",
"Tags": [
"java",
"android"
],
"Title": "JSON AsyncTask refactoring to improve quality?"
} | 26489 |
<blockquote>
<p>A generic <em>blocking queue</em> has the following properties:</p>
<ol>
<li>It is thread-safe.</li>
<li>It allows queuing and de-queuing of items of a certain type (T).</li>
<li>If a de-queue operation is performed and the queue is empty, the de-queuing thread waits indefinitely for an ite... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T23:11:32.233",
"Id": "41050",
"Score": "0",
"body": "It looks like your question is “How would you do this?” That's not what this site is for, so your question is off-topic here."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<blockquote>\n <p><strong>This is a 10-in-1 question.</strong> This answer is taking a quick look at <code>SimulatorForm.cs</code>.</p>\n</blockquote>\n\n<p>What you mention at the end of your [epic] post, that you've chosen <em>reflection</em> but that you could have used an enumeration of IoC cont... | {
"AcceptedAnswerId": null,
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T22:15:16.177",
"Id": "26497",
"Score": "5",
"Tags": [
"c#",
"multithreading",
"winforms",
"generics",
"interface"
],
"Title": "Generic Task Blocking Queue"
} | 26497 |
<p>I have the following function:</p>
<pre><code>def item_by_index(iterable, index, default=Ellipsis):
"""Return the item of <iterable> with the given index.
Can be used even if <iterable> is not indexable.
If <default> is given, it is returned if the iterator is exhausted before
th... | [] | [
{
"body": "<p>I would argue the best option is to make an explicit sentinel value for this task. The best option in a case like this is a simple <code>object()</code> - it will only compare equal to itself (aka, <code>x == y</code> only when <code>x is y</code>).</p>\n\n<pre><code>NO_DEFAULT = object()\n\ndef i... | {
"AcceptedAnswerId": "26500",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-22T22:56:50.490",
"Id": "26499",
"Score": "6",
"Tags": [
"python"
],
"Title": "Optional argument for which None is a valid value"
} | 26499 |
<p>I am making a web editor for fun and I was told that the way I was doing it (using PHP) would be a bad way. I also thought about it while I was making it, and in massive sums of data transfer it would be a bad idea to do it this way. I can't think of another way to do it and was looking for someone to help me improv... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T06:27:25.373",
"Id": "41067",
"Score": "0",
"body": "How much data do you expect per transfer?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T20:37:26.043",
"Id": "41122",
"Score": "0",
"... | [
{
"body": "<ul>\n<li><p>I'd prefer a form with a textarea rather than a contenteditable element. Forms and text areas were built for that purpose.</p></li>\n<li><p>As for your save code, <code>GET</code> requests should not do anything on the server. It should only do what it was called to do, and that is to <e... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T01:38:40.943",
"Id": "26502",
"Score": "3",
"Tags": [
"javascript",
"php",
"html"
],
"Title": "Transferring large amounts of data in web editor"
} | 26502 |
<p>I am actually quite new to C++, although I have previously programmed in Java. Do you see any ways I can improve readability, maintainability and performance, and make it more object-oriented?</p>
<pre><code>/*
Control + 0 = enable aimbot
*/
#include "stdafx.h"
#include <math.h>
const float pi = 3.14159... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-14T07:18:13.177",
"Id": "44677",
"Score": "0",
"body": "At `getCX` there is some pieces of repeated code. I think it's best to eliminate it, maybe use another function. Otherwise looks good for me - but I'm not good in C and/or WinAPI.... | [
{
"body": "<ul>\n<li><p>This is C++, not C, so use <code><cmath></code> instead of <code><math.h></code>.</p></li>\n<li><p>This would look and function better with more <code>class</code>es, especially since it's a game. For instance, <code>Player</code> can become a class instead of a <code>struct... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T02:02:13.090",
"Id": "26503",
"Score": "11",
"Tags": [
"c++",
"beginner",
"ai"
],
"Title": "Aimbot for open-source FPS game Assault Cube"
} | 26503 |
<p>How could this code be improved and have fewer repeated lines?</p>
<pre><code>vent.on("createAccountLayout:rendered", function() {
logger.info('createAccountLayout:rendered => CreateAccountLayoutController');
showRegion(['phoneNumberRegion', 'keyboardRegion', 'nextRegion', 'quitRegion']);
vent.trigg... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T02:52:23.780",
"Id": "41057",
"Score": "1",
"body": "If the code isn't that repetitive or that many, I suggest you leave it be. This is too little for a generic routine to be created."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Answerifying what Joseph the Dreamer commented on, </p>\n\n<p>there is really not enough code to build a general routine out of, the code is fine as is. Though ideally you could add comments.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-S... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T02:46:48.480",
"Id": "26505",
"Score": "2",
"Tags": [
"javascript",
"backbone.js"
],
"Title": "Backbone Marionette code improvement 2"
} | 26505 |
<h1>Background</h1>
<p>Breaking from MVC, I've implemented the following architecture:</p>
<pre><code>POST/GET ➤ PHP ➤ Database Calls ➤ XML ➤ XSLT ➤ HTML
</code></pre>
<p>All database interactions are relegated to the <code>call</code> method in the <code>Database</code> class, without exception. This adheres to the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T05:27:07.523",
"Id": "41064",
"Score": "0",
"body": "Do I get this right that you are trying to move most of your logic to stored procedures?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T16:06:49.8... | [
{
"body": "<p>Here's my sniff at the first things I saw for the code (not the implementation).</p>\n\n<pre><code>public function __construct() {\n ...\n try {\n $this->setDataStore(\n new PDO( \"pgsql:dbname=$dbname;host=$dbhost\", $dbuser, $dbpass ) );\n }\n ...\n</code></pre>\n\n<p>... | {
"AcceptedAnswerId": "26589",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T04:02:20.380",
"Id": "26507",
"Score": "6",
"Tags": [
"php",
"object-oriented",
"postgresql",
"delegates"
],
"Title": "Generic method for database calls"
} | 26507 |
<p>The following is a small part of some code I am working on
Which is better/faster/nicer?</p>
<p>1.</p>
<pre><code>for (Future<Subscription> future : futures) {
try {
executorService.submit(new Updater(future.get()));
} catch (ExecutionException e) {
logger.error(e, e);
}
... | [] | [
{
"body": "<p>Your presumtion that the future.get() method is called in another thread is wrong. The constructor still executes in the same thread as the loop, its the run() method in the Updater class that is called in its own thread. Consider passing the whole future to the Updater and store a reference to t... | {
"AcceptedAnswerId": "26511",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T06:02:07.680",
"Id": "26508",
"Score": "2",
"Tags": [
"java",
"multithreading"
],
"Title": "Best way to call future.get()"
} | 26508 |
<pre><code>eval {
# here is put some code that may throw exception
1; # Why is the "1;" here ?
} or do {
my $error = $@;
# Handle error.
};
</code></pre>
<ol>
<li>Does the following style protect against $@ not being set
correctly ? </li>
<li>What does the following "1;" protect against?</li>
<li>Is the... | [] | [
{
"body": "<p>Ad. 1. Yes and no - <a href=\"https://metacpan.org/module/Try::Tiny#BACKGROUND\" rel=\"nofollow noreferrer\">there are still some pitfalls</a> (please read further).</p>\n\n<p>Ad. 2. You must remember about returning truthy value from <code>eval</code> block because it evaluates to last value in b... | {
"AcceptedAnswerId": "26520",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T07:20:33.433",
"Id": "26512",
"Score": "4",
"Tags": [
"exception-handling",
"perl"
],
"Title": "What changes, if any, are required to make the following Perl eval bullet proof?"
} | 26512 |
<p><a href="http://brislink.github.io/Abstract/" rel="nofollow">My application</a>. The <a href="https://github.com/brislink/Abstract" rel="nofollow">repository</a> and the <a href="https://github.com/brislink/Abstract/blob/master/javascript/index.js" rel="nofollow">file</a> that needs review.</p>
<p>Here is the sourc... | [] | [
{
"body": "<p>I suggest you break down your application into concerns. Break them so that you separate your UI code, your IO code (read/write), your logic and your utilities. Then you could use a dependency system like <a href=\"http://requirejs.org/\" rel=\"nofollow\">Require</a> to manage these separated code... | {
"AcceptedAnswerId": "26550",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T07:44:16.207",
"Id": "26514",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"knockout.js"
],
"Title": "Need suggestions to improve the code for an open source web based draft... | 26514 |
<p>Using OpenMP, is it correct to parallelize a <code>for</code> loop inside a function "func" as follows?</p>
<pre><code>void func(REAL coeff, DATAMPOT *dmp, int a, int la, int b, int lb, REAL L)
{
int i,j,k;
REAL dx,dy,dz;
REAL dx2,dy2,dz2;
REAL r;
#pragma omp parallel for default(shared) privat... | [] | [
{
"body": "<p>There is nothing wrong with your code, but it can be improved somehow.</p>\n\n<p>First, automatic variables, defined in a scope that is outer to the parallel region, are automatically <code>shared</code>. Therefore the <code>default(shared)</code> clause is redundant.</p>\n\n<p>Second, the loop co... | {
"AcceptedAnswerId": "26528",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T07:44:42.807",
"Id": "26515",
"Score": "4",
"Tags": [
"c",
"openmp"
],
"Title": "OpenMP parallelization of a for loop with function calls"
} | 26515 |
<p>I am summing the total <code>.outerHeight()</code> of multiple <code>div</code>s like this:</p>
<pre><code>var h = $('#div1').outerHeight() + $('#div2').outerHeight() + $('#div3').outerHeight() + $('#div4').outerHeight();
</code></pre>
<p>Is there any way to do this more efficiently?</p>
<p>I was considering some... | [] | [
{
"body": "<p>You'll have to add a class to the <code>div</code>s to be able to select them all</p>\n\n<pre><code><div id=\"div1\" class=\"sumdiv\"></div>\n<div id=\"div2\" class=\"sumdiv\"></div>\n</code></pre>\n\n<p>Then, use <code>$.each()</code> (<a href=\"http://api.jquery.com/each/... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T08:22:47.627",
"Id": "26518",
"Score": "1",
"Tags": [
"javascript",
"performance",
"jquery"
],
"Title": "Summing outerHeight of multiple divs"
} | 26518 |
<p>I made this Javascript to hide, show and change some DIVs but I believe it's not really good code. Can you help me to make it better?</p>
<pre><code>function colorM(n) {
switch(n){
case 1:
document.getElementById("slideM1").style.backgroundColor="#009CFF";
document.getElementById... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T09:09:13.690",
"Id": "41077",
"Score": "1",
"body": "For starters: Instead of clearing the `className` of every div that you want to hide, assign a class name that already has the `background-color: 'silver'` and `display: none`. Th... | [
{
"body": "<p>Loop through the ID's instead of doing a switch. This should do the same as yours</p>\n\n<pre><code>function colorM(id){\n\n // if not a number\n if (!(!isNaN(parseFloat(n)) && isFinite(n))) id =1;\n // default for numbers\n if (id > 5 || id < 1) id = 1;\n\n for (var i... | {
"AcceptedAnswerId": "26523",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T08:56:02.900",
"Id": "26519",
"Score": "1",
"Tags": [
"javascript",
"dom"
],
"Title": "Better way to hide, change and show DIVs in Javascript"
} | 26519 |
<p>I just wrote this code to concatenate two wide characters strings. Could someone please comment if it looks OK? (seems to work at least).</p>
<pre><code>SomeStringClass amount = Window->get_text();
wchar_t strAmount[100] = L"Amount: "; // I know I could remove 100 from here too
wchar_t *ptr = wcscat( strAmount, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T12:12:29.040",
"Id": "41087",
"Score": "0",
"body": "Why not just use `std::wstring`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T12:14:51.770",
"Id": "41088",
"Score": "0",
"body": "@... | [
{
"body": "<p>Firstly, avoid the non-<code>n</code> versions of <code>(w)str_</code> functions. You've got a buffer overflow just begging to happen here - if <code>amount.length() > 100 - 8</code>, it'll overflow your buffer, causing undefined behaviour and general bad times. Use <code>wcsncat</code> instead... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T11:37:47.393",
"Id": "26524",
"Score": "1",
"Tags": [
"c++",
"strings"
],
"Title": "Concatenating wide character strings"
} | 26524 |
<p>I need to implement a system of queueing that extracts elements equally from <code>x</code> queues to one single queue with <code>y</code> positions.</p>
<p>Let's say I have 5 queues, each with a number of elements and I need to extract elements from each of the 5 queues to build a new queue containing the extracte... | [] | [
{
"body": "<p>First off, you're code looks nice, but it can be improved in places:</p>\n\n<ol>\n<li><p>I don't see why:</p>\n\n<pre><code> $totSmsToSend = count($smsToSend);\n</code></pre></li>\n</ol>\n\n<p>Is indented so far, you should fix that. There's quite a few elements that have been over indented... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T14:22:35.037",
"Id": "26530",
"Score": "3",
"Tags": [
"php",
"queue"
],
"Title": "Extract equally from X queues to one queue with Y elements"
} | 26530 |
<p>Is there any way I can DRY up this Rails 4 routes.rb code?</p>
<pre><code> match '/oauth/apps/' => 'oauth/applications#index', :as => :oauth_applications, :via => :get
match '/oauth/apps/new/' => 'oauth/applications#new', :as => :new_oauth_application, :via => :get
match '/oauth/apps/new/' =&... | [] | [
{
"body": "<p>Yes, use <code>namespace</code> and <code>resources</code>:</p>\n\n<pre><code>namespace :oauth do\n resources :apps, controller: \"applications\", as: :applications\nend\n</code></pre>\n\n<p>This is not 100% identical (the names of some of your routes have changed) but it is the way you <em>shoul... | {
"AcceptedAnswerId": "26546",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T14:28:36.083",
"Id": "26531",
"Score": "3",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Clean up Rails Routes"
} | 26531 |
<p>Consider a process composed of three algorithms: <em>makeRuns</em>, <em>meld</em> and <em>traverse</em> (each taking the output of the previous one as input): it is interesting to test each separately. Now consider three (or more) instances (e.g. <em>singleton</em>, <em>twoPairs</em>, <em>SimplePair</em>): it is int... | [] | [
{
"body": "<p>You have recognized that each of the tree functions can be tested separately. In the context of unit testing this means that each function is a \"unit\". Now each of your tests tests all three functions. This has drawbacks:</p>\n\n<ul>\n<li>When a test fails, the name of the failing test does not ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T14:40:01.187",
"Id": "26532",
"Score": "2",
"Tags": [
"python",
"unit-testing"
],
"Title": "Two dimensional unit testing"
} | 26532 |
<pre><code>def stopWatchSeconds(secondCnt) :
""" counts second for secondCnt seconds """
# is there a better way to do this?
startTime = time.clock()
ellapsed = 0
for x in range(0, secondCnt, 1) :
print "loop cycle time: %f, seconds cnt: %02d" % (ellapsed , x)
ellapsed = 1 - (ti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T06:54:17.250",
"Id": "41142",
"Score": "1",
"body": "Could you give a little bit more info about the goal of this function? Is it for benchmarking, a timer, etc? Different goals might make different methods more appropriate. Also,... | [
{
"body": "<p>I'm not sure this code does what you think it does, at least on a *nix OS. <a href=\"http://docs.python.org/2.7/library/time.html#time.clock\" rel=\"noreferrer\">According to the documentation</a>, <code>time.clock()</code> returns <em>processor time</em>, which basically means that any time spent... | {
"AcceptedAnswerId": "26669",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T14:42:04.043",
"Id": "26534",
"Score": "6",
"Tags": [
"python"
],
"Title": "Is there a better way to count seconds in python"
} | 26534 |
<p>I have this API to control some hardware. The API is not very well documented, but I've been able to make do with what I have. It is a API for a RFID device, but also has LED's on it that are controlled from the API.</p>
<p>So the idea is that this is a OPOS program. The RFID device opens/claims/and enables. When i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-10-01T10:02:25.210",
"Id": "194635",
"Score": "0",
"body": "There's too little to really understand what this is about. You claim multithreading; I do not see anything threading. And by-the-way what is OPOS?"
},
{
"ContentLicense"... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T15:24:37.580",
"Id": "26538",
"Score": "1",
"Tags": [
"c++",
"multithreading"
],
"Title": "Multi threaded API calls problem"
} | 26538 |
<p>The <a href="http://community.topcoder.com/stat?c=problem_statement&pm=1835&rd=4655" rel="nofollow">TopCoder question</a> specifies (in summary):</p>
<blockquote>
<p>Two words are considered rhyming if they have the same ending pattern (defined below). This comparison is case-insensitive (see Example 1.)<... | [] | [
{
"body": "<p>Instead of commenting on your code, I felt I had to make a rewrite. Your code is very hard to understand because of characteristics like:</p>\n\n<ul>\n<li>Your methods contain a lot of functionality</li>\n<li>Using a class without reason (e.g. no use of internal state, a lot of things being done i... | {
"AcceptedAnswerId": "26544",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T16:16:03.723",
"Id": "26541",
"Score": "8",
"Tags": [
"strings",
"ruby"
],
"Title": "Determine a poem's rhyme scheme"
} | 26541 |
<p>I've been writing this data structure for a few days, and now I'm really curious about what it actually is, and to get some critique on my logic. </p>
<p>A branch, based on this usage, exists when a <code>HEAD</code> node contains at least one node of the same type referenced. </p>
<p>The purpose of the structure... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T20:11:47.563",
"Id": "41120",
"Score": "0",
"body": "Looks like a type of Priority Queue to me."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T05:26:47.213",
"Id": "41139",
"Score": "0",
... | [
{
"body": "<ol>\n<li>Why do you have HEAD and TAIL NodeTypes? Doesn't their position on the branch tell you that?</li>\n<li>I'm concerned that you have structure traversal code infused into <code>AchievementNode</code> class. Classically the structure - tree, queue, List, etc. - is independent of the objects it... | {
"AcceptedAnswerId": "27178",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T19:45:08.433",
"Id": "26543",
"Score": "2",
"Tags": [
"c#",
"recursion",
"linked-list",
"queue"
],
"Title": "What is this structure called?"
} | 26543 |
<p>I have this class that pulls people out of a database. I want it to be a little prettier and function better.</p>
<pre><code><?php
class comps extends db_config {
public $output = array();
private $arr = array();
public $area;
public $me;
public $options = array();
public function __con... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T20:34:58.237",
"Id": "41121",
"Score": "3",
"body": "This is a bug: `... && $this->options['showMe'] = true`, I believe you meant to use `==`."
}
] | [
{
"body": "<p>Here's the code smells:</p>\n\n<ol>\n<li>The <code>new</code> keyword in a class definition</li>\n<li>A <code>result()</code> method and <code>$output</code> attribute for data created by single method</li>\n<li>A very long, ambiguous method: <code>run</code></li>\n<li>Two mostly-different SQL sta... | {
"AcceptedAnswerId": "26582",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T20:31:57.757",
"Id": "26545",
"Score": "2",
"Tags": [
"php",
"pdo"
],
"Title": "Pulling people out of a database"
} | 26545 |
<p>I am diving into Scala (using 2.10) headfirst and am trying out a simple task of taking bulk data and then doing something with that stream. The first part is generating that stream. I have seem to be able to cobble together what seems to work, but I think I am missing shortcuts in scala. Any pointers or code cleanu... | [] | [
{
"body": "<p>Two thoughts:</p>\n\n<ol>\n<li><p>I doubt that <code>getInnerPolygons</code> is tail recursive, because the\nrecursive call to <code>getInnerPolygons</code> within <code>flatMap</code> is not the\nlast statement to be executed. This is <code>flatMap</code> itself (but I may\nbe wrong). Recursive c... | {
"AcceptedAnswerId": "29706",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T20:48:02.187",
"Id": "26547",
"Score": "2",
"Tags": [
"optimization",
"recursion",
"scala",
"iterator"
],
"Title": "Is this a correct recursive Scala iterator creation?"
} | 26547 |
<p>I'm trying to read some SNMP packets on my own. So far so good, I was able to put up some functions to write some SNMP TRAP packets as I need them. However, now I need to be able to read them and while my code works, I'm not happy with it.</p>
<p>I'd like to see if any of you could please tell me if there's a bette... | [] | [
{
"body": "<p>So, based on your update it looks like you've switched to reading from <code>Stream</code> - good decision.</p>\n\n<p>A bit simplified/cleaner approach for reading int is:</p>\n\n<pre><code>public static class ASN1Int\n{\n public static int Read(Stream inputStream)\n {\n const int siz... | {
"AcceptedAnswerId": "27348",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T21:55:34.767",
"Id": "26549",
"Score": "1",
"Tags": [
"c#",
"serialization"
],
"Title": "Reading BER-encoded data"
} | 26549 |
<p>I'm trying to implement a PID without floating point operations on a micro controller. I appreciate all feedback I can get.</p>
<p>Header file:</p>
<pre><code>#ifndef BRUSHPID_H
#define BRUSHPID_H
#if defined(ARDUINO) && (ARDUINO >= 100) // Arduino Library
#include "Arduino.h"
#else
#include "WProgram.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T03:15:55.550",
"Id": "41130",
"Score": "0",
"body": "I personally find all this `this->` business visually distracting. If you're coding in an IDE that can't highlight class members in a different color, I find that a simple leadin... | [
{
"body": "<p>I know nothing of PID controllers, so I'll restrict comments to the code itself.</p>\n\n<h2>Comments on the header:</h2>\n\n<ul>\n<li><p>A <code>#endif</code> doesn't take a tag (BRUSHPID_H)</p></li>\n<li><p>Use of the 'signed' keyword is unusual. Do you have a good reason for its use?</p></li>\n<... | {
"AcceptedAnswerId": "26552",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-23T22:37:57.000",
"Id": "26551",
"Score": "3",
"Tags": [
"c++",
"library",
"arduino"
],
"Title": "PID Controller library"
} | 26551 |
<p>This is working code for a URI template (RFC 6570) implementation; when the character to render is not within a specific character set, it is needed to grab the UTF-8 representation of that character and encode each byte as a percent-encoded sequence.</p>
<p>The question is whether something more efficient than thi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T12:32:03.823",
"Id": "41157",
"Score": "0",
"body": "What kind of performance do you need? Is this just a general question? Did you try essentially the same thing on the whole string and see if it was faster?"
},
{
"ContentL... | [
{
"body": "<p><a href=\"http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URLEncoder.html\" rel=\"nofollow\">Documentation here</a></p>\n\n<pre><code>public static void main(final String[] args) {\n try {\n System.out.println(URLEncoder.encode(\"a?>éàùA-Z\",\n System.... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T04:51:20.127",
"Id": "26553",
"Score": "5",
"Tags": [
"java",
"guava",
"utf-8"
],
"Title": "Better code for converting a char to its UTF-8 percent encoding representation?"
} | 26553 |
<p>I'm trying to figure out whether I should do the following:</p>
<p>This class (over-simplified version) retrieves information about an order by having 1 main query function that select a specific column from the table and throws out the value for that column and that specific order ID. </p>
<pre><code>class jobin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T05:19:47.427",
"Id": "41138",
"Score": "0",
"body": "What you should do first and foremost is using prepared statements instead of string concatenations!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-2... | [
{
"body": "<p>Doing this in a loop will be slow, and doubling the calls by retrieving each column with a different query will make things worse.</p>\n\n<p>Why not use a JOIN between your original query, something like this:-</p>\n\n<p>SELECT database.job_id, job_sheet.qty, job_sheet.row\nFROM database\nINNER JO... | {
"AcceptedAnswerId": "26560",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T04:37:33.030",
"Id": "26554",
"Score": "2",
"Tags": [
"php",
"performance",
"mysql"
],
"Title": "SQL Query efficiency within class"
} | 26554 |
<p>If you were interviewing me, and saw this code written in a little under an hour, would you consider me as a candidate for a position at your company if you knew I had 2 years of C++ experience?</p>
<pre><code>#include <stdlib.h>
#include <cassert>
/*! \class Node to be used in likned list like constru... | [] | [
{
"body": "<p>I can't speak for others, but I'd personally have some reservations. To be fair, perhaps I'm not being lenient enough for doing this under pressure in an hour, but there are multiple issues that I'd want to address with this code.</p>\n\n<h2>Questions and Small Problems</h2>\n\n<p>Why is <code>nod... | {
"AcceptedAnswerId": "26559",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T05:40:48.077",
"Id": "26557",
"Score": "4",
"Tags": [
"c++",
"linked-list"
],
"Title": "Would this linked list be considered clean if written in an hour-long interview?"
} | 26557 |
<p>Firstly, here's a link to the <a href="http://jsfiddle.net/RobH/zgJRb/1/" rel="nofollow">fiddle</a>.</p>
<p>Basically my situation is that there is a requirement to show tooltips on textboxes on some forms being created for a website to allow employees to update their personal information (among other things). </p>... | [] | [
{
"body": "<p><a href=\"http://jsfiddle.net/zgJRb/5/\" rel=\"nofollow\">The demo is seen here</a></p>\n\n<pre><code>$('.tooltip').each(function () {\n\n //title can be fetched directly from the element. I know no bugs for to\n //require the use of `attr()`. This removes several function calls.\n\n //No... | {
"AcceptedAnswerId": "26563",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T08:42:22.280",
"Id": "26561",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Showing jQuery UI tooltip on focus of text box"
} | 26561 |
<p>I'd like a review of Haskell tree heap code in <a href="https://stackoverflow.com/questions/16639793/turning-a-tree-into-a-heap-in-haskell/16655447#comment24033886_16655447">Turning a tree into a heap in Haskell</a>.</p>
<pre><code>module Heapify where
data Tree a = Leaf a | Node (Tree a) a (Tree a)
deriving S... | [] | [
{
"body": "<h2>Correctness? Unanticipated cases?</h2>\n\n<pre><code>module Heapify where\n\ndata Tree a = Leaf a | Node (Tree a) a (Tree a) \n deriving Show\n</code></pre>\n\n<p>I think this <strong>can't host an even number of elements</strong>. <code>fromList [1,2]</code> seems impossible.</p>\n\n<pre><code... | {
"AcceptedAnswerId": "26565",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T10:00:04.493",
"Id": "26564",
"Score": "5",
"Tags": [
"haskell",
"tree",
"heap"
],
"Title": "Tree heap Haskell code"
} | 26564 |
<p>I have Winform application and I want to separate the button click event from the main form.</p>
<p>My application has Add button which adds files into my <code>Listbox</code> and until now all my code was inside this button click event and caused my code to look complicated.<br>
So I created this class:</p>
<pre>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T12:14:19.877",
"Id": "41152",
"Score": "1",
"body": "This looks a lot more complex than it needs to be, can you explain what you are trying to achieve with the code? Obviously the user is selecting some files to be added to a listbo... | [
{
"body": "<p>My first reaction is that your click handler is doing way too much work on its own. You should break up the code into smaller methods to make it easier to maintain.</p>\n\n<ol>\n<li>Move all the OpenFileDialog setup to the designer file. This will make it a field rather than local variable, prev... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T11:04:27.503",
"Id": "26566",
"Score": "1",
"Tags": [
"c#",
"winforms"
],
"Title": "Class design question"
} | 26566 |
<p>The following program is supposed to return the length of a 'hidden' string within each of the sentences of another string, using pointers and avoiding as much as possible the use of <code>[]</code> as a means to access strings. We were instructed on how to declare the functions, hence their declarations are a given... | [] | [
{
"body": "<p>A couple of points:</p>\n\n<ul>\n<li>I don't know if it's just the way the question is formatted, but better indentation would improve readability</li>\n<li>In <code>divideStringIntoSentences</code>, it would be better to add <code>{ }</code> around the <code>if</code> as if you add something to t... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T12:45:55.650",
"Id": "26567",
"Score": "4",
"Tags": [
"c",
"strings"
],
"Title": "Returning the length of a 'hidden' string within each of the sentences of another string"
} | 26567 |
<p>While working on one of my projects I actively used Reflection. While working with class <code>Type</code> I expected methods: <code>TryGetMember</code>, <code>TryGetProperty</code>, <code>TryGetField</code>, <code>TryGetMethod</code>. I've implemented them as extension methods:</p>
<pre><code>public static class T... | [] | [
{
"body": "<p>In the first <code>TryGetMember()</code>, I'd change the last line from <code>return result.Count() != 0;</code> to <code>return result.Length != 0;</code>. It's the only code that references LINQ and it's not really even needed there. If you feel compelled to use LINQ, that line would also be bet... | {
"AcceptedAnswerId": "26571",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T13:24:11.970",
"Id": "26569",
"Score": "2",
"Tags": [
"c#",
"reflection",
"extension-methods"
],
"Title": "Extension methods for class Type"
} | 26569 |
<p>I have implemented the first coding challenge on <a href="http://projecteuler.net/" rel="nofollow">http://projecteuler.net/</a>. I would love to get it reviewed by some expert rubyists!</p>
<pre><code># Multiples of 3 and 5
#
# If we list all of the natural numbers below 10 that are multiples of
# 3 and 5, we get 3... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T14:20:58.180",
"Id": "41169",
"Score": "12",
"body": "`(1...1000).select { |x| x % 3 == 0 || x % 5 == 0 }.reduce(:+)`. Food for thought: http://en.wikipedia.org/wiki/Side_effect_(computer_science) and http://en.wikipedia.org/wiki/Fu... | [
{
"body": "<ul>\n<li><p>Don't use <code>or</code>. It's for flow control. Use <code>||</code> for boolean logic.</p></li>\n<li><p>Don't use <code>Array.new</code>, use <code>[]</code></p></li>\n<li><p>Don't use <code>(1..999).to_a</code> or <code>Array(1..999)</code> when all you really want to do is iterate. I... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T14:06:56.543",
"Id": "26573",
"Score": "5",
"Tags": [
"ruby",
"programming-challenge"
],
"Title": "Multiples of 3 and 5 from Euler code challenge"
} | 26573 |
<p>I have the following code:</p>
<pre><code><?php
include '../../inc/config.php';
$size = isset($_REQUEST['size']) ? $_REQUEST['size'] : 'full';
$image = isset($_REQUEST['image']) ? $_REQUEST['image'] : FALSE;
if(!$image) {
print 'Nenhuma imagem definida!';
exit;
}
$img_hash = $PDO->prepare("SELECT ... | [] | [
{
"body": "<p>You can use <a href=\"http://php.net/manual/en/function.getimagesize.php\" rel=\"nofollow\">PHP's getimagesize() function</a> to get the MIME type.</p>\n\n<pre><code><?php\ninclude '../../inc/config.php';\n\nif(!isset($_REQUEST['image'])) die('Nenhuma imagem definida!');\n\n$size = isset($_REQU... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T16:04:03.547",
"Id": "26577",
"Score": "1",
"Tags": [
"php"
],
"Title": "Need to clean up my code and add the ability to resize the image"
} | 26577 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.