body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I ran into a problem, I'm using MyIsam tables in mysql database, using PDO to connect.</p> <p>In all my tests (calling for 1 user everything works fine), now having around 300 users connected at the same time all day making requests is really really slowing down mySQL. Ive got my.cnf with (key_buffer=512M and max_c...
[]
[ { "body": "<p>One thing I can see right off the bat is that you're likely to be selecting more data than you need. A good rule of thumb is to <em>never</em> use <code>SELECT * FROM</code>. Only select the columns that you need for your query.</p>\n\n<p>For example, in your gifts query you could change the query...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-09T17:07:11.423", "Id": "25993", "Score": "2", "Tags": [ "php", "mysql", "pdo" ], "Title": "PHP PDO mysql multiple queries mak" }
25993
<p>I am creating new elements for a webpage at run-time and I have code like this:</p> <pre><code> var dynDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("Div") {ID = "dynDiv"}; dynDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Red"); dynDiv.Style.Add(HtmlTextWriterStyle.Position, "absolu...
[]
[ { "body": "<p>Under normal circumstances, you could use collection initializer to write your code this way:</p>\n\n<pre><code>var dynDiv = new HtmlGenericControl(\"Div\")\n{\n ID = \"dynDiv\",\n Style =\n {\n { HtmlTextWriterStyle.BackgroundColor, \"Red\" },\n { HtmlTextWriterStyle.Positi...
{ "AcceptedAnswerId": "26001", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-09T17:37:43.747", "Id": "25994", "Score": "2", "Tags": [ "c#", "html", "asp.net" ], "Title": "Is there a method to add multiple properties to HtmlTextWriterStyle?" }
25994
<p>How do I elegantly check for null before calling a method on an object? This is how I do it right now:</p> <pre><code>var title = document.querySelector('title'); title = title ? title.text : ''; </code></pre> <p>Null Object pattern would be nice in this case but I don't own the <code>document.querySelector</code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-09T20:21:42.053", "Id": "40208", "Score": "2", "body": "`var title = document.querySelector('title') || {text:''};`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-09T20:26:21.203", "Id": "40209", "...
[ { "body": "<p>You can do this:</p>\n\n<pre><code>var title = document.querySelector('title') || {text:''};\n</code></pre>\n\n<p>then just use <code>title.text</code> in-line.</p>\n\n<p>Alternatively, you could use this one-liner:</p>\n\n<pre><code>var title = (document.querySelector('title') || {text:''}).text;...
{ "AcceptedAnswerId": "26010", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-09T20:14:21.213", "Id": "26000", "Score": "4", "Tags": [ "javascript" ], "Title": "Elegantly check for null before method call" }
26000
<p>Preamble: it's a self-assigned and pure syntetic task to learn (and remember what I already knew) C# threads and synchronization and data structures.</p> <p>The original question was here <a href="https://stackoverflow.com/questions/16458937/synchronization-of-remote-files-download">https://stackoverflow.com/questi...
[]
[ { "body": "<p>If you change <code>_retrieveFile</code> to return a <code>Task</code> that's already started, you could simplify the whole <code>Get()</code> into just:</p>\n\n<pre><code>return _progress.GetOrAdd(key, _retrieveFile).Result;\n</code></pre>\n\n<p>Also, it seems that <code>Downloader</code> with em...
{ "AcceptedAnswerId": "26004", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-09T20:46:18.850", "Id": "26002", "Score": "2", "Tags": [ "c#", "multithreading", "thread-safety" ], "Title": "Synchronization of remote files download" }
26002
<p>I am struggling with the basic concepts of SASS.</p> <p>I have a page that has multiple section, all of them are sharing properties like <code>width</code>, <code>font-size</code> etc.</p> <p>I would like to optimize my code and do one of the following:</p> <p><strong>1. Use an extendable silent class</strong></p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-27T19:48:03.740", "Id": "97290", "Score": "0", "body": "I would def. go with option 3. It seems like an attempt to over complicate your code just to use cool SASS features." } ]
[ { "body": "<p>Calling a mix-in for each section will duplicate the rules. Remember, you want to keep your code as D.R.Y (do not repeat) as possible. Inuit.css does something similar with the margins of elements. They use a %rhythm silent class that defines a global margin for anything that extends it. </p>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-09T20:48:31.820", "Id": "26003", "Score": "4", "Tags": [ "optimization", "design-patterns", "sass" ], "Title": "Mixin, @extend or (silent) class?" }
26003
<p>I am looking for someone to review my solution to a jQuery DOM manipulation exercise on appendto.com: <a href="http://learn.appendto.com/lesson/dom-manipulation-101#exercise" rel="nofollow">http://learn.appendto.com/lesson/dom-manipulation-101#exercise</a></p> <p>I'm wondering if there is a way I can optimize or if...
[]
[ { "body": "<p>Your code's very nice. My points below are mostly of the \"but what if...\" variety concerning the DOM manipulation, rather than the JavaScript itself. In other words, your solution seems spot on for the given exercise, whereas my comments mostly refer to situations which are not part of the exerc...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-09T22:52:16.493", "Id": "26006", "Score": "1", "Tags": [ "javascript", "jquery", "jquery-ui" ], "Title": "Using jquery to prepare jQuery UI tabs, optimize?" }
26006
<p>I need objects in python that I can compare, reference to and hash.</p> <p>In principal a tuple or list would be good enough just that a list I cannot hash and the tuple I cannot change, except replacing it which means losing references to it.</p> <p>So I created a class for it, but still have the feeling there sh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T00:26:33.767", "Id": "40227", "Score": "0", "body": "Why do you want the object to be hashable?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T00:33:30.167", "Id": "40228", "Score": "0", ...
[ { "body": "<p>The python dictionary assumes that the keys are immutable. It assumes they will not change. That's why mutable classes in python (such as lists) don't hash. Its to prevent you from putting them in dicts which just won't work. </p>\n\n<p>As a result the entire premise of your class is wrong. You sh...
{ "AcceptedAnswerId": "26013", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-09T23:21:26.020", "Id": "26008", "Score": "3", "Tags": [ "python" ], "Title": "Class for simple python object to be hashed and referenced" }
26008
<p>when we need to add some javascript code to html, where we have to put it?</p> <p>What is the best practice:</p> <p>in line:</p> <pre><code>&lt;script type="text/javascript"&gt;document.write(new Date().getFullYear())&lt;/script&gt; </code></pre> <p></p> <p>or centralized:</p> <pre><code>&lt;header&gt;&lt;scri...
[]
[ { "body": "<p>Optimally, it's loaded just before the body tag closes</p>\n\n<pre><code> &lt;!-- all html above here --&gt;\n &lt;script src=\"...\"&gt;&lt;/script&gt;\n&lt;/body&gt;\n</code></pre>\n\n<p>for the following common reasons:</p>\n\n<ul>\n<li><p>The DOM elements that you are operating are safel...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T10:34:25.497", "Id": "26020", "Score": "2", "Tags": [ "javascript", "dom" ], "Title": "when we need to add some javascript code to html, where we have to put it?" }
26020
<p>.NET does not support generic numbers. It is not possible to enforce a generic method with generic argument T that T is a number. The following code will simply not compile:</p> <pre><code>public T DifficultCalculation&lt;T&gt;(T a, T b) { T result = a * b + a; // &lt;== WILL NOT COMPILE! return result; } C...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-02-24T13:53:13.147", "Id": "148358", "Score": "0", "body": "It is not currently possible to multiply a double with an integer with automatic widening." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-03-04T10:35:4...
[ { "body": "<p>This is a nifty implementation! Only one thought I came up with: I think <code>Number</code> is too tightly coupled with <code>Calculator</code>. Now I couldn't decouple it completely, due to the operator overloads in <code>Number</code>, but I think I made it such that you could sub in mock or di...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T11:00:32.777", "Id": "26022", "Score": "14", "Tags": [ "c#", "linq", "generics", "calculator", "overloading" ], "Title": "Generic Calculator and Generic Number" }
26022
<p>I am new to Java programming, and to help me learn, I created a simple telephone address book. The code runs as expected, but I would be interested to here from more advanced programmers if they think I should do it differently.</p> <pre><code>import com.mongodb.MongoClient; import com.mongodb.MongoException; impo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T12:11:45.697", "Id": "40268", "Score": "1", "body": "You did good. I like that you have methods that do exactly as you say they should. ie `displayAll` displays all your entries. My only small suggestion is to make all your methods ...
[ { "body": "<p>I'm not sure what version of the JDK you are using, but in Java 7 they introduced switch statements on a String variable instead of just integers. Your code could instead read like this, to make it a little bit more readable. </p>\n\n<pre><code>do {\n System.out.println(\"Enter comm...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T11:58:26.347", "Id": "26023", "Score": "6", "Tags": [ "java", "beginner", "mongodb" ], "Title": "Simple telephone address book" }
26023
<p>I have a running program. That accepts 1 to 15 variables The goal of the program was a simplifier. Based on the <strong><em>Quine–McCluskey algorithm</em></strong></p> <p>Consider 3 variables</p> <pre><code>000 001 010 011 100 101 110 111 </code></pre> <p>I group them by number of 1</p> <pre><code>000 001 010 1...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T12:39:48.780", "Id": "40270", "Score": "0", "body": "It's good to see you here." } ]
[ { "body": "<p>I don't know how to write C#, but I want to help. So my code is given in Java.</p>\n\n<ol>\n<li><p>I think <code>==</code> is an <code>O(n)</code> operation, your <code>CompareString</code> is <code>O(nlgn)</code> (<code>n = str1.Length</code>). Use a simpler and faster <code>O(n)</code> way and s...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T12:22:48.553", "Id": "26024", "Score": "1", "Tags": [ "c#" ], "Title": "Based on Quine–McCluskey algorithm. Improve Nested loop for performance" }
26024
<p>What would be the most efficient way to write the following code in Perl:</p> <pre><code> my $index = 0; foreach ( @spec ) { if ( $module =~ m/$_/ ) { splice(@spec, $index, 0, $module); last; } $index++; } </code></pre> <p>This works ...
[]
[ { "body": "<p>You want \"more efficient wordiness\"??? I presume you're not asking for golfing, but for code that's more readable from conciseness.</p>\n\n<pre><code>@spec = map { $_ eq $module ? ($_, $_) : $_ } @spec;\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T12:53:29.050", "Id": "26026", "Score": "2", "Tags": [ "perl" ], "Title": "Adding an entry for a matched $module" }
26026
<p>I would like an opinion on my code. I need a random access iterator for my custom container. If I read the C++ 2011 standard, specially chapter 24, I understood that an implementation could be the following:</p> <pre><code>class my_iterator : public std::iterator&lt;std::random_access_iterator_tag, my_element&gt; {...
[]
[ { "body": "<p>Sure but:</p>\n\n<p>Sure:</p>\n\n<pre><code> my_iterator ();\n bool operator != (my_iterator);\n pointer operator -&gt; ();\n my_iterator&amp; operator ++ ();\n my_iterator&amp; operator -- ();\n my_iterator&amp; operator += (difference_type);\n my_iterat...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T14:46:52.953", "Id": "26030", "Score": "3", "Tags": [ "c++", "c++11", "iterator", "c++0x" ], "Title": "Creating custom random access iterator in C++ 2011" }
26030
<p>Looking for a cleaner (possibly one liner) way to write the following</p> <pre><code>my $spec_2d = ( ); foreach ( @spec ) { $spec_2d[$_][0] = $spec[$_]; } @spec = @spec_2d; </code></pre> <p>Basically I'm making an array an array of arrays</p>
[]
[ { "body": "<pre><code>@spec_2d[@spec] = map [ $spec[$_] ], @spec;\n</code></pre>\n\n<p>but judging from the subject I think you want this,</p>\n\n<pre><code>my @spec_2d = map [ $_ ], @spec;\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T15:28:28.317", "Id": "26031", "Score": "1", "Tags": [ "perl" ], "Title": "clean way to make array a 2d array" }
26031
<p>I wrote John Conway's Game of Life in Java:</p> <pre><code>class GameOfLife { static int countSurrounding(int[][] board, int a, int b) { int count = 0; int[][] surrounding = {{a - 1, b - 1}, {a - 1, b }, {a - 1, b + 1}, ...
[]
[ { "body": "<p>A few suggestions:</p>\n\n<ul>\n<li><p>Each cell in the Game of Life has exactly two states: <em>dead</em> or <em>alive</em>. Unless you plan to implement <code>-1</code> as <em>undead</em>, I'd suggest you use booleans instead of integers to indicate the state.</p></li>\n<li><p>The <code>int i[]<...
{ "AcceptedAnswerId": "26066", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T15:42:09.860", "Id": "26033", "Score": "12", "Tags": [ "java", "game-of-life" ], "Title": "Game of Life in Java" }
26033
<p>I have code like the following, which performs a series of replacements on a string, to convert it to its final form.</p> <pre><code>public String convertString(String string) { String convertedString = string; if( string.contains("something")) { convertedString = convertStringA(string); return converted...
[]
[ { "body": "<p>Your Algorithm is a little bit too abstract to provide a one size fits all solution.</p>\n\n<p>What does it mean, when a string contains \"something\" or \"something else\"?\nAre they completely different strings like \"I know (something)\" and \"He gave me (something else)\"? Or are there similar...
{ "AcceptedAnswerId": "26047", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T19:03:08.573", "Id": "26041", "Score": "2", "Tags": [ "java", "design-patterns" ], "Title": "Performing multiple substring replacements on a string" }
26041
<p>This is my first "large scale" system I've designed for myself. Since I'm more of a front end developer than backend developer, I'm not sure if my architecture is sound.</p> <p>I've created a <code>Factory</code> class which I use to create all my classes and connect to the DB. I think I've tried to use used Singel...
[]
[ { "body": "<h2>Factory</h2>\n\n<p>Three things about this:</p>\n\n<ol>\n<li>Consider using an autoloader (see <a href=\"https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md\" rel=\"nofollow\">PRS-0</a>). Then you don't have to bother about, where files get included.</li>\n<li>A Factory is used...
{ "AcceptedAnswerId": "26085", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-10T21:49:25.283", "Id": "26052", "Score": "2", "Tags": [ "php", "mysql" ], "Title": "How can this layered PHP architecture be improved?" }
26052
<p>I've written a short snippet of code to replace JQuery's $.post ( to get ride of JQuery, mainly ). The function does seem to work. But, since I might be using this function in a couple of other pages, I'm just hoping to get a general review of the code.</p> <p>I'm not confident the parameter formatting is done prop...
[]
[ { "body": "<p>First of all, I'd suggest you use a library for several reasons:</p>\n\n<ul>\n<li><p>It's abstracted a lot of cross-browser differences</p></li>\n<li><p>Spread the task of the code to the community. That way you focus more on the task at hand, rather than fixing some bugs.</p></li>\n<li><p>More ev...
{ "AcceptedAnswerId": "26057", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T02:34:04.597", "Id": "26054", "Score": "1", "Tags": [ "javascript" ], "Title": "XMLRequest Function" }
26054
<p>As I am getting my Linq query to a functional point, I start looking at the query and think about all the "ANY" and wonder if those should be a different method and then I have data conversions going on.</p> <p>Does anything jump out as being a performance issue? What is recommended to make this more performant? (Y...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T01:21:33.010", "Id": "40307", "Score": "0", "body": "Do you need to perform the `ToList()` call? This will (of course) freeze the enumerable contents at creation time, so maybe this is hat you require; but maybe not." }, { "...
[ { "body": "<p>You can definitely optimize this query. If <code>list</code> has M items and <code>excelViolations</code> has N items, the query will iterate <code>excelViolations</code> M*5N times.</p>\n\n<p>It is possible to reduce this to M*N iterations by consuming <code>excelViolations</code> only once per i...
{ "AcceptedAnswerId": "26124", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T01:15:10.773", "Id": "26055", "Score": "2", "Tags": [ "c#", "performance", "linq" ], "Title": "Linq query performance improvements" }
26055
<p>I am learning actionscript 3 coding by making a crappy platformer game :)</p> <p>The problem I am facing is passing lots of options to a construct function that will setup the display object where all of them have default values.</p> <p>I could send the options the normal way, like this:</p> <pre><code>function ...
[]
[ { "body": "<p>People do this sort of thing all the time in the JavaScript (this.arguments) and Python world (*args); however, by removing type constraints from the parameter list, you have to be wary that you're always providing the types of parameters your function is expecting. If one of your parameters is su...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T07:44:14.020", "Id": "26062", "Score": "1", "Tags": [ "actionscript-3" ], "Title": "Passing lots of options to a function" }
26062
<p>How can I improve my jQuery form preview implementation? I'm currently using the <a href="http://potomak.github.io/jquery-instagram/" rel="nofollow">jQuery Instagram Plugin</a> to get the hashtag from Instagram. </p> <pre><code>var timeoutReference; var element; var tagsa; $(document).ready(function() { $('input...
[]
[ { "body": "<pre><code>//$(document).ready(fn) can be shortened to $(fn)\n//you can use it to avoid global scope pollution so we place everything in here\n$(function () {\n\n //IDs are unique, so we drop input\n //cache values that are static and used more than once\n var instagramHashtag = $('#instagram_hash...
{ "AcceptedAnswerId": "26064", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T07:50:18.447", "Id": "26063", "Score": "1", "Tags": [ "javascript", "jquery", "instagram" ], "Title": "jQuery form preview using the Instagram plugin" }
26063
<p>I have set up a basic MVC project which is a student administration application based upon a CSV file as datastore. Each user has a specific role (student, lecturer, professor, leader of degree program). After successful login, the main window should have different actions to be performed based upon each role.</p> ...
[]
[ { "body": "<ol>\n<li><p>A great comment from <a href=\"https://codereview.stackexchange.com/a/19459/7076\"><em>@tb-</em>'s answer</a>:</p>\n\n<blockquote>\n <p>Do not extend <code>JPanel</code>, instead have a private <code>JPanel</code> \n attribute and deal with it (Encapsulation). \n There is no need to g...
{ "AcceptedAnswerId": "43652", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T10:05:07.037", "Id": "26065", "Score": "7", "Tags": [ "java", "mvc", "swing", "gui" ], "Title": "Student administration application" }
26065
<p>I've tried to create a small OpenGL abstraction layer.</p> <p>I've tried to favor composition over inheritance but somehow it added extra complexity to my code. I probably overused it.</p> <p><strong>shader.h</strong></p> <pre><code>#ifndef SHADER_H #define SHADER_H #include "filereader.h" #include &lt;string&gt;...
[]
[ { "body": "<p>Drop all the interface classes. It really only makes sense to have them if you are going to implement them multiple times. But you don't. It just increases the complexity of your code for no gain.</p>\n\n<p><code>BaseHandler</code> does nothing more than hold a GLuint. So its a useless class. It d...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T13:18:38.570", "Id": "26067", "Score": "2", "Tags": [ "c++", "beginner", "c++11", "opengl" ], "Title": "OpenGL abstraction layer" }
26067
<p>Here is the question followed by my working program:</p> <blockquote> <p>Given a string, return a version without the first 2 chars. Except keep the first char if it is 'a' and keep the second char if it is 'b'. The string may be any length. Harder than it looks. </p> <pre><code>deFront("Hello") → "llo" de...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T14:57:48.040", "Id": "40333", "Score": "0", "body": "Yes. Fix the indentation so it's easier to read." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T16:34:03.683", "Id": "40335", "Score": "0"...
[ { "body": "<p>First, is this part correct?</p>\n\n<pre><code>} else if (str.length() == 1 &amp;&amp; str.charAt(0) == 'a') {\n return str;\n} else {\n return str;\n}\n</code></pre>\n\n<p>This will return a string of length 1, unchanged, regardless of the character. What should happen if you pass \"z\"? Si...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T14:42:41.147", "Id": "26068", "Score": "4", "Tags": [ "java", "strings" ], "Title": "String manipulation in Java" }
26068
<p>Does the code below respect Python programming conventions? (and if not, which one does it disrespect?) The objective would be to publish this code as part of a scientific article, as "reproducible research".</p> <p>In 1998, Moffat and Turpin described in "<a href="http://ieeexplore.ieee.org/xpl/login.jsp?tp=&amp;a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-12T21:06:30.780", "Id": "40351", "Score": "0", "body": "Yes, this code is not ready for review. See the [FAQ](http://codereview.stackexchange.com/faq) item 5: \"To the best of my knowledge, does the code work?\"" }, { "ContentL...
[ { "body": "<h3>1. Comments on your code</h3>\n\n<ol>\n<li><p>The Python style guide (<a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a>) recommends using 4 spaces for each indentation step, and <code>lowercase_words_with_underscores</code> for variable names and function names. You'r...
{ "AcceptedAnswerId": "26309", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T15:44:50.907", "Id": "26071", "Score": "4", "Tags": [ "python" ], "Title": "Computation of Prefix Free Codes with many repeated weight values in reduced space" }
26071
<p>I was writing a function (named <code>listenString</code>) in haskell to see if a string contains one of the strings in a list of strings, and to then return a value (of the type <code>m ()</code>) that corresponded with the string it found. The type of that function is <code>(Eq a, Monad m) =&gt; [a] -&gt; [([a], m...
[]
[ { "body": "<p>Why do you need the element type to be a monad? The only point you require it is when you do <code>return ()</code> in order to signal failure. I'd propose implementing a more general function</p>\n\n<pre><code>lookupSublist :: Eq a =&gt; [a] -&gt; [([a], b)] -&gt; Maybe b\n</code></pre>\n\n<p>Whi...
{ "AcceptedAnswerId": "26082", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T18:01:40.860", "Id": "26072", "Score": "2", "Tags": [ "haskell" ], "Title": "Parsing a String to see if it contains another String, and then returning a monad if it does" }
26072
<p>This piece of code basically just asks for a word and sees if it exists in a file. If not, the user is asked if it should be added to the file.</p> <p>I am new to C programming and I want to know what you think about my code: things to change, things to remove, what not to do.</p> <pre><code>#include &lt;stdlib.h&...
[]
[ { "body": "<p>Your code looks quite neat, although note that formatting, including spaces\naround operators etc, line lengths, defining multiple variable per line, should follow a conventional style. </p>\n\n<p>There are some issues, the main one being that compiling and running the code,\nit does not work. T...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-12T01:50:37.180", "Id": "26074", "Score": "4", "Tags": [ "beginner", "c", "search", "file" ], "Title": "Checking for an existing word in a file" }
26074
<p>I'm trying to optimize a python string that works on big data sets, the way it works is by taking in a with a list of keywords and scores and taking in a file loaded with data from the twitter api. The program does a keyword match against tweet text. At the end of the program I want to produce an average for each te...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-12T21:10:08.077", "Id": "40352", "Score": "0", "body": "Please provide some example data. Without being able to run your program, it's hard to tell whether we've made it any faster." } ]
[ { "body": "<p>Your code contains a mix of tabs and spaces. This caused your code to display incorrectly before I edited it. The most common way in python is to use only spaces. You should be able to configure your editor to insert spaces instead of tabs when you push the tab key.</p>\n\n<pre><code>import sys\ni...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-12T09:12:19.680", "Id": "26077", "Score": "4", "Tags": [ "python", "optimization", "twitter" ], "Title": "Optimizing python code for big data sets" }
26077
<p>What are your thoughts on the fallowing immutable stack implementation? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference counted implementation like here).</p> <pre><code>namespace immutable { template&lt;typename T&gt; class stac...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-12T14:46:46.110", "Id": "40342", "Score": "1", "body": "Shouldn't `pop()` remove or un-scope the value at `tail`, or do you mean it to be a `top()` function instead?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<ol>\n<li><p>Element mutability</p>\n\n<p>Your stack is not <em>entirely</em> immutable, because <code>peek</code> returns a pointer to a non-const <code>T</code>, which means it's possible to modify the elements of the stack. And given your use of <code>shared_ptr</code>, this may have severe conseq...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-12T13:19:06.067", "Id": "26080", "Score": "5", "Tags": [ "c++", "performance", "functional-programming", "stack", "immutability" ], "Title": "Immutable C++ stack - thoughts a...
26080
<p>I recently started learning Haskell and as my first project I decided to port a particle simulation I had written in C.</p> <p>The simulation is pretty simple. We have a cubic box with particles (spheres) inside it. Then we choose to either move a particle or to change the volume of the box and check for any collis...
[]
[ { "body": "<p>Heap profiling will not tell you much in this case - memory leaking is definitely not your problem. Using cost-centre profiling would probably be better suited for identification of the hot-spots.</p>\n<p>After looking at the profile a bit (using <a href=\"https://github.com/scpmw/ghc\" rel=\"nore...
{ "AcceptedAnswerId": "26118", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-12T15:51:15.420", "Id": "26081", "Score": "13", "Tags": [ "performance", "haskell", "simulation", "physics" ], "Title": "Haskell Particle Simulation" }
26081
<p>The requirement is to skip a line beginning from <code>#</code> sign. Basically, we need to treat it as a comment line. The input is given by the user from the keyboard. I will not be reading it from a file. I have a link to the code that i have written so far. In this code, I have used multiple lines to skip a com...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T00:20:56.347", "Id": "40353", "Score": "0", "body": "This code is a simple tcam simulation" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T00:53:49.117", "Id": "40354", "Score": "0", "body...
[ { "body": "<p>There is far too much code here for me to review all of it. However, this looks like pure <code>C</code> except for <code>std::string</code> and some <code>iostream</code> usage. I don't know how familiar you are with <code>C++</code> as opposed to <code>C</code>, but I would write many of these f...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T00:19:21.323", "Id": "26088", "Score": "2", "Tags": [ "c++", "stream" ], "Title": "Skipping comment line from keyboard via stdin" }
26088
<p>I wrote this simple function in CoffeeScript to see if elements are found in an array:</p> <pre><code>isFoundIn = (searchTerm, arrayToSearch) -&gt; returnVal = false for a in arrayToSearch returnVal = true if searchTerm is a returnVal </code></pre> <p>Usage:</p> <pre><code>isFoundIn('james', ['robert', ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T05:04:09.523", "Id": "40359", "Score": "0", "body": "It seems you've replicated the native JS array `indexOf` function. While there's no exact match for Ruby's `include?` in JavaScript, a simple `array.indexOf(term) isnt -1` will gi...
[ { "body": "<p>Expanding on my comment above:</p>\n\n<p>Your <code>isFoundIn</code> function can be rewritten as simply</p>\n\n<pre><code>isFoundIn = (term, array) -&gt; array.indexOf(term) isnt -1\n</code></pre>\n\n<p><code>indexOf</code> uses the strict <code>===</code> comparison, which is what CoffeeScript a...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T04:29:14.973", "Id": "26091", "Score": "3", "Tags": [ "strings", "search", "coffeescript" ], "Title": "Determining if a target string is found in an array of strings" }
26091
<p>I have recently had a whole load of help trying to roll my own <em>loosely-coupled</em> Observable/Observer paradigm, here: <a href="https://stackoverflow.com/questions/16498315/loosely-coupled-observer-pattern">https://stackoverflow.com/questions/16498315/loosely-coupled-observer-pattern</a></p> <p>To keep things ...
[]
[ { "body": "<p>I have several remarks:</p>\n\n<ul>\n<li>Why do you need <code>public class Source&lt;ListenerType extends IListener&lt;SourceType&gt;, SourceType&gt;</code>? Why does <code>Source</code> need to implement <code>IListener</code>? This seems unecessary complex.</li>\n</ul>\n\n<p>I would do it in a ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-11T22:44:00.870", "Id": "26093", "Score": "1", "Tags": [ "java", "mvc", "generics" ], "Title": "Java; Generic Observer/Observable - is this as messy as I think?" }
26093
<p>I couldn't find a good example, so after some fighting with writing non-serializable object to file in Android, I decided to show you my solution. Could you tell me if it is OK or how could it be improved?</p> <p>This class is used to store information in a file. <code>writeObject</code> and <code>readObject</code>...
[]
[ { "body": "<p>Just a small detail: you don't need to make <code>strokes</code> transient. When you override <code>readObject</code>/<code>writeObject</code>, you completely override the usual serialization mechanism.</p>\n\n<p>Transient just means that the usual serialization mechanism should skip that member ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T08:12:52.497", "Id": "26095", "Score": "1", "Tags": [ "java", "android", "makefile", "stream", "serialization" ], "Title": "Write and read non-serializable object to file ...
26095
<p>I have the following code that allows easy creation, pulling, and deletion of Tickets in a CakePHP application.</p> <pre><code>App::uses('Component', 'Controller'); App::uses('Ticket', 'Model'); App::import(array('Security')); class TicketComponent extends Component { public $name = 'Ticket'; // Create a ...
[]
[ { "body": "<p>In order to call each time the garbage function just create a </p>\n\n<pre><code>public function beforeFilter() {\n parent::beforeFilter();\n $this-&gt;garbage();\n</code></pre>\n\n<p>About the new Ticket()\ni think it would be okay to change the</p>\n\n<pre><code>$ticketObj-&gt;..\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T09:09:47.830", "Id": "26096", "Score": "2", "Tags": [ "php", "cakephp" ], "Title": "CakePHP Ticket Component" }
26096
<p>I have written the following Javascript class</p> <pre><code>function InScroll( container, options ) { "use strict"; var isRunning = false; // utilities var noop = function() {}; var inter = null; if(!container) { alert('container element not provided'); return; } ...
[]
[ { "body": "<p>It seems to me that you don't need the self invoking function and the anonymous function:</p>\n\n<pre><code>inter = window.setInterval( scroll, 50);\n</code></pre>\n\n<p>should do</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "26099", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T10:04:58.893", "Id": "26097", "Score": "1", "Tags": [ "javascript", "ajax" ], "Title": "Continuously scrolling content loader" }
26097
<p>When I need to get maximum value of A, B, and C, then I would write like:</p> <pre><code>val = A; val = max(val, B); val = max(val, C); </code></pre> <p>But, in this case, I need to write two "val" in the one line. And, it is cumbersome if the "val" is more complex like "val[0][1][2].element"... If it is adding va...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T14:55:14.873", "Id": "40392", "Score": "1", "body": "Would you like a version that allows `for( x : list ) val <= highest(x);`? But this is a better question for StackOverflow not CodeReview." }, { "ContentLicense": "CC BY-...
[ { "body": "<p>If you have access to C++11, I'd suggest using <code>std::max</code> with an <code>initializer_list&lt;T&gt;</code>. A complete minimal example:</p>\n\n<pre><code>#include &lt;algorithm&gt;\n#include &lt;initializer_list&gt;\n#include &lt;iostream&gt;\n\nint main()\n{\n int a = 1;\n int b = ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T11:48:46.110", "Id": "26100", "Score": "15", "Tags": [ "c++" ], "Title": "Maximum of three values in C++" }
26100
<p>Test version of my code for handling individual mouseenter / mouseleave events for objects created dynamically. The code emulates a seating cart for a bus, as you mouse over the objects it will display the students name and remove it when your mouse leaves the object. Current test only accounts for four students. If...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T13:16:55.327", "Id": "26102", "Score": "1", "Tags": [ "delphi" ], "Title": "Suggestions for Improvement, handling MouseEnter / MouseLeave Events for dynamically created objects." }
26102
<p>I have the following mockup that I need some feedback on how I might improve the <code>url_decode</code> function to make it faster and use less memory. There are a couple of requirements. I have to use the <code>StringArg</code> and <code>StringReturn</code> structs. I also need to completely decode the string. I...
[]
[ { "body": "<p>This is doomed to failure:</p>\n<pre><code>struct StringArg\n{\n int length;\n char* data;\n StringArg(const char* inData)\n {\n length = strlen(inData);\n data = new char[length+1];\n strcpy(data, inData);\n }\n};\n</code></pre>\n<p>This can only lead to disast...
{ "AcceptedAnswerId": "26120", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T14:08:05.643", "Id": "26103", "Score": "3", "Tags": [ "c++", "strings", "url" ], "Title": "URL decode function optimization" }
26103
<p>I am using this code for my responsive layout mobile sidebar hide/show. I am not an expert in jQuery and just wonder if I can optimize this code with the same functionality.</p> <pre><code>$(function() { var a = $("#sidepanelpull"); var l = $("#sidepanelclose"); side = $(".qa-sidepanel"); sideHeight...
[]
[ { "body": "<p>style-wise I did some changes, have a look</p>\n\n<pre><code>$(function() {\n\nvar $window = $(window),\n $a = $(\"#sidepanelpull\"),\n $l = $(\"#sidepanelclose\"),\n $side = $(\".qa-sidepanel\"),\n sideHeight = $side.height(); // Declared but never used??\n\n$a.on(\"click\", function(...
{ "AcceptedAnswerId": "26109", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T14:51:47.520", "Id": "26105", "Score": "2", "Tags": [ "javascript", "jquery", "mobile" ], "Title": "Hide/show sidebar" }
26105
<p>I have this small Haskell script that I wrote some time ago to parse a set of financial CSV files to produce other CSV files. I've recently had a problem with large input files (around 300Mb) that I solved with RTS options. </p> <p>Still, I'd like to make it more lazy and efficient. For example, I noted that it loa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T05:22:58.580", "Id": "40528", "Score": "0", "body": "I don't have time at the moment to give a full write up, but you can fix the memory issues by using `pipes` or `conduit`. Both libraries will allow you to avoid the large interme...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T15:13:03.763", "Id": "26107", "Score": "3", "Tags": [ "haskell", "functional-programming", "memory-management", "csv", "finance" ], "Title": "Parsing and producing sets of...
26107
<p>I want to make a container which manages <strong>big objects</strong>. which performs <strong>deep copies</strong> on copy construction and copy assignment. I also like the interface of the <strong>std containers</strong>, so I wanted to implement it using public inheritance:</p> <pre><code>template &lt;class TBigO...
[]
[ { "body": "<p>I think you are going about it the wrong way.</p>\n\n<p>Containers already perform copy on copy construction/assignment because they are designed for value objects not pointers. What you really want is a wrapper object for pointers that performs a deep copy when that object is copied.</p>\n\n<p>Th...
{ "AcceptedAnswerId": "26241", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T16:33:22.463", "Id": "26111", "Score": "3", "Tags": [ "c++", "c++11" ], "Title": "How to design interface of deep-copy behaving pointer containers?" }
26111
<p><em>ETC = "Estimated Time of Completion"</em></p> <p>I'm counting the time it takes to run through a loop and showing the user some numbers that tells him/her how much time, approximately, the full process will take. I feel like this is a common thing that everyone does on occasion and I would like to know if you h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T13:19:32.190", "Id": "40395", "Score": "0", "body": "I'm sure you've seen timers like this that switch over to \"less than a minute\" and \"less than 30 seconds\" when nearing the end of the processing. If you see the last few esti...
[ { "body": "<p>Your approach looks reasonable if one makes the assumption that the average time for item processing is roughly the same for each item. </p>\n\n<p>Updating the UI once a second is ok, updating it more often does not make much sense since the typically user cannot follow that visually either. If th...
{ "AcceptedAnswerId": "26113", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T11:46:12.037", "Id": "26112", "Score": "3", "Tags": [ "c#" ], "Title": "Norms, rules or guidelines for calculating and showing ETA/ETC for a process" }
26112
<p>Can I do something better with this code? It's just a snippet of a library I wrote.</p> <pre><code>&lt;?php /* * Variable.class.php * (c) 2013 sinan eker`enter code here` * */ class Variable extends Config { protected static $vars = array(); final public static function variables(){ return s...
[]
[ { "body": "<p>First of all, method and variable docblocks are recommended. Provide a description of each method, its parameters and their return values.</p>\n\n<p>I would give your getter function <code>Variable::variables()</code> an active name like <code>getVariables()</code> and rename your <code>Variable::...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T16:51:44.980", "Id": "26114", "Score": "2", "Tags": [ "php", "object-oriented", "php5" ], "Title": "Variable class from library" }
26114
<p>In the ZF2 model mapper, mappings are quite often duplicated in the original mapping class &amp; other mapping classes.</p> <p>I am using a static mapping methods (<code>mapToInternal</code>, <code>mapToExternal</code>) to remove this duplication. Could this be done any better?</p> <pre><code>&lt;?php //... /**...
[]
[ { "body": "<p>Two minor notes:</p>\n\n<ol>\n<li><p>This function uses only data of <code>ItemEntity</code>:</p>\n\n<blockquote>\n<pre><code>static public function mapToExternal(ItemEntity $item)\n{\n $data = array(\n 'id' =&gt; $item-&gt;getId(),\n // @todo complete once login is done\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T17:20:17.610", "Id": "26116", "Score": "4", "Tags": [ "php", "zend-framework" ], "Title": "ZF2 Model Mapper" }
26116
<p>I try to intercept some OpenGL calls for testing my rendering classes. Reflection is used for replacing the OpenGL backend.</p> <p>I feel this class is badly written and I need advices for refactoring it.</p> <pre><code>package fr.meuns.opengl; import java.lang.reflect.InvocationTargetException; import java.lang....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T21:05:36.353", "Id": "40518", "Score": "0", "body": "I can elaborate if necessary." } ]
[ { "body": "<pre><code>public class GL\n</code></pre>\n\n<p>Your class name should really be a more descriptive noun.</p>\n\n<pre><code>private static class MethodSignature\n</code></pre>\n\n<p>You actually have no need for this <code>private static class</code> since Reflection gives you direct access to method...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T18:02:58.450", "Id": "26119", "Score": "2", "Tags": [ "java", "reflection", "static", "opengl" ], "Title": "Java reflection and static classes" }
26119
<p>I am looking for a starting point to code plugins, primarily for Zepto.js (with fall back for jQuery). These will provide reusable functions for Tumblr theming.</p> <p>However, I can't seem to find anything in depth about writing a plugin (with Zepto) as the example, apart from a small snippet on the Zepto site: <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T20:56:05.117", "Id": "40420", "Score": "1", "body": "You could check the [jQuery Boilerplate](http://jqueryboilerplate.com/) for a better understanding." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14...
[ { "body": "<p>This looks fine to me, but then again it's sample (boilerplate) code ;)</p>\n\n<ul>\n<li>Consider <code>\"use strict\"</code>; </li>\n<li>If it was not for the <code>onComplete</code>, you could simply <code>return</code> the result of <code>$.each</code></li>\n</ul>\n\n<p>I like your options hand...
{ "AcceptedAnswerId": "46963", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T19:07:01.773", "Id": "26121", "Score": "2", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "Zepto / jQuery plugin base" }
26121
<p>I need to get the numbers in a string like "1,2,5-9", the function should return a list with these values ​​[1,2,5,6,7,8,9]</p> <p>Here's what I did. Is this the best way or there's something simpler/better?</p> <pre><code>function isNumber(n) { return !isNaN(parseFloat(n)) &amp;&amp; isFinite(n); } function ge...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T20:37:07.040", "Id": "40414", "Score": "1", "body": "`str.match(/(\\d+)/g).slice(1)` or something similar should probably be enough though :-)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T20:37:53....
[ { "body": "<p>Well, <a href=\"http://jsfiddle.net/mkhC3/\" rel=\"nofollow\">here's my version</a> that's <a href=\"http://jsperf.com/getting-numbers-and-ranges-from-string/5\" rel=\"nofollow\">benchmarked across different browsers</a>. Might need some improvement (currently finding shortcuts for the isNumber), ...
{ "AcceptedAnswerId": "26138", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T20:25:16.047", "Id": "26125", "Score": "7", "Tags": [ "javascript" ], "Title": "Getting all number from a String like this \"1,2,5-9\"" }
26125
<p>I wrote a class with this function. Can I improve my code performance in the bottom of the function? I don't like the <code>while</code> loops!</p> <pre><code>public function loadFields(array $fields, $as_object = Config::FIELDS_AS_OBJECT) { $connection = $this-&gt;connection; $sql = "SELECT ".implo...
[]
[ { "body": "<p>I'd imagine a <a href=\"http://php.net/manual/en/pdostatement.fetchall.php\" rel=\"nofollow\"><code>$stmt-&gt;fetchAll()</code></a> would be more performant than the while-loop and <code>$stmt-&gt;fetch()</code>. Rather than paging over an entire set of records one at a time, try returning the res...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T21:35:04.913", "Id": "26126", "Score": "3", "Tags": [ "php", "performance", "object-oriented", "php5" ], "Title": "Performance of loading fields" }
26126
<p>I'm working on a web application using Bottle, and it is, at this point, functional. </p> <p>The gist of it is that I have a database of drinks, with associated IDs, and associated sets of ingredients. the name and ID of the drink are passed to the client, which displays them.</p> <p>Currently, when the program lo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T07:57:53.827", "Id": "40445", "Score": "0", "body": "You should use `lower_case_with_underscores` for variable names like `SampleDrinkDict` - see the [style guide](http://www.python.org/dev/peps/pep-0008/#method-names-and-instance-v...
[ { "body": "<p>Whether you need to store data in the DB is really gonna depend on your testing, but here are a few thoughts about how to reduce memory usage while still building the entire drink table at startup:</p>\n\n<ul>\n<li>While they're convenient, you don't necessarily need to use dictionaries for this. ...
{ "AcceptedAnswerId": "26132", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-13T21:47:14.203", "Id": "26127", "Score": "6", "Tags": [ "python", "performance", "sql", "hash-map", "bottle" ], "Title": "Load drinks and their ingredients into dictionar...
26127
<p>I want to play around with the Powerball lotto drawing history. What other probability theories could I try or what other probability class libraries exist. The code parses the file very quickly but is there a better way to go about it?</p> <p>I am working on a multiple regression analysis with the first <code>wh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T17:50:21.890", "Id": "40498", "Score": "1", "body": "For inspiration, take a look at the following:\nhttp://isocpp.org/blog/2013/03/n3551-random-number-generation ;\n[PDF] http://isocpp.org/files/papers/n3551.pdf ;\nhttp://en.cppref...
[ { "body": "<p>My suggestions won't make your code faster, I focused on idiomatic and clear code. It's already quite nice as it is. :)</p>\n\n<pre><code>// Powerball rules.\n// (http://en.wikipedia.org/wiki/Powerball)\nconst int POWERBALL_WHITE = 59; // White balls number 1-59\nconst int WHITE_DRAWS = 5; ...
{ "AcceptedAnswerId": "26136", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T03:21:02.207", "Id": "26130", "Score": "5", "Tags": [ "c++", "c++11", "statistics" ], "Title": "Fun with probability theory" }
26130
<p>I am validating two IP addresses. I simply wrote a peice of code like </p> <pre><code>if(string.IsNullOrEmpty(ip1) &amp;&amp; string.IsNullOrEmpty(ip2) return true; </code></pre> <p>But is this logically correct? What should we done with empty strings? If both are empty strings, is it okay to return true?</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T07:43:47.277", "Id": "40442", "Score": "2", "body": "What do you want to achieve?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T07:50:49.830", "Id": "40444", "Score": "0", "body": "It se...
[ { "body": "<p>Personally i would check the strings on NullOrWhitespace, but knowing you want to validate IP addresses, i recommend to use the IPAddress object for them which has an Parse and TryParse method. When that's done it's quite easy to create an static method for it which provides easy access.</p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T07:41:31.283", "Id": "26135", "Score": "0", "Tags": [ "c#" ], "Title": "Should I return true or false if both of the IP address strings are empty?" }
26135
<p>I was curious about trying to write my own simple Database Connection Pool, where all the responsibility for freeing resources belongs to objects which use those connections.</p> <p>There are:<br/> <strong>3 classes</strong> - ConnectionPool, RecoverableConnection and ConnectionFactory<br/> <strong>1 interface</str...
[]
[ { "body": "<p>ConnectionFactory looks like a singleton and I think could probably be rewritten and would be safer as a singleton. Unsynchronized concurrent calls to initializeConnectionPool() would have unintended side-effects. Take a look at <a href=\"http://en.wikipedia.org/wiki/Singleton_pattern\" rel=\"no...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T08:16:13.660", "Id": "26139", "Score": "4", "Tags": [ "java" ], "Title": "Connection Pooling" }
26139
<p>I have this repetitive block of code and I'm looking for ways to make it reusable and as flat as possible.</p> <p>Here it is:</p> <pre><code>Controller.showKeyboardRegion = function() { logger.info('Controller.showKeyboardRegion =&gt; CreateAccountLayoutController'); var view = new CreateAccountKeyboardVie...
[]
[ { "body": "<pre><code>var key;\n\n//Here you store the necessary information for each of the 9 functions\n\n//the key of the map will be the function name\n//builder will be the reference to the constructor\n//layoutObj is the name of the property from Controller.layout from which we call show()\n//viewStarter ...
{ "AcceptedAnswerId": "26144", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T10:18:47.200", "Id": "26142", "Score": "-1", "Tags": [ "javascript", "backbone.js" ], "Title": "Backbone Marionette code improvement" }
26142
<p>I have written a small batch job which will collect data from db and send mail to user. Can you please do a review of the code with design prinicples in mind and also with best practices for Db and file writer. I am writing to file in this code and sending it in mail.</p> <p>The user will call the class with report...
[]
[ { "body": "<ol>\n<li><p>Eating up exceptions</p>\n\n<pre><code>} catch (Exception e) {\n e.printStackTrace();\n} \n</code></pre>\n\n<p>Since your application cannot recover from most of the exceptions it should not catch and ignore (eat) exceptions but rather catch it, print the stack trace and pass it along...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T10:28:35.197", "Id": "26143", "Score": "1", "Tags": [ "java", "optimization", "performance", "design-patterns" ], "Title": "Email report generation from database" }
26143
<p>I have made this function that should take a set of price data and calculate a set of monthly returns. The idea is that is should be able to cope with irregular time intervals. For example I have daily data for the S&amp;P 500 but many hedge funds only release price data monthly.</p> <p>Here is what I have come up ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T12:25:09.317", "Id": "40467", "Score": "0", "body": "So `$dates` is sorted and you are actually only interested in the price at the last date of a month to calculate the return?" }, { "ContentLicense": "CC BY-SA 3.0", "C...
[ { "body": "<p>If there are now performance constraint I always prefere a readable solution over a compact one. So I would go with the following: (assuming <code>$prices</code> is sorted and there are no gaps in the months)</p>\n\n<pre><code>&lt;?\ndate_default_timezone_set('Europe/Berlin');\n\n//Put the data in...
{ "AcceptedAnswerId": "26152", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T11:05:49.337", "Id": "26146", "Score": "1", "Tags": [ "php" ], "Title": "improvements to this php function to calculate monthly returns from a set of price data" }
26146
<p>In my project I am using 10-15 SQL queries, for that I have a common <code>class</code> for <strong>database connectivity</strong> and using that I have executed the queries by passing the <code>connection</code>, <code>command</code> and <code>dataReader</code>. </p> <p>With some reference in SO, I learned that m...
[]
[ { "body": "<p>The reader/command/connection fields of <code>DBConnectivity</code> are not really being used to represent state of <code>DBConnectivity</code>. This is obvious because of usage like:</p>\n\n<pre><code>dbConnectivity.command = new SqlCommand(salesQuery, dbConnectivity.connection);\ndbConnectivity....
{ "AcceptedAnswerId": "26151", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T12:16:07.480", "Id": "26149", "Score": "4", "Tags": [ "c#" ], "Title": "Handling multiple queries in C#" }
26149
<p>Just a little thing I made to load 20 random images from imgur. I looked at the way that imgur references images on its site, and I felt like I could probably generate a random string of letters and numbers that would, on occasion, produce a valid image URL. So I threw this together in PHP, because I am trying to le...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T16:07:43.513", "Id": "40493", "Score": "0", "body": "First of all I'd separate my php from the HTML. Create class of functions and call them on the HTML like `myclass::myfunction(arguments)` or similar. See [Model-View-Controller](h...
[ { "body": "<p>Definitely separate your PHP from HTML as Alex suggested. You probably don't need to go the full <a href=\"http://phpmaster.com/the-mvc-pattern-and-php-1/\" rel=\"nofollow\">MVC route</a> for something so simple, but simply generating your PHP variables <em>then</em> outputing your HTML would make...
{ "AcceptedAnswerId": "26185", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T14:01:30.850", "Id": "26153", "Score": "2", "Tags": [ "php", "beginner", "html", "random", "image" ], "Title": "Random imgur image loader" }
26153
<p>I know that this is a complete mess and does not even come close to fitting PEP8. That's why I'm posting it here. I need help making it better.</p> <pre><code>bookName = None authorName = None bookStartLine = None bookEndLine = None def New_book(object): def __init__(self, currentBookName, currentA...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T16:02:09.083", "Id": "40490", "Score": "0", "body": "`I know that this is a complete mess`. If you know something is a complete mess I'm sure you have a reason to think so. Focus on the why and try to change it." } ]
[ { "body": "<ul>\n<li>No need for a New_Book class with something so simple – I recommend a <a href=\"http://docs.python.org/3/library/collections.html#collections.namedtuple\" rel=\"nofollow\">named tuple</a> instead.</li>\n<li>HTTPResponse objects don't seem to have a readlines() method (in Python 3) – this fo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T14:27:03.410", "Id": "26155", "Score": "2", "Tags": [ "python", "beginner", "parsing" ], "Title": "New book parser" }
26155
<p>I just posted a small open source CFML project <a href="https://github.com/jetendo/db-dot-cfc" rel="nofollow noreferrer">here</a> db.cfc is a standalone CFC with <strike>472</strike> lines of code.</p> <p>Here is the execute function in db.cfc. This is just a partial example pulled from the 400+ lines of the code ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T17:00:39.417", "Id": "40494", "Score": "0", "body": "I prefer `NOT len(trim(this.dbtype))` over `this.dbtype NEQ \"\"`, but looks good other than that imo" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05...
[ { "body": "<p>Points:</p>\n\n<ul>\n<li>I agree with @baynezy. The function is doing too much. What are your\nunit tests like for this they must be a nightmare? (I just noticed you said you don't have any unit tests yet. Write the tests FIRST. You are doing yourself and your clients a disservice by writing code ...
{ "AcceptedAnswerId": "26398", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T15:44:57.697", "Id": "26156", "Score": "2", "Tags": [ "performance", "coldfusion", "cfml" ], "Title": "Open source CFML database project" }
26156
<p>I have just written an API framework which I am hoping to implement into one of my large sites very soon. However, before I do so, I want to be sure that the script is well written and there are no obvious mistakes that I have missed.</p> <p>As with most projects, the key here is automation and speed... I have trie...
[]
[ { "body": "<p>Ignoring your code for a second, here's some feedback on the design of your API.</p>\n\n<p>It may be better to simply include the user's companies in the response for the /user endpoint. This would make your code more complex, but API consumers' lives easier.</p>\n\n<p>Obviously removing the /user...
{ "AcceptedAnswerId": "26160", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T15:50:19.937", "Id": "26157", "Score": "0", "Tags": [ "php", "api" ], "Title": "How is this for an API structure" }
26157
<p>Please help me restructure this Java code to allow for sometime have 4 items in packagePriceList.</p> <pre><code>public static HTMLSelectOptionsElement listPremiumPackageTermsWithPrice(String[] packagePriceList, int cyberSourceBillingMode) { HTMLSelectOptionsElement optionsElement = new HTMLSelectOptionsElement...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T19:16:55.193", "Id": "40511", "Score": "0", "body": "The question is not clear: you'll always get `packagePriceList` of length 4, or sometimes less, sometimes more?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>First, a simple solution:</p>\n\n<pre><code>optionsElement.addOption(\"1 Month - \" + packagePriceList[0], String.valueOf(UserPackage.PREMIUM_PACKAGE_TERM_30_DAYS));\noptionsElement.addOption(\"3 Months - \" + packagePriceList[1], String.valueOf(UserPackage.PREMIUM_PACKAGE_TERM_90_DAYS));\noptions...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T16:31:11.987", "Id": "26159", "Score": "-1", "Tags": [ "java" ], "Title": "Restructure this Java code to allow for sometime have 4 items in packagePriceList" }
26159
<p>I'm sort of at a loss for what to do with webapps and whether what I'm doing is actually allowed or not. Here is a sample of the type of thing I'm doing at the moment. I need a list that is accessible by essentially everything.</p> <pre><code>global_list = [] @bottle.route('/') def index(): global_list.append(...
[]
[ { "body": "<p>Ah, the age old pragmatism vs. purism. While it sounds like you have a healthy amount of skepticism, I think this is actually one of the few instances where it's OK to use a global variable. The core of your problem is you need to share data (state) between two routes. A global variable is the sim...
{ "AcceptedAnswerId": "26193", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T18:02:28.427", "Id": "26165", "Score": "3", "Tags": [ "python", "design-patterns", "scope", "bottle" ], "Title": "Accessing a global list" }
26165
<p>The rules for this program are to:</p> <ul> <li>Generate n X n grid.</li> <li>Arbitrarily pick a point and grow a 'shape' based off that initial point.</li> <li>Must have at least 3 points.</li> <li>Strongly biased to not completely fill grid.</li> </ul> <hr> <pre><code>using System; using System.Collections.Gene...
[]
[ { "body": "<ol>\n<li><p><code>runCount</code> and <code>CurrentLevel</code> seem redundant.</p></li>\n<li><p>I don't see why you pass <code>start</code>, <code>neighbors</code> and <code>neighborsToActivate</code> as parameters to the recursive function since you just clear them without using the data.</p></li>...
{ "AcceptedAnswerId": "26239", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T18:06:58.407", "Id": "26166", "Score": "1", "Tags": [ "c#", ".net", "recursion" ], "Title": "Implement recursion" }
26166
<p>I am developing a script that will act as a surrogate of sorts for a web portal and an email blast program. The web portal is used to create web-to-print files and is very good at creating print-ready PDF files, but currently lacks any email blast or HTML output options for the end user. In order to circumvent this ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T04:31:53.667", "Id": "40526", "Score": "0", "body": "Just curious, is there a (possibly business) reason everything has to be done through email? It sounds like you're generating email templates for something like MailChimp or Campa...
[ { "body": "<h3>PEP8</h3>\n\n<p>You're not following <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a>, Python's official coding style guide, for example:</p>\n\n<ul>\n<li>Don't put multiple imports on the same line</li>\n<li>Put a space after commas in parameter lists, so <code>m.lo...
{ "AcceptedAnswerId": "74470", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T18:07:17.047", "Id": "26167", "Score": "6", "Tags": [ "python", "parsing", "email" ], "Title": "Parse emails and create HTML markup from attachments" }
26167
<p>I have an image which is a black ring:</p> <p><a href="http://imageshack.us/a/img51/2029/blackcb.png" rel="nofollow noreferrer">black ring http://imageshack.us/a/img51/2029/blackcb.png</a></p> <p>In my view, I need to display it as a white ring. So, to tint the image, I have written the below method:</p> <pre><co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T18:05:13.950", "Id": "40500", "Score": "0", "body": "What do you mean by \"better?\"" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T18:14:10.237", "Id": "40501", "Score": "0", "body": "By...
[ { "body": "<p>Try this function that I adapted. It creates a mono-color \"mask\" from an input image. If you use white, it turns every non-transparent pixel to white:</p>\n\n<pre><code>- (UIImage*)convertToMask: (UIImage *) image\n{\n UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);\n ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T18:04:24.233", "Id": "26168", "Score": "2", "Tags": [ "objective-c", "ios", "image" ], "Title": "Tinting an image" }
26168
<p>I created a library/npm module to handle the signaling process for <code>RTCPeerConnection</code>. There is still a good bit of work that needs done (error handling, dealing with users disconnecting during the signaling process, etc.), but at the moment I am mostly looking for suggestions/ideas about the overall arc...
[]
[ { "body": "<p>Interesting code,</p>\n\n<p>I am somewhat surprised that you assign <code>connectToPeer</code> to <code>Peer.prototype</code>. A distinct <code>Peer</code> function object will be created with each call of <code>createPeer</code>, which makes it pointless to assign anything to the <code>prototype<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T20:13:54.550", "Id": "26178", "Score": "2", "Tags": [ "javascript", "node.js", "library-design", "socket" ], "Title": "RTCPeerConnection signaling library" }
26178
<p>I couldn't quickly find Java code with googling to make serialized Json easier to read (this is a <strong>debugging library</strong>, obviously implementation code wouldn't use this as it's just more characters). This is <strong>not</strong> intended to be viewed in a web browser, this is intended for console output...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T00:58:48.180", "Id": "40522", "Score": "0", "body": "This will be thrown off by any of the characters tested for occurring in a value string." } ]
[ { "body": "<p>I think you need to ignore the contents of quoted values.</p>\n\n<p>Add the flag:</p>\n\n<pre><code> boolean inQuotes=false;\n</code></pre>\n\n<p>then, at the top of your <code>if</code> statement:</p>\n\n<pre><code> if (c == '\"') {\n inQuotes=!inQuotes;\n }\n i...
{ "AcceptedAnswerId": "26183", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-14T21:25:02.623", "Id": "26181", "Score": "2", "Tags": [ "java", "json", "formatting" ], "Title": "Json whitespace formatter" }
26181
<p>For my models for a certain section I thought it would be better to have a base class model for both "view" and "edit" models, like so:</p> <pre><code>public abstract class Setting { [Required] public int SettingId { get; set; } public string Name { get; set; } [Required] [MaxLength(255)] ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T07:05:27.393", "Id": "40533", "Score": "0", "body": "I might consider composition over inheritance in this case. Of course that's probably a preference thing." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<p>The Model wouldn't change regardless of whether you were viewing it or editing the records in the given model. </p>\n\n<hr>\n\n<p>Let's go ahead and create a view and edit model from the information you have given us, it will look like this</p>\n\n<p><strong>Note:</strong> this doesn't work, it is...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T02:25:54.470", "Id": "26184", "Score": "2", "Tags": [ "c#", ".net", "asp.net", "entity-framework" ], "Title": "Models in .NET: separate settings" }
26184
<p>I have this <code>Board</code> class:</p> <pre><code>import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Random; import javax.swing.JButton; import javax.sw...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T09:06:56.587", "Id": "40539", "Score": "0", "body": "Give better names for button1, frame1, etc." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T13:22:18.923", "Id": "40547", "Score": "0", ...
[ { "body": "<ol>\n<li>As was suggested in the comments, initialize your matrix as <code>boolean[][] emptyBoard = new boolean[10][10]</code>, as in Java booleans will default to <code>false</code>.</li>\n<li>Document your code: all IDEs will have some support for JavaDoc, use it.</li>\n<li>Also suggested in the c...
{ "AcceptedAnswerId": "26232", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T06:57:10.647", "Id": "26196", "Score": "4", "Tags": [ "java", "swing", "game-of-life" ], "Title": "Game of Life Animation Java" }
26196
<p>Can someone please review my code:</p> <pre><code># dup/ish -&gt; //github.com/rails/rails/issues/5449 class Form include Mongoid::Document attr_accessor :source def self.ish(prefix, suffix, &amp;block) klass_name = prefix.classify + suffix dup.tap do |klass| klass.class_eval do defi...
[]
[ { "body": "<p>Few things I have noted in your design are listed below. Beware all of this is purely from a design perspective rather than application.</p>\n\n<ol>\n<li><strong>Source</strong> is defined as <code>attr_accessor</code> which essentially violates encapsulation. Inject it from outside in constructor...
{ "AcceptedAnswerId": "108258", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T14:10:17.557", "Id": "26202", "Score": "2", "Tags": [ "object-oriented", "ruby", "ruby-on-rails", "form", "meta-programming" ], "Title": "Duplicating Rails model for a...
26202
<pre><code> SELECT BR.IDObject AS IDObject, B.imgName AS imgName, BK.imgPath AS imgPath, BR.imgType AS imgType FROM ImageReferences BR INNER JOIN BDB_WebImages B ON BR.IDWebImage = B.ID INNER JOIN BDB_WebImageCategory BK ON BR.IDImageCategory...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-20T21:53:50.443", "Id": "58196", "Score": "0", "body": "what SQL database are you using?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-20T21:54:46.230", "Id": "58197", "Score": "0", "body": "a...
[ { "body": "<p>Queries involving a large amount of data blobs on a SQL Server version that does not support streams will be pretty slow.</p>\n\n<p>Try using a common table expression to build up your reference query before hitting the actual image data (I'm assuming you're using data blobs to store your image da...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T14:47:27.010", "Id": "26203", "Score": "-2", "Tags": [ "optimization", "sql" ], "Title": "Optimizing this seemingly slow Query" }
26203
<p>I'm trying to come up with a simple router class. I considered using a <code>Request</code> class, but I think that will turn something simple into something overly complex. That is why I did not consider creating one for my framework.</p> <pre><code>class Router { private $uri; private $controller; pr...
[]
[ { "body": "<h2>What is a router used for?</h2>\n\n<p>Translate one address to another one connection two different <em>network</em> to eahc other depending on rules. It will never instantita a browser to display for example a HTTP request.</p>\n\n<h2>Your class doing to much and much lesser than it should</h2>\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T14:48:02.323", "Id": "26204", "Score": "2", "Tags": [ "php", "mvc", "controller", "url-routing" ], "Title": "Router Class In a Lightweight MVC Boilerplate" }
26204
<p>How can I eliminate repetition from this code?</p> <pre><code>std::vector&lt;std::wstring&gt; vec; bool descending; if (descending) { std::sort(vec.begin(), vec.end(), std::greater&lt;std::wstring&gt;()); } else { std::sort(vec.begin(), vec.end...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T18:21:58.147", "Id": "40578", "Score": "0", "body": "All containers have an internal type indicating the type they contain: `vec::value_type`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T18:30:52.4...
[ { "body": "<p>not an answer but extended comment that needs space:</p>\n\n<pre><code> typedef std::vector&lt;std::wstring&gt; Vec;\n Vec vec;\n\n std::sort(vec.begin(), vec.end(), std::greater&lt;Vec::value_type&gt;());\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", ...
{ "AcceptedAnswerId": "26221", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T15:46:35.703", "Id": "26209", "Score": "8", "Tags": [ "c++", "sorting", "vectors" ], "Title": "C++ vectors sort ascending/descending" }
26209
<p>I'm pretty excited to have coded my first JavaScript file which now works, and I've spent my evening trying to improve it.</p> <p>It takes a location in the <code>#loc</code> input box and geocodes it (gets coordinates from a location) when the search button is pressed, or when the autosuggestion is clicked, then s...
[]
[ { "body": "<p>Looking at your code, the first thing that stands out is the <code>coded</code> variable. You're checking or setting its value in many different places, which is the sort of thing you want to avoid, as it can quickly lead to errors. You're manually keeping track of the state.</p>\n\n<p>A simpler, ...
{ "AcceptedAnswerId": "26220", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-15T20:15:45.463", "Id": "26215", "Score": "3", "Tags": [ "javascript", "performance", "jquery", "formatting", "geospatial" ], "Title": "JavaScript geocoder" }
26215
<p>With the inclusion of <code>&lt;random&gt;</code> into C++11, we can finally chuck out <code>std::rand</code> and start using generator with much better properties. Still, it's easy to get things wrong (uniform sampling where 0 occurs more than it should due to usage of <code>% size</code> comes to mind). To that en...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T12:01:53.043", "Id": "40615", "Score": "3", "body": "Double underscore in identifiers `__` is reserved." } ]
[ { "body": "<p>Overall, your code is clean, well written and seems very consistent (and the comments also seem relevant). There is not much to say, so I will focus on some details since I don't see anything else to review:</p>\n\n<ul>\n<li>First of all, Loki is right in his comment: your header guards names (<co...
{ "AcceptedAnswerId": "46909", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T03:48:29.343", "Id": "26222", "Score": "11", "Tags": [ "c++", "c++11", "random" ], "Title": "Random Generation From Sequences" }
26222
<p>The goal is to have fields in a class which are optional and can be determined if they are set in order to be able to leave them out of serialization. </p> <pre><code>template&lt;typename T&gt; class Nullable { public: Nullable() : m_value(), m_isSet(false) {} Nullable(T value) : m_value(value), m_isSet(tr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-11-05T14:55:15.557", "Id": "125908", "Score": "0", "body": "Use `const T&` and `T&&` for construct and assignment operators. Also use `const T&` where you don't modify the values. Use variadic templates with perfect forwarding for versati...
[ { "body": "<p><strike>Don't see the point in:</p>\n<pre><code>using std::swap;\n</code></pre>\n<p>It adds a line. It is also longer to type than just prefix each swap with <code>std::</code></strike></p>\n<p>As pointed out by @Matt below. There is a good reason to do this.<br />\nRead his links below for a more...
{ "AcceptedAnswerId": "26226", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T07:46:57.090", "Id": "26224", "Score": "12", "Tags": [ "c++", "template" ], "Title": "Simple \"nullable\" template class. Are there weaknesses in the implementation?" }
26224
<p>I'm learning to work in GAE. I'm so used to SQL, but transform my way of think the last 20 years to NoSQL is a little hard for me.</p> <p>I have the next simple structure:</p> <ul> <li><code>BOOKS</code> than can have <code>CHAPTERS</code></li> <li><code>CHAPTERS</code> that can have <code>VOTES</code></li> </ul> ...
[]
[ { "body": "<ol>\n<li><p>This depends on a few things (keep reading).</p></li>\n<li><p>Not necessarily. This is a question of optimization. You could fetch a vote's book by using Chapter as an intermediary (<code>vote.getChapter().getBook()</code>), but this would obviously require sequential trips to the databa...
{ "AcceptedAnswerId": "26276", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T08:54:22.560", "Id": "26225", "Score": "1", "Tags": [ "python", "google-app-engine" ], "Title": "Defining book models in GAE" }
26225
<p>I am solving a problem on calculation of factorial and the challenge is as follows!</p> <pre><code>You are asked to calculate factorials of some small positive integers. Input An integer t, 1&lt;=t&lt;=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1&lt;=n&lt;=100....
[]
[ { "body": "<p>The following comments are somewhat related :</p>\n\n<ul>\n<li><p>Your <code>factorial</code> function should probably be called <code>printFactorial</code>.</p></li>\n<li><p>You should separate the computing logic and the printing logic.</p></li>\n<li><p>You could use/implement a way to handle Bi...
{ "AcceptedAnswerId": "26250", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T12:19:49.853", "Id": "26228", "Score": "2", "Tags": [ "c", "algorithm", "performance" ], "Title": "Time limit of a c program while calculating factorial of numbers in c" }
26228
<p>I am hiding and fading in different content on the same page using jQuery to <code>hide()</code> and <code>fadeIn()</code> the content depending on which link is clicked.</p> <p>It works how I want it to, but the way I've written the jQuery looks like it could be simplified.</p> <pre><code>$("#navItem1").on('click...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T12:49:02.660", "Id": "40627", "Score": "1", "body": "For some reason all the current answers seem to want you to change the HTML or add random loops. There is no need. My answer here uses basic jQuery functionality to achieve all of...
[ { "body": "<p>Perhaps change the HTML:</p>\n\n<p>Navitem:</p>\n\n<pre><code>&lt;span class=\"navItem\" data-content-id=\"1\"&gt;&lt;/span&gt;\n</code></pre>\n\n<p>The content</p>\n\n<pre><code>&lt;div id=\"content-wrap1\" class=\"content-wrap\"&gt;&lt;/div&gt;\n</code></pre>\n\n<p>jQuery</p>\n\n<pre><code>$('.n...
{ "AcceptedAnswerId": "26230", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T12:31:46.860", "Id": "26229", "Score": "25", "Tags": [ "javascript", "jquery" ], "Title": "Set of jQuery .onclick functions" }
26229
<p>I just wrote my first Java database program for the purpose of getting feedback on the implementation and coding. It has 1 table and 2 buttons and prompts the user to select a folder, lists the contents of the folder in the table and lists the hash of the files in the table and writes it to a database.</p> <p>It wo...
[]
[ { "body": "<p>This is what I noticed after taking a quick look:</p>\n\n<ol>\n<li>I'm not a big fan of the static/singleton-ness of this class. Those attributes make this class harder to mock and unit test. Take a look at POJO/dependency injection (you don't need a container to do DI).</li>\n<li>I would consid...
{ "AcceptedAnswerId": "26255", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T13:29:25.500", "Id": "26242", "Score": "3", "Tags": [ "java", "database" ], "Title": "Basic Java database" }
26242
<p>At this moment I'm reading an <code>XmlNodeList</code> into a <code>ListItemCollection</code> one node at a time using a <code>foreach</code>:</p> <pre><code>foreach (XmlNode node in authCompXml.SelectNodes("//Code")) { CompaniesList.Items.Add(new ListItem(node.InnerText)); } </code></pre> <p>How can this be i...
[]
[ { "body": "<pre><code>CompaniesList.Items.AddRange(authCompXml.SelectNodes(\"//Code\")\n .Cast&lt;XmlNode&gt;()\n .Select(node =&gt; new ListItem(node.InnerText))\n .ToArray());\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "26244", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T13:42:12.360", "Id": "26243", "Score": "1", "Tags": [ "c#", "asp.net" ], "Title": "XmlNodeList to ListItemCollection" }
26243
<p>InstaSlider is a lightweight jQuery image slider / carousel plugin that populates content from an Instagram hashtag.</p> <p>After searching for a similar solution for one of my own projects with no luck I decided there might be others who would benefit from this.</p> <p>It is the bare minimum function at the momen...
[]
[ { "body": "<p>I think you'd really benefit looking at either jQuery UI's widget factory or (my preference) using some boilerplate such as <a href=\"http://jqueryboilerplate.com/\" rel=\"nofollow\">jQuery Boilerplate</a>.</p>\n\n<p>Other than that, in no particular order:</p>\n\n<ol>\n<li><code>$.fn.instaSlider....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T14:40:26.487", "Id": "26245", "Score": "1", "Tags": [ "javascript", "jquery", "plugin", "instagram" ], "Title": "InstaSlider slider/carousel plugin" }
26245
<p>This is on a job listing site and it has a Linkedin apply button plugin - this provides for a callback the someone has applied for a job. I've written the callback function which extracts the Job ID (a primary key in my database) and makes an AJX call to indcate that this Job ID has been applied for.</p> <p>The Li...
[]
[ { "body": "<p>This looks pretty good, not much room for improvement I think. LinkedIn's JavaScript is calling linkedInApplySuccess, correct? All you have to do is specify data-success-callback, or something similar, in your HTML? </p>\n\n<p>The only minor thing I would do is instead of sending <em>just</em> the...
{ "AcceptedAnswerId": "26248", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T15:34:57.617", "Id": "26247", "Score": "1", "Tags": [ "javascript", "jquery", "json", "ajax", "callback" ], "Title": "Callback for job applicant" }
26247
<p>I am relatively new to Ruby and am trying to get a handle on making my code more Ruby-esque. At the same time I am experimenting with the branch and bound algorithm to solve a problem that I outline in this <a href="http://www.mikecordell.com/blog/2013/05/05/branch-bound-problem-in-ruby.html" rel="nofollow">blog pos...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T21:01:20.340", "Id": "40670", "Score": "0", "body": "A note from experience: if you ask to review so many LOC, chances are nobody will answer, too much work. Maybe you can reduce it to a method you're specially worried about." }, ...
[ { "body": "<p>One thing that will help a lot is using <code>attr_accessor</code>. You can use is so that you don't have so many instance variables littering your methods. You can also initialize <code>best_score</code> and <code>best_combos</code> and give them default values. (But generally, according to <a hr...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T16:29:33.523", "Id": "26251", "Score": "3", "Tags": [ "algorithm", "ruby" ], "Title": "Ruby Branch and Bound Algorithm implementation?" }
26251
<p>I would appreciate some feedback regarding best practices on the following code for a college project.</p> <p>What should go in the controller and what in the views? How to attach and remove the views to the single main frame? Change the Controller after successful login?</p> <p><strong>Studentenverwaltung.java</s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T20:45:21.393", "Id": "40665", "Score": "0", "body": "on popular naming convention is for all private variable to begin with an underscore id `private JLabel _lblWelcome;` this would also eliminate the need for so many uses of `this`...
[ { "body": "<p>Use <a href=\"http://whitemagicsoftware.com/encapsulation.pdf\" rel=\"nofollow noreferrer\">self-encapsulation</a>, which will help apply the Open-Closed Principle.</p>\n\n<h1>Studentenverwaltung.java</h1>\n\n<p>Use an IDE that will automatically import classes explicitly. Future maintainers shoul...
{ "AcceptedAnswerId": "38850", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T17:02:05.923", "Id": "26252", "Score": "5", "Tags": [ "java", "mvc" ], "Title": "Feedback on college project" }
26252
<p>I am working on a <code>java swing project</code> that looks like a Terminal (but with less functionality).</p> <p>The GUI contains a <code>jTextArea</code> to display output and a <code>jTextField</code> for user input.</p> <p>Here is an application of the my GUI to perform a simple task.</p> <ol> <li>Ask the us...
[]
[ { "body": "<p>Maybe something like this? Note: may add textField as a member of State0 and State1</p>\n\n<pre><code>public interface State\n{\n boolean hasNext();\n State next();\n}\n\npublic final class State0\n implements State\n{\n private boolean okToContinue = false;\n private int number;\n\...
{ "AcceptedAnswerId": "26555", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T20:26:00.110", "Id": "26258", "Score": "1", "Tags": [ "java", "swing" ], "Title": "Better Design Pattern For Terminal-Like GUI" }
26258
<p>I have this view that populates an unordered list from values in a JSON file, which I am doing in Node.</p> <p>Is there a better way to do this, or a more 'node-like' way? Can I load the JSON file without an Ajax call?</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;4&amp;middot;pli...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T20:37:00.430", "Id": "40663", "Score": "2", "body": "`async: false` --- baaaad" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T20:38:11.767", "Id": "40664", "Score": "0", "body": "@JanDvor...
[ { "body": "<p>What you're looking for is <code>JSON.parse</code>. It's not in the Node docs, because it's \"lower\" than that: Every modern javascript runtime has it (<a href=\"https://developer.mozilla.org/en/docs/JSON\" rel=\"nofollow\">see MDN</a>).</p>\n\n<p>Here's a simple function to read a file, parse it...
{ "AcceptedAnswerId": "26262", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T20:31:39.417", "Id": "26259", "Score": "2", "Tags": [ "javascript", "json", "node.js", "express.js" ], "Title": "Populating an unordered list from values in a JSON file" }
26259
<p>I am trying to show the 6 most popular products on my homepage from left to right, in two rows. My code actually works... but I have the feeling I am making things way too complicated. Is there a simpler way to do this?</p> <p>Here is my code:</p> <pre><code>$dynamicList = ""; $sql = mysql_query("SELECT * FROM pro...
[]
[ { "body": "<p>Let's go for a step-by-step cleanup.</p>\n\n<p>1) Get rid of repetition by using a variable to store your html code common to the different branches.</p>\n\n<p>2) Remove useless levels of indentation to make things easier to follow.</p>\n\n<p>The inside of the <code>while</code> loop is now :</p>\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T20:36:25.853", "Id": "26260", "Score": "3", "Tags": [ "php", "mysql" ], "Title": "Dynamic homepage with PHP - making things too complicated?" }
26260
<p>I've created a singleton by means of an interface. I don't want to make a thing with <code>getInstance()</code> etc because I don't care about inheritance, and it's redundant and non-declarative.</p> <p>Are there downsides of doing it this way? Any redundancy I can remove? Is there a cleaner/more consise way to do ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T21:19:55.513", "Id": "40676", "Score": "1", "body": "I would think passing null in for no parameters would get a little tiresome, and also make the code a little less clear." }, { "ContentLicense": "CC BY-SA 3.0", "Creat...
[ { "body": "<p>Your implementation fails to adhere to some important Object Oriented principles.</p>\n\n<ol>\n<li><p>Encapsulation</p>\n\n<p>The state of your singleton can be modified by others.</p>\n\n<pre><code>package a;\n\npublic class Cat implements Dog {\n\n static {\n State.age = 17;\n }\n\n...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T20:54:23.707", "Id": "26263", "Score": "3", "Tags": [ "java", "singleton", "interface" ], "Title": "Singleton interface in Java" }
26263
<p>I have a WPF application that needs to get a XML document using a web request. The request is based on an id that the user enters. If the user enters a second id, before the first returns, I would like to cancel the first request, and start over with the second id. The following works, but I'm not sure if there is a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T22:54:27.390", "Id": "40680", "Score": "0", "body": "Can you use C# 5.0? It makes working with asynchronous code much easier." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T23:08:43.700", "Id": "...
[ { "body": "<blockquote>\n <p>Is this approach poor form?</p>\n</blockquote>\n\n<p>I think yes</p>\n\n<blockquote>\n <p>Is passing in a reset event better than having a loop within the function that tests the DoWorkEventArgs::Cancel property every tenth of a second?</p>\n</blockquote>\n\n<p>Both are wrong. Eve...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T21:31:04.637", "Id": "26267", "Score": "3", "Tags": [ "c#", "multithreading" ], "Title": "Proper way to cancel WebClient in BackgroundWorker" }
26267
<p>I like the way Zend Framework works it's views and I make extensive use of partials but every partial include results in it's own file system hit. As I'm building my own framework I thought I could do better so this is what I came up with. What I'm looking for is any potential problems that I should watch out for an...
[]
[ { "body": "<p>You might have noticed that this is not very clean code:</p>\n\n<pre><code>$code = 'if (is_array($data)) {foreach($data as $k=&gt;$v){${$k} = $v;}} ?&gt;' . file_get_contents($targetPath) . '&lt;?php '; \n$func = create_function('$data = array()', $code);\n</code></pre>\n\n<p>You don't need to us...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T22:19:00.653", "Id": "26268", "Score": "3", "Tags": [ "php", "php5", "template", "zend-framework" ], "Title": "Potential Problems with this templating technique" }
26268
<p>I am working on page titles to be responsive. The code I have works and gets the job done, but I know that this is verbose. I decided upon the widths by trial and error based on how the words were stacking on each other </p> <p><br /> <strong>Desktop</strong> <img src="https://i.stack.imgur.com/qnfEy.png" alt="Desk...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T06:55:23.593", "Id": "40701", "Score": "0", "body": "(Note: trial and error based on what you're seeing is error-prone, I often see overflowing text on my browser because of this.)" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>If you have control over your html, give both headers the same class, for example .header-stretch.\nFor media queries - you actually can get rid of min-width. Yep, your code will be overriden for several times. But browser won't care rewriting the same parameter(font-size in this case - in any oth...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T22:21:20.400", "Id": "26269", "Score": "4", "Tags": [ "html", "css" ], "Title": "Minimizing CSS media queries for the page title?" }
26269
<p>A common idiom that I use for Python2-Python3 compatibility is:</p> <pre><code>try: from itertools import izip except ImportError: #python3.x izip = zip </code></pre> <p>However, a <a href="https://stackoverflow.com/questions/16598244/zip-and-groupby-curiosity-in-python-2-7/16598378?noredirect=1#comment23...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T23:10:11.107", "Id": "40683", "Score": "0", "body": "Perhaps the commenter meant to use the import to shadow `zip`? I.e., `try: from itertools import izip as zip; except ImportError: pass`. (Please excuse the lack of newlines.)" }...
[ { "body": "<p>Not sure this is really an answer, or I should elaborate on my comment, and in hindsight probably not even a very good comment anyway, but:</p>\n\n<p>Firstly, you can just simplify it to:</p>\n\n<pre><code>try:\n from itertools import izip as zip\nexcept ImportError: # will be 3.x series\n p...
{ "AcceptedAnswerId": "26273", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T22:53:34.787", "Id": "26271", "Score": "12", "Tags": [ "python", "dynamic-loading" ], "Title": "Import \"izip\" for different versions of Python" }
26271
<p>Let's say we need to create a store for selling prime numbers.</p> <p>Users enter the store and ask to buy a number.</p> <ol> <li><p>If the number asked <strong>is a prime number</strong>, </p> <p>1.1. then it's either <strong>available for sale</strong></p> <p>1.2. or was purchased earlier, hence <strong>not av...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T06:53:02.317", "Id": "40699", "Score": "1", "body": "It's nice to see thoughtful questions. Thanks!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-21T09:13:20.857", "Id": "88544", "Score": "0", ...
[ { "body": "<pre><code>foreach (var number in parallelQuery)\n{\n _primes.Add(number, false);\n}\n</code></pre>\n\n<p>You could simplify this to:</p>\n\n<pre><code>_primes = parallelQuery.ToDictionary(n =&gt; n, n =&gt; false);\n</code></pre>\n\n<hr>\n\n<pre><code>public void BuyNumber(Int32 number, Action&lt...
{ "AcceptedAnswerId": "26277", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-16T23:39:49.593", "Id": "26272", "Score": "7", "Tags": [ "c#", "primes", "singleton", "callback", "sieve-of-eratosthenes" ], "Title": "Prime Numbers Store" }
26272
<p>I am creating a game, with Ruby scripting.</p> <p><code>Sprite</code> and <code>Label</code> objects can be drawn on the screen. Depending on the order you draw them, one will overlap the other.</p> <p>To make things easier, I want to implement a property in my drawable objects: <strong>Z order</strong>. So the hi...
[]
[ { "body": "<blockquote>\n <p>how can I further improve this class to be able to draw the objects in the right order depending on their Z property?</p>\n</blockquote>\n\n<p>The abstraction for the task is a <a href=\"http://en.wikipedia.org/wiki/Priority_queue\" rel=\"nofollow\">priority queue</a>, that's it, a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T01:07:36.130", "Id": "26278", "Score": "2", "Tags": [ "optimization", "ruby" ], "Title": "Drawing game objects using their Z-order property" }
26278
<pre><code>try{save.Username = usernamedetails.Rows[0].ItemArray[0].ToString(); } catch{ save.Username = ""; } try { save.Firstname = dtdetails.Rows[0].ItemArray[1].ToString(); } catch { save.Firstname = ""; } try { save.LastName = dtdetails.Rows[0].ItemArray[2].ToString(); } catch { save.LastName = ""; } try { save.Ad...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T05:42:35.783", "Id": "40698", "Score": "27", "body": "**YUCK!** ​​​​​​" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T10:01:02.120", "Id": "40705", "Score": "0", "body": "What is the reas...
[ { "body": "<p>First: Never have an exception raised just because you're too lazy to validate the input.\nSecond: The very repetitive wording begs for some improvement. You're dealing with the same objects in each line pair, so why not implement some array and null checks in sub functions?</p>\n", "comments"...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T05:08:34.823", "Id": "26280", "Score": "8", "Tags": [ "c#", "exception-handling" ], "Title": "Saving a contact and dealing with exceptions" }
26280
<p>A while ago I started working on a project, which does things mostly with jQuery and PHP. I had some problems with my structure and started using CodeIgniter which uses an MVC pattern. So the PHP part is all good now.</p> <p>I am just a little worried about my jQuery code. It looks bloated and I feel like there is ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T12:59:09.973", "Id": "40713", "Score": "1", "body": "What about security? Will the server refuse to send data if the player executes LoadGame() from the browser debug window without having been authentified?" }, { "ContentLi...
[ { "body": "<p>You say you got a hundred of these? And possibly longer?</p>\n\n<p>I suggest you invest on learning these tools:</p>\n\n<ul>\n<li><p>A client-side MV* framework like <a href=\"http://backbonejs.org/\" rel=\"nofollow\">Backbone</a>. That way, your code will be modular and structured.</p></li>\n<li>...
{ "AcceptedAnswerId": "26336", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T08:36:15.467", "Id": "26286", "Score": "4", "Tags": [ "javascript", "jquery", "design-patterns", "mvc", "ajax" ], "Title": "jQuery code repetition and MVC" }
26286
<p>I am currently working on a project that involves Lua. For convenience, I created a wrapper class for the Lua state structure. However, I also added some methods for getting globals and table fields. Since these methods are very similar, I decided do turn them into macros.</p> <p>Do you consider this a good solutio...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T17:49:50.473", "Id": "40738", "Score": "1", "body": "If you change (or wrap) functions like (`lua_isnumber` and `lua_tonumber`) or (`lua_isstring` `lua_tostring`) to function templates (e.g., `lua_is<TypeHere>` and `lua_to<TypeHere>...
[ { "body": "<blockquote>\n <p>Do you consider this a good solution?</p>\n</blockquote>\n\n<p>No.</p>\n\n<blockquote>\n <p>Would you have done it another way?</p>\n</blockquote>\n\n<p>Yes.</p>\n\n<p>Macros are never the solution. There is always a better tool. Macros are designed to deal with Hardware/OS/Compil...
{ "AcceptedAnswerId": "26323", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T12:29:34.640", "Id": "26291", "Score": "6", "Tags": [ "c++", "macros", "lua" ], "Title": "C++: Generating similar methods with macros" }
26291
<p>This question is about the best way to declare functions in Javascript. The app is a small 2 player board game I'm working on as part of a bigger web page. Basically I have a socket which receives and send messages and the game acts according to the content of the message.</p> <pre><code>$(function () { var boa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T14:52:52.267", "Id": "40722", "Score": "0", "body": "I just answered, but now I realize I may have misread your code. are the lines with action1 inside of func1() and action2 inside of func2() meant to be method calls? is doAction1...
[ { "body": "<p>Since this is all the code you posted, I'm going to assume you're only using these functions in the place they're defined, so the later code would be best. It's more readable and doesn't include unnecessary identifiers.</p>\n\n<p>Your question is really about anonymous functions, not closures. To ...
{ "AcceptedAnswerId": "26299", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-17T13:11:08.473", "Id": "26293", "Score": "2", "Tags": [ "javascript", "jquery", "game" ], "Title": "2-player board game app" }
26293