body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>What is your opinion in arguments in constructors matching members as in the following example</p> <pre><code>public Join(final int parent, final TIntHashSet children) { this.parent = parent; this.children = children; } </code></pre> <p>I find this annoying since I have to use <code>this.</code> and also some ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-30T23:53:11.900", "Id": "765", "Score": "3", "body": "I'm not sure if this question really fits on code review but I provided a response for it below anyway." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-...
[ { "body": "<p>If you're worried about typing the extra characters for <code>this</code> you can consider the coding style used in C++. To avoid ambiguity between class data and parameter's passed into a method I usually use one of the following naming conventions for data members: <code>m_parent</code> and <cod...
{ "AcceptedAnswerId": "475", "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-30T23:30:36.383", "Id": "471", "Score": "6", "Tags": [ "java", "constructor" ], "Title": "Arguments in constructors matching fields" }
471
<p>I've recently been doing some mods to some old code I've been maintaining for a couple of years now. </p> <p>As part of a wider set of scripts using YAHOO YUI 2.2 (yes, that old) for dialog-style panels, I have a function that listens to click events on 3 buttons in a given panel set:</p> <pre><code>addFooListene...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-20T21:47:59.170", "Id": "75726", "Score": "1", "body": "My personal opinion is that the `?` ternary operator is worth using only when it's not nested. In your case it just makes the code more unreadable and unmaintainable." }, { ...
[ { "body": "<p>It looks like you can reduce that ternary a bit by using &amp;&amp; like this:</p>\n\n<pre><code>var handlers = {\n show: ( overrides != null &amp;&amp; overrides.show != null ? overrides.show : showFoo ),\n hide: ( overrides != null &amp;&amp; overrides.hide != null ? overrides.hide : hid...
{ "AcceptedAnswerId": "482", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-30T23:43:07.143", "Id": "472", "Score": "26", "Tags": [ "javascript" ], "Title": "Usage of the ternary \"?:\" operator with functions listening to click events" }
472
<p>There's got to be a better way than this that preserves the logic while sparing me the multitude of lines:</p> <pre><code>sub has_path { clearerr; my %Graph = gref(shift); my $A = shift; my $B = shift; my $C = shift; my $D = shift; my $E = shift; my $F = shift; my $G = shift; my $H = shift; my...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-31T06:52:11.170", "Id": "778", "Score": "0", "body": "Arrays and slices, I think!" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-31T06:53:50.763", "Id": "779", "Score": "0", "body": "Can you gi...
[ { "body": "<p>As I noted in a comment, I think the solution lies in using arrays and <a href=\"http://perldoc.perl.org/perldata.html#Slices\">slices</a>. Maybe like this:</p>\n\n<pre><code>sub has_path {\n clearerr;\n my %Graph = gref(shift);\n my(@States) = @_;\n my $bool = 0;\n my $switcher = dectab( [ ...
{ "AcceptedAnswerId": "480", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-31T04:52:54.217", "Id": "478", "Score": "9", "Tags": [ "perl", "graph" ], "Title": "Function, taking up to 27 parameters, that checks for the existence of a path in a graph" }
478
<p>My homework question states:</p> <blockquote> <p>Develop a class to measure distance as feet (should be <code>int</code>), inches (should be <code>float</code>). Include member functions to set and get attributes. Include constructors. Develop functions to add two distances.</p> <p>The prototype of th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-15T20:28:20.247", "Id": "3213", "Score": "1", "body": "Whitespace is cheap nowadays: don't be afraid to use it." } ]
[ { "body": "<p>When designing a class for your program, whether it's for homework or a real production application, you want to always consider how that class is going to be use and what its responsibilities should be. Each function and method should do <em>one</em> thing/task and it should be reflected by the m...
{ "AcceptedAnswerId": "481", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-31T06:33:47.660", "Id": "479", "Score": "28", "Tags": [ "c++", "homework" ], "Title": "Class for measuring distance as feet and inches" }
479
<p>Okay... here's the beast:</p> <pre><code>SELECT SUBSTRING(DischDate, 7, 4) + SUBSTRING(DischDate, 1, 2) as YYYYMM ,Type ,SubType ,Diags ,Count(*) as Count ,SUM(Charges) as Charges ,SUM(Payments) as Payments FROM ( SELECT DISTINCT ID ,Dia...
[]
[ { "body": "<p>This looks like a good use for UNPIVOT. And you can use <a href=\"http://msdn.microsoft.com/en-us/library/ms175972.aspx\" rel=\"nofollow\">common table expressions</a> to <a href=\"http://en.wikipedia.org/wiki/Don%27t_repeat_yourself\" rel=\"nofollow\">avoid repeating yourself</a>. Like this:</p>\...
{ "AcceptedAnswerId": "1018", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-31T20:17:49.470", "Id": "490", "Score": "7", "Tags": [ "sql", "sql-server" ], "Title": "Tame this Beast: TSQL Unpivot" }
490
<p>I have written a simple spinner wrapper, but was wondering if any of you could think of any ways to make it more robust. It only handles strings at the moment.</p> <p><code>MySpinner</code>:</p> <pre><code>package a.b.c; import android.content.Context; import android.util.AttributeSet; import android.widget.Array...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-31T06:02:33.630", "Id": "11475", "Score": "0", "body": "Why were so many common things like \"add\" and \"clear\" and \"insert\" and \"delete\" totally left out of Android Spinners, in the first place????" } ]
[ { "body": "<p>A few ways you could make it more robust.</p>\n\n<ol>\n<li>In <code>getSelected()</code>, why not call <code>getSelectedItem()</code> instead?</li>\n<li>You tend to use <code>super.foo()</code> instead of <code>foo()</code>; that's usually a bad idea. Just call <code>foo()</code>, unless you reall...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-31T20:29:24.857", "Id": "491", "Score": "11", "Tags": [ "java", "android" ], "Title": "Simplified Android Spinner" }
491
<p>This is a simple list of items in a list, which allows the user to dynamically generate that list of events. Then a controller action does the work of serializing that into the database.</p> <p>The issue is that there's the PHP-generated HTML segment, and there's a separate JavaScript segment to do the additions (f...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-31T21:27:17.620", "Id": "181523", "Score": "0", "body": "Use something like [Mustache](http://mustache.github.com/), which is a templating framework that has renderers both on the client-side and the server side, which allows you to av...
[ { "body": "<p>I'm assuming from looking the code you're using Zend Framework. I've solved similar issues in Zend and Symfony using php partials.</p>\n\n<p>You could create a partial _list_item.phtml</p>\n\n<pre><code>&lt;li class=\"ui-content\"&gt;\n &lt;div style=\"float: left; width: 200px;\"&gt;\n ...
{ "AcceptedAnswerId": "726", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-31T20:48:27.087", "Id": "492", "Score": "22", "Tags": [ "php", "javascript" ], "Title": "Dynamically generating a list of events" }
492
<p>I've been writing a function:</p> <pre><code>float turnToRequestedHeading(float initialHeading, float requiredHeading, float turnRate) </code></pre> <p>I keep thinking there must be a clever way to do it, but it escapes me.</p> <p>All values are in Radians, Headings between -<span class="math-container">\$\pi\$</...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-03T08:22:05.207", "Id": "1005", "Score": "0", "body": "(1) You can use a code coverage tool to find out if your tests leave any branch of code untested. Then you can add more tests to cover them. This will help cover all the \"special ...
[ { "body": "<p>Just winging it off the top of my head, pseudocode follows:\nEDIT - correcting some math\nEDIT2 - have some javascript :)</p>\n\n<pre><code>function turnToRequestedHeadingTest(initial, requested, turnRate, newAngle)\n{\n var ang1 = (Math.PI/180.0) * initial;\n var ang2 = (Math.PI/180.0) * re...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-01-31T20:55:47.097", "Id": "493", "Score": "2", "Tags": [ "java", "android" ], "Title": "Function to turn to requested bearing" }
493
<p>I'm looking for the most commonly used style for writing the <code>delete_item()</code> function of a singly linked list, that find a matching item and deletes it. Is what I have the 'typical' or 'normal' solution? Are there more elegant ones?</p> <p>What seems inelegant to me about my solution below, although I do...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-31T23:47:22.593", "Id": "832", "Score": "1", "body": "Forgetting for a moment it should invoke free() somewhere." } ]
[ { "body": "<p>It's been ages since I've done C++, but here are my observations:</p>\n\n<p>First off, you're using global variables, which is ill-advised. I'm not sure if C supports member functions, but if not, you should be using parameter passing, e.g. <code>delete_item(node* head, int x)</code> and so on.</...
{ "AcceptedAnswerId": "508", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-31T23:44:49.807", "Id": "496", "Score": "13", "Tags": [ "c", "linked-list" ], "Title": "C function to find and delete a node from a singly linked list" }
496
<p>This function in my <code>Profile</code> model receive a hash from a search form and should filter the table depending on those values. I guess there is something like a pattern for such a standard behavior, right now I ended up with this (unfortunately I had to reproduce the code here, so it might not work for some...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-01T18:40:24.187", "Id": "879", "Score": "1", "body": "Does the code you posted in your edit actually work? It seems like you're missing `profiles =` at the beginning of every line after the first and a final `profiles` at the end of th...
[ { "body": "<p>Have you looked into using a pre existing gem for this? I found one called <a href=\"https://github.com/plataformatec/has_scope\" rel=\"noreferrer\">has_scope</a> that seems like it might do exactly what you're trying to refactor. You would need to add a scope for each of your filters and then add...
{ "AcceptedAnswerId": "501", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-01T00:46:02.727", "Id": "500", "Score": "8", "Tags": [ "ruby-on-rails", "ruby" ], "Title": "Filtering (search) a model with multiple params in hash" }
500
<p>A little background first. I've been working on a fairly large Rails application which quickly grew into a breeding ground for "smelly" code. One antipattern we were using a lot was storing objects in an STI lookup table and having lots of scattered logic based on the name of the object.</p> <p>Here's a dumbed dow...
[]
[ { "body": "<p>Yes, it is a common problem. </p>\n\n<p>I think this is a great way to solve this, I wish I'd done it! Back in my java days I did use the typesafe enum pattern. In ruby I tend to create method objects after the third or so repetition in cases like this, but this is a much cleaner solution and I'm ...
{ "AcceptedAnswerId": "625", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-01T02:20:22.557", "Id": "503", "Score": "8", "Tags": [ "ruby", "ruby-on-rails", "enum", "lookup" ], "Title": "RubyGem for Enums" }
503
<p>I have a class whose purpose is to display a comment. I'd like to be able to instantiate it by passing a <code>Comment</code> object if I happen to have it available, or just the values if that's what I have available at the time. Unfortunately PHP doesn't allow overloaded constructors, so here's the workaround I ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-01T22:31:49.617", "Id": "3537", "Score": "0", "body": "Partly covered by the migrated [Single array or many single argument to call a constructor with params](http://codereview.stackexchange.com/questions/2189/single-array-or-many-sing...
[ { "body": "<p>Given that php allows optional parameters and doesn't require type checking of parameters that are passed in, you can sort of \"fake\" an overloaded constructor.</p>\n\n<p>something like this:</p>\n\n<pre><code>class CommentPanel extends Panel {\n public function __construct($text_or_comment, $...
{ "AcceptedAnswerId": "509", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-01T02:57:13.353", "Id": "504", "Score": "7", "Tags": [ "php", "constructor" ], "Title": "Workaround for overloaded constructor in PHP" }
504
<p>I intend this to be a general question on writing an effective set of test cases for a controller action.</p> <p>I include the following ingredients:</p> <ul> <li><strong>Ruby on Rails</strong></li> <li><strong>RSpec:</strong> A testing framework. I considered doing a vanilla Rails question, but I personally use R...
[]
[ { "body": "<p>You've coded by your principles pretty reasonably. </p>\n\n<p>My only real suggestion is to have just one assertion per test, including any <code>#should_receive</code> or <code>#should=</code> statements. The intention of most of your tests seems to be to test one single unit of functionality, so...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-01T03:01:24.973", "Id": "505", "Score": "28", "Tags": [ "ruby", "unit-testing", "ruby-on-rails", "controller" ], "Title": "Unit-testing a controller in Ruby on Rails" }
505
<p>Please review this:</p> <pre><code>from os import path, remove try: video = Video.objects.get(id=original_video_id) except ObjectDoesNotExist: return False convert_command = ['ffmpeg', '-i', input_file, '-acodec', 'libmp3lame', '-y', '-ac', '2', '-ar', '44100', '-aq', '5', '-qscale', '10',...
[]
[ { "body": "<p>Clean, easy to understand code. However:</p>\n\n<p>Never hide errors with a bare except. Change </p>\n\n<pre><code>try:\n ...\nexcept:\n return False\n</code></pre>\n\n<p>into </p>\n\n<pre><code>try:\n ...\nexcept (IOError, AnyOther, ExceptionThat, YouExpect):\n logging.exception(\"Fil...
{ "AcceptedAnswerId": "510", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-01T04:39:28.163", "Id": "507", "Score": "5", "Tags": [ "python", "converting", "django" ], "Title": "Converting an already-uploaded file and saving it to a model's FileField" }
507
<p>I have 2 functions used for parsing a house number and I think these can both be improved.</p> <p>Any suggestions?</p> <p><strong>input:</strong></p> <blockquote> <pre><code>45a - 47b </code></pre> <p>or</p> <pre><code>45a bis 47b </code></pre> </blockquote> <p><strong>output:</strong></p> <blockquote> <p...
[]
[ { "body": "<p>Anytime I encounter a method that's only doing read-only parsing of strings and I see it's using <code>String.IndexOf()</code> and <em>positions</em>, it leaps out at me like a gigantic code smell.</p>\n\n<p>Sometimes upon examination it turns out to be a legitimate and wise usage. However very of...
{ "AcceptedAnswerId": "515", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-01T07:58:30.563", "Id": "513", "Score": "16", "Tags": [ "c#", "parsing" ], "Title": "House number parsing" }
513
<pre><code>&lt;% @descriptions.each_with_index do |description, i| %&gt; &lt;% description.tale2.each do |tax_ref| %&gt; &lt;% if condition %&gt; &lt;% if condition %&gt; &lt;% if condition %&gt; &lt;%= $text_first_describe%&gt; &lt;%= $paren_aut...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-01T10:03:52.760", "Id": "845", "Score": "0", "body": "try to edit your code with a good completion" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-01T10:04:34.177", "Id": "846", "Score": "1", "b...
[ { "body": "<p>In general, you can try inverting the condition on your outermost if block, and work your way in. This will often result in less nesting, eg:</p>\n\n<pre><code>if condition1\n if condition2\n #ifblock\n else\n #elseblock2\n end\nelse\n #elseblock\nend\n</code></pre>\n\n<p>Inside a loop,...
{ "AcceptedAnswerId": "524", "CommentCount": "7", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-01T09:36:07.163", "Id": "514", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "How to reduce number of hierarchical 'if statements'" }
514
<p>I need a code review for <em>best practices</em> and <em>code correctness</em> of the following piece of code. <code>run</code> executes a program and validates in output. If the output is valid status can be found in <code>VALID_SOLUTIONS</code>.</p> <pre><code>elapsed = None tmpdir = tempfile.mkdtemp(prefix='stru...
[]
[ { "body": "<p>Well, firstly, don't be afraid of empty lines. This code is quite hard to read.</p>\n\n<p>Secondly, functions is good invention. ;) That code as it is now is a bare piece of code, with no indication of where most of the parameters come from, and it seems that the acceptable solutions is a global, ...
{ "AcceptedAnswerId": "521", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-01T13:25:51.633", "Id": "519", "Score": "14", "Tags": [ "python", "file", "error-handling", "timer" ], "Title": "Executing a program with a temporary directory and measuring the...
519
<p>I'm building an ASP.NET MVC app and would like some feedback for my way to query/execute statements to the ORM.</p> <p>I'm using Fluent NHibernate, and have mixed the UoW provided by NHibernate with a Command pattern.</p> <p><strong>ICommand.cs</strong> (Core layer)</p> <pre><code>using NHibernate; namespace MyD...
[]
[ { "body": "<p>This seems to be a lot of code to say the same as this:</p>\n\n<pre><code>[AjaxOnly]\n[Authorize]\npublic ActionResult Details(int id)\n{\n User userToGet = _session.Get&lt;User&gt;(id);\n\n if (userToGet == null)\n {\n return PartialView(\"Partials/UserNotFound\");\n }\n\n D...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-01T14:22:20.707", "Id": "522", "Score": "4", "Tags": [ "c#", "asp.net" ], "Title": "NHibernate (UoW) + cCommand pattern" }
522
<p>I have a small solution to the following hypothetical problem:</p> <blockquote> <p>Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemption...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-03-13T23:49:05.500", "Id": "228756", "Score": "0", "body": "This precise homework problem has been addressed before in the StackExchange universe." } ]
[ { "body": "<p>Wow, a lot of code to review. Unfortunately I'm too lazy to look through entire solution, let's I'll post my first 10 points. </p>\n\n<p>1) <a href=\"http://en.wikipedia.org/wiki/Overengineering\">http://en.wikipedia.org/wiki/Overengineering</a>. Looked through the solution and have found absolut...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-01T21:56:09.690", "Id": "531", "Score": "8", "Tags": [ "c#", "programming-challenge", "design-patterns", "unit-testing", "finance" ], "Title": "Hypothetical SalesTax challeng...
531
<p>Is there a better (more pythonic?) way to filter a list on attributes or methods of objects than relying on lamda functions?</p> <pre><code>contexts_to_display = ... tasks = Task.objects.all() tasks = filter(lambda t: t.matches_contexts(contexts_to_display), tasks) tasks = filter(lambda t: not t.is_future(), tasks)...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-01T22:49:25.317", "Id": "889", "Score": "3", "body": "I think this is too specific a question to qualify as a code review." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T16:47:05.750", "Id": "1319",...
[ { "body": "<p>I think lambdas are fine in this case. (Yeah, not much of a code review, but what can I say... You basically ask a yes/no question. Answer: \"No\". :) )</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-...
{ "AcceptedAnswerId": "547", "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-01T22:44:01.423", "Id": "533", "Score": "1", "Tags": [ "python" ], "Title": "Is there a better way than lambda to filter on attributes/methods of objects?" }
533
<p>I'm currently working on several projects for my company to help reduce the amount of calls we have to deal with so we can focus on higher priority task, such as server resource reduction, etc.</p> <p>The first project on my list was to reduce the number of proxy issues a user has when migrating from an internal ne...
[]
[ { "body": "<p>Just a few points that came to mind as I was reading your code.</p>\n\n<ul>\n<li><p>It appears to me that the main thread terminates once the <code>NetworkChange.NetworkAddressChanged</code> event is hooked, in which case the thread is redundant as the event will be raised by another thread anyway...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-01T23:26:29.873", "Id": "536", "Score": "10", "Tags": [ "c#", "proxy" ], "Title": "Windows service for monitoring network interface changes" }
536
<p>I've written an abstract class in C# for the purpose of random number generation from an array of bytes. The .NET class <code>RNGCryptoServiceProvider</code> can be used to generate this array of random bytes, for example.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using Syste...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T00:50:00.677", "Id": "899", "Score": "0", "body": "What is the purpose of the interdependent get() methods?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T00:59:42.587", "Id": "900", "Score":...
[ { "body": "<p>If you're planning on placing this in a reusable library you should validate inputs (min > max throws an IndexOutOfRangeException, etc.) Also, you do not need to cast to double in the GetDouble method as the division implicitly returns a double and casting the first operand of the division in GetS...
{ "AcceptedAnswerId": "550", "CommentCount": "10", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T00:39:38.673", "Id": "538", "Score": "12", "Tags": [ "c#", "random" ], "Title": "Random Number Generator Class" }
538
<p>I have a small 10-liner function that writes some data to a file using an <code>std::ofstream</code>. I did not explicitly call <code>.close()</code> at the end of my function, but it failed code review with the reason that it is better to explicitly call it for style and verbosity reasons. I understand there is no ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T11:33:17.797", "Id": "920", "Score": "7", "body": "If the reviewers need reassurance that close is called automatically, then C++ is probably not the best language choice. The \"verbosity\" reason is particularly alarming." }, ...
[ { "body": "<p>I'm torn on this one. You are absolutely correct. However if a coding standard requires calling close() explicitly or it's a group people's consensus of doing that, there's not much you can do. If I were you, I would just go with the flow. Arguing such things is unproductive.</p>\n", "comments...
{ "AcceptedAnswerId": "544", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-02T04:00:41.190", "Id": "540", "Score": "70", "Tags": [ "c++", "stream", "raii" ], "Title": "Open, write and close a file" }
540
<p>How does this class to resize an image look?</p> <pre><code>using System; using System.Collections.Generic; using System.Web; using System.Drawing; using System.IO; /* * Resizes an image **/ public static class ImageResizer { // Saves the image to specific location, save location includes filename privat...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T14:46:29.657", "Id": "935", "Score": "3", "body": "PascalCase on the methods...since you stated no matter how nitty..." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T14:47:07.283", "Id": "936", ...
[ { "body": "<p><a href=\"http://c2.com/cgi/wiki?PascalCase\">PascalCase</a> the method names and method params if you are feeling overly ambitious.</p>\n\n<pre><code> // Set new width if in bounds\n if (onlyResizeIfWider)\n {\n if (ImageToResize.Width &lt;= newWidth)\n {\n newWi...
{ "AcceptedAnswerId": "552", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-02T14:13:43.487", "Id": "549", "Score": "12", "Tags": [ "c#", "asp.net", "image" ], "Title": "Image resizing class" }
549
<p>Here you go:</p> <pre><code>#define abort(msg) (fprintf(stderr, msg) &amp;&amp; *((char*)0)) </code></pre>
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T14:44:24.167", "Id": "934", "Score": "3", "body": "I'm pretty sure others are going to agree with me on this, but this is way way too short to be considered for a code review." }, { "ContentLicense": "CC BY-SA 2.5", "Cre...
[ { "body": "<h3>Non-standard interface to standard function</h3>\n\n<p>The obvious criticism of that implementation is that it has a different interface from what the C standard requires:</p>\n\n<blockquote>\n <p>§7.20.4.1 The abort function</p>\n \n <p>Synopsis</p>\n\n<pre><code>#include &lt;stdlib.h&gt;\nvo...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-02T14:39:53.470", "Id": "551", "Score": "3", "Tags": [ "c", "error-handling" ], "Title": "abort() implementation" }
551
<p>Please have a look at these iterators which I use for my Sudoku solver. They behave slightly different from STL iterators and don't implement all functionality that would be needed to use them in a stl context. But the basic idea behind them was to clean up the code in the Sudoku program that makes heavy use of the ...
[]
[ { "body": "<p>In my first quick scan through, here are some things I want to bring up:</p>\n\n<ul>\n<li>If you are going to overload operators, do it the way the users of the language expect, or don't do it at all. I expect <code>operator++</code> to return something, not be a <code>void</code>.</li>\n<li>Does...
{ "AcceptedAnswerId": "560", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T17:26:42.450", "Id": "558", "Score": "15", "Tags": [ "c++", "iterator", "sudoku" ], "Title": "Sudoku Grid special purpose Iterators" }
558
<p>I have a class that spawns threads to process data. I am working on instrumentation code. When the process is started, <code>time = System.currentTimeMillis();</code> When it completes, <code>time = System.currentTimeMillis() - time;</code> I have a method to retrieve this time:</p> <pre><code>/** * Get the time t...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-03T03:03:11.907", "Id": "992", "Score": "3", "body": "should document your units" } ]
[ { "body": "<p>It appears that the method sometimes returns a timestamp (<code>time</code>) and sometimes it returns a duration (difference between timestamps) (assuming that <code>time</code> is always a timestamp - if not, then this issue simply moves to <code>time</code> having a dual definition).</p>\n", ...
{ "AcceptedAnswerId": "565", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-02-02T19:14:50.720", "Id": "562", "Score": "8", "Tags": [ "java", "multithreading", "datetime" ], "Title": "Spawning threads to process data" }
562
<p>I am learning clojure and decided to start out by trying to write a solution to a fairly simple algorithm, reservoir sampling. As I stated, I am learning clojure specifically and problem solving in a functional language in general. Can someone please take a look at my code and critique it on it's "clojureness". A...
[]
[ { "body": "<p>I think your code is pretty readable and looks like idiomatic enough Clojure code¹. So from a readability standpoint your code seems fine. However performing <code>assoc</code> on a vector of length <code>n</code> takes <code>O(log n)</code> time, so your runtime will be in <code>O(n log n)</code>...
{ "AcceptedAnswerId": "577", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T21:25:51.983", "Id": "568", "Score": "13", "Tags": [ "functional-programming", "clojure" ], "Title": "Reservoir Sampling in Clojure" }
568
<p>I implemented a solution to <a href="https://codegolf.stackexchange.com/questions/339/binary-tree-encoding">this coding challenge</a> on the Code Golf. I have decent experience with C/C++, but it's been a while since I've used them extensively.</p> <pre><code>#include &lt;math.h&gt; #include &lt;stdio.h&gt; #includ...
[]
[ { "body": "<p>I only have a minute before running out the door, so here's the first thing I saw:</p>\n\n<ul>\n<li>Its good practice to set your pointers to <code>NULL</code> after you free them. Just as you are testing to ensure its not set to <code>NULL</code> since you do that upon creation, you should do th...
{ "AcceptedAnswerId": "573", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-02T21:26:15.803", "Id": "569", "Score": "12", "Tags": [ "c", "tree" ], "Title": "Binary tree encoding" }
569
<p>I'm trying to learn a little bit about functional programming and as my tool I chose F# since I'm a .NET developer and the environment is more natural to me.</p> <p>In one of my pet projects I'm dealing with dates, so I created a function to get the last date where a given week day occurred. For example, last Tuesd...
[]
[ { "body": "<p>The most obvious point to make is that <code>whenWasLast</code> repeats the entire code of <code>whenWasLastBasedOnDate</code>. You can (and should) simply write the whole method by just calling <code>whenWasLastBasedOnDate</code>:</p>\n\n<pre><code>let whenWasLast (weekDay:DayOfWeek) =\n whenW...
{ "AcceptedAnswerId": "574", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-02T21:36:26.723", "Id": "572", "Score": "10", "Tags": [ ".net", "functional-programming", "f#", "datetime" ], "Title": "Getting the last date where a given week day occurred" }
572
<p>My own CMS is currently using jQuery, but as one of the goals is to have the whole project to be very small, I've decided to write my own basic library. I only really need to select elements and modify them using results from my server (via Ajax).</p> <p><strong>The JavaScript-library v0.01: (Attempt 1)</strong></...
[]
[ { "body": "<p>I would suggest writing your code with full variable names and generating your production version with a minimizer to improve readability. As it stands this is reviewable because it's small, but I have no desire to be thorough because your variables are annoying to trace. This will also make maint...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-03T07:40:05.443", "Id": "580", "Score": "8", "Tags": [ "javascript", "ajax", "library" ], "Title": "Basic JavaScript library" }
580
<p>This code writes to Excel using the COM interface. The general issue is that any exception handling has to handle the "Excel is busy" exception. This occurs if information is sent to Excel quicker than it can handle it - eg. latency when a workbook is loaded/created, or the user is playing with the scrollbars (there...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-03T16:06:25.413", "Id": "1016", "Score": "0", "body": "To clarify, I'm using C# 4.0, so sepp2k's relatively advanced solution is fine. I'm a new convert from 2.0, mainly for the new multi-threading capabilities." } ]
[ { "body": "<p>If I understood you correctly, you have a lot of methods which are identical to the one you've shown except for the parameters they take and the contents of the <code>try</code>-block. The rest is repeated code, which is bad.</p>\n\n<p>To fix this I'd recommend to abstract the \"repeat this action...
{ "AcceptedAnswerId": "583", "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-03T14:32:50.913", "Id": "582", "Score": "6", "Tags": [ "c#", "exception" ], "Title": "Handling COM exceptions / busy codes" }
582
<p>I'm writing a logger extension that allows multiple threads to log a process, and then dump that log to the main log in one atomic operation. The point of it is to make the logs easier to read when many threads are executing. Is this test valid and clear or not?</p> <pre><code>/** * Test that thread logs do not in...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T06:36:20.460", "Id": "1061", "Score": "2", "body": "1. A barrier can ensure the threads execute in an interleaved fashion. 2. assertTrue instead of assertEquals(.., true, ..). 3. cut and paste error has you modifying t2Correct ins...
[ { "body": "<p>A barrier can ensure the threads execute in an interleaved fashion.</p>\n\n<pre><code>final CyclicBarrier rendezvous = new CyclicBarrier(2);\nfinal CyclicBarrier conclusion = new CyclicBarrier(3);\nThread a = new Thread() {\n public void run() {\n try {\n rendezvous.await();...
{ "AcceptedAnswerId": "614", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-02-03T20:26:24.293", "Id": "587", "Score": "8", "Tags": [ "java", "unit-testing", "multithreading" ], "Title": "Multithreaded log test" }
587
<p>I have a block of code below. The <code>allDone()</code> method at the bottom should only be run if the <code>allCompleted == true</code>. It should run through each of the statements to test.</p> <ul> <li><p><code>allCompleted</code>: This starts as true so the below logic works right.</p></li> <li><p><code>run*.C...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T06:38:06.090", "Id": "1062", "Score": "0", "body": "Can you not change the 4 pairs of variables (runPartN and cmdPartN) into an array of an appropriate structure type? Then you could loop over the array." }, { "ContentLicen...
[ { "body": "<pre><code>allCompleted = true;\nallCompleted &amp;= (!runPart1.Checked || cmdPart1 == \"done\"));\nallCompleted &amp;= (!runPart2.Checked || cmdPart2 == \"done\"));\nallCompleted &amp;= (!runPart3.Checked || cmdPart3 == \"done\"));\nallCompleted &amp;= (!runPart4.Checked || cmdPart4 == \"done\"));\n...
{ "AcceptedAnswerId": "593", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-03T20:59:00.940", "Id": "590", "Score": "11", "Tags": [ "c#", ".net" ], "Title": "Nested if statements with 3 different parameters" }
590
<p>I got sick of manually xrandering things on my computers (especially since I always just sequence monitors from left to right and set each at the highest resolution) so I wrote this:</p> <pre><code>#!/usr/bin/ruby def xrandrPairs (xList) ## Takes a split list of xrandr output and returns [[&lt;display name&gt;, &l...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T03:46:40.970", "Id": "1055", "Score": "0", "body": "Could you mention your ruby version?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T03:54:28.353", "Id": "1056", "Score": "0", "body": ...
[ { "body": "<p>First of all, the convention in ruby is to use <code>snake_case</code>, not <code>camelCase</code> for variable and method names. It's generally a good idea to adhere to a language's naming conventions - if only so that the code looks consistent when you're calling standard library methods as well...
{ "AcceptedAnswerId": "598", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-04T03:24:48.727", "Id": "597", "Score": "4", "Tags": [ "ruby" ], "Title": "Autodetecting monitors in XFCE" }
597
<p>I'm working on a web application that I inherited from a colleague long gone. To connect to the MySQL database I use the following classes:</p> <p><strong>statement.php</strong></p> <pre><code>&lt;?php //class sql //{ class Statement { private $m_connection; function __construct($connectio...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T13:54:49.133", "Id": "1074", "Score": "4", "body": "What kind of trouble are they causing?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T14:12:57.023", "Id": "1075", "Score": "0", "body"...
[ { "body": "<p>Consider using mysqli instead of mysql:</p>\n\n<p><a href=\"http://www.php.net/manual/en/mysqli.connect.php\" rel=\"nofollow\">mysqli</a></p>\n\n<p>Mysqli (the \"i\" stands for \"improved\") is more OO-friendly and has better security. It also seems like the standard mysql functions are being dep...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-04T13:31:10.493", "Id": "601", "Score": "8", "Tags": [ "php", "mysql" ], "Title": "Connecting to a database" }
601
<p><strong>The point of this question</strong></p> <p>I'm actually using it while developing a simple application and it seems to cover all my needs. Also it uses PDO so that we don't really have to worry about SQL Injection. I know I usually code strange, but I hope you could give me suggestions and feedback in order...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T17:18:03.967", "Id": "1083", "Score": "1", "body": "What is PDO? I've never heard of it before." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T18:26:15.397", "Id": "1086", "Score": "6", ...
[ { "body": "<h3>Why not make DB a Singleton class?</h3>\n<p>Making it Singleton will prevent multiple sign-ons. Now in your code, each time a DB object is created, you authenticate with the database server.</p>\n<p>If you make it Singleton, you just have to connect once. And whenever you need the instance, you j...
{ "AcceptedAnswerId": "670", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-04T15:03:42.493", "Id": "602", "Score": "8", "Tags": [ "php", "mysql", "php5", "pdo" ], "Title": "Database class using PDO" }
602
<p>Please take a look at my program and let me know how I can improve it.</p> <pre><code>/* " To Print A Line On The Display Screen" Date:5th January 2011 Programmer:Fahad */ #include &lt;iostream&gt; using namespace std; class Print { public: void print_(); }; int main() { Print Obj; Obj...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T18:33:21.287", "Id": "1088", "Score": "3", "body": "I think you misunderstood the idea of using underscore from my previous post. Usually you want to append the underscore to *private data members* of your class. As others have alre...
[ { "body": "<p>Not sure what you mean by coding style. If you're talking about spacing and such, here are changes I would make. Note that these are entirely subjective and people are probably going to disagree with me.</p>\n\n<p>Don't indent the <code>public:</code> specifier in the class -- leave it flush with ...
{ "AcceptedAnswerId": "607", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-04T16:19:12.370", "Id": "604", "Score": "13", "Tags": [ "c++", "beginner", "console" ], "Title": "\"Hello, world!\" program using a class for printing" }
604
<p>The function below is called to determine if a given file is the archive of another file. I'm also looking for a way to supports wildcards. For example if the original log file is serverw3c.log and we type serverw3c*.log, it returns true for the following:</p> <ul> <li>serverw3c.log.2011-02-04</li> <li>serverw3c.lo...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T19:04:32.723", "Id": "1090", "Score": "0", "body": "I'm sorry, I can't make the code formatting to work properly." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T19:57:01.513", "Id": "1091", "...
[ { "body": "<p>Your regex can be shortened using <code>{x}</code>, which repeat a pattern <code>x</code> times. So your third regex would become:</p>\n\n<pre><code>exp = new Regex(string.Concat(Path.GetFileNameWithoutExtension(originalFile),\n \"_[0-9]{8}_[0-9]{3}\",\n ...
{ "AcceptedAnswerId": "612", "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T19:02:43.127", "Id": "611", "Score": "6", "Tags": [ "c#", "regex" ], "Title": "How to reduce this archive detection function and make it supports wildcards" }
611
<p>After asking <a href="https://stackoverflow.com/questions/4868049/how-to-efficiently-wrap-the-index-of-a-fixed-size-circular-buffer">this question</a>, I decided to write a test and determine the fastest way to wrap an index (where my <code>maxSize</code> is always a power of 2).</p> <p>There are 3 functions that I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-22T08:17:44.393", "Id": "40986", "Score": "0", "body": "I think this link may be useful for future visitors: [Benchmarking small code samples in C#](http://stackoverflow.com/questions/1047218/benchmarking-small-code-samples-in-c-can-th...
[ { "body": "<p>Your results do seem odd, so I tried to rewrite your test and see if I can get different results. I suspected that you might be starting and stopping the stopwatch too frequently, which can skew your results due to the loss of precision every time you start and stop. In my code, I only start and...
{ "AcceptedAnswerId": "616", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-05T01:28:10.697", "Id": "615", "Score": "6", "Tags": [ "c#", "performance", "unit-testing" ], "Title": "Performance testing functions for wrapping an index" }
615
<p>I have a piece code similar to below:</p> <p>But I keep having this nagging feeling that there has to be an easier way! Any ideas?</p> <pre><code>var synch = false var indexArray = new Array(); var rowCount = theTable.find('tr').length; $(".views").each(function(index) { indexArray.push( $(this).val()); // Not...
[]
[ { "body": "<p>There is absolutely no need for the <code>synch</code> part - <a href=\"https://stackoverflow.com/questions/2035645/when-is-javascript-synchronous\">JavaScript <em>is</em> synchronous</a>, and you should not get into a situation where the processing of that function (the one you're showing) will n...
{ "AcceptedAnswerId": "618", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-05T07:57:03.443", "Id": "617", "Score": "4", "Tags": [ "javascript", "jquery", "synchronization" ], "Title": "Making sure all elements are processed in a JQuery call" }
617
<p>I have written another program in C++. Excluding the point that the class definition should be in a separate header file, is there anything that needs to be improved?</p> <pre><code>/* Date:5th January 2011 Programmer:Fahad */ #include &lt;iostream&gt; #include &lt;string&gt; using namespace std; class Pers...
[]
[ { "body": "<p>I <a href=\"https://stackoverflow.com/questions/1265039/using-std-namespace/1265092#1265092\">avoid</a> <code>using namespace std;</code>.</p>\n\n<hr>\n\n<pre><code>cout &lt;&lt; \"Enter Number Of Persons:\";\nint n; //This is the number of objects that the user wants to make.\ncin &gt;&gt; n;...
{ "AcceptedAnswerId": "623", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-05T10:55:43.063", "Id": "621", "Score": "12", "Tags": [ "c++", "classes" ], "Title": "Class for holding person's information" }
621
<p>I've got a Clojure function here that's meant to parse a string of form:</p> <blockquote> <p>"DDXXXYYY"</p> </blockquote> <p>where DD is meant to be discarded, and XXX and YYY are string representations of integers.</p> <pre><code>(defn split-id [tileid] (map #(Integer/parseInt %) (map (partial apply s...
[]
[ { "body": "<p>You could try the following, using the Java substring method and a vector of offsets:</p>\n\n<pre><code>(defn split-id [tileid]\n (map \n #(Integer. (.substring tileid % (+ % 3)) ) \n [2 5]))\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "Content...
{ "AcceptedAnswerId": "2483", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-05T20:46:52.977", "Id": "631", "Score": "7", "Tags": [ "strings", "clojure" ], "Title": "Partitioning strings into substrings of fixed length" }
631
<p>This is what I've done so far:</p> <pre><code>$block-height: 180px; @mixin block { float: left; margin-bottom: 20px !important; margin-right: 20px !important; overflow: hidden; } #content h2 { height: 30px; } #top-bar { overflow: hidden; } .block-1 { @include block; width: 340px;...
[]
[ { "body": "<p>It looks a bit like block-1's height is calculated from @block-height, in which case I would do that calculation rather than putting in a literal value. This way if you change @block-height, block-1 will adjust with it.</p>\n\n<p>Beyond Sass and efficiency, I would also advise you to think again a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-06T00:09:11.227", "Id": "634", "Score": "5", "Tags": [ "php", "css", "sass" ], "Title": "Adding flair to PHP page with Sassy (SCSS)" }
634
<p>I haven't had anyone help me out with code review, etc, so I thought I'd post a Python class I put together for interfacing with Telnet to get information from a memcached server.</p> <pre><code>import re, telnetlib class MemcachedStats: _client = None def __init__(self, host='localhost', port='11211'): ...
[]
[ { "body": "<p>The pattern</p>\n\n<pre><code>self.client.write(\"some command\\n\")\nresponse = self.client.read_until('END')\n</code></pre>\n\n<p>appears three times in your code. I think this is often enough to warrant refactoring it into its own method like this:</p>\n\n<pre><code>def command(self, cmd):\n ...
{ "AcceptedAnswerId": "638", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-06T01:42:42.690", "Id": "636", "Score": "10", "Tags": [ "python", "networking" ], "Title": "Python class w/ Telnet interface to memcached" }
636
<p>I basically have an AJAX-fetched skin (html/css) that's loaded into a dummy element (id=SkinContainer) when the page is loaded, and then the content of one of its divs (contentdiv) is fetched with another AJAXHTTPRequest.</p> <p>At any rate, when the page is loaded, the user can click a button to swap the theme/ski...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-06T06:30:32.000", "Id": "1145", "Score": "2", "body": "Have you looked at http://www.alistapart.com/articles/bodyswitchers/?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-06T06:54:22.597", "Id": "1146...
[ { "body": "<p>My 2 cents:</p>\n\n<ul>\n<li><p>The code is not bad, I really only have minor nitpickings</p></li>\n<li><p>Your theme selection code use a trinary:</p></li>\n</ul>\n\n<blockquote>\n<pre><code>var oldTheme = themeSelect;\nvar themeSelect = themeSelect==1?2:1;\n</code></pre>\n</blockquote>\n\n<ul...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-06T05:23:13.670", "Id": "639", "Score": "8", "Tags": [ "javascript", "html", "css", "ajax" ], "Title": "Theme/skin swap... version 2! (CSS-driven)" }
639
<p>Instead of writing four almost identical <code>setOnClickListener</code> method calls, I opted to iterate over an array, but I'm wondering if this was the best way to do it. Do you have any suggestions for improving it?</p> <pre><code>/* Set up the radio button click listeners so two categories are not selected ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-02T18:24:55.580", "Id": "6789", "Score": "0", "body": "One thing I'd recommend is to use lowerCamelCase for variable names. That's the variable naming convention for Java" } ]
[ { "body": "<p>It's typical callback method, you just <strong>defined</strong> <code>setOnClickListener</code> once. Calling 4 times is not bad <a href=\"http://en.wikipedia.org/wiki/Code_smell\" rel=\"nofollow\">smell</a>.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentL...
{ "AcceptedAnswerId": "643", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-02-06T03:08:27.397", "Id": "640", "Score": "13", "Tags": [ "java", "event-handling", "gui" ], "Title": "Setting up radio button click ActionListeners" }
640
<p>I wrote the following Ruby script several years ago and have been using it often ever since.</p> <p>It opens a text editor with the list of files in current directory. You can then edit the file names as text. Once you save and exit the files are renamed.</p> <p>The <code>renamer</code> allowed me to maintain spre...
[]
[ { "body": "<p>Just a couple of things:</p>\n\n<pre><code>#!/usr/bin/ruby\n</code></pre>\n\n<p>It's possible that on some systems this isn't where ruby lives, it's better to do:</p>\n\n<pre><code>#!/usr/bin/env ruby\n</code></pre>\n\n<hr>\n\n<pre><code>from = Dir.entries('.').sort; from.delete('.'); from.delete(...
{ "AcceptedAnswerId": "660", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-06T06:51:17.670", "Id": "645", "Score": "10", "Tags": [ "ruby", "file-system" ], "Title": "A text editor driven file renamer in Ruby" }
645
<p>I just want to make sure there aren't any deadlocks or inconsistencies (the code is also available on <a href="https://github.com/ripper234/Basic/blob/master/java/src/main/java/org/basic/concurrent/SynchedQueue.java" rel="nofollow noreferrer">GitHub</a>). </p> <p><strong>Disclaimer</strong> - In real life, I would ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-07T06:29:09.063", "Id": "1194", "Score": "0", "body": "(1) if you are prepping for interviews, consider what tests you could write for this. (2) call trimToSize() on your buffer after you're done adding to it." }, { "ContentLi...
[ { "body": "<p>I have not coded in Java for a few years so it might be good to get another opinion, though some points did stand out while reading your code.</p>\n\n<ul>\n<li><p>It seems odd to me that you would use an <code>ArrayList</code> with a fixed size, personally I would just use an array for the buffer....
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-02-06T07:12:24.630", "Id": "646", "Score": "8", "Tags": [ "java", "multithreading" ], "Title": "Java synchronous queue implementation" }
646
<p>I wanted a class which executes any number of tasks but only a certain amount at the same time (e.g. to download various internet content and keep the overall download speed at a good level). The class I wrote seems to work but there are probably things that can be improved.</p> <ol> <li>Do these locks make sense? ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-09T22:12:55.893", "Id": "1294", "Score": "0", "body": "I added an answer with a good, imho, open source library." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-06T14:58:57.620", "Id": "58725", "Sco...
[ { "body": "<p>In <code>ThreadCompleted</code> looks like you're raising <code>OnCompleted</code> twice - once in this method itself and another one in <code>CheckQueue</code> method</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-06T14:00:59.153", ...
{ "AcceptedAnswerId": "711", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-06T12:04:29.877", "Id": "654", "Score": "19", "Tags": [ "c#", "multithreading", "queue", "locking" ], "Title": "A custom thread-pool/queue class" }
654
<p>I have inherited this snippet of jQuery JavaScript and am currently brushing up on my jQuery. NetBeans IDE complains that <code>Anonymous function does not always return a value</code>. So there is not always an explicit exit point.</p> <p>I am aware that the <code>$()</code> shortcut is not being used. This is bec...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-06T16:22:39.350", "Id": "1171", "Score": "0", "body": "it depends, does the function call require the function to return a value. such as: `value = (function(){return 1})(document)`;" }, { "ContentLicense": "CC BY-SA 2.5", ...
[ { "body": "<p>Netbeans is right to complain about this (there are <a href=\"http://wiki.netbeans.org/JavaScript_anonnoreturnvalue\" rel=\"nofollow\">some details</a> on the website about it but they are a bit sparse). Also this isn't Netbeans specific, for example Firefox with <a href=\"http://kb.mozillazine.or...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-06T12:32:10.430", "Id": "656", "Score": "5", "Tags": [ "javascript", "jquery" ], "Title": "Do I always have to return something in an anonymous function?" }
656
<p>The following code retrieve custom post types with their custom taxonomy.</p> <p>I'm just a beginner in PHP and I would like to know tips in order to improve readability and perhaps efficiency.</p> <p><strong>home.php:</strong></p> <pre><code>&lt;?php /** * Template Name: Home * @package WordPress * @subpackag...
[]
[ { "body": "<p>Some general tips</p>\n\n<ol>\n<li>Mind your nesting. Indent at new block-level tags always, and at line-level when it aids legibility</li>\n<li>Wrap where it makes sense: between arguments, at attributes, etc</li>\n<li>Be consistent!</li>\n</ol>\n\n<p>For example, this chunk</p>\n\n<pre><code> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-06T14:17:58.370", "Id": "657", "Score": "6", "Tags": [ "php", "wordpress" ], "Title": "modify custom loops to improve readability and efficiency for Wordpress?" }
657
<p><strong>Question + Desired Outcome</strong></p> <p>The code below works currently, however I'm not convinced the utilisation of an <code>Array</code> to iterate through numerous non-existent form fields is anywhere near efficient enough for my liking. Can this process be improved to effectively eliminate the first ...
[]
[ { "body": "<p>I managed to get around a generic array by pulling out the numbers from the name= attribute on each form field with the following:</p>\n\n<pre><code>// Pulls numbers from submitted \"ticket_fields\" which are stored in the name= attribute.\n// Used to iterate through the dynamically generated \"ti...
{ "AcceptedAnswerId": "697", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-07T11:12:54.570", "Id": "673", "Score": "6", "Tags": [ "javascript", "jquery", "validation", "form" ], "Title": "Basic form validation" }
673
<p>Is there a better way to accomplish the following?</p> <pre><code>/** * Performs an access check given a user. * * @param Cas_Acl_Sid $user The user or SID being checked. * @param Cas_Acl_Privilege $privilege The privilege to check. * @return int|null 1 if user access allowed, 2 if group access allowed, false ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-11T06:43:54.113", "Id": "1346", "Score": "3", "body": "could you supply a basic schema of the tables involved?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-15T23:34:13.100", "Id": "18898", "Score...
[ { "body": "<h2>Stored procedure</h2>\n\n<p>The query above is enough big to move it from the application layer to the database in the form of a stored procedure. It will be clearer and faster, the only disadvantage is that an SP has a hard dependency on the database type (MySQL, MSSQL, other).</p>\n\n<h2>Return...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-07T17:46:50.907", "Id": "676", "Score": "8", "Tags": [ "php", "zend-framework" ], "Title": "Large Zend_Db query" }
676
<p>I started to write a code with top-down tests. My first version, grow to something like this:</p> <pre><code>public class Worker { public void Execute(Foo foo) { //Do X on Foo //Do Y on Foo //Do Z on Foo //Get Bar from Foo //Do A on Bar //Do B on Bar //Do C on Bar } } </c...
[]
[ { "body": "<p>Have you considered using the Chain of Command instead of the visitor?</p>\n\n<pre><code>public interface IFooChainLink\n{\n void Execute(Foo foo);\n}\n\npublic interface IBarChainLink\n{\n void Execute(Bar bar);\n}\n\npublic class Worker\n{\n public Worker(IFooChainLink fooChain, IBarCha...
{ "AcceptedAnswerId": "679", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-07T18:29:30.293", "Id": "677", "Score": "4", "Tags": [ "c#", "design-patterns", "object-oriented" ], "Title": "Sorting Visitors" }
677
<p>This seems a bit wrong because there's a lot of business logic going on inside the bootstrapper. Is there a better way to accomplish what's going on here?</p> <pre><code>&lt;?php /** * Zend_Application Bootstrapper * * @copyright 2011 Case Western Reserve University, College of Arts and Sciences * @author Bill...
[]
[ { "body": "<p>You're right, there's a lot of work going on here.</p>\n\n<p>You probably need to be a bit more granular in your use of _init methods. You have navigation, ACL, view configuration and plugin registration all wrapped up in the _initView method. Try breaking these up into their own _init methods. Tr...
{ "AcceptedAnswerId": "882", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-07T18:47:18.450", "Id": "678", "Score": "3", "Tags": [ "php", "zend-framework" ], "Title": "Zend_Application bootstrapper" }
678
<p>I am trying to write a LISP interpreter in C#, so I started with a tokenizer. I haven't finished it yet (have to handle floating point numbers &amp; symbols), but I already rewrote it two times because I can't wasn't satisfied with design. </p> <pre><code> public class TokenizerException : System.ApplicationExce...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-07T23:45:22.237", "Id": "1211", "Score": "1", "body": "Are you sure you want to write a tokenizer in C#? Why not go with a language that is specifically designed to tokenize a stream. Such as LEX." }, { "ContentLicense": "CC BY...
[ { "body": "<p>1) I would remove <code>string val</code> from your base <code>Token</code> class, it smells like stringly typed code. Your inheritors may have more specific information, for example number token may provide a double instead of string<br>\n2) <code>public string val;</code> - Pascal case for publi...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-07T19:37:41.053", "Id": "680", "Score": "12", "Tags": [ "c#", "parsing" ], "Title": "LL(1) tokenizer for LISP" }
680
<p>I wrote this <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="noreferrer">sieve of Eratosthenes</a> with MPI, but I'm not sure if it's good enough. Should I use <code>MPI_Scatter</code> and <code>MPI_Gather</code> instead of collecting arrays of separate processes in the root process?</p> <p>Also, ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-08T01:19:18.410", "Id": "113429", "Score": "2", "body": "My advice: split up that main function." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-14T07:59:23.263", "Id": "121287", "Score": "0", "...
[ { "body": "<p>Since you tagged this question <a href=\"/questions/tagged/c%2b%2b\" class=\"post-tag\" title=\"show questions tagged &#39;c++&#39;\" rel=\"tag\">c++</a> I assume you would like a C++ approach also.</p>\n\n<p>I would suggest using <code>std::vector&lt;int&gt;</code> rather than an <code>int*</code...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-07T22:21:35.953", "Id": "683", "Score": "16", "Tags": [ "c++", "c", "primes", "sieve-of-eratosthenes", "mpi" ], "Title": "Eratosthenes sieve and MPI" }
683
<p>Here is the pertinent code:</p> <p>index.html</p> <pre><code>&lt;!-- DOM INITIALIZATION --&gt; &lt;script type="text/javascript"&gt; $().ready(function() { getThemeInfo(); if (themeSelect==2) { ReplaceJSCSSFile("css/skin1.css", "css/skin2.css", "css"); // overwrite CSS } AJAX_LoadResponseIntoElement("skin...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-13T13:00:16.900", "Id": "1403", "Score": "0", "body": "We are missing relevant details: please include the code of the functions used to fetch CSS from server. I noticed that script.readyState was not reliable in some versions of Opera...
[ { "body": "<p>I would suggest to take a different approach. It is complicated to get a callback for the complete loading of a CSS stylesheet loaded dynamically: see this Stack Overflow question for reference:</p>\n\n<p><a href=\"https://stackoverflow.com/questions/3078584/link-element-onload\">Is there anyway t...
{ "AcceptedAnswerId": "771", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-08T09:24:24.270", "Id": "687", "Score": "2", "Tags": [ "javascript", "css" ], "Title": "Do I need to use a callback function here, or is there another way?" }
687
<p>This sample code works fine, but it looks awful. How would you improve this?</p> <pre><code>data.Add(((Adress)(((OwnerIDList)owner.Adresses.Value)[0].Adress.Value)).FirstName.Value.ToString()); data.Add(((Adress)(((OwnerIDList)owner.Adresses.Value)[0].Adress.Value)).LastName.Value.ToString()); </code></pre> <p>Wh...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-08T11:46:22.027", "Id": "1217", "Score": "0", "body": "What are the types of Addresses and Address? Can you change them, perhaps using generics, to avoid having to cast altogether?" }, { "ContentLicense": "CC BY-SA 2.5", "...
[ { "body": "<p>at least I would extract a variable: </p>\n\n<pre><code>var address = (Adress)((OwnerIDList)owner.Adresses.Value)[0].Adress.Value;\ndata.Add(address.FirstName.Value.ToString());\ndata.Add(address.LastName.Value.ToString());\n</code></pre>\n\n<p>All these cast operations make me believe that your ...
{ "AcceptedAnswerId": "689", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-08T10:42:26.507", "Id": "688", "Score": "4", "Tags": [ "c#", "casting" ], "Title": "Multiple explicit cast operations" }
688
<pre><code>public boolean connectedOnGameServer = false; public final Object conGameServerMonitor = new Object(); public void connectedToGameServer() { synchronized (conGameServerMonitor) { if (connectedOnGameServer != false) throw new RuntimeException("Player connected twice"); connect...
[]
[ { "body": "<p>My code examples are excerpts. Don't copy/paste them, they are suggestions you can incorporate into your code. </p>\n\n<pre><code>if (waited &gt; GAMESERVER_CONNECT_TIMEOUT &amp;&amp; connectedOnGameServer)\n{\n throw new RuntimeException(\"Client didn't connect to game server in time (\" + GAME...
{ "AcceptedAnswerId": "693", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-08T11:57:36.830", "Id": "690", "Score": "7", "Tags": [ "java", "synchronization", "timeout", "locking" ], "Title": "Waiting for game server connection" }
690
<p>I'm writing a quiz application in PHP and am querying the DB for questions and their associated answers. I then wrangle the result set into a usable array for my front end. However, it always seems like a wrestling match and I'm wondering if I could have got to my desired array structure more efficiently.</p> <p>Wh...
[]
[ { "body": "<p>From the structure of the sql query, it looks like your output is going to have duplicate rows, due to the fact that a single question can have multiple answers. This means you're going to have to do some screwy stuff, like what you did with the nested <code>foreach</code> loops. I would recommend...
{ "AcceptedAnswerId": "739", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-08T12:57:24.190", "Id": "692", "Score": "6", "Tags": [ "php", "sql", "array" ], "Title": "Extract a joined result set into a parent-child hierarchy" }
692
<p>I recently had a discussion in the forum of an API, because they changed an exception from checked to unchecked. I believed it needs to be checked, because it is recoverable. The arguments of "the other side" were verbosity and tediousness of try/catch or throws.</p> <p>If it were purely theoretical question, I'd b...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-08T17:43:36.367", "Id": "1231", "Score": "1", "body": "if you really want to recover from an unchecked exception, you can still explicitly catch it right?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-08T...
[ { "body": "<p>Ok, I'm going to assume that this is a honest-to-goodness exceptional case, that is extremely unlikely to happen. It isn't like java.sql, that throws an exception when opening a connection fails, which can happen very easily and should be handled by returning <code>null</code>.</p>\n\n<p>If there ...
{ "AcceptedAnswerId": null, "CommentCount": "21", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-08T17:37:42.390", "Id": "698", "Score": "9", "Tags": [ "java", "api", "exception", "exception-handling" ], "Title": "Providing unchecked exception \"wrapper\" interfaces for an ...
698
<p>I have a rectangle with size <code>w</code> and height <code>h</code>. Now I want to split this rectangle into <code>n</code> new rectangles that are as similar as possible to a square. Afterwards I'd like to calculated the center of each square.</p> <pre><code>public static List&lt;Point&gt; getCenters(int number,...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-09T02:53:11.713", "Id": "1270", "Score": "0", "body": "Are you sure your code does what you say it does? The best way to place 4 rectangles in a 2x8 rectangle would be if each one was 2x2 and thus square. However your algorithm would p...
[ { "body": "<p>Your first step should be to use meaningful variable names, even for your looping variables. I've never looked at this code before. I have no idea what it's doing. When other members of your team (if you have one) look at this code, they'll have no idea what's happening. If you come back to this c...
{ "AcceptedAnswerId": "704", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-09T01:09:51.197", "Id": "702", "Score": "5", "Tags": [ "c#", "algorithm", "computational-geometry" ], "Title": "Find the center of n squares which together build a rectangle" }
702
<p>Here's a function that interpolates between a given value and a value fetched out of a legacy serialization buffer:</p> <pre><code>template&lt;typename T&gt; T interpolate(Buffer&amp; buffer, const T currentValue, const float prop) { T bufferValue; buffer.readT(&amp;buferValue); return currentValue + (b...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-09T16:10:10.930", "Id": "1286", "Score": "2", "body": "Is there a particular reason you don't want to pass ints, floats, etc. by reference?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-09T16:20:08.267", ...
[ { "body": "<p>If I understand your question correctly, using the <code>RefTrait</code> policy in your second solution is acceptable but you want to avoid specifying template parameters from the client code that's using it.</p>\n\n<p>If so then perhaps one possible idea is to create an inline wrapper function ar...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-09T15:46:57.603", "Id": "706", "Score": "9", "Tags": [ "c++", "serialization" ], "Title": "Interpolating given value and legacy value from serialization buffer" }
706
<p>I am building up a basic folder tree with a list of strings in the form /root/node/node/node. Here is the basic algorithm I am using currently to build this collection and fill in my <code>TreeGridView</code>:</p> <pre><code>// This method gets the list of folders and leaves, then trims out any folder paths // that...
[]
[ { "body": "<p>One improvement that comes to mind is:</p>\n\n<pre><code>bool found = false;\nforeach(var item in finalList)\n{\n if (item.StartsWith(path, StringComparison.Ordinal))\n {\n found = true;\n break;\n }\n}\n</code></pre>\n\n<p>Finding out whether a condition is met for any item...
{ "AcceptedAnswerId": "709", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-09T15:50:05.563", "Id": "707", "Score": "9", "Tags": [ "c#", "tree" ], "Title": "Basic folder tree with a list of strings" }
707
<p>For interop purpose, this is something that I always do (C#):</p> <pre><code> public static extern BigObject InteropWithCPlusPlus(); </code></pre> <p>where <code>BigObject</code> is ( you guess it) a big object, it's not something small like <code>int</code>, or <code>double</code>.</p> <p>Now, is this a good pra...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-09T16:28:11.123", "Id": "1289", "Score": "0", "body": "This site is for reviewing code (which means we should see some code and implementation in the question). The question above is asking about best practices, which seems more in lin...
[ { "body": "<p>I don't think there would be too much of a difference. You have to use a reference anyway, because non-native types are stored as references. On x86 processors, returns are placed in register A, which is limited length. So, your C++ program would be either returning a reference to <code>BigObject<...
{ "AcceptedAnswerId": "710", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-09T15:57:29.487", "Id": "708", "Score": "5", "Tags": [ "c#", "comparative-review" ], "Title": "Interop: Return Parameter Method as Void" }
708
<p>Could this be made more efficient, and/or simpler? It's a path-finding function. It seems to work, but do you see any potential cases where it could fail?</p> <pre><code>// Searches for a path from [start] to [end]. // Predicate [passable] should take an std::pair&lt;int,int&gt; and return true if the node is pas...
[]
[ { "body": "<pre><code>// keep track of visited nodes so we don't visit them twice\nstd::vector&lt;node&gt; visited_nodes;\nauto visited = [&amp;visited_nodes] (node n) {\n return std::find(visited_nodes.begin(), visited_nodes.end(), n) != visited_nodes.end();\n};\n</code></pre>\n\n<p>Every time you have to c...
{ "AcceptedAnswerId": "750", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-09T21:06:39.297", "Id": "714", "Score": "13", "Tags": [ "c++", "algorithm", "c++11", "pathfinding" ], "Title": "Path finding function" }
714
<p>I've written this rather naïve branch-and-bound based IP solver.</p> <p>Are there any obvious JavaScript optimisations that could speed it up? I am not looking for asymptotically better algorithms, just simple speed optimisations effective on problem sizes with 5-6 variables and <code>minSize</code> values up to a...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T22:56:04.070", "Id": "1332", "Score": "2", "body": "I'll try to take a more serious look at this if it's still not answered when I have more time, but for starters, anywhere you can use \"===\" instead of \"==\" would be good. \"==\...
[ { "body": "<p>Nowadays we have great tools at our disposal, one of them is <a href=\"http://code.google.com/closure/compiler/\" rel=\"noreferrer\">The Closure Compiler</a> from Google, which is a tool for making JavaScript download and run faster. It parses your JavaScript, analyzes it, removes dead code and r...
{ "AcceptedAnswerId": "1365", "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-10T00:34:51.283", "Id": "716", "Score": "6", "Tags": [ "javascript", "algorithm", "optimization", "integer" ], "Title": "Branch-and-bound based IP solver" }
716
<p>I've got some legacy code which I need to maintain and its got this function which <strong>works perfectly fine</strong>, but I'm trying to understand if it is working using acceptable coding practices or not... I am trying to understand if it is safe and secure to operate the site with the function as-it-is.</p> <...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T09:10:57.147", "Id": "1302", "Score": "0", "body": "is this code running on a php4 or php5 interpreter?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T10:37:20.730", "Id": "1303", "Score": "0...
[ { "body": "<p>Simply put, this code fails a lot best practices also contains massive security issues.\nSuggestion to improve for best practices:</p>\n\n<blockquote>\n <p><code>$GLOBALS[\"HTTP_POST_VARS\"]</code> is <strong>deprecated</strong> in favor of <code>$_POST</code></p>\n</blockquote>\n\n<p>So you loop...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T08:04:17.733", "Id": "719", "Score": "5", "Tags": [ "php", "mysql" ], "Title": "Generalized PHP function for editing data in a table" }
719
<p>I'm going over the interview questions from "<a href="http://rads.stackoverflow.com/amzn/click/145157827X" rel="noreferrer">Cracking the Coding Interview</a>" and one of the chapters (Chapter 7) deals with Object Oriented Design (OOD). The requirements for one of the problems are as follows:</p> <blockquote> <p>I...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T14:15:18.533", "Id": "1312", "Score": "0", "body": "I don't see a `getCallHandler`... :)" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T18:39:20.303", "Id": "1321", "Score": "0", "body": ...
[ { "body": "<p>In short, in my opinion, I think you've done too much.</p>\n\n<p>It seems like your design has gone beyond a design for the initial interview question and into an exercise of your own.</p>\n\n<p><strong>However</strong>, I don't have the book you're reading, so you may be going off more than just ...
{ "AcceptedAnswerId": "730", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T10:21:06.773", "Id": "720", "Score": "10", "Tags": [ "c#", "interview-questions" ], "Title": "Review of object oriented design for a sample interview question" }
720
<p>I want my application to support multiple UI-languages (aka i18n). To do so, I have built the static class below, to automatically translate the form and all its contents to the desired language. It looks into a resource file for the user's Culture, and replaces the .Text properties of the controls with the strings ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T11:13:50.567", "Id": "1304", "Score": "0", "body": "Please, someone with >150 reputation should also create the tags translation or i18n and tag this question with them. Thanks!" }, { "ContentLicense": "CC BY-SA 2.5", "C...
[ { "body": "<p>You can avoid the overloading by using the common superclass on <code>ToolStripItem</code>:</p>\n\n<pre><code>static private void Translate(ToolStripItem o, string lang)\n{\n string str = TranslateString(o.Name, lang);\n if (str != null)\n c.Text = str;\n}\n</code></pre>\n\n<p>Unfortunate...
{ "AcceptedAnswerId": "745", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T11:12:42.267", "Id": "721", "Score": "8", "Tags": [ "c#", ".net" ], "Title": "Automatic translation of forms" }
721
<p>I use named scopes all over the place. </p> <p>When I have a named scope that deals with two different tables, I tend to query the second table in a sub-query. That way, if I mix and match with other tables I don't need to worry about reusing a table alias or having ambiguous column names that only appear in bizarr...
[]
[ { "body": "<p>You want to use what Rails calls eager loading. This is done with the <code>:include</code> parameter in your <code>AR</code> call. Add it to your lambda block.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
{ "AcceptedAnswerId": "1074", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-10T21:47:11.813", "Id": "731", "Score": "8", "Tags": [ "ruby", "sql", "mysql", "ruby-on-rails" ], "Title": "Avoiding sub-queries in named scopes" }
731
<p>I've implemented the <strong><code>GroupBy</code></strong> extension method for <strong><code>IEnumerable&lt;T&gt;</code></strong> type as an excersise to deep a little more into <strong>LINQ</strong>.</p> <p>What do you think about the source code?</p> <p><strong>Code:</strong> </p> <pre><code>static IEnumerabl...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-11T08:57:10.373", "Id": "1348", "Score": "1", "body": "Do not see anything related to `SortBy`, is your topic correct?" } ]
[ { "body": "<pre><code>foreach (var x in dict)\n{\n yield return new Grouping&lt;TKey, TElement&gt;(x.Key, x.Value);\n}\n</code></pre>\n\n<p>Could change to:</p>\n\n<pre><code>return dict.Select(x =&gt; new Grouping&lt;TKey, TElement&gt;(x.Key, x.Value));\n</code></pre>\n\n<p>It's a little thing, but I would ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T22:28:31.387", "Id": "732", "Score": "8", "Tags": [ "c#", "linq" ], "Title": "Implementation of GroupBy<TKey, TElement> in .NET" }
732
<p>The CMS I use uses the Xalan XSLT processor which is a XSLT version 1.0 processor. Editors who use WYSIWYG fields within the CMS can save content that will look like either:</p> <pre><code>&lt;story&gt; &lt;p&gt;Story Text which may have &lt;em&gt;formatting&lt;/em&gt;.&lt;/p&gt; &lt;/story&gt; </code></pre> <...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-11T10:13:37.173", "Id": "1350", "Score": "0", "body": "I don't know how complex the \"real\" XML will be, but if you only have XHTML wrapped in `<story>` elements you could simply replace those with `<div>`s. If it's more complicated i...
[ { "body": "<p>You should change your mindset when working with XSLT: look at it as a functional language, where you declare rules for the transformation of elements. Think about it in terms of events: when a p element is found in input, I expect this and that in the output.</p>\n\n<p>First, regarding the defini...
{ "AcceptedAnswerId": "758", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T23:13:04.567", "Id": "735", "Score": "6", "Tags": [ "html", "xml", "xslt" ], "Title": "Using XSLT to turn content of WYSIWYG stored in XML into HTML" }
735
<p>I've written a lengthy procedure that I call a few times to apply filters defined by the customer to a table, as I didn't see how I could turn my <strong>column name string</strong> into a <strong>LINQ column</strong> and how I could turn my <strong>action string</strong> into an <strong>action on a string</strong> ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-12T17:39:42.400", "Id": "1386", "Score": "0", "body": "Is there any reason you went for a ref parameter rather than returning IQueryable<TempArticle>?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-12T21:5...
[ { "body": "<p>I don't see anything LINQ related that could be done here... but it looks to me like all the contents of all the IF statements are the same. Perhaps that should be extracted into a method?</p>\n\n<p>Also: </p>\n\n<pre><code>ToLower().StartsWith(actionValue) == action.AddOrKill\n</code></pre>\n\n<p...
{ "AcceptedAnswerId": "749", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-11T13:23:35.370", "Id": "744", "Score": "9", "Tags": [ "c#", "linq" ], "Title": "Applying filters to a table" }
744
<p>The main view in my (toy!) Todo app is, of course, to display the list of tasks. These are grouped by some criterion, and the <code>tasks</code> structure below is actually a list of pairs (header, list of tasks).</p> <pre><code>{% for tasks in tasks %} &lt;p class="list-header"&gt;{{ tasks.0 }}:&lt;/p&gt; ...
[]
[ { "body": "<p>I would move that conditional logic in the span tags to the view. Have your view pass the template a modified version of <code>tasks.1</code>, where each task instead of being the original datum is now the modified version that the template could use raw. For example, instead of passing your templ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-11T14:54:59.473", "Id": "746", "Score": "5", "Tags": [ "css", "django", "to-do-list", "django-template-language" ], "Title": "Todo app for displaying a list of tasks" }
746
<p>I need help to refactor my code. I usually had a hard time figuring out how to make my code reusable.</p> <p>I have an XML file that hold the data for each Tag element. Tag element should have child nodes LastClocked, and TotalClocked. I first thought of creating Tag object and do serialization. But, I found Linq t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-10-05T13:33:39.237", "Id": "195374", "Score": "0", "body": "As we all want to make our code more efficient or improve it in one way or another, try to write a title that summarizes what your code does, not what you want to get out of a re...
[ { "body": "<p>Your code seems very procedural - you're worrying about implementing how things will be done before you think about what those things are and how you'd like to use them. You don't have any properties, just methods, which I don't particularly like.</p>\n\n<p>From what I understand you want to writ...
{ "AcceptedAnswerId": "760", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-13T03:37:56.223", "Id": "759", "Score": "4", "Tags": [ "c#", "linq", "xml", "wpf" ], "Title": "Inserting and updating time spans in XML" }
759
<p>The code pretty much explains what I am doing here. Just wondering if anyone can think of a better way.</p> <pre><code>public class AttachmentQuery { /// &lt;summary&gt; /// Initializes a new instance of the &lt;see cref="AttachmentQuery"/&gt; class. /// &lt;/summary&gt; /// &lt;param name="type"&gt...
[]
[ { "body": "<p>How about adding an extension method to IAttachmentSpecification, such as</p>\n\n<pre><code>public static class AttachmentSpecificationExtensions\n{\n public static IAttachmentSpecification And(this IAttachmentSpecification orig, IAttachmentSpecification spec)\n {\n if (orig is Nul...
{ "AcceptedAnswerId": "769", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-13T21:56:47.670", "Id": "762", "Score": "6", "Tags": [ "c#", "linq" ], "Title": "Better ways to build a linq specification for querying or is this the only way?" }
762
<p>Below are two solutions to the FizzBuzz problem in Python. Which one of these is more "Pythonic" and why is it more "Pythonic" than the other?</p> <p>Solution One:</p> <pre><code>fizzbuzz = '' start = int(input("Start Value:")) end = int(input("End Value:")) for i in range(start,end+1): if i%3 == 0: ...
[]
[ { "body": "<p>From my brief experience with Python, I would say the second is more Pythonic as it takes advantage of the Python lists and the first is just appending to strings which causes the output to be a wee bit ugly and clumped together. Although you could eliminate an entire extra iteration by appending...
{ "AcceptedAnswerId": "768", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-13T22:06:54.343", "Id": "763", "Score": "14", "Tags": [ "python", "comparative-review", "fizzbuzz" ], "Title": "Two FizzBuzz solutions" }
763
<p>Often I generate long lines of code such as the following...</p> <pre><code>shippedItems.AddRange(OrderItem.Fetch(market: this.MARKET, shipConfirmState: ORDERITEMSHIPCONFIRMSTATE.NONE, orderPlacedAfter: serverTime.AddDays(-7), orderPlacedBefore: serverTime.AddHours(-85))); </code></pre> <p>... which adds the resul...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-14T18:37:43.197", "Id": "1428", "Score": "2", "body": "There's nothing wrong with creating a variable that is only used once. Sometimes, the required indentation is just too much." }, { "ContentLicense": "CC BY-SA 2.5", "Cr...
[ { "body": "<p>I would break it up something like this:</p>\n\n<pre><code>shippedItems.AddRange(\n OrderItem.Fetch(market: this.MARKET,\n shipConfirmState: ORDERITEMSHIPCONFIRMSTATE.NONE,\n orderPlacedAfter: serverTime.AddDays(-7),\n orderPlacedBefore: ...
{ "AcceptedAnswerId": "773", "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-14T15:41:32.040", "Id": "772", "Score": "9", "Tags": [ "c#" ], "Title": "How to break up long lines of code. (Example Line: Results of method call added to list.)" }
772
<p>I've created and I manage a point of sale web application built in PHP which has thus far followed no clear guidelines or methodology for development; it's operation is completely procedural. In turn, because the department that's using it requests new and different features like it's a Las Vegas buffet, the softwar...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-27T04:02:54.270", "Id": "1829", "Score": "1", "body": "Just a style thing, but it seems really weird having verbs for class names. Classes describe objects, which are inherently \"things\" (ie: nouns)." }, { "ContentLicense": ...
[ { "body": "<p>The first comment is that you have six functions in <code>manageReports</code> which are identical, which each call a seventh one, <code>createReports</code>. While I understand that you mean to have logical function naming, given that you have all the logic as to when each program should be made ...
{ "AcceptedAnswerId": "787", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-14T16:55:21.320", "Id": "776", "Score": "10", "Tags": [ "php", "mysql", "classes", "object-oriented" ], "Title": "Object Paradigm for PHP, Practice in Design" }
776
<p><a href="http://stackoverflow.com/tags/c%2b%2b/info">From the C++ tag wiki on Stack Overflow</a>:</p> <h3>What is C++?</h3> <p><a href="http://en.wikipedia.org/wiki/C++" rel="nofollow noreferrer">C++</a> is a statically-typed, free-form, (usually) compiled, multi-paradigm, intermediate-level, general-purpose progr...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-02-14T19:00:02.587", "Id": "779", "Score": "0", "Tags": null, "Title": null }
779
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. This tag should be used for any question which requires knowledge or expertise with the C++ programming language. This is a general tag which is used for any of the C++ language standards (C++98, C++11, C++17, etc.). T...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-14T19:00:02.587", "Id": "780", "Score": "0", "Tags": null, "Title": null }
780
<p>I have a parser for CNF formulas in <a href="http://logic.pdmi.ras.ru/~basolver/dimacs.html" rel="nofollow">Dimacs format</a>, which is very slow. Any suggestion on how to improve its speed? I did some profiling and I might have to replace <code>Scanner</code>. Is there anything faster?</p> <p>A possible input for ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-08T19:26:57.903", "Id": "3021", "Score": "0", "body": "Are you sure it's the parsing that is the bottleneck here? Simply reading data from disk is an expensive operation, so, it could be just that." }, { "ContentLicense": "CC B...
[ { "body": "<p>Use a <a href=\"http://download.oracle.com/javase/1.4.2/docs/api/java/io/BufferedInputStream.html\"><code>BufferedInputStream</code></a> to speed up the disk access. If that's not enough, you can read the file line-by-line and use <a href=\"http://download.oracle.com/javase/1.4.2/docs/api/java/lan...
{ "AcceptedAnswerId": "788", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-15T00:04:18.437", "Id": "784", "Score": "7", "Tags": [ "java", "parsing" ], "Title": "Parser for CNF formulas" }
784
<p>The following is like the Unix "tail" program. It was assigned as an exercise in Chapter 5 of Kernighan &amp; Ritchie's <em>The C Programming Language</em>. Because I've only read through most of Chapter 5, I'm still unfamiliar with certain topics, such as malloc(), which may have been more appropriate to use, I don...
[]
[ { "body": "<p>Interesting design. Performance could probably be improved by allocating a couple of large buffers, and reading large blocks of input alternately into the two buffers until EOF is encountered. At that point, count backward through the two blocks until the proper number of newlines have been foun...
{ "AcceptedAnswerId": "799", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-15T15:29:26.360", "Id": "790", "Score": "16", "Tags": [ "beginner", "c" ], "Title": "Simple C Implementation for Unix \"tail\" Command" }
790
<p>I had a question about using the modulus operator in Python and whether I have used it in a understandable way. </p> <p>This is how I've written the script:</p> <pre><code>#sum numbers 1 to 200 except mults of 4 or 7 def main(): sum = 0 for x in range(200+1): if (x % 4 and x % 7): #is this bad??? ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-16T02:45:46.707", "Id": "1471", "Score": "2", "body": "Omitting the `!= 0` is fine, even preferable. Most everyone understands that non-zero numbers are `True` in most high-level languages, so you're not exploiting some tough-to-remem...
[ { "body": "<p>I think your use of <code>%</code> is fine, but that could be simplified to:</p>\n\n<pre><code>def main():\n print sum([i for i in range(201) if i % 4 and i % 7])\n\nif __name__ == '__main__':\n main()\n</code></pre>\n\n<p><em>Edit:</em> Since I had a bug in there, that's a pretty clear indi...
{ "AcceptedAnswerId": "795", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-15T22:37:23.323", "Id": "794", "Score": "10", "Tags": [ "python" ], "Title": "Print sum of numbers 1 to 200 except mults of 4 or 7 in Python" }
794
<p>Is there a way to do this using parameters so the value is automatically converted to whatever datatype the keyfield has in the datatable?</p> <p>This code should be reusable for future bulk update applications hence the constant and the check on multiple datatypes.</p> <pre><code>private const string DBKEYFIELDNA...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-16T08:35:45.520", "Id": "1484", "Score": "0", "body": "@Peter, where did csvKeyValue come from? Who generates it? Do you have control over it? From its name, it sounds like it was read from a csv file at some point, and whoever read...
[ { "body": "<p>A few comments:</p>\n\n<ul>\n<li>This method does way too much. It is difficult to understand and will be difficult to debug and maintain. Break it down into smaller methods that each have a single responsibility.</li>\n<li>Use curly braces after your if and else statements. This improves reada...
{ "AcceptedAnswerId": "801", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-16T08:07:25.013", "Id": "800", "Score": "6", "Tags": [ "c#", "csv" ], "Title": "Strongly-typed reading values from CSV DataTable" }
800
<p>I have some small applications that I want to secure. I've been using the following setup that <em>I think</em> is fairly safe, but I've never been able to set my mind at ease that it really is. Could you give me some reviews on the security of this? It doesn't need super-security like credit card data, but I supp...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-16T19:35:07.273", "Id": "64510", "Score": "0", "body": "This should be relevant: [How To Safely Store A Password](http://codahale.com/how-to-safely-store-a-password/ \"How To Safely Store A Password\") (bcrypt)" }, { "ContentLi...
[ { "body": "<p>Assuming that you also have user authenticated application behavior check against the open session before it executes, your security process appears reasonably solid. I would personally feel a little uncomfortable storing my salt in the user's cookie - though excluding it in your setup may prove p...
{ "AcceptedAnswerId": "925", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-16T14:35:29.563", "Id": "802", "Score": "8", "Tags": [ "php", "mysql", "security", "authentication", "session" ], "Title": "Securely handling a password protected applicatio...
802
<p>Here's a method I made that's supposed to print out multiples of any numbers up to any quantity:</p> <pre><code>def DisplayMultiples(multiplesOf, count) i = multiplesOf while i &lt;= count if i % multiplesOf == 0 puts i end i += 1 end end </code></pre> <p>Any suggestions on how to improve t...
[]
[ { "body": "<p>One important note regarding naming in ruby:</p>\n\n<p>The <strong>syntax</strong> in ruby is that constants (including class and module names) have to start with capital letters and local variables have to start with lower case letters. Instance, class and global variables must start with their r...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-16T14:43:54.687", "Id": "803", "Score": "12", "Tags": [ "beginner", "ruby" ], "Title": "Displaying the multiples of a given number" }
803
<p>The below is \$O(n^3)\$. I'm sure there is a way to improve this..</p> <pre><code>//vector&lt;string&gt; flight_path; given as parameter //vector&lt;int&gt; flight_number; need to fill //vector&lt;segment&gt; flight_segments; known, contains segments (dep, arr, flightnum) //Purpose of the function is to take in a ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-17T03:20:58.107", "Id": "1519", "Score": "0", "body": "Your inner loops don't seem to find segment chains correctly. The first `if()` tests if the flight covers the current path segment." }, { "ContentLicense": "CC BY-SA 2.5", ...
[ { "body": "<p>If I understand this, you have a directed graph that consists of a series of flight segments. You are given a series of flight segments, say, A -> B -> C, that makes up a flight path.</p>\n\n<p>In addition, you have a group of flight numbers. The flight numbers correspond to paths. Flight number 1...
{ "AcceptedAnswerId": "811", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-16T16:49:59.310", "Id": "808", "Score": "14", "Tags": [ "c++", "optimization" ], "Title": "Retrieving list of flight numbers from flight path" }
808
<p>I am primarily a Python programmer and have finally ditched the IDE in favour of vim and I will admit, I am loving it !</p> <p>My <code>vimrc</code> file looks like this:</p> <pre><code>autocmd BufRead,BufNewFile *.py syntax on autocmd BufRead,BufNewFile *.py set ai autocmd BufRead *.py set smartindent cinwords=if...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-21T19:53:30.063", "Id": "1646", "Score": "0", "body": "Hi Henry, welcome to the site. This really isn't a question for Code Review though, as this site is for reviewing working code. It is most likely better on Stack Overflow." }, ...
[ { "body": "<p>I like to add the following:</p>\n\n<pre><code>\" Allow easy use of hidden buffers.\n\" This allows you to move away from a buffer without saving\nset hidden\n\n\" Turn search highlighting on\nset hlsearch\n\n\" Turn on spelling\n\" This auto spell checks comments not code (so very cool)\nset spel...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-16T17:48:55.890", "Id": "810", "Score": "11", "Tags": [ "python" ], "Title": "Review the vimrc for a Python programmer" }
810
<p>I have a function that takes a column title, and a response.body from a urllib GET (I already know the body contains text/csv), and iterates through the data to build a list of values to be returned. My question to the gurus here: have I written this in the cleanest, most efficient way possible? Can you suggest any ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-16T19:13:14.887", "Id": "1508", "Score": "1", "body": "Tip: Don't use a blanket `except`, you will catch ALL exceptions rather than the one you want." } ]
[ { "body": "<p>My suggestions:</p>\n\n<pre><code>def _get_values_from_csv(self, column_title, response_body):\n # collect results in a set to eliminate duplicates\n results = set()\n\n # iterate the DictReader directly\n for dic in csv.DictReader(response_body.split(\"\\r\\n\")):\n # only add ...
{ "AcceptedAnswerId": "817", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-16T19:08:41.697", "Id": "812", "Score": "9", "Tags": [ "python", "csv" ], "Title": "Getting lists of values from a CSV" }
812
<p>I was playing around with LINQ and I came up with the following idea for composing locks taking advantage of C# Monadic syntax. It seems too simple, so I thought let me post it on StackExchange and see if anyone can quickly spot any major problems with this approach.</p> <p>If you comment the lock inside the atomic...
[]
[ { "body": "<p>I'm trying to compile your code: </p>\n\n<ul>\n<li>What kind of class is Unit? Do I need to reference an additional assembly?</li>\n<li>Run at the end of <code>Enumerable.Range(1, 100000).AsParallel().Select(_ =&gt; accA.TransferAndReverse(accB, 100).Execute(syncObject)).Run();</code> seems to be...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-16T21:07:12.450", "Id": "819", "Score": "3", "Tags": [ "c#", "linq", "multithreading", "locking" ], "Title": "Composable Locks using LINQ. Can anyone see any problem with this ?"...
819
<p>I have created a small server program that encrypts text using a named pipe:</p> <pre><code>#define UNICODE #define WIN32_WINNT 0x0500 #include &lt;stdio.h&gt; #include &lt;windows.h&gt; #include &lt;signal.h&gt; HANDLE hPipe; DWORD WINAPI ServerProc(LPVOID lpVoid) { hPipe = CreateNamedPipe(L"\\\\.\\pipe\\...
[]
[ { "body": "<p>It depends on what you want the server to do when an interrupt is sent.</p>\n\n<p>If you really want the program to stop when it is sent an interrupt, even though it is a service (Windows) or daemon (Unix), then what you did works. If, however, the program was run with settings to ignore interrup...
{ "AcceptedAnswerId": "825", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-17T08:12:40.473", "Id": "823", "Score": "5", "Tags": [ "c", "file-system", "windows", "server", "signal-handling" ], "Title": "Handling SIGINT signal for a server program" }
823
<p>I am looking for any possible improvements on this tagging widget.</p> <p>I ask for special attention to be paid to my <em>blur</em> handler in the event of a autocomplete option being specified but any optimizations or critiques are welcome.</p> <pre> Demo: <a href="http://webspirited.com/tagit">http://webspi...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-18T20:23:52.923", "Id": "1572", "Score": "0", "body": "4 +votes and no answers/comments? Does that mean that this is almost max-optimized?" } ]
[ { "body": "<p>Cocky comment saying that this is almost max-optimized deserves a harsh review. </p>\n\n<p>I don't know anything about the <code>$.widget</code>, from my brief look of it none of my comments can be ignored because it's \"Something you need to do to play nicely with the $.widget\".</p>\n\n<p>Admitt...
{ "AcceptedAnswerId": "859", "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-17T09:30:50.847", "Id": "824", "Score": "8", "Tags": [ "javascript", "optimization", "jquery", "jquery-ui" ], "Title": "Looking for improvements on my jQuery-UI tagging widget" ...
824
<p>I was writing a piece of code (a custom <code>EntityProcessor</code> for Solr, but that isn't too relevant) designed to break lines of input based on a string delimiter (<code>toMatch</code> below).</p> <p>Characters are read from a stream and then passed to <code>addChar</code>.<br> The assumption is that each cha...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-18T22:35:34.030", "Id": "1577", "Score": "1", "body": "Depends on the statistics of toMatch. [Knuth-Morris-Pratt](http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm) might be an improvement if the delimiters are ...
[ { "body": "<p>There are more-sophisticated algorithms you can use, depending on the input and the search string. Even keeping the \"one character at a time\" interface though, there are optimizations to the implementation. Someone linked to KMP in a comment to your question - that's a good way to go if you can ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-17T18:18:47.860", "Id": "827", "Score": "9", "Tags": [ "java", "stream" ], "Title": "Implementing a fast 'split' function on a stream of characters in Java" }
827
<p>In my spare time I decided to write a program that would systematically identify prime numbers from 2 to 18,446,744,073,709,551,615. This is for fun and learning, as I know it will take too long to actually ever reach the upward value, but I'm using this to explore parallel processing. I know this is not a traditi...
[]
[ { "body": "<p>Hmmmm... To speed it up, I'd look into alternate Prime Number tests, like <a href=\"http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test\" rel=\"nofollow\">Miller Rabin Test</a> or <a href=\"http://en.wikipedia.org/wiki/AKS_primality_test\" rel=\"nofollow\">AKS Test</a></p>\n\n<p>Here ...
{ "AcceptedAnswerId": "18565", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-17T21:01:51.293", "Id": "828", "Score": "39", "Tags": [ "c#", "primes" ], "Title": "Calculation of prime numbers making use of Parallel.ForEach" }
828
<p>The general idea of the code is that I have a <code>+</code> or <code>-</code> icon (<code>".trigger"</code>) that is click-able and will expand or collapse the content (<code>".cont"</code>) directly following it (there are many of there expand/collapse pairs). I also have a <code>span</code>(<code>"#expandAll"</c...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-18T13:34:24.267", "Id": "1552", "Score": "0", "body": "@Jonathan, ha, nothing really. It just seems that everyone these days starts 'programming' with html, css, and JQuery." }, { "ContentLicense": "CC BY-SA 2.5", "Creatio...
[ { "body": "<p>I've refactored your code and added comments to explain certain things.</p>\n\n<pre><code>// We can shorten this from document.ready(...) to $(...) \n// Internally, jQuery will add the passed in function to a list\n// of handlers that will be invoked when the document is ready.\n$(function() {\n ...
{ "AcceptedAnswerId": "831", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-17T21:19:39.140", "Id": "830", "Score": "14", "Tags": [ "javascript", "jquery", "beginner" ], "Title": "Clickable icon for expanding/collapsing content" }
830
<p>I'm trying to apply <code>string.strip()</code> to all the leafs that are strings in a multidimensional collection, but my Python is a bit rusty (to say the least). The following is the best I've come up with, but I suspect there's a much better way to do it.</p> <pre><code>def strip_spaces( item ): if hasattr(...
[]
[ { "body": "<pre><code>elif isinstance( item, dict ):\n return dict([(value,strip_spaces(value)) for value in item])\n</code></pre>\n\n<p>This will transform <code>{ ' a ': ' b ' }</code> into <code>{' a ': 'a' }</code>, which I suspect is not what you want. How about:</p>\n\n<pre><code> return dict(...
{ "AcceptedAnswerId": "844", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-02-18T02:52:08.510", "Id": "834", "Score": "12", "Tags": [ "python", "strings" ], "Title": "Traversing a multidimensional structure and applying strip() to all strings" }
834