body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<blockquote>
<p>Remove an event listener after firing once or any number of times</p>
</blockquote>
<p>This is what I have:</p>
<pre><code>/*jslint browser: true, vars: true, white: true, maxerr: 50, indent: 4 */
(function ()
{
"use strict";
function removeEventListenerAfterFiring(numberOfTimes, callback, ... | [] | [
{
"body": "<p>Consider using <code>event.currentTarget</code> instead of <code>event.target</code>, since your handlers are probably bound to an ancestor element, not the current element.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"Cre... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T03:03:26.260",
"Id": "7515",
"Score": "5",
"Tags": [
"javascript",
"event-handling",
"callback"
],
"Title": "Remove an event listener after firing once or any number of times"
} | 7515 |
<pre><code>$('pre').each(function(index) {
var c = $(this).attr("class");
if (!c) {
return true;
}
// Match only Javascript code snippets
if (!c.match(/brush: js; class-name: 'jsbox'/)) {
return true;
}
var code = $(this).text();
$(this).after($("<button>Run example... | [] | [
{
"body": "<p>Change</p>\n\n<pre><code>var code = $(this).text(); \n</code></pre>\n\n<p>to</p>\n\n<pre><code>var code = $(this).val();\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-09T08:08:08.250",
"Id": "11954",
"Score... | {
"AcceptedAnswerId": "7640",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T04:30:03.173",
"Id": "7517",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"regex"
],
"Title": "Checking a HTML element's class"
} | 7517 |
<p><strong>Input:</strong> any integer</p>
<p><strong>Output:</strong> that integer in number format (commas) with a leading <code>a</code> or <code>an</code> as appropriate with the rules of English</p>
<p>After a bit of groping around I hacked out the following PHP function, and am looking for any advice on code st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T16:31:14.923",
"Id": "11825",
"Score": "0",
"body": "Not a function, but a component made for such jobs: http://php.net/manual/en/class.numberformatter.php"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01... | [
{
"body": "<p>Rather than having many return statements I would keep the logic that determines whether it should be 'a' or 'an' together. I think it is actually easier to understand reading the ANDs and ORs than spread out <code>if</code> and <code>else</code> statements.</p>\n\n<p>I prefer not to create tempo... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T06:05:25.390",
"Id": "7519",
"Score": "1",
"Tags": [
"php"
],
"Title": "function to append \"a\" or \"an\" to the front of a number as appropriate"
} | 7519 |
<p>Further to the <a href="https://stackoverflow.com/questions/8711239/circle-summation-30-points-interviewstree-puzzle/8712670#8712670">question</a>
I solved it in following way.</p>
<pre><code>#include <iostream>
#include <algorithm>
#include <iterator>
#include <stdio.h>
int main ( int ar... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T06:47:37.567",
"Id": "11791",
"Score": "0",
"body": "hehe, I'm trying the same problem. I don't know how to solve it."
}
] | [
{
"body": "<pre><code>#include <iostream>\n#include <algorithm>\n#include <iterator>\n#include <stdio.h>\n\n\nint main ( int argc, char **argv) {\n int T; // number of test cases\n std::cin >> T;\n for ( int i = 0 ; i < T; i++) {\n int N; // number of childrens\n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T06:19:31.010",
"Id": "7521",
"Score": "0",
"Tags": [
"c++",
"algorithm"
],
"Title": "Circle Summation (30 Points) InterviewStree Puzzle cont"
} | 7521 |
<p>I have this module which computes checksums from a list of files in a given directory.
The problem is that my is_changed_file is long and ugly, but my attempts in refactoring failed, so I would like some other point of views...</p>
<pre><code>import hashlib
import logging
# if available use the faster cPickle modu... | [] | [
{
"body": "<p>Probably there is no need to refactor the method as it represents quite clear decision tree. Breaking it down into smaller methods will cause readability problems.</p>\n\n<p>Just make sure you have unit tests covering each outcome and that there are no cases, which the code doesn't handle.</p>\n\n... | {
"AcceptedAnswerId": "7595",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T13:50:15.787",
"Id": "7529",
"Score": "2",
"Tags": [
"python"
],
"Title": "Python and computing checksums"
} | 7529 |
<blockquote>
<p>The following is a new question based on answers from here: <a href="https://codereview.stackexchange.com/q/5039/3163">Small PHP Viewer/Controller template</a> </p>
</blockquote>
<p>I have written a small MVC template library that I would like some critiques on.</p>
<p>The library is <a href="https:... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T14:38:52.543",
"Id": "12247",
"Score": "0",
"body": "@ZaphodBeeblebrox The `Config` is just a holder of global Configuration variables. I do not feel the need to include it here since it is not really important. I **did not** includ... | [
{
"body": "<p>I think your code is at a point where you need to stop worrying about it. It's not <em>perfect</em>, but it's way past the point of anything obvious. </p>\n\n<p>The one thing I really don't like is your <code>Config</code> class. I get it that <code>static</code> is heplful, but you are abusing it... | {
"AcceptedAnswerId": "7894",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T14:55:49.853",
"Id": "7531",
"Score": "8",
"Tags": [
"php",
"library"
],
"Title": "Small PHP MVC Template"
} | 7531 |
<p>This is a framework for a JSON parser I put together last night.</p>
<p>Any comments appreciated.</p>
<ul>
<li>JsonLexer.l: Breaks the input into lexemes</li>
<li>JsonParser.y: Understands the language syntax</li>
<li>JsonParser.h: Header file to bring it all togeter</li>
<li>main.cpp: Test harness so it can ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T08:30:14.793",
"Id": "26521",
"Score": "3",
"body": "What is C++ or object oriented about this? Flex & Bison generate C code. The only C++ code that is see is the test code written in main.cpp. Either you call it a C parser or use [... | [
{
"body": "<p>I've hesitated for quite a while, but decided there are a few points worth commenting on.</p>\n\n<p>The first and most obvious is that (by design) this simply doesn't do much. It can log the types of statements encountered in the JSON you give to it, but that's all. To be of much real use, you'd n... | {
"AcceptedAnswerId": "55612",
"CommentCount": "12",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T17:26:31.463",
"Id": "7536",
"Score": "48",
"Tags": [
"c++",
"parsing",
"json",
"lex",
"yacc"
],
"Title": "Yet another C++ JSON parser"
} | 7536 |
<p>I've taken criticism before on my PHP and have since then taken the improvements into my routine. However, I still believe that I can improve.</p>
<p>I believe that SE is the best place for the best programmers. If any of you are bored enough to tell me what I can do better, I'd appreciate it greatly.</p>
<p>You c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-08-04T23:34:06.427",
"Id": "181561",
"Score": "0",
"body": "The title of your post should be the function/purpose of your code."
}
] | [
{
"body": "<p>I've not reviewed the whole piece of code yet but I spotted two things right away just three lines in. </p>\n\n<pre><code>$file = @$_GET['u'] ? $_GET['u'] : 'tasks';\n</code></pre>\n\n<p>There are two problems with this. The first is the use of @ to suppress errors. This is considered bad pract... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T20:08:05.783",
"Id": "7539",
"Score": "0",
"Tags": [
"php",
"mvc"
],
"Title": "I want to improve my overall PHP"
} | 7539 |
<p>This is my solution to the codercharts problem <a href="http://codercharts.com/puzzle/word-swap" rel="nofollow">http://codercharts.com/puzzle/word-swap</a> but if keeps failing when I submit the solution because of the <code>cpu_excess_time</code>. Please suggest possible optimisations for this problem, I believe my... | [] | [
{
"body": "<p>Simple optimizations:</p>\n\n<p>By reading the whole file into text, then splitting the text into a word list, you will need enough memory to hold two copies of the file, which might be huge. Look into line-by-line input methods.</p>\n\n<p>Many strings, after a quick check, don't need to be seen e... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T21:11:07.320",
"Id": "7540",
"Score": "2",
"Tags": [
"python"
],
"Title": "CoderCharts puzzle optimization"
} | 7540 |
<p>I started a web project. Now I was wondering if it is secure enough. I followed some tutorials on HTS, but I can't see all holes (if there are any). Can you check my pages and if you can find any hole in it (like XSS or SQL injections). Thanks for helping :)!</p>
<p>My URL is: **</p>
<p>And another security questi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T05:54:15.580",
"Id": "11838",
"Score": "0",
"body": "I can't scroll down on [this page](https://websilon.org/user/create/). Chrome Canary 18.x."
}
] | [
{
"body": "<p>Check your MySQL database. If you have another table called \"websiteIsNotSecure\" then you need to sanitize your database inputs. Also, it'd be easier to check security if we had some code to look at. You can't view PHP code, it's all parsed/executed on the server.</p>\n",
"comments": [
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T00:30:20.063",
"Id": "7543",
"Score": "1",
"Tags": [
"php",
"javascript",
"optimization",
"html",
"security"
],
"Title": "My web project security"
} | 7543 |
<p>I've got a module I use to log around functions that performs external requests.</p>
<pre><code># Functions to track when a block begins and ends
module LogAround
# log at begin and end of a given block
# with a mesage and the given params
def log_around(message, *args)
start_time = Time.now
Rails.lo... | [] | [
{
"body": "<p>You may not define a free message, but I think this may be a solution:</p>\n\n<pre><code>module LogAround\n # log at begin and end of a given block\n # with a mesage and the given params\n def log_around( method_to_log )\n alias_method \"_orig_#{method_to_log}\".to_sym, method_to_log\n\n ... | {
"AcceptedAnswerId": "7553",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T13:39:15.653",
"Id": "7549",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Log around a function call"
} | 7549 |
<p>I wrote a web files browser. I want to refactor my JavaScript code, but I'm new to JavaScript. </p>
<p>I have some thoughts:</p>
<ol>
<li><p>Split the file into several files:</p>
<ul>
<li><code>FoldersManager.js</code></li>
<li><code>FilesManager.js</code></li>
<li><code>Paginator.js</code></li>
<li><code>Globa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T16:56:24.503",
"Id": "11844",
"Score": "0",
"body": "naming conventions: Use a [styleGuide](https://github.com/Raynos/pd/blob/master/docs/styleGuide.md) of your choice."
}
] | [
{
"body": "<p>Your thinking is much better. One thing need to attention: don't left global <code>var</code>s. The best practice is to use global objects, and put the global <code>var</code>s into them.</p>\n\n<p>When you make the object's responsibility clear, make sure every function is in the right object. ... | {
"AcceptedAnswerId": "7653",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T14:50:27.080",
"Id": "7551",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"beginner"
],
"Title": "Web files browser"
} | 7551 |
<p>This is in C/C++ (using a c-string as input). I'm curious if my solution could be more efficient than it currently is.</p>
<pre><code>char mostFrequent(char *bytes, int length) {
char holder[26];
for (int i = 0; i < 26; i++) {
holder[i] = 0;
}
for (int i = 0; i < length; i++) {
holder[bytes[i... | [] | [
{
"body": "<p>If you are intended to measure the frequency of bytes, as the name of your input string seems to suggest, rather than just lowercase ASCII letters, then your <code>holder</code> array should be 256 elements long. </p>\n\n<p>This also saves you from all the additions and subtractions of the 'magic'... | {
"AcceptedAnswerId": "7554",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T16:52:16.407",
"Id": "7552",
"Score": "8",
"Tags": [
"c++",
"c",
"strings"
],
"Title": "Finding the most frequent character in a string"
} | 7552 |
<p>I have just started learning about JavaScript and events. I am interested in learning the JavaScript and not jQuery until I am better at JavaScript.</p>
<p>I wrote this code that will show and hide my div because I basically want to be able to use this code in future web development projects but at the moment it wi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T19:43:19.433",
"Id": "11849",
"Score": "0",
"body": "My initial thought is -- you are really doing great. Doesn't look like NOOBs code. Think of using `prototype` to improve modularity of the code."
},
{
"ContentLicense": "C... | [
{
"body": "<p><strong>Item 1:</strong> I'd suggest getting rid of all global variables except <code>tog</code>. They don't look like they are needed and just open you up for a potential conflict with other global variables.</p>\n\n<p><strong>Item 2:</strong> This line of code:</p>\n\n<pre><code>if (tog = 1 &am... | {
"AcceptedAnswerId": "7561",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T19:34:32.520",
"Id": "7559",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Showing and hiding element, making my code more useful"
} | 7559 |
<pre><code>List<Route> listOfRoutes = routeStopsService.getAllRoutes();
Set<String> listOfStopNames = new TreeSet<String>();
for(Route route:listOfRoutes){
Set<Stop> stops = routeStopsService.getStops(route);
for(Stop stop:stops)
listOfStopNames .add(stop.getStopName());
list... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T22:26:03.863",
"Id": "11860",
"Score": "2",
"body": "can you guarantee that the last one is the one you want to remove? sets aren't necessarily ordered..."
}
] | [
{
"body": "<p>It is kind of hard to tell by looking at your code, (you have not shown us the definition of <code>listOfSources</code>, and you appear to be doing some stuff which appears to have no purpose in the sample code you provided,) but it appears to me that your approach of removing the last item from t... | {
"AcceptedAnswerId": "7569",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T19:36:35.817",
"Id": "7560",
"Score": "1",
"Tags": [
"java",
"collections"
],
"Title": "How to delete last element in java.util.Set efficiently?"
} | 7560 |
<p>So this is probably a popular problem, and I decided to take a crack at it today using C#.</p>
<p>I came up with the following solution: </p>
<pre><code>private BinaryTree<int>.BinaryTreeNode FindLowestNodes(BinaryTree<int>.BinaryTreeNode node, int depth, ref int biggestDepth) {
this.WriteResult("... | [] | [
{
"body": "<p>Passing an int with the <code>ref</code> keyword does <em>not</em> involve any boxing at all. Do not confuse this with \"passing an int by reference\" (as in, a function with return type <code>Object</code> returning an <code>int</code>,) which is quite a different thing, and it <em>does</em> invo... | {
"AcceptedAnswerId": "7565",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T21:47:14.503",
"Id": "7564",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Find lowest leaf nodes in a binary tree"
} | 7564 |
<p>I am writing code that has objects having integer member variables where the integer value has a specific constant meaning, which normally means "use an enum".</p>
<p>Suppose the values are the days of the week, Monday = 0, Tuesday = 1, and so on. (In my real case, there are several different "types" involved, som... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T23:50:48.760",
"Id": "11866",
"Score": "0",
"body": "What's wrong with `Days.Monday`? How is that not readable? Why wouldn't you want to use the `DayOfWeek` enumeration that's already included in the framework? I don't understand... | [
{
"body": "<p>Normally it would disgust me, but you appear to have a valid reason to use it, which stems from the pre-existing disgusting situation that you have to cope with these data objects that use ints.</p>\n\n<p>The only thing I would ask is, why can these data objects not use enums? What is it about the... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T23:31:23.383",
"Id": "7566",
"Score": "8",
"Tags": [
"c#",
"enum"
],
"Title": "Enum vs int wrapper struct"
} | 7566 |
<p>Following on from this request <a href="https://codereview.stackexchange.com/q/7536/507">Yet another C++ Json Parser</a></p>
<p>A friend pointed out that he though a recursive decent parser would be more efficient.<br>
Before I agree I want to test it so I wrote it for testing.</p>
<p>I found the implementation of... | [] | [
{
"body": "<p>Recursion generally isn't more efficient, just easier to program and understand. For simpler examples it also leads to much neater code however can be harder to understand if you have multiple levels of recursion jumping around.</p>\n\n<p>Each function call will add stuff to the stack as such it w... | {
"AcceptedAnswerId": "7614",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T23:36:10.100",
"Id": "7567",
"Score": "4",
"Tags": [
"c++",
"json",
"lex",
"yacc"
],
"Title": "Yet another C++ Json Parser (Recursive)"
} | 7567 |
<p>The goal of this code is to save a list of 250000 words with a number that indicates its frequency. The 250000 are sorted alphabetically but the frequency is unsorted. The idea is that a user must insert capitalized words, spaces or numbers after each word to lookup in the saved 250000-word list.</p>
<p>The max num... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T22:19:12.347",
"Id": "11874",
"Score": "6",
"body": "What is your question?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T22:21:46.400",
"Id": "11875",
"Score": "0",
"body": "How can I f... | [
{
"body": "<p><code>Dictionary<Y></code> is only efficient if you access the entries through the key. You are enumerating the dictionary with linq. This is very slow. Try to access it like this:</p>\n\n<pre><code>int count;\nif (dic.TryGetValue(am, out count)) {\n // found\n} else {\n // not found\n... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-07T22:15:28.983",
"Id": "7571",
"Score": "2",
"Tags": [
"c#",
"homework",
"lookup"
],
"Title": "Alphabetically-sorted word lookup"
} | 7571 |
<p>Below is an implementation of a typical <code>Logger</code> interface that uses <code>syslog()</code> as the default means to store messages and falls back to <code>error_log()</code> if that does not work. This is the first time I've used <code>syslog</code> and just want to ensure that my code is logical and ther... | [] | [
{
"body": "<p>You need a <code>SysLog</code> interface and a <code>SysLogImpl</code> implementation class.</p>\n\n<pre><code>public interface SysLog {\n public bool openlog(string $ident, int $option ,int $facility);\n public bool syslog (int $priority, string $message);\n public bool closelog (void);\... | {
"AcceptedAnswerId": "7586",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T05:12:39.263",
"Id": "7574",
"Score": "2",
"Tags": [
"php",
"unit-testing"
],
"Title": "Logger to syslog with error_log fallback"
} | 7574 |
<p>Given that it is better to reuse objects than create new ones when developing with Android, is it worth while deleting the contents of a <code>StringBuilder</code> and reusing it?</p>
<pre class="lang-java prettyprint-override"><code>StringBuilder b = new StringBuilder();
//build up a string
b.delete(0, b.length())... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T14:23:23.840",
"Id": "11894",
"Score": "1",
"body": "Is this even worth thinking about as long as it is not in a very tight loop?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T09:22:00.917",
"Id... | [
{
"body": "<p>Yes, of course it is worthwhile, even in the great big world outside of Android.</p>\n\n<p>According to <a href=\"http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/StringBuilder.html\" rel=\"nofollow\">the documentation about <code>StringBuilder</code></a>:</p>\n\n<blockquote>\n <p>Every str... | {
"AcceptedAnswerId": "7585",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T05:26:10.157",
"Id": "7575",
"Score": "26",
"Tags": [
"java",
"optimization",
"performance",
"strings",
"android"
],
"Title": "Reusing StringBuilder or creating a new on... | 7575 |
<p>I'm currently looking at, from a rather high level, the parallelization of the gravity calculation in an <a href="http://en.wikipedia.org/wiki/N-body_simulation">N-body simulation</a> for approximating a solution to the <a href="http://en.wikipedia.org/wiki/N-body_problem">N-body problem</a>.</p>
<p>The simple form... | [] | [
{
"body": "<p>You seem to be making the problem more complex:</p>\n\n<p>I would take a step back to your original algorithm:</p>\n\n<pre><code>#pragma omp parallel for\nfor (int i = 0; i < n; i++)\n for (int j = i + 1; j < n; j++)\n bodies[i].PairwiseGravity(bodies[j]);\n</code></pre>\n\n<p>Your... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T08:34:01.773",
"Id": "7578",
"Score": "15",
"Tags": [
"c++",
"multithreading",
"locking",
"cache",
"lock-free"
],
"Title": "Lock-free cache oblivious n-body algorithm"
} | 7578 |
<p>I have a table in a SQL Server database, which holds information of some images, and the relevant gallery of them. The columns are like:</p>
<p><code>ImageId</code>, <code>GalleryId</code>, <code>Order</code></p>
<p>I have a unique key on <code>GalleryId-Order</code> columns, that is, each image should have a uniq... | [] | [
{
"body": "<p>Little merging, since you have an index on GalleryId, [Order]:</p>\n\n<pre><code>create procedure MoveImage(@imageId int, @newOrder int)\nas\nbegin\n declare @mediaCount int;\n declare @galleryId int;\n declare @currentOrder int;\n\n -- Finding the related gallery\n -- Finding the c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T08:47:47.193",
"Id": "7580",
"Score": "3",
"Tags": [
"sql",
"sql-server",
"t-sql",
"sorting"
],
"Title": "Shifting records in SQL Database while sorting with algorithm"
} | 7580 |
<p>What do you think of <a href="http://websilon.org/" rel="nofollow">http://websilon.org/</a>? Are there things that can be improved? Is there something missing? See the source of the webpages for code.</p>
<pre><code><!DOCTYPE HTML>
<html><head>
<title>Websilon - Mathematical Knowledge Base&l... | [] | [
{
"body": "<p>Don't mix up html, css and javascript. Put the css and javascript into separate files and externally reference them from the html files, this will:</p>\n\n<ol>\n<li>clean up your html files</li>\n<li>allow the browser to cache the css and javascript so the files don't have to be re-downloaded for ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T15:01:56.383",
"Id": "7587",
"Score": "3",
"Tags": [
"javascript",
"html",
"css"
],
"Title": "New web project"
} | 7587 |
<p>This is a subtle question about design in which I want to find the most elegant and appropriate solution. </p>
<p>I have an enumeration representing a French card deck (see code below). With it I need to do certain things, such as displaying the elements in a table. I'll want to display the elements starting with A... | [] | [
{
"body": "<p>I think you <em>should</em> add a numeric field indicating the order of a card relative to the other cards. You do not need to use it for anything other than sorting. </p>\n\n<p>Also, instead of taking the identifier of the enum value and doing uppercase and lowercase tricks with it in order to tu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T18:20:54.730",
"Id": "7593",
"Score": "5",
"Tags": [
"java",
"playing-cards",
"enum"
],
"Title": "Should I design my enumeration in some way that indicates what the highest value ... | 7593 |
<p>I'm a beginner in Java so I would appreciate a review of following simple class - in fact it's my first real usage of enums.</p>
<p>The background: I'm parsing MySQL internal client-server protocol. One of the fields in server greeting and client authorization packet is "Client capabilities" which is 32 bit integer... | [] | [
{
"body": "<p>Looks fine to me. The only thing I have to notice is that <code>if ((capabilities & f.weight) > 0)</code> should instead be <code>if ((capabilities & f.weight) != 0)</code>. The reason for this is that if you were using bit #31 (the 32nd bit) then the expression <code>capabilities &... | {
"AcceptedAnswerId": "7602",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T18:31:14.033",
"Id": "7594",
"Score": "3",
"Tags": [
"java",
"enum"
],
"Title": "Boolean flags encoded as integer implemented with EnumSet"
} | 7594 |
<p>For practice, I've implemented Sieve of Eratosthenes in Java by thinking about <a href="http://en.wikipedia.org/wiki/File%3aSieve_of_Eratosthenes_animation.gif" rel="nofollow">this visual animation</a>.</p>
<p>I would like to hear some suggestions for improvements, especially how to make it more efficient and reada... | [] | [
{
"body": "<p>Input checking is missing. You should throw an <code>IllegalArgumentException</code> if <code>max</code> is less than zero instead of the <code>NegativeArraySizeException</code>. </p>\n\n<p>Result of <code>Math.sqrt(max)</code> doesn't change, so maybe it's would worth to extract out to a local va... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T19:20:59.177",
"Id": "7599",
"Score": "12",
"Tags": [
"java",
"optimization",
"algorithm",
"primes",
"sieve-of-eratosthenes"
],
"Title": "Sieve of Eratosthenes"
} | 7599 |
<p>I asked a <a href="https://codereview.stackexchange.com/questions/7574/logger-to-syslog-with-error-log-fallback">question about an implementation of a logger using <code>syslog</code> and <code>error_log</code> as fallback</a> that made me re-evaluate my <code>Logger</code> interface. Before it simply forced a <cod... | [] | [
{
"body": "<blockquote>\n <p><code>NullLogger</code> wouldn't really need any parameters passed to \n <code>openLog()</code> where as <code>SysLogLogger</code> would probably need some \n parameters passed. How would I accomplish this?</p>\n</blockquote>\n\n<p>Pass these parameters to the constructor, store ... | {
"AcceptedAnswerId": "7603",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T20:03:52.433",
"Id": "7600",
"Score": "2",
"Tags": [
"php",
"api"
],
"Title": "Refactoring Logger interface to open and close logs"
} | 7600 |
<p>What do you say about the code structure below? This is one of the recommended ways of writing JS code in my education.</p>
<p>What is the pros and cons with writing code this way?
Can you recommend any better and maybe more elegant ways of writing code?</p>
<pre><code>var DESKTOP = DESKTOP || {};
DESKTOP.Init = D... | [] | [
{
"body": "<p>Oh gosh... that looks horrible, whoever is teaching you has no idea of JS whatsoever.</p>\n\n<p>I'll give you a quick start on \"good\" structure.</p>\n\n<p>A bit on naming:</p>\n\n<pre><code>UPPERCASE = Constant\nUpperCamelCase = Class\neverythingElse = method / function / variable\n</code></pre>... | {
"AcceptedAnswerId": "7604",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T20:28:32.597",
"Id": "7601",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Desktop windows code"
} | 7601 |
<p>I am creating a simple server that accepts a <code>int</code> and returns the value received twice:</p>
<pre><code>public class MyServer{
private static int port = 1234;
public static void main(String args[]){
try{
ServerSocket serversock=new ServerSocket(port);
while(true)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T15:18:13.817",
"Id": "12626",
"Score": "0",
"body": "NEVER catch exceptions and eat them silently, as you are doing: `catch(IOException e){}` At least put `e.printStackTrace();` between the braces."
}
] | [
{
"body": "<p>The ugly part that sticks out is that you are silently ignoring the exceptions... You should do some cleanup and close the sockets at least.</p>\n\n<p>Improving a bit on the performance side, you are starting a new thread to execute a very small task, thus wasting a lot of time to start-up threads... | {
"AcceptedAnswerId": "7611",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-08T22:31:17.317",
"Id": "7609",
"Score": "12",
"Tags": [
"java",
"multithreading",
"server"
],
"Title": "Concurrent programming with a simple server"
} | 7609 |
<p>I've got my answer working (up until a <a href="http://www.nairaland.com/nigeria/topic-791297.0.html#msg9490894" rel="nofollow">7-digit answer</a> is requested, anyway), and would like some help </p>
<ol>
<li>returning the correct answer</li>
<li>speeding up the results</li>
</ol>
<p>I was thinking of storing the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-09T00:59:54.577",
"Id": "11926",
"Score": "0",
"body": "what makes you think your code is broken for 7 digit numbers?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-09T02:13:13.557",
"Id": "11933",
... | [
{
"body": "<p>The way you use ranges is not particularly pythonic, as far as I can judge. I think something like this would be preferred:</p>\n\n<pre><code>def main(n):\n start = 10**n - 1\n for i in range(start, 0, -1):\n for j in range(start, i, -1):\n if is_palindrome(str(i*j)):\n ... | {
"AcceptedAnswerId": "7617",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-09T00:31:08.417",
"Id": "7615",
"Score": "3",
"Tags": [
"python",
"optimization",
"project-euler",
"palindrome"
],
"Title": "Project Euler, #4: Incorrect Results on 7-digit num... | 7615 |
<p>I have this recursive function that searches an object tree structure:</p>
<pre><code>dataSearcher = (dataElement, identifierToFind) ->
if dataElement.identifier == identifierToFind
return dataElement
else
for childDataElement in dataElement.children
found = dataSearcher chil... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T18:34:38.337",
"Id": "11930",
"Score": "2",
"body": "You could make the `for` a comprehension, but it wouldn't cut the visit short when a match was found, so while this is less \"functional\" it's just as good. The real test of code... | [
{
"body": "<p>I'd prefer writing it like this:</p>\n\n<pre><code>dataSearcher = (element, identifier) -> \n return element if element.identifier is identifier\n for child in element.children\n found = dataSearcher child, identifier\n return found if found\n</code></pre>\n\n<p>Changes:</p>\n\n<ul>\n<l... | {
"AcceptedAnswerId": "7619",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T15:47:07.810",
"Id": "7618",
"Score": "4",
"Tags": [
"beginner",
"recursion",
"search",
"coffeescript"
],
"Title": "Searching an object tree structure"
} | 7618 |
<p>I've been working on a JS/HTML5 Game Engine. Right now I'm calling it DimSumJs, because like <a href="http://en.wikipedia.org/wiki/Dim_sum" rel="nofollow">DimSum</a>, isn't a full meal, my framework still runs too slowly to make a full game (it can only run about 400 "objects" despite before slowing down, it becomes... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-09T11:05:55.027",
"Id": "25197",
"Score": "0",
"body": "Have you tried setting the objects to null once your done using them?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-09T12:37:32.677",
"Id": "251... | [
{
"body": "<p>The biggest improvement i could give is getting rid of all the if oftype</p>\n\n<p>replace with :</p>\n\n<pre><code>var enem1 = [];\nfunction enem1Step()\n{\n this.anim(); \n if (this.y > MASTER_HEIGHT){\n this.x = random()*(MASTER_WIDTH-64);\n this.y = -128;\n thi... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-09T04:13:06.200",
"Id": "7621",
"Score": "3",
"Tags": [
"javascript",
"optimization",
"html"
],
"Title": "Help optimize my HTML/JS game engine"
} | 7621 |
<p>I wrote <a href="http://en.wikipedia.org/wiki/Nim">Nim Game</a> in Haskell. Since I'm just learning any review comments are highly appreciated.</p>
<pre><code>module Nim where
import Char
import List
import Maybe
--Domain
--Nim is a mathematical game of strategy
--in which two players take turns removing objec... | [] | [
{
"body": "<p>These variations seem more direct and make better use of standard functions and idioms</p>\n\n<pre><code>--Build new board according to old one and turn.\napplyTurn :: Turn -> Board -> Board\napplyTurn (heap, removed) b = \n let (before, (at:after)) = splitAt (heap-1) b\n in before ++... | {
"AcceptedAnswerId": "7636",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-09T10:24:39.313",
"Id": "7623",
"Score": "9",
"Tags": [
"haskell",
"game"
],
"Title": "Nim Game in Haskell"
} | 7623 |
<p>I'm trying to compare my own implementation with another solution of <a href="http://projecteuler.net/problem=1" rel="nofollow">Project Euler problem #1</a>, which uses a list comprehension:</p>
<pre><code>module Progression1 (sumProgressions) where
import Prelude
sumProgressions :: Integer -> Integer -... | [] | [
{
"body": "<p>I'll leave the question open, but here are some other attempts. Credit goes to <a href=\"https://stackoverflow.com/users/46642/r-martinho-fernandes\">RMartinhoFernandes</a> for <code>solution3</code>, which requires his <a href=\"http://hg.tumtumtree.me/pointfree/src\" rel=\"nofollow noreferrer\"... | {
"AcceptedAnswerId": "7644",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T02:05:13.633",
"Id": "7629",
"Score": "7",
"Tags": [
"performance",
"beginner",
"haskell",
"functional-programming",
"programming-challenge"
],
"Title": "Finding the sum... | 7629 |
<p>Usually, people would create two extra-threads in order to read the standard output and error respectively. However, the following code would allow to handle a Process outputs without those threads (it is arguably a little bit more difficult to decode the characters if you are using something else than a single-byte... | [] | [
{
"body": "<p>Is <code>inputStream.available()</code> a blocking method?</p>\n\n<p>The process might send an error message while your are blocked (possibly forever) in the standard output <code>available()</code> waiting for something that will never arrive.</p>\n",
"comments": [
{
"ContentLic... | {
"AcceptedAnswerId": "7844",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T02:46:24.593",
"Id": "7631",
"Score": "11",
"Tags": [
"java",
"io"
],
"Title": "Handle Java Process outputs without extra-threads"
} | 7631 |
<p>I have started to reading up on electronics and embedded software. Lately I have been looking at IC's, particularly shift registers. I thought a good way of learning more about serial communication and shift registers was to implement the internal logic of a shift register. </p>
<p>The one I have chosen is the <a h... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T15:57:24.190",
"Id": "11993",
"Score": "1",
"body": "Pretty general question but is :\nvoid setVal (Object foo, Value bar) { if (foo->value != bar) foo->value = bar; }\nreally better than :\nvoid setVal (Object foo, Value bar) { foo... | [
{
"body": "<p>OK. Looking at this as a code maintainer and not understanding what the underlying logic of the chip does (which is what will happen in real life).</p>\n\n<p>The function names look a bit generic.<br>\nYou may want to prefix them with the name of the chip (C unlink C++ does not provide function ov... | {
"AcceptedAnswerId": "7649",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T12:22:34.020",
"Id": "7638",
"Score": "4",
"Tags": [
"c"
],
"Title": "74HC595 IC software implementation"
} | 7638 |
<pre><code>mysql> select count(username) from users where no_tweets > 50;
+-----------------+
| count(username) |
+-----------------+
| 282366 |
+-----------------+
1 row in set (5.41 sec)
mysql> select sum(no_tweets) from users where no_tweets > 50;
+----------------+
| sum(no_tweets) |
+-------... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T19:32:13.970",
"Id": "12004",
"Score": "1",
"body": "And your question is...?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T19:34:56.443",
"Id": "12005",
"Score": "0",
"body": "Did not r... | [
{
"body": "<p>You want better performance? </p>\n\n<p>if you want really better performance you should try to use some of the compiled code languages (like C). Because interpreted language takes much more time.</p>\n\n<p>For example, if you take a simple loop, you will notice the difference</p>\n\n<p>int i = 0;... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T19:26:53.443",
"Id": "7645",
"Score": "5",
"Tags": [
"python",
"mysql",
"performance"
],
"Title": "40 million tweets from 200k users"
} | 7645 |
<p>I have created a piece of code for a live pagination, but I don't like the code. It works it does the job, but I guess I could done it better.</p>
<pre><code>$('.show-content').livequery(function() {
$(this).find('.page-me:not(:first)').hide();
var totalPage = $(this).find('.page-me').length;
for (var ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T21:34:48.623",
"Id": "12026",
"Score": "1",
"body": "livequery is the devil and needs to die in fire"
}
] | [
{
"body": "<p>The code looks fine to me. The only things I would personally change is the use of the <code>live()</code> method (which has been deprecated, and was slow anyway) to<code>delegate()</code> and the use of the <code>:nth()</code> selector, which again I believe is not very fast - although I've not s... | {
"AcceptedAnswerId": "7651",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T21:17:14.827",
"Id": "7650",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"pagination"
],
"Title": "Pagination using livequery in jQuery"
} | 7650 |
<p>I need help refactoring code for my PHP template engine. I just have this feeling that the code is too disorganized and can be improved performance-wise. My main concerns are running a preg_match on every line in the file and hard-coding functionality for conditional and repeat blocks. </p>
<pre><code><?php
cl... | [] | [
{
"body": "<p>Once I saw a similar templating engine, and it was so unnecessarily complex that I replaced it with something stupidly simple:</p>\n\n<pre><code>function php_as_template( $_t_filename, $_t_vars = null ){\n // make local variables from values in $_t_vars\n if( $_t_vars ) foreach( $_t_vars as $_t_... | {
"AcceptedAnswerId": "7719",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T01:35:17.223",
"Id": "7656",
"Score": "2",
"Tags": [
"php"
],
"Title": "PHP Templating Engine"
} | 7656 |
<p>I created a PHP class to handle building SQL query strings. I need advice on how to make the code more efficient. </p>
<pre><code><?php
/**
* Example:
*
* $query = new SQLQuery();
* $query->select('*')->from('users')->where(array('banned' => 0))->order('id' => 'asc')->limit(1);
* $res... | [] | [
{
"body": "<p>I usually prefer to use existing solutions, can you look at the PHP Doctrine Query Builder, which has its own DQL language inspired by HQL (Hibernate Query Language), while its focused on objects it may provide useful pointers at <a href=\"https://github.com/doctrine/dbal/tree/master/lib/Doctrine/... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T01:42:46.043",
"Id": "7657",
"Score": "4",
"Tags": [
"php",
"sql"
],
"Title": "PHP SQLQuery class"
} | 7657 |
<p>Below is the code for a database class that wraps around a small set of the features that the <code>mysqli</code> extension provides. I'm looking for ways to improve its efficiency. Which parts of the code seem hack-ish and how can I make it more structured and organized?</p>
<pre><code>class Database extends Compo... | [] | [
{
"body": "<p>It looks like you are trying to write object oriented code, however this is completely procedural. Remove <code>static</code> everywhere and use dependency injection if you want to make this OO.</p>\n\n<p>Static code is hard to test. It is the equivalent a namespaced function.</p>\n\n<p>The real ... | {
"AcceptedAnswerId": "7660",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T01:48:23.660",
"Id": "7658",
"Score": "3",
"Tags": [
"php",
"sql",
"mysqli"
],
"Title": "PHP Database class"
} | 7658 |
<p>In page load I'm saving a query string int value in a viewstate. Then I save it to my DB. Here is the code I use to retrieve viewstate value and validating it:</p>
<pre><code>protected int CurrentCom
{
get
{
if (ViewState["CurrentCom"] == null)
return 0;
else
{
... | [] | [
{
"body": "<p>I'm not too familiar with C#, but the else branch looks unnecessary, since if <code>ViewState[\"CurrentCom\"] == null</code> is <code>true</code> the method returns with <code>0</code>.</p>\n\n<pre><code>if (ViewState[\"CurrentCom\"] == null) {\n return 0;\n}\nint currentCom;\nif (int.TryParse(... | {
"AcceptedAnswerId": "7669",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T11:22:15.247",
"Id": "7663",
"Score": "4",
"Tags": [
"c#",
"casting"
],
"Title": "Is this a proper way to check a viewstate of type int?"
} | 7663 |
<p><strong>Usage example</strong></p>
<pre><code>var qm = new QueueMessage("foo", 99);
var ba = ByteArraySerializer<QueueMessage>.Serialize(qm));
</code></pre>
<p><strong>Class that performs the serialization / deserialization</strong></p>
<pre><code>using System.IO;
using System.Runtime.Serialization.Formatte... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T18:43:04.467",
"Id": "12093",
"Score": "1",
"body": "It should be noted that this only (de)serializes serializable objects, so it won't necessarily work for any _arbitrary_ unknown object."
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>Your methodology is solid on the generics front. Highly recommend using <code>using</code> statements rather than <code>try..finally</code>s. I also converted the methods to extension methods.</p>\n\n<pre><code>namespace Codingoutloud\n{\n using System.IO;\n using System.Runtime.Serialization.... | {
"AcceptedAnswerId": "7677",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-01-11T16:01:45.973",
"Id": "7673",
"Score": "9",
"Tags": [
"c#",
"generics",
"serialization"
],
"Title": "Serialize C# objects of unknown type to bytes using generics"
} | 7673 |
<p>Here is my controller class for my MVC pattern with all the <code>includes</code> removed. From what I know of the MVC pattern it is good to have a small controller class. Mine is just a collection of public static functions which accept requests and send data to the client.</p>
<p>Regarding <code>send()</code>. ... | [] | [
{
"body": "<p>It looks like you are trying to write object oriented code, however this is completely procedural. Remove static everywhere and use dependency injection if you want to make this OO.</p>\n\n<p>Static code is hard to test. It is the equivalent of a namespaced function.</p>\n\n<p>Even your new object... | {
"AcceptedAnswerId": "7680",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T16:48:05.673",
"Id": "7676",
"Score": "4",
"Tags": [
"php"
],
"Title": "MVC Controller Class"
} | 7676 |
<p>I'm developing a Rails-based web interface/API for a large, vendor-supplied, legacy Oracle database. One of the constraints is that I can't change the schema other than adding views, because it still has to support the vendor's application.</p>
<p>The table for customer data has a limited number of columns, and ext... | [] | [
{
"body": "<p>I think the query of the database would only happen once in production mode (the class would get cached, in development mode, the class gets reloaded every request that references a Customer object). You can confirm this by setting:</p>\n\n<pre><code>config.log_level = :debug\n</code></pre>\n\n<p>... | {
"AcceptedAnswerId": "7854",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T19:10:31.763",
"Id": "7682",
"Score": "7",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Dynamic association generation in ActiveRecord"
} | 7682 |
<p>Currently, in my project I have one class that is dedicated to the all of the queries for the IBM i and converts it into usable models for my .NET code. There is already 12 methods in this class and there <em>will</em> be many, many more to come. This is for a tool that pulls data from our IBM i and pushes it to our... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T19:29:46.607",
"Id": "12099",
"Score": "1",
"body": "Please post some code (according to the FAQ)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T19:40:52.330",
"Id": "12101",
"Score": "0",
... | [
{
"body": "<p>This class has a well defined role and by keeping it intact you are satisfying the <a href=\"http://en.wikipedia.org/wiki/Single_responsibility_principle\">Single Responsibility Principle</a>. So, I would leave it like that. Perhaps you might want to look into how you could refactor some common co... | {
"AcceptedAnswerId": "7686",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T19:26:21.247",
"Id": "7683",
"Score": "6",
"Tags": [
"c#",
"classes"
],
"Title": "Should I split class or keep it all in one?"
} | 7683 |
<p>Parallism is achieved by using a simple call to <code>tbb::parallel_invoke()</code>. However I can't break a speedup factor of x2 (after ~3-4 parallel HW threads), although 8 parallel HW threads are used. Advice on this is highly appreciated.</p>
<pre><code>template<class In>
void insertion_sort(In b, In e) {... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T20:13:30.943",
"Id": "12107",
"Score": "1",
"body": "What is the type and size of the data set that you used in your benchmarks which failed to yield a 2x speedup?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<p>Maybe you're at a memory bandwidth limit. I've done similar experiments with Java threads on an 8 core machine (2 quad core Xeons). Non-memory tasks scaled very well, but memory intensive tasks did not. Try something more computation just to see if memory is a limiting factor for you, too.</p>\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T19:41:52.993",
"Id": "7684",
"Score": "14",
"Tags": [
"c++",
"multithreading",
"c++11",
"sorting",
"mergesort"
],
"Title": "Parallel Merge Sort"
} | 7684 |
<p>A few days ago I saw <a href="https://stackoverflow.com/questions/8776954/is-there-any-big-advantages-of-having-its-c-developping-applications-running-o">this question</a> on Stack Overflow.</p>
<p>I have tried to make a little demo to show the speed advantage of using 64-bit memory operations compared to 32-bit on... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T17:48:26.513",
"Id": "12508",
"Score": "0",
"body": "There may be applications where this kind of loop is the \"bottleneck\". All the serious apps I've seen have call stacks ending, nearly all the time, deep in system code, 3rd-part... | [
{
"body": "<p>You are using <code>int64_t</code>, so most of your code gets compiled into the same machine code regardless of the bitness of the target. Also, A^A = 0, so the compiler might be optimizing your entire for loop with a single call to <code>memset</code> with zero.</p>\n\n<p>I would recommend that y... | {
"AcceptedAnswerId": "7689",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T20:02:43.777",
"Id": "7685",
"Score": "3",
"Tags": [
"c",
"performance"
],
"Title": "Comparing 32- and 64-bit"
} | 7685 |
<p>I am toying with a simple class to inherit from to manage my dynamic resources. I am fairly new to C++, so my "implementation" might be suboptimal. Suggestions how to improve functionality are welcome. There are plenty of <code>cout</code>s for orientation purposes, so feel free to ignore those.</p>
<p>The idea of ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T19:13:04.590",
"Id": "12109",
"Score": "0",
"body": "Why a special class for this purpose? What's wrong with using `std::unique_ptr` (or containers thereof) where needed?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>I would agree with the commenters that smart pointers or other forms of RAII are a more traditional solution and generally to be preferred.</p>\n\n<p>And the virtual destructor <em>is</em> critical, otherwise your derived classes' destructors will never be called -- just the <code>UObject</code> d... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T19:10:08.050",
"Id": "7688",
"Score": "4",
"Tags": [
"c++",
"memory-management"
],
"Title": "Simple, lightweight deterministic \"garbage collection\""
} | 7688 |
<p>I have a module that builds swing tables based on an <code>Object[][]</code>, then I have another module that queries an SQLite database and returns a <code>ResultSet</code>.</p>
<p>I have written a method that converts the <a href="http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html" rel="nofollow"><c... | [] | [
{
"body": "<p>Well, you could just call the <a href=\"http://docs.oracle.com/javase/6/docs/api/java/util/List.html#toArray%28T%5B%5D%29\"><code>toArray</code></a> method of your list to transform the list into an array. Or even better, you could make the table model use a <code>List<Object[]></code> rathe... | {
"AcceptedAnswerId": "7692",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T16:02:59.017",
"Id": "7690",
"Score": "7",
"Tags": [
"java",
"collections",
"jdbc"
],
"Title": "Module for building swing tables"
} | 7690 |
<p><strong>Table Structure</strong></p>
<blockquote>
<p>ApprovalOrder int </p>
<p>EntityCode varchar </p>
<p>CostCentre varchar</p>
<p>DelegationCode varchar </p>
<p>ProjectCode varchar</p>
<p>RoleGroup varchar</p>
<p>Position varchar</p>
<p>DelegationText varchar</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-12T01:00:31.187",
"Id": "12147",
"Score": "0",
"body": "I like the formatting style (i.e. the indentation and separation of each condition onto its own line), but (without trying to execute it) I don't see the purpose of the subquery."... | [
{
"body": "<p>My suggestion is to create a \"RowID\" <a href=\"http://msdn.microsoft.com/en-us/library/ms191250.aspx\" rel=\"nofollow\">computed column</a> on the workflow.delegation_engine table.</p>\n\n<pre><code>ALTER TABLE workflow.delegation_engine ADD [RowID] AS\n cast(de.ApprovalOrder + 1 as varchar(4... | {
"AcceptedAnswerId": "7697",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T22:30:01.850",
"Id": "7694",
"Score": "5",
"Tags": [
"performance",
"sql",
"sql-server",
"t-sql"
],
"Title": "Adding a new record to the beginning of the approval chain from... | 7694 |
<p>This is my first attempt at writing something in JavaScript besides a few Project Euler problems I did first. It's intended to be a library used client side and server side (both of which I know very little about). I've read Crockford's <em>Javascript: The Good Parts</em>, but nothing else. I have the most current ... | [] | [
{
"body": "<p>If you stop worrying about "privates" everything becomes much cleaner.</p>\n<blockquote>\n<p>By using closure with my "country" object am I wasting memory, and hence should be using prototypical inheritance?</p>\n</blockquote>\n<p>The closure is a small performance hit. For a b... | {
"AcceptedAnswerId": "7698",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-12T01:00:30.703",
"Id": "7696",
"Score": "4",
"Tags": [
"javascript",
"game"
],
"Title": "Risk board game - best practices, private vs public variables and methods"
} | 7696 |
<pre><code>public double getValueWithPercentage(double number, double percentage)
{
return number + ((percentage / 100.0) * number);
}
</code></pre>
<p>Are there any tricks to optimize this simple code?</p>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T23:49:37.733",
"Id": "12162",
"Score": "5",
"body": "What lead you to believe that this method may need optimising?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T23:53:08.430",
"Id": "12163",
... | [
{
"body": "<p>Since floating-point divide is sometimes a little slower than multiply (and never faster, AFAIK), I'd write your function like this:</p>\n\n<pre><code>public double getValueWithPercentage(double number, double percentage)\n{\n return number * (1 + percentage * 0.01);\n}\n</code></pre>\n",
"... | {
"AcceptedAnswerId": "7703",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-11T23:46:38.253",
"Id": "7702",
"Score": "6",
"Tags": [
"java",
"optimization"
],
"Title": "Can this simple percentage calculator be further optimized?"
} | 7702 |
<p>I've been struggling with concurrent programming in Haskell for a while. It's so hard to reason about, especially when exceptions come into the picture.</p>
<p>As a learning exercise, I implemented a simple chat server. Clients connect using telnet on port 1337, and start typing text. Each message is broadcast t... | [] | [
{
"body": "<blockquote>\n <p>One hurdle is that I can't send and receive simultaneously in the same thread. Thus, I'm forced to send and receive in separate threads.</p>\n</blockquote>\n\n<p>Naturally. This is because \"send\" and \"receive\" for a chat server behave asynchronously, and block on different even... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-12T06:03:55.540",
"Id": "7705",
"Score": "12",
"Tags": [
"multithreading",
"haskell"
],
"Title": "Simple chat server in Haskell"
} | 7705 |
<p><a href="http://projecteuler.net/" rel="nofollow">Project Euler</a> is a free collection of mathematical programming problems of varying difficulty. Only the solution of a problem needs to be submitted, so the challenge is language agnostic. As a general rule (although it is not enforced in any way), a program shoul... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-12T16:23:58.017",
"Id": "7715",
"Score": "0",
"Tags": null,
"Title": null
} | 7715 |
Project Euler is a collection of mathematical programming problems of varying difficulty. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-12T16:23:58.017",
"Id": "7716",
"Score": "0",
"Tags": null,
"Title": null
} | 7716 |
<p>This file takes a user picture upload and converts two pictures which are named according to the Session ID.</p>
<p>Right now he biggest drawback is that you cannot crop the image at upload time like you can on popular sites like Facebook. </p>
<p>However I'm just looking for overall constructive criticism on the ... | [] | [
{
"body": "<p>With this piece of code you are almost beginning to write good OO. Its good to see you are trying to hide implementation details from other classes.</p>\n\n<p>However, what you have here is a constructor that does everything. The constructor should do no more than initialize the object. Have fa... | {
"AcceptedAnswerId": "7721",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-12T16:35:36.410",
"Id": "7718",
"Score": "3",
"Tags": [
"php"
],
"Title": "Image Upload Class"
} | 7718 |
<p>I am writing a few python functions to parse through an xml schema for reuse later to check and create xml docs in this same pattern. Below are two functions I wrote to parse out data from simpleContent and simpleType objects. After writing this, it looked pretty messy to me and I'm sure there is a much better (more... | [] | [
{
"body": "<p>Do more with literals:</p>\n\n<pre><code>def get_simple_type(element):\n return {\n element.get(\"name\"): {\n \"restriction\": element.getchildren()[0].attrib,\n \"elements\": [ e.get(\"value\") for e in element.getchildren()[0].getchildren() ]\n }\n }\n\... | {
"AcceptedAnswerId": "10493",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-12T21:06:39.923",
"Id": "7725",
"Score": "0",
"Tags": [
"python",
"parsing",
"xml"
],
"Title": "Python xml schema parsing for simpleContent and simpleTypes"
} | 7725 |
<p>I have a Rectangle class, of which I have 5-6 vectors for each instance. The main vectors are the center and color of the object, while the secondary vectors represent more or less the north, south, east, and west directions of the rectangle itself. These vectors are used to detect collision by "pointing" outside of... | [] | [
{
"body": "<p>Your constructor arguments and defaults are unusual.\nWhat does radius mean for a Rectangle?\nShould there be an argument for initializing mass?\nI suggest:</p>\n\n<pre><code> static const Vec2f& defaultCenter();\n static const Vec2f& defaultSquareDimensions();\n static const Vec3... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-12T21:53:24.537",
"Id": "7727",
"Score": "6",
"Tags": [
"c++",
"memory-management",
"computational-geometry"
],
"Title": "Is this a good algorithm for 2D collision, or will it alloca... | 7727 |
<p>I wrote a function (<code>get_last_word_of</code>) that takes a C string and a destination buffer, and then copies the last word into the buffer. The code was originally C++, and was changed into C later.</p>
<pre><code>#include <assert.h>
#include <stdio.h>
#include <string.h>
// Check whether ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T00:32:18.427",
"Id": "12208",
"Score": "0",
"body": "`assert(input && \"input must be a valid C string\");` will never fail. If input is false, the string will evaluate to true, no?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Found some inputs that could cause wordcpy to perform undefined behaviour. See below.</p>\n\n<p>Enough comments? Pretty close, though some needed tweaking. \nWhat IS lacking is some definition of what is meant by \"word\", \"space\", \"whitespace\" especially as they relate to the presence of punc... | {
"AcceptedAnswerId": "7736",
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T00:11:20.007",
"Id": "7731",
"Score": "3",
"Tags": [
"c",
"strings"
],
"Title": "Defensive programming in C"
} | 7731 |
<p>My application is for the use of comparing a product sold by several merchants on a daily basis. A process runs to load the current values of data for each store and enters it into a database along with any previous data. Later I plan to create graphs and such off of the history of data.</p>
<pre><code>SELECT `a`.`... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T04:50:24.450",
"Id": "12230",
"Score": "0",
"body": "The above is horrid in my eyes, but achieves exactly as I need. The nested selects with ORDER and GROUP work appropriately and the query returns the grouped data in the example. G... | [
{
"body": "<p>The <code>ORDER BY</code> inside the inner-most sub-select is pointless - it's going to get thrown out. Also, you should <em>never</em> rely on MySQL's behaviour of selecting a 'random' value for non-grouped columns - <em>always</em> explicitly specify the transformation that needs to happen on t... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T00:18:46.630",
"Id": "7732",
"Score": "2",
"Tags": [
"performance",
"sql",
"mysql"
],
"Title": "Comparing products sold by several merchants"
} | 7732 |
<p>I'm writing a small PHP framework to help me develop Web applications. The framework is split into numerous components, each of which are automatically loaded according to the configuration settings. This is my component base class:</p>
<pre><code>class Component {
public static void init() {}
}
</code></pre>
... | [] | [
{
"body": "<p>The OO equivalent of this is one of:</p>\n\n<pre><code>interface Component {\n public function init();\n}\n\nclass Authenticator implements Component {\n}\n\n// OR\n\nabstract class Component {\n abstract public function init();\n}\n\nclass Authenticator extends Component {\n}\n</code></pre>\n... | {
"AcceptedAnswerId": "7737",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T01:51:07.577",
"Id": "7734",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"static"
],
"Title": "Component functions - static vs. OO?"
} | 7734 |
<p>For fun, I made a function queue in JavaScript. I named it <a href="https://github.com/NTICompass/tinyq">tinyq</a>. You can add functions to it, and each function is passed the next function in the queue. You can also pass parameters to the functions, and they can return values.</p>
<pre><code>function q(){
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-30T05:30:08.207",
"Id": "13210",
"Score": "1",
"body": "I feel like I'm not really understanding the purpose behind this. It seems like really complicated function composition. I realize the sample is purposely simple, so how else coul... | [
{
"body": "<p>I'm still trying to wrap my head around what exactly is happening in that <code>apply</code>/<code>call</code> mass :-)</p>\n\n<p>But that may be a hint, that those three lines aren't really well readable. I'm aware you want to keep it small, but unless the code needs to be really, really fast (wh... | {
"AcceptedAnswerId": "8483",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T02:43:00.837",
"Id": "7735",
"Score": "6",
"Tags": [
"javascript",
"queue"
],
"Title": "Custom JavaScript function queue"
} | 7735 |
<p>I am working on an app for iPhone and iPod Touch that has to show complex mathematical equations like algebraic, integration, summation formulas along with some text.</p>
<p>For that I have used Quartz2D and below is what I have created. Can anyone please verify if this is the correct procedure to draw an equation?... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-05-13T19:12:10.673",
"Id": "239973",
"Score": "0",
"body": "Take a look at the code here: https://github.com/kostub/iosMath That will help you with rendering math equations using CoreText."
}
] | [
{
"body": "<p>These questions may be relevant:</p>\n\n<p><a href=\"https://stackoverflow.com/questions/4340478/rendering-mathematical-formulas-on-an-idevice\">https://stackoverflow.com/questions/4340478/rendering-mathematical-formulas-on-an-idevice</a></p>\n\n<p><a href=\"https://stackoverflow.com/questions/132... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T03:21:30.670",
"Id": "7738",
"Score": "3",
"Tags": [
"objective-c",
"ios"
],
"Title": "Display complex mathematical equations in iOS 5.0 devices"
} | 7738 |
<p>I am starting to write a plugin that is aiming to validate a piece of mark up against requirements of schema.org.</p>
<p>I was hoping if I could get some more tips on how to improve the structure of my code. <em>Is this how you would go about this if you were to do it?</em></p>
<pre><code> $.fn.hasAttr = functi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T10:36:22.950",
"Id": "12659",
"Score": "0",
"body": "I haven't used code review before? Is the no response due to much lower traffic compared to stack or I am doing something wrong? Do people expect me to start a bounty to make this... | [
{
"body": "<p>This will return <code>false</code> for <code>attr</code> in such an object <code>{'attr': undefined}</code>:</p>\n\n<pre><code>$.fn.hasAttr = function(name) { \n return this.attr(name) !== undefined;\n};\n</code></pre>\n\n<p>If this is not exactly what you want, have a look at related posts (<... | {
"AcceptedAnswerId": "8057",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T11:24:49.870",
"Id": "7745",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"microdata"
],
"Title": "Schema.org Microdata validation plugin"
} | 7745 |
<p>A design pattern is a description or template that helps solve a reoccurring problem, which can be used in many different situations.</p>
<p>It is common to classify design patterns into the following categories:</p>
<ul>
<li><strong>Creational design patterns</strong> deal with object creation mechanisms, trying ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T11:45:21.413",
"Id": "7746",
"Score": "0",
"Tags": null,
"Title": null
} | 7746 |
A design pattern is a general reusable solution to a commonly occurring problem in software design. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T11:45:21.413",
"Id": "7747",
"Score": "0",
"Tags": null,
"Title": null
} | 7747 |
<p>Scheme follows a minimalist design philosophy specifying a small standard core with powerful tools for language extension. Its compactness and elegance have made it popular with educators, language designers, programmers, implementors, and hobbyists. The main feature of scheme when compared to common lisp is its hyg... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T11:58:26.963",
"Id": "7748",
"Score": "0",
"Tags": null,
"Title": null
} | 7748 |
Scheme is a functional programming language in the Lisp family, closely modeled on lambda calculus with eager (applicative-order) evaluation.
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T11:58:26.963",
"Id": "7749",
"Score": "0",
"Tags": null,
"Title": null
} | 7749 |
<p><a href="http://www.mysql.com" rel="nofollow">MySQL</a> is a <em>relational database management system</em> that runs as a server providing multi-user access to a number of databases.</p>
<h2>Deprecation of <code>mysql_</code> functions</h2>
<p>PHP functions that start with <code>mysql_</code> have been deprecated... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:06:34.157",
"Id": "7750",
"Score": "0",
"Tags": null,
"Title": null
} | 7750 |
MySQL is an open-source, relational database management system. If your PHP code uses MySQLi, use the MySQLi tag instead. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:06:34.157",
"Id": "7751",
"Score": "0",
"Tags": null,
"Title": null
} | 7751 |
<p>In computer science, program or software <a href="http://en.wikipedia.org/wiki/Optimization_%28computer_science%29" rel="nofollow">optimization</a> is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. In general, a computer program may be optimized so that it e... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:07:09.647",
"Id": "7752",
"Score": "0",
"Tags": null,
"Title": null
} | 7752 |
DO NOT USE THIS TAG. It is in the process of being eliminated. If your question is just about performance, use the [performance] tag. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:07:09.647",
"Id": "7753",
"Score": "0",
"Tags": null,
"Title": null
} | 7753 |
<p>Multi-threading is a common model to implement SM in multi-cored machines, where threads share memory through shared variables. In this model in parallel programming a processor can create multiple threads that will be executed in parallel. Each thread has its own stack, variables and ID, considered private state. F... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:27:57.303",
"Id": "7754",
"Score": "0",
"Tags": null,
"Title": null
} | 7754 |
Multi-threading is how work performed by a computer can be divided into multiple concurrent streams of execution (generally referred to as threads). | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:27:57.303",
"Id": "7755",
"Score": "0",
"Tags": null,
"Title": null
} | 7755 |
<p>I'm trying to improve the quality/efficiency of my coding (having only been learning jQuery for a couple of months).</p>
<p>I have a function which loops through all <code>$('.loop-bar')'</code>s and applies a jQueryUI slider to each. Each loop bar is a range slider which controls the portion of each song (playin... | [] | [
{
"body": "<blockquote>\n <p>it performs absolutely fine in real world</p>\n</blockquote>\n\n<p>And </p>\n\n<blockquote>\n <p>have i fallen into any common pitfalls</p>\n</blockquote>\n\n<p>Yes, you have. It's called premature optimization. The code looks fine, it's not hard to understand. You are just missin... | {
"AcceptedAnswerId": "8164",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:31:38.830",
"Id": "7756",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"jquery-ui",
"audio"
],
"Title": "Audio scrubber slider bar"
} | 7756 |
<p>LINQ is a .NET-based DSL (Domain Specific Language) for querying data sources such as databases, XML files, or in-memory object lists. All these data sources can be queried using the exact same readable and easy-to-use syntax - or rather, syntaxes, because LINQ supports two notations:</p>
<p>Inline LINQ or query sy... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:37:48.410",
"Id": "7757",
"Score": "0",
"Tags": null,
"Title": null
} | 7757 |
Language INtegrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:37:48.410",
"Id": "7758",
"Score": "0",
"Tags": null,
"Title": null
} | 7758 |
<p>A late-binding, message-based, object-oriented language that is a strict superset of C and is primarily used for programming primarily on Apple's Mac OS X and iOS platforms. Objective-C can also be used on other platforms that support gcc or clang.</p>
<p><a href="http://en.wikipedia.org/wiki/Objective-C" rel="nofo... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:38:51.107",
"Id": "7759",
"Score": "0",
"Tags": null,
"Title": null
} | 7759 |
This tag should be used only on questions that are about Objective-C features or depend on code in the language. The tags [cocoa] and [cocoa-touch] should be used to ask about Apple's frameworks or classes. Use the related tags [ios] and [osx] for issues specific to those platforms. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:38:51.107",
"Id": "7760",
"Score": "0",
"Tags": null,
"Title": null
} | 7760 |
ASP.NET MVC 3 is the third major version of Model-View-Controller extension for developing web applications in a .NET framework | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T12:39:38.470",
"Id": "7762",
"Score": "0",
"Tags": null,
"Title": null
} | 7762 |
<p>This works well, but can anybody see any faults in this code? If so, could you suggest ways in which I can fix it?</p>
<pre><code>CREATE PROC ValidateUser
(
@Email NVARCHAR(100),
@PasswordHash NVARCHAR(128)
)
AS
IF EXISTS ( SELECT 1
FROM dbo.[User]
WHERE ... | [] | [
{
"body": "<p>The only \"fault\" I see is that you return \"magic strings\" as your result - those are always a bit hard to use, and can cause issues (if you misspell a string).</p>\n\n<p>This is a <strong>boolean check</strong> - you get back True or False - but I would return the <strong>boolean</strong> valu... | {
"AcceptedAnswerId": "7766",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T05:53:16.113",
"Id": "7765",
"Score": "5",
"Tags": [
"sql",
"validation"
],
"Title": "Validating a user"
} | 7765 |
<p>I want to prevent double form submissions within a small window, then allow the form to be submitted again.</p>
<p>I wrote this script after looking at several examples, but the global variable is bugging me. I'd welcome any suggestions on improving it.</p>
<pre><code>var aLockedForms= [];
jQuery.fn.preventDoubl... | [] | [
{
"body": "<p>Regarding the global variable, you're already using jQuery so why not just attach an attribute or class to the form?</p>\n\n<pre><code>jQuery.fn.preventDoubleSubmit=function(duration) {\n duration = duration || 1984;\n jQuery( this ).submit( function() {\n if ( this.hasClass(\"locked\... | {
"AcceptedAnswerId": "7771",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T14:35:22.230",
"Id": "7769",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "Prevent Double Form Submit within X seconds"
} | 7769 |
<p>Here is the code I wrote for the problem at <a href="http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4efa210eb70ac">http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4efa210eb70ac</a> where we need to to print the substring at a particular index from the lexicograp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T04:28:43.087",
"Id": "12588",
"Score": "1",
"body": "For starters, type this at the python prompt `>>> import itertools` `>>> for i in itertools.combinations(\"ABCDE\",3):` `... print i`. Getting just what you want? Then you may wan... | [
{
"body": "<p>To successfully pass all test cases you need to implement something more sophisticated like <a href=\"http://en.wikipedia.org/wiki/Suffix_tree\" rel=\"nofollow\">suffix tree</a>. That will allow you to solve this task in O(n) time using O(n) space.</p>\n",
"comments": [],
"meta_data": {
... | {
"AcceptedAnswerId": "7979",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T15:40:04.423",
"Id": "7773",
"Score": "6",
"Tags": [
"python",
"optimization",
"strings",
"memory-management"
],
"Title": "Memory issues with Find Strings Problem on Intervi... | 7773 |
<p>I recently dived into Ruby, so I want to improve this code. Is this good enough?</p>
<pre><code>def ranksystem
logfile = IO.readlines("some_logfile.log")
logfile.each do |value|
value.gsub!(/[\n]+/, "")
end
logfile.delete("")
logcount = Hash.new(0)
logfile.each do |v|
logcount[... | [] | [
{
"body": "<p>\"Cool\" enough? It seems fine, if procedural. Depends what you mean by cool.</p>\n\n<p>I might combine a few steps. I'd also refactor and not put everything into one method, since each separate \"chunk\" does very distinct, and different, things. Separation makes testing easier.</p>\n\n<p>The bel... | {
"AcceptedAnswerId": "7783",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T16:08:52.270",
"Id": "7774",
"Score": "5",
"Tags": [
"ruby",
"sorting",
"io"
],
"Title": "Ranking lines of a file according to number of occurrences"
} | 7774 |
<p>Here are 3 methods which handle my ajax calls. </p>
<p>I loop until pass b.c. I've had problems with the Ajax Object working as expected. This is noted <a href="http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23421667.html" rel="nofollow">here</a></p>
<pre><code>/**
* Ajax
*/
v... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T16:53:18.470",
"Id": "12264",
"Score": "0",
"body": "What's your question?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T17:15:16.773",
"Id": "12269",
"Score": "0",
"body": "First questi... | [
{
"body": "<p>This is the real bad practice.</p>\n\n<ol>\n<li>The Ajax is Asynchronous, you never know how the response will back.</li>\n<li>Javascript is the single thread language, so that means in one time period just can run one function. in your repeatUseAjax function, you try to loop send ajax. the result... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T16:47:47.447",
"Id": "7776",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Ajax Object - 12030 Loop Fix?"
} | 7776 |
<p>I am about to start a very large project in Ruby. To get myself in the Ruby mindset I have been doing all of my homework and other side work in Ruby. I am hoping that some of you who know Ruby very well can look at this small program I have written and point out areas that aren't written in a Ruby-like fashion. Any ... | [] | [
{
"body": "<p>I'd initialize with something closer to this (although I might inline the two arrays):</p>\n\n<pre><code>plain_alphabet = ('a'..'z').to_a\ncipher_alphabet = ('A'..'Z').to_a.rotate KEY\n$caesar_map = Hash[plain_alphabet.zip cipher_alphabet]\n</code></pre>\n\n<p>The en/decryption (which could likely... | {
"AcceptedAnswerId": "7781",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T17:35:06.150",
"Id": "7777",
"Score": "4",
"Tags": [
"ruby",
"caesar-cipher"
],
"Title": "Menu-based Caesar Cipher with encryption and decryption"
} | 7777 |
<p>Quoting the wikipedia <a href="http://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs" rel="nofollow">page</a>:</p>
<blockquote>
<p>Structure and Interpretation of Computer Programs (SICP) is a textbook published in 1984 about general computer programming concepts from MIT Press written by... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T17:48:34.520",
"Id": "7778",
"Score": "0",
"Tags": null,
"Title": null
} | 7778 |
Structure and Interpretation of Computer Programs (SICP) is a classic textbook for learning how to program. The language used in the book is Scheme, a dialect of Lisp. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T17:48:34.520",
"Id": "7779",
"Score": "0",
"Tags": null,
"Title": null
} | 7779 |
<p>I'm having a hard time creating a design (due to my lack of experience). I need a little of help to create the Model.</p>
<p>It's a mathematics system. I've created an <code>IProblem</code> interface with a function <code>IsCorrect</code>, this function helps me to know if the result is correct or not (by parameter... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T20:11:24.060",
"Id": "12278",
"Score": "1",
"body": "Not a direct answer to your question, but you should override the `bool Equals(object)` method instead of (or in addition to) providing you own typed Equals method. Also, you sho... | [
{
"body": "<p>Firstly, do you really need it to be that generic? You support arbitrary types and numbers of answers. But unnecessary genericness just make the design overly complicated. If you are only going to every have a single number answer, then just write code to do that. </p>\n\n<p>Secondly, you store th... | {
"AcceptedAnswerId": "7834",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T18:10:28.270",
"Id": "7784",
"Score": "7",
"Tags": [
"c#",
"quiz",
"abstract-factory"
],
"Title": "Factory for mathematics Q&A"
} | 7784 |
<p>The Javascript libraries have pretty complicated functions to calculate an element's offset on the page. I wrote the following function that works in all the places I need it, and I've tested a few edge cases as well. It adds the element's <code>offsetTop</code> to its parent's <code>offsetTop</code> all the way up ... | [] | [
{
"body": "<p>For starters, this doesn't work in IE7 or IE8. I'm assuming you knew that, although you never mentioned compatibility if any you were aiming for.</p>\n\n<p>I rewrote what you made, to work in IE7 & IE8, so you can see where it fails. It is available at <a href=\"http://jsfiddle.net/Akkuma/Xem3... | {
"AcceptedAnswerId": "7935",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T19:36:45.130",
"Id": "7785",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "Where will this .offsetTop() function fail?"
} | 7785 |
<p>I am currently developing a new breed of 3D engine for my upcoming thesis and I really liked the C# properties, but now I am on C++11 for obvious reasons. Since I couldn't find it elsewhere, I tried to write my own property mechanism that shall nicely integrate with C++.</p>
<p>I'd appreciate expert feedback on my... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T20:53:46.847",
"Id": "12280",
"Score": "3",
"body": "How is this different than having a public field? What's the point?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T20:57:23.907",
"Id": "12281... | [
{
"body": "<p>The idea of encapsulating your properties with a template is not bad, but, you are are missing the power of properties' accessors. There is not much difference on using properties without been able to override them.</p>\n\n<p>Accessors allow a property to \"communicate\" with its containning class... | {
"AcceptedAnswerId": null,
"CommentCount": "14",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-13T20:49:45.873",
"Id": "7786",
"Score": "20",
"Tags": [
"c++",
"c++11",
"properties"
],
"Title": "C#-like class properties"
} | 7786 |
<p>Use this tag for code that is to be compiled as <a href="http://en.wikipedia.org/wiki/C%2B%2B11" rel="nofollow noreferrer">C++11</a>, published as ISO/IEC 14882:2011 in September 2011.</p>
<ul>
<li>Predecessor: C++03</li>
<li>Successor: C++14</li>
</ul>
<p>Some of the main improvements of C++11, compared to C++03,... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-01-14T04:38:29.450",
"Id": "7791",
"Score": "0",
"Tags": null,
"Title": null
} | 7791 |
Code that is written to the 2011 version of the C++ standard, sometimes known by its pre-publication name of "C++0x". Use in conjunction with the 'c++' tag. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-01-14T04:38:29.450",
"Id": "7792",
"Score": "0",
"Tags": null,
"Title": null
} | 7792 |
<p>When invoking a Web Service from C# (where the external service might be WCF, ASMX, Java, etc. - you just don't know), it is common practice to point your modern development tool of choice (Visual Studio in my case) at the service's WSDL to generate a proxy class for calling the service. You can also create a proxy ... | [] | [
{
"body": "<p>Instead of wrapping the proxy creation in a concrete service proxy implementation, I'd write a concrete service factory instead which in turn uses the ChannelFactory. The service factory class could also use an interface for creation, so you can have multiple concrete factories.</p>\n\n<p><a href=... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T05:07:58.520",
"Id": "7793",
"Score": "3",
"Tags": [
"c#",
"wcf"
],
"Title": "How to improve WCF client proxy based on CreateChannel (not generated from WSDL) in C#"
} | 7793 |
<p>This code allows me to save some settings from my small app to the text file which later I can retrieve by using substring and delimiter.</p>
<p>I wonder if there's any better way of doing this. If not, how could I make my code better or more efficient? </p>
<p>This is my code:</p>
<pre><code>using System;
using ... | [] | [
{
"body": "<p><code>LastUsed</code> is an awful name for a class. The name of a class should always be a noun. No exceptions.</p>\n\n<p>Read-only fields should be marked as read-only using the <code>readonly</code> keyword.</p>\n\n<p><code>CheckFileStatus</code> is an awful name for a function. It does not gi... | {
"AcceptedAnswerId": "7805",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T05:15:06.610",
"Id": "7794",
"Score": "1",
"Tags": [
"c#",
"performance"
],
"Title": "Is there any flaws in my code which let me to save settings to a file?"
} | 7794 |
<p>This is a small web application that I have created using the Flask framework. </p>
<p>I am looking for best practices feedback, as well as design pointers. I am not confident that my design choices have been very good, or rather that they were the best they could have been, but I would like some feedback regardles... | [] | [
{
"body": "<h1>Opening files using <code>with</code></h1>\n\n<p>It's not a great idea to open a file just using something like this:</p>\n\n<blockquote>\n<pre><code>dtd = open(Config.DTDPATH, 'r')\n</code></pre>\n</blockquote>\n\n<p>If your program unexpectedly exits, or crashes, resources that are taken up by ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T06:10:52.327",
"Id": "7796",
"Score": "6",
"Tags": [
"python",
"beginner",
"flask"
],
"Title": "Contest assist web app"
} | 7796 |
<p>I just started Python a few days ago, and I haven't programmed much before. I know my code is terrible; however, I would like someone to look it over. What I'm trying to do is create a photo "loop" that changes my Windows 7 login screen. I had a batch file doing it, but even though my code is crappy it does the job ... | [] | [
{
"body": "<ul>\n<li>Your variable names are pretty bad: <code>filename1</code>, <code>filename2</code>, <code>filename3</code>, ... is bad, use something more meaningful.</li>\n<li>There is no need to use different loop variables in consecutive loops. Use <code>filename</code> everytime.</li>\n<li>You need to ... | {
"AcceptedAnswerId": "7823",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T19:29:00.193",
"Id": "7809",
"Score": "5",
"Tags": [
"python",
"image"
],
"Title": "Photo changer loop"
} | 7809 |
<pre><code><?php
/**
* Module : Control
* Name : ControlSigin
* Input : Text Array
* Output : Pass or Fail(w/responseText)
* Notes :
* Call :
$instanceControlSignIn = new ControlSignIn();
$... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T20:28:24.503",
"Id": "12343",
"Score": "0",
"body": "Again, what is your question?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-16T11:18:20.313",
"Id": "12445",
"Score": "0",
"body": "@sta... | [
{
"body": "<p>Without a question there's no way to give a definitive answer. Still, here's a few comments you might want to take on board. </p>\n\n<ul>\n<li><p>You're instantizing your dependencies in your constructor. This means that your class is now irrevocably coupled to those dependencies. This makes te... | {
"AcceptedAnswerId": "7864",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T19:47:33.703",
"Id": "7810",
"Score": "1",
"Tags": [
"php"
],
"Title": "Control Signin Class - Remove Dependencies"
} | 7810 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.