body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>As an update to <a href="https://codereview.stackexchange.com/questions/9193/linked-list-review">previous code</a> I've submitted:</p>
<p>Improvements this time are mainly having everything moved to a class, before I plough on and add more functionality (I've come back to C++ after a few years away and this is a re... | [] | [
{
"body": "<p>You have a problem with your constructor and <code>push()</code> method.</p>\n\n<p>When you create a new linked list, you automatically create two new nodes - head and last. This means you can't have an empty linked list as every new linked list will have 2 nodes in it. This isn't what I'd expec... | {
"AcceptedAnswerId": "9399",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T15:22:40.997",
"Id": "9230",
"Score": "9",
"Tags": [
"c++",
"linked-list"
],
"Title": "Linked list implemented as classes, not imperative code"
} | 9230 |
<p>Here it is at work: <a href="http://pcsn.nnja.co" rel="nofollow noreferrer">pcsn.nnja.co</a></p>
<p>As you can see, while the slider <code>.shuffle</code> works and is adjusting itself as it was intended to when the corresponding navigational item <code>#menu-main-navigation li a</code> is hovered upon, the effect ... | [] | [
{
"body": "<p>A cursory glance at the plugin's documentation yielded <a href=\"http://jquery.malsup.com/cycle/pager10.html\" rel=\"nofollow\">this example</a>, which seems close to what you're aiming for. Alas, no fade...</p>\n\n<p>Anyway, I tinkered a little with it, and this works. It's not elegant, but that'... | {
"AcceptedAnswerId": "9496",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T16:13:00.850",
"Id": "9233",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery cycle slider"
} | 9233 |
<p>Questions regarding homework assignments are more than welcome, provided that they are <a href="/help/on-topic">on-topic</a> and meet our <a href="/help/how-to-ask">usual quality criteria</a>. In particular, the code must <strong>already be working as intended</strong>.</p>
<p>It is suggested that you include the ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T18:31:30.283",
"Id": "9237",
"Score": "0",
"Tags": null,
"Title": null
} | 9237 |
Questions requesting help with school homework. This tag lets potential answerers know that they should GUIDE the student in solving the problem, rather than showing a complete solution. CAUTION: Before posting, consider that classmates may be tempted to reuse code from your post. (Read the tag wiki.) | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T18:31:30.283",
"Id": "9238",
"Score": "0",
"Tags": null,
"Title": null
} | 9238 |
<p>This feels like the kind of problem that has an extremely elegant solution. But my code is mechanical and straightforward. Not bad but I'm interested if there's something nicer.</p>
<p><strong>Performance is not really an issue.</strong> I'm looking for elegant/shorter, not faster.</p>
<p>No underscore.js please; ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T05:37:27.080",
"Id": "14513",
"Score": "0",
"body": "In general you want to name it `containSameIds` and just swap `return true` with `return false`. I personally would convert arrays to hash sets and then iterate over one, then ano... | [
{
"body": "<pre><code>function areDifferentByIds(a, b) {\n var idsA = a.map( function(x){ return x.id; } ).unique().sort();\n var idsB = b.map( function(x){ return x.id; } ).unique().sort();\n return (idsA.join(',') !== idsB.join(',') );\n}\n</code></pre>\n\n<p>This is the simplest I could make it. I t... | {
"AcceptedAnswerId": "9247",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T19:57:44.493",
"Id": "9241",
"Score": "11",
"Tags": [
"javascript"
],
"Title": "Comparing two arrays to see if they contain objects with different IDs"
} | 9241 |
<p>Please review my first query project. It achieves the desired result, but am I doing it right?</p>
<pre><code>window.onresize = centreBoxInViewport;
function displayLightBox(obj) {
// Get the path to the image
var path = obj.getAttribute("href");
// Create a new image, and set its source.
var ima... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-11-30T06:31:17.580",
"Id": "207271",
"Score": "0",
"body": "Your `#lightbox` has style `display: none`, so there is nothing visible to click on."
}
] | [
{
"body": "<p>Looks fine to me, but I do have a few recommendations:</p>\n\n<p>Instead of calling the <code>onclick</code> handler inline, consider doing the following:</p>\n\n<pre><code>$('#close').click(function(e) { fadeBox(e); });\n</code></pre>\n\n<p>Then I would pass <code>e</code> to <code>fadeBox()</cod... | {
"AcceptedAnswerId": "9244",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T20:01:27.410",
"Id": "9243",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"html",
"css"
],
"Title": "Displaying an image in a lightbox"
} | 9243 |
<p>I am building a Perl module which I am attempting to use as few non-core dependencies as possible. Should my following code fail, I would add a dependency on HTML::LinkExtor and be done with it, but I want to try. All I want is to extract the <code>href=</code> attributes from <code><a></code> tags. I do it us... | [] | [
{
"body": "<pre><code><script language=\"javascript\">\nvar a='<a href=\"1\" title=\"Passably ok, yes, why not. Perfect, no.\">'\ndocument.write('<a href=\"2\" title=\"Real-world HTML is just really complicated.\">')\n</script>\n<style type=\"text/css\">\np { font-family: \"<a h... | {
"AcceptedAnswerId": "10143",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T20:30:31.517",
"Id": "9245",
"Score": "1",
"Tags": [
"html",
"perl"
],
"Title": "extract href from html"
} | 9245 |
<p>I managed to put together following code to correctly Populate RequestExecutionViewModel model,however this looks extremely verbose to me. I feel some sort of LINQ builtin mapping construct can be used to reduce the over all code size. Please suggest improvements.</p>
<pre><code>string userName = User.Identity.Name... | [] | [
{
"body": "<p>What is going to give you massive overhead is pulling back requests then looping through all of the requests and finding associated table data. In reality, you should be building a single query (stored procedure) that will pull back all requests and will also return tables for ExecutionStatus and ... | {
"AcceptedAnswerId": "9256",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T03:24:42.377",
"Id": "9252",
"Score": "1",
"Tags": [
"c#"
],
"Title": "How to make this ASP.NET MVC ViewModel population query efficient?"
} | 9252 |
<p>Using Delphi XE2, I'm wondering if it would be usable to define a base object something like below.
Class is prone to be used in multiple projects.</p>
<p>I've chosen TSQLConnection as my starting point - since it's using the dbxpress framework and should be able to connect to a wide range of databases and other. B... | [] | [
{
"body": "<blockquote>\n <p>Is this the best design?</p>\n</blockquote>\n\n<p>Best design for what? and the answers of yes, no and maybe are all correct.</p>\n\n<p>What you want to research is design patterns and more specifically Patterns of Enterprise Application Architecture, Active Record, Business Object... | {
"AcceptedAnswerId": "9265",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T08:20:29.743",
"Id": "9254",
"Score": "1",
"Tags": [
"design-patterns",
"object-oriented",
"delphi"
],
"Title": "Defining a new Delphi Class with built-in Connection"
} | 9254 |
<p>Let's keep this simple.</p>
<p>Input:</p>
<pre><code>- abc
- def
- ghi
</code></pre>
<p>Desired output (whitespace optional):</p>
<pre><code><ul>
<li>abc</li>
<li>def</li>
<li>ghi</li>
</ul>
</code></pre>
<p>Current code:</p>
<pre><code>$output = preg... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T10:11:02.473",
"Id": "14518",
"Score": "0",
"body": "Do you need to handle nested lists? Because that won't work with a regex."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T10:31:55.820",
"Id": ... | [
{
"body": "<p>Wouldn't this give you the desired output:</p>\n\n<pre><code>$result = '<ul>' . preg_replace('/^- (.*)$/m', '<li>$1</li>', $subject) . '</ul>';\n</code></pre>\n\n<p><strong>Update:</strong></p>\n\n<pre><code>$output = preg_replace_callback(\n \"((^- (.*)$\\r*\\n*)+)m\",\... | {
"AcceptedAnswerId": "9258",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T08:56:00.307",
"Id": "9255",
"Score": "2",
"Tags": [
"php",
"regex"
],
"Title": "Bulleted list from dashes"
} | 9255 |
<p>I guess I made the mistake of creating <code>UIImage *image1</code> to <code>UIImage *image11</code>. Can an one advise me on how to improve it?</p>
<pre><code>+(NSArray *)stampImages{
UIImage *image1 = [UIImage imageNamed:@"abcd.png"];
UIImage *image2 = [UIImage imageNamed:@"fron.png"];
UII... | [] | [
{
"body": "<p>If you have the list of files you want to add to the array, then you can fast enumerate through them:</p>\n\n<pre><code>NSArray *fileArray; //List of file name here\nNSMutableArray *stampList = [NSMutableArray array];\nfor (NSString *fileName in fileArray)\n{\n [stampList addObject:[UIImage ima... | {
"AcceptedAnswerId": "9261",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T09:47:13.897",
"Id": "9257",
"Score": "1",
"Tags": [
"array",
"objective-c",
"image"
],
"Title": "Function to create an array of images"
} | 9257 |
<p>I've made a method, which inserts a new query parameter, when the value of a select changes, then reloads the page. I've had enough of URL jQuery hax, so I figured it would be a great idea to put the query parameters in an array, and manipulate it that way. I'm a little unsure whether or not this is the best way of ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-07-12T07:58:17.680",
"Id": "382495",
"Score": "0",
"body": "According to vanilla-js.com, you can run 12,137,211 ops/second of `document.getElementById('test-table');` In comparison, you can run 350,557 ops/second of `$jq('#test-table');`.... | [
{
"body": "<p>if you already use jQuery for something else in your page, it doesn't bother if you use jQuery or not.</p>\n\n<p>if it's the only JQuery in your page, I suggest to change it to \"vanilla\" javascript, because you won't need to load the jquery library.</p>\n\n<p>Some may say that often the jquery l... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T13:28:06.533",
"Id": "9264",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"form",
"event-handling",
"url"
],
"Title": "Change URL on select change"
} | 9264 |
<p>I need to draw tabulated data given a header as list and rows as list of lists
This is what I came up with. I wouldn't say that I like it much.
Could you please have a look if it can be done better (I am sure it can) and generally point to any error and possible optimization. Maybe someone has done exact same thing ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T09:22:35.140",
"Id": "14534",
"Score": "0",
"body": "A quick fixup: `(\\ x -> foo x)` is identical to just `foo`."
}
] | [
{
"body": "<p>It might make sense to use a pretty-printing library to do this. You can use <a href=\"http://hackage.haskell.org/package/pretty\" rel=\"nofollow\">pretty</a> along with the extension <a href=\"http://hackage.haskell.org/package/pretty-ncols\" rel=\"nofollow\">pretty-ncols</a> package; or possibl... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T06:01:37.640",
"Id": "9266",
"Score": "2",
"Tags": [
"haskell"
],
"Title": "Haskell: Draw tabulated data given header and rows as lists"
} | 9266 |
<p>I am implementing a list structure in C. My current function I am working on is a destructive append function that takes two lists and appends the second one onto the end of the first. Right now, it appears to be working without runtime errors and memory leaks and I think I have all my cases covered, but when I subm... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T15:58:15.287",
"Id": "14558",
"Score": "0",
"body": "Also note that calling `free()` on a null pointer has no effect."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T16:05:55.057",
"Id": "14559",
... | [
{
"body": "<p>Your temporary variable names are horrible and give a false impression of what they are doing.</p>\n\n<pre><code>ilist tmp = iempty(); // Is this really a temporary and a temporary of what.\n // Looks like you are building a copy of il1 onto this list.\n\nilist clone = il1;... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T15:26:05.887",
"Id": "9272",
"Score": "2",
"Tags": [
"c",
"linked-list",
"homework"
],
"Title": "Destructively appending one list to another"
} | 9272 |
<p>It's very popular to see code like this:</p>
<pre><code>bool DoSomething([some arguments]);
</code></pre>
<p>You can't understand the result of this method by looking at its name (it could actually be a <code>void</code>).</p>
<p>What's the best approach to refactor such kind of methods? What I have in mind is s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T19:04:55.940",
"Id": "14702",
"Score": "0",
"body": "Use exceptions unless you need performance and this private method is just a helper."
}
] | [
{
"body": "<p>I would go with</p>\n\n<pre><code>bool TryDoSomething([some arguments]);\n</code></pre>\n\n<p>, following the naming logic of <a href=\"http://msdn.microsoft.com/en-us/library/f02979c7.aspx\"><code>Int.TryParse</code></a>.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T17:25:23.700",
"Id": "9274",
"Score": "18",
"Tags": [
"c#"
],
"Title": "Using return value vs out parameters"
} | 9274 |
<p>I tried to implement a naive brute-force Sudoku solver in Haskell (I know there are <a href="http://www.haskell.org/haskellwiki/Sudoku" rel="nofollow">loads of good solutions already</a>) and I'd like some reviews from you experts.</p>
<p>The solver is very simple and it uses the List monad to try all the possible ... | [] | [
{
"body": "<p>The <code>set</code> operation would be slightly faster using <code>splitAt</code> instead of <code>take</code> and <code>drop</code>. Other than that I don't see obvious problems (which doesn't mean much).</p>\n\n<p>I guess other data structures could help a lot (e.g. I think some vector implemen... | {
"AcceptedAnswerId": "9294",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T18:19:05.603",
"Id": "9281",
"Score": "2",
"Tags": [
"haskell",
"sudoku"
],
"Title": "Sudoku solver in Haskell"
} | 9281 |
<p>I would like to optimise this code. It seems a bit verbose, particularly with the 'elseif' that doesn't do anything.</p>
<p>This code either:</p>
<ul>
<li>takes a plain text password, generates a salt, and returns them both OR</li>
<li>takes a plain text password and a salt with which to encrypt the password, and ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T18:18:11.957",
"Id": "14576",
"Score": "0",
"body": "If you want to get rid of that empty `elseif`, just change it to `strlen($salt) != 64` and put the `else` code in the `elseif` block."
},
{
"ContentLicense": "CC BY-SA 3.0... | [
{
"body": "<p>How about the following:</p>\n\n<pre><code>if (!$salt) {\n $salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));\n} elseif (strlen($salt) !== 64) {\n log_message('info', 'Supplied password to process_password() was not the correct 64-byte length.');\n return false;\n}\n// if we're h... | {
"AcceptedAnswerId": "9283",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T18:15:20.303",
"Id": "9282",
"Score": "4",
"Tags": [
"php",
"authentication",
"codeigniter"
],
"Title": "SHA256 password hash generation and verification"
} | 9282 |
<blockquote>
<p><strong><em>K&R</em> 1.9 exercise:</strong></p>
<p>Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.</p>
</blockquote>
<p>Is this correct and proper code? Could I have put <code>c</code> and <code>inspace</code> on a single line?<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-01T09:08:15.253",
"Id": "15150",
"Score": "0",
"body": "What is your operating system? How do you launch your program? On unix-like operating systems, one way to do it is to type this in a terminal (without the $): $ `echo \"a really ... | [
{
"body": "<p>Looks fine to me. But I would replace </p>\n\n<pre><code>if (inspace == 0)\n</code></pre>\n\n<p>with</p>\n\n<pre><code>if (!inspace)\n</code></pre>\n\n<p>for stylistic reasons. And</p>\n\n<pre><code>if (c != ' ')\n</code></pre>\n\n<p>with</p>\n\n<pre><code>else \n</code></pre>\n\n<p>because there... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T19:49:37.467",
"Id": "9287",
"Score": "7",
"Tags": [
"beginner",
"c",
"strings"
],
"Title": "Replacing each string of one or more blanks by a single blank"
} | 9287 |
<p>I came up with this question. </p>
<blockquote>
<p>Let A and B be two N bit numbers. You are given initial values for A and B, and you should write a program which processes three kinds of queries:</p>
<p>set_a idx x: Set A[idx] to x, where 0 <= idx < N (where A[idx] is idx'th least significant bit of... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T12:49:48.707",
"Id": "14583",
"Score": "1",
"body": "your result needs some refactoring if you want other to read it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T21:31:16.293",
"Id": "14584",
... | [
{
"body": "<p>Don't use arrays as representation for binary numbers. <code>BitSet</code> could save you a lot of work.</p>\n\n<p>Except from that, your code is very repetitive. An example:</p>\n\n<pre><code> if ((A[idx] == '0' && B[idx] == '1') || (A[idx] == '1' && B[idx] == '0')) {\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T12:46:40.030",
"Id": "9289",
"Score": "2",
"Tags": [
"java",
"algorithm",
"contest-problem"
],
"Title": "Changing bits in given big strings"
} | 9289 |
<p>This is a solution I wrote for a programming puzzle which I believe and I'm sure is correct, but for two of their test cases the online judge gives me 'Time Limit Exceeded' only by a few 100ms! I've tried a lot to knock those few ms out, but no luck.</p>
<p>For a time limit of 3s I've submitted solutions which ran ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T05:35:28.857",
"Id": "14606",
"Score": "0",
"body": "Leave cin and cout. Instead use read and write."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T16:06:34.073",
"Id": "14679",
"Score": "2",... | [
{
"body": "<ol>\n<li><p>Some low-hanging fruit in the NChooseK_Sum code:</p>\n\n<p>Initialize two vectors up-front to a full allocation of N elements to avoid resizing overhead.</p>\n\n<p>Don't call <code>clear</code> -- instead, just use <code>V[0] = 1;</code> <code>V[j] = ...;</code> <code>V[i] = 1;</code> in... | {
"AcceptedAnswerId": "9303",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T22:17:13.930",
"Id": "9293",
"Score": "3",
"Tags": [
"c++",
"time-limit-exceeded"
],
"Title": "Mathematical programming puzzles"
} | 9293 |
<p>I am working on a fluent interface for exception handling.
Here's how it looks :</p>
<pre><code>On<NullReferenceException>()
.First.LogTo("errors")
.Then.TranslateTo("null object");
On<FileNotFoundException>()
.First.Translate(excp... | [] | [
{
"body": "<p>I would remove the First and Then methods and just execute actions in the order they are declared.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T23:30:40.727",
"Id": "14597",
"Score": "0",
"body": "I wanted t... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T22:41:43.067",
"Id": "9296",
"Score": "1",
"Tags": [
"c#"
],
"Title": "How to improve this fluent interface?"
} | 9296 |
<p>I have got code here which I have tried to refactor on my own - but do any of you experts feel that it needs to be refactored more? What are the points should I cover? I would appreciate it if some one gives me some points on this code review.</p>
<pre><code>package com.vilant.app.outbound;
import java.util.ArrayL... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T23:40:40.903",
"Id": "14598",
"Score": "2",
"body": "If it looks like this after refactoring I wonder what it looked like before :))"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T14:07:59.207",
... | [
{
"body": "<p>First , It seems that this code violates Single Responsibility Principle and it way too long to do just a single task .If that's the case maybe you can introduce new small classes that assist this class in doing its task.\nSecond , I can see signs of DRY here and there specially in performDbCheck ... | {
"AcceptedAnswerId": "9300",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T22:42:09.190",
"Id": "9297",
"Score": "3",
"Tags": [
"java"
],
"Title": "Is the code properly refactored or still some more improvements needs to be done?"
} | 9297 |
<p>I'd like to know if I'm doing this properly. Basically, I have 3 models: <code>Student</code>, <code>Course</code>, <code>StudentCourse</code>. I'm running into problems when I'm trying to sign a student up for a course (I've removed a lot of the non-important code - auth component, view, etc). </p>
<pre><code>// C... | [] | [
{
"body": "<p>To me your code and relations looks good! You removed the redundancy in your database by splitting the tables up. Your cake really looks cakes way to me!</p>\n\n<p>Just make sure you actually do something with the exception thrown and it should be all good.</p>\n\n<hr>\n\n<p><strong>Edit :</strong... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T02:01:03.130",
"Id": "9304",
"Score": "2",
"Tags": [
"php",
"cakephp"
],
"Title": "Using CakePHP models/controllers properly"
} | 9304 |
<p>There are many problems on the Internet that require you to find prime numbers, so I decided to write a set of functions to find them. I used the Sieve of Eratosthenes for generating the primes as it was fast and easy to implement compared to other algorithms.</p>
<p>However, I'm wondering if my code, rather than m... | [] | [
{
"body": "<p>I take it you are really hell bent to use STL for everything but maybe you are over using it. However your code as it is, is very redundant. The specific issue I found are:</p>\n\n<ol>\n<li>Whenever you call <code>isPrime()</code>, you are generating the <code>primes</code> array inside <code>gene... | {
"AcceptedAnswerId": "9309",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T03:39:36.700",
"Id": "9306",
"Score": "6",
"Tags": [
"c++",
"performance",
"primes",
"sieve-of-eratosthenes"
],
"Title": "Generating primes with Sieve of Eratosthenes"
} | 9306 |
<p>In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.</p>
<p>A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T09:20:13.897",
"Id": "9310",
"Score": "0",
"Tags": null,
"Title": null
} | 9310 |
Design in programming is the act of making particular choices about how best to structure a program, to achieve goals of reliability, maintainability, correctness or ease of use. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T09:20:13.897",
"Id": "9311",
"Score": "0",
"Tags": null,
"Title": null
} | 9311 |
<p>New dedicated Mathematica SE site: <a href="http://mathematica.stackexchange.com/">http://mathematica.stackexchange.com/</a></p>
<p><a href="http://www.wolfram.com/mathematica/" rel="nofollow">Wolfram Mathematica</a> is a computer algebra system and programming language from Wolfram Research. The programming langu... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T09:23:12.067",
"Id": "9312",
"Score": "0",
"Tags": null,
"Title": null
} | 9312 |
Computer algebra system and term-rewriting functional programming language from Wolfram Research. Not to be confused with "mathematics". New dedicated Mathematica SE site: http://mathematica.stackexchange.com/ | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T09:23:12.067",
"Id": "9313",
"Score": "0",
"Tags": null,
"Title": null
} | 9313 |
<p>A Graphical User Interface is any kind of visual interface which is capable of displaying more than just fixed-width text. GUIs can display information in the form of images and other abstract graphics, and present interactive controls such as buttons, menus, icons and windows.</p>
<p>There's now a Stack Exchange ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T09:24:42.703",
"Id": "9314",
"Score": "0",
"Tags": null,
"Title": null
} | 9314 |
Graphical User Interface development for applications or web sites. This tag should usually be combined with other tags specifying the programming language, platform or framework, if applicable. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T09:24:42.703",
"Id": "9315",
"Score": "0",
"Tags": null,
"Title": null
} | 9315 |
<p>I've decided to write a small function for rounding decimals because it'll most likely be useful later on. However, my current attempt seems pretty inefficient. How would one best optimize such a function?</p>
<pre><code>#include <cmath>
double getRemainder(double a, double b)
{
int quotient = (int)(a/b)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T18:31:26.227",
"Id": "14699",
"Score": "3",
"body": "Because of the way floating point numbers are stored rounding to the nearest decimal does not work that well (as some numbers just can not be represented so you may think you have... | [
{
"body": "<p>I agree with the comments implying that floating-point shouldn't be used with money due to issues with precision. Nonetheless, I'll point out some general flaws I've found in your code.</p>\n\n<ul>\n<li><p>There should be a <code>std::</code> in front of <code>pow(10.0, pos)</code> since you're n... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T15:52:09.797",
"Id": "9324",
"Score": "6",
"Tags": [
"c++",
"optimization",
"floating-point"
],
"Title": "Rounding decimals"
} | 9324 |
<p>I have a couple of nested objects, where A is always a part of B.</p>
<p>May I use the following code to access owner's properties and methods?</p>
<pre><code>function A( owner ) {
this.value = function () { return owner.value() + 1 };
}
function B() {
this.value = function () { return 1; };
this.a = new A(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T12:09:06.603",
"Id": "62814",
"Score": "0",
"body": "That's fine, at least from the implementation standpoint. Do you have any specific concerns about this approach?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<blockquote>\n <p>Actually, it works. But I would like to know whether it is correct or\n not.</p>\n</blockquote>\n\n<p>It works because you create new instance of parent and access it there:</p>\n\n<pre><code>this.a = new A( this );\n</code></pre>\n\n<p>The correct way (for inheritence) is to set ... | {
"AcceptedAnswerId": "9329",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T12:05:52.773",
"Id": "9326",
"Score": "2",
"Tags": [
"javascript",
"object-oriented"
],
"Title": "Link to a parent object"
} | 9326 |
<p>Is there any simpler way to find all elements in a list that are equal to the max element.</p>
<pre><code>List v = [ 1,2,3,4,5,5 ]
def max = v.max()
def maxs = v.findAll { it == max }
</code></pre>
<p>Thanks!</p>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T17:41:05.463",
"Id": "14772",
"Score": "2",
"body": "Use an inline method: `v.findAll { it == v.max() }`"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2020-06-10T13:45:20.497",
"Id": "478267",
"Score":... | [
{
"body": "<p>How you've done it for the simple example is exactly how I would do it. I may use <code>groupBy</code> if I was dealing with a more complex object.</p>\n\n<pre><code> List v = [ 1,2,3,4,5,5 ]\n def max = v.max()\n def results = v.groupBy {it}.get(max)\n assert [5,5] == results\n</code... | {
"AcceptedAnswerId": "9332",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T19:03:27.803",
"Id": "9331",
"Score": "5",
"Tags": [
"sorting",
"groovy"
],
"Title": "Groovy: find all elements in a list equal to the max element"
} | 9331 |
<p>I'm building a rails app which uses a has many through relationship between three models. I have a Recipes model and an Ingredients model. The join table is called rec_items and it contains a few additional data fields. So, recipes have_many ingredients through rec_items, and ingredients have_many recipes through re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T03:45:33.327",
"Id": "14727",
"Score": "0",
"body": "Check out this Railscast. It is doing a bit more than you're trying, but there is a working version you can compare with yours. http://railscasts.com/episodes/196-nested-model-for... | [
{
"body": "<p>I think you may want to look at route nesting to achieve what you want.<br>\nI have found that hidden fields often point to a need for a better solution and they are not a good approach themselves.</p>\n\n<p>It can be confusing initially as there are usually two distinct areas to consider.</p>\n\n... | {
"AcceptedAnswerId": "9461",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T20:34:10.740",
"Id": "9333",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails",
"form"
],
"Title": "Please help me improve this Rails 3 nested form code"
} | 9333 |
<p>We have a Debian Squeeze server where we upload files through <a href="http://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol" rel="noreferrer">SFTP</a>, and I wrote this script to automatically compress uploaded files.</p>
<p>The script is scheduled through a cron job in an unprivileged user's crontab.</p>
<p>As... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T12:10:41.047",
"Id": "14739",
"Score": "1",
"body": "Grabbing the extension can be implemented without `awk` using `ext=${filename##*.}`."
}
] | [
{
"body": "<p>Almost all the work you've done can be done by find directly. It's efficient at eliminating based on your parameters, and can pass a tailored list of arguments to bash for final zipping.</p>\n\n<pre><code>#!/bin/bash\n\n# The folder to watch.\ndir=\"/path\"\n\n# You shouldn't ever loop over for x ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T21:53:19.847",
"Id": "9334",
"Score": "6",
"Tags": [
"bash"
],
"Title": "Script to monitor a folder and compress the content"
} | 9334 |
<p>Everything works, i just want to know if i can change the way the xml tags are retreived. This way seems a bit bulky - but i could be wrong. Thoughts?</p>
<pre><code> var d = 0
$(".timeline").children().eq(d).addClass("active")
// default traverse function to buttons, inject node
prev.data("node", ... | [] | [
{
"body": "<ul>\n<li><p>There's a lot of duplication to get <code>src</code>, <code>name</code>, and so on. Simply use <a href=\"http://api.jquery.com/jQuery.map/\" rel=\"nofollow\"><code>$.map</code></a>:</p>\n\n<pre><code>var properties = $.map([\"src\", \"name\", \"date\", \"desc\"], function(id) {\n return... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-22T18:15:40.107",
"Id": "9335",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"html",
"xml"
],
"Title": "How can I make this XML gallery snippet prettier?"
} | 9335 |
<p>Is there any chance to make this script run faster?The script goes through each number from <code>a</code> to <code>b</code>, and checks if it holds 1, if it holds 2, if it holds 3, if it holds 1 and 2, if it holds 1 and 3 and if it holds 1, 2 and 3. Then it saves all results.</p>
<pre><code>unsigned long long a, b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T19:11:39.447",
"Id": "14709",
"Score": "3",
"body": "Lop a couple 0's off the end of `b` and it'd run much faster."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T19:12:37.823",
"Id": "14710",
... | [
{
"body": "<p>You could start by changing your chained <code>if</code>s to <code>switch</code> statements and avoid duplicate <code>%</code> computations:</p>\n\n<pre><code>switch (f % 10) {\n case 1: f1++;\n break;\n case 2: f2++;\n break;\n case 3: f3++;\n break;\n default: //... | {
"AcceptedAnswerId": "9338",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T19:09:43.940",
"Id": "9336",
"Score": "3",
"Tags": [
"c++",
"performance"
],
"Title": "Checking for certain values in a range of numbers"
} | 9336 |
<p>I am trying to solve the puzzle <a href="http://www2.stetson.edu/~efriedma/holiday/2011/index.html" rel="nofollow noreferrer">RINGING IN THE NEW YEAR</a>.</p>
<blockquote>
<p>Start at 2011. By moving through the maze and doing any arithmetic operations you encounter, exit the maze with a result of 2012. You may ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T14:41:26.910",
"Id": "14720",
"Score": "0",
"body": "Isn't this a homework? If it is, you should tag it as such."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T15:12:07.127",
"Id": "14721",
"... | [
{
"body": "<p>I wrote this solution that runs in 0.2 seconds on my computer when compiled. It also does a BFS with memoisation. However, it uses two heuristics: Don't divide by two unless the denominator is 1 and don't go above 10000. A more elegant way would be to use a priority queue that prioritises \"states... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T14:33:05.197",
"Id": "9344",
"Score": "7",
"Tags": [
"haskell",
"graph",
"breadth-first-search"
],
"Title": "\"Ringing in the New Year (2011→ 2012)\" puzzle"
} | 9344 |
<p>I've been learning Python and in order to put my skills to the test, I created a simple program that returns the sum of all of the multiples of number <code>num</code> up to 1000.</p>
<pre><code>def get_multiple_sum(num):
sum = 0
i = 0
for i in range(0, 1001):
if i % num == 0:
sum +=... | [] | [
{
"body": "<p><code>range</code> takes an optional third argument, which is the step size for the sequence. For example:</p>\n\n<pre><code>range(0, 10, 3) # Returns [0, 3, 6, 9]\n</code></pre>\n\n<p>Python also has a built-in <code>sum</code> function that adds up all the numbers in an array, so you could refac... | {
"AcceptedAnswerId": "9348",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-23T23:12:09.153",
"Id": "9347",
"Score": "1",
"Tags": [
"python",
"algorithm",
"performance"
],
"Title": "Returning the sum of all multiples of a number up to 1000"
} | 9347 |
<pre><code>public sealed class LinkXPathRepository : ILinkXPathRepository
{
private static readonly ILog _log = LogManager.GetLogger(typeof(LinkXPathRepository));
internal ILink Parse(Uri endpoint)
{
if (endpoint == null)
{
throw new ArgumentNullException("endpoint");
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T03:41:20.027",
"Id": "14726",
"Score": "2",
"body": "What is this code supposed to do?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T03:49:52.620",
"Id": "14728",
"Score": "0",
"body": "... | [
{
"body": "<p>This <em>should</em> work, though without a working swath of source, I can't say for sure.</p>\n\n<pre><code> foreach (var source in sources)\n {\n var sourcetype = source.GetType();\n var resulttype = result.GetType();\n const BindingFlags BindingFla... | {
"AcceptedAnswerId": "9360",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T02:37:58.840",
"Id": "9350",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Make this C# code more DRY"
} | 9350 |
<p>I am creating an application which needs to validated user input to ensure the words being entered are real words. What improvements if any can I make?</p>
<pre><code>class MyDictionary {
Vector<String> words = new Vector<>();
public MyDictionary() {
URL url;
try {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T22:24:17.783",
"Id": "14798",
"Score": "3",
"body": "You're using `Vector` which is _synchronized_, even though you don't appear to be using it in a threaded context. Beyond that, there's no good way to use a different word list (b... | [
{
"body": "<ol>\n<li>What do you want to do when there are no words? The current solution isn't satisfactory at all. You're simply failing silently, and hasWord will always return false. By the way, if there's an exception in the middle of of the loop, will your file be closed?</li>\n<li>Searching in a <code>Ve... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T12:14:37.947",
"Id": "9362",
"Score": "6",
"Tags": [
"java"
],
"Title": "Dictionary application"
} | 9362 |
<pre><code>public class Item { /*...*/ }
public class Model { /*...*/ }
public interface IConventionInstanceSelector {
IConventionInstance Select(Item item);
}
public interface IConventionInstance {
void ApplyTo(Model model);
}
public interface IConvention {
bool IsMatchedBy(Item item);
IConventionInstance C... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T13:06:46.653",
"Id": "14740",
"Score": "0",
"body": "Do you have some (unit)test code excuting this? Makes it a lot easier to review if one doesn't have to imagine the usage. You also partially answer your own question - specificati... | [
{
"body": "<p>First of all, the combination of a Specification and another method is not that unusual - it's called the <a href=\"http://blogs.msdn.com/b/kcwalina/archive/2005/03/16/396787.aspx\" rel=\"nofollow\">Tester-Doer Pattern</a> (although to be fair, I'm not sure whether it's a bona-fide <em>pattern</em... | {
"AcceptedAnswerId": "9416",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T12:58:39.420",
"Id": "9364",
"Score": "2",
"Tags": [
"c#"
],
"Title": "What would be alternative ways to model IConvention?"
} | 9364 |
<p>As you can see I have to populate the ViewModel with the List of Tags so that the dropdown can have all the options for the user to select.
And I have to do this 2 times for the Create Action and 2 times for the Edit action. </p>
<pre><code>[Authorize]
public ActionResult Create()
{
var tags = from i in _art... | [] | [
{
"body": "<p>You could refactor out your tagging into a helper method, as below:</p>\n\n<pre><code>[Authorize]\npublic ActionResult Create()\n{\n var model = new CreateArticleViewModel {};\n TagModel (model, _ => false);\n return View(model);\n}\n[HttpPost, Authorize]\npublic ActionResult Create(Creat... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T15:37:03.347",
"Id": "9373",
"Score": "1",
"Tags": [
"c#",
"asp.net-mvc-3"
],
"Title": "How can I avoid all this code duplication?"
} | 9373 |
<p>I've re-written my old pagination class into something a little cleaner, and also added PDO support (The prev version was mysqli only). I'd like to clean it up even more if it's possible, does anyone have any pointers?</p>
<p>Here's the class:</p>
<pre><code><?
class paginate
{
/**
* Array of option... | [] | [
{
"body": "<p>I'm not going to do a full code review, but there are a couple of issues that I think need to be addressed. </p>\n\n<p>Everything's public in your class, this is very bad because it means that external agents can scribble all over the class internal state. You should definitely make all your pro... | {
"AcceptedAnswerId": "9415",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T15:47:00.403",
"Id": "9374",
"Score": "1",
"Tags": [
"php",
"pagination"
],
"Title": "PHP/MySQL Pagination Class - How can it be improved?"
} | 9374 |
<p>My disgusting list comprehension in the <code>return</code> statement is quite a headful.</p>
<pre><code>"""Hopefully this function will save you the trip to oocalc/excel.
"""
def rangeth(start, stop=None, skip=1):
"""rangeth([start,] stop[, skip])
returns a list of strings as places in a list (1st, 2nd, etc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T17:55:56.660",
"Id": "14775",
"Score": "0",
"body": "Range - http://docs.python.org/library/functions.html#range. Which version of Python are you using? I'm a novice at python, but one thing I know is that `yield` (http://stackoverf... | [
{
"body": "<p>Firstly, I'd suggest not duplicating the overloading logic of range. Instead:</p>\n\n<pre><code>def rangeth(*args):\n print range(*args)\n</code></pre>\n\n<p>Just take your arguments and pass them onto to range. </p>\n\n<p>Secondly, I'd write a function that takes a single number and produces t... | {
"AcceptedAnswerId": "9382",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T17:04:49.817",
"Id": "9375",
"Score": "1",
"Tags": [
"python"
],
"Title": "Range of ordinal numbers"
} | 9375 |
<p>I have this code:</p>
<pre><code> lengths = []
lengths.append(len(self.download_links))
lengths.append(len(self.case_names))
lengths.append(len(self.case_dates))
lengths.append(len(self.docket_numbers))
lengths.append(len(self.neutral_citations))
lengths.append(len(self.precedential_statu... | [] | [
{
"body": "<p>Firstly, consider whether these shouldn't be <code>None</code>, but instead should be empty lists. Most of the time <code>None</code> is better replaced by something else like an empty list.</p>\n\n<p>If that's not an option, you can use a list:</p>\n\n<pre><code>for item in [self.download_links, ... | {
"AcceptedAnswerId": "9383",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T18:21:34.580",
"Id": "9377",
"Score": "4",
"Tags": [
"python"
],
"Title": "Better way to do multiple try/except in Python"
} | 9377 |
<p>For a while now, our team has been doing peer code reviews of all submissions. As we've learned, everyone has different styles and going forward, all of us see a need to converge at some kind of tribal/team style so that the code looks consistent and we don't spend time in code reviews arguing one style vs. another.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T18:35:53.383",
"Id": "14778",
"Score": "4",
"body": "This is a waste of time. There is being consistent then there is micro management. As long as it is readable and correct. Legislating every single thing is silly and counterproduc... | [
{
"body": "<p>I don't see how wrapping a single identifier into parentheses is ever going to make things clearer. On the other hand, I also don't see myself immediately understanding how <code>a op b ? c : d</code> parses for every possible operator <code>op</code>, or what <code>a && b, c || d</code> ... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T18:32:08.983",
"Id": "9380",
"Score": "6",
"Tags": [
"c++"
],
"Title": "Extra parenthesis in if-clause vs. readability"
} | 9380 |
<p>I am diving deeper into JavaScript and starting to learn more about prototypes and simulating classes etc. I am used to working with the Module pattern and would like to try and combine this pattern along with working with prototyping into an own little framework (purely for learning purposes).</p>
<p>I have devise... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T21:16:02.200",
"Id": "14789",
"Score": "0",
"body": "So, you want the `Version` property to be hard-coded into the `Mui` constructor, yes?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T21:21:07.950"... | [
{
"body": "<p>A singleton is an object which is the only instance of its type. Therefore, it makes most sense to define all non-function properties and methods directly on that singleton:</p>\n\n<pre><code>var singleton = {\n prop1: ...,\n prop2: ...,\n method1: function () { ... },\n method2: funct... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T20:57:12.630",
"Id": "9389",
"Score": "1",
"Tags": [
"javascript",
"singleton"
],
"Title": "JavaScript singleton with methods and properties"
} | 9389 |
<p>I'm trying to get rid of some of the horrible nested loops in the following code.
Essentially is moving TDs to top rows based on whether the current row has the current cell. You can see the execution here:
<a href="http://jsfiddle.net/Jq8sk/" rel="nofollow">http://jsfiddle.net/Jq8sk/</a></p>
<p>How can I clean it... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T21:32:59.650",
"Id": "14791",
"Score": "1",
"body": "Out of curiosity, if you're using jquery, why only use it on the first line?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T21:44:50.993",
"Id... | [
{
"body": "<p>This may not actually be any better as far as performance goes, but I believe it is equivalent to your code (and possibly more readable?).</p>\n\n<p><a href=\"http://jsfiddle.net/Jq8sk/1/\" rel=\"nofollow\">http://jsfiddle.net/Jq8sk/1/</a></p>\n\n<pre><code>var arr = ['n0', 'n1', 'n2'];\n\n$('.trs... | {
"AcceptedAnswerId": "9394",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T21:24:33.273",
"Id": "9390",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Refactoring 3 level depth for loops in JavaScript"
} | 9390 |
<p>I want to refactor this code into js object,
but not sure how. How should I do it?</p>
<p>I initialize an object for every item in the DS.data_per_folder array.
how can I define it in a higher level? Where should I init it then?</p>
<pre><code> ..
DS.data_per_folder[CurrentContextMgr.current.folder.attr('... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T22:59:55.053",
"Id": "14803",
"Score": "0",
"body": "I initialize an object for every item in the DS.data_per_folder array.\nhow can I define it in a higher level? Where should I init it then?"
}
] | [
{
"body": "<p>I would recommend using a constructor function to create the objects:</p>\n\n<pre><code>function FolderData() {\n\n this.allAttachments_vector_counter = 0;\n this.allAttachments_vector = [];\n this.attachment_position_dict = {};\n this.extraDetails_dict = {};\n\n}\n\nFolderData.prototy... | {
"AcceptedAnswerId": "9409",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T21:25:51.663",
"Id": "9391",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "refactoring common behavior to js object"
} | 9391 |
<p>We have a large number of defined constants that are used as enum values when storing records. We convert the int values into language for our web portals. This was very straightforward when only dealing with one language, but now are tasked with making the portals support multiple languages.</p>
<p>The functions d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T21:56:47.383",
"Id": "14838",
"Score": "0",
"body": "You've two typos in your array declaration (`;` instead of `,`)."
}
] | [
{
"body": "<p>In all honesty, that seems a bit redundant... But since you can't change the constant values here it goes:</p>\n\n<pre><code>define('ACTION_ACCOUNT_NEW', 1024);\ndefine('ACTION_ACCOUNT_DELETE', 1025);\n\nfunction ActionToString($action)\n{\n $actions_map = array();\n $defined_constants = get... | {
"AcceptedAnswerId": "9428",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T22:55:24.540",
"Id": "9397",
"Score": "1",
"Tags": [
"php",
"i18n"
],
"Title": "Converting PHP defined constant values to multiple languages"
} | 9397 |
<p>This code is the basic structure I use for coding plugins. It's pretty standard with the settings extended and the each loop. However, now I'm working on the best way to provide setters/getters. For example, I may want to do something like:</p>
<pre><code>var sp = $("#container").wScratchPad();
alert(sp.wScratchP... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T20:02:22.313",
"Id": "217586",
"Score": "0",
"body": "This is exactly what the [jQuery Ui Widget Factory](http://wiki.jqueryui.com/w/page/12138135/Widget%20factory) is for. It is awesome, you should use it even if you don't use anyt... | [
{
"body": "<p>The only issue I see is with this:</p>\n\n<pre><code>else if(defaultSettings[option])\n</code></pre>\n\n<p>If you have any boolean options or numeric options which are set to 0, this will evaluate to false and the code within the <code>if</code> will not execute. </p>\n\n<p>Perhaps use <code>type... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T02:23:47.690",
"Id": "9403",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "Setup options for a jQuery plugin"
} | 9403 |
<p>I am working on a log in form. Basically, my code searches for a user name, then retrieves the hashed password that is related to that account. It then converts that string hashed password then converts it to its real value. But my issue here is that it is messy.</p>
<pre><code> private void userVerification() {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T04:20:15.233",
"Id": "14814",
"Score": "0",
"body": "A small note is I would always use .Any() when doing Count() != 0 > 0 etc comparisons. I would also probably look at putting the var password inside the if statement closer to it... | [
{
"body": "<p>Perhaps something like this. I put in some pre data entry validation but you might not need this dependant on where it is done in the application. </p>\n\n<p>The main thing I would do is remove the MessageBox from this method and do that elsewhere. That way you could at least do some unit testi... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T03:41:55.237",
"Id": "9404",
"Score": "3",
"Tags": [
"c#",
".net",
"sql",
"linq"
],
"Title": "Retrieving a user's password for verification"
} | 9404 |
<p>I'm newly working with CodeIgniter and PHP. I wrote a category structured 'pages' code with listing pages as multilevel list or indented select box.</p>
<pre><code>page page_lang
------------------------------------- ----------------------------
id_page | id_menu | id_pa... | [] | [
{
"body": "<p>How slow is it? Did you measure it? Do you have a lot of nodes? A performant way to store hierarchies in databases is the <a href=\"http://en.wikipedia.org/wiki/Nested_set_model\" rel=\"nofollow\">nested set model</a>.</p>\n\n<p>Also, why are you doing rendering in the model? Did you read CodeIgni... | {
"AcceptedAnswerId": "9609",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T09:07:37.590",
"Id": "9407",
"Score": "3",
"Tags": [
"php",
"mysql",
"array",
"codeigniter"
],
"Title": "Mutlilevel page list in CodeIgniter"
} | 9407 |
<p>I have a text file in a specific format that I pass as the input of my program. I then want to write the output back to that same file. The format is as follows:</p>
<pre><code>Input1:
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
-----------------------------------------
Input2:
1 2 3 8 5 6 7
1 2 3 9 5 6 7
1 2 3... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T11:30:11.393",
"Id": "14983",
"Score": "0",
"body": "Are you looking for code review, or diagnostic help?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T15:11:53.100",
"Id": "14994",
"Score":... | [
{
"body": "<p>First and foremost, fix your formatting. A little bit of effort spent on making the code readable will mean that it can be understood (and thus reviewed) faster. By the way, you are <a href=\"https://stackoverflow.com/q/5205491/559931\">not using the STL</a>.</p>\n\n<p>Now, significant issues in... | {
"AcceptedAnswerId": "9414",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T10:04:50.717",
"Id": "9410",
"Score": "2",
"Tags": [
"c++"
],
"Title": "Inserting strings in middle of a text file using streams"
} | 9410 |
<p>I'm shooting blind when it comes to coding I'm reading and coding a lot but no one ever looks at my code so it wold be good if someone could look over the project at github and see if I have any major design issues or other bad practice issues that I must work on.</p>
<p>The Github project is here: <a href="https:/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T20:56:50.527",
"Id": "14833",
"Score": "0",
"body": "A) Run StyleCop on all your non-designer code. B) Do not re-create objects that are meant to be reused."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-0... | [
{
"body": "<p>One thing that comes to my mind by a quick look, is to use <a href=\"http://msdn.microsoft.com/en-us/library/yh598w02.aspx\" rel=\"nofollow\">using statement</a> around disposable objects (for example Graphics,Pen,...)</p>\n\n<p>I mean :</p>\n\n<pre><code>using(var graphics=Grapihcs.FromImage(...)... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T11:11:15.690",
"Id": "9411",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Does my drawing tool have design issues?"
} | 9411 |
<p>I've made a little function to eliminate continuous duplicate from a <code>std::vector</code>. I have to use C++03.</p>
<p>For example, if a vector of ints is composed of: 1,1,2,3,,3,1,1,2 my function should return 1,2,3,1,2. I've tried to use templates (I've just began to use c++) and made it as fast as possible!<... | [] | [
{
"body": "<p>Let's go through mechanical errors:</p>\n\n<ol>\n<li><p>use <code>size_t</code> instead of <code>int</code></p>\n\n<pre><code>int length = vec.size();\n</code></pre></li>\n<li><p>what if there is no zero element?</p>\n\n<pre><code>result[0] = vec[0];\n</code></pre></li>\n<li><p>the same as first:<... | {
"AcceptedAnswerId": "9422",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-02-25T13:35:52.793",
"Id": "9417",
"Score": "0",
"Tags": [
"c++",
"vectors",
"c++03"
],
"Title": "Remove continuous duplicate"
} | 9417 |
<p>The puzzle is:</p>
<blockquote>
<ol>
<li>The deck contains 21 unique numbers</li>
<li>The numbers should be laid up in rows of 7 (3 rows in total)</li>
<li>ask the player to memorize a number to start the game</li>
<li>once the game starts, rearrange the numbers in random in all rows.</li>
<li>ask the p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T22:43:08.623",
"Id": "15031",
"Score": "0",
"body": "This is a minor point, but don't use `define` to set constants. You should instead use something like `const int NUM_ROWS = 3;` which provides type safety."
},
{
"ContentL... | [
{
"body": "<p>Your <code>random_rearrange_num</code> function has a bias. If you want an equal chance of getting every permutation, implement something like the Fisher-Yates shuffle. Your implementation is actually a common implementation error. You can read about it <a href=\"http://en.wikipedia.org/wiki/Fi... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T13:57:41.087",
"Id": "9419",
"Score": "3",
"Tags": [
"c",
"homework"
],
"Title": "Programming of 3 x 7 trick"
} | 9419 |
<p>This is a function that reads until <code>EOF</code> and reallocs as it goes.</p>
<pre><code>char *
read_to_end(int fd, int *bread)
{
ssize_t size, nread, rc;
char *buf, *tmp;
nread = 0;
size = MINLEN;
buf = malloc(size);
while ((rc = read(fd, buf + nread, size - nread))) {
if (rc ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T21:33:38.173",
"Id": "14837",
"Score": "0",
"body": "You can use fseek() and ftell() to get the size if this is a file."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T21:23:37.760",
"Id": "15928"... | [
{
"body": "<p>I would refrain of using GOTO in pure C code. It's not very common...</p>\n\n<p>Also, when you return the buf pointer to the calling function, that function is going to need to actively manage that piece of memory (It becomes in charge of the \"free\"-ing process). </p>\n",
"comments": [
... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T15:15:21.023",
"Id": "9421",
"Score": "3",
"Tags": [
"c",
"strings",
"memory-management"
],
"Title": "Read until EOF and realloc as needed"
} | 9421 |
<h2>Subject</h2>
<p>I have to iterate through a collection of objects (in this case <code>IGrouping<string, SupplyDemand></code>). So I could do this easyly using a query with LINQ.</p>
<h2>Code</h2>
<pre><code> public IEnumerable<string> getParentPegs(IGrouping<string, SupplyDemand> data)
{... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T16:11:45.707",
"Id": "14934",
"Score": "1",
"body": "How are you using the getParentPegs method? The original code returns a lazily evaluated expression and not an actual collection, so if in your code you do this:\n\n`var pegs = ge... | [
{
"body": "<p>how about this :</p>\n\n<pre><code> public IEnumerable<string> GetParentPegs(IGrouping<string, SupplyDemand> data)\n {\n foreach(var d in data)\n if(d.Source.ToLower() == \"make\") yield return d.Part;\n\n }\n</code></pre>\n",
"comments": [
{
... | {
"AcceptedAnswerId": "9432",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T22:17:54.910",
"Id": "9429",
"Score": "3",
"Tags": [
"c#",
"linq"
],
"Title": "Iterating through a collection of objects"
} | 9429 |
<p><code>boost::thread_group</code> doesn't automatically clean up contained threads when they end, so I needed something like that described in <a href="http://boost.2283326.n4.nabble.com/thread-group-removal-of-items-tp2585545p2585546.html" rel="nofollow noreferrer">this <code>boost-users</code> list post</a>. Howeve... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T00:21:37.293",
"Id": "14844",
"Score": "0",
"body": "**Note:** Yes, I'm aware that thread pools are \"better\" in a lot of cases. But I do want to be able to just create and destroy threads at will."
},
{
"ContentLicense": "... | [
{
"body": "<p>I think you have <strong>UB</strong> here: <code>mutex::unlock()</code> must only be called (1) if the <code>mutex</code> is presently locked and (2) by the same thread that <code>lock()</code>ed it in the first place (i.e. <em>if the calling thread owns the mutex</em>). Anything else is UB (at le... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T00:20:24.003",
"Id": "9431",
"Score": "7",
"Tags": [
"c++",
"multithreading",
"thread-safety"
],
"Title": "Have I thought of everything in this wrapper around boost::thread_group?... | 9431 |
<p>How could I improve the following code that runs a simple linear regression using matrix algebra? I import a .csv file (<a href="https://docs.google.com/open?id=0B0iAUHM7ljQ1dDM3UVJWaGZRZlNoNnFyZ3h1ekpydw" rel="nofollow noreferrer">link here</a>) called 'cdd.ny.csv', and perform the matrix calculations that <a href... | [] | [
{
"body": "<pre><code>import numpy\nfrom numpy import *\nimport csv\n\ndf1 = csv.reader(open('cdd.ny.csv', 'rb'),delimiter=',')\ntmp = list(df1)\nb = numpy.array(tmp).astype('string')\nb1 = b[1:,3:5]\nb2 = numpy.array(b1).astype('float')\n</code></pre>\n\n<p>Firstly, I'd avoid all these abbreviated variables. I... | {
"AcceptedAnswerId": "9435",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T00:49:27.857",
"Id": "9433",
"Score": "1",
"Tags": [
"python",
"numpy"
],
"Title": "Linear Regression and data manipulation"
} | 9433 |
<p>I am nearly done developing my pong game (made in HTML5 / JavaScript), and I would like some constructive criticism on my code.</p>
<p><a href="http://code.google.com/p/pong-redux/source/browse/#git%2Fjs" rel="nofollow">Full code</a></p>
<p><strong>Initialization:</strong></p>
<pre><code>var play2 = false;
funct... | [] | [
{
"body": "<p>Your application should be defined in a scope.</p>\n\n<p>like </p>\n\n<p><code>PingPong = {}; PingPong.calculateAI= function(){...}</code></p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T01:46:55.617",
"Id": "14970",
"... | {
"AcceptedAnswerId": "9507",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T02:20:58.740",
"Id": "9434",
"Score": "2",
"Tags": [
"javascript",
"beginner",
"jquery",
"game",
"html5"
],
"Title": "HTML5 / JavaScript Pong game"
} | 9434 |
<p>I'm attempting to make a nice-looking UI where a user views current items in a list and can add/edit/delete. </p>
<p>For each item, i've included an edit and delete link, but I'm trying to do so in such a way as to gracefully degrade/progressively enhance:</p>
<pre><code><li>My Course Name
<div class="... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T19:16:37.633",
"Id": "14880",
"Score": "0",
"body": "One thing to note is that you have a block-level element (`div`) within an inline element (`li`), which is considered a no-no."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>I believe this is more trouble than it is worth. You may be shooting yourself in the foot since your complicated solution might not work as you expect for the different configurations you want to support. Designing for accessibility is not only \"turn off CSS and JS and see how it works out\", but... | {
"AcceptedAnswerId": "9473",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T04:12:16.343",
"Id": "9436",
"Score": "2",
"Tags": [
"html",
"css"
],
"Title": "Can I improve this progressive enhancement?"
} | 9436 |
<p>This is the program I was given, it searches a large array for a max value:</p>
<pre><code>import java.util.Date;
import java.util.Random;
class FindMax {
private static final int N = 256 * 1024 * 1024;
public static void main(String args[]) {
assert(N > 0);
int array[] = new int [N];
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T22:23:48.817",
"Id": "14849",
"Score": "1",
"body": "Why should it increase speed? Unless the threads are run on different processors that is?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T22:25:05.... | [
{
"body": "<p>Contrary to your belief, running a program with more threads than the number of processors (<a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#availableProcessors%28%29\"><code>Runtime.getRuntime().availableProcessors()</code></a>) will not increase the performance of your p... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T22:18:29.440",
"Id": "9437",
"Score": "1",
"Tags": [
"java",
"multithreading"
],
"Title": "why does this programs speed not increase?"
} | 9437 |
<p>Q: Please comment on the usage of structures and structure assignment operations in C</p>
<p>I am working on converting a MATLAB program to C using BLAS and LAPACK for linear algebra support. The MATLAB code uses cell arrays. I created a Matrix datatype and a Cell data-type.</p>
<p>A section of the header file/imp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T16:43:49.837",
"Id": "14936",
"Score": "0",
"body": "Okay. This is sorted now. The valgrind profile is hosted here: I get the Conditional Jump ... error when I do a plain alloc (not zeroing out the array) and no errors when the arra... | [
{
"body": "<h2>About your valgrind issue</h2>\n\n<p>I don't think the valgrind warning is about uninitialized fields in Matrix. Your <code>zeros</code> functions does the initialization, right? I tested myself with this code:</p>\n\n<pre><code>Matrix zeros(int rows, int cols) {\n Matrix tmp;\n int i;\n\n ... | {
"AcceptedAnswerId": "9474",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T05:56:29.870",
"Id": "9439",
"Score": "3",
"Tags": [
"c",
"memory-management",
"matlab"
],
"Title": "Is this a valid usage of structure assignment in C?"
} | 9439 |
<p>I have the following C++ function which I'd like to speed up, if possible. This program will have many different users, so parallelization is not really an option.</p>
<p>The C++ function is wrapped by C code and then called from R, using:</p>
<pre><code>R CMD SHLIB -o jonckterp.so wrapper.cpp inside.cpp
</code></... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T20:04:27.173",
"Id": "14856",
"Score": "6",
"body": "Use some profiling tools to find out where the most CPU is being used. Once you have found out that you can concentrate on that part of the code."
},
{
"ContentLicense": "... | [
{
"body": "<p>I didn't read in it's entirity, but change this line</p>\n\n<pre><code>static int mannwhit(std::vector<int> c, std::vector<int> sizes)\n</code></pre>\n\n<p>to</p>\n\n<pre><code>static int mannwhit(const std::vector<int>& c, \n const std::vector<int>&a... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-25T20:01:14.273",
"Id": "9440",
"Score": "1",
"Tags": [
"c++",
"performance",
"r"
],
"Title": "Computing the distribution of a Jonckheere-Terpstra statistic"
} | 9440 |
<p>I tried extending ForwardingMap because I wanted to intercept all calls to put/putAll/remove/clear and also intercept calls on Iterators of KeySet/EntrySet/Values such as remove/Map.Entry.setValue() etc.</p>
<p>It took me a while to figure out what methods to override and how - especially the entrySet() method. Som... | [] | [
{
"body": "<p>Co-author of <code>ForwardingMap</code> here. (You should probably be using <code>codereview.stackexchange.com</code>, FYI.) Suggestions for how to improve the <code>standardXXX</code> Javadocs would be appreciated, by the way.</p>\n\n<p>First off, not using generics is a <em>bad plan</em>. Ser... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-24T19:59:05.677",
"Id": "9442",
"Score": "1",
"Tags": [
"java"
],
"Title": "How do you intercept all put/remove/modify calls to a Map using a ForwardingMap?"
} | 9442 |
<p>I wrote up the following script for the realtime synchronization service, <a href="https://code.google.com/p/google-mobwrite/" rel="nofollow">MobWrite</a>, to be used with the browser-based editor, <a href="http://codemirror.net/" rel="nofollow">CodeMirror</a>:</p>
<pre><code>// Based on MobWrite's code for TextBox... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>You should remove commented out code</li>\n<li>both <code>linech2n</code> and <code>n2linech</code> could use better naming of the function and variables, and a line of comment.</li>\n<li>one liner <code>if</code> statements like <code>if(!\"id\" in cmObj) cmO... | {
"AcceptedAnswerId": "40861",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T07:27:17.487",
"Id": "9444",
"Score": "3",
"Tags": [
"javascript",
"sync"
],
"Title": "Realtime collaborative editor: a CodeMirror extension for MobWrite"
} | 9444 |
<p><strong>Context</strong></p>
<p>I have a project which has an importation module to import content of Excel files. </p>
<p>Originally, importation was possible only for .xls file (< 2003) through Interop assemblies through a pretty ugly non-modular <em>architecture</em>. But there was a need to support impor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T10:45:24.723",
"Id": "14868",
"Score": "1",
"body": "does implementing data importer for Json and XML files are really necessary ? Please be cautioned not to over refactor your code to achieve YAGNI."
},
{
"ContentLicense": ... | [
{
"body": "<p>Since there should be a relation between your importer data reader and data accessor ( importer should know how to use data accessor to access data.) I suggest that you use generics to achieve such coherence.(Since each importer needs its unique data then IDataAccessors can't be replaced by each o... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T10:12:16.300",
"Id": "9445",
"Score": "0",
"Tags": [
"c#"
],
"Title": "Building a modular data reader system"
} | 9445 |
<p>I use 3 lists to store field name, its value and score. If field name is already added to according list, then I just need to update other 2 lists. If it is not there, then I need to add it. I do the following:</p>
<pre><code>user = User.get_by_key_name(user_key_name)
if user:
field_names = user.field_names
... | [] | [
{
"body": "<pre><code>user = User.get_by_key_name(user_key_name)\nif user:\n</code></pre>\n\n<p>Python convention is to use <code>user is None</code> when checking against <code>None</code></p>\n\n<pre><code> field_names = user.field_names\n field_values = user.field_values\n field_scores = user.field_... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T19:14:11.240",
"Id": "9448",
"Score": "1",
"Tags": [
"python",
"google-app-engine"
],
"Title": "How to verify if value already added to the list and if so, then update the value?"
} | 9448 |
<p>I am trying to make a page background for my website. Is this a good way to do it?</p>
<p>This is my <strong>HTML</strong>:</p>
<pre><code><div id="page-background">
<img src="images/website/background.jpg" width="100%" height="100%" alt="Wallpaper" />
</div>
</code></pre>
<p>And this is my ... | [] | [
{
"body": "<p>The first small comment is that there's no need to put this extra <code>div</code> tag. Simply apply the <code>page-background</code> id to your <code>img</code> tag. It's still nice that you put it in the HTML code.</p>\n\n<p>The other two issues are image ratio (do you want it to be preserved?) ... | {
"AcceptedAnswerId": "9465",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T19:47:22.900",
"Id": "9449",
"Score": "6",
"Tags": [
"html",
"css"
],
"Title": "Full-page background in HTML"
} | 9449 |
<p>I use this method to extract table name and field name from formula.</p>
<pre><code>public List<string> ExtractFieldsFromFormula(string formula)
{
List<string> formulas = new List<string>();
formulas.AddRange(formula.Split(new char[] {'{', '}'}).Where(f=>!f.Contains("+") && !f.C... | [] | [
{
"body": "<p>This should a) make it a bit more compact and b) be a bit faster.</p>\n\n<pre><code> private static readonly char[] splitChars = new[] { '{', '}' };\n\n private static readonly char[] charsToExclude = new[] { '+', '-', '/', '*', '(', ')' };\n\n public static List<string> ExtractFiel... | {
"AcceptedAnswerId": "9453",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T19:53:05.933",
"Id": "9450",
"Score": "2",
"Tags": [
"c#",
"linq"
],
"Title": "Contains method in lambda expression"
} | 9450 |
<p>I'm coding a jQuery plugin that basically checks if a set of checkboxes groups have at least <code>x</code> options checked. A checkbox group is named as <code>name=group[]</code>. You'd call the plugin like:</p>
<pre><code>$(':checkbox').checkpass({min: 1}) // Make sure at least one checkbox per group is checked
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T00:29:56.550",
"Id": "14883",
"Score": "0",
"body": "FYI: `shorted !== faster`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T00:39:49.133",
"Id": "14885",
"Score": "0",
"body": "Well, in... | [
{
"body": "<p>Instead of using an array for <code>names</code>, you could use some implementation of a set, which automatically skips duplications; see <a href=\"http://community.service-now.com/blog/slightlyloony/4113\" rel=\"nofollow\">here</a>.</p>\n\n<p>Instead of keeping the <code>num</code> variable, I wo... | {
"AcceptedAnswerId": "9459",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T23:24:50.617",
"Id": "9455",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"performance"
],
"Title": "Checking if a set of checkboxes have a certain number of options checked"... | 9455 |
<p>I've got this MVC pager helper and it's working exactly as expected. Is there a prettier or more performant way to build this out?</p>
<p>Also, I know that the StringBuilder might not be the best way. Would a <code>TagBuilder</code> be a better approach?</p>
<pre class="lang-vb prettyprint-override"><code><Exte... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T14:38:36.893",
"Id": "15080",
"Score": "0",
"body": "I would not worry about performance. There's no way this code runs often enough to be a problem. The general rule-of-thumb is don't worry about performance until you start having ... | [
{
"body": "<p>How about something like this?</p>\n\n<pre><code>// Put this in its own class so that you can have private methods without being confused with your other HtmlHelpers\npublic class PagerGenerator {\n //extension method hook so this gets added to HtmlHelper\n public static MvcHtmlString Pager(... | {
"AcceptedAnswerId": "9558",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T23:36:55.903",
"Id": "9456",
"Score": "1",
"Tags": [
"vb.net",
"asp.net-mvc-3",
"pagination"
],
"Title": "MVC pager helper"
} | 9456 |
<p>Just after a bit of feed back or peoples ideas on which practice is best. </p>
<p>I currently have a method but am unsure of the best way to approach it from a readability point of view or even from best practices point of view. Or perhaps it doesn't really matter at all and they are all fine?</p>
<p>My three op... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T00:42:35.567",
"Id": "14886",
"Score": "1",
"body": "For compactness, I would use the third method, but for clarity, I would probably use the second one. Plus, I personally like queries over the function call chains for readability.... | [
{
"body": "<p>I would go with the third, with the second as secondary choice.</p>\n\n<p>The first mixes addition logic and comparison logic: it's not immediately clear that the zero is meant to exclude those objects, as opposed to giving a default for <code>object.Area</code>.</p>\n\n<p>The second is better, bu... | {
"AcceptedAnswerId": "9460",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T23:38:47.240",
"Id": "9457",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Inline Sum() vs query Sum() vs Where on a List<T> object"
} | 9457 |
<p>Are there alternative (better) ways to factor out the common parts other than my use of abstract base class? I find myself following this pattern lately and it makes sense when I code it but sometimes leads to code that is particularly susceptible to obfuscation as time goes by (i.e. I come back to it later and hav... | [] | [
{
"body": "<p>This bit is a little too much to digest:</p>\n\n<blockquote>\n<pre><code>this.Controls.Add(new Xml {\n DocumentContent = new XElement(\"keys\",\n from key in this.Keys\n select new XElement(\"key\",\n n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T05:58:03.003",
"Id": "9463",
"Score": "5",
"Tags": [
"c#",
"asp.net",
"xslt"
],
"Title": "Controls to dump key/value pairs"
} | 9463 |
<p>I am trying to figure out how to DRY up this code:</p>
<pre><code>nino = "QQ"
3.times { nino += Random.rand(10..99).to_s}
nino += ("A".."D").to_a.sample
</code></pre>
<p>I am trying to generate a sample National Insurance number starting with QQ, six digits and then ending with A, B, C or D.</p>
| [] | [
{
"body": "<p>Disclaimer: I don't know Ruby but code in similar languages.</p>\n\n<p>This looks \"dried\" enough to me. What would enhance readability though is to write this one simple line. It would show in a very explicit way that you are simply building one string (and would also make this shorter). Is it p... | {
"AcceptedAnswerId": "9472",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T06:22:40.743",
"Id": "9464",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "National Insurance number generator"
} | 9464 |
<p>I instantiate GtkInfobars a lot in my GTK+ application in order to communicate with the user. There are various types of infobars, depending on the message. Basically, any infobar could be a combination of the 4 different infobar message types and 5 different icons (which are painted on the left side of the infobar)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T15:33:30.807",
"Id": "14927",
"Score": "0",
"body": "What do you think you've saved by doing this? I.e. to your mind, what's the purpose of being concise?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-... | [
{
"body": "<p>It's less readable. You made two surprising changes:</p>\n\n<ul>\n<li>switching from a constant to an integer: this really impairs readability: you cannot know what it means without looking it up. You only save a few characters, not even a line or so.</li>\n<li>switching from two parameters to a t... | {
"AcceptedAnswerId": "9502",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T09:25:02.863",
"Id": "9471",
"Score": "3",
"Tags": [
"python",
"gtk"
],
"Title": "GtkInfobars for a GTK+ application"
} | 9471 |
<p>I have a function that works with a database. If something wrong happens I want to throw an exception, and I also want that all resources have to be closed. </p>
<p>Is this a good way to do it? There is a better way to do it?</p>
<pre><code>public Strint getStuff(Integer id) throws Exception {
String result =... | [] | [
{
"body": "<ol>\n<li>You can skip <code>catch</code> part of try-catch-finally block</li>\n<li>You should check that <code>rs</code> is not null</li>\n</ol>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T01:39:31.620",
"Id": "15036",
"... | {
"AcceptedAnswerId": "9477",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T11:49:42.320",
"Id": "9476",
"Score": "8",
"Tags": [
"java"
],
"Title": "How to handle Throw exception + close connection"
} | 9476 |
<h1>Unicode</h1>
<p><a href="http://unicode.org/" rel="nofollow">Unicode</a> assigns each character a code point to act as a unique reference:</p>
<ul>
<li>U+0041 <strong>A</strong></li>
<li>U+0042 <strong>B</strong></li>
<li>U+0043 <strong>C</strong></li>
<li>...</li>
<li>U+039B <strong>Λ</strong></li>
<li>U+039C <s... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T12:51:01.837",
"Id": "9479",
"Score": "0",
"Tags": null,
"Title": null
} | 9479 |
Unicode is intended to be a universal character set for describing all the characters required for written text incorporating all writing systems, technical symbols and punctuation. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T12:51:01.837",
"Id": "9480",
"Score": "0",
"Tags": null,
"Title": null
} | 9480 |
<p>My rating controller:</p>
<pre><code> def rate
@ip = request.remote_ip
@konkurrencer = Rating.where(:IP => @ip, :konkurrencer_id => params[:id])
if @konkurrencer.empty?
params[:kon][:IP] = request.remote_ip
params[:kon][:konkurrencer_id] = params[:id]
@konkurrencer = Rating.new(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T17:30:44.740",
"Id": "14939",
"Score": "0",
"body": "I can't help but wonder if it would be possible to mess up your rating system by using Firebug to manipulate the values being sent in the request."
}
] | [
{
"body": "<p>Controller code looks good.. You only need to refactor code little bit so that it will look more clean & robust. otherwise rest things are ok. regarding ajax response, you need to implement success/failure response either inside controller or js file.</p>\n\n<p>just to give idea on implementin... | {
"AcceptedAnswerId": "9487",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-26T12:32:55.487",
"Id": "9485",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails",
"ajax"
],
"Title": "Rails controller method to accept one rating per IP address via AJAX"
} | 9485 |
<p>I am still a newbie at coding in general. Over the years the amount of programming that I have done in PHP has always been procedural. I am now working on a project for my course, and was hoping to use it as an opportunity to learn OOP since I come across it everywhere.</p>
<p>I am still trying to really get my hea... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T15:04:51.960",
"Id": "14930",
"Score": "4",
"body": "I see a few problems, var is deprecated you should replace with (public,private,protected). `$this->$username` should most likely be $this->username to assign the `$username` prop... | [
{
"body": "<p>All your <code>var $something;</code> declarations should be <code>public</code> or <code>private</code>, rather than <code>var</code>.</p>\n\n<p>Where you do <code>$this->$username</code>, it should be <code>$this->Username</code>, although it the context you've used it there doesn't seem t... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T14:58:28.593",
"Id": "9488",
"Score": "4",
"Tags": [
"php",
"beginner",
"object-oriented",
"validation"
],
"Title": "AJAX-based PHP server-side form validation"
} | 9488 |
<p>I am using Python 2.6.5 and am trying to find the fastest way to print out the contents of a .gz file. It's my understanding that prior to v2.5, zcat was much faster than gzip (see <a href="http://spyced.blogspot.com/2006/12/wow-gzip-module-kinda-sucks.html" rel="nofollow">here</a>)....I guess that has changed (at l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T17:54:23.570",
"Id": "14944",
"Score": "6",
"body": "Are you profiling? I imagine that most of the 17 mins is spent printing to your screen."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T17:55:28.17... | [
{
"body": "<p>As it stands, you are measuring the speed of printing. Printing is one of the slowest things your program will ever have to do. Take the prints out and remeasure to find out the speed.</p>\n\n<p>Your middle method will almost certainly be the fastest.</p>\n",
"comments": [],
"meta_data": {... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T17:49:53.367",
"Id": "9492",
"Score": "4",
"Tags": [
"python",
"performance",
"io",
"comparative-review",
"compression"
],
"Title": "Reading a .gz file"
} | 9492 |
<p>I am still learning to develop my skills in OOP. </p>
<p>It uses a combination of the factory and its real singletons? </p>
<p>As I did more research, I have realized this design pattern is bad because of global state and it is hard to test.</p>
<p>I can't figure how how to convert this OOP to Dependency injectio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T01:33:53.310",
"Id": "14968",
"Score": "0",
"body": "Is this real code from your project?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T01:44:16.340",
"Id": "14969",
"Score": "0",
"body"... | [
{
"body": "<p>First, a few minor comments:</p>\n\n<p>Class properties should almost always be protected or private. This forces you to use a known tested interface (the class methods) to interact with the state stored in the class. The properties section, something and validation should have all been protecte... | {
"AcceptedAnswerId": "9505",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-27T22:25:14.577",
"Id": "9499",
"Score": "4",
"Tags": [
"php",
"design-patterns",
"object-oriented",
"php5",
"classes"
],
"Title": "How to convert my classes to Dependency ... | 9499 |
<pre><code>class Submission < ActiveRecord::Base
def get_status_css()
if self.status == IN_PROGRESS
"info"
elsif self.status == FAILED
"error"
elsif self.status == COMPLETED
"success"
else
"warning"
end
end
end
</code></pre>
<p>Submission is a model class and it ha... | [] | [
{
"body": "<p>It actually should be put in the view. I don't know how RoR implements it, but the submission status should be retrieved by the controller and transferred to your view. The view will then decide which CSS class to apply.</p>\n\n<p>You could use a substitution test to know whether it should belong ... | {
"AcceptedAnswerId": "9513",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T06:09:36.717",
"Id": "9506",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails",
"mvc"
],
"Title": "Should view related methods be included in models?"
} | 9506 |
<p>I wrote this code in Python/ Scrapy for data extraction. It works fine for me, but I am a newbie in Python, so any suggestions for code optimization would be welcome.</p>
<pre><code>def parse(self, response):
hxs = HtmlXPathSelector(response)
item = GenesishcsItem()
item['graduate_education']=[]
it... | [] | [
{
"body": "<p>The code looks good, but as always, there are always issues one can bring up. I don't believe them to be important though. Your code seems to be getting the job code in a concise way, and if your XPath expressions are robust, there's no need to worry.</p>\n\n<ul>\n<li>Do you have actual performanc... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T09:19:39.857",
"Id": "9509",
"Score": "2",
"Tags": [
"python",
"beginner",
"parsing",
"scrapy"
],
"Title": "Data extraction"
} | 9509 |
<p>I have created a simple palindrome function that works only on single words. It is working as intended, but I feel that it definitely needs improvement.</p>
<pre><code>def is_palindrome(w):
if not isinstance(w, str):
return "ERROR: input is not a string."
elif len(w) > 2:
if w[0] == w[-... | [] | [
{
"body": "<p>Firstly, your testing is insufficient. This code thinks that \"defad\" is a palindrome and that \"deed\" is not. You algorithm is completely broken.</p>\n\n<pre><code>def is_palindrome(w):\n\n if not isinstance(w, str):\n return \"ERROR: input is not a string.\"\n</code></pre>\n\n<p>Don'... | {
"AcceptedAnswerId": "9526",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T17:34:52.233",
"Id": "9515",
"Score": "1",
"Tags": [
"python",
"palindrome"
],
"Title": "Simple palindrome function for single words"
} | 9515 |
<p>I've been searching for a suitable plugin for an input mask for a time field. There are some inherent difficulties with masking a time input, while giving the user the most flexibility. </p>
<p>I have tried to recreate what Google Calendar uses for their time inputs, minus the drop down select. What I've made seems... | [] | [
{
"body": "<p><strong>Spelling</strong></p>\n\n<ul>\n<li>pluing -> plugin</li>\n</ul>\n\n<p><strong>Remove commented out code</strong></p>\n\n<p>Once you feel the code is ready to be used, delete commented out code such as </p>\n\n<pre><code> /* // This would be nice, but this plugin pattern isn't set up for... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T18:44:41.923",
"Id": "9517",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"datetime"
],
"Title": "Time Input Mask Plugin in jQuery"
} | 9517 |
<p>Working through Day 2 of Ruby in "7 Languages in 7 Weeks" - the answer to the second question seems acceptable, the first one feels quite wrong. Any suggestions?</p>
<ol>
<li><p>Print the contents of an array of sixteen numbers, four numbers at a
time, using just <code>each</code>.</p>
<pre><code>group = 0
(1..16... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T22:55:09.507",
"Id": "15032",
"Score": "1",
"body": "(1..16) is not an array. Besides using `each`, the first solution uses `print and puts` from the Kernel class, and `% and +`from Numeric. This book is not for me."
},
{
"... | [
{
"body": "<p>No need to save <code>group</code> <code>x</code> already saving it.</p>\n\n<pre><code>(1..16).each do |x|\n print x\n puts if x % 4 == 0\nend\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T21:52:21.727",
"Id": "... | {
"AcceptedAnswerId": "9523",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T21:17:40.990",
"Id": "9522",
"Score": "3",
"Tags": [
"ruby"
],
"Title": "Using 'each' to print chunks of an array"
} | 9522 |
<p>One hassle with working with mobile websites is inconsistency between how the device reports the screen's width and height. <a href="http://tripleodeon.com/2011/12/first-understand-your-screen/" rel="nofollow">James Pearce wrote a fantastic article about the headaches that come with detecting screen width and heigh... | [] | [
{
"body": "<p>First, the code above can be simplified a lot, at least for the purposes of this \"review,\" and rewritten as:</p>\n\n<pre><code>var currentWidth = document.body.clientWidth,\n newOrientation = window.orientation || (currentWidth > 400);\n</code></pre>\n\n<p>Second, I'd probably be really su... | {
"AcceptedAnswerId": "9527",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T22:04:02.403",
"Id": "9524",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Working with Mobile Device Orientation Detection"
} | 9524 |
<p>I have a tv show I created a MySQL database for. I am trying to get my code to group and order correctly the seasons and episodes within their respective season.</p>
<p>Current Code</p>
<pre><code>if (!($result = mysql_query("SELECT season_num, sub_season_num, esp_num, title, descrip FROM season ORDER BY season_nu... | [] | [
{
"body": "<p>You didn't need to hard-code season values like 1 and 2. Just use the nicely sorted repeating values from the rows and detect when the value changes from one row to the next. With such a generic test, as shown below, you can use one loop and avoid repeated code.</p>\n\n<p>Also note that you seeme... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-28T23:15:00.753",
"Id": "9528",
"Score": "1",
"Tags": [
"php",
"mysql"
],
"Title": "PHP MySQL grouping and ordering"
} | 9528 |
<p>I'm very new to jQuery and JavaScript in general but decided to develop my own code rather than use 3rd party plugins as I really need to learn the language. Would anyone be so kind as to review my code?</p>
<p>I wanted a relatively simple project to start with and decided to build the jQuery front end to a PHP sho... | [] | [
{
"body": "<p>Some suggestions:</p>\n\n<ol>\n<li>In most places you are retrieving <code>.html()</code>, I think you really want <code>.text()</code>.</li>\n<li>You don't want to be using <code>$(this)</code> over and over again because you keep making a new jQuery object over and over again. Evaluate it once ... | {
"AcceptedAnswerId": "9537",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T00:10:22.807",
"Id": "9529",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"e-commerce"
],
"Title": "Front end to PHP shopping cart"
} | 9529 |
<p>I've been helping out a student with an exercice, typed this up rapidly and thought it would be the ideal opportunity to improve my own programming style and approach to problem solving.</p>
<p>In this exercice a grid represents one of those slide puzzles. The patterns have been replaced by numbers. The zero repres... | [] | [
{
"body": "<pre><code> System.out.println(\"Enter height (>0)\");\n\n int height = sc.nextInt();\n</code></pre>\n\n<p>This pattern repeats itself several times in your code. Turn it into a method, e.g. (assuming the <code>Scanner</code> is turned into a static field):</p>\n\n<pre><code>private ... | {
"AcceptedAnswerId": "9539",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T05:10:14.493",
"Id": "9533",
"Score": "3",
"Tags": [
"java",
"sliding-tile-puzzle"
],
"Title": "Simple exercice representing a slidepuzzle"
} | 9533 |
<p>I have a unit test method that looks like this:</p>
<pre><code>...
113 CPPUNIT_ASSERT( !m_pInputFilter[0]->SendPacket() );
114
115 CppUnitUtil::CUnitTestTimeline::GetInstance().Advance( 1, CppUnitUtil::Seconds );
116 CPPUNIT_ASSERT_NO_THROW( m_pTimer->Fire() );
117
118 CPPUNIT_ASSERT_EQUALS( 1, m_pOutputFilt... | [] | [
{
"body": "<p>Blame the tool, but keep your code DRY. The best solution would be to find a way to launch the debugger whenever an ASSERT fails. You could then use the backtrace and select an upper stack frame. Even if it's not possible, you still have access to:</p>\n\n<ol>\n<li>the expected and actual values, ... | {
"AcceptedAnswerId": "9873",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T06:38:35.860",
"Id": "9536",
"Score": "2",
"Tags": [
"c++",
"unit-testing"
],
"Title": "should DRY apply to unit tests as much as production code"
} | 9536 |
<p>I have spent all night whipping up this recipe. It's my first Python decorator. I feel like I have a full understanding of how decorators work now and I think I came up with a good object-oriented algorithm to automatically provide memoization. Please let me know what you think.</p>
<p>I made a few quick changes af... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T09:55:50.113",
"Id": "15056",
"Score": "1",
"body": "Why would you need anything else than `__call__` and `__init__`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T17:12:56.470",
"Id": "15098",
... | [
{
"body": "<pre><code>\"\"\"Gives the class it's core functionality.\"\"\"\ndef __call__(self, *args):\n if args not in self._memos:\n self._memos[args] = self._function(*args)\n return self._memos[args]\n</code></pre>\n\n<p>It's more idiomatic (and faster) to \"ask for forgivness rather than ask f... | {
"AcceptedAnswerId": "9589",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T07:54:20.873",
"Id": "9538",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"memoization"
],
"Title": "Python memoization decorator"
} | 9538 |
<p>How would you refactor this method to make it more performant?</p>
<p>If you have refactored the code you need to prove the performance gain in numbers to get the solution :)</p>
<pre><code>public static T Find<T>(
this IEnumerable<T> source,
Func<T, IEnumerable<T>> childrenSelector... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T14:09:28.803",
"Id": "15072",
"Score": "1",
"body": "How can one \"prove the performance gain in numbers\" if you do not give us a concrete example? Also: http://stackoverflow.com/tags/performance/info `Good question states performa... | [
{
"body": "<p>Do you really have a performance issue?</p>\n\n<p>Optimizing a recursive function is usually done by performing tail call optimization, but this is not possible here since you have multiple branchs to explore at each function call.</p>\n\n<p>I would thus not try to make the <em>code</em> faster, b... | {
"AcceptedAnswerId": "9549",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T09:40:02.207",
"Id": "9544",
"Score": "2",
"Tags": [
"c#",
"performance",
"recursion"
],
"Title": "Make a recursive method faster"
} | 9544 |
<p><code>struct iovec</code> is defined in <code><uio.h></code> by the following way:</p>
<pre><code>/* Structure for scatter/gather I/O. */
struct iovec
{
void *iov_base; /* Pointer to data. */
size_t iov_len; /* Length of data. */
};
</code></pre>
<p>Now I do ugly casting from <code>const void*... | [] | [
{
"body": "<p>I think you should keep it. <code>const</code> is not only meant for the compiler, but also for anybody reading your code. Even with the <code>void*</code> cast, you're still saying to readers \"Trust me, I'm not touching your buffer!\" and this is a valuable information that should not be discard... | {
"AcceptedAnswerId": "9548",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T10:09:24.587",
"Id": "9547",
"Score": "3",
"Tags": [
"c",
"casting"
],
"Title": "Casting const pointer to non-const pointer when using struct iovec"
} | 9547 |
<p>I'm sure this is wrong, but I can't think of a cleaner way to do this. I'm looping through a set of column to identify which column identifies the company name, the test is true if one of a large number of tests are true.</p>
<pre><code>if (heading.ToLower().Contains("organisation") ||
heading.ToLower()... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T12:47:29.120",
"Id": "15065",
"Score": "8",
"body": "For one, you could at least extract `heading.ToLower()` to a variable of its own, so that you don't have to repeat it. (Imagine you will want to change it to `ToLowerInvariant()` ... | [
{
"body": "<p>Sure. Put this into a function, eg. \"isCompanyName\". This function can be easily commented and written in separate lines.</p>\n\n<pre><code> if (heading.ToLower().Contains(\"organisation\")\n return true;\n\n if (heading.ToLower().StartsWith(\"address.\") &&\n heading.ToLower().End... | {
"AcceptedAnswerId": "9551",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-29T11:58:47.260",
"Id": "9550",
"Score": "3",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Extremely long if-or-or statement just feel wrong"
} | 9550 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.