body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I just finished rewriting my Router class. Any input would be much appreciated.</p> <p>The class routes URLs based on a <code>site.com/class/method/param/param/etc</code> syntax.</p> <p>One thing I've done differently is created a mechanism for basic templates to be loaded directly without the need for a controlle...
[]
[ { "body": "<p>This is really good, there are only a few things I would point out.</p>\n\n<p>Why are you using <code>is_null()</code>? All this does is check for a null value. It would be equivalent to doing <code>! $uri</code>, except that would have the added benefit of checking for FALSE. Check out <code>filt...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T21:22:12.367", "Id": "11286", "Score": "4", "Tags": [ "php", "object-oriented", "mvc", "url-routing" ], "Title": "Object Oriented PHP Url Router" }
11286
<p>I am relatively new to jQuery and this is one of the first attempts to use it. Tell me if I am using it wrong:</p> <p>This is the main code that toggles everything:</p> <pre><code>$(function(){ $("#tree li").hide();//collapse everything by default $("#tree span").click(function(){ $(this).toggleCl...
[]
[ { "body": "<p>That is not valid html.</p>\n\n<p>The only thing you can put inside a <code>&lt;ul&gt;</code> tag is <code>&lt;li&gt;</code> tags.</p>\n\n<p>With that in mind, this would be much better (change the selector as necessary):</p>\n\n<pre><code>$(\"#tree span\").click(function () {\n $(this).toggleC...
{ "AcceptedAnswerId": "11297", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T23:52:33.850", "Id": "11289", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Collapsable Tree" }
11289
<p>I'm creating a <a href="https://github.com/kentcdodds/Java-Helper" rel="nofollow">Java Helper Library</a> with helpful static methods. I find myself needing to call <code>...getResource(...)</code> or <code>...getResourceAsStream(...)</code> in several instances and I'm wondering what's the best practice for this. I...
[]
[ { "body": "<p>I would prefer the second one. The others will bite if the library runs inside an OSGi container.</p>\n\n<p>Furthermore, I would</p>\n\n<ol>\n<li>pass <code>UTF-8</code> character encoding to the constructor of the <code>InputStreamReader</code>. Otherwise it will use the system encoding which var...
{ "AcceptedAnswerId": "11294", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T00:04:02.870", "Id": "11290", "Score": "3", "Tags": [ "java", "comparative-review" ], "Title": "Which class is best to call .getResource on?" }
11290
<p>I'm not sure whether I should be throwing exceptions in the below model code (and rescuing in the controller - rescues not implemented below) or returning <code>nil</code> (in both or one of the exception cases). Also, should the model method be <code>identify</code>, or is <code>identify</code> proper?</p> <p>My l...
[]
[ { "body": "<blockquote>\n <p>should the model method be identify! or is identify proper?</p>\n</blockquote>\n\n<p>You should only end the method name with a bang (!) if the method modifies the object it is called on. Furthermore, only if there is also another method of the same name without the bang which doe...
{ "AcceptedAnswerId": "11373", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T01:29:50.797", "Id": "11293", "Score": "2", "Tags": [ "beginner", "ruby", "ruby-on-rails", "exception" ], "Title": "Stylistic exception and bang usage" }
11293
<p>My code is below. List anything that looks wrong, anything that could be improved. This is an update from <a href="https://codereview.stackexchange.com/questions/11282/any-suggestions">this question</a>. I know, my old code was a complete mess.</p> <p>New Code:</p> <pre><code>import math class ChangeableRange: ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T14:18:18.170", "Id": "18153", "Score": "0", "body": "I'd be rather curious to see how you plan to use this code, especially `change_range`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T20:17:02.080"...
[ { "body": "<p>One thing I believe is missing is checking whether or not the inputs are valid. The step should not be zero, for instance. To simplify maintenance, a single \"setter\" method can be used, so you can call it both from <code>__init__</code> and <code>change_range</code>.</p>\n\n<p>I see you do a few...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T01:39:23.703", "Id": "11295", "Score": "4", "Tags": [ "python" ], "Title": "General feedback on ChangeableRange object" }
11295
<p>Suppose we are writing a GUI toolkit in C++ (though this question may also apply to other languages). We have a button class with a member function <code>hide</code>, which hides the button. This member function takes a Boolean parameter <code>animated</code> to control if the button should be hidden with an animati...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-10-23T18:10:56.833", "Id": "199519", "Score": "0", "body": "I dunno if they are in C++, but a good alternative that does not require a new type to be defined is using a named parameter. `button.hide(animated: false);`, for example. Otherw...
[ { "body": "<p>I think it is always a good idea to improve clarity of the code, and your change does improve clarity indeed.</p>\n\n<p>If this is the only use of that enum, I would consider it too high of a cost to introduce that enumeration though. I came to adopt the Clang practice on that issue</p>\n\n<pre><c...
{ "AcceptedAnswerId": "12385", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T09:41:24.990", "Id": "11300", "Score": "38", "Tags": [ "c++", "enum" ], "Title": "Boolean enums: improved clarity or just overkill?" }
11300
<p>I have an HTML table representing a database table and a sidebar which holds different anchors ready to perform CRUD operations on click.</p> <p>Because the hrefs in the anchors aren't in general valid for all columns I have written a script which automatically inserts the id of a selected column into the hrefs:</p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T20:43:27.933", "Id": "18163", "Score": "0", "body": "`$('.image_bar ul li a')` selects all elements from document, not from the selected row. Are you sure that it is correct?" }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<pre><code>&lt;script type=&quot;text/javascript&quot;&gt;\n$(function () {\n var $lastSelected = $([]);\n $('tr').click(function () { //tr tag is always inside a table\n $lastSelected.removeClass('selected'); //by caching this variable in the closure we don't need to traverse for it aga...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T15:02:27.357", "Id": "11309", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Column selection and URL modification" }
11309
<p>I'm working on an application that turns a raw camera image into a binary (pure black/white) image and I need this to happen as fast as possible for swift further processing. This is what my code currently looks like:</p> <pre><code>public static boolean[][] createBinaryImage( Bitmap bm ) { int[] pixels = new i...
[]
[ { "body": "<p>You can get rid of the nested loop, replacing this</p>\n\n<pre><code>for ( int x = 0; x &lt; bm.getWidth(); x++ )\n {\n for ( int y = 0; y &lt; bm.getHeight(); y++ )\n {\n c = pixels[x+y*w];\n lLightness = ((c&amp;0x00FF0000 )&gt;&gt;16) + ((c &amp; 0x0000FF00 )&gt;&gt;8) +...
{ "AcceptedAnswerId": "11338", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T19:16:52.963", "Id": "11312", "Score": "2", "Tags": [ "java", "android" ], "Title": "Fast image binarization on Android" }
11312
<p>A question of organization and best practices with Wordpress templates:</p> <ul> <li>Where should I put my variables? Directly in the template? In a separate file via <code>includes()</code>?</li> <li>Should I place all variables at the top of the template, or is it OK to mix them in with the HTML?</li> <li>Should ...
[]
[ { "body": "<blockquote>\n <p>Where should I put my variables? Directly in the template? In a separate file via includes()?</p>\n</blockquote>\n\n<p>Directly in the template, it makes it easier to find them.</p>\n\n<blockquote>\n <p>Should I place all variables at the top of the template, or is it OK to mix th...
{ "AcceptedAnswerId": "11331", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T19:35:28.373", "Id": "11314", "Score": "2", "Tags": [ "php" ], "Title": "Organizing a wordpress template with lots of variables" }
11314
<p>I'm trying to learn Python through the excellent online book <a href="http://getpython3.com/diveintopython3/" rel="noreferrer">Dive Into Python 3</a>. I have just finished chapter 2 about data types and felt like trying to write a program on my own.</p> <p>The program takes an integer as input and factorizes it into...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T23:11:52.770", "Id": "18165", "Score": "2", "body": "You should definitely create a list of the prime numbers that you've found and keep it as your find more. The higher the numbers you get the more iterations you would have to do ...
[ { "body": "<pre><code>#!/usr/bin/python\n\nimport sys\nimport math\n\ndef prime_factorize(n):\n factors = []\n number = math.fabs(n)\n</code></pre>\n\n<p>Prime factorization really only makes sense for integers. So you really use abs not fabs.</p>\n\n<pre><code> while number &gt; 1:\n factor = g...
{ "AcceptedAnswerId": "11320", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T21:23:06.467", "Id": "11317", "Score": "8", "Tags": [ "python", "primes" ], "Title": "Prime factorization of a number" }
11317
<p>I've just started with coffeescript, and I saw <a href="http://blog.8thlight.com/uncle-bob/2012/04/20/Why-Is-Estimating-So-Hard.html" rel="nofollow">http://blog.8thlight.com/uncle-bob/2012/04/20/Why-Is-Estimating-So-Hard.html</a> which has a little programming problem, so I figured I'd do it in coffeescript (whi...
[]
[ { "body": "<p>This is how I would write it.</p>\n\n<pre><code>lineEndings = (s, len) -&gt;\n words = s.split ' '\n line = []\n result = []\n for word in words\n if line.length + 1 + word.length &lt;= len\n line = [line..., word]\n else\n result.push line.join ' '\n line = [word]\n last...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T22:24:05.660", "Id": "11318", "Score": "1", "Tags": [ "coffeescript" ], "Title": "Is there any way to make this CoffeScript code simpler / smaller" }
11318
<p>Another stab at the <a href="http://en.wikipedia.org/wiki/Josephus_problem" rel="nofollow" title="Josephus problem">Josephus problem</a>, this time using Actors. <code>N</code> people stand in a circle and every <code>step</code>th person is eliminated until one is remaining. </p> <p>The way I solve it here is to g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T09:12:55.393", "Id": "18174", "Score": "1", "body": "It's a fun way to model the problem, sure. But it's probably more efficient to simply use a linked list for a naive implementation. Your wikipedia pages shows that the best soluti...
[ { "body": "<blockquote>\n <p>would like to make <code>next</code> private[this], but it's then very tricky to set up</p>\n</blockquote>\n\n<p>To achieve that, you can define the initial next person as a <code>lazy val</code> field, and then define a <code>var</code> locally in the <code>act</code> method:</p>\...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T05:57:07.163", "Id": "11322", "Score": "2", "Tags": [ "scala", "actor" ], "Title": "Scala: Josephus problem with Actors" }
11322
<p>I would be happy to hear feedback on my implementation of HttpClient. I am not so strong with error handling so I want to improve. My thought process behind this was that <a href="http://hc.apache.org/httpclient-3.x/exception-handling.html" rel="nofollow"><code>IOException</code>s can be recoverable and should be tr...
[]
[ { "body": "<ol>\n<li><p>I would create a common <code>executeRequest</code> method:</p>\n\n<pre><code>private HttpResponse executeRequest(final HttpUriRequest request, \n final String authHeader, final boolean authHeader) {\n if (authHeader){\n request.addHeader(authHeader); \n }\n return...
{ "AcceptedAnswerId": "11343", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T08:30:05.883", "Id": "11323", "Score": "3", "Tags": [ "java", "android", "recursion", "exception-handling", "error-handling" ], "Title": "HttpClient error handling" }
11323
<p>Is there a way to reduce the number of lines by setting the output variable inside LINQ select statement? How would you do it?</p> <pre><code>public void GetSomeValue(int bonusID, out decimal? maxGiving, out int? isActive) { maxGiving = 0; isActive = 0; try { var con = new BonusModelDataCont...
[]
[ { "body": "<p>No, you can't do that, you can't use <code>out</code> parameters in a lambda.</p>\n\n<p>But even if you could, I don't think it would be a good idea to do so, because it would make the code less readable.</p>\n\n<p>There are also some suspicious practices in your code:</p>\n\n<ol>\n<li>You're usin...
{ "AcceptedAnswerId": "11330", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T11:07:40.777", "Id": "11328", "Score": "4", "Tags": [ "c#", "linq" ], "Title": "Setting output parameter inside LINQ select" }
11328
<p>I have been working on a Backbone.js application, and I am starting to think I am making a huge mistake.</p> <p>I never fully understand garbage collecting, and how exactly some closures prevent it. I just try to keep as organized as possible.</p> <p>I just read an article that states that JavaScript variables tha...
[]
[ { "body": "<p>This code looks mostly fine to me, when the <code>.move</code> method gets called, <code>.once</code> gets moved to <code>.old</code> and then when <code>.clean</code> happens, <code>.old</code> gets deleted (and eventually garbage collected unless a reference to it continues to exist somewhere el...
{ "AcceptedAnswerId": "11346", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T11:49:48.660", "Id": "11333", "Score": "1", "Tags": [ "javascript", "memory-management", "backbone.js", "garbage-collection" ], "Title": "Will this code get cleaned up by t...
11333
<p>I have an HTML table representing a database table and a sidebar which holds different anchors ready to perform CRUD operations on click.</p> <p>Because the <code>href</code>s in the anchors aren't general valid for all columns I have written a script which automatically inserts the id of a selected column into the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T13:53:21.153", "Id": "18183", "Score": "0", "body": "fiddle please.." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T14:27:37.257", "Id": "18184", "Score": "1", "body": "Your code is fine,...
[ { "body": "<p>I do not like too much this:</p>\n\n<pre><code>var name = $(this).find('td:nth-child(2)').html(); \n</code></pre>\n\n<p>I would generally use html5 data attribute on the tr row to pass the id.</p>\n\n<p>example:</p>\n\n<pre><code>&lt;table&gt;\n &lt;tr data-id=\"1\"&gt;&lt;td&gt;bla&lt;/td&gt;&l...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T13:49:55.257", "Id": "11335", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "HTML table representing a database table and a sidebar" }
11335
<p>This allows users to upload an file from the browser into my Rails app using the paperclip gem. Once the file is uploaded it gets saved into the filesystem. When the user then goes in and the "show" method or the "edit" method is evoked the image is shown to the user. This is fine for image files but for .csv and .t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T18:26:19.930", "Id": "18191", "Score": "1", "body": "write a helper that returns a string given a filetype (isJPG, isPNG, ...)." } ]
[ { "body": "<p><a href=\"https://stackoverflow.com/users/188031/tokland\">tokland</a> is right (on both counts), you should push all that logic into a helper. You can also add a bit of <a href=\"http://ruby-doc.org/stdlib-1.9.3/libdoc/ostruct/rdoc/OpenStruct.html\" rel=\"nofollow noreferrer\">OpenStruct</a> into...
{ "AcceptedAnswerId": "11340", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T18:24:32.020", "Id": "11339", "Score": "2", "Tags": [ "beginner", "ruby", "ruby-on-rails", "image", "file-system" ], "Title": "Uploading a file from the browser" }
11339
<p>I've written a script that deletes a member of a hash if an array within the has contains all the other elements of another array within the same hash.</p> <p>It works but it looks a little messy. Is there a better way to do this?</p> <pre><code>def title_contains_blocks(candidate, titles, index) test_group = ti...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T12:36:48.943", "Id": "18192", "Score": "0", "body": "Would it have been equivalent if you removed the [1,2,3] and [4,5,6]? That is, do you simply need to cover all digits and remove redundant entries?" } ]
[ { "body": "<p>Convert the Hashes to Arrays, then use the difference operations on them.</p>\n\n<pre><code>a = { :a =&gt; 1, :b =&gt; 2, :c =&gt; 2 }\nb = { :a =&gt; 1 }\n\np (b.to_a - a.to_a).empty?\n</code></pre>\n\n<p>You can do other things, like identify if two Hashes overlap in any places, by use the inter...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T07:52:52.293", "Id": "11341", "Score": "4", "Tags": [ "ruby" ], "Title": "Comparing hash members to other hash members" }
11341
<p>This hides <code>div.extended</code> then creates a button that toggles its text and <code>div.extended</code>'s visibility.</p> <p>While the below works, I was wondering if there was a more concise way of writing this code.</p> <pre><code>(function() { var extended = $('.extended').hide(); $('&lt;button&gt;&lt;...
[]
[ { "body": "<pre><code>$(function () {\n var extended = $('.extended').hide(),\n hidden = true;\n $('&lt;button&gt;&lt;/button&gt;', {\n text: 'Read more'\n }).appendTo('.intro').on('click', function () {\n extended.slideToggle();\n hidden = !hidden;\n $(this).text(hid...
{ "AcceptedAnswerId": "11345", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T13:46:57.240", "Id": "11344", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Toggling button & content with jQuery" }
11344
<p>Though it works I wonder if there might be a better way to do this. I would like to reuse this loading and establishing of fields of another class(es) (the static TileMapper class mentioned at the end) in a C#/.net/XNA environment.</p> <p>I noticed that when moving through the OpenFileDialog to find files it felt s...
[]
[ { "body": "<blockquote>\n <p>I noticed that when moving through the OpenFileDialog to find files it\n felt sluggish. Is that because I had to set [STAThreadAttribute] just\n to get it to open?</p>\n</blockquote>\n\n<p>That is a StackOverflow or GameDev.StackExchange kind of question.</p>\n\n<p>Refactoring th...
{ "AcceptedAnswerId": "11351", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T15:53:19.347", "Id": "11348", "Score": "1", "Tags": [ "c#", ".net", "winforms" ], "Title": "What should I do to improve this snippet" }
11348
<p>I have a class <code>bar</code> that keeps track of <code>N</code> instances of class <code>foo</code> in a <code>std::map</code> (so <code>N</code> = <code>map.size()</code>). When I call <code>bar::func</code> I want to have <code>N</code> threads that call <code>foo::foo_func</code>.</p> <p><code>foo::foo_func</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T16:55:48.723", "Id": "18215", "Score": "1", "body": "Can you use C++11's `std::thread`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T16:57:34.563", "Id": "18216", "Score": "1", "body": ...
[ { "body": "<p>You might want to take a look at C++'s new <a href=\"http://en.cppreference.com/w/cpp/thread/thread\" rel=\"nofollow\">std::thread</a> class, which is part of the C++11 standard library. Its constructor is scheduled to run the created thread immediately and takes a function object such as a functi...
{ "AcceptedAnswerId": "11354", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T16:49:17.133", "Id": "11352", "Score": "10", "Tags": [ "c++", "pthreads" ], "Title": "Is there a better way to thread this class function?" }
11352
<p>I am making an interpreter for a custom programming language (concatenative, soft-typed) and for that purpose I have a central datatype <code>Token</code>. A Token can be of one of the many different types, either of scalar ones or vector ones. To minimize the amount of memory, I used a <code>union</code> first but ...
[]
[ { "body": "<p>This problem is solved very elegantly by <a href=\"http://www.boost.org/doc/libs/1_49_0/doc/html/variant.html\" rel=\"nofollow\">Boost.Variant</a>.</p>\n\n<p>Not only is it easier and more efficient, it’s also completely type safe (meaning, you cannot accidentally retrieve a wrong type) when using...
{ "AcceptedAnswerId": "11566", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-30T21:46:09.907", "Id": "11358", "Score": "2", "Tags": [ "c++", "performance" ], "Title": "Memory allocation for a variant-typed token" }
11358
<p>I just recently learned how to use Bit Field Structures in C++, and I was thinking of applying it to a project. It would certainly make the project code much easier to work with. So, I typed up a quick test program to see if it would work as I expected, and it does. But, I'm not 100% convinced that it is safe. </p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T06:55:47.710", "Id": "18242", "Score": "0", "body": "Does DataHeader represent a (partial) DDCMP data message?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T21:54:22.363", "Id": "18250", "Sc...
[ { "body": "<pre><code>#include &lt;stdint.h&gt;\n</code></pre>\n\n<p>At least officially, you're supposed to prefer to use <code>&lt;cstdint&gt;</code> instead. I have a hard time getting very excited about it though.</p>\n\n<pre><code>#include &lt;cstring&gt;\n</code></pre>\n\n<p>From the looks of the code, yo...
{ "AcceptedAnswerId": "43836", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T01:22:09.183", "Id": "11360", "Score": "3", "Tags": [ "c++" ], "Title": "Bit field structures in C++" }
11360
<p>I know it's been done a million times already, but I couldn't find a serialization library to suit my needs. This is the very basis of what I came up with. I know the code is ugly and unstructured, so you don't have to tell me that.</p> <p>My goal is to make a serialization/deserialization system that provides a mi...
[]
[ { "body": "<p>The claim <em>\"As you can see I only had to add two functions - an enumerator and a typename function.\"</em> will not generally be true for every type. Specifically, you'll also need to provide an appropriate <code>operator&lt;&lt;</code> for every type you'd like to use as a member in a seriali...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T09:31:36.180", "Id": "11367", "Score": "6", "Tags": [ "c++", "library", "reflection", "serialization" ], "Title": "Basis of custom C++ serialization lib" }
11367
<p>Here is what I have. A <code>User</code> model and an <code>Address</code> model. <code>User</code> <code>has_many :addresses</code> and Address belongs_to :user.</p> <p>Now I want to search for users whose email contains a give term, or one of the user's addresses contains that term. So lets say the term is 'jap',...
[]
[ { "body": "<pre><code>User.joins(:addresses).where([\"addresses.city like ? OR addresses.address_line like ?\", '%jap%', '%jap%'])\n</code></pre>\n\n<p>or</p>\n\n<pre><code>a = Address.arel_table\nUser.joins(:addresses).where(a[:city].matches('%jap%').or(a[:address_line].matches('%jap%')))\n</code></pre>\n", ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T21:52:12.820", "Id": "11375", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Query Rails 3 Active Record Fetch associated model based on conditions" }
11375
<p>Do you have any suggestions about how to make this code faster/better? Maybe suggest new features or better comments/docstrings? </p> <pre><code>from time import time, ctime, sleep from random import choice, uniform from glob import glob import os # Gets current working directory DIRECTORY_NAME = os.getcwd() ...
[]
[ { "body": "<pre><code>input(\"Press ENTER to view all files and sizes\")\n</code></pre>\n\n<p>should be at the beginning of the <code>files_in_dir</code> function. <code>size_of_dir</code> should not know anything about what is next called function after it.</p>\n", "comments": [ { "ContentLic...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T22:56:47.220", "Id": "11376", "Score": "1", "Tags": [ "python" ], "Title": "Directory operations" }
11376
<p>I was looking for a solution to allow me to rate limit the number of outgoing REST calls but preserved the order of queued elements so I found a <a href="http://www.pennedobjects.com/2010/10/better-rate-limiting-with-dot-net/" rel="noreferrer">rate limiter implementation</a> and combined it with <code>ConcurrentQueu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T23:28:39.507", "Id": "18252", "Score": "0", "body": "I don't understand, why is `BlockingCollection` lacking when it comes to order of the elements? By default, it internally uses `ConcurrentQueue`, which guarantees FIFO order." }...
[ { "body": "<p>I think the worst thing in that code is what you alluded to in your comment: if the queue is empty, your code will busy-wait, which is a very bad idea. To fix that, you could use <code>BlockingCollection&lt;T&gt;</code> and its blocking method <a href=\"http://msdn.microsoft.com/en-us/library/dd28...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T23:01:56.557", "Id": "11377", "Score": "5", "Tags": [ "c#", "system.reactive" ], "Title": "Implementation of a throttled ConcurrentQueue Rx observer" }
11377
<p>I previously posted my <a href="https://codereview.stackexchange.com/questions/10858/what-is-wrong-with-this-java-code-is-it-hard-to-follow">first attempt</a> at writing a program that I was given to test my skills for a position that I was interviewing for. I have rewritten the program using the excellent advice t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T20:25:41.570", "Id": "18349", "Score": "1", "body": "I'll take a look at it. I suggest you take a look at how to use [Generics](http://tutorials.jenkov.com/java-generics/index.html) properly." }, { "ContentLicense": "CC BY-S...
[ { "body": "<p>Some quick comments:</p>\n\n<p>For the getPrintableSchedule method in class Schedule.\nYou can override the method toString() in the class Course, so you get a \"printable\" version of a Course.</p>\n\n<p>In your for loops, you are calculating the length of your arrays in every iteration. Since yo...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T23:48:31.603", "Id": "11379", "Score": "1", "Tags": [ "java", "object-oriented" ], "Title": "Do the objects in this code follow OO standards?" }
11379
<p>I'm writing a program to build and solve a Maze using DFS and backtracking using Java Swing. The code was a mess when I have to put my logic into my JPanel in order to show animation via the call to <code>repaint()</code>. Here are all classes: </p> <p><strong>Point</strong></p> <pre><code>public class Point { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T16:44:26.100", "Id": "18296", "Score": "1", "body": "Why did you create your own `Point` class? [Java already has one](http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Point.html) which looks identical to yours, except with som...
[ { "body": "<p>Here's a few tips:</p>\n\n<ul>\n<li>When I ran you program at first, I got a blank frame. Make sure <code>frame.setVisible(true)</code> is the last thing you do. Everything else should be set up before that.</li>\n<li><p>Really, really, really avoid magic numbers. Code like this:</p>\n\n<pre><code...
{ "AcceptedAnswerId": "13233", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T00:43:36.677", "Id": "11383", "Score": "6", "Tags": [ "java", "swing" ], "Title": "How to separate logic and GUI" }
11383
<p>I have found that writing unit tests helps me to discover both the intent and also reusability of code that I'm working on. It has been generally helpful in helping develop my "code smell."</p> <p>I was working on two unit tests that are basically mirror images, and realized that I was typing code that looked almos...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T01:31:24.020", "Id": "18265", "Score": "0", "body": "I just realized that my method name could be read: \"Fire Class as...\" but it's intended as \"Fire Class A's...\"" } ]
[ { "body": "<p>It looks like you can extract the method bodies entirely. Warning: I typed this code into a web browser, not an IDE:</p>\n\n<pre><code>- (NSDictionary *)invokeClassBBlockRunnerWithExpectedObject: (id)object expectedError: (NSError *)error {\n [mockClassA setObject: object];\n [mockClassA set...
{ "AcceptedAnswerId": "11398", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T01:26:34.527", "Id": "11384", "Score": "2", "Tags": [ "unit-testing", "objective-c" ], "Title": "Asyncronous unit test refactoring in Objective-C" }
11384
<p>I have recently made a small program to generate D&amp;D (original edition) monster stat blocks in text form. I use this program myself to generate stats block so that I can then copy and paste them in the adventures I am writing.</p> <p>The main reason for using a program is to have the program roll the random val...
[]
[ { "body": "<p>Erlang does pattern-matching, so anywhere you do</p>\n\n<pre><code>function_name(Arg) -&gt; \n case Arg of foo [foo code]\n bar [bar code]\n etc\n end.\n</code></pre>\n\n<p>or similar, you can instead do</p>\n\n<pre><code>function_name(foo) -&gt; [foo code];\nfu...
{ "AcceptedAnswerId": "11388", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T02:12:02.863", "Id": "11386", "Score": "1", "Tags": [ "erlang" ], "Title": "Erlang code that generates text output" }
11386
<p>How can I make this piece of code better? The problem to be solved is in the topmost comment.</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;cassert&gt; #include &lt;stdint.h&gt; #include &lt;iterator&gt; #include &lt;queue&gt; /* * Shuttle Puzzle: * A Shuttle Puzzle of size 4 cons...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T08:17:25.563", "Id": "18270", "Score": "2", "body": "Note that `_N` is illegal. See [what are the rules about using an underscore](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identif...
[ { "body": "<p>What's the point of this code? </p>\n\n<pre><code>try {\n _game_board.resize(2*N + 1);\n } catch (std::bad_alloc ba) {\n throw ba;\n }\n</code></pre>\n\n<p>For rethrowing you just do <code>throw</code>, but I see no logic here. If you catch an exception, then process it. If you don't proce...
{ "AcceptedAnswerId": "11395", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T03:13:25.030", "Id": "11387", "Score": "3", "Tags": [ "c++", "algorithm", "programming-challenge" ], "Title": "Shuttle Puzzle solver" }
11387
<p>This code achieves the effect, but is it a resource friendly way of doing it?</p> <p>Just to clarify: target <code>div.fixMe</code> and fix it to the top of the window when the user scrolls past its natural position. (I do realise there are plugins to achieve this result, but I wanted to build it myself)</p> <p>Is...
[]
[ { "body": "<p>Two things I noticed/would recommend:</p>\n\n<ol>\n<li>Cache jQuery variables such as $(this) and $('.fixMe') to prevent redundant lookups during each scroll event.</li>\n<li>Implement an event debouncer/limiter, this is because the scroll event fires a lot more than you likely think it does. Ther...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T09:06:43.427", "Id": "11397", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Fix element on window scroll" }
11397
<p>Hope that title makes sense. This is part of an object I have:<br> The event listener attaches to the correct marker passed in the parameter but inside the function, <code>this</code> points to something else.</p> <pre><code>function UserGoogleMap($mapElement) { this.$mapElement = $mapElement; this.map = {...
[]
[ { "body": "<p>There's nothing too elegant to be done here, just use</p>\n\n<pre><code>var that = this;\n</code></pre>\n\n<p>And inside your functions, use <code>that</code>.</p>\n\n<p>As in:</p>\n\n<pre><code>function UserGoogleMap($mapElement) {\n this.$mapElement = $mapElement;\n this.map = {};\n thi...
{ "AcceptedAnswerId": "11403", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T12:34:22.103", "Id": "11402", "Score": "1", "Tags": [ "javascript", "object-oriented" ], "Title": "Trying to use \"this\" to refer to a class's instance variable inside a function ...
11402
<p>Here's a program I wrote to sort a list of numbers in increasing order (without using inbuilt sort function).</p> <pre><code>(define (sort-list l) (define first-element (if (not (null? l)) (car l) 0)) (cond ((null? l) (quote ())) (else (cons (find-shortest l first-element) (sort-list (remove-member l (f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T03:03:26.823", "Id": "18285", "Score": "0", "body": "I think that `find-shortest` should be named `find-smallest`." } ]
[ { "body": "<p>What you've written is called \"selection sort\", and it works fine. It's not the best sort, but it's not bad, either. It's one of a class called \"n^2\" sorts, because it generally runs in time proportional to the square of the length of the list.</p>\n\n<p>Selection sort is a somewhat painful s...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T02:59:00.113", "Id": "11404", "Score": "5", "Tags": [ "beginner", "scheme", "sorting" ], "Title": "Sorting a list of numbers in increasing order" }
11404
<p>Here is my implementation of the <a href="http://en.wikipedia.org/wiki/Greedy_algorithm" rel="nofollow">greedy algorithim</a> in Ruby. Do you have any suggestions?</p> <pre><code>class Greedy def initialize(unit, total, *coins) @total_coins = 0 @unit = unit @total = total @currency = coins.sort ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T15:02:33.863", "Id": "18398", "Score": "1", "body": "It is \"a solution using a greedy algorithm\", not \"the Greedy Algorithm\" itself. Greedy algorithm is a concept." } ]
[ { "body": "<p><code>@currency</code> could be renamed <code>@currencies</code>, or perhaps better, <code>@denominations</code>. Naming an array in the plural leads to easy naming when iterating, e.g.:</p>\n\n<pre><code>@currencies.each do |currency|\n</code></pre>\n\n<p>instead of:</p>\n\n<pre><code>@currency....
{ "AcceptedAnswerId": "11443", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T15:44:08.483", "Id": "11408", "Score": "3", "Tags": [ "optimization", "ruby" ], "Title": "Greedy algorithm in Ruby - any suggestions?" }
11408
<p>I have written a custom drop down menu handler using jQuery because I felt that the native drop down didn't fit my UI. I have taking into consideration the native way of going through a drop down box using arrows and tabs to move to next input.</p> <p>I was wondering if anyone can see any mistakes or errors or anyw...
[]
[ { "body": "<p>Just two small notes from a non-JavaScript/jQuery developer:</p>\n\n<ol>\n<li><p>Named constants would be better instead of the magic numbers/strings.</p>\n\n<pre><code>e.keyCode == 16\nshift = 'on';\nshift = 'off';\ncase 13:\ncase 9:\ncase 13:\ncase 40:\ncase 38:\n</code></pre></li>\n<li><p>I'd s...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T16:35:56.080", "Id": "11409", "Score": "3", "Tags": [ "javascript", "jquery", "html", "css", "gui" ], "Title": "Custom dropdown menu using jQuery" }
11409
<p>This is a short program meant to give me an Erlang hook into the ImageMagick FFI for performance reasons. </p> <p>All comments welcome, but specifically </p> <ul> <li>my C experience is minimal, bordering on nonexistent, so I would particularly appreciate hints in that area. </li> <li>the setup here is one of a lo...
[]
[ { "body": "<p>If you are using several files to implement this, you need a header file to\nhold the prototypes of external functions (<code>read_cmd</code> etc) and types (<code>typedef\nunsigned char byte;</code>)</p>\n\n<p>In <code>read_exact</code> and <code>write_exact</code>, a <code>do .. while</code> loo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T17:12:29.727", "Id": "11411", "Score": "2", "Tags": [ "c", "erlang" ], "Title": "Erlang FFI into ImageMagick" }
11411
<p>The reason I want to do this is that the JavaScript objects are created from XML elements and if the element has changed I want to be able to detect that change in the JavaScript objects. So I wrote a function which maps out the differences between the first and second object. Can you improve on this function? (<cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T18:08:46.007", "Id": "18325", "Score": "0", "body": "You can simply use the jQuery `extends` function...(If jQuery is an option)" } ]
[ { "body": "<p>Replacing conditions with guard clauses would improve readability a little bit. (<a href=\"http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html\" rel=\"nofollow\">Flattening Arrow Code</a>)</p>\n\n<p>I would try to build two maps first - one for properties of the first object, and o...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T18:39:42.010", "Id": "11412", "Score": "8", "Tags": [ "javascript", "algorithm", "xml" ], "Title": "Mapping the differences between JavaScript objects" }
11412
<p>How can I make these methods better?</p> <pre><code>Range.class_eval do def addto_begin(x) return self.begin + x..self.end end def addto_end(x) return self.begin..self.end+x end end </code></pre> <p>Right now, I have to type:</p> <pre><code>x = 1..10 x = x.addto_begin(3) </code></p...
[]
[ { "body": "<p>You can't. <code>Range</code> doesn't provide write access to properties (i.e. begin/end).</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T15:06:45.947", "Id": "11416", "ParentId": "1141...
{ "AcceptedAnswerId": "11417", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-01T14:57:16.627", "Id": "11415", "Score": "2", "Tags": [ "ruby" ], "Title": "How to make a mutable Range in Ruby?" }
11415
<p>I wanted to download a webpage. I confirmed that this code works. But I'm not sure whether I'm doing it neatly. Would you review my (full) code?</p> <pre><code>import java.io.IOException; import java.io.InputStream; import java.io.FileOutputStream; import java.net.URL; public class GetHTML { private InputStrea...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T20:56:21.263", "Id": "18303", "Score": "0", "body": "1. Can you use automatic resource management? http://stackoverflow.com/questions/2943542/using-keyword-in-java 2. Pass the article name directly to the constructor. 3. Take the ur...
[ { "body": "<ol>\n<li><p>From Clean Code, page 25: </p>\n\n<blockquote>\n <p>Classes and objects should have noun or noun phrase names like <code>Customer</code>, <code>WikiPage</code>,\n <code>Account</code>, and <code>AddressParser</code>. [...] A class name should not be a verb.</p>\n</blockquote>\n\n<p>I'd...
{ "AcceptedAnswerId": "11421", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T20:35:19.490", "Id": "11418", "Score": "10", "Tags": [ "java", "html" ], "Title": "Webpage downloader" }
11418
<p>So far, this is just a class that tracks the state of a baseball game. Unfortunately, I can't tell you for sure what the next step is. It might be a an interactive playable baseball game, or a game simulator, or some combination.</p> <p>I am hoping this class is sufficient to do either of those things. The test ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T03:29:35.217", "Id": "18312", "Score": "0", "body": "You could probably treat `bases` as a list rather than a dictionary. Then `__homer()` could simply do `self.score[\"home/away\"] = sum(self.bases)` and then `self.bases = [0, 0, 0...
[ { "body": "<pre><code># pylint: disable=R0902\n# Ignore error about too many instance attributes.\n</code></pre>\n\n<p>PyLint is trying to tell you something. Your class is to complex, and should be split into several smaller classes</p>\n\n<pre><code>def __init__(self):\n '''Set up a new game.'''\n self....
{ "AcceptedAnswerId": "11439", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T20:40:01.563", "Id": "11419", "Score": "3", "Tags": [ "python", "simulation" ], "Title": "Baseball game state class in python looking for feedback" }
11419
<p>I just made this responsive image solution, but I'm not sure if it's the best way to do what I'm trying to achieve. Use cases can be found at <a href="http://responsimage.com/" rel="nofollow">http://responsimage.com/</a>.</p> <pre><code>/* responsimage.com v0.2.3 */ (function ($, window, Date) { 'use strict'; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T22:23:24.193", "Id": "18307", "Score": "4", "body": "please put code in question" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T22:24:11.557", "Id": "18308", "Score": "4", "body": "Do you...
[ { "body": "<ol>\n<li><p>declare the variables inside \"rTags.each()\" on the outside. This way there not being declared on each iteration.</p></li>\n<li><p>The naming of parameters \"window\" and \"Date\". I would suggest naming them something different to avoid confusion. This way you can distinguish between ...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-02T22:20:02.847", "Id": "11422", "Score": "1", "Tags": [ "javascript", "image" ], "Title": "Responsive image solution" }
11422
<p>I am developing code for <a href="https://math.stackexchange.com/questions/139842/in-how-many-ways-can-a-number-be-expressed-as-a-sum-of-consecutive-numbers/140072#140072">a problem posted on StackOverflow.</a> I have written my solution in Java but it is taking too much time to execute for numbers such as <code>21...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T23:07:18.010", "Id": "62383", "Score": "0", "body": "What about using multiple processors and threads? The algorithm in its current form is a good candidate for parallelization." } ]
[ { "body": "<p>You have one serious problem - that supergigantic number you want to use is larger than the precision of both doubles AND longs. In fact, because both doubles and longs use 64 bits in Java, you would be better off using longs because with doubles, only 53 of those 64 bits are available for what yo...
{ "AcceptedAnswerId": "11437", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T05:50:50.750", "Id": "11425", "Score": "2", "Tags": [ "java", "algorithm", "performance" ], "Title": "{Sum+=i++} to Reach N" }
11425
<p>Right now I am working on an AJAX call that grabs a random photo that a Facebook user is tagged in and then grabs the large source for it. Is there any way to speed this up or at least distill the call into one query?</p> <pre><code>var query1 = encodeURI("SELECT pid,xcoord,ycoord FROM photo_tag WHERE subject={{mys...
[]
[ { "body": "<p>I haven't worked with Facebook's API using queries like this, but I know SQL inside and out, and this screams INNER JOIN to me.</p>\n\n<pre><code>var joinedQuery = \"SELECT Photo_Tag.pid,Photo_Tag.xcoord,Photo_Tag.ycoord,Photo.src_big FROM photo_tag AS Photo_Tag INNER JOIN photo AS Photo ON Photo_...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T07:23:18.470", "Id": "11427", "Score": "3", "Tags": [ "javascript", "jquery", "ajax", "facebook" ], "Title": "Is there any way to shorten up this Facebook API call?" }
11427
<p>I'm new to using PDO and am trying to create a secure class to handle MySQL statements. Here is what I have so far:</p> <pre><code>class SQL { private static $dbh = null; private function __construct($host, $user, $pass, $data, $table) { $this-&gt;host = (!empty($host)) ? $host: 'localhost'; $this-&gt;user...
[]
[ { "body": "<p><strong>Disclaimer:</strong> I've not tackled SQL or PDO as of yet, so this answer will focus mainly on the code itself.</p>\n\n<p>You should not set <code>$this-&gt;data</code> in the <code>__construct()</code> method unless you are planning on using it. I would set it in whatever method you use ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T11:31:37.710", "Id": "11432", "Score": "1", "Tags": [ "php", "object-oriented", "pdo" ], "Title": "PDO MySQL class" }
11432
<p>I have an application coded in VB.NET that has a bunch of servers in a DataGridView and does a continuous asynchronous ping. If all the servers are up it refreshes great, but if one goes down and starts to time out it takes about 5-10 seconds before the program starts responding again. This program needs to ping a...
[]
[ { "body": "<p>I have a similar problem (but I have to use PSLoggedOn.Exe which times out in 10-15 seconds).</p>\n\n<p>To mitigate the problem I use WMI to Ping.</p>\n\n<p>I will then do PSLoggedOn only if the result was a valid IPnumber.</p>\n\n<p>WmiPingStatus is perhaps a little less reliable because it is fa...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T13:31:41.293", "Id": "11433", "Score": "2", "Tags": [ ".net", "vb.net", "asynchronous" ], "Title": "Datagrid not refreshing correctly with Async Ping VB .Net" }
11433
<p>Questions:</p> <ol> <li>Is this code secure? (I think that it is, but I'm a newbie so I want to be sure.)</li> <li>Is the <code>get_pass</code> function correct with passing the arguments to the <code>free_memory</code> function?</li> <li>Do I have to delete the pass' buffer with <code>memset</code>?</li> </ol> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T04:37:47.737", "Id": "18382", "Score": "0", "body": "What do you mean by \"secure code\" and why do you think your code is secure?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T06:41:13.917", "I...
[ { "body": "<p>I'm not sure it's exactly insecure, but I'd consider it excessively verbose and repetitive. Given that your <code>user</code>, <code>host</code> and <code>pass</code> are all small, fixed-size, and allocated for the duration of a single function, dynamic allocation seems to gain little (and cost q...
{ "AcceptedAnswerId": "11449", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T16:07:43.760", "Id": "11438", "Score": "6", "Tags": [ "c", "security", "memory-management" ], "Title": "Memory management with password retrieval" }
11438
<p>I've programmed a minimal parallel workers queue in Ruby, and I wanted to know if it's correct, and if there are simpler ways of implementing it.</p> <p>I'm aware of the existence of MonitorMixin, but it won't save any code, I think.</p> <p>The design is kept intentionally trivial (e.g. it uses Thread.abort_on_exc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T20:40:18.470", "Id": "18431", "Score": "0", "body": "Independently of the improvements, there is bug, actually. If an error is raised when **yield**ing, the following code is not executed - so the latter must be wrapped in an ensure...
[ { "body": "<p>I would prefer to use <code>Queue</code> in Erlang style (message passing), it looks cleaner. You can even pass something more useful than <code>:done</code> back, e.g. creating parallel map.</p>\n\n<pre><code>require \"thread\"\n\nPOOL_SIZE = 5\n\ntasks = (0..99).map { |i| lambda { puts \"Process...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T18:21:41.103", "Id": "11440", "Score": "2", "Tags": [ "ruby", "multithreading" ], "Title": "Correctness of a minimal parallel workers queue in Ruby" }
11440
<p>I'm doing some homework and am just curious if everything I've done looks good and/or if you'd suggest I modify something to keep with "javaese."</p> <pre><code>import java.util.Scanner; import java.util.Random; public class rockpaperscissors { public static void main (String[] args) { int cCh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T18:57:45.483", "Id": "18333", "Score": "0", "body": "Looks good could be shortened but if you are just starting and learning this is fine." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T19:00:13.270"...
[ { "body": "<p>Once you have working code, it is time to refactor.</p>\n\n<p>For example, once the computer makes a choice, print \"Computer picked %s\" to announce the choie. This is better than repeating the same code in multiple sections (because it makes the code shorter, easier-to-understand, easier-to-tes...
{ "AcceptedAnswerId": "11450", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T18:55:56.310", "Id": "11444", "Score": "12", "Tags": [ "java", "game", "homework", "rock-paper-scissors" ], "Title": "Does my Rock Paper Scissors game look good?" }
11444
<p>This is the simplest possible implementation.</p> <p>The two lists will contain at max, 3-5 elements, so the size of lists is not a matter of concern.</p> <p>Any recommendation on how can I make this pretty?</p> <pre><code>private ListsHolder findDiffOfLists(List&lt;MyObject&gt; objsFromDB, List&lt;MyObjRequest&g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T15:07:42.900", "Id": "18570", "Score": "0", "body": "It there an hierarchical relation between MyObject and MyObjectRequest?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T17:09:50.827", "Id": "1...
[ { "body": "<p>I would create this method:</p>\n\n<pre><code>private MyObject findMatch(List&lt;MyObject&gt; objsFromDB, MyObjRequest req_obj){\n for(MyObject db_obj : objsFromDB){\n if(isSameObj(db_obj, req_obj)){\n return db_obj;\n }\n }\n return null;\n}\n</code></pre>\n\n<p>...
{ "AcceptedAnswerId": "11453", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T20:56:48.760", "Id": "11451", "Score": "3", "Tags": [ "java" ], "Title": "An elegant way to find diff of two list of objects in Java" }
11451
<p>Just wondering if my </p> <pre><code>else {return false;} </code></pre> <p>statements are superfluous... do I just need one <code>return true;</code> here?</p> <pre><code>function has_access() { if ( is_user_logged_in() ) { $role = get_current_user_role(); $admins = array( 'Admini...
[]
[ { "body": "<p>I'd replace the conditions with guard clauses. (<a href=\"http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html\">Flattening Arrow Code</a>)</p>\n\n<pre><code>function has_access() {\n if ( !is_user_logged_in() ) {\n return false;\n }\n $role = get_current_user_role()...
{ "AcceptedAnswerId": "11458", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-03T21:43:40.107", "Id": "11455", "Score": "1", "Tags": [ "php", "authorization" ], "Title": "Checking authorization by role" }
11455
<p>can someone read through this script really quick and verify that I didn't miss anything... I'm not getting any errors in my IDE so just have to make sure the structure is correct</p> <pre><code>&lt;?php require_once '/usr/local/cpanel/3rdparty/lib/php/Mail.php'; $db_server = 'localhost'; $db_user = '-----'; $db_p...
[]
[ { "body": "<p>Although it'll lenghten your code quite a bit, in my opinion it's worth checking if the $_POST variables are set (using isset), to avoid any exceptions.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T03:02:57.400", "Id": "11466", "Score": "1", "Tags": [ "php" ], "Title": "Verify $_POST script will work correctly" }
11466
<p>This is a custom effect for jQuery tools that enable caching for ajaxed tabs. Please advice on anything that I can improve. Note that I'm not sure where to put the loading indicator, so, at least have a look at that.</p> <pre><code>$.tools.tabs.addEffect("ajax_cache", function(tabIndex, done) { //check if conte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T22:11:47.567", "Id": "18438", "Score": "0", "body": "Instead of giving the loading image an id and then traversing for it, you should make it a cached jquery object." } ]
[ { "body": "<p>From a once over : </p>\n\n<ul>\n<li>Whether the content is loaded or not, you call <code>panes_cont.children().hide();</code>, you might as well centralize that 1 call </li>\n<li>There is too much going on in the creation of <code>new_pane</code>, it ought to be split up.</li>\n<li>lowerCamelCasi...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T04:16:15.907", "Id": "11467", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "jQueryTools plugin custom effect for caching ctabs" }
11467
<p>I'm writing a form that contains 2 ListViews with a set of 4 buttons. 2 move all the items from one to the other in each direction, the other move only selected items in each direction.</p> <p>Nothing fancy or complicated.</p> <p>However I'm feeling like I could write the MoveItem method in a more elegant way and ...
[]
[ { "body": "<p>Before thinking about how to write this in a more elegant way, you should first ask yourself: is this code actually correct? The “problem” with that code is that you're iterating the collection you're modifying. Quite often (for example in the case of <code>List&lt;T&gt;</code>), that's not allowe...
{ "AcceptedAnswerId": "11472", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T10:40:28.103", "Id": "11469", "Score": "5", "Tags": [ "c#", "winforms" ], "Title": "Moving List View items from one list to another" }
11469
<p>I'd like to know if this is the right syntax for using cookies. I haven't yet tested this code with cookies being used.</p> <p>I'm using a jQuery Plugin called <a href="http://luis-almeida.github.com/jPages/" rel="nofollow">jPages</a> to display pages on my (one page) website, it has a lot of options and it's very ...
[]
[ { "body": "<p>At the expense of having a little more code, I would use a <a href=\"https://gist.github.com/2398893/d6327b3ca7b7c50d3f4f784e06bac76cf649fe0f\" rel=\"nofollow\">localStorage polyfill</a> <a href=\"https://developer.mozilla.org/en/DOM/Storage#localStorage\" rel=\"nofollow\">[2]</a>.</p>\n\n<p>With ...
{ "AcceptedAnswerId": "11486", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T11:07:05.683", "Id": "11471", "Score": "1", "Tags": [ "javascript" ], "Title": "Is this correct way to use cookies from a syntax point of view?" }
11471
<h1>Description</h1> <p>I'm writing a program that makes changes to a few Python source files--creating some, and appending content to others. Since some changes depend on others, I check frequently to make sure everything is going smoothly (try importing the modified file, etc). I would like to revert any and all cha...
[]
[ { "body": "<p>A common way to do this sort of thing is with the <a href=\"http://en.wikipedia.org/wiki/Command_pattern\" rel=\"nofollow\">Command pattern</a>, implementing Undo.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T16:05:48.460", ...
{ "AcceptedAnswerId": "11478", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T14:21:13.380", "Id": "11473", "Score": "1", "Tags": [ "python", "design-patterns" ], "Title": "Performing a chain of mutually dependent actions, and reversing in case of failure" }
11473
<p>I have many-to-many mapping with extra columns in the join table. The table structure looks like this:</p> <pre><code>table vendor{vendor_id, vendor_name, vendor_password, etc...} table student{student_id, student_name, student_password, etc..} table test{test_id, test_subject, test_price,test_level, etc..} </code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-08-20T06:18:21.910", "Id": "26081", "Score": "0", "body": "I think you will find the solution in this link http://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/" }, { "ContentLicense": ...
[ { "body": "<p>I'm not familiar with Hibernate mappings, so just some other notes about the code:</p>\n\n<ol>\n<li><p>Calling a class <code>Test</code> could be a disadvantage later. Build frameworks/tools could recognize your class erroneously as a JUnit test class. Although this might be the proper term in you...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T14:48:44.307", "Id": "11474", "Score": "4", "Tags": [ "java", "beginner", "hibernate" ], "Title": "Many-to-many hibernate mapping if link table is having extra columns mappings" }
11474
<p>The following method is designed to display what we owe to a vendor based on 5 buckets. Basically, an aged trial balance (totals only). It also needs to be able to display the data based on any date. It shows me what the trial balance would have looked like on April 1st. By default it displays based on the date that...
[]
[ { "body": "<p>I wrote methods for determining if the date falls within the desired range. This doesn't really solve the cluster of <code>if else</code> statements, but it is more readable. </p>\n\n<p>I also used a few built-in Python functions, <code>filter</code> and <code>reduce</code>. These are tailor-made ...
{ "AcceptedAnswerId": "11485", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T17:51:26.770", "Id": "11479", "Score": "1", "Tags": [ "python", "finance" ], "Title": "Accounts payable buckets (Current,30,44,48,60)" }
11479
<p>Looking to optimize this method so it will run quicker, but can't seem to find anything. WOrking in .NET 3.5. ExcludedWords and NewCodes are both HashSet of strings.</p> <pre><code> private bool isValid(String code) { String pattern = "[a-zA-Z]{3}"; if (chkLessThan2Letters.Checked &amp;&am...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T17:13:53.067", "Id": "18405", "Score": "3", "body": "How long is it currently taking? How long does it need to take for you to have sufficiently optimized it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<p>Before you optimize this, make sure that it actually needs optimization and that you're not wasting your time. Have you checked that this is a performance bottleneck in your application?</p>\n\n<p>One way to optimize this is to store your excluded words in a datastructure like a <a href=\"http://e...
{ "AcceptedAnswerId": null, "CommentCount": "13", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T17:11:51.680", "Id": "11481", "Score": "0", "Tags": [ "c#", "optimization", ".net" ], "Title": "How to optimize this validation method?" }
11481
<p>The common <a href="http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/">FizzBuzz</a> implementation I saw is using a check for % 15 for printing "FizzBuzz"</p> <p>Would you let me know if there is anything wrong / better with this approach?</p> <pre><code>public class FizzBuzz { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T23:01:59.533", "Id": "18440", "Score": "1", "body": "Your version is optimized for the computer. Winston's version is optimized for the human. Got to trust a compiler that it can do a good job at re-shuffling and optimizing the code...
[ { "body": "<p>It looks fine. <code>String.valueOf()</code> is unnecessary, <code>System.out.println(i)</code> would print the same but it is still OK. This test is used only to make sure that the interviewee can write code as the linked site says:</p>\n\n<blockquote>\n <p>This sort of question won’t identify g...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-04T21:01:25.847", "Id": "11489", "Score": "16", "Tags": [ "java", "interview-questions", "fizzbuzz" ], "Title": "FizzBuzz implementation" }
11489
<p>Is there a better way to do this?</p> <pre><code>function Person(name) { this._type='Person'; this.name=name; this.hello = function(){ alert('Hello '+this.name); }; } function object_to_instance(key, value) { if (!value.hasOwnProperty('_type')) return value; var obj= eval(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T01:32:50.087", "Id": "18444", "Score": "0", "body": "instead of eval you could do: `var obj = new window[value._type](value.name);` (I think you could at least; I don't use classes in js)." } ]
[ { "body": "<p>Instead of <code>eval</code>, you could create a <code>Person</code> constructor that accepts an object:</p>\n\n<pre><code>function Person(arg)\n{\n if (typeof arg === 'string')\n {\n var name = arg;\n this._type='Person';\n this.name=name;\n }\n else if (typeof ar...
{ "AcceptedAnswerId": "11497", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T00:58:26.073", "Id": "11494", "Score": "2", "Tags": [ "javascript", "json" ], "Title": "Loading a pseudo-class instance from JSON" }
11494
<p>In a Mako template partial I accept an argument (<code>step</code>) that can be an instance of <code>Step</code> class, a <code>dict</code> or <code>None</code>. Can I in some way avoid repetition or do the check in other more 'pythonic' way? Or how could I gracefully avoid checking types at all?</p> <pre><code>&lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T16:23:08.797", "Id": "18453", "Score": "1", "body": "actually, the most pythonic way would be to avoid passing different types to this partial." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T18:58:43...
[ { "body": "<p>1.I assume <code>if type(step) is dict:</code> should be <code>elif type(step) is dict:</code>.</p>\n\n<p>2.<code>isinstance</code> is preferable than <code>type</code> because <code>isinstance</code> caters for inheritance, while checking for equality of type does not (it demands identity of type...
{ "AcceptedAnswerId": "11499", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T02:35:26.960", "Id": "11495", "Score": "1", "Tags": [ "python" ], "Title": "How to (and should I) avoid repetition while assigning values from different sources?" }
11495
<p>I created this as part of an interview process of graduate programming job. Submitted the code to them, and I was called for an interview. </p> <p>This is the assignment brief: <a href="http://knight-path.sourceforge.net/puzzle.html" rel="nofollow">http://knight-path.sourceforge.net/puzzle.html</a>, however I was t...
[]
[ { "body": "<p>I personally wouldn't do things like <code>this.build();</code> but just <code>build();</code>... although that's a matter of taste. IMO <code>this</code> doesn't clarify anything but just adds noise to the code.</p>\n\n<hr>\n\n<p>I don't see any reason why your <code>squares</code> is a linked li...
{ "AcceptedAnswerId": "11504", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T03:05:26.803", "Id": "11496", "Score": "3", "Tags": [ "java", "design-patterns", "object-oriented" ], "Title": "Knight's Travails solution" }
11496
<p>I recently wrote my first C# app that's goal it to take a drive letter and output a CSV list of some basic information. <code>TOTALSPACE,FREESPACE,STATUS</code>.</p> <p>I've been wondering If it would be possible to make this application even faster. Got any good suggestions?</p> <pre><code>using System; using Sys...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T02:57:43.093", "Id": "18475", "Score": "0", "body": "I'm assuming that `DriveInfo` is a `class`..... Possibly provide us with that?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T23:17:44.217", "...
[ { "body": "<p>It is possible to make the application faster (but I am not sure that you will notice the difference unless you call the application with many arguments and have many drives). The main problem with the code is that you iterate through all the arguments, and for each argument you iterate through al...
{ "AcceptedAnswerId": "11572", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T05:29:49.003", "Id": "11498", "Score": "3", "Tags": [ "c#" ], "Title": "Optimize DriveSpace Checker" }
11498
<p>This program downloads a Code Review HTML file and parses it.</p> <p>Could you review my program?</p> <p>Main.java</p> <pre><code>import java.net.URL; public class Main { public static void main(String[] args) throws Exception { final String site1 = "http://codereview.stackexchange.com/questions/"; ...
[]
[ { "body": "<pre><code>public static void main(String[] args) throws Exception {\n final String site1 = \"http://codereview.stackexchange.com/questions/\";\n String site2;\n String site3;\n</code></pre>\n\n<p>Why do define site1 as a final constant, but delay the other assignments until later? They shou...
{ "AcceptedAnswerId": "11513", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T08:35:35.267", "Id": "11501", "Score": "2", "Tags": [ "java", "html", "parsing", "regex", "web-scraping" ], "Title": "HTML downloader and parser for CR" }
11501
<p>A little while ago I wrote some jQuery code to make a div flip (similar to the Apple Dashboard). I know there is already code that has this idea from Jon Raasch, but this code positioned divs absolutely, which I did not need for my cause.</p> <p>I just wondered if anyone could give me some advice as to how to tidy ...
[]
[ { "body": "<p>Looks cool, nice job!</p>\n\n<p>One this I would say is that the plugin makes too many assumptions about the client's DOM structure. Having fixed selectors like <code>$('.front')</code> and <code>$('.back')</code> within your plugin script is dangerous -- what if I'm working in a page that has a <...
{ "AcceptedAnswerId": "11562", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T11:23:27.383", "Id": "11502", "Score": "4", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "jQuery 'flip' plugin" }
11502
<p>I only recently started coding so I know my code is not very good, but i would really appreciate any help on improving my code.</p> <p>my database table looks like this game_id |title |developer |publisher |genre |release_date |platform </p> <p>rating |image_location |description</p> <p>the first page th...
[]
[ { "body": "<p>here's a quick run down on your script from my perspective. Hopefully it will help you out and make your code a bit more efficient and a little prettier! :)</p>\n\n<p>Whilst admirable that you are attempting to stop SQL injection attacks with <code>mysql_real_escape_string()</code> it is really no...
{ "AcceptedAnswerId": "11533", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T05:14:16.127", "Id": "11503", "Score": "2", "Tags": [ "php", "mysql", "search" ], "Title": "need help improving mysql and php filter code" }
11503
<p>I've an <code>IEnumerable&lt;T&gt;</code> source which takes time to generate each item. Once an item is generated, I want to cache it to avoid recomputing the same thing. I want to separate out caching logic from original source.</p> <p>A few things that bother me are:</p> <ol> <li>Where should I have <code>_cach...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T09:46:47.427", "Id": "18576", "Score": "3", "body": "The idea of IEnumerable is that it is lazy and executed on command. If you want to cache data, then why not put it in a List? You can then write further queries onto your list." ...
[ { "body": "<p>You do not have to go to all this trouble to implement a caching wrapper. It can be done much more simply:</p>\n\n<pre><code>class CachedEnumerable&lt;T&gt; : IEnumerable&lt;T&gt; \n{\n private readonly IEnumerable&lt;T&gt; producer;\n private IEnumerable&lt;T&gt; cache;\n\n public Cached...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T20:12:03.767", "Id": "11505", "Score": "5", "Tags": [ "c#", ".net", "linq", "cache", "ienumerable" ], "Title": "Generic cached IEnumerable<T>" }
11505
<p>This is my solution to the <a href="http://learnpythonthehardway.org/book/ex48.html" rel="nofollow">exercise 48 of Learn Python the hard way by Zed Shaw</a>. Please visit the link for testing suite and requirements.</p> <p>I'm worried about my the word banks I have created (COMPASS, VERBS, etc...) as this seems a d...
[]
[ { "body": "<pre><code>lword = string.lower(word) \n</code></pre>\n\n<p>There is no need to import the string module for this, you can use:</p>\n\n<pre><code>lword = word.lower()\n</code></pre>\n\n<p>As for this:</p>\n\n<pre><code>elif int(lword):\n</code></pre>\n\n<p>Probably better as</p>\n\n<pre><code>elif l...
{ "AcceptedAnswerId": "11509", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T20:37:51.960", "Id": "11506", "Score": "1", "Tags": [ "python", "unit-testing", "exception-handling" ], "Title": "LPTHW - ex48 - Handling exceptions and unit testing" }
11506
<p>I'm trying to improve my code. I've some doubts about db_index, primary_key and unique parameters.</p> <pre><code> # -*- coding: UTF-8 -*- from django.db import models from django.contrib.auth.models import User #=================================================================================# ...
[]
[ { "body": "<p>Is it introspected DB or newly created models? If it is created, you do not need <code>SOMETHING_id</code> fields, Django creates primary keys automatically.</p>\n\n<p>Always use unicode strings (<code>u'something'</code>) for everything that is displayed to user and can contain non-ascii characte...
{ "AcceptedAnswerId": "11517", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T20:45:15.057", "Id": "11507", "Score": "1", "Tags": [ "python", "django" ], "Title": "Doubts about db_index, primary_key and unique parameters" }
11507
<p>I am looking to make the below code a bit more efficient / OOP based. As can be seen by the X, Y &amp; Z variables, there is a bit of duplication here. Any suggestions on how to make this code more pythonic?</p> <p>The code functions as I wish and the end result is to import the dictionary values into a MySQL datab...
[]
[ { "body": "<pre><code>import fnmatch\nimport os\nimport pyexiv2\n\nmatches = []\ndict1 = {}\n</code></pre>\n\n<p><code>dict1</code> isn't a great name because its hard to guess what it might be for. </p>\n\n<pre><code># The aim of this script is to recursively search across a directory for all\n# JPEG files. Ea...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T21:38:10.247", "Id": "11508", "Score": "1", "Tags": [ "python", "object-oriented" ], "Title": "JPEG metadata processor" }
11508
<p>The goal is to display all posts with their categories underneath them. The code below accomplishes this, however I'm thinking it's bad and was hoping someone could review and offer some feedback.</p> <p>Because each post can have many categories and because each category can belong to many posts, I used a many-to...
[]
[ { "body": "<p>By the looks of it, you</p>\n\n<ul>\n<li>get the category IDs using the post ID</li>\n<li>get the categories according to the category IDs you just had</li>\n</ul>\n\n<p>Well, you can use JOINS to bridge the tables:</p>\n\n<pre><code>SELECT c.category_name //select category name\nFROM cats_t...
{ "AcceptedAnswerId": "11519", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T06:12:05.580", "Id": "11518", "Score": "0", "Tags": [ "php", "mysql" ], "Title": "Displaying data from from many-to-many table" }
11518
<p>I just finished my working code, but still want to improve it.</p> <p>I want to transform this input:</p> <pre><code>&lt;item&gt;asdf&lt;/item&gt; &lt;item&gt;asdf&lt;/item&gt; &lt;item&gt;asdf&lt;/item&gt; </code></pre> <p>to this output:</p> <pre><code>&lt;string name="x1"&gt;asdf&lt;/string&gt; &lt;string nam...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T09:00:52.740", "Id": "18480", "Score": "0", "body": "So, you're saying your code is too slow? Have you profiled it? How big is the file you're converting? Are you sure the code is the bottleneck and not the disk?" }, { "Cont...
[ { "body": "<p>Don't parse it through string manipulation, use the XML libraries in the framework. I'd recommend LINQ to XML. Parse it and make your changes.</p>\n\n<pre><code>var xmlStr = @\"&lt;root&gt;\n&lt;item&gt;asdf&lt;/item&gt;\n&lt;item&gt;asdf&lt;/item&gt;\n&lt;item&gt;asdf&lt;/item&gt;\n&lt;/root&gt...
{ "AcceptedAnswerId": "11521", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T07:16:39.650", "Id": "11520", "Score": "0", "Tags": [ "c#", "strings", "xml" ], "Title": "Manipulate XML files in c#" }
11520
<p>I want to write an example for a language similar to Haskell called <a href="http://code.google.com/p/frege/">Frege</a>. While the interpreter is conceptually easy, it is lengthy and looks still quite messy. Note that I <strong>don't</strong> want to use Parsec etc, as it isn't available yet in Frege. Please help me...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T19:23:34.180", "Id": "18493", "Score": "0", "body": "This is about as straightforward as it gets. You could line some things up with whitespace, and perhaps use `where` instead of `let/in`, but other than that, there's really not mu...
[ { "body": "<p>Disclaimer: I know nothing about Frege, all comments apply to Haskell only.</p>\n\n<p>1)</p>\n\n<p>Running <a href=\"http://community.haskell.org/~ndm/hlint/\">hlint</a> on your code shows places where you can remove <code>$</code> and brackets. Please do it!</p>\n\n<p>2)</p>\n\n<p>In <code>exec</...
{ "AcceptedAnswerId": "11639", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T10:19:49.320", "Id": "11525", "Score": "9", "Tags": [ "haskell", "brainfuck", "interpreter" ], "Title": "Brainfuck Interpreter" }
11525
<p>I wrote a little function to compact long text. I am relatively new to JavaScript so I am not sure I wrote it as elegantly as possible. I wrote it to be runnable on the server side (Node.js) as well, so can't use jQuery or such. Can the code be improved?</p> <pre><code>// change a long text into "bla bla bla... (m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T14:58:13.120", "Id": "18485", "Score": "0", "body": "Why do you need the br? Can't you use `white-space: pre-line;`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T22:38:45.480", "Id": "18498", ...
[ { "body": "<ol>\n<li><p>Instead of <code>pn</code> use a longer variable name. A variable like this with such a big scope really deserves a longer name. It would make the code easier to read.</p>\n\n<pre><code>var pn = text.split(' ');\n</code></pre></li>\n<li><p>Instead of commenting use the comment name as a ...
{ "AcceptedAnswerId": "11529", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T13:52:19.257", "Id": "11528", "Score": "1", "Tags": [ "javascript", "node.js" ], "Title": "Collapse long text (with more/less links)" }
11528
<p>Having spent years writing procedural PHP (albeit with a moderate understanding of OOP from Java) I took the plunge and have attempted to write an autoload class for my PHP applications.</p> <pre><code>abstract class AutoloadClass { protected $_observers = array(); protected $structure; protected $exte...
[]
[ { "body": "<p>Yes, this is <strong>massive overkill</strong>. I'll cover this first, then give some minor comments.</p>\n\n<h2>Autoload Overkill</h2>\n\n<p>The point of autoloading is that it happens automatically. You just assume that it works (because it has to). What happens when you can't autoload a cla...
{ "AcceptedAnswerId": "11543", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T15:03:45.487", "Id": "11530", "Score": "2", "Tags": [ "php", "object-oriented", "php5" ], "Title": "PHP autoload class" }
11530
<p>I need to generate a sequence of <code>int</code> values: <code>{ 0, 1, 2, ... }</code>, but there's a twist: I need to access them from different threads.</p> <p>So I wrote this code:</p> <pre><code>class Counter { private static Counter instance = new Counter(); private static int i = 0; public stat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T17:12:36.823", "Id": "18487", "Score": "0", "body": "Your code looks quite simple, readable and obvious to me (ignoring the unnecessary singleton “noise”). Why do you want to do it even simpler?" }, { "ContentLicense": "CC B...
[ { "body": "<pre><code>private static int i = 0;\n</code></pre>\n\n<p>Are you sure that <code>i</code> should be static? If it's static there isn't too much sense of the <code>Counter instance = new Counter()</code> instance and the <code>Next</code> and the <code>Reset</code> methods also could be static.</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T16:52:44.243", "Id": "11531", "Score": "1", "Tags": [ "c#", "multithreading" ], "Title": "Generate consecutive sentence of int values accessed from different threads" }
11531
<p>Commenting omitted to give you the idea. I've been toying with this recently as a variant of the Builder pattern. I've recently fallen in love with immutable objects for the benefits they give in larger concurrent systems.</p> <p>Questions: </p> <p>Is there a way to do this without having to instantiate two Obje...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T20:56:35.450", "Id": "18496", "Score": "1", "body": "Your code doesn't compile: The inner class must be just `Mutable`, and you need to rename the `finalize` method (which is already defined in `Object`)." }, { "ContentLicen...
[ { "body": "<p>If you <em>really</em> want to avoid object creation, you have no other choice as dropping <code>final</code>, e.g.:</p>\n\n<pre><code>public interface Something {\n\n public int getSomeInteger();\n public String getSomeString();\n\n public static class Mutable implements Something {\n ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-06T20:39:21.277", "Id": "11538", "Score": "1", "Tags": [ "java", "design-patterns", "immutability" ], "Title": "Comments on my Java pattern for Mutable turned Immutable objects" }
11538
<p>I was looking for a way of doing simple message passing in Guile and found some references to the module (ice-9 occam-channel) which is a pretty nifty, but undocumented, module for occam-like channels. Since I decided I wanted to use buffered channels I decided to try and write my own implementation of it based on t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T13:49:31.003", "Id": "18527", "Score": "0", "body": "No suggestions (which is why this isn't an answer). In terms of your surprise, I'd be more suspicious of overlong code than of short code that does the same thing. If you're comin...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T01:43:36.707", "Id": "11542", "Score": "1", "Tags": [ "lisp", "scheme", "multithreading" ], "Title": "Implementing buffered channels in Guile" }
11542
<p>The output result is perfect to what I wanted, but takes a tad bit too long to pull data then render into a graph. Is there a better way to rewrite this code to speed up the process?</p> <pre><code>CASE "TestGrid": $SnapArrayResult = array(); $PlayArrayResult = array('A','B','C','D'); echo "&lt;table i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T10:52:41.267", "Id": "18519", "Score": "0", "body": "How large is your data? Do you have index on `alliance`? try not using sql functions. enable caching." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-...
[ { "body": "<p>Look at the code below. I haven't tried it yet, but the idea is avoid iterating query that will take a long time. So, I just use one query.</p>\n\n<pre><code>CASE \"TestGrid\":\n $SnapArrayResult = array();\n $PlayArrayResult = array('A','B','C','D');\n echo \"&lt;table id='tb...
{ "AcceptedAnswerId": "11549", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T10:48:31.673", "Id": "11548", "Score": "2", "Tags": [ "php", "mysql", "ajax" ], "Title": "Rendering data into a graph" }
11548
<p>Here is my template code</p> <pre><code>&lt;?php namespace classes; /** * Description of Template * * @author Aamir */ class Template { private $templateVars, $templateFile ; protected static $templateFolder, $masterTemplate, $masterInstance, $placehold...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T13:11:59.097", "Id": "18524", "Score": "0", "body": "I'm still looking over it, but the first major improvement I would suggest is to indent everything appropriately. You don't seem to indent the first level for some reason." }, ...
[ { "body": "<p>A lot of these suggestions are just that, suggestions. I have little to add for improvement except for aesthetics or readability. So here it goes.</p>\n\n<p><strong>Class Properties</strong></p>\n\n<p>Cool thing about class properties is that they can be combined when initially declaring them. A l...
{ "AcceptedAnswerId": "11560", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T12:10:05.067", "Id": "11551", "Score": "3", "Tags": [ "php", "template" ], "Title": "Template system with master layout" }
11551
<p>I'm writing a method to save an input stream to an output stream. What's the optimal size for the buffer? Here's my method: </p> <pre><code>/** * Saves the given InputStream to a file at the destination. Does not check whether the destination exists. * * @param inputStream * @param destination * @throws FileNotFoun...
[]
[ { "body": "<p>It depends on a lot of factors, there's no universally \"optimal\" size. 512kB is probably good enough.</p>\n\n<p>If you want, you can always benchmark it for various buffer sizes: this will let you know what the best option is for your computer and OS.</p>\n", "comments": [ { "C...
{ "AcceptedAnswerId": "11557", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T14:09:50.820", "Id": "11555", "Score": "1", "Tags": [ "java", "optimization" ], "Title": "Optimal buffer size for output stream" }
11555
<p>I'm making a method to save a <code>byte[]</code> to a file. It's for a <a href="https://github.com/kentcdodds/Java-Helper" rel="nofollow noreferrer">Java Helper</a> I'm writing, so it needs to be able to handle any kind of system. I saw on <a href="http://www.java-examples.com/write-byte-array-file-using-fileoutput...
[]
[ { "body": "<p>Given the care and effort that has been put into performance within the JVM and Java standard libraries, it is a virtual certainty that the second implementation will be faster.</p>\n\n<p>However, does it really matter? Worrying about optimization is generally only useful if the system performance...
{ "AcceptedAnswerId": "11559", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T14:15:35.790", "Id": "11556", "Score": "2", "Tags": [ "java", "optimization", "file", "comparative-review" ], "Title": "Optimal method for writing bytes to file" }
11556
<p>I am writing a program which automatically crawls codes from this site!</p> <p>Would you please review my code?</p> <p>The required .jars: <a href="http://jsoup.org/packages/jsoup-1.6.2.jar" rel="nofollow">jsoup</a>, <a href="http://www.nic.funet.fi/pub/mirrors/apache.org//commons/io/binaries/commons-io-2.3-bin.zi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T04:14:59.537", "Id": "18559", "Score": "0", "body": "any reason you haven't taken my advice to use something like jSoup?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T08:27:43.543", "Id": "18568...
[ { "body": "<p>At least at first sight I couldn't tell you were new to Java, so that's pretty good. :) Not many issues there, but a some:</p>\n\n<p>First, your <code>divideFile</code> method has some duplicate code. You should refactor that into a new method. The method also never closes the <code>BufferedWriter...
{ "AcceptedAnswerId": "11577", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T14:34:57.400", "Id": "11558", "Score": "2", "Tags": [ "java", "beginner", "web-scraping", "stackexchange" ], "Title": "CR Stack Exchange crawler" }
11558
Model–View–Controller (MVC) is a design pattern for computer user interfaces that divides an application into three areas of responsibility. It is often applied to websites.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T16:00:49.867", "Id": "11564", "Score": "0", "Tags": null, "Title": null }
11564
<p>I'm working on adding checkbox functionality that controls adding new checkboxes to a <code>div</code> element as well a tracking checkbox behavior. My goal is to make this dirt simple. I've noticed that there is some JavaScript function prototypes for creating objects such as checkboxes and also controlling basic...
[]
[ { "body": "<p>In my opinion, it seems like this should be it's own class. You should have another object to control the <code>FamousPerson</code> objects and add them when they are instantiated. I would also decouple the checkbox from the <code>FamousPerson</code> class itself and tie the behavior in elsewhere....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T18:11:41.393", "Id": "11569", "Score": "4", "Tags": [ "javascript", "form" ], "Title": "Adding a checkbox to a JavaScript class object" }
11569
<p>From my original question on Stack Overflow: <a href="https://stackoverflow.com/questions/10486743/is-my-implementation-of-reversing-a-linked-list-correct">Is my implementation of reversing a linked list correct?</a></p> <p>I'm a beginner at C and I'd like to know about style, and correctness of the reverse algorit...
[]
[ { "body": "<p>Good fix for the edge case of only one element, but what happens if there's only <em>two</em> elements? I'm seeing another edge case concern.</p>\n\n<pre><code>//inside reverse_list\n...\nlast = head;\ncurr = head-&gt;next;\nhead = curr-&gt;next; //or head-&gt;next-&gt;next - null if two elements\...
{ "AcceptedAnswerId": "11581", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T20:15:29.690", "Id": "11573", "Score": "6", "Tags": [ "c", "beginner", "recursion", "memory-management" ], "Title": "Reversing a linked list by iteration and recursion" }
11573
<p>I'm uploading videos to Vimeo using the <a href="http://vimeo.com/api/docs/upload" rel="nofollow">VimeoAPI</a>. I want to show a progress bar to the user. The only way to do this with the VimeoAPI is to call a method to the server which verifies the chunk you've just sent. I can send a video up in chunks of 8 bytes ...
[]
[ { "body": "<p>An idea: measure how fast is the user's internet connection, how many bytes they can send per ten second, for example, then use this as chunk size. It should have a minimum value which is bigger than 8 bytes because of the TCP/IP overhead. Check the overhead with a packet sniffer (<a href=\"http:/...
{ "AcceptedAnswerId": "11583", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T02:01:49.603", "Id": "11578", "Score": "1", "Tags": [ "java", "optimization" ], "Title": "Optimal buffer size for HTTP PUT" }
11578
<p>I use the following code to store user passwords.</p> <pre><code>string password = "..."; string user_salt = System.Web.Security.Membership.GeneratePassword(20, 5); string common_salt = "..."; byte[] hash_target = Encoding.UTF8.GetBytes(password + user_salt + common_salt); string password_hash = BitConverter. T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T13:41:18.933", "Id": "18586", "Score": "3", "body": "Semi-related: `SHA512CryptoServiceProvider` implements `IDisposable`, so it should be assigned to a variable and wrapped in a `using` block." }, { "ContentLicense": "CC BY...
[ { "body": "<p>In SQL Server, we store password salts as an int and password hashes as binary. There really is no reason to have the salt as a string value. Also, there is no need to have the hash as a string. You can use the bytes from the computed hash (which is a fixed, known number of bytes) and store the bi...
{ "AcceptedAnswerId": "11615", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T12:05:58.637", "Id": "11588", "Score": "1", "Tags": [ "c#", "security" ], "Title": "Password hashing" }
11588
<p>This linq query works, and it does what I want it to do, but is there any other way I could improve the query so I'm not repeating <code>a.AnswerRevisions.OrderByDescending(r =&gt; r.DateCreated).FirstOrDefault()</code>?</p> <pre><code>IQueryable&lt;Article&gt; query = from a in _db.Articles ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T13:14:43.393", "Id": "18584", "Score": "3", "body": "I'd rather do `.UpVotes < .Downvotes`." } ]
[ { "body": "<p>Use the <code>let</code> statement and also do the final <code>orderby</code> after the <code>where</code> clause, this will increase efficiency, as less entries will have to be sorted</p>\n\n<pre><code>IQueryable&lt;Article&gt; query = from a in _db.Articles \n let rev = a.AnswerRevisions.Ord...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T12:41:41.823", "Id": "11589", "Score": "2", "Tags": [ "c#", "linq", "entity-framework" ], "Title": "How could I remove repetition from this linq-to-entities query?" }
11589
<p>I'm novice in C++, I've recently read some simple books and now I'm reading <code>Scott Meyers "Effective C++"</code> book, but I understand that I can't apply new knowledge.</p> <p>I have to realize a simple C++ class that (with help of openCV) generates bitmap kernels consist of n circles.</p> <p>Here is my code...
[]
[ { "body": "<p>The first thing that I notice is:</p>\n<pre><code>int maxArr(int arr[], int length)\n</code></pre>\n<p>Notice that you have to pass an array and a length (as the size is not part of the array). In C++ we usually fix this by using std::vector (or std::array in C++11). Pass this object around as it ...
{ "AcceptedAnswerId": "11595", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T13:57:10.737", "Id": "11592", "Score": "3", "Tags": [ "c++" ], "Title": "C++ Kernel Factory class" }
11592
<p>In an effort to learn as much as possible about best development practices and software architecture, I created my own MVC framework using PHP (github: <a href="https://github.com/alemmedia/miniMVC" rel="nofollow">https://github.com/alemmedia/miniMVC</a>). I've found that this has resulted in phenomenal improvements...
[]
[ { "body": "<p>Use braces <code>{}</code>! Can't say this enough. PHP has made many mistakes, but allowing this syntax is by far the worst. Adding those braces only increases file size by 2 bits! And it increases readability so much!</p>\n\n<pre><code>if ( !isset(self::$instance) ) { self::$instance = new self()...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T15:59:56.707", "Id": "11594", "Score": "1", "Tags": [ "php", "mvc" ], "Title": "PHP MVC Framework Class" }
11594
<p>I have written a program to find all the possible permutations of a given list of items. This precisely means that my program prints all possible P(n,r) values for r=0 to n.</p> <pre><code>package com.algorithm; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Ha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T18:23:34.073", "Id": "18608", "Score": "0", "body": "http://codereview.stackexchange.com/a/6991/9390" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T20:26:54.823", "Id": "18617", "Score": "2",...
[ { "body": "<p>The number of permutations typically increases factorially. Since 3! = 6, 4! = 24, 5! = 120, 6! = 720, 7! = 5040, 8! = 40,320, 9! = 362,880, 10! = 3,628,800, 11! = 39,916,800, 12! = 479,001,600.</p>\n\n<p>You can see that it get very large, very quickly. The output would be similarly huge.</p>\n\n...
{ "AcceptedAnswerId": "11600", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T17:35:53.820", "Id": "11598", "Score": "8", "Tags": [ "java", "algorithm", "combinatorics" ], "Title": "Permutations of a list of numbers" }
11598
<p>Suppose I have this code:</p> <pre><code>public interface BaseType { public void doSomething(); } public class ExtendedTypeA implements BaseType { //No Instance Variables @Override public void doSomething() { //really do something } } public class ExtendedTypeB implements BaseTyp...
[]
[ { "body": "<p>Two things strike me:</p>\n\n<ul>\n<li>There's no need to have a separate factory class when you could put the functionality into the enum, unless you expect to have other factory implementations</li>\n<li>As you say, if the classes are stateless, there's no need to create a new instance on each c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-08T14:47:48.240", "Id": "11603", "Score": "9", "Tags": [ "java", "factory-method" ], "Title": "Is this a good implementation of the Factory Pattern?" }
11603
<p>I was wondering if there was any way I would be able to improve my HTML/CSS. Would you mind reviewing the following and telling me what I should do?</p> <p>CSS:</p> <pre><code>&lt;style type="text/css"&gt; body { font-family:Georgia, Palatino, Times, 'Times New Roman', serif; color:#333333; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T03:46:38.897", "Id": "18628", "Score": "0", "body": "What are \"{block:IndexPage}\" type like things? I never seen them in html." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T11:48:59.530", "Id...
[ { "body": "<p>The first thing that really caught my eye is your usage of <code>margin-...</code>. If I am setting more than two sides of margin I like to use the syntax <code>margin: &lt;top&gt; &lt;right&gt; &lt;bottom&gt; &lt;left&gt;;</code> So this... </p>\n\n<pre><code>#portrait {\n margin-left:auto;\n ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T00:56:00.357", "Id": "11607", "Score": "2", "Tags": [ "html", "css" ], "Title": "HTML and CSS for a theme engine" }
11607
<p>I am a 3rd-year computer science undergraduate. One of my university lecturers has developed his own page for students to submit work. It came up that one student was accused of hacking (sic) by the system. The problem was the characters used in the comment field.</p> <p>The lecturer claimed that he needed to filte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T13:20:15.340", "Id": "18646", "Score": "0", "body": "Not going to leave an actual answer because I've not done enough research in security to make any answer of mine educated enough. However, I am concerned about your passing any so...
[ { "body": "<p>It seems fine for me.</p>\n\n<p>Some small changes:</p>\n\n<ol>\n<li><p>I'd change the action to </p>\n\n<pre><code>&lt;form action=\"&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;\" method=\"post\"&gt;\n</code></pre>\n\n<p><a href=\"http://www.html-form-guide.com/php-form/php-form-action...
{ "AcceptedAnswerId": "11640", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T04:21:34.680", "Id": "11610", "Score": "5", "Tags": [ "php", "sql", "security" ], "Title": "Testing filtering of certain characters" }
11610
<p>I'm using Selenium to test a PHP site that goes through the following process:</p> <ol> <li>Register user</li> <li>Log in</li> <li>Fill out Form 1 and submit</li> <li>Fill out Form 2 and submit</li> <li>Fill out Form 3 and submit</li> <li>(tear down) Delete user</li> </ol> <p>A real user would go through these ste...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-11T07:54:58.150", "Id": "18726", "Score": "2", "body": "The \"bite sized tests\" remark is certainly true for unit tests (which test a single chunk of code in isolation), but I don't think it's necessarially so for a functional test (w...
[ { "body": "<h2>@depends does not define order</h2>\n\n<blockquote>\n <p>[@depends] do not define the order in which the test methods are to be executed</p>\n</blockquote>\n\n<p>Using <a href=\"http://www.phpunit.de/manual/3.6/en/writing-tests-for-phpunit.html\" rel=\"nofollow\">@depends</a> and not returning/p...
{ "AcceptedAnswerId": "11613", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T05:40:04.953", "Id": "11611", "Score": "2", "Tags": [ "php" ], "Title": "Functional testing issue - Feels like one long test" }
11611
<p>I am using PHP to get data from a MySQL database, and use the data to drop multiple markers into Google Maps. Please give me some suggestions for my code.</p> <pre><code>&lt;?php require_once 'Common/system_start.php'; $sql="select * from tab_mem order by sn desc "; $result= mysql_query($sql); $data=mysql_fetch_as...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T08:51:35.737", "Id": "18631", "Score": "2", "body": "fixing the whitespace so it's a little easier to read would help" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T13:56:36.713", "Id": "18650", ...
[ { "body": "<p><strong>PHP</strong></p>\n\n<p>The commonly accepted approach to SQL statements is to make commands all caps, so I would convert my SQL statements to look like so...</p>\n\n<pre><code>$sql=\"SELECT * FROM tab_mem ORDER BY sn DESC \";\n</code></pre>\n\n<p>In other words, only the information from y...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T08:02:28.817", "Id": "11612", "Score": "1", "Tags": [ "php", "beginner", "html5", "google-apps-script", "google-maps" ], "Title": "Markers on Google Maps" }
11612
<p>I am looking for ways to enhance this function in C++. </p> <p>The function gets a date and returns the total number of seconds since the epoch (01/01/1970).</p> <p>Do you have any suggestion regarding the algorithm, the code style, etc ?</p> <p>Note: I use this function instead of the standard library functions ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T18:07:19.157", "Id": "18661", "Score": "1", "body": "Its a leap year if divisible by 400. Thus 1900 is not but 2000 was a leap year." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T18:10:45.440", ...
[ { "body": "<p>Edit: I very wrongly accused Jacobi of posting a flawed algorithm. So I removed my ranting and replaced by:</p>\n\n<p>I had a try compiling your code and I worked on it to represent how I would have written it. See below. I hope this gives you hints about a different possible coding style. I hope ...
{ "AcceptedAnswerId": "11662", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-09T10:36:08.273", "Id": "11614", "Score": "2", "Tags": [ "c++", "datetime", "reinventing-the-wheel" ], "Title": "Determine total number of seconds since the epoch" }
11614