body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I have this assignment to write the optimized space and time code for finding the sum of all primes under 2 million. I'm using the following function to check if each number is prime:</p>
<pre><code>int IsPrime(unsigned int number) {
if (number <= 1) return 0;
unsigned int i;
for (i=2; i*i<=numbe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-26T05:35:51.460",
"Id": "11171",
"Score": "0",
"body": "Why are you using a long double in the outer loop? Will you show all of your code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-26T05:43:03.580",
... | [
{
"body": "<p>There are dozens of possible optimizations. The most obvious -- why are you multiplying <code>i</code> by itself every pass in the loop?! Just calculate the loop cut off <em>once</em>.</p>\n\n<p>And why <code>i++</code>?! After you test 2, there's no reason to test 4, 6, or 8. You can test 2, and ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-26T05:32:21.490",
"Id": "7167",
"Score": "9",
"Tags": [
"c++",
"performance",
"primes",
"homework"
],
"Title": "Sum of all primes under 2 million"
} | 7167 |
<p>I am trying to remove duplicates from a string without using additional buffers.<br>
This seems to work correct, I think. Can this be improved? Should I be doing it differently? </p>
<pre><code>private static String removeDuplicates(char[] chars) {
if(chars == null)
return null;
in... | [] | [
{
"body": "<p>A few stylistic comments :</p>\n\n<ol>\n<li><p>I'd change the while loop for a for loop. It doesn't matter at all but I feel it better that way.</p></li>\n<li><p>You could perform <code>len--;</code> before the while (or for) loop so that you can go til <code>len</code> instead of <code>len - 1</c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-26T18:42:01.880",
"Id": "7173",
"Score": "7",
"Tags": [
"java",
"algorithm",
"strings"
],
"Title": "Review on code for duplicate removal"
} | 7173 |
<p>Delphi is a general purpose language for rapid development of native Windows, OS X and iOS applications. </p>
<p>The name also refers to the Delphi IDE, which is used to help edit and debug Delphi projects more efficiently. It is sold by Embarcadero, as a standalone product or included in RAD Studio, which includes... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-27T14:57:34.470",
"Id": "7180",
"Score": "0",
"Tags": null,
"Title": null
} | 7180 |
Delphi is a language for rapid development of native Windows, OS X and iOS applications through use of Object Oriented Pascal. The name also refers to the Delphi IDE, which is used to help edit and debug Delphi projects more efficiently. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-27T14:57:34.470",
"Id": "7181",
"Score": "0",
"Tags": null,
"Title": null
} | 7181 |
<p>Based on the standard implementation of <code>Array.sort</code> in JavaScript, would the following be a reasonable way of shuffling the contents of an array? Is it moderately efficient and will it produce a fairly even spread of results?</p>
<pre><code>Array.prototype.shuffle = function () {
return this.sort(fu... | [] | [
{
"body": "<p><a href=\"http://javascript.about.com/library/blsort4.htm\" rel=\"nofollow noreferrer\">This article</a> says that a test run on that algorithm showed a bias with items less likely to move farther away from their original location than near (a bias). </p>\n\n<p>My own intuition says that it could... | {
"AcceptedAnswerId": "7187",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-27T17:39:06.570",
"Id": "7186",
"Score": "3",
"Tags": [
"javascript",
"array",
"sorting",
"shuffle"
],
"Title": "JavaScript shuffle idea"
} | 7186 |
<p>I posted the following Matlab script in response to a question on <a href="http://dsp.stackexchange.com">Signal Processing</a>. Here is the <a href="https://dsp.stackexchange.com/questions/1036/what-are-high-frequencies-and-low-frequencies-in-a-signal/1038">questions</a> with my <a href="https://dsp.stackexchange.co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T09:25:10.730",
"Id": "34943",
"Score": "1",
"body": "Y = fft(y)/L\nWhy do you divide by L?"
}
] | [
{
"body": "<p>Your time vector definition is defined a bit strange, I would go for the more standardized form of</p>\n\n<p>startpoint:stepsize:endpoint</p>\n\n<pre><code>endpoint = T*(L-1) % is this correct?\n0:T:endpoint\n</code></pre>\n\n<p>Besides this you could perhaps add some comments in the calculate spe... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-27T19:10:55.883",
"Id": "7188",
"Score": "3",
"Tags": [
"matlab",
"signal-processing"
],
"Title": "Matlab code demonstrating use of fft (Fast Fourier Transform)"
} | 7188 |
<p>I've written a quick "local document crawler" that fetches the title tag and an expandable amount of metatag information from files on a webserver.</p>
<p>I develop in .net for a living and don't have a clue what I'm doing, but the site I'm helping with only has PHP hosting.</p>
<p>The goal is to gather metadata f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T12:15:13.473",
"Id": "11426",
"Score": "0",
"body": "Why use PHP to crawl document? Wouldn't the parsing be much faster if you do with with BASH or other language? (PHP is more like server side scripting, but will not parse fastest ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-27T22:33:10.783",
"Id": "7194",
"Score": "2",
"Tags": [
"php"
],
"Title": "PHP local document crawler"
} | 7194 |
<p>Inspired by another question here: <a href="https://codereview.stackexchange.com/questions/7167/sum-of-all-primes-under-2-million">Sum of Prime numbers under 2 million</a>, I decided to try and implement <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="nofollow noreferrer">Eratosthenes' Sieve</a> fr... | [] | [
{
"body": "<p>You shouldn't append non-primes to a list and then perform a large number of find operations on it (which will all scan the entire container).</p>\n\n<p>Instead a sieve is a table of whether a number is a multiple of some prime or not. Something like this which you then fill out.</p>\n\n<pre><code... | {
"AcceptedAnswerId": "7197",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-27T23:19:40.170",
"Id": "7195",
"Score": "5",
"Tags": [
"c++",
"performance",
"primes"
],
"Title": "Prime Number calculation bottleneck"
} | 7195 |
<p>I have a module, that fetches some object. Then other modules can use this object. Here is a little example of this task:</p>
<pre><code>var Structure = (function(){
var tree = null,
df = $.ajax({
'url' : '/some/path',
'type' : 'POST',
'data' : { som... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T18:03:53.323",
"Id": "11301",
"Score": "0",
"body": "Basically this is completely fine, however I would say it's unnecessarily complex. Can you expand on why you think you need this and can't just use a AJAX call with a callback fun... | [
{
"body": "<p>I'm repeating @RoToRa for the sake putting it in answer form for beta-stats:</p>\n\n<p>Your syntax is fine. Without knowing more of the problem domain, it does seem a little unnecessary. Why not use callbacks on your <code>$.ajax()</code> call?</p>\n",
"comments": [],
"meta_data": {
... | {
"AcceptedAnswerId": "7236",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T00:06:44.437",
"Id": "7198",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "Getting object when is ready"
} | 7198 |
<p>I have two tables<br/> </p>
<pre><code>table_inventory
List item
inventory_rack_key(primarykey)
node_key
rack_id
inventory_item_key
in_coming_qty,locked_qty
quantity
table_item
inventory_item_key(primary key)
item_id,product_zone
</code></pre>
<p>The table example are provided ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T13:25:23.503",
"Id": "11267",
"Score": "0",
"body": "Which database engine are you using? MSSQL, Oracle, etc?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T13:57:59.047",
"Id": "11268",
"Sc... | [
{
"body": "<p>I am not exactly familiar with Oracle syntax, but I know that Oracle supports indexes on functions. I'm not sure if it will be used, since there is grouping involved, but you may wish to look into creating an index for this query if performance of the query becomes an issue. A guess at the synta... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T00:24:31.723",
"Id": "7199",
"Score": "1",
"Tags": [
"sql",
"oracle"
],
"Title": "SQL query for adding column value to compare with other column"
} | 7199 |
<p>Here are some examples:</p>
<pre><code>[1, 2, 3, 4, 5] => [1, 2, 3, 4, 5]
[10, 15, 10, 15, 30] => [10, 15]
[1, 2, 3, 4, 1, 5, 6, 7] => [1, 2, 3, 4]
</code></pre>
<p>Here's my best (and deeply ugly) non-recursive, side-effect-free solution so far:</p>
<pre><code>x.scanLeft(List[Int]())((B, Term) => Ter... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T02:31:48.743",
"Id": "11244",
"Score": "1",
"body": "You probably just want the `distinct` method... see http://stackoverflow.com/questions/1538598/how-in-scala-to-find-unique-items-in-list"
}
] | [
{
"body": "<p>This is a fold, not a scan. A scan produces something with the same number of elements, and change the elements. A fold produces something new.</p>\n\n<pre><code>def firstDistinct[T](s: Seq[T]) = s.foldLeft(Seq[T]() -> false) {\n case (result @ (_, true), _) => result\n case ((se... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T01:27:47.237",
"Id": "7200",
"Score": "5",
"Tags": [
"functional-programming",
"scala"
],
"Title": "Finding the first stream of non-repeating elements in Scala (without recursion or s... | 7200 |
<p>This is the proof-of-concept code with drafts for widgets for my current project that uses Google Maps. As a result the code produces 3 buttons in the top right corner:</p>
<p><img src="https://i.stack.imgur.com/BWWIc.png" alt="enter image description here"></p>
<p>Any advice on how I may improve it? (personally I... | [] | [
{
"body": "<p>Pretty good Zmayte!</p>\n\n<p>But, if I had to nitpick...</p>\n\n<pre><code>var defaults = {};\nthis.settings = $.extend({}, defaults, options);\n</code></pre>\n\n<p>The <code>defaults</code> is redundant, whilst an empty object.</p>\n\n<pre><code>for (i in this.settings.classes) {\n this.jq.ad... | {
"AcceptedAnswerId": "7203",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T04:10:17.517",
"Id": "7202",
"Score": "5",
"Tags": [
"javascript",
"google-maps"
],
"Title": "Google Maps buttons"
} | 7202 |
<p>I have a set of components that each need to both publish and receive messages using a multicast channel. In production, any one machine could host two or more of these components with 12 or more machines communicating with each other. </p>
<p>My question is... given that components on the same machine and componen... | [] | [
{
"body": "<p>Unfortunately, I'm unable to comment about the actual options you are setting since</p>\n\n<ul>\n<li>while I've used Sockets in Java, I haven't used them in C#</li>\n<li>I'm finding it a bit hard to see what your code is doing because it isn't very expressive</li>\n</ul>\n\n<p>So, while I can do n... | {
"AcceptedAnswerId": "7215",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T09:07:44.953",
"Id": "7206",
"Score": "1",
"Tags": [
"c#",
"networking"
],
"Title": "Multicast Socket Configuration for Pub/Sub"
} | 7206 |
<p>I know <a href="https://codereview.stackexchange.com/questions/2650/waiting-for-a-lock-to-release-with-thread-sleep">I've already asked a similar question</a>, but this feels quite different to me.</p>
<p>The main goal is to wait for a file to be accessible (read: waiting until the file lock releases), since it see... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T12:05:32.880",
"Id": "11260",
"Score": "2",
"body": "http://stackoverflow.com/questions/1304/how-to-check-for-file-lock-in-c"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T14:10:00.480",
"Id": "1... | [
{
"body": "<p>How about making this an asynchrounous operation that only returns if the stream has successfully been opened. you can get rid of the while(true) and the thread sleep plus the new mthod call cn have a retry count.</p>\n\n<p>Here is what it might look like if you use C# 4.0 (not tested).</p>\n\n<pr... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T10:10:27.990",
"Id": "7210",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Waiting for a file to be accessible with Thread.Sleep() and exception catching"
} | 7210 |
<p>This code basically finds duplicate strings within a file.</p>
<blockquote>
<p>An example: DUPLICATE_LENGTH set to 6, file contains: </p>
<pre><code>process hash michael honeycomb interrupt system call deadlock scheduling michael
</code></pre>
<p>The output will be <code>michael</code>, as its a duplicate w... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-28T01:10:17.987",
"Id": "30498",
"Score": "1",
"body": "related: [Effcient way to find longest duplicate string for Python (From Programming Pearls)](http://stackoverflow.com/questions/13560037/effcient-way-to-find-longest-duplicate-st... | [
{
"body": "<p>Loop through the lines of the file, rather than reading it all into memory with <code>fileHandle.read()</code>.</p>\n\n<p>You can use <code>line.split()</code> to break the line into a list of words.</p>\n\n<p>Keep the words seen as a <code>set</code>, and the duplicates as another <code>set</code... | {
"AcceptedAnswerId": "7240",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T10:59:14.340",
"Id": "7213",
"Score": "4",
"Tags": [
"python",
"optimization",
"algorithm",
"beginner",
"strings"
],
"Title": "Finding duplicate strings within a file"
} | 7213 |
<p>In our embedded application, we have to replace <code>::operator new</code> and <code>::operator delete</code> to call a special <code>malloc()</code>, to ensure that the memory is allocated correctly. The code, written with <a href="https://stackoverflow.com/questions/7194127/how-should-i-write-iso-c-standard-confo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T12:20:26.327",
"Id": "11262",
"Score": "0",
"body": "(This is technically not *overloading* the operators, but rather to replace them, but I still consider it relevant to the operator-overloading tag.)"
}
] | [
{
"body": "<p>I am surprised this compiles and works (it does I test it)</p>\n\n<pre><code> global_handler();\n</code></pre>\n\n<p>As global handler is a pointer to a function I was expecting to see this:</p>\n\n<pre><code> (*global_handler)();\n</code></pre>\n\n<h3>Comments:</h3>\n\n<p>Throw specifiers (excep... | {
"AcceptedAnswerId": "7227",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T12:19:18.637",
"Id": "7216",
"Score": "4",
"Tags": [
"c++",
"operator-overloading"
],
"Title": "Custom operator new and operator delete"
} | 7216 |
<p>If I have a long string:</p>
<pre><code>// 10MB string
$string='';
for($run=0; $run<1000000; $run++)
$string.='012345689';
</code></pre>
<p>Then I perform many <code>substr</code>, cutting off small portions from the beginning.</p>
<pre><code>for($run=0; $run<100000; $run++)
{
$temp=substr($string,0,10);
Do... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-27T13:01:22.260",
"Id": "11274",
"Score": "0",
"body": "Is the length of the substrings cut off at the beginning constant?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-27T13:03:25.887",
"Id": "11275"... | [
{
"body": "<p>Use</p>\n\n<pre><code>for($run=0; $run<100000; $run++)\n{\n$temp=substr($string,$run*10,10);\nDoSomething($temp);\n//$string=substr($string,10);\n}\n</code></pre>\n\n<p>You trade RAM for performance: The original string will not become shorter, but you don't need the very expensive copying of t... | {
"AcceptedAnswerId": null,
"CommentCount": "14",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-27T12:59:11.630",
"Id": "7220",
"Score": "3",
"Tags": [
"php",
"strings"
],
"Title": "PHP substr slow?"
} | 7220 |
<p>I am trying to implement a TCP/UDP server so all I have to do is something like this:</p>
<pre><code>var server = new Server(Type.UDP, "127.0.0.1", 8888);
server.OnDataRecieved += Datahandler;
server.Start();
</code></pre>
<p>I have tried to make it perform as fast as possible by using Asynchronous calls where pos... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T18:13:51.427",
"Id": "11302",
"Score": "0",
"body": "Define \"correct.\" It could mean any number of different things."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T18:37:06.827",
"Id": "11306"... | [
{
"body": "<p>At a quick glance, there are a couple minor things I noticed regarding how you handle your events:</p>\n\n<ul>\n<li><p>You are passing null event args. I would instead use EventArgs.Empty, as callers will typically assume the EventArgs object they get from the event handler will be non-null.</p><... | {
"AcceptedAnswerId": "7228",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T17:44:28.987",
"Id": "7226",
"Score": "5",
"Tags": [
"c#",
"asynchronous",
"networking"
],
"Title": "Implementation of an asynchronous TCP/UDP server"
} | 7226 |
<p>I have a subsystem in a web application that essentially allows users to build views of certain lists of objects. They can specify which columns to display, how to sort and group the list, and what filters they want to assign to the results set. These views of certain objects are fundamentally similar, but due to li... | [] | [
{
"body": "<p>Yes. I would break them up into serial calls. It should help things stay a bit more modular as well and make refactoring/alterations easier down the road. Not to mention it would be easier to read.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T22:13:25.607",
"Id": "7233",
"Score": "5",
"Tags": [
"c#"
],
"Title": "Allowing users to build views of certain lists of objects"
} | 7233 |
<p>I've got an MVC site, using <code>FormsAuthentication</code> and custom service classes for <code>Authentication</code>, <code>Authorization</code>, <code>Roles</code>/<code>Membership</code>, etc.</p>
<p><strong>Authentication</strong></p>
<p>There are three ways to sign-on:</p>
<ol>
<li>Email + Alias</li>
<li>O... | [] | [
{
"body": "<p>I'll take a stab at answering your questions and provide some suggestions:</p>\n\n<ol>\n<li><p>If you have FormsAuthentication configured in <code>web.config</code>, it will automatically pull the cookie for you, so you shouldn't have to do any manual population of the FormsIdentity. This is prett... | {
"AcceptedAnswerId": "7286",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T22:14:12.970",
"Id": "7234",
"Score": "11",
"Tags": [
"c#",
"authentication",
"asp.net-mvc-3",
"authorization"
],
"Title": "Custom Authentication, Authorization, and Roles i... | 7234 |
<p>I'm not a css expert so please help me figuring this out. Would you consider this as good css code?</p>
<p>Please point any issues if you believe this is not what you would exactly consider as good code.</p>
<pre><code> html { -webkit-text-size-adjust: 70%; }
body { margin:0px;... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T22:36:11.883",
"Id": "11324",
"Score": "0",
"body": "Whats your markup those goes with this CSS?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T22:37:17.673",
"Id": "11325",
"Score": "1",
... | [
{
"body": "<p>I don't beleave it is \"good\" CSS code because:</p>\n\n<ul>\n<li>It is inconsistant (white space, multi/single line, etc)</li>\n<li>There are obvious syntax errors</li>\n<li>There is a lot of repetition</li>\n<li>It is mostly percent based sizes which will break in a lot of cases</li>\n<li>There ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T22:34:24.963",
"Id": "7237",
"Score": "1",
"Tags": [
"css"
],
"Title": "Css code quality?"
} | 7237 |
<p>This is a rot-n (rotate n times) encrypt/decrypt algorithm, where n can be any integer (+/-).</p>
<p>It's written to encrypt/decrypt all the alphabets (upper/lower case) and leaving behind all non-alphas.</p>
<p>rot-n where n is the key, is given in the first line of input file.</p>
<p>Everything is working fine.... | [] | [
{
"body": "<p>First, your <code>process</code> method violates the Single Responsibility Principle: It calculates something, and it prints it out. Such coupling makes it inflexible. It's better to return a String, and letting the caller decide what to do with it.</p>\n\n<p>Second, you're code is way too complic... | {
"AcceptedAnswerId": "7284",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T01:28:28.940",
"Id": "7241",
"Score": "3",
"Tags": [
"java",
"optimization",
"algorithm",
"cryptography",
"programming-challenge"
],
"Title": "Rot -n algorithm in Java"
... | 7241 |
<p>It is known a <code>Revealing Module Pattern</code> in javascript, and here it is a little example.</p>
<pre><code>var Module = (function(){
var a = 3,
init = function(a_user){ a = a_user; },
update = function(){},
get = function(){return a},
set = function(a_user){ a = a_us... | [] | [
{
"body": "<p>There's nothing really wrong with variation 1, but there's also no point in putting things in <code>pr</code>. Sure you can chain it, but why chain something where <code>this</code> only refers to half the stuff you need (the private stuff)? You might as well just use function declarations. And yo... | {
"AcceptedAnswerId": "7247",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T01:46:24.493",
"Id": "7242",
"Score": "1",
"Tags": [
"javascript",
"design-patterns"
],
"Title": "More Revealing Module Patter in Javascript"
} | 7242 |
<p>I am creating a Minecraft-like terrain engine in XNA to learn HLSL and more XNA. The problem is my lighting algorithm. Whenever a block which emits light is placed, it takes about half a second to calculate it. I have implemented the lighting in a recursive way.</p>
<pre><code>public void DoLight(int x, int y, int ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T15:25:21.860",
"Id": "11348",
"Score": "1",
"body": "It's always a little surprising when people expect to get decent performance out of voxel rendering engines. Voxels just never caught on in a big enough way for graphics hardware ... | [
{
"body": "<p>Did you try using performance profiler with this code? Usually profiler can tell you where the problem is or at least show you the whole picture and give a starting point. Here's a <a href=\"http://www.jetbrains.com/profiler/\" rel=\"nofollow\">decent profiler</a> with 10 days trial period.</p>\n\... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T02:09:51.817",
"Id": "7244",
"Score": "4",
"Tags": [
"c#",
"performance",
"algorithm",
"xna",
"minecraft"
],
"Title": "Optimizing lighting algorithm for a voxel engine"
} | 7244 |
<p>Please point out every problem you see with this code. Any fundamental flaws, naming conventions, design decisions, you name it.</p>
<pre><code>#include <iostream>
#include <algorithm>
#include <vector>
class SieveHelper {
public:
SieveHelper() : cur(2) {}
bool operator()(unsigned int i)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T15:23:49.953",
"Id": "11347",
"Score": "2",
"body": "A classical prime sieve is probably not implemented in terms of erasing from a vector. http://ideone.com/8yKTK is an example, optimized for minimizing memory usage. sieve_vec is a... | [
{
"body": "<ul>\n<li>I sort includes alphabetically, making it easier to keep track of which headers are included in long lists.</li>\n</ul>\n\n<p>I would write:</p>\n\n<pre><code>#include <algorithm>\n#include <iostream>\n#include <vector>\n</code></pre>\n\n<p>In a long, unsorted list of incl... | {
"AcceptedAnswerId": "7255",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T02:38:18.593",
"Id": "7245",
"Score": "10",
"Tags": [
"c++",
"c++11",
"primes",
"sieve-of-eratosthenes"
],
"Title": "Sieve of Eratosthenes in C++11"
} | 7245 |
<p>Struggling to write a simple tool to quickly sum up the last reported versions in a <a href="http://static.dabase.com/count-stats.tar.gz" rel="nofollow">bunch of files</a>. I'm using a <a href="http://mywiki.wooledge.org/BashFAQ/024" rel="nofollow">named pipe</a> to get the count out the loop for the final value, bu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T03:30:50.900",
"Id": "11336",
"Score": "0",
"body": "I don't quite understand what your script tries to accomplish, I see you're getting the last line of each file in stats, sorting them numerically and then? that second loop is wei... | [
{
"body": "<p>This shell works:</p>\n\n<pre><code>while IFS= read -r line\ndo\n test -z \"$line\" && continue\n version=$line # only assign version to line once we know it has a value for L23\n if test \"$version\" = \"$last\"\n then\n count=$((count + 1))\n else\n test \"$l... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T02:55:15.130",
"Id": "7246",
"Score": "1",
"Tags": [
"bash"
],
"Title": "Counting last reported version in shell"
} | 7246 |
<p>Is it possible to shorten this, or to improve the code in any way? I know it's just a simple if-statement, but it's always fun to learn a shorter way of doing things.</p>
<pre><code>if self.citizenship == 'ES'
@identification_type = IDENTIFICATION_TYPES[0]
elsif self.country == 'ES'
@identification_type = IDENT... | [] | [
{
"body": "<p>You could remove a little duplication like this:</p>\n\n<pre><code>@identification_type = if self.citizenship == 'ES'\n IDENTIFICATION_TYPES[0]\nelsif self.country == 'ES'\n IDENTIFICATION_TYPES[1]\nend\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": "7261",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T08:35:18.817",
"Id": "7252",
"Score": "4",
"Tags": [
"ruby"
],
"Title": "Ruby if-statement, possible to shorten it further?"
} | 7252 |
<p>For digital electronic circuit simulation, i wanted to implement Three states. i.e <strong>High</strong>, <strong>Low</strong> and <strong>Undefined</strong> in C++.</p>
<p>I saw <code>Boost::tribool</code>, and they implement it using <code>enum</code></p>
<p>Now for conserving some memory i have implemented it u... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-01T16:13:21.913",
"Id": "11518",
"Score": "0",
"body": "That's an 8-bit int, not a 1-byte int."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T06:00:34.593",
"Id": "11546",
"Score": "0",
"bod... | [
{
"body": "<p>The <strong>main</strong> reason there is no accidental conversion (type safety is one of the keys to using C++ correctly).</p>\n\n<pre><code>enum Tri { Yes, No, Maybe };\n\nint main()\n{\n Tri y = Yes;\n y= 1; // Fails to compile.\n}\n</code></pre>\n\n<p>Secondly you are using three... | {
"AcceptedAnswerId": "7293",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T10:45:41.713",
"Id": "7262",
"Score": "5",
"Tags": [
"c++"
],
"Title": "Implementing Tribool with int8_t"
} | 7262 |
<p>I have the following code that loops through a collection of objects and dumps different properties out to Excel. The whole <code>j++</code> on every other line doesn't seem very elegant. Is there a more elegant way to have this functionality where I loop through objects in a collection and dump out properties?</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T21:48:45.563",
"Id": "11356",
"Score": "6",
"body": "You're basically hard-coding it. You could just as easily write each line in the format, \"excelExport.SetCell(1, rowIndex, book.BookId)\" etc. and accomplish the same thing with... | [
{
"body": "<p>This </p>\n\n<pre><code>excelExport.SetCell(j, rowIndex, book.BookId);\nj++;\n</code></pre>\n\n<p>is equivalent to this:</p>\n\n<pre><code>excelExport.SetCell(j++, rowIndex, book.BookId);\n</code></pre>\n\n<p><code><sarcasm></code> Now you have one line doing two things! <code></sarcasm&... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-28T21:44:59.597",
"Id": "7264",
"Score": "26",
"Tags": [
"c#",
"excel",
"collections"
],
"Title": "Exporting information on a collection of books to Excel"
} | 7264 |
<p>This is based on <a href="http://careers.stackoverflow.com/nevermind">Alexey Drobyshevsky's</a> excellent article, <a href="http://www.codeproject.com/KB/cs/safe_enumerable.aspx" rel="nofollow">"Problems with Iteration"</a>. With Alexey's suggestion, I implemented his solution using a <code>ReaderWriterLockSlim</cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T14:51:24.873",
"Id": "11622",
"Score": "0",
"body": "I believe this implementation may be prone to deadlocks. I have a unit test that starts 300 CRUD threads against a collection of 1,000,000 objects in a random fashion. 90% of the... | [
{
"body": "<p>Debugging multi threaded apps, for me, has always had the affect of aligning the threads and hiding deadlocks. This experience is mostly in native code, however, I could imagine the same thing could happen in managed. I'm not exactly sure why, but I think it has to do with introducing a delay on c... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T16:42:24.993",
"Id": "7276",
"Score": "5",
"Tags": [
"c#",
"linq",
"thread-safety",
"concurrency",
"collections"
],
"Title": "Reader-writer collection"
} | 7276 |
<blockquote>
<p><strong>Puzzle:</strong></p>
<p>For two strings A and B, we define the similarity of the strings to be
the length of the longest prefix common to both strings. For example,
the similarity of strings "abc" and "abd" is 2, while the similarity
of strings "aaa" and "aaab" is 3. Calculate the s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T22:01:56.017",
"Id": "11399",
"Score": "2",
"body": "I tried hard to find a way to make it faster, but I couldn't. I give up. Do you have reasons to believe that it can be made faster?"
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>Converting the input <code>String</code> to <code>char[]</code> helps a little bit but I cannot profile it now.</p>\n\n<pre><code>private void solve2(final String input) {\n int total = 0;\n final char[] inputArray = input.toCharArray();\n for (int i = 1; i < inputArray.length; i++) {\... | {
"AcceptedAnswerId": "7288",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T20:21:01.633",
"Id": "7283",
"Score": "6",
"Tags": [
"java",
"optimization",
"performance",
"strings",
"programming-challenge"
],
"Title": "Calculating sum of similariti... | 7283 |
<p>I'm writing a (nearly-)single-page app using Ruby on Rails 3.1 and Backbone.js. Thus, most of my controllers return rootless JSON, courtesy this setting as per the Backbone.js docs:</p>
<pre><code>ActiveRecord::Base.include_root_in_json = false
</code></pre>
<p>So the returned JSON for an account, say, looks like... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T06:04:39.933",
"Id": "11413",
"Score": "0",
"body": "What in particular feels icky or non-idiomatic about this? My app is also a single-page Backbone/Rails 3.1 app, and my tests are similar to this. My tests are a bit more broken do... | [
{
"body": "<p><strong>I think your method of testing is fine.</strong> </p>\n\n<p>My app is also a single-page Backbone/Rails 3.1 app, and my tests are similar to yours. My tests are a bit more broken down -- I generally aim for one assertion per <code>it</code> / <code>specify</code> block -- but the substance... | {
"AcceptedAnswerId": "7476",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-29T22:20:11.850",
"Id": "7287",
"Score": "4",
"Tags": [
"ruby",
"ruby-on-rails",
"json"
],
"Title": "Testing Backbone.js"
} | 7287 |
<p>Is this implementation of AES for Android safe? Is it 128 bit encryption? How can I strengthen this implementation? Please help me, all suggestions are welcome :)</p>
<pre><code>import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-13T13:39:41.603",
"Id": "31328",
"Score": "0",
"body": "Hi pal, not to sound like a bad sport, but does this class come with any license restriction to it? You don't specify in the headers and i would like to know. Thanks in advance"
... | [
{
"body": "<p>I observe the following deficiencies:</p>\n\n<ul>\n<li>Use of strings to store the key, which is then extracted using <code>getBytes()</code>. This has multiple problems:\n<ul>\n<li>The character encoding used to convert the string to bytes can vary between Java implementations (so while the Andro... | {
"AcceptedAnswerId": "7311",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T03:20:46.830",
"Id": "7297",
"Score": "8",
"Tags": [
"java",
"security",
"android",
"aes"
],
"Title": "Secure AES encryption and decryption in Android"
} | 7297 |
<p>I have an MD5 hash string:</p>
<pre><code>_hash = '743a0e0c5c657d3295d347a1f0a66109'
</code></pre>
<p>I want to write function that splits passed string to path in nginx cache format:</p>
<pre><code>print hash2path(_hash, [1, 2, 3])
# outputs '7/43/a0e/743a0e0c5c657d3295d347a1f0a66109'
</code></pre>
<p>This is m... | [] | [
{
"body": "<p>Why you can't just hardcode cache path calculation?</p>\n\n<pre><code>>>> _hash = '743a0e0c5c657d3295d347a1f0a66109'\n>>> def hash2path(_hash):\n... return \"%s/%s/%s/%s\" % (_hash[0], _hash[1:3], _hash[3:6], _hash)\n... \n>>> hash2path(_hash)\n'7/43/a0e/743a0e0c5c65... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T05:58:48.010",
"Id": "7298",
"Score": "1",
"Tags": [
"python",
"cryptography"
],
"Title": "Nginx cache path function"
} | 7298 |
<p>I have an increasing table which already has records of 50,000+.
So in a combo box I have to load it, so that it shows which one is selected and its a main record which need to be selected and based on that it spread other relational records. But when I load it the whole web browser freeze.</p>
<p>How do you handl... | [] | [
{
"body": "<p>50k is simply too many for a drop-down list. Use AJAX-based autocomplete input boxes or split the list to smaller parts, for example by state. I think the users also don't like it, it's really hard to scroll or search in a so huge drop-down list.</p>\n",
"comments": [],
"meta_data": {
... | {
"AcceptedAnswerId": "7303",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T10:02:52.733",
"Id": "7301",
"Score": "1",
"Tags": [
"php",
"javascript",
"html",
"zend-framework"
],
"Title": "Browser freeze - How to handle or optimize 50,000 rows in one... | 7301 |
<p>I want to build a small newsletter like tool which sends mails in pre-defined timespans. First after registration, second 14 days later, third 7 days later etc.</p>
<p>I came across for two database designs and those two queries:</p>
<ol>
<li><p>Create a separate table (dispatch) and put the next mails into it (ca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T12:12:02.413",
"Id": "11425",
"Score": "3",
"body": "Use `explain query` to see what it is using how many keys are involved. You can analyze it and show us the output."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [
{
"body": "<ol>\n<li>Use <code>EXPLAIN</code> in the sql console to determine what the query optimizer is doing with each query. This will give you clues as to how each query performs, and may also help you optimize further, for example by indicating places where adding an index will speed the query up. </li>\... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T10:30:13.493",
"Id": "7302",
"Score": "2",
"Tags": [
"php",
"performance",
"sql",
"mysql"
],
"Title": "Newsletter SQL query optimization"
} | 7302 |
<p>I was searching for a way to get all active log4net logfiles (if any) at runtime without adding a reference to the project. </p>
<p>This is the solution I came up with: </p>
<pre><code>private static IEnumerable<AbstractReportInformation> GetLog4NetLogfiles()
{
var type = Type.GetType("log4net.LogManager... | [] | [
{
"body": "<p>Well, that seems a strange solution to me. Despite the fact you don't have a formal reference in References folder of a VS project you still have a dependency on the log4net library. And if in runtime the log4net library won't be available, your code will fail. Moreover, somebody has to remember a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T11:34:43.697",
"Id": "7304",
"Score": "4",
"Tags": [
"c#",
".net",
"reflection"
],
"Title": "Find log4net logfiles at runtime without adding dependency to project"
} | 7304 |
<p>I'm working on a game for iOS devices and this is the function we use to create server-loaded buildings. The server loading is in another function and everything works just fine, but I was wondering if this function could be prettier? This function runs every 60 seconds as we reload the whole base (with the building... | [] | [
{
"body": "<p>You should rewrite <code>convertImageToGrayScale:</code> to <code>grayScaled</code> in a category on UIImage</p>\n\n<pre><code> image1 = [self grayScaled];\n</code></pre>\n\n<p>in the following block you should add the images to array first, and then loop through it, to perform <code>for(UIImage *... | {
"AcceptedAnswerId": "7312",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T12:08:19.363",
"Id": "7305",
"Score": "2",
"Tags": [
"game",
"objective-c",
"ios",
"cocoa"
],
"Title": "Server-loaded buildings function for an iOS game"
} | 7305 |
<p>In one of our project with 3 tier architecture (tightly coupled), there's a bad code smell and it doesn't follow the DRY principle. I want to refactor it with design possible design pattern. I don't want to write this project from scratch.</p>
<p>Here's one of the class in BLL:</p>
<pre><code>namespace BAL
{
pu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T08:40:36.230",
"Id": "11427",
"Score": "1",
"body": "repeated stuff like `(Convert.ToInt16(dtblNotifList.Rows[0][\"GlobNotification\"]) == 1) ? true : false` looks like a candidate for my favorite [Extract method pattern](http://mar... | [
{
"body": "<p>I would start with those steps:</p>\n\n<ul>\n<li>Create an <code>enum</code> for your flags 'FBWallPost', 'Emails', and so on. </li>\n<li>Put yor \"signs\" into an boolean array indexed by values of that <code>enum</code> (instead of individual booleans), then you can easily create a loop around t... | {
"AcceptedAnswerId": "7310",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T06:57:10.600",
"Id": "7306",
"Score": "3",
"Tags": [
"c#",
"design-patterns",
"asp.net"
],
"Title": "How can the below code can be refactored with design pattern?"
} | 7306 |
<p>I have a unit test that needs to compare two arrays but it shouldn't care about the order of the arrays. I didn't see anything in the Test:Unit docs that provided this so I wrote my own. I really don't want to use this code if I don't have to (want to avoid Not Invented Here syndrome). </p>
<p>If you can give me so... | [] | [
{
"body": "<p>You have adequate test coverage for integers, and probably this will extend to floating points as well (although you really should test those as well, IMO). However you should also test for objects. Also, try a couple combinations of objects, numbers, and strings to be really sure that your assert... | {
"AcceptedAnswerId": "7314",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T13:23:37.510",
"Id": "7313",
"Score": "3",
"Tags": [
"ruby",
"unit-testing"
],
"Title": "Can this custom Test:Unit assert be replaced/refactored? Am I missing test cases?"
} | 7313 |
<p>I decided to build my own fade-in fade-out function, since that is all I need on my page.</p>
<p>Please comment on things I can make better.</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<div>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T00:34:23.240",
"Id": "11467",
"Score": "6",
"body": "You could skip all of this and let css transitions do the work for you. http://css3.bradshawenterprises.com/transitions/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creat... | [
{
"body": "<p>Just some generic notes about the JavaScript code: I'd extract out a <code>setOpacity</code> function and create a <code>fadeOut</code> and a <code>fadeIn</code> function too.</p>\n\n<pre><code>function setOpacity(opacity) {\n fading_div.style.opacity = opacity / 100;\n fading_div.style.filt... | {
"AcceptedAnswerId": "7323",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T15:55:34.197",
"Id": "7315",
"Score": "14",
"Tags": [
"javascript",
"animation"
],
"Title": "Fade-in and fade-out in pure JavaScript"
} | 7315 |
<blockquote>
<p><strong>Puzzle Description</strong></p>
<p>Given \$N\$ numbers, \$N <= 10^5\$, count the total pairs of numbers \$(N_i, N_j)\$ that have a difference of \$K = N_i - N_j\$ where \$0 < K < 10^9\$.</p>
<p>Input Format:</p>
<ul>
<li><p>1st line contains \$N\$ and \$K\$ (integers)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T17:09:56.267",
"Id": "11444",
"Score": "0",
"body": "What is N and K in your sample?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T17:15:27.137",
"Id": "11445",
"Score": "0",
"body": "Fi... | [
{
"body": "<p>Some things which just jump into my eyes (even if not asked, I'll tell you anyway):</p>\n\n<ul>\n<li><strong>Whitespaces</strong>: Use whitespaces were appropriate, f.e. <code>for(int i=0;i<nums;i++)</code> is harder to rad then <code>for(int i = 0; i < nums; i++)</code>.</li>\n<li><strong>M... | {
"AcceptedAnswerId": "9406",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T17:02:08.103",
"Id": "7316",
"Score": "4",
"Tags": [
"java",
"optimization",
"performance",
"algorithm",
"programming-challenge"
],
"Title": "k_diff challenge in Java"
} | 7316 |
<p>This started as a hacked-together tool to remove annoyances I was facing with experimenting with code on live remote servers, then getting that code into my development environment after experimenting. I thought others might be able to benefit from the tool, so I cleaned it up and released it as open source on <a hr... | [] | [
{
"body": "<pre><code>#!/usr/bin/env python\n\n\"\"\"\npytograph - Reflect local filesystem changes on a remote system in real time, automatically.\n\n<https://github.com/joshdick/pytograph>\n\nRequires Python 2.7, and the third-party Python packages config, pysftp, and watchdog.\n\"\"\"\n\n__author__ = '... | {
"AcceptedAnswerId": "7320",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T17:29:20.723",
"Id": "7317",
"Score": "8",
"Tags": [
"python",
"python-2.x",
"file-system"
],
"Title": "Keeping remote folders in sync with local ones"
} | 7317 |
<p>I am optimizing the variable parser for <a href="http://code.google.com/p/hack-programming-language/" rel="nofollow">my programming language</a>, and also trying to make it more readable and concise (precedence: readable and concise > efficient). What is the best way to improve this code and make the best out of eac... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T08:13:32.590",
"Id": "11476",
"Score": "1",
"body": "I'd use a parser generator instead of writing your own from scratch. It will be a lot easier to define and maintain your grammar and code."
}
] | [
{
"body": "<h1>A few observations...</h1>\n\n<h2>General</h2>\n\n<ul>\n<li>It would be great if you could include a syntax snippets of how a line in your programming language would look so we can test our solutions against the expected output. I had to go to your Google Code project and search for an actual syn... | {
"AcceptedAnswerId": "7330",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T17:34:09.163",
"Id": "7318",
"Score": "3",
"Tags": [
"c#",
".net",
"performance",
"parsing"
],
"Title": "Variable parser for the Hack programming language"
} | 7318 |
<p>I have a model with a number of complex/simple properties that has a corresponding strongly typed view, that calls <code>EditorFor</code> to a custom editor template view for the model.</p>
<p>One of the form's requirements is to auto fill the form based on a choose of values from a database.</p>
<p>Previously, I ... | [] | [
{
"body": "<p>Not a JavaScript pitfall <em>per se</em>, but I'd stay away from using two variable names that are only differentiated by the case of the second letter in a single lexical scope like that. (<code>JsonObject</code> vs <code>JSonObject</code>)</p>\n\n<p>Also, the bindFormToJson function is re-defini... | {
"AcceptedAnswerId": "8050",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T18:45:15.680",
"Id": "7321",
"Score": "0",
"Tags": [
"coffeescript",
"asp.net-mvc-3"
],
"Title": "Model with complex/simple properties"
} | 7321 |
<blockquote>
<p><strong>Puzzle Description:</strong></p>
<p>You are given 'n' strings w1, w2, ......, wn. Let Si denote the set of strings formed by considering all unique substrings of the string wi. A substring is defined as a contiguous sequence of one or more characters in the string. More information on sub... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T19:36:52.770",
"Id": "11452",
"Score": "2",
"body": "You been asking all the question for recruitment from interviewstreet.com"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T19:47:21.023",
"Id": ... | [
{
"body": "<p>Just formal way :</p>\n\n<p>Use <code>TreeSet<String> ts</code> to store <code>S = {S1 U S2}</code> : </p>\n\n<ul>\n<li>if String is already stored, it returns <code>false</code>,</li>\n<li>you can use <code>ts.toString()</code> to print all values of the Set, separated by '<code>,</code> ' ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T19:19:36.060",
"Id": "7324",
"Score": "3",
"Tags": [
"java",
"optimization",
"strings",
"programming-challenge",
"time-limit-exceeded"
],
"Title": "Output strings from a s... | 7324 |
<p>This is for a page where it displays some social media information for that user.</p>
<p>I would like to improve the following code that I posted below. It does the job perfectly, but I just feel like it could definitely be improved. I could easily leave it the way it is but I am trying to learn and that's why I ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T12:28:30.220",
"Id": "11487",
"Score": "1",
"body": "Consider using a templating engine like twig: http://twig.sensiolabs.org/"
}
] | [
{
"body": "<p><strong>Style (PHP)</strong></p>\n\n<ul>\n<li><p>At the beginning, the test seems pretty weird but in any case, I usually prefer </p>\n\n<pre><code>$var = (condition) ? val1 : val2;\n</code></pre>\n\n<p>over </p>\n\n<pre><code>if(condition) {\n $var = val1;\n} else {\n $var = val2;\n}\n</co... | {
"AcceptedAnswerId": "7327",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T19:36:30.377",
"Id": "7325",
"Score": "1",
"Tags": [
"php",
"twitter",
"facebook"
],
"Title": "Displaying a user's social media information"
} | 7325 |
<p>Edit - <code>decl</code> smokes <code>dojo.declare</code> - <a href="http://jsperf.com/dojo-declare-vs-decl" rel="nofollow">http://jsperf.com/dojo-declare-vs-decl</a></p>
<p>The code has been updated a bit. <code>decl</code> now accepts object literals as well, although I still like "declaration functions" better.<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T20:52:15.487",
"Id": "11457",
"Score": "1",
"body": "Doing it wrong."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T21:09:27.640",
"Id": "11458",
"Score": "2",
"body": "Since that doesn't... | [
{
"body": "<p>From a onceover:</p>\n\n<ul>\n<li><code>instanceof</code> works, so bonus points there</li>\n<li>Some terrible names : <code>decl</code>, <code>getCtor</code>, <code>declFn</code>, <code>declObj</code>, just type the full name</li>\n<li>You have an unmaintainable/undocumented nested ternary in <co... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-30T20:40:10.303",
"Id": "7326",
"Score": "1",
"Tags": [
"javascript",
"object-oriented",
"constructor",
"prototypal-class-design"
],
"Title": "\"metaconstructors\" for inheritanc... | 7326 |
<p>I have the following <code>Student</code> class:</p>
<pre><code>class Student {
public $user_id;
public $name;
public function __construct($user_id) {
$info = $this->studentInfo($user_id);
$this->name = $info['name'];
$this->is_instructor = $info['is_instructor'];
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T01:25:28.833",
"Id": "11468",
"Score": "0",
"body": "PDO http://php.net/manual/en/book.pdo.php and Dependency Injection http://fabien.potencier.org/article/11/what-is-dependency-injection"
},
{
"ContentLicense": "CC BY-SA 3.... | [
{
"body": "<p>From an OOP standpoint, I dont think your properties should be public.</p>\n\n<p>I think <code>studentInfo</code> should be renamed <code>getStudentInfo</code></p>\n\n<p>For database access its good to look at a ORM framework. I suggest <a href=\"http://www.doctrine-project.org/\" rel=\"nofollow\"... | {
"AcceptedAnswerId": "7337",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T01:01:44.387",
"Id": "7331",
"Score": "4",
"Tags": [
"php",
"object-oriented"
],
"Title": "What would be a better way of adding the functionality to \"add\" a student?"
} | 7331 |
<p><strong>Background</strong>:</p>
<p>I'm a member of my high school's robotics club (and in charge of the
programming team). The robot is going to be written in C++, but I'm mostly
a Python coder and want to make sure I don't have any fundamental gaps in my
knowledge.</p>
<p>In preparation for the start of the ... | [] | [
{
"body": "<p>Do you plan to replace the Joystick object?</p>\n\n<pre><code>Joystick *leftStick;\nJoystick *rightStick;\n</code></pre>\n\n<p>If not then declare them as</p>\n\n<pre><code>Joystick leftStick;\nJoystick rightStick;\n</code></pre>\n\n<p>If you are going to replace them then you should be using sm... | {
"AcceptedAnswerId": "7335",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T06:50:22.833",
"Id": "7334",
"Score": "3",
"Tags": [
"c++"
],
"Title": "Allowing a robot to drive around"
} | 7334 |
<p>Some code im working with for a stock system , i have two ways to do this, looking for review on if any of them are correct and if so which one is better OO than the other</p>
<pre><code>public interface Order {
public void processed(AllocationResponse response);
}
</code></pre>
<p>the two solutions i have in ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T09:03:42.563",
"Id": "11477",
"Score": "0",
"body": "please add a tag to show us what language you are using - C#? Java?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T09:12:46.783",
"Id": "11478... | [
{
"body": "<p>A partial answer to the partial question (with no partiality to C#, Java, or quantum mechanics):</p>\n\n<p>The invariants:</p>\n\n<ul>\n<li><p>Some unnamed caller needs to effectively call:</p>\n\n<pre><code>order.processed(warehouse.calculateAllocation(order.getQuantity()));\n</code></pre>\n\n<p>... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T08:48:26.040",
"Id": "7336",
"Score": "2",
"Tags": [
"java",
"object-oriented"
],
"Title": "looking for OO input , is any of this code good OO or am i doing it all wrong?"
} | 7336 |
<p>I have applied some optimizations like storing only odd values
and starting to mark off from square of the number.</p>
<p>Can it be optimized further?</p>
<pre><code>bool * isPrime = new bool [n/2];
for (int i=0; i < n/2; ++i)
isPrime [i] = true;
cout<< 2 << "\n";
for (int i = 3; i < n; i ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-01T13:10:09.580",
"Id": "11514",
"Score": "0",
"body": "You can get less memory usage (one bit per bool) by using `std::vector<bool>`. Possibly downside, indexing is a bit harder. But in any case a `vector<char>` would be better over d... | [
{
"body": "<p>Before starting to optimize, a few questions to be asked :</p>\n\n<ul>\n<li>does you code compile ? (I find the way you use isPrime pretty weird)</li>\n<li>is your code working properly ? (I think the initialization of isPrime with \"false\" is wrong)</li>\n</ul>\n\n<p>And then, once you have a ye... | {
"AcceptedAnswerId": "7342",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T13:47:20.310",
"Id": "7338",
"Score": "8",
"Tags": [
"c++",
"optimization",
"sieve-of-eratosthenes"
],
"Title": "Sieve of Eratosthenes optimization"
} | 7338 |
<p>Being new to <code>Node.js</code>, I'd like to know of a better way of implementing this:</p>
<pre><code>server = http.createServer( function(req, res) {
if (req.url === '/') {
fs.readFile('index.html', function(err, page) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.writ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T17:33:26.297",
"Id": "11497",
"Score": "0",
"body": "Use a router like express."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T23:30:27.647",
"Id": "11503",
"Score": "1",
"body": "Other t... | [
{
"body": "<p>Whether you wanna implement a static server?\nIf so, you can just use <a href=\"http://senchalabs.github.com/connect/\" rel=\"nofollow\">connect</a> and its built-in <em>static</em> middlewave. With it, you just need to write the following code to implement a static server:</p>\n\n<pre><code>var c... | {
"AcceptedAnswerId": "7522",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T16:57:00.497",
"Id": "7341",
"Score": "2",
"Tags": [
"javascript",
"node.js"
],
"Title": "How can I improve this Node.js file's routing?"
} | 7341 |
<p>This code performs 301 redirects based on the taxonomy terms associated with the node, as 301 redirects can adversely effect page load time. How could this be best optimized?</p>
<pre><code> <?php
/**
* Implementation of hook_init().
*calling this hook causes the code below to execute before the pa... | [] | [
{
"body": "<pre><code> function region_filter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {\n\n switch ($op) {\n\n case 'view':\n\n\n if( (arg(1) == 0)){ } //do not execute on homepage. if there are no aruments after the base url in arument one is thedelimagazine.com/argument1, if... | {
"AcceptedAnswerId": "7347",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T19:06:19.877",
"Id": "7345",
"Score": "3",
"Tags": [
"php",
"optimization"
],
"Title": "Performing redirects based on taxonomy terms associated with nodes"
} | 7345 |
<p>Below is a set of extensions that I use in unit tests. </p>
<p>The basic idea is that when creating or modifying some sort of user output type of string, I want to eyeball the output to see that it makes sense, even though it might be 'correct' in a unit test sense. But when doing almost any other tests and certain... | [] | [
{
"body": "<p>I use log4net in my test code along with the <a href=\"https://github.com/drewburlingame/ObjectPrinter\" rel=\"nofollow\">ObjectPrinter</a> library and the log4net ConsoleAppender. </p>\n\n<p>When I'm actively working on a test where I want to see additional output I just crank up my logging level... | {
"AcceptedAnswerId": "7590",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T20:44:14.643",
"Id": "7346",
"Score": "2",
"Tags": [
"c#",
".net",
"unit-testing"
],
"Title": "Trace-like extensions for unit testing"
} | 7346 |
<p>I know that Facebook has an algorithm to filter out posts that may be irreverent, but I'm building a very simple yet functional algorithm to improve on it.</p>
<p>It's getting complicated to maintain, and I want to know how to organize the code in one specific way, have patterns, use shortcuts etc...</p>
<p>Please... | [] | [
{
"body": "<p>I haven't really tried to understand your code but I have a few remarks :</p>\n\n<ul>\n<li><p>There's a much better way than using an array to get the i-th letter of the alphabet.</p>\n\n<pre><code>string ac[] = {\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \... | {
"AcceptedAnswerId": "7366",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-01T02:13:54.813",
"Id": "7349",
"Score": "2",
"Tags": [
"c++",
"algorithm",
"beginner"
],
"Title": "HappyBook algorithm for filtering out posts"
} | 7349 |
<p>What is the best way to considerably decrease the size of the following code without sacrificing functionality, and to make it more readable, and well, make it look professional?</p>
<pre><code>class Compiler
{
public string Compile(TextReader src)
{
string rtn = SourceTemplate.Top;
... | [] | [
{
"body": "<p>Just some generic notes since I'm not too familiar with C#:</p>\n\n<ol>\n<li><p><a href=\"https://stackoverflow.com/questions/73883/string-vs-stringbuilder\"><code>rtn</code> should be <code>StringBuilder</code></a></p></li>\n<li><p>I'd change the <code>preprocessor</code> and <code>ParserRounds</... | {
"AcceptedAnswerId": "7354",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-01T14:14:23.087",
"Id": "7353",
"Score": "2",
"Tags": [
"c#",
"parsing"
],
"Title": "Cleaning up Compiler class"
} | 7353 |
<p>I have a keyup function that expands an input field as text is added. There are a lot of fields where this code will be applied, what is the best way to write this for best performance?</p>
<p>Here is a working demo: <a href="http://jsfiddle.net/J9Ner/" rel="nofollow">http://jsfiddle.net/J9Ner/</a></p>
<pre><code>... | [] | [
{
"body": "<p>You can rearrange the if/else to be a little more efficient.</p>\n\n<p>You can retrieve the length a little more efficiently.</p>\n\n<p>And, use <code>.delegate()</code> (pre jQuery 1.7) or <code>.on()</code> (jQuery 1.7+) with a selector of a parent object close to the elements. That will perfor... | {
"AcceptedAnswerId": "7357",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-01T16:52:32.317",
"Id": "7356",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"performance"
],
"Title": "Increase performance for this keyup function?"
} | 7356 |
<p>I wrote a Hangman game to try out some of the new features in C++11. I'm pretty new to C++, and I would like some good advice on how I can improve this code (in terms of conventions, bad/good practices, ...):</p>
<pre><code>#include <iostream>
#include <fstream>
#include <vector>
#include <stri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-28T21:35:37.967",
"Id": "18132",
"Score": "0",
"body": "missing include `#include <ctime>`"
}
] | [
{
"body": "<p>A few thoughts:</p>\n\n<p>Instead of </p>\n\n<pre><code>do {\n std::getline(words_file, word);\n words.push_back(word);\n} while (!words_file.eof());\n</code></pre>\n\n<p>You should do</p>\n\n<pre><code>while(std::getline(words_file, word))\n words.push_back(word);\n}\n</code></pre>\n\n<p... | {
"AcceptedAnswerId": "7363",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-01T23:12:09.220",
"Id": "7362",
"Score": "12",
"Tags": [
"c++",
"beginner",
"c++11",
"hangman"
],
"Title": "Testing new C++11 features with Hangman"
} | 7362 |
<p>I am attempting to optimize a piece of C code which aims to multiply a series of pairs of unsigned shorts and add the result. I am only concerned about the high 16 bits of the result, and I can guarantee that the sum of the multiples will fit in a 32-bit value. I initially coded this in C, and then rewrote it to use... | [] | [
{
"body": "<p>Some suggestions:</p>\n\n<ul>\n<li><p>forget asm (for now at least) and stick with SSE intrinsics - you can concentrate on optimisation and let the compiler worry about the implementation details like register allocation, instruction scheduling and loop unrolling</p></li>\n<li><p>use a decent comp... | {
"AcceptedAnswerId": "7489",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-01T23:31:18.920",
"Id": "7364",
"Score": "4",
"Tags": [
"c",
"assembly",
"sse"
],
"Title": "SSE2 assembly optimization - multiply unsigned shorts and add the result"
} | 7364 |
<p>I was experimenting with lists, sets, and finally maps when I spotted a pattern in my code to make it recursive. Now I haven't used recursion much in the past or at work and I was very excited to have something that does recursion.</p>
<p>I have this recursive method that takes in an <code>Integer</code> and return... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T02:57:38.037",
"Id": "11538",
"Score": "2",
"body": "in last else if should be num>1000000, not '<'"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T03:02:50.530",
"Id": "11540",
"Score": "3",
... | [
{
"body": "<p>By all means, implement your code iteratively -- recursion is probably never the most efficient way to do something, because you do indeed make multiple copies of the local variables. If your method allocates a 256 byte buffer on the stack, that 256 byte buffer is allocated every method call, and ... | {
"AcceptedAnswerId": "7381",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T02:49:02.090",
"Id": "7369",
"Score": "6",
"Tags": [
"java",
"strings",
"recursion",
"converting",
"integer"
],
"Title": "Integer to String recursive method"
} | 7369 |
<p>I decided to put together a quick project using jquery, the Kendo UI HTML 5 framework and JavaScript. </p>
<p>I don't do much JavaScript development and I'd like some input on how to make this look less like a complete spaghetti hack, walking up and down DOM elements, trying to find the right event handler to hook ... | [] | [
{
"body": "<p>Here's my approach:</p>\n\n<ol>\n<li>Reduce temporary variables when it makes sense (when they're only used once)</li>\n<li>Reduce string tokens into reusable functions for url generation</li>\n<li>Add comments to increase clarity</li>\n<li>Add whitespace for clarity</li>\n<li>Reduce the duplicate... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T06:12:25.223",
"Id": "7372",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html5"
],
"Title": "JavaScript code quality"
} | 7372 |
<p>I'm learning java, although because of work I didn't had much time to go to classes. We had a final work to do but since I'm more familiarised with python I'm not sure if I'm doing java correctly...</p>
<p>I'm also a bit confused about attributes and constructors, I don't really understand the use of it.</p>
<p>Fo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T12:16:31.030",
"Id": "11557",
"Score": "2",
"body": "I'm not a friend of localized variable names and comments. You might want to consider to keep *everything* in English, especially if you come with your code to an English website ... | [
{
"body": "<p>I haven't read it all, but one thing I picked up:</p>\n\n<pre>\npublic Scorer(ArrayList> athletes, boolean gender) {\n this.athletes = athletes;\n this.gender = gender;\n if (gender == true) {\n this.bike = bike + \"F.tab\";\n this.run = run + \"F.tab\";\n } else { \n ... | {
"AcceptedAnswerId": "7394",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T12:09:11.307",
"Id": "7376",
"Score": "2",
"Tags": [
"java",
"homework"
],
"Title": "Is this correct java? Attributes and constructors especially"
} | 7376 |
<p>I'm kinda worried that the way I did my animation intro is a bit too heavy and is not optimized. Please review and let me know your thoughts.</p>
<pre><code>$(document).ready(function() {
introIconFirst();
function introIconFirst() {
$('h2.ribbon').css({
'marginTop': '+30px',
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-01T09:30:01.913",
"Id": "11560",
"Score": "0",
"body": "@JoshSmith Thanks. I didn't know it before. Will do for future post."
}
] | [
{
"body": "<p>Looks good, though I prefer to keep the $(document).ready() as clean as possible, by only making calls and not definitions. Makes DOM management a bit easier.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-01T11:09:38.937",
"Id"... | {
"AcceptedAnswerId": "7378",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-31T18:52:55.450",
"Id": "7377",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html5",
"easing"
],
"Title": "jQuery animation procedural approach, suggestions need"
} | 7377 |
<p>On ASP.NET MVC, I try to write an async Controller action with the old asynchronous programming model (actually, it is the current one, new one is still a CTP). </p>
<p>Here, I am trying to run 4 operations in parallel and it worked great. Here is the complete code:</p>
<pre><code>public class SampleController : A... | [] | [
{
"body": "<p>I would certainly include exception handling in the process. I normally use try catch statements. This at least allows me to catch the exceptions and return a more meaningful and informative message vs letting a method create a silent exception that may not be returned.</p>\n\n<p>Example within th... | {
"AcceptedAnswerId": "7398",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T13:24:57.937",
"Id": "7380",
"Score": "3",
"Tags": [
"c#",
"asp.net",
"asp.net-mvc-3",
"asynchronous"
],
"Title": "Old-way of asynchronous programming in ASP.NET MVC 3"
} | 7380 |
<blockquote>
<p>First number indicates the number of points, followed by N points
(x,y). Then the next number indicates Q num_queries, followed by Q queries:</p>
<ol>
<li>Reflect all points between point i and j both including along the
X axis. This query is represented as "X i j" </li>
<li>Reflect all ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T22:33:25.333",
"Id": "11578",
"Score": "1",
"body": "Can you add the expected output for the input you gave ?\n\nAs a first quick and useless comment, I would say that variable \"num_of_points\" is not really useful."
}
] | [
{
"body": "<p>Instead of initializing your arrayList when you create the instance of the class, do it when you have the num_of_points value from the scanner.</p>\n\n<pre><code>arrayList = new ArrayList<Point>(num_of_points);\n</code></pre>\n\n<p>This will mean the array list doesn't need to resize itself ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T20:00:09.787",
"Id": "7383",
"Score": "3",
"Tags": [
"java",
"homework",
"coordinate-system"
],
"Title": "Reflecting and counting points on a 2D grid"
} | 7383 |
<p>I'm calling this function from my html (and in some cases from another function in my JavaScript). These type of <code>switch</code> statements are starting to litter my code. Is there a more elegant solution to these <code>if</code> statements? I wish I could pass a reference to the variables I want to modify. ... | [] | [
{
"body": "<p>Use an object, with the keys being the letters, and then you can just do:</p>\n\n<pre><code>function incCriteriaStats(exp) {\n if(exp in obj)\n obj[exp]++;\n}\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-... | {
"AcceptedAnswerId": "7387",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T17:41:40.527",
"Id": "7385",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Looking for a better solution than a bunch of switch statements in my JavaScript"
} | 7385 |
<p>I would like to simplify to following function as much as possible:</p>
<pre><code>public string[] GetPowerSet(string input)
{
IEnumerable<IEnumerable<string>> seed = new List<IEnumerable<string>>() { Enumerable.Empty<string>() };
return input.Split(',').ToList().A... | [] | [
{
"body": "<p>Can't say I've simplified it much... but I've removed some syntactic extras that were unnecessary in the original version, made the method itself static (no reliance on instance data or methods) and hoisted out the seed to a one-time initialized class-level variable for speed/GC (over multiple cal... | {
"AcceptedAnswerId": "7461",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T21:52:19.830",
"Id": "7390",
"Score": "6",
"Tags": [
"c#"
],
"Title": "Simplify a powerset function in C#"
} | 7390 |
<p>I recently asked for some advice on the best way to structure my code for a program I was writing. (see <a href="https://softwareengineering.stackexchange.com/questions/127841/how-to-structure-this-program">this question on Programmers.SE</a>). The solution I was given was quite elegant, however I am less happy wit... | [] | [
{
"body": "<p>1) I would use the <code>ProgressChanged</code> event with a custom object as my <code>e.UserState</code> which is updated within the code.</p>\n\n<pre><code>// sample worker state class definition\ninternal class WorkerState\n{\n public Exception ExceptionThrown { get; set; }\n public strin... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-01-02T22:27:33.563",
"Id": "7391",
"Score": "3",
"Tags": [
"c#",
"multithreading",
"event-handling",
"user-interface"
],
"Title": "Keeping UI responsive while performing long runnin... | 7391 |
<p>Below is one of the first classes I've built. I started creating my functions like so:</p>
<pre><code>public function getCourseInfoByID($id) { }
</code></pre>
<p>Requiring the user to pass a course ID. I've recently modified it to assign the course ID (and <code>$course_info</code> - an array to reference each el... | [] | [
{
"body": "<p>Going from top to bottom:</p>\n\n<p><strong>Constructor</strong> </p>\n\n<pre><code>public function __construct($mysqli, $course_id = NULL) {\n</code></pre>\n\n<p>What kind of object is '$mysqli'? You can probably <a href=\"http://php.net/manual/en/language.oop5.typehinting.php\" rel=\"nofollow... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T00:38:40.730",
"Id": "7395",
"Score": "2",
"Tags": [
"php",
"object-oriented"
],
"Title": "PHP: Learning OOP"
} | 7395 |
<p>I am writing a prototype for something at work. Not very many people here know much about Linux/Unix or Xlib, so I can't really ask here at work (most developers are expert Windows programmers). With this said, I have one class and a driver that I would like feedback on how well I have integrated threads, XLib and O... | [] | [
{
"body": "<p>I would clean up the makefile<br>\nYou don't want to do it separately for each file as you then get cut/paste errors.<br>\nYou want to generalize this as much as possible (so that any change only needs to be done in one place (not in multiple locations). </p>\n\n<p>PS. Not tested.</p>\n\n<pre><cod... | {
"AcceptedAnswerId": "7409",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T01:15:45.847",
"Id": "7396",
"Score": "3",
"Tags": [
"c++",
"opengl",
"pthreads"
],
"Title": "Separate rendering thread with XLib (GLX) and OpenGL"
} | 7396 |
<p>I have this static class in an ASP.NET MVC project:</p>
<pre><code> public static class Setup
{
private static bool _intialized = false;
public static void Initialize(IWindsorContainer Container)
{
//Check if it has already run
if (_intialized)
{ return; }
var connectionStri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T21:22:47.203",
"Id": "14835",
"Score": "0",
"body": "Is there any way that you can use a static constructor? Right now the parameter gets in your way. Where does the `IWindsorContainer come` from, and why can it be called multiple t... | [
{
"body": "<p>This could execute more than once pretty easily if called on multiple threads at the same time. This should make it a bit more foolproof:</p>\n\n<pre><code> public static class Setup\n {\n private static readonly object _locker = new object();\n private static bool _intialized = false;\n\n... | {
"AcceptedAnswerId": "7413",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T01:26:18.150",
"Id": "7397",
"Score": "5",
"Tags": [
"c#"
],
"Title": "Having initialization code certain to run only once"
} | 7397 |
<p>I've been working on a semi-awkward query in that it uses a very high number of functions given its relatively small size and scope. I was hoping to get some feedback on any ways I could format or re-factor this better?</p>
<pre><code>select Name ,
avg(TimeProcessing / 1000 + TimeRendering / 1000 + TimeDat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T18:05:29.043",
"Id": "11638",
"Score": "0",
"body": "Because I _sincerely_ hope that you aren't actually getting a 'Month' value (say, `1` for 'January') by using the `AVG()` function, you should probably rename `Current Month` to w... | [
{
"body": "<p>You might want to use Common Table Expression or Should use meaningful table alias in Join.</p>\n\n<p>You might also want to use indexes on your date column with <= and >= operator instead of between.</p>\n\n<p>Surround your column names in [] instead of single quotes.</p>\n",
"comments": [... | {
"AcceptedAnswerId": "7405",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T04:25:40.457",
"Id": "7403",
"Score": "0",
"Tags": [
"sql",
"sql-server",
"t-sql"
],
"Title": "Query to compare execution performance metrics for the three most recent months"
} | 7403 |
<p>I am trying to create a very simple timer framework which allows you to setup event handling based on a timeout.</p>
<p>The basic primitives allow the programmer to:</p>
<ul>
<li>allocate or free timers</li>
<li>arm/disarm timers</li>
<li>set attributes and timeout for a timer</li>
</ul>
<p>Currently, the self co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T05:34:23.107",
"Id": "11587",
"Score": "2",
"body": "Your signal handler should be async-safe see https://www.securecoding.cert.org/confluence/display/seccode/SIG30-C.+Call+only+asynchronous-safe+functions+within+signal+handlers so... | [
{
"body": "<p>Usability could be improved a bit. For example, <code>alloc_timer()</code> (note, name is deceptive as no actual allocation takes place) could be put inside of the <code>set_timer()</code> function. Let your framework worry about finding a free timer in the pool, or returning an error code. A s... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T05:26:17.403",
"Id": "7406",
"Score": "6",
"Tags": [
"c",
"timer"
],
"Title": "Timer framework in C"
} | 7406 |
<p>Essentially, I am making an app that allows the user to type in chemistry formulas using a custom keyboard. </p>
<p>The keyboard will have several keys, for example, "Na", "H", and "O". Pressing them in different combinations will result in different formulas. For example, Na + O will result in NaO. Pressing any ke... | [] | [
{
"body": "<p>You can use some <code>if else</code> statement, where u use several independent <code>if</code>s. This will lead to a slightly faster code, because in the case, where the previous if is try, no further testing is needed. Personally I also find it more readable for short and medium sized code bloc... | {
"AcceptedAnswerId": "7592",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T06:40:46.910",
"Id": "7407",
"Score": "6",
"Tags": [
"objective-c",
"memory-management",
"ios"
],
"Title": "App for allowing the user to type in chemistry formulas using a custo... | 7407 |
<p>I just wanted to know if I'm doing this right. Note that all the matrices are <code>int[16]</code>s.</p>
<pre><code>for (int i= 1; i <= 3; i++){
for (int j= 1; j <= 3; j++){
int sum = 0;
for (int h = 1; h <= 3; h++){
sum = sum + position[i*4+h]*projection[h*4+j];
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T05:03:45.387",
"Id": "11612",
"Score": "0",
"body": "It looks like you are indexing a vector (one dimension) rather than a matrix (at least 2 dimensions),"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-... | [
{
"body": "<p>No. Let's first look at it as two dimensional arrays, so we know what we're talking about:</p>\n\n<pre><code>int i[4][4];\nint j[4][4];\nint k[4][4];\n\nfor (int x = 0; x < 4; x++) { // row number of output\n for (int y = 0; y < 4; y++) { // column number of output\n k[x][y] = 0;\n... | {
"AcceptedAnswerId": "7416",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-02T05:00:56.560",
"Id": "7415",
"Score": "2",
"Tags": [
"c++",
"matrix"
],
"Title": "Am I multiplying two matrices together correctly?"
} | 7415 |
<p>I want to make this code generic, so that I could remove <code>if</code>/<code>else</code> and recursive <code>for</code> loops. </p>
<p>I am open to accept all kind of suggestions regarding common interface implementation but kindly check that their property names FKID are different, and as these are POCO entities... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T13:35:27.337",
"Id": "11619",
"Score": "0",
"body": "I would start by extracting newClientTripTypeContract.ClientTripTypeContractChargeValueLists[i] and newClientTripTypeContracts[i] to make the loop easier to read."
}
] | [
{
"body": "<p>Bug? In each of your 4 inner for loops, your code is referencing the following:</p>\n\n<pre><code>newClientTripTypeContract.ClientTripTypeContractChargeValueLists[i]\n</code></pre>\n\n<p>Shouldn't it be this, instead?</p>\n\n<pre><code>newClientTripTypeContracts[i]\n</code></pre>\n\n<p>EDIT: I mis... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T13:10:14.850",
"Id": "7417",
"Score": "3",
"Tags": [
"c#",
"generics"
],
"Title": "Client trip type contracts"
} | 7417 |
<p>I've got this function which returns an SQLObject instance as a dict (taking into account inherited classes, properties, etc). It doesn't work right now on SQLObject classes which inherit from another class but add new attributes, so that's a work in progress, but I feel like this could be done smarter/better in Py... | [] | [
{
"body": "<pre><code>def sqlobject_to_dict(obj):\n obj_dict = {}\n cls_name = type(obj)\n</code></pre>\n\n<p>That's not a name, its a class object</p>\n\n<pre><code> has_props = False\n for attr in vars(cls_name):\n attr_parent = type(getattr(obj, attr)).__bases__[0]\n</code></pre>\n\n<p>You... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T15:46:21.603",
"Id": "7420",
"Score": "4",
"Tags": [
"python",
"json"
],
"Title": "A better way to convert an SQLObject instance into a dict"
} | 7420 |
<p>I have a method which compares two lists of strings. If the strings, and only the strings, from <code>listA</code> appear in <code>listB</code>, return <code>true</code>. Else return <code>false</code>.</p>
<pre><code>internal bool DoIdsMatchThoseFromXml(List<string> Ids, List<string> XmlIds)
{
... | [] | [
{
"body": "<p>If you can use LINQ, I think you can do</p>\n\n<pre><code>internal bool DoIdsMatchThoseFromXml(List<string> Ids, List<string> XmlIds)\n{\n return \n Ids.Count == XmlIds.Count &&\n Ids.All(XmlIds.Contains) &&\n XmlIds.All(Ids.Contains);\n}\n</code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T19:59:29.090",
"Id": "7422",
"Score": "13",
"Tags": [
"c#",
"algorithm",
"strings"
],
"Title": "Compare items in two lists"
} | 7422 |
<p>I created a simple Python script to log track listens in iTunes and it seems that it's pretty inefficient. I'm primarily a front-end developer, so this is clearly not my area of expertise. I know loops can cause problems in any language, so I assume that's the issue here.</p>
<p>If I run this script for a while (sa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T20:02:00.200",
"Id": "11643",
"Score": "0",
"body": "Try running it through `python -m cProfile -o prof.dat <prog> <args>` for a while, and you'll get file that gives you calls and how long each call took in CPU seconds. To view it... | [
{
"body": "<pre><code>#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\nimport wx, sqlite3, datetime, threading\nfrom appscript import *\n</code></pre>\n\n<p><code>import *</code> is frowned upon as it makes it difficult to trace where names came from.</p>\n\n<pre><code>it = app('iTunes')\n</code></pre>\n\n<p>I rec... | {
"AcceptedAnswerId": "7428",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T19:57:30.340",
"Id": "7423",
"Score": "2",
"Tags": [
"python"
],
"Title": "Inefficient Python script eating up memory (I believe)"
} | 7423 |
<p>It seems that lxml/etree are generally imported as <code>from lxml import etree</code> -- why is that? It keeps the code tidier, and while the potential namespace ambiguity might not be a concern, I don't have any incentive of doing this as it's generally frowned upon.</p>
<p>I know for a script of this size it do... | [] | [
{
"body": "<p>You might be confusing <code>from lxml import etree</code> that is a legitimate (even preferred) form of an absolute import with relative imports for intra-package imports that are discouraged: <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">http://www.python.org/dev/peps/pep... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-03T22:15:32.377",
"Id": "7430",
"Score": "6",
"Tags": [
"python",
"parsing",
"lxml"
],
"Title": "Extracting a div from parsed HTML"
} | 7430 |
<p>Is there a better way to express the dispatch (switch) code without using a lambda? I think I need the lambda to act as an intermediary because the functions have varying numbers of parameters.</p>
<pre><code>def printf(arg):
print arg
def printf2(arg1, arg2):
print arg1
print arg2
def printn(arg):
... | [] | [
{
"body": "<p>You could change it to just store the functions <em>and</em> the arguments. Then use the argument unpacking to fill in the correct arguments to the function call.</p>\n\n<pre><code>action = 'op2'\nfunctions = {\n 'op1': (printf, ('op1 called',)),\n 'op2': (printf2, ('op2 called', 'param 2')... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T01:58:23.687",
"Id": "7433",
"Score": "4",
"Tags": [
"python"
],
"Title": "Dictionary-based dispatch in Python with multiple parameters"
} | 7433 |
<p>I read that if an object is made using the <code>init</code> it must be released, but if it's something like this <code>elementFormula = [[NSMutableString stringWithString:@""]</code> it is autoreleased. However, there are some other aspects of memory management that confuse me.</p>
<p>For example, something like... | [] | [
{
"body": "<p>It's not init that causes you to have to be responsible for releasing the memory its alloc. If you call alloc, retain or new (this is rarely used these days) then you are responsible for releasing the memory yourself.</p>\n\n<p>So in the case where you had an autoreleased object and you retained i... | {
"AcceptedAnswerId": "7448",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T04:26:18.977",
"Id": "7437",
"Score": "3",
"Tags": [
"objective-c",
"memory-management"
],
"Title": "Am I managing my memory correctly?"
} | 7437 |
<p>I've made a mock version of Silverlight in D2. It is meant to output HTML, but since I don't know HTML yet, its current output is in. HTML is not the reason I'm here, though. The goal of my project was to create a framework that uses XAML and MVVM to create a site bound to a viewmodel. It doesn't do too much and isn... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T10:39:09.153",
"Id": "16303",
"Score": "1",
"body": "You will be happy to learn that in HTML you can use either `\"` or `'` around the properties... so you can use `name='item1'` instead of `name=\\\"item1\\\"`. :) You will also fin... | [
{
"body": "<p>Here's what I've settled with in case anyone is interested:</p>\n\n<p>Using the factory pattern I was able to build an <strong>injectable factory</strong>. Then using dependency injection I forward the factory through all the control extraction steps. <strong>This has the advantage of allowing a c... | {
"AcceptedAnswerId": "21645",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T05:52:41.720",
"Id": "7438",
"Score": "10",
"Tags": [
"template-meta-programming",
"mixins",
"d",
"silverlight"
],
"Title": "Mixin and template-heavy code for a Silverlight... | 7438 |
<p>I'm worried about my code performance. The code I've written is an implementation of SHA-256 using pseudocode from Wikipedia. It works fine, but I want to speed it up. With a buffer of 4096 bytes, I only get 40 Mb/s, whereas commercial software gets 120Mb/s. I've degugged the code, and it seems that the problem is ... | [] | [
{
"body": "<ul>\n<li><p>As a really quick comment, you can do : </p>\n\n<pre><code>for(i = index, index+=64; i < index; i++, j++, ctBuffer++) { (...) }\n</code></pre>\n\n<p>instead of </p>\n\n<pre><code>for(i = index; i < (index + 64); i++, j++, ctBuffer++) { (...) } index += 64;\n</code></pre>\n\n<p>to m... | {
"AcceptedAnswerId": "7446",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T13:56:59.540",
"Id": "7443",
"Score": "11",
"Tags": [
"c++",
"performance",
"reinventing-the-wheel",
"cryptography"
],
"Title": "My own SHA-256 code implementation"
} | 7443 |
<p>A method that I'm working on in a C# project includes the following:</p>
<pre><code>if (isDailyRateRequired)
{
CalculatedDailyRate = dailyRate;
}
if (isWeeklyRateRequired)
{
CalculatedDailyRate = weeklyRate / 7;
}
if (isMonthlyRateRequired)
{
CalculatedDailyRate = monthlyRate / 30;
}
</code></pre>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T11:37:58.987",
"Id": "11732",
"Score": "0",
"body": "Show the code please where the boolean variables is set I mean isDailyRateRequired etc. Show more code or explain what you want to do at all. I think it is need to redesign not on... | [
{
"body": "<p>Since those seem to be mutually exclusive conditions, you may not want to execute all 3 <code>if</code>s every time by putting an <code>else</code> in between:</p>\n\n<pre><code>if (isDailyRateRequired) \n{\n CalculatedDailyRate = dailyRate;\n}\nelse if (isWeeklyRateRequired) \n{\n Calculate... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T16:02:47.417",
"Id": "7447",
"Score": "7",
"Tags": [
"c#"
],
"Title": "Cleaning up a three-factor if statement"
} | 7447 |
<p>I have written a class and spec for testing my class. Can anyone determine whether or not this is a correct and good spec?</p>
<p><strong>Class:</strong></p>
<pre><code>module Sitemap
=begin
Class Name: Cities
Function: This class is responsible for getting the data to create the sitemap
for each country accordin... | [] | [
{
"body": "<p>Here are a few things I thought of:</p>\n\n<ol>\n<li><p>Use let when you can, it is a pretty versatile function for testing.</p>\n\n<pre><code>before :all\n @city = City.new :country_version, :directory, :country_host, :locale\nend\n</code></pre>\n\n<p>Can be rewritten as:</p>\n\n<pre><code>let(:... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T16:36:58.313",
"Id": "7452",
"Score": "3",
"Tags": [
"ruby",
"unit-testing",
"rspec"
],
"Title": "City class and spec for testing it"
} | 7452 |
<p>I am new to Android programming and I'm working on an Activity in an app that will plot the location of contacts from a specific email account on to a map. The following is what I in a class that the Activity will use to get the Contact info I want to use when plotting the location. I have tested this and it works. ... | [] | [
{
"body": "<p>Just some generic Java notes since I'm not too familiar with Android.</p>\n\n<ol>\n<li><p>The reference type of your list should be only <code>List</code>. Instead of:</p>\n\n<pre><code>ArrayList<String> nameList = new ArrayList<String>();\n</code></pre>\n\n<p>use:</p>\n\n<pre><code>L... | {
"AcceptedAnswerId": "7487",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T20:03:29.350",
"Id": "7465",
"Score": "3",
"Tags": [
"java",
"android"
],
"Title": "Extracting Android contact Info"
} | 7465 |
<p>I have a navigation, with a sprite that changes based on the class. In my jQuery, I'm clearing out the classes so it will just have <code>.nav</code> and then <code>addClass</code> the right class based on the click. It works but feels very redundant. Does anyone have suggestions on optimizing this?</p>
<p>HTML: <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T19:16:17.727",
"Id": "11700",
"Score": "0",
"body": "is the `grid_12` class supposed to go away when you click a link?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T18:43:38.730",
"Id": "11706",... | [
{
"body": "<p>How about this? (Untested!)</p>\n\n<pre><code>$('DIV.content DIV.nav ul li').click(function(){\n $(this).closest('DIV.nav').attr('class', 'nav').addClass($(this).attr('class'));\n});\n</code></pre>\n\n<p>The idea is that when an li element is clicked, you take whatever classes are on that li el... | {
"AcceptedAnswerId": "7468",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T18:34:27.240",
"Id": "7466",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Changing a sprite based on the class"
} | 7466 |
<p><strong>Preview:</strong> <a href="http://sparksonrails.pennfolio.com/" rel="nofollow">http://sparksonrails.pennfolio.com/</a></p>
<p><strong>Jquery:</strong></p>
<pre><code>function introIconFirst()
{
$('h2.ribbon').css(
{
'marginTop': '+30px',
'opacity': '0'
}).animate(
{
... | [] | [
{
"body": "<p>First off, if you're trying to do these animations sequentially, the code isn't written to do that. You need to pass a function reference, not the result of a function call so this:</p>\n\n<pre><code>function introIconFirst()\n{\n $('h2.ribbon').css(\n {\n 'marginTop': '+30px',\n ... | {
"AcceptedAnswerId": "7472",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-04T22:01:10.760",
"Id": "7471",
"Score": "2",
"Tags": [
"jquery",
"optimization",
"css",
"html5"
],
"Title": "Can my code be optimized more?"
} | 7471 |
<p>Basically I'm trying to generalise and extend the notion of mapping one string into another.
There are two methods I often find myself using for this: Functions, and Dictionairies.</p>
<p>So here are my 3 classes. (I intend to create some explict classes as well, like ToCamelCase - as my current project requires)</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T14:47:44.863",
"Id": "11739",
"Score": "0",
"body": "Hmm, try adding an implicit operator to convert `Expression<Func<string, string>>` to `FuncStringMapping`. I think that your issue might be that the compiler does not consider the... | [
{
"body": "<p>This is a fairly hackish idea. You can decide whether you want to pollute your codebase with this. This idea is similar to jQuery, which heavily overloads the $ character to provide a multitude of functionality.</p>\n\n<p>First, define a utility class named \"s\":</p>\n\n<pre><code>public static ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T08:48:29.810",
"Id": "7480",
"Score": "1",
"Tags": [
"c#",
"strings",
"functional-programming",
"operator-overloading"
],
"Title": "Extending string mapping"
} | 7480 |
<p>I started an open source Markdown editor using C#. I'm a huge fan of the MVC pattern, however I am having trouble refactoring my back-end form code. It's getting pretty long and I was wondering if anyone had tips on which pieces I can move to separate classes.</p>
<p>Here is my main form C# code: </p>
<pre><code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T15:00:46.540",
"Id": "63131",
"Score": "1",
"body": "My experience is that the MVP pattern works better with Windows Forms. It is more or less the same principle.\nIt also makes it easier to create a WebForms application with the sa... | [
{
"body": "<p>There is a port to C# of PureMVC out there that I have been using, and made modifications to it to do the following:</p>\n\n<ol>\n<li>In PureMVC the views are called Mediators, so the technique is to group concerns into a mediator -- so your MainForm will have numerous Mediators (basically, ideall... | {
"AcceptedAnswerId": "7763",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T12:49:31.620",
"Id": "7485",
"Score": "2",
"Tags": [
"c#",
"design-patterns",
"mvc"
],
"Title": "Refactor Windows Form code to follow MVC"
} | 7485 |
<p>How can I re-factor the code to remove duplication and create a common method ?</p>
<pre><code>(function(){
$("#a", "#main").bind("mouseover", function(){
var id1 = $("#one").text(),
args = ["DCSext.common1","common1","DCSext.common2","DCSext.title","one", "DCSext.ti", id1];
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T02:05:34.890",
"Id": "12471",
"Score": "0",
"body": "@paul Can you clarify your problem? I don't understand what you mean by \"common logs\". Are you referring to the `args` array you're passing into `dcsMultitrack()`? The `commonlo... | [
{
"body": "<p>There is not much you can do,\nthe only thing I would suggest is to use <code>concat</code> instead of <code>push</code>, this way you can keep re-using <code>commonLogs</code>, and maybe have 1 <code>commonLogs</code> per group.</p>\n\n<p>So</p>\n\n<pre><code> var commonLogs = [ [] ];\n commonL... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T12:57:18.110",
"Id": "7486",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Creating a webtrend function to remove duplication using js apply and call"
} | 7486 |
<p>These two methods do very similar things. Is it possible to condense these somehow? This is using the Entity Framework. </p>
<pre><code>public void ExportSiteData (FLEX_INV_EXP_SITE siteData)
{
var uniqueSite = from e in _context.FLEX_INV_EXP_SITE
where e.SITE_ID == siteData.SITE_ID
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T15:48:09.097",
"Id": "11752",
"Score": "0",
"body": "Can you make them both share an interface? - that would be the easiest way (and wouldn't use generics at all).\nThere is also a duck typing library for C# (never looked at it myse... | [
{
"body": "<p>Here is a wildly simplified example, but you could try something like this:</p>\n\n<pre><code>public class EXP_SITE\n{\n public int SITE_ID { get; private set; } \n}\n\npublic class EXP_ADDRESS\n{\n public int SITE_ID { get; private set; } \n}\n\npublic class SomeList<T> : List&l... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T14:42:08.820",
"Id": "7488",
"Score": "5",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Exporting site and address data"
} | 7488 |
<p>I'm hoping someone is willing and can take a minute to look over this function and tell me what they think of it, if it can be improved or what not. I tried commenting out what the purpose of everything is. I would like to note that something isn't quite right with the time_remaining and what not because what's supp... | [] | [
{
"body": "<p><strong>Okey, first of all; I had a hard time determining if this was a login script or a registration script even if you explicitly said it was a script containing login validation. If I was you I would review the code and try to clear up any vagueness, because I got a headache trying to sort you... | {
"AcceptedAnswerId": "7511",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T22:05:33.043",
"Id": "7501",
"Score": "3",
"Tags": [
"php",
"codeigniter"
],
"Title": "Login Validation"
} | 7501 |
<p>I am working on bettering my C# skills, and recently wrote this program to solve a projecteuler.net problem:</p>
<blockquote>
<p>A palindromic number reads the same both ways. The largest palindrome
made from the product of two 2-digit numbers is 9009 = 91 * 99. Find
the largest palindrome made from the produ... | [] | [
{
"body": "<ul>\n<li><p>First of all, add benchmarking to your program: before anything else, record the current time. Right before the program terminates, subtract the recorded time from the current time and display the difference. Run it and record the time it takes. Then, implement the following optimization... | {
"AcceptedAnswerId": "7512",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T22:06:28.743",
"Id": "7502",
"Score": "9",
"Tags": [
"c#",
"programming-challenge",
"palindrome"
],
"Title": "Determining numeric palindromes"
} | 7502 |
<p>I've tried making a payment system for an <a href="http://api.payson.se/" rel="nofollow">API called Payson</a>, which is a European company similar to PayPal.</p>
<p>I get the right response when I press the button so it seems to work, and I wonder if you can look at my code to see if it looks OK. I didn't test the... | [] | [
{
"body": "<p>First of all, please make sure that your indentation is correct, especially when posting Python code. Also, take a look at <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a>. You are violating it in at least the following places:</p>\n\n<ul>\n<li>You have tabs, not ... | {
"AcceptedAnswerId": "7681",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T23:55:59.920",
"Id": "7503",
"Score": "3",
"Tags": [
"python",
"finance"
],
"Title": "Payment system for a web shop"
} | 7503 |
<p>I am relearning C so if you could point obvious faults in this solution to <a href="http://news.ycombinator.com/item?id=3429466" rel="noreferrer">this problem</a> I'd greatly appreciate such comments. Please note that I'm using GCC extensions to use larger than 32 bit numbers. Most importantly I want to be aware of ... | [] | [
{
"body": "<p>Looks pretty good to me. If I were doing this for an interview question, I would take on the challenge of implementing it recursively. Here are some minor changes I would make:</p>\n\n<ol>\n<li><p>You are hard-coding your for loop to 31 iterations. That ought to be a <code>const uint32_t num_itera... | {
"AcceptedAnswerId": "7516",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T00:30:07.027",
"Id": "7504",
"Score": "6",
"Tags": [
"c"
],
"Title": "Pascal's triangle in C"
} | 7504 |
<p>I'm attempting some Project Euler problems in an attempt to learn Python. While I can get the correct answer quite easily, my programs are quite slow. Project Euler, if doing it correctly, specifies that each program should run in <1 minute. Some of mine take 5-10 mins.</p>
<p><a href="http://projecteuler.net/p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T00:00:29.793",
"Id": "11773",
"Score": "4",
"body": "Yuck, it looks like you are trying to write C in python"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T00:02:12.117",
"Id": "11774",
"Scor... | [
{
"body": "<p>While many of the Project Euler problems <em>can</em> be solved by brute force, this often isn't the fastest way to do them. Usually there is some kind of algorithmic insight that you can apply that will make your solution faster. This kind of insight is independent of programming language - simpl... | {
"AcceptedAnswerId": "7507",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-05T23:58:22.827",
"Id": "7505",
"Score": "7",
"Tags": [
"python",
"performance",
"project-euler"
],
"Title": "Project Euler #14 - Longest Collatz sequence"
} | 7505 |
<p>I just created a script on jQuery which loads my articles dynamically with an AJAX call if the user changes the page.</p>
<p>I added some cool effects like the articles move on the left, then the new ones appear in fade while a loading black screen cover the articles.</p>
<p>The thing is, I'm afraid my code is too... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T02:43:33.997",
"Id": "11789",
"Score": "1",
"body": "I think you could improve by perhaps utilising chaining, and also wrapping it up as your own plugin so you can just go `$('div').myplugin()` but if it works and looks good then th... | [
{
"body": "<p>One big step to opimize your code is to cache your jQuery objects.</p>\n\n<pre><code>var $layer = $('#layer');\n</code></pre>\n\n<p>You can also chain your method calls</p>\n\n<pre><code>$layer.css({ height: '30px' }).fadeIn(300).append('<span>hi</span>');\n</code></pre>\n\n<p>Also, ma... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-06T02:34:21.073",
"Id": "7513",
"Score": "2",
"Tags": [
"javascript",
"performance",
"jquery"
],
"Title": "Loading articles dynamically on page change"
} | 7513 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.