body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I'm trying to learn C++ with Eigen. Here's my attempt at computing <a href="http://stat.ethz.ch/R-manual/R-patched/library/stats/html/mahalanobis.html" rel="nofollow">Mahalanobis</a> distances of a set of points <code>x</code> with respect to a sub-matrix <code>xs</code>.</p> <p>The aim of the project is to turn a...
[]
[ { "body": "<h3>Is it effecient</h3>\n\n<p>Imposable to tell as we have no idea how stuff in Eigen is implemented.</p>\n\n<h3>Comments on code:</h3>\n\n<p>There should be some logic in the ordering of includes. So you can easily find ones that have been included or spot missing ones (or know where to put knew on...
{ "AcceptedAnswerId": "9573", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-29T13:07:20.277", "Id": "9554", "Score": "3", "Tags": [ "c++", "beginner", "matrix", "eigen" ], "Title": "Implementation of Mahalanobis distances using Eigen" }
9554
<p>For flexing my newly acquired Django &amp; Python muscles, I have set up a mobile content delivery system via Wap Push (Ringtones, wallpapers, etc).</p> <p>The idea is that a keyword comes in from an sms via an URL, let's say the keyword is "LOVE1" and the program should search if this keyboard points to a Rington...
[]
[ { "body": "<p>You have 2 models (Ringtone extends Contenido). As I understand you store same <code>nombre</code>, <code>fecha_creacion</code>, <code>keyword</code> in both models and every update/delete/insert operation on the first model must be synchronized with another one. You can avoid this, make foreign k...
{ "AcceptedAnswerId": "9570", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-29T13:24:36.157", "Id": "9555", "Score": "3", "Tags": [ "python", "django" ], "Title": "Mobile content delivery system" }
9555
<p>I have been wondering this for a while. Take this example:</p> <pre><code>&lt;?= Zend_Registry::get('translate')-&gt;_('translate me!'); </code></pre> <p>I have my views cluttured with such code. My coworkers also complain often that its a lot to type juste to get translation and since it is repeated all over the ...
[]
[ { "body": "<p>The two real questions are:</p>\n\n<ol>\n<li>What are the advantages of having this in Zend_Registry?</li>\n<li>What would you loose when using a helper function?</li>\n</ol>\n\n<p>I believe the answers to these questions lead to this: <strong>use the helper function</strong>. This will:</p>\n\n<u...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-29T15:50:24.970", "Id": "9560", "Score": "0", "Tags": [ "php", "comparative-review", "i18n", "zend-framework" ], "Title": "Fetching translated strings, keeping in the philosophy ...
9560
<p>This project is based on trivia (question/answer quiz). The scenario is simple but I have to improve/optimize my query using these tables:</p> <p><img src="https://i.stack.imgur.com/g3V8s.png" alt="enter image description here"></p> <pre><code>$query=$this-&gt;db-&gt;query("SELECT q.`id`, q.`topic_id`, t.`topic`, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-29T10:41:44.593", "Id": "15102", "Score": "0", "body": "I agree. I'd vote to move it but there isn't an option for codereview in the migrate voting list." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-29T...
[ { "body": "<p>well I used the MS sql for reference but that should be a bit batter. I would also reccomend you to structure your sql cos that way you get a better overview of things.\nCarefull the below seelect is not grouped you can group it as a subquery again</p>\n\n<pre><code>SELECT q.id, q.topic_id, q.ques...
{ "AcceptedAnswerId": "9566", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-29T10:35:48.883", "Id": "9565", "Score": "3", "Tags": [ "php", "sql", "mysql", "quiz" ], "Title": "Q/A trivia quiz query" }
9565
<p>I'm new to Java and this is my first program. I'm trying to verify that my thought processes are good.</p> <p>Let me know of any improvements infor the code, whether it's too few/too many comments, poorly structured code, etc.</p> <pre><code>import javax.swing.*; import java.math.*; import java.util.*; class Root...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-29T22:10:26.367", "Id": "15118", "Score": "4", "body": "looks spaghettic. Not reusable. Merging interactive IO with the calculation (business logic)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T18:14...
[ { "body": "<p>You have way too many comments. Assume the developer reading your code knows Java, and can read standard library documentation. Thus, you do not need comments like:</p>\n\n<p><code>//Variable for Coefficient A</code> (or equivalent for any other variable)</p>\n\n<p><code>//Variable &amp; Constan...
{ "AcceptedAnswerId": "9576", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-29T21:37:26.620", "Id": "9571", "Score": "4", "Tags": [ "java", "beginner", "mathematics", "swing" ], "Title": "How does this quadratic formula program look?" }
9571
<p>I came across <a href="https://codereview.stackexchange.com/questions/9289/changing-bits-in-given-big-strings">this thread</a> and I am working on the same problem. My best algorithm passes 6/11 cases while the algorithm in the other thread does indeed pass 8/11 cases. Running time trials with random input my algori...
[]
[ { "body": "<p>Consider this case:</p>\n\n<pre><code>A: 1111111111\nB: 1111111111\nQuery: n+1\n</code></pre>\n\n<p>The other post terminates very quckly. It knows that since both numbers end in 1, it must carry and thus doesn't have to scan throughout the entire string. On the other hand, your method tries to fi...
{ "AcceptedAnswerId": "9579", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T00:26:37.990", "Id": "9578", "Score": "2", "Tags": [ "java", "algorithm" ], "Title": "Strange algorithm results" }
9578
<p>My code will, from a web-gui, generate <a href="http://thevash.com" rel="nofollow">Vash</a> images. This currently involves making a call to a local binary, java. I'm wondering, if I've taken reasonable measures against this being exploited by a malicious user, or not.</p> <p>The code will be used in several differ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T15:57:55.047", "Id": "53803", "Score": "0", "body": "are you running Java on the BackEnd or PHP? the question is Tagged PHP but then you mention Java and Jar files?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<p>You aren’t validating any user input in your code, while <code>escapeshellarg</code> protects you from malicious arguments nothing protects you from calling your JAR with wrong arguments. Properly validating everything is the best advice I can give you.</p>\n\n<p><b>Example</b></p>\n\n<pre><code>&...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T07:51:34.193", "Id": "9580", "Score": "4", "Tags": [ "php", "security" ], "Title": "Safely pass user input to a CLI application on the server?" }
9580
<p>I want to design API which could handle XPATH input from a user. I currently model the XPATH input in the following way:</p> <pre><code>public interface ICondition { String getConditionString(); } public class XPathCondition implements ICondition { private Class&lt;? extends XPATHFunction&gt; clazz = null...
[]
[ { "body": "<p>Can I ask why you're trying to do this? If this is homework or a way to \"practice Java/Object-Oriented programming\", please say so. If it's a real question, the best way to represent XPath input is actually <strong>a string</strong>. XPath is way more complicated than what you've (XPath 2.0 even...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T09:32:56.483", "Id": "9582", "Score": "1", "Tags": [ "java", "xpath" ], "Title": "Handling XPATH input from a user" }
9582
<p>This code is very simple, but it is intended as an experiment in the relative performance of mutexes/CAS on different platforms. The latest version can always be found at:</p> <p><a href="https://github.com/alexdowad/showcase/blob/master/ruby-threads/concurrent_stack.rb" rel="nofollow">https://github.com/alexdowad/...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T18:51:43.130", "Id": "15508", "Score": "0", "body": "The bounty on this question is going to expire; if you want it, run the benchmark and post the results, even if you can't find any way to improve the code!" } ]
[ { "body": "<p>I took the latest source code from the github and have started review of this project. Here are my benchmarks results:</p>\n\n<pre><code># Intel(R) Core(TM)2 Duo CPU P7570 @ 2.26GHz\n# ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]\nTesting ThreadSafeStack with 1 thread, iterating 10...
{ "AcceptedAnswerId": "9858", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T09:58:11.177", "Id": "9583", "Score": "3", "Tags": [ "ruby", "performance", "multithreading", "stack" ], "Title": "Concurrent stack implementations in Ruby (relative perform...
9583
<p>I have the following solution structure. This is a business domain (for an amount transfer operation in bank account) which will be called by a WCF service. Is the solution structuring correct? </p> <ol> <li><p>Data Acess Layer does not create domain objects. It just pass database record wrapped in another simple o...
[]
[ { "body": "<p>No, it is not. It sucked 10 yars ago and ever since LINQ and IQueryable it is just bad.</p>\n\n<p>How coms you need an AccountDAL while I have not had a DAL for a specific entity for the last 15 years, awlw\n\n<p>Please read up on RM's and all the technology that is avaialble in .NET ever since .N...
{ "AcceptedAnswerId": "9587", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T05:35:43.230", "Id": "9585", "Score": "3", "Tags": [ "c#", ".net", "object-oriented", "design-patterns" ], "Title": "Is the solution design optimal? C# 3 - Tier" }
9585
<p>This is the first piece of code I wrote on my own. I tried to use everything I know, like functions, loops and variables. Is it good or could it be simpler?</p> <p>Please be hard as you can be with me because I feel my programming knowledge is quite poor and I end up using Google for solving my problems.</p> <pr...
[]
[ { "body": "<p>First of all, stop using <code>system(\"pause\");</code> and <code>system(\"cls\");</code>. Both of those are not portable, and are silly ways of achieving what you want. Take a look <a href=\"https://stackoverflow.com/q/1173208/559931\">here</a> for an actual solution.</p>\n\n<p>Secondly, you a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T12:10:46.983", "Id": "9590", "Score": "4", "Tags": [ "c++", "beginner", "game", "rock-paper-scissors" ], "Title": "Rock-Paper-Scissors game" }
9590
<p>I'm working on some code that deals with mangled C++ function names. I'm displaying these to the user, so to help with readability of some of the really long C++ template class/function names, I'm removing some of the template arguments based on how deeply nested the template argument is.</p> <p>The code below work...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-05-02T17:12:32.953", "Id": "160487", "Score": "2", "body": "This is a C++ comment rather than a Python answer, but, please be aware that attempting to parse C++ template names with hand-written code places you in a state of sin just as mu...
[ { "body": "<p>First of all, your code doesn't seem to work: <code>removeTemplateArguments(\"foo&lt; bar&lt;int&gt; &gt;()\", 2)</code> has a trailing \">\" that shouldn't be here according to your docstring:</p>\n\n<ul>\n<li><code>foo&lt; bar&lt;&gt; &gt;()</code> (expected)</li>\n<li><code>foo&lt; bar&lt;&gt; ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T12:53:24.207", "Id": "9592", "Score": "2", "Tags": [ "python" ], "Title": "Removing C++ template arguments from a C++ function name" }
9592
<p>I have two more methods the same as this except that they query a different table. Is there another way to know if the result of the query is <code>null</code>? The <code>hasher.CompareStringToHash()</code> method is not allowed to have a <code>null</code> value.</p> <p>If it's not <code>null</code>, it proceeds to...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T17:28:39.117", "Id": "15183", "Score": "6", "body": "Minor recommendation: Don't prefix or abbreviate things as \"Ass\". Use \"Asst\" for \"Assistant\"." } ]
[ { "body": "<p>I believe you're looking for <a href=\"http://msdn.microsoft.com/en-us/library/system.string.isnullorempty.aspx\" rel=\"nofollow\"><code>String.IsNullOrEmpty</code></a>.</p>\n\n<pre><code>// test for null or empty string\nif (!String.IsNullOrEmpty(password) {\n}\n\n// -- OR --\n\n// If the hasher ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T15:03:43.340", "Id": "9597", "Score": "4", "Tags": [ "c#", "performance", ".net", "authentication" ], "Title": "Check assistant's password" }
9597
<p>I'd like to get input on a F# actor that coordinates receives around a blocking message buffer. The actor is a piece of code that continuously tries to fetch messages from Azure Service Bus.</p> <pre><code>(* Copyright 2012 Henrik Feldt Licensed under the Apache License, Version 2.0 (the "License"); you may not use...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T13:18:22.877", "Id": "15396", "Score": "0", "body": "So let's say something to try to get this question up into the active set." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-13T13:37:13.457", "Id":...
[ { "body": "<p><em>Disclaimer:</em> I know some OCaml and a bit of Erlang, but never implemented an F# actor before. I also read the async paper you mentioned in the comments (apart from \"Semantics\" and \"Implementation\").</p>\n\n<h1>Style</h1>\n\n<p><strong>Indentation</strong></p>\n\n<pre><code>type RecvMsg...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T18:31:31.800", "Id": "9605", "Score": "3", "Tags": [ "c#", ".net", "f#", "actor" ], "Title": "Review an asynchronous/message-oriented library actor" }
9605
<p>As I thought about <a href="https://stackoverflow.com/questions/9523476/how-to-skip-a-field-without-entering-value-in-c">this question</a> on SO, I realized that I wanted to implement either a string trimmer or a trimmed string inputter. </p> <p>This is what I came up with, but I have a nagging feeling I could have...
[]
[ { "body": "<p>Some thoughts:</p>\n\n<ul>\n<li>Would you lose anything if <code>trim</code> took a single template parameter that would accept the type of the string? You're not doing anything with the individual parameters, after all.</li>\n<li>I don't think the second loop is particularly ugly. You could use...
{ "AcceptedAnswerId": "9654", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-01T21:46:32.250", "Id": "9610", "Score": "3", "Tags": [ "c++" ], "Title": "String Trimmer and trimmed Input routine" }
9610
<p>I'm building a GWT application for GAE, using JDO for Datastore access. I use and Entity class for data mapping, so it contains lots of Persistence annotations:</p> <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION) public class AppointmentEntity implements Serializable { private static fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T12:48:17.123", "Id": "15221", "Score": "0", "body": "My feeling is that few members have GWT/JDO experience, but lot of them have design/programming experience. Linking to what Entity or DTO are would probably help everyone understa...
[ { "body": "<p>There is this <a href=\"http://code.google.com/p/objectify-appengine/wiki/ObjectifyWithGWT\" rel=\"nofollow\">concerning GWT and GAE objects</a>. If that doesn't work for you, I would rather have a class of public static methods that does the conversions rather than sticking it into some kind of \...
{ "AcceptedAnswerId": "9640", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T01:09:24.600", "Id": "9619", "Score": "1", "Tags": [ "java" ], "Title": "Parsing: Entity Classes to DTO" }
9619
<p>My goal in the method is to write a simple clustering program that determines if a clustering document is valid based on these rules:</p> <ul> <li>All clusterings start with <code>&lt;</code> and end with <code>&gt;</code>. Every start clustering <code>&lt;something&gt;</code> must be followed (eventually) by an en...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T06:37:26.480", "Id": "15203", "Score": "3", "body": "The headline of your question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T12:22:04.053", "Id": "15217", "Score": "0", "body": "1/ ...
[ { "body": "<p>Thanks for sharing your code! Let's see what can be improved.</p>\n\n<h2>Design</h2>\n\n<p>You're mixing a lot of things in your code. This makes it difficult to read and write. It also violates the <a href=\"http://en.wikipedia.org/wiki/Single_responsibility_principle\" rel=\"nofollow\">Single Re...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T02:14:58.087", "Id": "9620", "Score": "2", "Tags": [ "java", "validation", "clustering" ], "Title": "Validating a clustering document" }
9620
<p>I have created this model for Codeigniter. It's working fine, but I need to know if it can be more optimized.</p> <pre><code>class Basic_Function_Model extends CI_Model { var $msg_invalid_array; var $msg_no_table; function __construct() { parent::__construct(); $this-&gt;msg_inval...
[]
[ { "body": "<p>First of all, thanks for sharing your code, this is the best way to improve yourself!</p>\n\n<h2>The M in MVC</h2>\n\n<p>A <em>Model</em> in any MVC framework should provide an easy way to access a <em>specific</em> type of data. It allows you to stop worrying about database details and only acces...
{ "AcceptedAnswerId": "9626", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T06:05:40.640", "Id": "9624", "Score": "5", "Tags": [ "php", "codeigniter" ], "Title": "Codeigniter Model Optimization" }
9624
<p>Flash messages are generally composed in the controller. Sometimes we need those flash messages to have links in them (like an <kbd>undo</kbd> button).</p> <p>How would you compose such a message?</p> <p>The only sane way I have found to create such messages is by a presenter that includes much of ActionView in it...
[]
[ { "body": "<p>You actually have several options. One way to clean this up a bit would be to use Rails' <a href=\"http://guides.rubyonrails.org/i18n.html\" rel=\"nofollow\">I18n</a> module, e.g.:\n</p>\n\n<pre class=\"lang-none prettyprint-override\"><code># config/locales/en.yml\nen:\n post_successful_html: Po...
{ "AcceptedAnswerId": "9659", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T09:27:21.967", "Id": "9629", "Score": "4", "Tags": [ "ruby", "ruby-on-rails", "mvc" ], "Title": "HTML flash messages" }
9629
<p>Can this Code be any shorter? because it seems it is very long with just simple insertion of data using LINQ TO SQL</p> <pre><code> public void addPatientInformation() { using(DbClassesDataContext myDb = new DbClassesDataContext()){ PatientInfo patientInfo = new PatientInfo(); ...
[]
[ { "body": "<p>Yes. You can use <a href=\"http://msdn.microsoft.com/en-us/library/bb384062.aspx\">object initializer</a> syntax and bring the amount of text down a bit:</p>\n\n<pre><code> public void addPatientInformation() {\n using(DbClassesDataContext myDb = new DbClassesDataContext()) {\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T15:19:27.373", "Id": "9638", "Score": "1", "Tags": [ "c#", ".net", "sql", "linq" ], "Title": "Inserting Data in The Database using LINQ TO SQL" }
9638
<pre><code>&lt;html&gt; &lt;body&gt; &lt;?php $username = $_POST['username']; $password = $_POST['password']; $name = $_POST['name']; echo "Doing ``"."useradd $username -p '$password' "."'' as ".get_current_user()."..&lt;br/&gt;"; passthru("/usr/bin/sudo /usr/bin/sbin/useradd $username -p '$password'" ); echo "finished...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T20:36:57.760", "Id": "15268", "Score": "0", "body": "I have no idea how to sanitize that properly. Do you really need it? Oh and add a `$return_var` parameter to see what sudo returns to you." } ]
[ { "body": "<p>I strongly suggest to sanitize the input ($_POST[]) before using. Even more in your case that you execute shell command with it.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T19:46:58.293", ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T17:06:38.737", "Id": "9649", "Score": "-2", "Tags": [ "php" ], "Title": "Add User Via php" }
9649
<p>I have experience is C#/ASP.NET, and I've done MVC in Ruby On Rails, so I figured making the jump to ASP.NET MVC would be a breeze. Unfortunately, I'm second-guessing my every decision. I'd like some more eyes on this to tell me if my way of doing things is insane.</p> <p>My main question is around editing an ent...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T17:39:00.157", "Id": "15259", "Score": "1", "body": "Not enough expirience with EF to answer your question (which DOES look right btw) but I generally disparage people away from the `from...where...select` LINQ syntax as it hides wh...
[ { "body": "<p>Here is a link to <a href=\"http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application\" rel=\"nofollow\">the \"official\" tutorial on basic CRUD operations in ASP.NET MVC and EF</a>. </p>\n\n<p>The...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T17:12:31.053", "Id": "9650", "Score": "2", "Tags": [ "c#", "entity-framework", "asp.net-mvc-3" ], "Title": "Am I approaching this ASP.Net MVC/Entity Framework pattern incorrectly?...
9650
<p>Could someone be kind enough to review this Fourier transformation, please? I'm especially interested in going about unit testing the code (I don't really know where to begin, beyond applying the fft twice to retrieve the input), and have left test functions blank.</p> <p>If you do spot a bug (and no doubt there ar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T21:59:18.903", "Id": "15271", "Score": "0", "body": "Wish I knew enough C++ to be of help here. I remember the fourier transform from image processing class - it was fun." } ]
[ { "body": "<p>Using <code>operator==</code> on doubles isn't usually a good idea, although it may be okay in the <code>TestSpike</code> case as you know you've assigned exactly 1.0 to it previously.</p>\n\n<p>I would write <code>GenerateSpike</code> as follows:</p>\n\n<pre><code>void GenerateSpike(Complex* data...
{ "AcceptedAnswerId": "9666", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T19:39:05.723", "Id": "9651", "Score": "3", "Tags": [ "c++", "signal-processing" ], "Title": "Fourier transformation" }
9651
<p>Problem:</p> <p>What is an effective design pattern to allow an end user to indirectly modify the state of data in an object based on a prioritized list of user specified modifers?</p> <p>Explanation : This is very general of course, but hang in there for a second so I can elaborate - I'm not a software person by ...
[]
[ { "body": "<h2>Design pattern?</h2>\n\n<p>Thanks for your detailed question. Sorry, but what you're looking for is not a \"design pattern\". Look at this quote from Wikipedia (emphasis mine):</p>\n\n<blockquote>\n <p>In software engineering, a design pattern is a general reusable\n solution to a <strong>commo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-03T00:55:48.207", "Id": "9656", "Score": "0", "Tags": [ "c++", "c++11" ], "Title": "How to design a class that allows a user to indirectly modify its internal state through a prioritized...
9656
<p>As a learning exercise, I decided to write a script for helping me maintain my Unix configuration/dot-files under a git repository. I check out a copy of the repository in my home directory called .dotfiles, and, inside that, I have the Python script called linkify, which deals with creating links from my home direc...
[]
[ { "body": "<pre><code>#!/usr/bin/env python\n\nimport errno\nimport os\n\nto_keep_private = [\n</code></pre>\n\n<p>By convention, global constants are in ALL_CAPS in python</p>\n\n<pre><code> 'cifs-credentials',\n 'config',\n 'fetchmailrc',\n 'gitconfig',\n 'gnupg',\n 'mpoprc',\n 'msmtprc',...
{ "AcceptedAnswerId": "9667", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-03T01:04:10.570", "Id": "9657", "Score": "3", "Tags": [ "python", "beginner", "file-system", "git", "unix" ], "Title": "Symlinking git-managed dotfiles into a home director...
9657
<p>I am writing a shell script to sort my files by extension and unzip archives. It works in simple cases, but I haven't tested it extensively. How can I make it more robust against the set of file names that may be present?</p> <pre><code>#!/bin/bash #File sorter SECONDS=0 SAVEIFS=$IFS IFS=$(echo -en "\n\b") echo "tr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-03T01:18:49.257", "Id": "15276", "Score": "0", "body": "Given that two of us have posted a review of your code, I'm going to suggest that this question be migrated to [codereview.se]. Do not repost there! Once you've figured out what y...
[ { "body": "<p>I don't see why you want to use awk, or what kind of report you want to see. I have made some code-review-type adjustments to your script:</p>\n\n<pre><code>#!/bin/bash\n# sort files into subdirectories\nstart=$SECONDS # this is a magic bash variable\necho \"trigger took place i...
{ "AcceptedAnswerId": "9664", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T23:07:46.880", "Id": "9662", "Score": "4", "Tags": [ "bash", "shell" ], "Title": "Script to group files by extension and unzip archives" }
9662
<p>I'm worried about my own attempt at a solution for a Sphere-Plane collision testing. I originally implemented a solution I found on a mix of Game Development websites around the place, which was similar enough to the following:</p> <pre><code>bool intersecting(BoundingSphere const&amp; s, Vector3 const&amp; s_origi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-03T23:00:38.937", "Id": "15297", "Score": "1", "body": "Off topic. Would probably by a better for http://math.stackexchange.com/" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T10:22:03.337", "Id": "...
[ { "body": "<p>I'm not sure what kind of error your getting but here is a very simple collision test:</p>\n\n<pre><code>#include &lt;cmath&gt;\n#include &lt;iostream&gt;\n\nclass float3 {\n public:\n float x,y,z;\n};\n\nclass float4 {\n public:\n float a,b,c,d;\n ...
{ "AcceptedAnswerId": "9673", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-03T17:48:17.010", "Id": "9672", "Score": "2", "Tags": [ "c++" ], "Title": "Sphere-Plane collision test" }
9672
<p>I use the following code:</p> <pre><code> var newValue = ($(event.target).is(":checked")) ? 1 : 0; var oldValue = (!$(event.target).is(":checked")) ? 1 : 0; sendMessage(this.name, oldValue, newValue); </code></pre> <p>Is there any better approach?</p>
[]
[ { "body": "<p><code>sendMessage(this.name, +!event.target.checked, +event.target.checked)</code></p>\n\n<p>Not your sending <code>sendMessage(text, !bool, bool)</code> which is silly just send one bool.</p>\n\n<p>Also <code>$(thing).is(\":checked\")</code> is stupid (jQuery ಠ_ಠ)</p>\n", "comments": [ ...
{ "AcceptedAnswerId": "9675", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-03T20:37:53.773", "Id": "9674", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "How to transform true and false to 1 and 0?" }
9674
<p>I'm attempting to improve my coding style by concentrating on simple and focused OOP client-server interfaces and error handling - atm in the context of designing a Blackjack game. I'm starting with the Card class that represents an individual card. I'm looking for any improvements on or flaws with my approach.</p...
[]
[ { "body": "<p>If you are going to go to the trouble of creating Rank and Suit enum then use them.</p>\n\n<pre><code>Card( int rank, int suit ) throw(std::range_error)\n</code></pre>\n\n<p>I would have done</p>\n\n<pre><code>Card(Rank rank,Suit suit )\n</code></pre>\n\n<p>That way you can't accidentally go: <cod...
{ "AcceptedAnswerId": "9678", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-03T21:39:05.297", "Id": "9676", "Score": "3", "Tags": [ "c++", "beginner", "playing-cards" ], "Title": "Card class for card games" }
9676
<p>I feel that my app could be more efficient but I am not sure what else I can do. I feel like I could be reusing more. If you could give me some tips on how I could improve this, I would really appreciate it.</p> <pre><code>public class Main { /** * @param args * @throws InterruptedException */ pub...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T12:54:42.227", "Id": "15338", "Score": "0", "body": "Note that you don't need to write `(float) 0.0575`, just `0.0575F`." } ]
[ { "body": "<ol>\n<li><p>I believe you'd be better off with having term, interestRate,... as privates, and provide those in the Calc constructor.</p></li>\n<li><p>The name DoWork does not convey the task the function performs; a better name could be CalculatePayment. Also, the \"do\" in \"DoWork\" suggests that ...
{ "AcceptedAnswerId": "9682", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T01:20:42.640", "Id": "9680", "Score": "4", "Tags": [ "java", "finance" ], "Title": "Mortgage calculator" }
9680
<p>I have a sort of database with a <a href="http://www.tomjewett.com/dbdesign/dbdesign.php?page=manymany.php" rel="nofollow" title="many-to-many">many-to-many</a> association between tags and files. For various reasons, I decided to forgo a junction table in favor of having the left and right tables store the associat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T03:23:16.940", "Id": "15321", "Score": "0", "body": "What are the types of `db->forward` and `db->reverse`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T03:49:20.907", "Id": "15323", "Score"...
[ { "body": "<p>You can pass a function that gets the correct object from tagdb.<br>\nAKA Service Locator pattern</p>\n\n<pre><code>typedef HashTable* (*ITEM_GETTER)(tagdb*);\n\nHashTable* getTag(tagdb *db) { return db-&gt;reverse;}\nHashTable* getFile(tagdb *db) { return db-&gt;forward;}\n\nGHashTable *tagdb_ge...
{ "AcceptedAnswerId": "9704", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T01:34:22.357", "Id": "9681", "Score": "4", "Tags": [ "c" ], "Title": "Creating a common interface" }
9681
<p>As you can see from the code below, my <code>set</code> function accepts two types of parameters: either strings or arrays. Now, ideally I would like to be using operator overloading to handle this, but since PHP doesn't offer anything like that I am stuck with code like this. Is there a better way to write this (o...
[]
[ { "body": "<p>First, there is a simple way to flatten out those loops, but it is not what I would suggest. Here is the simple way:</p>\n\n<pre><code>if ((sizeof($var) == sizeof($content))) {\n $count = sizeof($var);\n\n for ($i =0; $i &lt; $count; $i++) {\n $this-&gt;template = str_replace(\n ...
{ "AcceptedAnswerId": "9686", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T02:37:46.603", "Id": "9683", "Score": "1", "Tags": [ "php", "template" ], "Title": "Setting a variable for a view template" }
9683
<pre><code>public void AddClient(Client obj){ try{ using(System.Data.SQLite.SQLiteConnection conn = stock.db.SqlLiteConnection.getSQLLiteConnection()){ System.Data.SQLite.SQLiteCommand cmd = conn.CreateCommand(); string sql="insert into Client (email,firstName,lastName,telephone,address,city,state,z...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T14:36:12.240", "Id": "15340", "Score": "1", "body": "You should add relevant tags to get a better responce" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T16:16:15.187", "Id": "15351", "Score"...
[ { "body": "<p>OK, here goes: </p>\n\n<ol>\n<li><p>No. You're using <code>using</code> which means that the object will be disposed of in the end of the block. As part of the <code>Dispose()</code> method, the connection will be closed and its resources released.</p></li>\n<li><p>Not manually, you should open ...
{ "AcceptedAnswerId": "9695", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T14:08:08.110", "Id": "9694", "Score": "0", "Tags": [ "c#", "sql" ], "Title": "Basic SQL user database" }
9694
<p>I'm working on a framework (partly out of frustration with Zend, and partially as a learning exercise to improve my coding). I've constructed a fairly solid library of classes for data validation, and the next step was to string them all together with dependency injection. </p> <p>However, I was finding it to be a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T22:42:44.487", "Id": "15473", "Score": "0", "body": "Will look through this later, but I sent this to the guy who made the Zend DI Container :) He says https://github.com/ralphschindler/Zend_DI-Examples" }, { "ContentLicense...
[ { "body": "<p>I think the real problem here is your over-zealousness of using classes.</p>\n\n<p>Consider this snippet of your code:</p>\n\n<pre><code>$password -&gt; addProp (new prop\\Required ())\n -&gt; addProp (new prop\\Min (array ('limit' =&gt; 5)))\n -&gt; addProp (new prop\\Max ...
{ "AcceptedAnswerId": "9939", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T17:57:31.927", "Id": "9696", "Score": "5", "Tags": [ "php", "design-patterns", "dependency-injection" ], "Title": "DI container for data validation" }
9696
<p>This code is a mess due the complex nature of the job, so I'd like to know your opinions. The concept is very simple if you know what this is about, but there are some things I'm not being able to refactor.. </p> <p>Examples of what I want as an answer: Macroing of repetitive tasks? Declaring pointers in stack? But...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T21:26:07.377", "Id": "15356", "Score": "0", "body": "So what is the question? \"The concept is very simple if you know what it is about.\"..so, what is it about?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<h3>Turn on your compiler warnings: (Fix this first)</h3>\n<p>Even at the most basic warning level I get a whole bunch of warnings. Personally I compile at a much higher warning level then basic and then I get two pages of warning messages.</p>\n<p>They may be called warnings but really they are <str...
{ "AcceptedAnswerId": null, "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T21:19:03.377", "Id": "9697", "Score": "2", "Tags": [ "c++", "computational-geometry" ], "Title": "Building 3d geometry from tile description" }
9697
<p>It does generate pretty decent normals but I'm not sure if I could improve it even more without losing performance.</p> <p>You can find the whole code here:</p> <ul> <li><a href="http://code.google.com/p/roplusplus/source/browse/RO%2B%2B/ropp_map.h" rel="nofollow">ropp_map.h</a></li> <li><a href="http://code.googl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T21:35:04.700", "Id": "15360", "Score": "0", "body": "Examples of what I want as an answer: Macroing of repetitive tasks? Declaring pointers in stack? But I also want to keep it as clear as possible, and I don't think want to declare...
[ { "body": "<p>Your code is hard to review, since one would need to exactly understand the underlying mathematics, then understand your code, then propose meaningful abstractions. I do hope someone will do it, but I can't. I also believe that for complicated code like that, it's OK to repeat yourself, since it's...
{ "AcceptedAnswerId": "9735", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T21:28:03.803", "Id": "9698", "Score": "2", "Tags": [ "c++", "computational-geometry" ], "Title": "Normal calculation for tile terrain geometry" }
9698
<p>I have a large library (four packages) of data processing code that I have written over the last 12 months. I am quite new to python and would like to see if I am doing things correctly.</p> <p>This utility/convenience code is currently kept in a module called utils that is imported in many places (for an example, ...
[]
[ { "body": "<p>It was really hard to understand what you're code is doing, but it does have some easy spottable \"problems\":</p>\n\n<h2><code>is None</code> vs. <code>== None</code></h2>\n\n<p>PEP8 clearly states: </p>\n\n<blockquote>\n <p>Comparisons to singletons like <em>None</em> should always be done with...
{ "AcceptedAnswerId": "9705", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T21:34:29.007", "Id": "9700", "Score": "2", "Tags": [ "python", "numpy" ], "Title": "Simple utility/convenience module - am I doing it right?" }
9700
<p>I have a data processing application that does some data cleaning as the first step. This is the module I import for that purpose.</p> <p>The only 'public' part of the api is the 'clean' function which returns a processed version of the input data.</p> <p>So to clean data I currently do something like this:</p> <...
[]
[ { "body": "<p>I wasn't able to fully understand what your code does, but there are a couple of improvements that could be made. I will go through them first, and answer your questions after.</p>\n\n<h2>Inheritance</h2>\n\n<p>There's a pattern going on here:</p>\n\n<pre><code>class ConsumptionCleaner(CleanerBase...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-04T23:09:57.433", "Id": "9702", "Score": "1", "Tags": [ "python", "numpy" ], "Title": "Data cleaning - am I using classes correctly here?" }
9702
<p>Consider the following CSV file:</p> <pre><code>A; B; ; B; ; A; C; ; E F; D; ; E; E; C; ; </code></pre> <p>The fields:</p> <ul> <li><code>$1</code>: the <code>jname</code>. A unique id of the entry.</li> <li><code>$2</code>: a " "(space)-separated list of <code>incond</code>.</li> <li><code>$3</code>: a " "(space...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T17:09:28.317", "Id": "15401", "Score": "1", "body": "Not really a CSV file is it! C => Comma => ','. You have a SSC. Semicolon separated file." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-03-11T17:43:18....
[ { "body": "<h3>Your main questions</h3>\n\n<blockquote>\n <p>The script works, although I do not have large data to test against.</p>\n</blockquote>\n\n<p>You don't necessarily need a large dataset.\nIt's better to think of all possible corner cases.\nFor example, your sample data demonstrates failures of <cod...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T03:46:27.003", "Id": "9706", "Score": "2", "Tags": [ "shell", "awk" ], "Title": "Linking input/output states and conditions in an input file" }
9706
<p>The <a href="/questions/tagged/computational-geometry" class="post-tag" title="show questions tagged &#39;computational-geometry&#39;" rel="tag">computational-geometry</a> tag should be assigned to questions about computation and manipulation of locations or properties of geometric identities or objects. Since geome...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T07:28:06.933", "Id": "9707", "Score": "0", "Tags": null, "Title": null }
9707
Computer geometry is a branch of computer science devoted to the study of algorithms which can be stated in terms of geometry.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T07:28:06.933", "Id": "9708", "Score": "0", "Tags": null, "Title": null }
9708
<p>Note that I'm using a C++ compiler ( hence, the cast on the <code>calloc</code> function calls) to do this, but the code is essentially C.</p> <p>Basically, I have a <code>typedef</code> to an <code>unsigned char</code> known as <code>viByte</code>, which I'm using to create a string buffer to parse a file from bin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T14:43:47.360", "Id": "15398", "Score": "1", "body": "This question is a bit offtopic since the code doesn't work, and that's forbidden (cf. the faq). But since there's also an interesting question about code correctness, it could be...
[ { "body": "<p>Your problem is here:</p>\n<pre><code>buf-&gt;str[ buflen ] = '\\0';\n</code></pre>\n<p>You allocate a buffer (str) of buflen bytes.<br />\nThis means you can index it (str) from 0 -&gt; (buflen-1).</p>\n<p>Thus the accesses above is writing one past the end of the buffer and corrupting memory.<br...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T07:58:57.860", "Id": "9709", "Score": "1", "Tags": [ "c", "strings", "parsing" ], "Title": "C-Style unsigned char parsing and manipulation" }
9709
<p>Mostly a question on which approach would be better <em>and</em> when utilizing the <code>using</code> keyword, would it still be neccesary to close streams programatically. If an object implements <code>IDisposable</code> should <code>using</code> always be used?</p> <p>Link to my full answer using this sample: <a...
[]
[ { "body": "<p>Yes, always. Unless it's a class-level variable in which your type should then implement <code>IDisposable</code> and dispose of them in its <code>Dispose()</code> method.</p>\n\n<p>So, option 2.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
{ "AcceptedAnswerId": "9726", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T12:03:16.090", "Id": "9714", "Score": "14", "Tags": [ "c#" ], "Title": "Using statement in context of streams and WebClients" }
9714
<p>I try to implement a simple RLE compression algorithm as a learning task. In the first step, i need to split my source list to sequences of repeating and non-repeating elements. I've done it, but code seems to be so ugly. Can I simplify it?</p> <pre><code>src = [1,1,2,3,3,4,2,1,3,3,4,3,3,3,3,3,4,5] from itertools ...
[]
[ { "body": "<p>First of all I must tell you that Python makes astonishing easy to write a <a href=\"http://en.wikipedia.org/wiki/Run-length_encoding\" rel=\"nofollow\">Run-length encoding</a>:</p>\n\n<pre><code>&gt;&gt;&gt; src = [1,1,2,3,3,4,2,1,3,3,4,3,3,3,3,3,4,5]\n&gt;&gt;&gt; from itertools import groupby\n...
{ "AcceptedAnswerId": "9728", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T18:33:55.590", "Id": "9721", "Score": "3", "Tags": [ "python" ], "Title": "List splitting for RLE compression algorithm" }
9721
<p>I have a problem to solve. My algorithm is assigning Players to Positions. On the start I have a list of about 16 positions and 4 players. The problem is to assing every player to it's closest positions so the overall distance is as low as possible.</p> <p>I've already done this:</p> <pre><code>List players = ... ...
[]
[ { "body": "<p>You could use the <a href=\"http://groovy.codehaus.org/groovy-jdk/java/util/Collection.html#eachPermutation%28groovy.lang.Closure%29\" rel=\"nofollow\"><code>eachPermutation</code></a> method to avoid building the set of permutations in memory.</p>\n\n<p>That said, with 16 positions there will be ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T17:19:33.803", "Id": "9723", "Score": "1", "Tags": [ "algorithm", "groovy" ], "Title": "Groovy: permutations() with size limit" }
9723
<p>I needed to create a method that would sanitize DOM IDs based on the HTML 4 criteria (yeah, HTML 5 is a lot looser). Does this make sense? Did I get too cute with making it concise? Am I totally misinterpreting what a DOM id is? I presumed it meant something like <code>&lt;p id="annoying_paragraph"&gt;&lt;/p&gt;</co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T14:05:48.633", "Id": "15455", "Score": "0", "body": "are you using Rails? You know there is such helpers in Rails?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T13:44:50.133", "Id": "15482", ...
[ { "body": "<p>Here is my implementation, the early return and extra variable are probably a matter of taste. \nThat early return doesn't feel idiomatic.</p>\n\n<p>It attempts to remove invalid characters at the start of the candidate_id, until it finds valid ones. It will only prefix if it can't find a valid id...
{ "AcceptedAnswerId": "9961", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-05T21:49:54.117", "Id": "9730", "Score": "2", "Tags": [ "ruby", "html", "ruby-on-rails", "regex", "dom" ], "Title": "Sanitize DOM IDs" }
9730
<p>Super-duper javascript noob here. I'm trying to fetch public repos from GitHub, and add them to a dl. I know this won't work on every website due to cross-site scripting, but GitHub offers a JSON-P API. I'm fairly certain that I'm doing this mostly the right way (it works), but the append function looks ugly, and I'...
[]
[ { "body": "<p>Looks fine dude,</p>\n\n<p>Peronsal pref, although like you I am NO javascript guru, however...</p>\n\n<pre><code>(function($){\n\n var GIt = {\n init: function(){\n this.get_repo_list();\n },\n get_repo_list : function(){\n\n var uri = \"https://ap...
{ "AcceptedAnswerId": "9740", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T01:54:20.207", "Id": "9732", "Score": "2", "Tags": [ "javascript", "jquery", "ajax" ], "Title": "Fetching data via jquery and adding items to a list" }
9732
<p>I am designing a class which (among other things) acts as a vertex in an undirected graph.</p> <pre><code>#include &lt;iterator&gt; #include &lt;string&gt; class Node { public: explicit Node(const std::string&amp; name); Node(const Node&amp;); Node(Node&amp;&amp;); class iterator : public ...
[]
[ { "body": "<h1><code>struct</code> has <code>public</code> inheritance</h1>\n\n<p>By default, <code>struct</code> has <code>public</code> inheritance. Therefore, you don't need to manually specify it every time. You can write shorter (and so more readable) code:</p>\n\n<pre><code>template &lt;&gt;\nstruct templ...
{ "AcceptedAnswerId": "51533", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T03:22:44.717", "Id": "9736", "Score": "12", "Tags": [ "c++", "c++11", "graph", "template-meta-programming", "variadic" ], "Title": "Variadic function with restricted ty...
9736
<p>I'm a ruby programmer who's writing Java for university. I'd love to get some feedback on how my Java looks and how to improve it to conform with the norms.</p> <pre><code>import java.util.Set; import java.util.HashSet; import java.util.List; import java.util.ArrayList; public class Cell { private Set&lt;Integer...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T09:04:45.483", "Id": "15439", "Score": "2", "body": "Additionally to Cygal's comments you should stick with Java naming conventions. Especially you should use camelCase for methods (underscores in names are only used in `static fina...
[ { "body": "<p><em>Edit:</em> As Landei suggested, use camelCase! Thanks Landei.</p>\n\n<ol>\n<li>Your <code>set</code> function does not need to take an Integer. Idiomatic code would only use an <code>int</code>. Autoboxing means you can still add an int to <code>this.possibles</code>.</li>\n<li>Why don't you u...
{ "AcceptedAnswerId": "10253", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T08:05:31.843", "Id": "9738", "Score": "2", "Tags": [ "java" ], "Title": "Experienced ruby programmer starting with Java" }
9738
<p>In the following code, <code>checkServerExists</code> function checks if the server exists in the vector. If it does, then the new message is directly pushed in the vector, otherwise a new thread is created and then the message is pushed in the vector.</p> <p>I need to know whether it makes sense to write the code...
[]
[ { "body": "<p>Any function that is a callback from a C library must use the C ABI.<br>\nIf your code is C++ (as this is) then you <strong>MUST</strong> declare the callback function appropriately to make sure the compiler gets the correct ABI:</p>\n\n<pre><code>extern \"C\" void* printHello (void* threadId);\n<...
{ "AcceptedAnswerId": "9759", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T08:08:03.120", "Id": "9739", "Score": "3", "Tags": [ "c++", "multithreading", "thread-safety", "pthreads" ], "Title": "Thread design for sending data to multiple servers" }
9739
<p>I am new to VB.NET and one of the functions I wrote is below. The idea behind it is to just send a dictionary and table name to the function, get the result and then return.</p> <p>Is this good practice or just silly?</p> <pre><code>Public Function dbInsert(ByRef EntryDetails As Dictionary(Of String, String),ByRef...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T17:09:22.177", "Id": "15464", "Score": "2", "body": "Using `byref` parameters when not needed is bad practice." } ]
[ { "body": "<blockquote>\n <p>This approach is not much good, but may be suit your required functionality. The method name is dbInsert and you\n are passing table and data in dictionary. you can make it much better by using better naming convention and parameter types. </p>\n</blockquote>\n\n<p>On the place of...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T09:07:15.200", "Id": "9742", "Score": "1", "Tags": [ "vb.net" ], "Title": "General insert function" }
9742
<p>Here's the exercise in brief:</p> <blockquote> <p>Consider the following file: Code:</p> <p><em>before.csv</em></p> <pre><code>A; ; B; B; A; H; C; ; D; D; C; G; E; D; F; F; E; H; G; D; ; H; G; ; </code></pre> <p>And a modified version of the file: </p> <p><em>after.csv</em></p> <pre><code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T13:01:21.813", "Id": "15447", "Score": "0", "body": "Could you realy on the sorting of the `id`s? Because if you can I would suggest a different approach, i.e. parsing the two files side by side." }, { "ContentLicense": "CC ...
[ { "body": "<p>I think that a simpler approach could be using the two files \"indexes\" using list comprehensions. What I would propose:</p>\n\n<p>create an Id list for the before and after file, extracted for the CSV (as you already do)</p>\n\n<p>So you would end up with something like:</p>\n\n<pre><code>befor...
{ "AcceptedAnswerId": "9747", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T12:14:25.140", "Id": "9744", "Score": "4", "Tags": [ "python", "performance", "python-2.x", "csv" ], "Title": "Comparing 2 CSV files" }
9744
<p>I had an interview recently where I was asked to produce the traditional FizzBuzz solution:</p> <blockquote> <p>Output a list of numbers from 1 to 100.</p> <ul> <li>For all multiples of 3 and 5, the number is replaced with "FizzBuzz"</li> <li>For all remaining multiples of 3, the number is replaced with ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T09:05:01.080", "Id": "15563", "Score": "0", "body": "@Winston: Thanks for the correction, this is probably better - I was originally thinking others would vote up/down my draft revision" } ]
[ { "body": "<ul>\n<li>You can avoid the special case for FizzBuzz</li>\n<li>No need to hard-code the limits </li>\n<li>It's not really <em>bad</em> if you have multiple <code>return</code>s in a short (!) method, but it should be avoided if you have an equally readable solution with only one <code>return</code><...
{ "AcceptedAnswerId": "9764", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T13:47:00.510", "Id": "9749", "Score": "6", "Tags": [ "java", "unit-testing", "interview-questions", "fizzbuzz" ], "Title": "Ways to improve my coding test FizzBuzz solution ...
9749
<p>I just started programming in Python this morning, and it is (more or less) my first programming language. I've done a bit of programming before, but never really did much except for "Hello World" in a few languages. I searched around for some Python FizzBuzz solutions, and they all seem significantly more complicat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T09:06:01.113", "Id": "35931", "Score": "3", "body": "Only slightly related to your question but this pages contains a few tricks quite interesting if you are starting to learn Python : http://www.reddit.com/r/Python/comments/19dir2/...
[ { "body": "<p>Your code looks fine. It certainly works. The only thing I'd say about it is that you are repeating the incrementation in all <code>if</code> blocks. You could just move that out of and after them and you'll achieve the same thing.</p>\n\n<pre><code>if (count % 5) == 0 and (count % 3) == 0:\n ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T14:32:50.613", "Id": "9751", "Score": "21", "Tags": [ "python", "beginner", "fizzbuzz" ], "Title": "Ultra-Beginner Python FizzBuzz ... Am I missing something?" }
9751
<p>In current task, I'm refactoring the code of converting JSON file into SQLite database on Android device. Code compliant with Java 6.</p> <p>As a benchmark, grabbing the code from remote server takes <code>~1 second</code>, but parsing it and saving to database takes <code>up to 1 minute</code></p> <p>In file the...
[]
[ { "body": "<p>You're trying to do a <a href=\"http://en.wikipedia.org/wiki/Bulk_insert\" rel=\"nofollow\">bulk insert</a>, which is notoriously slow on many databases if you're not careful. Indeed, each call to <code>insertWithOnConflict()</code> creates a new transaction, then inserts, then closes the transact...
{ "AcceptedAnswerId": "9767", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T11:02:17.780", "Id": "9766", "Score": "8", "Tags": [ "java", "parsing", "android", "json", "sqlite" ], "Title": "Optimize JSON insertion to SQLite (insert ... on duplica...
9766
<p>I have a <code>List&lt;string&gt;</code> being stored in my cache with about 600K members. I want this to act as the backend for an Ajax autocomplete box. It's accessible through my model:</p> <pre><code>public static List&lt;string&gt; GetProducts() { var cached = HttpContext.Current.Cache["MyApp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T17:13:51.553", "Id": "15494", "Score": "0", "body": "Were you aware that the `List<T>` type that you are using as backend is not thread safe? You should really take that into account when attempting to use it in a multi-threaded env...
[ { "body": "<p>A starts-with should be easy enough to store in a pre-sorted list, ideally using a case-insensitive sort comparer rather than applying conversions each sort. Then: use binary search to find the first match, and keep moving forwards until it no longer matches. Should be pretty efficient.</p>\n\n<p>...
{ "AcceptedAnswerId": "9776", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T17:11:42.080", "Id": "9773", "Score": "19", "Tags": [ "c#", "performance", "linq" ], "Title": "Optimizing List<string> performance" }
9773
<p>I have created code to show/hide data from a DB. It works, but as I am new to jQuery, I would like to know if this is a good way.</p> <p><strong>HTML:</strong></p> <pre><code>&lt;li class="devInfo"&gt; &lt;span class="sn_table"&gt;&lt;? echo $sn; ?&gt;&lt;/span&gt; &lt;span class="last_edit_table"&...
[]
[ { "body": "<ul>\n<li><p><strong><code>.live()</code></strong>: As of jQuery 1.7, the <code>.live()</code> method is deprecated <a href=\"http://api.jquery.com/live/\" rel=\"nofollow\">for various reasons</a>. Users should go for a combination of <a href=\"http://api.jquery.com/on/\" rel=\"nofollow\"><code>.on()...
{ "AcceptedAnswerId": "9800", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T19:24:59.803", "Id": "9780", "Score": "2", "Tags": [ "javascript", "jquery", "beginner", "html", "css" ], "Title": "Query, populate, show, hide data" }
9780
<p>This code feels like it goes through too many conversions to accomplish my goal:</p> <blockquote> <p>based on an IEnumerable of ids get those objects from a data store and set their <code>DisplayOrder</code> property to the position of the associated id.</p> </blockquote> <p>Is there a more elegant solution ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T19:55:05.303", "Id": "15511", "Score": "0", "body": "Are the elementSks in any particular order when the enter the method?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T21:40:46.460", "Id": "155...
[ { "body": "<p>If the list on input is going to be short, or if performance doesn't matter to you, you can simplify the code by using <code>IndexOf()</code> instead of the dictionary:</p>\n\n<pre><code>public void ReorderElements(IEnumerable&lt;int&gt; elementSks)\n{\n var elementsToReorder = GetSession().Que...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T19:41:36.667", "Id": "9782", "Score": "5", "Tags": [ "c#", "linq" ], "Title": "Reorder objects based on provided enumerable order" }
9782
<p>I'm trying to make an audio file tag editor, but I ran into some serious performance issues. Here's my method for loading files:</p> <pre><code>private void LoadFiles(params string[] fileNames) { foreach (string fileName in fileNames) { string path = fileName; if (loadedSongs.ContainsKey(path)) ...
[]
[ { "body": "<p>There are a couple suggestions:</p>\n\n<ul>\n<li>First, you do not need to use your path variable - it is simply fileName re-packaged. This is probably of negligible impact, but there's no reason to keep the extra string around, either.</li>\n<li>Next, a filesystem is not going to give you much i...
{ "AcceptedAnswerId": "9864", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T19:25:42.787", "Id": "9785", "Score": "5", "Tags": [ "c#" ], "Title": "Adding many items generated from Taglib# is incredibly slow and expensive, how can I increase the performance?" }
9785
<p>I'm new to rails. I am using Redis instead of something backed w/ ActiveRecord. I need to validate the presence of location, categories, start_date, and end_date. I then need to check that start_date and end_date are valid dates, that start_date comes before end_date. And that location matches a regex [A-Za-z_]....
[]
[ { "body": "<p>You should not validate your model in controller.\nImagine situation, where you need to create another controller, for example it will be the API controller with same logic. What you will do? Copy your code and paste?\nAnd what about unit testing? ;)</p>\n\n<p><a href=\"http://www.sitepoint.com/10...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-07T20:57:31.067", "Id": "9788", "Score": "3", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Rails and Redis: how should I handle validation here?" }
9788
<p>I tried to solve one <a href="http://www.spoj.pl/problems/PALIN/" rel="nofollow" title="problem">SPOJ problem</a>. I wrote one program in Python, however, it got accepted by the SPOJ judges, but its total execution time is 2.88s. The same algorithm used in C language having execution time 0.15s.</p> <p>Please offer...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T17:52:43.090", "Id": "15465", "Score": "0", "body": "Could you also provide the timing enviroment? Otherwise we'll have to set it up on our own, it could give different result, we're lazy, etc... etc... :)" }, { "ContentLice...
[ { "body": "<pre><code>def tempPalindrome(inputString):\n</code></pre>\n\n<p>Python convention is to name function lowercase_with_underscores. Also what is temporary about this palindrome?</p>\n\n<pre><code> \"\"\" Code for finding out temporary palindrome. used by nextPalindrome function\"\"\"\n inputList...
{ "AcceptedAnswerId": "9793", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-06T17:34:48.673", "Id": "9790", "Score": "1", "Tags": [ "python", "performance", "beginner", "programming-challenge", "palindrome" ], "Title": "The Next Palindrome - reduci...
9790
<p>I'm attempting to escape ampersands from a string before passing to PHP's <code>SimpleXMLElement-&gt;addChild()</code> for use with some SOAP webservices, but I don't want to double escape them. I'm getting these strings from a variety of sources so I can't count on them not being escaped already. <code>&amp;amp;am...
[]
[ { "body": "<p>Your code is hard to read, and a few test cases would be nice to know what this should handle. For example, do you want to allow multiple lines? Do you want to replace things that are not \"amp\", like <code>&amp;gt;</code>? Are you sure this will correctly sanitize your inputs?</p>\n\n<p>It seems...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-03-08T00:27:51.567", "Id": "9796", "Score": "2", "Tags": [ "php", "regex", "xml" ], "Title": "Escaping XML to be used with SOAP" }
9796
<p>I have the following function for validating users facebook information against the rules setup in the database for users. Its working fine but i need to know if it can be more optimized. Few things that you need to know are: </p> <ol> <li>There is a possibility that particular rule would not exists in db.</li> <li...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T09:03:38.120", "Id": "15562", "Score": "0", "body": "Hi! Thanks for your question. You're asking for a performance improvement, but you didn't say how slow it was, and where you think the issue is. \"Premature optimization is the ro...
[ { "body": "<p>The code looks OK, and what is probably going to take you time is the call to the Facebook API, which means there's no need to optimize that snippet.</p>\n\n<p>I also have two unimportant remarks:</p>\n\n<ul>\n<li>Your function either returns true/false, or redirects to another page. There is no r...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T08:32:42.823", "Id": "9803", "Score": "2", "Tags": [ "php", "codeigniter" ], "Title": "Controller method optimization" }
9803
<p>I have the following loop which uses Idiorm to write to a table from a PHP Slim application:</p> <pre><code>foreach($jobs-&gt;get_items() as $job) { echo $job-&gt;get_title().'&lt;br /&gt;'; $jobRow = ORM::for_table('jobs')-&gt;create(); $jobRow-&gt;guid = $job-&gt;get_id(TRUE); $jo...
[]
[ { "body": "<p>How exceptional is this error? What do you want to do when this happens?</p>\n\n<p>If it's rare and you don't want to do anything, then:</p>\n\n<ul>\n<li>Only catch the actual exception (maybe it's <code>PDOException</code>).</li>\n<li>Remove the <code>continue</code> which serves no purpose here ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T10:55:49.917", "Id": "9804", "Score": "1", "Tags": [ "php", "mysql" ], "Title": "Is there a cleaner way to ensure I am not writing duplicate data?" }
9804
<p>I had a requirement where I need to create object using same interface but one derived class expects simple data and other array of type. Here is solution I came up with:</p> <p>I had two questions:</p> <ol> <li>As you can see I am converting <code>IEquatable&lt;T&gt;</code> into <code>T</code>. In my testing so f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T13:21:25.383", "Id": "15583", "Score": "1", "body": "If you are building the interface, why not build always an array and check for the quantity of data?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-0...
[ { "body": "<p>I'm not completely sure what are you trying to accomplish, but I think this is bad and very confusing code.</p>\n\n<p>You seem to be using the interface <code>IEquatable&lt;T&gt;</code> to mean “<code>T</code>, or a type that has some relation to <code>T</code>”. That's not what it's meant for at ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T13:19:11.763", "Id": "9808", "Score": "1", "Tags": [ "c#" ], "Title": "Arrays, inheritance, generics" }
9808
<p>In a data processing and analysis application I have a dataCleaner class that conducts a series of functions that help me to clean raw time series data. </p> <p>One of the problems I see in my data is that they often include large gaps at the beginning and end. This is due to the occasional corruption of the timest...
[]
[ { "body": "<p>Firstly, a loopless solution (not actually tested)</p>\n\n<pre><code>big_gaps = np.diff(timestamps) &gt;= big_gap\n</code></pre>\n\n<p>As you did</p>\n\n<pre><code>front_gaps = np.logical_and.accumulate(big_gaps)\n</code></pre>\n\n<p>This produces an array which is <code>True</code> until the firs...
{ "AcceptedAnswerId": "9823", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T15:12:22.633", "Id": "9809", "Score": "0", "Tags": [ "python" ], "Title": "Pythonic data processing? Should I use an iterator?" }
9809
<p>I had a need to isolate some long-running blocking calls in a background thread of my app. I also needed to keep this thread running indefinitely, because COM would complain if some object I created in that thread were accessed from another thread. I then needed to control what these objects did from my main UI thre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T17:34:53.117", "Id": "15602", "Score": "0", "body": "Shouldn't you be using `delegate`s or `Task`s? Or even `event`s?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T18:02:13.587", "Id": "15605", ...
[ { "body": "<p>You're right, most of the time, you shouldn't use polling like this. You should instead block the thread indefinitely if there is no work and wake it up when it's needed.</p>\n\n<p>Fortunately, the same namespace that contains the <code>ConcurrentQueue&lt;T&gt;</code> you use also has the solution...
{ "AcceptedAnswerId": "9833", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T15:59:36.640", "Id": "9812", "Score": "5", "Tags": [ "c#", "multithreading" ], "Title": "Polling loop - Always a bad decision?" }
9812
<p>The code follows the requested format of the output exactly for my assignment. But, for my own personal reference, is there a better way that I could have done anything? Are there any additional tips? Maybe some simple ways that I could gold plate against exceptions or errors? I know how <code>try</code>, <code>catc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-09T00:43:25.383", "Id": "15635", "Score": "1", "body": "Use `System.out.format`." } ]
[ { "body": "<p>There is a general purpose guideline - the Single Responsibility Principle. For a given procedure/function you should be able to write a simple statement \"This code does X.\" If you find yourself writing \"This code does X and Y.\" then you should consider breaking the code up into pieces - one p...
{ "AcceptedAnswerId": "9819", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T16:25:39.833", "Id": "9814", "Score": "4", "Tags": [ "java", "homework", "finance" ], "Title": "Money class for handling calculations with coins" }
9814
<p>I am busy creating a basic php mailer script to post to _self and email to a address.</p> <p>Is the script secure?</p> <p>How can I avoid someone clicking on submit the whole time, to spam the mailbox, with minimal extra code</p> <pre><code>&lt;?php //Mail header removal function remove_headers($string) { $he...
[]
[ { "body": "<p>Your using the <strong>email</strong> sanitize filter on each field, you need to use <code>FILTER_SANITIZE_STRING</code> for the name and <code>FILTER_SANITIZE_FULL_SPECIAL_CHARS</code> for the message field.</p>\n\n<p>Sanitizing is not the same as validating...</p>\n\n<p><a href=\"http://www.php....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T19:17:48.160", "Id": "9827", "Score": "2", "Tags": [ "php", "html" ], "Title": "Creating a basic secure php mailer" }
9827
<p>I'm a fairly new programmer (just started yesterday!). I decided to tackle Project Euler #2 today, as I did #1 yesterday without many problems. I came up with what seems to me to be a working solution, but I feel like I did it in an exceedingly ugly way. Could anyone suggest improvements to my code and/or logic?</p>...
[]
[ { "body": "<p>I would use separately Fibonacci generator</p>\n\n<pre><code>def even_fib(limit):\n a, b = 0, 1\n while a &lt; limit:\n if not a % 2: \n yield a\n a, b = b, a + b\n</code></pre>\n\n<p>And <code>sum</code> function to calculate sum of items</p>\n\n<pre><code>p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T19:40:36.567", "Id": "9830", "Score": "12", "Tags": [ "python", "beginner", "project-euler", "fibonacci-sequence" ], "Title": "Python Solution for Project Euler #2 (Fibonacci ...
9830
<p>I've been trough a few css tutorials. I've also been using basic css for a while now.</p> <p>My question, How do you decide witch css to use. For instance. If you want a div box to show on the left. You can either use.</p> <pre><code>float: left; </code></pre> <p>or</p> <pre><code>position: absolute; </code></p...
[]
[ { "body": "<p>I'm afraid that there's no 'good' answer here. There are many ways to achieve a certain effect, but they are dependent on the context.</p>\n\n<p>Floated containers differ from the ones that are positioned absolutely. An absolutely positioned container is 'taken out of the layout' - that means e.g....
{ "AcceptedAnswerId": "9843", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T19:45:54.413", "Id": "9831", "Score": "1", "Tags": [ "css" ], "Title": "CSS layout basics to follow" }
9831
<p>I am creating a site that is very heavily relying on Ajax. To stop major spamming on my site, I decided to implement a PHP system that checks how many actions have been made in the last 5 minutes. I wrote this fairly quickly and I was wondering if there are any major issues with my code. Read the footnote as to why ...
[]
[ { "body": "<p>Okay, so the first thing here: prevent yourself from SQL injections. Of course you can escape your parameters but parametrized queries with PDO or so would be much better. You can also use mysqli - <a href=\"http://www.php.net/manual/de/mysqli.prepare.php\" rel=\"nofollow noreferrer\">here</a>'s a...
{ "AcceptedAnswerId": "9951", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T20:55:54.153", "Id": "9834", "Score": "1", "Tags": [ "php", "ajax" ], "Title": "PHP Action Verification" }
9834
<p>I've tried to write a simple timer class that could later be used in games, such as for updating the screen every second. Problem is, I read <code>gettimeofday()</code> was UNIX-specific and unsafe to use as well (that last one I'm not sure about). I know C has a <code>clock()</code> function, but it only has second...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T21:40:41.523", "Id": "15622", "Score": "0", "body": "Busy waits are not a good idea. `while (clock() < endwait);`. It will basically burn your CPU out as it goes to 100% utilization in a tight loop. Your timer may work for this scen...
[ { "body": "<p>It is not clear why one is multiplied by 1000 and the other divided by a thousand (nor why one is an integer and the other a double).</p>\n\n<pre><code> m_delayAmount = delayAmount * 1000; \n m_initialDelay = initialDelay/1000;\n</code></pre>\n\n<p>This just detects if the delay has been exceede...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T21:27:06.283", "Id": "9835", "Score": "2", "Tags": [ "c++", "timer" ], "Title": "Timer class for games" }
9835
<p>Let's say I want to create dynamic documentation of functions I wrote, without using the <code>help()</code> function (I don't want the user to care about arguments accepted by my function, nor get cluttered with other stuff like the copyright info, or other stuff that aren't functions). </p> <p>Here's an attempt:<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-09T09:50:12.023", "Id": "15666", "Score": "0", "body": "It's not clear how could you use this function on user defined funtions. The users are going to edit this file? Are you going to import their module? Are you forcing them to impor...
[ { "body": "<p>Use <code>for name, value in globals().items():</code> then you don't need to use <code>eval</code></p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T23:13:03.453", "Id": "9840", "ParentId...
{ "AcceptedAnswerId": "9840", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T21:47:03.683", "Id": "9837", "Score": "1", "Tags": [ "python" ], "Title": "Displaying user-defined functions and their docstrings" }
9837
<p><strong>Intention:</strong> Automatically scroll the window to the top of a DOM element when the document is loaded. </p> <hr> <p><strong>via JavaScript:</strong></p> <pre class="lang-js prettyprint-override"><code>window.onload = function(){ document.getElementById('foo').scrollIntoView(true); }; </code></p...
[]
[ { "body": "<p>Three concerns:</p>\n\n<ol>\n<li><p>Error if there is not element called 'foo'</p></li>\n<li><p>I have no idea what that boolean in the function is for. Passing booleans at parameters is very bad. I have no idea what happens if I were to pass it false or any other value. Not scroll into view? I...
{ "AcceptedAnswerId": "9845", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T23:09:14.510", "Id": "9838", "Score": "3", "Tags": [ "javascript" ], "Title": "Scroll to the top of an element when document is loaded" }
9838
<p>I wish to create a database for a webpage where users are able to add their own events to a timetable. Users will be able to decide if the events should be recurring (weekly) or not. Users should be able to query other groups of users to organize a time for a meeting. That is it.</p> <p>What I have so far is as fol...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T22:32:41.543", "Id": "15625", "Score": "2", "body": "This should probably be moved to Code Review..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T22:40:43.770", "Id": "15626", "Score": "0",...
[ { "body": "<p>From looking at your database description . . .</p>\n\n<ul>\n<li>No unique constraint on <code>Users.username</code>. You can have 1000 users named \"Fred\".</li>\n<li>No unique constraint on <code>Groups.groupname</code>. You can have 1000 groups named \"Hamburger\". You probably don't want to al...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T22:26:08.723", "Id": "9839", "Score": "1", "Tags": [ "c#", "sql", "asp.net", "sql-server" ], "Title": "Users' timetable database" }
9839
<p>Here's a messy C# method used to calculate some business logic.</p> <p>Does anybody have any suggestions on how I can optimise this code? I'm asking in case there are bad practices, improvements or functions within .NET/LINQ which I'm missing.</p> <pre><code>private static decimal GetRecurringCostEquiv(List&lt;Quo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-09T14:33:43.650", "Id": "15671", "Score": "0", "body": "It would help to know what these other methods are and what they return. `GetDiscounts()`, `GetRecurringCost()`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>There's two things that I'm seeing right off the bat.</p>\n\n<ol>\n<li><p>Don't use \"magic integers\" where you can be using Enums. <code>GetDiscounts</code> should probably receive an enum, not an int:</p>\n\n<p><code>var discVal = GetDiscounts(items, RecordEnums.ProductClassification.Service);...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-09T14:13:03.530", "Id": "9852", "Score": "2", "Tags": [ "c#", "linq" ], "Title": "Calculating business logic" }
9852
<p>Here's a trivial example:</p> <pre><code>if type(length) != int: length = 16 </code></pre> <p>as opposed to:</p> <pre><code>try: len_mod = (length + 33) / 32 + 1 except TypeError: #recover here somehow, over-ride input? len_mod = (16 + 33) / 32 + 1 </code></pre> <p>I don't need an <em>authoritati...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-09T18:15:59.450", "Id": "15689", "Score": "1", "body": "Where did length come from? You've said it was user input, but was it read from a file? raw_input? the python interpreter?" }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>Why don't you check <code>length</code> type when you get value from user input?</p>\n\n<pre><code>try:\n length = int(user_input)\nexcept (ValueError, TypeError):\n length = DEFAULT_LENGTH\n</code></pre>\n\n<p>Also, I think it's not good to compare type of variable <code>type(length) != int...
{ "AcceptedAnswerId": "9868", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-09T15:04:56.217", "Id": "9855", "Score": "0", "Tags": [ "python", "casting" ], "Title": "Over-Riding User Input" }
9855
<p>Have some code that I wrote to parse a flat file of IP address and other junk unwanted information. Just wanting to see if there was any way to make shorter or better. </p> <pre><code>#!/usr/bin/perl use strict; use warnings; #opening the access_log flat file that contains a list of ip addresses with unwanted inf...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-09T16:35:14.270", "Id": "15680", "Score": "0", "body": "Can you please put the code in the question. This way we will never loose the code that is associated with any responses." }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>You should probably close the file as soon as you are finished.<br />\nDivorcing the open() and close() makes it harder to see maintain.<br />\nMove close() to here (just after you finish using the file).</p>\n<pre><code>open (YYY, &quot;/home/access_log&quot;);\n#assigning flat file to an array\n...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-09T16:09:11.443", "Id": "9859", "Score": "3", "Tags": [ "perl" ], "Title": "parsing a flat file and removing duplicates" }
9859
<p>This is a simple sort of array. The array (in fact I used <code>ArrayList</code>) is stored in <code>default_list.txt</code> file on server, all changes to it are made using servlets.</p> <p><strong>Add.java:</strong></p> <pre><code>import java.io.BufferedReader; import java.io.File; import java.io.FileReader; imp...
[]
[ { "body": "<p>Browsed quickly and here are a few pointers</p>\n\n<p>1) Separation of Concerns (SoC). Let your view (jsp) handle the rendering, Controller (servlet) handle the flow of the application, and all your processing in another set of classes. This would be the basics of MVC. \nHere is the <a href=\"http...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-08T13:35:33.213", "Id": "9865", "Score": "2", "Tags": [ "java", "jsp", "servlets" ], "Title": "Tomcat/JSP/servlets web-project" }
9865
<p>Im starting with MVC and I'd like you to see my code. Am I doing right? What can I improve in my classes? </p> <h2>Controller</h2> <pre><code>class Logar extends Controller { private $view; private $modelDAO; function __construct() { $this-&gt;modelDAO = new LogarModel(); $this-&gt;vi...
[]
[ { "body": "<p>Yes, you understood how MVC works, and you are doing it right. The helper functions such as <code>redirect()</code> are in the correct classes. A few comments on the code itself:</p>\n\n<ol>\n<li>I'd recommend to add an <code>exit;</code> statement after sending headers in <code>redirect()</code>....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-09T21:53:19.927", "Id": "9871", "Score": "2", "Tags": [ "php" ], "Title": "Starting MVC PHP - am I doing it right?" }
9871
<p>My classmates and I were given an assignment to make a 'Paint' application (similar to Microsoft Paint).</p> <p>There is a color selection JSlider with a connected textbox to each. My code works fine, but it has some bugs in it. Whenever I draw a shape on the panel and change its color, the background of the pane...
[]
[ { "body": "<p>I ran your exact code on my computer, I'm a little confused on what your actual problem is, but if you're trying to \"clear\" the panel every time you draw a new shape the code for that would be:</p>\n\n<pre><code>public void paint(Graphics g) \n{\n g.clearRect(0,0,getWidth(),getHeight());\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T08:57:37.297", "Id": "9875", "Score": "2", "Tags": [ "java", "swing", "image" ], "Title": "Shape-drawing using JavaX Swing" }
9875
<p>I am parsing a response from server, and in case it contains the fields "chunk_number"(<code>J_ID_CHUNK_NUMBER</code>) and "total_chunk_number"(<code>J_ID_CHUNK_TOTAL</code>), I want to check whether I should request another chunk or not. Not a complicated task. Yet I doubt what would be a better way to implement?</...
[]
[ { "body": "<p>I would recommend that you use option 2, especially since you have the ability to avoid the exception (by using the has method).</p>\n\n<p>Exceptions should be used in exceptional circumstances (e.g. You might expect getInt to throw an exception if J_ID_CHUNK_TOTAL exists but does not contain a ch...
{ "AcceptedAnswerId": "9877", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T09:10:15.087", "Id": "9876", "Score": "6", "Tags": [ "java", "json" ], "Title": "Check if a value exists or catch an exception" }
9876
<p>This is a simple Python program I wrote. I hope some one could help me optimize this program. If you found any bad habits, please tell me.</p> <pre><code>#!/usr/bin/python import urllib2 def GetURLs(srcURL=""): if srcURL == "": return -1 Content = urllib2.urlopen(srcURL, None, 6) oneLine = ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T12:55:58.290", "Id": "15718", "Score": "1", "body": "For starters, dont start your method name with capital letters.Try getURLS() instead of GetURLs same goes for Content (begins with capital letter). In general class names start wi...
[ { "body": "<p>You can shorten your code by optimizing iteration over the lines. <code>urlopen()</code> returns a file-like object that allows direct iteration:</p>\n\n<pre><code>content = urllib2.urlopen(srcURL, None, 6)\nfor line in content:\n print line\n\ncontent.close()\n</code></pre>\n", "comments":...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T12:49:17.887", "Id": "9879", "Score": "8", "Tags": [ "python", "url" ], "Title": "Function for getting URLs" }
9879
<p>I'm new to C++ and decided to have a go at the spotify challenges on their website, <a href="http://www.spotify.com/uk/jobs/tech/best-before/">http://www.spotify.com/uk/jobs/tech/best-before/</a></p> <p>I have now finished but I get the feeling my code is just terrible, I'm guessing it would be very hard for someon...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T17:26:16.373", "Id": "15725", "Score": "2", "body": "Proper indentation would be nice!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T17:30:54.603", "Id": "15727", "Score": "0", "body": "...
[ { "body": "<p>Here is my incomplete answer, this will tell you is you date is valid in any way but won't currently handle 2 figure years, it will print out all of the combinations not just the lowest, but the lowest will be the first. (note mine uses the British date format because it is the best :D, it is triv...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T15:55:56.863", "Id": "9883", "Score": "10", "Tags": [ "c++" ], "Title": "Best Before puzzle" }
9883
<p>I have the following jQuery plugin that binds touch events and moves an element.</p> <p>In the functions <code>moveMe</code> and <code>snap</code>, there is duplicate code doing the same thing because I couldn't figure out how to refactor the scope of the functions to only do this once.</p> <pre><code>$.fn.draggab...
[]
[ { "body": "<p>Could you write something like this?</p>\n\n<pre><code>var limited = function( value, limit ){\n if (value &gt;= limit) { \n return limit; \n } else if (value &lt;= 0) { \n return 0; \n } else { \n return value; \n } \n}\n</code></pre>\n\n<p>then, when you need to ...
{ "AcceptedAnswerId": "9897", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T17:18:29.507", "Id": "9885", "Score": "0", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "Binding touch events and moving an element" }
9885
<p>Can anyone help me improve my <code>instr()</code> function?</p> <pre><code>int myInstr(wchar_t *str, wchar_t c, int start, int dir){ int pos = 0, result = 0, len; wchar_t *p1; //Left if(dir == 0) { p1 = str; len = lstrlen(str); while(pos &lt; len) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T20:39:14.580", "Id": "15739", "Score": "1", "body": "What is start for?" } ]
[ { "body": "<pre><code>int myInstr(wchar_t *str, wchar_t c, int start, int dir){\nint pos = 0, result = 0, len;\nwchar_t *p1;\n</code></pre>\n\n<p>Names like p1 are best avoided. Its hard to guess what p1 might be for.</p>\n\n<pre><code>//Left\nif(dir == 0)\n{\n p1 = str;\n len = lstrlen(str);\n while(p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T19:00:25.717", "Id": "9888", "Score": "1", "Tags": [ "c", "strings" ], "Title": "Finding one string located in another" }
9888
<p>I have been learning PHP and wanted to see if I could make a very simple slot machine game. Everything works, but I'm sure this is not the best way to do this. Please let me know how you would do this and what I can do to improve.</p> <pre><code>&lt;?php $num1 = rand(1, 5); $num2 = rand(1, 5); $num3 = rand(1, 5);...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T19:13:37.107", "Id": "15732", "Score": "0", "body": "Bah: you deleted your question on Stack Overflow whilst I was writing out my answer, so I had to create an account here so as not to waste it! Once a question is asked, it is good...
[ { "body": "<p>Looks good. Few initial things:</p>\n\n<ul>\n<li>Indent inside control structures, so everything inside your <code>if()</code> statement would be prefixed by one tab. (You can use a fixed number of spaces, but that can cause problems if you share your code with people who use a different tab-spaci...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T19:02:57.537", "Id": "9889", "Score": "2", "Tags": [ "php", "beginner", "game" ], "Title": "Basic slot machine game" }
9889
<p>I use DMD 1.056 with Tango 0.99.9 to build a GPX document using API. I am a beginner in D language.</p> <hr> <p>Usage DMD 1.056 with Tango 0.99.9 is compulsory as a requirement</p> <p>The GPX data are here hardcoded but my intent is to write a more high level GPX builder code using appropriate API.</p> <hr> <p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-13T04:18:23.243", "Id": "15842", "Score": "1", "body": "why are you building this XML file in D, rather then loading it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-13T09:10:01.713", "Id": "15849", ...
[ { "body": "<p>Store this data in an XML file and parse it using <a href=\"http://dlang.org/phobos/std_xml.html\" rel=\"nofollow\">std.xml</a>.</p>\n\n<p>Tango also has had an <a href=\"http://www.dsource.org/projects/tango/wiki/TutXmlPath\" rel=\"nofollow\">XML parser</a> for years which is <a href=\"http://do...
{ "AcceptedAnswerId": "9927", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-11T06:35:09.403", "Id": "9898", "Score": "0", "Tags": [ "d" ], "Title": "How code be this piece of code be refactored?" }
9898
<p>I'm looking for a review of my macros. I have these in the project pre-compile header. I tent to copy them into all my new projects as well, unless its a very simple project.</p> <pre><code>#ifdef __APPLE__ #import &lt;TargetConditionals.h&gt; #endif // turn on or off different types of logging. ALog() is alw...
[]
[ { "body": "<p>One comment: don't define / undefine the flags that switch logging on or off in the file. That stops you from defining them on the compiler command line. The way you have things now, if you want to make a release build (with no debug logging at all), you have to change the source code.</p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-11T11:18:21.603", "Id": "9899", "Score": "2", "Tags": [ "objective-c", "macros" ], "Title": "Objective-C debug macros" }
9899
<p>I have a <code>Queue</code> class that is basically a single linked list. It has 2 remove methods. What would be the cleanest way to avoid duplication of the code? Only the comparisons in methods are different.</p> <pre><code>int Queue::remove(const string&amp; substring) { // Loop through the queue list si...
[]
[ { "body": "<p>You can abstract out the thing that changes, the comparison expression, into a predicate for a template function.</p>\n\n<pre><code>class PriorityMatch\n{\n int priority_;\npublic:\n explicit PriorityMatch(int priority)\n : priority_(priority) {}\n\n bool operator()(const Job&amp; ...
{ "AcceptedAnswerId": "9901", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-11T13:05:04.420", "Id": "9900", "Score": "8", "Tags": [ "c++", "queue" ], "Title": "Singly linked list queue class" }
9900
<p>I made this little library for personal use to make javascripting faster and easier. I would like to know if there are any inefficiencies in it (in size and performance) and possibly if there is a feature you think is missing that would be useful.</p> <pre><code>//PUT ALL CODE AT THE END OF THE PAGE!!!!!! THIS IS U...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T00:00:09.630", "Id": "15759", "Score": "1", "body": "1) There shouldn't be a requirement to load it at the end of the body. What if you want to use it before then? 2) The whitespace is really ugly, maybe run it through a linter or b...
[ { "body": "<p>Problems with it : </p>\n\n<ul>\n<li>in the global namespace</li>\n<li>use of innerHTML</li>\n<li>no cross-compatibility </li>\n<li>messing with object prototypes</li>\n<li>quite useless</li>\n</ul>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-11T23:48:35.113", "Id": "9902", "Score": "1", "Tags": [ "javascript", "optimization", "library" ], "Title": "Any criticism on my JavaScript micro-library?" }
9902
<p>I would like any advice on how to improve this code. To clarify what this code considers an intersection to be, the intersection of [3,3,4,6,7] and [3,3,3,6,7] is [3,6,7]. I would appreciate any improvements to make the code more readable or perform faster.</p> <pre><code>public ArrayList&lt;Integer&gt; findIt (int...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T10:26:44.887", "Id": "15783", "Score": "1", "body": "Examples of given arrays are already sorted. Are all given arrays sorted? If result ArrayList can not contain duplicate elements, maybe Set would be better?" }, { "Content...
[ { "body": "<h2>Algorithm</h2>\n\n<p>You're using a O(n log(n)) algorithm here, which could be O(n²) for difficult cases since <code>contains()</code> is O(n) and is called in a loop. Instead, use the property of <code>HashSet</code>: access is O(1), which means you can achieve this in O(n) time. My algorithm be...
{ "AcceptedAnswerId": "9911", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T10:01:16.913", "Id": "9909", "Score": "7", "Tags": [ "java", "optimization", "array" ], "Title": "Finding the Intersection of Arrays" }
9909
<p>This <code>HostResolve</code> procedure runs on a thread separately, to not interrupt other working functions. I would like to ask here if this procedure is correctly written or not?</p> <p>Any recommendations and improvements, if any one willing to help?</p> <pre><code>Procedure HostResolve(); const URL : ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-02-19T08:12:24.370", "Id": "147380", "Score": "0", "body": "@Greenonline do not edit code unless you are sure this is due to copy and paste errors." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-02-19T08:15:33.1...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T11:24:08.050", "Id": "9912", "Score": "1", "Tags": [ "delphi" ], "Title": "Internet Connectivty and Resolve host" }
9912
<p>I'm new To C++ and decided to have a go at the <a href="https://labs.spotify.com/puzzles/" rel="nofollow">Spotify challenges</a> on their website.</p> <p>I have now finished but I get the feeling my code is just terrible. I'm guessing it would be very hard for someone else to read and I feel like there are much bet...
[]
[ { "body": "<ol>\n<li><p>You should avoid using global variables. If you import this code into a future project it might cause problems -- name conflicts etc.</p>\n\n<p>If you must do this, put them in an anonymous namespace so that they're only in scope for this file:</p>\n\n<pre><code>namespace\n{\n int my;...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T15:43:47.167", "Id": "9915", "Score": "6", "Tags": [ "c++", "beginner", "parsing", "programming-challenge", "datetime" ], "Title": "\"Best before\" puzzle" }
9915
<p>I'm new to AJAX and am trying to learn by myself with a small test:</p> <p>It's a survey with 3 questions. I would like to know if I'm using AJAX the correct way, before starting bigger projects.</p> <p>Here is the question.xhtml page:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version='1.0'...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T19:33:29.787", "Id": "15787", "Score": "1", "body": "Your code looks fine. Nothing to complain about. Just a minor comment on your backing bean code: I would always use brackets for if/else constructs, even if there is only on comma...
[ { "body": "<ol>\n<li><pre><code>@ApplicationScoped\npublic class GeneralController {\n ...\n}\n</code></pre>\n\n<p>I think your bean should be <code>@SessionScoped</code> instead of <code>@ApplicationScoped</code>. Otherwise all of you clients will use the same controller instance.</p></li>\n<li><p>Instead o...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-10T18:32:12.040", "Id": "9916", "Score": "5", "Tags": [ "java", "beginner", "xml", "ajax", "jsf" ], "Title": "Survey program using JSF and Ajax" }
9916
<p>How can this be optimized?</p> <pre><code>char *crunch(char *s) { char *temp,buff[MAX]; int repeat,count,i,j,k; if (*s == '\0') return NULL; temp = (char*)malloc((strlen(s) + 1) * sizeof(char)); if (isdigit(*s)) return NULL; repeat = 0; for (i = 0, j = 0;i &lt; strlen(s);) { temp[j++] =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T13:20:34.423", "Id": "15789", "Score": "0", "body": "You have to be way more specific about your \"string crunching\" algorithm" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T13:21:27.107", "Id":...
[ { "body": "<p>Suggestions for improving this code:</p>\n\n<ol>\n<li><p>Comment the hell out of it. Your teacher/professor needs to be able to understand what you're doing and why you're doing it. Imagine you're working on a real-world project and you fall off a cliff--your teammates need to be able to pick up a...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T13:18:08.980", "Id": "9920", "Score": "2", "Tags": [ "c", "strings", "homework" ], "Title": "String-crunching routine" }
9920
<p>I need to receive an XML post then process all the data, and do whatever I need to do with the data. I could be receiving anywhere from 60 to 100 values. I know what all the elements are going to be, and all except one is mandatory. For billing, it could either be credit card info or checking info, so I need to chec...
[]
[ { "body": "<p>If your main goal is to verify the document structure, you may try using an XSD. Once you have a schema doc defined, <a href=\"http://msdn.microsoft.com/en-us/library/bb387037.aspx\" rel=\"nofollow\">you can use some LINQ to XML extensions to perform the validation and get the error messages (if ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T16:24:07.037", "Id": "9930", "Score": "1", "Tags": [ "c#", "validation", "xml" ], "Title": "Receiving an XML post and parsing" }
9930
<p>I would like to be able to use it with IE8 or earlier, so I'm staying away from newer array methods. I'm not an expert so my code may not be the most efficient choice, but it works.</p> <pre><code>var data = [ ["John", 2], ["Jenny", 3], ["John", 4], ["Beavis", 5]] var newarr = [["John",5]]; for (var x=0; x &lt; d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T19:13:04.580", "Id": "15814", "Score": "1", "body": "About your \"stay away from newer array methods\", have you considered [ES5-Shim](https://github.com/kriskowal/es5-shim)?" }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>Some general advice: </p>\n\n<ul>\n<li>You should use a function, even in this demonstration code. It's makes it clearer what the input and output are.</li>\n<li>You should chose better variable names. <code>newarr</code> doesn't make sense, since it's not \"new\" but pre-filled. And <code>x</code...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T16:55:34.800", "Id": "9931", "Score": "2", "Tags": [ "javascript" ], "Title": "JavaScript - Comparing 2 arrays - Would like to check if I'm reinventing the wheel or am I good to go?" }
9931
<p>We are generating our data access code following this pattern: </p> <pre><code>public static IEnumerable&lt;SomeDataOutputDTO&gt; GetSomeData(SomeDataInputDTO dto, IDbConnection dbConnection) { var queryString = @"Some SQL query"; using (var command = (OracleCommand)dbConnection.CreateCommand()) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T18:10:37.577", "Id": "15813", "Score": "0", "body": "It seems your code is badly indented, `try` doesn't match with `finally`." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-06-30T13:02:17.877", "Id": ...
[ { "body": "<p>Initially, I shared your concern over resource disposal. My assumption was that there was the possibility the command could be left hanging around in cases where you did not enumerate over the entire collection (as with something like FirstOrDefault).</p>\n\n<p>However, a few quick tests with a t...
{ "AcceptedAnswerId": "9935", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-12T16:55:04.497", "Id": "9933", "Score": "1", "Tags": [ "c#" ], "Title": "Please critique my Enumerable DataReader with yield and log data access pattern" }
9933