body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Help me review this code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;cassert&gt; using namespace std; template &lt;typename T&gt; class auto_ptr { public: explicit auto_ptr(T* p = NULL):m_p(p){} auto_ptr(auto_ptr&amp; other); auto_ptr&amp; operator=(auto_ptr&amp; other); T* get() const {...
[]
[ { "body": "<p>I presume you are aware of all the standard issues with <code>auto_ptr</code>, and that C++11 fixes by far most of them. I'm thus going to assume you have no C++11 support; if that's not the case, most of this doesn't apply because the whole thing should be rewritten with different semantics.</p>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T13:47:42.220", "Id": "29734", "Score": "5", "Tags": [ "c++", "pointers" ], "Title": "I wrote a class to implement auto_ptr" }
29734
<p>As a part of learning Haskell, I've implemented an AVL tree. As of now, I've only implemented insertion.</p> <p>I've compared its performance to a Java implementation I've picked at random (<a href="http://github.com/justinethier/AVL-Tree/blob/master/AvlTree.java" rel="nofollow">www.github.com/justinethier/AVL-Tre...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T14:28:37.527", "Id": "29738", "Score": "2", "Tags": [ "optimization", "performance", "haskell" ], "Title": "Optimizing AVL tree" }
29738
<p>If this question should be on stackoverflow instead, please point it out. I'll put it up there.</p> <pre><code> struct { FILE * fd; hdr_t file_header; body_t file_body; } fileinfo; </code></pre> <p>The above is an approximate recreation of a structure that I have in my code. There is a separate ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T15:26:03.940", "Id": "47062", "Score": "1", "body": "You must not call `free` on the `hdr_t` or `body_t` fields - they are part of the structure and were not allocated individually. The `FILE` pointer should be compared with `...fd ...
[ { "body": "<p>The basic logic is that you only free dynamically allocated resources. Those that were created with malloc.</p>\n\n<p>Hdr_t and body_t are automatically allocated and must therefore not be freed.</p>\n\n<p>The most important point is that you might under no circumstances free a pointer without che...
{ "AcceptedAnswerId": "29749", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T14:52:58.870", "Id": "29740", "Score": "2", "Tags": [ "c", "memory-management" ], "Title": "Freeing allocated memory: am I missing something?" }
29740
<p>I occasional write simple yet long Python scripts using Sqlite3 (I'm not proficient with functional or object oriented programming... yet)</p> <p>Usually my Sqlite3 is blazing fast. I'm used to looping through lists of <code>SELECT</code> statements with each <code>SELECT</code> taking a split second, and writing ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2019-11-27T08:06:04.437", "Id": "455367", "Score": "3", "body": "The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for the title to simply stat...
[ { "body": "<p>LEFT JOINS are not inherently slow. It really depends on how you set it up. Are there any indexes on b.Assetnum? Having an index on that would probably speed up your joins tremendously. It probably is doing a full table scan on the join right now if you don't have any indexes.</p>\n", "comment...
{ "AcceptedAnswerId": "29752", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-08-14T17:06:28.073", "Id": "29751", "Score": "2", "Tags": [ "python", "sqlite" ], "Title": "Improving SQLITE3 Left Join Performance" }
29751
<p>I'm finding it a bit tedious to write unit tests for my collision class because there are so many variations of collisions that need testing. I see repetition in the set-up and assertion stages of each test, but I don't see how I can reduce the repetition whilst keeping the code clear and concise.</p> <pre><code>p...
[]
[ { "body": "<p>I don't know what's best practice, but you could set up the needed Rectangles/Positions/expected Intersections in the setup method, so that the tests itselfs are shorter and faster to understand. </p>\n\n<p>I wrote some intersection unit tests myself the last weeks, i know that sometime you'll get...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T17:33:49.990", "Id": "29754", "Score": "1", "Tags": [ "unit-testing", "collision", "actionscript-3" ], "Title": "Unit tests for collisions" }
29754
<p>I had to calculate the difference between Chicago Board of Trade grain futures prices using VB.net and came up with the following (admittedly clunky) solution. It's a <em>little</em> tricky because CBOT prices, as posted, mix octal and decimal numbers. Anyway, here is my code for you to enjoy and tear apart:</p> ...
[]
[ { "body": "<p>The following will shorten your code considerably:</p>\n\n<pre><code>Public Function GrainSubtraction(ByVal numberOne As Double, ByVal numberTwo As Double) As Double\n Dim Dec1 As Integer = CInt(Int(numberOne / 10.0))\n Dim Oct1 As Integer = CInt(numberOne - (Dec1 * 10))\n Dim Dec2 As Int...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T15:12:28.967", "Id": "29755", "Score": "3", "Tags": [ "vb.net" ], "Title": "How To Subtract CBOT Grain Prices" }
29755
<p>I know this is not very good. I am currently in my first programming class (Java). It seems like it works, but I am sure there are things I have not thought of.</p> <p>The goal is to have a user enter</p> <ul> <li>the number of credit units each class they need to take is worth, one by one</li> <li>the number of ...
[]
[ { "body": "<p>I have been teaching Java to new students for some years, and I have seen a lot of beginner Java code. For a complete beginner, your code isn't horrible -- and that's high praise! For example, your variable naming is fairly decent, especially for a beginner. (But <code>cu</code> isn't a good name....
{ "AcceptedAnswerId": "29761", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T17:58:53.350", "Id": "29757", "Score": "6", "Tags": [ "java", "beginner" ], "Title": "Graduation planner" }
29757
<p>I like the fact that I can create a class and have the connection details in one file if I need to update them and then pass them to the method I create in the class that defines my specific use of mysqli. I was thinking also that I may give an option to pass the connection details if I need to use a different db in...
[]
[ { "body": "<p><em>Note: this post gets extremely side tracked, but the two ideas are pretty closely related, so hopefully my rambling ends up being helpful.</em></p>\n\n<p><code>new</code> in a constructor is an anti-pattern. It immediately creates very high coupling, and it murders any form of coding to interf...
{ "AcceptedAnswerId": "29779", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T20:16:49.323", "Id": "29763", "Score": "1", "Tags": [ "php", "object-oriented", "constructor" ], "Title": "__constructor mysqli variable options" }
29763
<p>How can I optimize the following class?</p> <p><code>prepareSharing</code> packs bits on left and <code>prepareMask</code> counts the required bits for encoding integers between zero and max. </p> <pre><code>public class KeyFactory { public static short[] prepareSharing( short[] sharing, int mask ) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T14:12:16.310", "Id": "47277", "Score": "0", "body": "What's wrong with good old `BitSet`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T15:24:03.657", "Id": "47288", "Score": "0", "body"...
[ { "body": "<p>The very first thing I miss, in both your question and the code, is a description of what it does. You should make a habit out of <a href=\"http://en.wikipedia.org/wiki/Javadoc\" rel=\"nofollow\">documenting your code with JavaDoc</a>. After some time it will go easy while writing code and will im...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T21:17:39.453", "Id": "29764", "Score": "5", "Tags": [ "java", "bitwise" ], "Title": "Playing with bits using Java" }
29764
<p>I'm using Twitter Bootstrap. I haven't coded anything significant web design related in a while, because I've been doing desktop stuff and games. I'm trying to get back into the flow of things. Can anyone tell me if what I have is sufficient without going into ridiculous detail (the script, not the answer)?</p> <p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T00:43:27.003", "Id": "47121", "Score": "0", "body": "I haven't done anything with PHP in a while but it's good that you are using prepared statements. Are you doing any parameter checking/sanitizing anywhere?" }, { "ContentL...
[ { "body": "<p>If you plan on putting this out in the wild (the web), I suggest you handle your <strong>error feedback a little more user friendly</strong>. If this is for your home server and you'll be the only one using it, it's fine. But displaying binding or executing errors definitely helps attackers get an...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T21:57:02.160", "Id": "29766", "Score": "3", "Tags": [ "javascript", "php", "html", "ajax", "twitter-bootstrap" ], "Title": "Simple AJAX login/register script" }
29766
<p>This was my first attempt at writing object-oriented JavaScript. It's a Minesweeper clone in jQuery. I thought I had done an OK job, but I've just received some feedback stating that it wasn't written in an object-oriented manner. I don't expect anyone to read this line for line. I'm just looking for general feedba...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T00:55:53.403", "Id": "47122", "Score": "0", "body": "Your entire program is pretty much in one function, try separating it into objects and methods. Also the usage of `self` is confusing, the language already has the perfectly fine ...
[ { "body": "<p>As @Esailija has said in the comments, OOP is about, well, <em>objects</em>.</p>\n\n<p><strong>Before you write any code</strong>, you should stop and think - what are the key concepts at play here? This is a <em>Minesweeper</em> implementation, so the very first thing you should do is lay down al...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T00:32:59.823", "Id": "29771", "Score": "3", "Tags": [ "javascript", "jquery", "beginner", "game", "minesweeper" ], "Title": "Minesweeper clone in jQuery" }
29771
<p>I wrote this as an academic exercise over on CA. It is supposed to tell a true story about two drag racers, one in his 80's who beat a young world champion in cars that traverse a 1/4 mile in 3 seconds at 300 mph. It is structured to let the old man win every time because it is based on a true story. I did it mai...
[]
[ { "body": "<p>Code-wise:</p>\n\n<pre><code>var comedy;\ncomedy = function(){...};\ncomedy();\n</code></pre>\n\n<p>The first two lines can be simplified into <code>var comedy = function(){...}</code>. If you don't need the function to be anonymous, you can even use <code>function comedy(){...};</code>. If this i...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T03:43:46.423", "Id": "29773", "Score": "7", "Tags": [ "javascript" ], "Title": "True story about two drag racers" }
29773
<p>I've just started learning HTML and CSS. Currently I'm creating a test site to practice with.</p> <p>I'm just after an early idea if the principles I'm using are correct. The below is an snippet from the main body of my HTML code. It's just about positioning text and images on a grid at the moment. I seem to be usi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T17:09:22.550", "Id": "47173", "Score": "1", "body": "Validating your code should be your first step if you want to do things the \"right\" way (ie. you are mising a semicolon for your HTML entities, which the validator would have ca...
[ { "body": "<p>You should get into a habit of adding the protocol to your anchors, as it can sometimes lead to confusing effects, such as in this case:</p>\n\n<pre><code>&lt;a href=\"www.website.com\"&gt;Website!&lt;/a&gt;\n</code></pre>\n\n<p>Let's say, the site where that code is on is called <a href=\"http://...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T07:59:43.560", "Id": "29777", "Score": "5", "Tags": [ "html", "css", "html5" ], "Title": "Positioning text and images on a site grid" }
29777
<p>I have some Java like this:</p> <pre><code>if (!fooclass.getInfoText().equals("")) { this.setInfoText(fooclass.getInfoText()); } </code></pre> <p>Is there a neater way of setting one value based on the test results of another value? It seems nasty to me that the method is run twice, but putting the result in a...
[]
[ { "body": "<p>I believe <code>fooclass</code> is a reference of <code>Foo</code> class. I can only think about introducing a variable and check it to prevent the double-invokation of same method.</p>\n\n<pre><code>String fooInfo = fooclass.getInfoText();\nif (!\"\".equals(fooInfo))\n{\n this.setInfoText(fooI...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T08:48:51.933", "Id": "29780", "Score": "1", "Tags": [ "java", "php" ], "Title": "How to use the value of a method result based on a test?" }
29780
<p>Is anything what could I improve on my code?</p> <pre><code>import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; public class Helper { public static Map&lt;User, BigDecimal&gt; createPlayersScoreMap(List&lt;...
[]
[ { "body": "<p><code>Helper</code> is not a good class name. You should be able to come up with something that provides more context to what the functions are doing.</p>\n\n<p>In <code>getPlayers()</code>, I would loop and add instead of adding all and then removing.</p>\n\n<pre><code>private static List&lt;User...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T12:19:50.037", "Id": "29783", "Score": "2", "Tags": [ "java" ], "Title": "Collating users and their scores" }
29783
<p>I am new to C and have written this code just to teach myself how to work with linked lists and was hoping someone could review it and give me any comments or tips for efficiency, etc. The code just creates a list, adds and removes nodes from the list, and can reverse the list.</p> <pre><code>/* Creates a linked li...
[]
[ { "body": "<p>I would suggest you run this program through <code>valgrind</code>. Looks like you are leaking memory without any frees for the mallocs.</p>\n\n<p><strong>EDIT: (In regards to calling a function from another file)</strong>\nTo call a function from another file (say foo.c) you separate your linked ...
{ "AcceptedAnswerId": "29795", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T12:50:53.377", "Id": "29784", "Score": "2", "Tags": [ "beginner", "c", "linked-list" ], "Title": "Reversing a linked list and adding/removing nodes" }
29784
<p>I have a process that reads multiple sheets from an Excel file, then inserts the data into a database table. However, I am experiencing some memory issues when one of the sheets contains more than 65536 rows and am looking for ideas on how to improve the code.</p> <p>In summary, I am using <code>cfspreadsheet</code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T14:50:44.883", "Id": "47148", "Score": "0", "body": "For those who didn't see it, here was the original question on SO: http://stackoverflow.com/questions/18246447/reading-excel-93-97-sheet-with-more-than-65536-rows-using-cfspreadsh...
[ { "body": "<p>This is in a function, but you haven't given us the complete function. How's your var scoping? Maybe update your code to show us all the function.</p>\n\n<p>You don't need to use the octothorpes in most cfset statements like this:</p>\n\n<pre><code>&lt;cfset count1 =#Query1.recordcount#&gt;\n</c...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T14:15:03.103", "Id": "29790", "Score": "2", "Tags": [ "sql", "excel", "coldfusion", "cfml" ], "Title": "Reading Excel (93-97) sheet with more than 65536 rows using cfspreadshe...
29790
<p>I have a console application that basically retrieves XML content, writes to the XML file and sends the file to an SFTP site:</p> <pre><code>public Main(string[] args) { try { //code to parse arguments to load into DTO to extract stored proc and report name List&lt;ReportInfo&gt; reports = Parse(args); f...
[]
[ { "body": "<p>I would start by looking at functional decomposition. Here's crack #1 at it:</p>\n\n<pre><code>internal static class Solid\n{\n private static readonly XmlWriterSettings settings = new XmlWriterSettings\n {\n OmitXmlDeclaration = false,\n ConformanceLevel = ConformanceLevel.Doc...
{ "AcceptedAnswerId": "29801", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T14:24:21.373", "Id": "29791", "Score": "4", "Tags": [ "c#", "xml", "error-handling", "network-file-transfer", "ssh" ], "Title": "Sending an XML file to an SFTP site" }
29791
<p>I have been working on a Magento module for sometime now (not because it is a large module, it's my first and I really struggled with it). I now have it working, which I was really pleased with at first, but now I would like to improve it by increasing the reusability of the code.</p> <p>While making my module I ha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T08:11:06.497", "Id": "47229", "Score": "0", "body": "I'm not familiar with Magento. Is there no Form component that encapsulate all the form-request-validation-stuff? Just as a example not a recommendation [Synfony Forms](http://sym...
[ { "body": "<p>First, I would apply self-encapsulation by changing:</p>\n\n<pre><code>$this-&gt;_salutation = $this-&gt;getRequest()-&gt;getPost('salutation');\n</code></pre>\n\n<p>to:</p>\n\n<pre><code>$this-&gt;set_salutation( $this-&gt;get_parameter( \"salutation\" ) );\n</code></pre>\n\n<p>Since PHP can call...
{ "AcceptedAnswerId": "36365", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T14:41:13.483", "Id": "29792", "Score": "1", "Tags": [ "php" ], "Title": "Retrieving user details from a custom form" }
29792
<p>I've created a form that gathers and submits information to SQL database via LINQ, and sends an email if all goes while saving the database and doing a redirect. Recently, it started submitting data and calling errors (thread aborts) within the submit function, which seemed unusual. I solved it by using Boolean flag...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T17:22:04.103", "Id": "47178", "Score": "0", "body": "I don't see `transError` used anywhere; it's set once but not evaluated. Regarding `dberror`, is there any reason you can't catch different exceptions within `FormSubmit()` rathe...
[ { "body": "<p>Is there any reason you can't do it the easy way?</p>\n\n<pre><code>protected void FormSubmit(object sender, EventArgs e)\n {\n Page.Validate();\n if (!Page.IsValid)\n return;\n\n try\n {\n CreateEntry();\n SendAdminMail(\"email@email.com\", txtFirstName.Tex...
{ "AcceptedAnswerId": "29806", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T14:56:31.483", "Id": "29794", "Score": "3", "Tags": [ "c#", "html", "asp.net" ], "Title": "In need of some aid in regards to making my code more efficient" }
29794
<p>What can be done better in this code? I am sure it's not missing much.</p> <p>You can copy and paste the whole thing in LinqPad; it's all there.</p> <pre><code>public interface IRep&lt;T&gt; { List&lt;T&gt; GetAll(); } public interface IEntity { int Id{get;set;} } public class Customer: IEntity { pu...
[]
[ { "body": "<p>To get it to work, use <code>IEnumerable&lt;T&gt;</code> instead of <code>List&lt;T&gt;</code> as it's covariant:</p>\n\n<pre><code>public interface IRep&lt;out T&gt;\n{\n IEnumerable&lt;T&gt; GetAll();\n}\n\npublic interface IEntity\n{\n int Id { get; set; }\n}\n\npublic class Customer: IEn...
{ "AcceptedAnswerId": "29798", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T15:14:38.510", "Id": "29796", "Score": "1", "Tags": [ "c#", "interface" ], "Title": "Proper implementation of generic repository" }
29796
<p>This is some C code I have to simply test the internet connection. Any comments/tips on efficiency and refactoring this program down would be greatly appreciated.</p> <pre><code>int testConnection(void) { int status; struct addrinfo host_info; struct addrinfo *host_info_list; memset(&amp;host_info,...
[]
[ { "body": "<p>Some comments, mostly minor:</p>\n\n<p>I would extract the \nserver connection to a function:</p>\n\n<pre><code>static int connect_server(const struct addrinfo *host_info)\n{\n struct addrinfo *host_info_list;\n int fd = -1;\n int status = getaddrinfo(...);\n while(...) {\n fd =...
{ "AcceptedAnswerId": "29820", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T18:47:03.680", "Id": "29805", "Score": "6", "Tags": [ "performance", "c" ], "Title": "Review internet connection pinging method" }
29805
<p>I've been working a lot recently with SerialPort in C# and I've come up with the following class as part of a class library I'm working on for another program. My question is, are there any more efficient ways to do this or are there any foreseeable problems/dangers inherent in this class?</p> <pre><code>using Syst...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T06:45:55.977", "Id": "47223", "Score": "0", "body": "What are you trying to achieve by calling `test += serialPort.ReadLine();` ? What do you expect to recieve from serial port?" }, { "ContentLicense": "CC BY-SA 3.0", "C...
[ { "body": "<p>Since your object owns a resource (<code>SerialPort</code>) which implements the <code>IDisposable</code> interface, your class must also implement it. Also, for repeated string concatenations, the <code>StringBuilder</code> class gives much better performance. I've cleaned up a bit and came up wi...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T18:47:56.993", "Id": "29807", "Score": "10", "Tags": [ "c#", "serial-port" ], "Title": "SerialPort class for a library" }
29807
<p>In order to separate my views (markup) and code, I elected to write my views like this:</p> <pre><code> &lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;%PAGE_TITLE%&lt;/title&gt; &lt;meta charset="UTF-8"&gt; &lt;link href='PotatoDocs/views/stylesheets/docs2013.css' ty...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T19:33:13.527", "Id": "47191", "Score": "0", "body": "This is a sensible way to render pages, but why not use [Twig](http://twig.sensiolabs.org/), or [Smarty](http://www.smarty.net/), or even [Savant](http://phpsavant.com/)?" }, ...
[ { "body": "<p>According your comment you don't want to use a template engine, but are actually creating a new one. At some point you will need loops or ifs and it starts becoming ugly.</p>\n\n<p>PHP is already a template engine. Actually it was designed for exactly this purpose. There is a <a href=\"http://php....
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T18:50:53.430", "Id": "29808", "Score": "1", "Tags": [ "php", "html" ], "Title": "HTML Templates with Substitutable Areas - PHP" }
29808
<pre><code>//AMOUNT CALCULATOR var totalAmount = 0; var serviceAmount = 0; jQuery('.select-service').click(function(){ var serviceAmount = parseInt(jQuery(this).parent().html().replace(/\D/g,'')); if(jQuery(this).is('.selected')){ jQuery(this).removeClass('selected'); to...
[]
[ { "body": "<p><strong>Security:</strong></p>\n\n<p>If you want to check amounts securely, don't do it in the browser alone: you need a server-side validation (e.g. with PHP if it is your language of choice).</p>\n\n<p><strong>Efficiency:</strong></p>\n\n<ol>\n<li>You can use <code>$('...')</code> instead of <co...
{ "AcceptedAnswerId": "29831", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T19:26:36.137", "Id": "29812", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "jQuery security and efficiency simple calculation code" }
29812
<p>I'm working on a C library which attempts to bring some of the Python string functions over to C.</p> <p><a href="https://github.com/shrimpboyho/octo" rel="nofollow">This</a> is where my full source is located, but the majority of what I have so far is here.</p> <p>Are there any places where code efficiency can be...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T20:30:17.480", "Id": "47197", "Score": "2", "body": "It is not a header file so your multiple-inclusion barrier is unnecessary (`#ifndef OCTO_H` etc)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T04...
[ { "body": "<p>Well efficiency can be improved by using the built-in string functions.<br>\nThey have been optimized at the assembly level for most implementations.</p>\n\n<p>Assuming you were writing len() in C rather than using some optimal assemble instructions. The canonical form looks more like this (though...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T19:45:53.667", "Id": "29815", "Score": "7", "Tags": [ "optimization", "c", "strings", "library" ], "Title": "C string library inspired by Python string functions" }
29815
<p>I'm currently taking an algorithm course in college. To find the maximum and minimum elements in an array, I'm using a <a href="http://en.wikipedia.org/wiki/Divide_and_conquer_algorithm" rel="nofollow">divide and conquer</a> algorithm. Please offer suggestions for this code snippet. I get a headache reading only co...
[]
[ { "body": "<ul>\n<li><p><code>size_t</code> is preferred over <code>int</code> for array indices and sizes (in general) because they cannot be negative. This also ensures you the highest possible numerical range.</p></li>\n<li><p>You're correct: <code>tempmax</code> and <code>tempmin</code> shouldn't be global...
{ "AcceptedAnswerId": "29825", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T20:28:12.910", "Id": "29821", "Score": "5", "Tags": [ "algorithm", "c", "divide-and-conquer" ], "Title": "Maxmin algorithm implementation" }
29821
<p>Trying to learn FRP and Elm. Is the program below "ok" from the perspective of FRP and Elm? What could be improved? The program can be executed here: <a href="http://elm-lang.org/try">http://elm-lang.org/try</a></p> <pre><code>import Random import Mouse data Fruit = Apple | Orange | Banana | Melon | Guava rand = Ra...
[]
[ { "body": "<p>Two months late, but I will try to answer nevertheless. ;-)</p>\n\n<p>Since your <code>rand</code> already makes sure the numbers will be valid indices for your fruits, you don't have to use so many if cases. The rest looks OK to me, but I made some annotations in the source.</p>\n\n<pre><code>imp...
{ "AcceptedAnswerId": "32515", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-15T20:56:59.530", "Id": "29823", "Score": "7", "Tags": [ "functional-programming", "elm" ], "Title": "Can this be written more concise and aligned with the Functional Reactive Program...
29823
<p>I'm trying to achieve a set of unique array with my following function.</p> <h2>The Function:</h2> <p></p> <pre><code>/** * uniqueAssocArray Removes arrys which have same keys * @param Array $array Array to get unique items from * @param String $uniqueKey the unique key * @return Array new array...
[]
[ { "body": "<p>Maybe you should try to use the function <code>array_unique</code>: <a href=\"http://php.net/manual/en/function.array-unique.php\" rel=\"nofollow\">http://php.net/manual/en/function.array-unique.php</a></p>\n\n<p>If you prefer to go with your own solution, have a look at the method <code>array_key...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T10:55:29.670", "Id": "29835", "Score": "4", "Tags": [ "php", "array" ], "Title": "What is a better way to get unique array Items based on key in PHP?" }
29835
<p>I'm a noob in programming. I was asked to code a program that can <strong>calculate prime numbers.</strong> So i coded as provided below. But it <strong><em>prints all the Odd Numbers instead of Prime Numbers</em></strong>. I think the <strong>Value start is not being divided by all the integers in the range (2,Star...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T15:34:02.370", "Id": "47290", "Score": "0", "body": "Although your issue has been solved, would you like a review on your *working* code? If not, this post will remain closed, preventing any new answers from being posted." }, {...
[ { "body": "<p>There is no need to keep for loop in the while as while is doing the job of for,\nassuming that your program tests whether the <code>startnumber</code> is prime or not.</p>\n\n<p>using of <code>break</code> in <code>else</code> will terminate your loop once it checks that its not divisible by 2 [ ...
{ "AcceptedAnswerId": "29849", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T13:10:00.963", "Id": "29843", "Score": "0", "Tags": [ "python", "algorithm", "primes" ], "Title": "Problem in calculating prime numbers in python" }
29843
<p>I wrote the below code and tested some example files on it. I didn't find any errors, but I still want to be thorough about this.</p> <p>Also, any suggestions in improving the code?</p> <pre><code>import string """ this implements an encryption standard over the message text it replaces the odd place alphabets by...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T17:36:36.807", "Id": "47321", "Score": "1", "body": "`((i+1)% 2) ==0)` is more traditionally written as `(i % 2 == 1)`. Conversely, `((i+1)% 2) == 1)` is the same as `(i % 2 == 0)`." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Functions are your friend. The remove repeated code and improve readability. I have absolutely no idea what the block of text does inside the <code>\"\".join(XXXX)</code> calls. There is too much going on there that I'm not going to take the time to see what it does or if it can be done better.</p...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T13:17:44.947", "Id": "29844", "Score": "2", "Tags": [ "python", "formatting", "caesar-cipher" ], "Title": "Implementing an encryption standard over message text" }
29844
<p>I wrote my very first directive and I'd like to get some suggestions for improvement. My code - <a href="http://plnkr.co/edit/NW5VPl2anBThpnvOZiSD?p=preview" rel="nofollow">plnkr.</a></p> <pre><code>webApp.controller('AppCtrl', function ($scope) { $scope.expandAdd = function() { $scope.hiddenAdd = true; }; $...
[]
[ { "body": "<p><strong>Option 1: Don't use a directive.</strong><br>\nWhat you are trying to do does not actually require a directive. It is simple enough to play with the scope.</p>\n\n<pre><code> $scope.expandAdd = function() {\n $scope.hiddenAdd = true;\n };\n\n $scope.addWeb = function() {\n $scope....
{ "AcceptedAnswerId": "30357", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T13:27:02.563", "Id": "29846", "Score": "1", "Tags": [ "javascript", "angular.js" ], "Title": "AngularJS, Directive improvement" }
29846
<p>I have the following object oriented class revolving about the PHP super global <code>$_SESSION</code> I shown the script to a fellow developer and he mentioned that all my returns are not necessary needed, whereas I believe that they are? </p> <p>My code is as followed: </p> <pre><code>/* * * * This class will...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T15:57:54.183", "Id": "47296", "Score": "1", "body": "I’d say the best way to handle that is probably to throw an exception if the session hasn’t been started, unless an unstarted session is going to be part of normal behaviour." }...
[ { "body": "<p>As for your question, at least Get should not return false if the value is not set, now the caller will not know whether the actual value is false or whether the value is not set.</p>\n\n<p>Other than that,</p>\n\n<ul>\n<li><p>I would suggest you use PHP_SESSION_DISABLED , PHP_SESSION_NONE and PHP...
{ "AcceptedAnswerId": "29864", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T14:30:57.007", "Id": "29851", "Score": "2", "Tags": [ "php" ], "Title": "Are the returns within my session function actually needed?" }
29851
<p>I am a student, and I am doing websites as freelancer. Lately I have started learning design patterns, refactoring, and test-driven development so that I can improve the maintainability, performance, and readability of my code.</p> <p>I did some refactoring with method extracting in this case, but I got feedback th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T15:18:02.213", "Id": "47287", "Score": "3", "body": "Well, you could try to write a unit test for it and see for yourself." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T16:56:16.540", "Id": "473...
[ { "body": "<p>In general comments should be used to say <strong>why</strong> you are doing something, not <strong>what</strong> you are doing. You should strive to have variable names that describe what they contain.</p>\n\n<p>Don't be scared to create sub-functions. If you feel like you need to explain what a ...
{ "AcceptedAnswerId": "29856", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T15:05:59.640", "Id": "29855", "Score": "3", "Tags": [ "c#", "math-expression-eval" ], "Title": "Parser for an arithmetic expression" }
29855
<p>This function is simple, it gets a number of bytes and returns its representation in either Bytes, KB, MB, GB and TB.</p> <p>As simple as it is, I am sure there are other (and perhaps better ways) to write it.</p> <pre><code>function kmgtbytes (num) { if (num &gt; 0 ){ if (num &lt; 1024) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T17:12:40.960", "Id": "47308", "Score": "3", "body": "Your primary concern should be the clarity of your code. minitech's answer is sweet and terse, yet your code requires little thought to discern its function. Both of you should ad...
[ { "body": "<p>I'd use a while loop, divide by 1024 and keep track of how many times you divided.</p>\n\n<p>This is my completely bonkers function:</p>\n\n<pre><code>function resolve_to_power_of(bytes, power) {\n var powers;\n powers = 0;\n while (bytes &gt;= power) {\n powers += 1;\n byte...
{ "AcceptedAnswerId": null, "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T15:40:35.263", "Id": "29858", "Score": "18", "Tags": [ "javascript" ], "Title": "Dealing with KB, MB, GB and TB and bytes" }
29858
<p>I am trying to simplify the amount of code required here using arrays, I feel like my foreach loop is still excessively long. Any advice would be appreciated.</p> <pre><code>$date_list = Array( Array( 'age', "$birthday", 'now' ), Array( 'membership', "$datejoined", 'now' ), Array( 'promoted', "$lastpromo", 'now' ),...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T23:30:03.703", "Id": "47352", "Score": "0", "body": "Ugh. Firstly, use switch statements. Why are you using substr_count when you could use switch? You put the data there, you know it is clean. If this is just test code and in r...
[ { "body": "<p>It's hard to suggest simplifications without a greater understanding of the problem being solved. However, this is perhaps a bit more readable:</p>\n\n<pre><code>$dates = array(\n array('type' =&gt; 'age', 'start' =&gt; $birthday, 'stop' =&gt; 'now' ),\n array('type' =&gt; 'members...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T15:43:09.573", "Id": "29859", "Score": "1", "Tags": [ "php", "array" ], "Title": "Simplify code using array" }
29859
<p>I have created this class for my WP theme. It allows you to create templates for a meta box which relates directly to a custom frontend template to have better control of the content displayed on the page.</p> <p>So for example:</p> <p>The meta box content file, which defines a "template":</p> <pre><code>theme_fo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T13:41:15.850", "Id": "47853", "Score": "0", "body": "Your code is very pretty and easy to read. Why do some methods begin with an underscore. Like, `_interceptTemplateDisplay`? I'm not complaining about it. Just curious." } ]
[ { "body": "<p>The formatting is a little off to what is considered normal/good. <a href=\"http://framework.zend.com/manual/1.12/en/coding-standard.naming-conventions.html\" rel=\"nofollow\">It is widely accepted</a> that each word in a class name should have it's first letter capitalized. Function names are mos...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T17:09:05.857", "Id": "29866", "Score": "6", "Tags": [ "php", "object-oriented", "wordpress" ], "Title": "WordPress Post Type template" }
29866
<p>I have this code:</p> <pre><code>for (int i = 0; i &lt; lst.Count(); i++) { lst[i].ColumnOrder = (short)i; } </code></pre> <p>But I was trying to find a way to do it via LINQ or something else with better performance. I'm pretty sure that there are better ways to change the sequence of a column. I use this co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T17:21:46.700", "Id": "47313", "Score": "0", "body": "I know it's kind silly question. But I really got curious about a better way to do it, and couldn't find anything on the web. **PS: The title looks a little weird for the context,...
[ { "body": "<p>You <em>can</em> use LINQ to do it, but that will end up as pretty ugly code. LINQ is used to process data and return a result, and that is not what you are doing here, so using LINQ for this would only mean that your code would produce a dummy result and have a side effect doing so.</p>\n\n<p>Wel...
{ "AcceptedAnswerId": "29872", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T17:21:05.027", "Id": "29867", "Score": "2", "Tags": [ "c#", ".net", "linq" ], "Title": "Change one column data from List<>" }
29867
<p>I wrote some type checking decorators for Python. One checks the type that a function returns, the other checks the type that a function accepts.</p> <pre><code>import functools def returns(t): """ Calls a function, and if it returns something of the wrong type, throws a TypeError """ def outer(func): ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T20:00:59.283", "Id": "47339", "Score": "1", "body": "`accepts` shouldn’t be a class." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T06:48:40.100", "Id": "47371", "Score": "0", "body": "@m...
[ { "body": "<p>I agree with @minitech that accepts shouldn't be a class. It can be written much more compactly using a nested decorator (like <code>returns</code>, in fact):</p>\n\n<pre><code>def accepts(*artypes, **kwtypes):\n \"\"\"\n Pass it a list consisting of types or tuples of types.\n in other w...
{ "AcceptedAnswerId": "67800", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T17:27:56.283", "Id": "29868", "Score": "2", "Tags": [ "python", "python-3.x" ], "Title": "How do I clean up these Python decorators?" }
29868
<p>I received help with adding the length of a stream in the first 4 bytes, meaning it's there as an <code>int</code>.</p> <p>I am adding it at the start and sending it, while the receiving part checks for its position.</p> <p>However, the position checking is a bit slow, so I wonder if it's possible to improve it. ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T20:42:00.207", "Id": "47345", "Score": "0", "body": "Any particular reason you don't want to open a `BinaryReader` on that stream? It'll take care of most of what you're looking for." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>I agree with the comments that it's not likely to be your position checking code that's slowing you down. Maybe you could squeeze some performance out with unsafe code, but that's maybe saving a copy from one buffer to another. It would be nice to put that reading loop into a separate function, ...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T20:27:06.217", "Id": "29875", "Score": "4", "Tags": [ "c#", "performance" ], "Title": "Speed up position check for embedded length on stream" }
29875
<p>Here are my code samples: <a href="https://github.com/arthaeus/war" rel="nofollow">https://github.com/arthaeus/war</a></p> <p>This particular sample is the card game 'War'. The interviewer off-handedly asked me: "what if I wanted to play War with an Uno deck of cards?" I threw an Uno deck implementation in there ...
[]
[ { "body": "<p>ugh. I don't even know where to start...</p>\n\n<p>The code you wrote is not OO. In no way at all.</p>\n\n<p>Let's answer you questions first:</p>\n\n<blockquote>\n <p>I have been told that my main() function is too procedural</p>\n</blockquote>\n\n<p>You have a 'War' class with a main() function...
{ "AcceptedAnswerId": "29927", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-16T22:23:32.797", "Id": "29878", "Score": "3", "Tags": [ "php", "object-oriented", "interview-questions", "game" ], "Title": "Review of object-oriented skills with War game" }
29878
<p>The navigation in my footer menu looks like this </p> <p><img src="https://i.stack.imgur.com/3SSb2.png" alt="footer navigation"></p> <p>It works, but I get a feeling that using spans the way I did was a bit of a hack. So I would also like to know how to maximize compatibility as used media queries.</p> <p>I creat...
[]
[ { "body": "<p>you should use a <code>&lt;div&gt;</code> where you need to separate a block of code from the rest, for positioning or for other purposes, your use of the <code>div</code> for the Footer section is correct, so that you can place this part of the page at the bottom, where it belongs. </p>\n\n<p>wh...
{ "AcceptedAnswerId": "30090", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T02:00:34.360", "Id": "29882", "Score": "5", "Tags": [ "html", "css" ], "Title": "Review of my CSS for aligning the navigation icons and text in a footer menu" }
29882
<p>I have the following code (I need the <code>LambdaExpression</code> as not all <code>Func&lt;&gt;</code>'s are <code>T, int</code>):</p> <pre><code>var orderDelegates = new Dictionary&lt;string, LambdaExpression&gt;(); Expression&lt;Func&lt;Image, int&gt;&gt; id = i =&gt; i.Id; orderDelegates.Add(ContentItem.ORDER...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T11:16:34.300", "Id": "47383", "Score": "0", "body": "So, what do you know about the lambdas, are they all `Func<Image, something>` or at least `Func<something1, something2>`?" }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>You can do this by creating a custom class that supports collection initializers. Its <code>Add()</code> method would be generic, so that it fits any allowed expression:</p>\n\n<pre><code>class ExpressionDictionary&lt;T&gt; : IEnumerable&lt;KeyValuePair&lt;string, LambdaExpression&gt;&gt;\n{\n ...
{ "AcceptedAnswerId": "29890", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T08:26:57.463", "Id": "29883", "Score": "3", "Tags": [ "c#", "linq" ], "Title": "Inline conversion/cast from Expression<Func<T, int>> to LambdaExpression" }
29883
<p>I wrote this code to overcome the deadlock condition described in <a href="http://docs.oracle.com/javase/tutorial/essential/concurrency/deadlock.html" rel="nofollow">this Oracle tutorial</a>.</p> <p><strong>Summary of Problem:</strong></p> <blockquote> <p>Alphonse and Gary are friends, and great believers in cou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T16:13:02.743", "Id": "47396", "Score": "0", "body": "`NewClass` should be `NewThread` if I'm not missing something and your static class should have proper indentation." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>Welcome to the wonderful world of deadlocks. In a nutshell: No, your “solution” is not adequate. Here is some pseudocode detailing what the two threads are doing. Note that a <code>synchronized</code> method aquires a lock on the object it is called on.</p>\n\n<pre><code>THREAD 1 ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T15:40:49.257", "Id": "29892", "Score": "3", "Tags": [ "java", "multithreading" ], "Title": "Volatile boolean to prevent deadlock" }
29892
<p>I wrote a custom URL encoding function and I'd like to run it past a few other experienced C developers. I have tested it on a few strings, and it has worked on all of them. </p> <p>This is to be run on iOS devices, so memory and processor use are potentially a small concern.</p> <p>Do you see any potential probl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T20:51:02.910", "Id": "47413", "Score": "0", "body": "Seems like you should be able to just use `NSString`'s `stringByAddingPercentEscapesUsingEncoding`? Or, if you need to expand on what is escaped (as you likely would to implement ...
[ { "body": "<p>First of all, URL encoding is more <a href=\"http://www.skorks.com/2010/05/what-every-developer-should-know-about-urls/\" rel=\"nofollow\">nuanced</a> than you might think. Be cautious when applying encoding.</p>\n\n<p>As for your code, the only blatant bug I see is that it can segfault when enco...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T20:42:06.323", "Id": "29895", "Score": "4", "Tags": [ "strings", "objective-c", "ios", "url" ], "Title": "URL percent encoding function" }
29895
<p>A little birdie suggested I bring this question here, so here it goes.</p> <p>Well I have a working script (see below) but it seems quite clunky and redundant; in my defense I wrote this code many moons ago, but that's not the point. I was curious if anyone has an idea on a more efficient way of writing this code, ...
[]
[ { "body": "<p>This:</p>\n\n<pre><code>$count = 1;\nfor($i = 1; $i &lt;= $num; $i++) {\n if(($i%$npp) === 0) {\n $count++;\n }\n}\n</code></pre>\n\n<p>is equivalent to</p>\n\n<pre><code>$count = floor($num / $npp) + 1;\n</code></pre>\n\n<p>As for the paging, I'd do it like this:</p>\n\n<pre><code>$f...
{ "AcceptedAnswerId": "29898", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T21:52:58.180", "Id": "29897", "Score": "2", "Tags": [ "php", "object-oriented" ], "Title": "More simplified way of creating page links dynamically?" }
29897
<p>I found <a href="http://projecteuler.net/" rel="nofollow">Project Euler</a> some time ago and I thought I'd enjoy trying those problems.</p> <p>I'm using C++11 (Visual Studio 2012). I thought I'd program a Manager to test each problem and the time it takes my solution to run. I programmed this:</p> <p><a href="ht...
[]
[ { "body": "<p>First of all, stylistic matters:</p>\n\n<p>Why are you making <code>ProjectManager</code> a singleton? There is no need to require that only one exists: it doesn't use of any global state except itself, and the logging path could easily be passed in using the constructor (along with any of the ot...
{ "AcceptedAnswerId": "29924", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-17T22:54:58.050", "Id": "29899", "Score": "1", "Tags": [ "c++", "performance", "c++11" ], "Title": "Differences in execution time for problems manager" }
29899
<p>I am trying to implement a class that implements a given schedule. I am trying to design this Scheduler class so it can be paused and everything. I have just written some example code so I can better convey my requirements. I would be grateful if more experienced minds could take a look and tell me if what I have ri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T12:18:43.627", "Id": "47443", "Score": "0", "body": "Just to verify: your current code works the way you want and you're looking for improvements of the code and not for improvements of the functionality, right?" }, { "Conte...
[ { "body": "<p>Your code is super-comlicated for such simple logic. I'm also pretty sure it deadlocks in pretty much any use case.</p>\n\n<pre><code>class Scheduler : IDisposable\n{\n private readonly object scheduleLock = new object();\n private int[] schedule = null;\n private int scheduleIndex = 0;\n...
{ "AcceptedAnswerId": "29941", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T03:29:37.060", "Id": "29907", "Score": "2", "Tags": [ "c#" ], "Title": "Implementing a Scheduler(something that implements a given schedule)" }
29907
<p>This code displays a lot of images based on color in columns. I'm thinking it can probably be optimized a lot better. But I'm wondering if anyone has a more fundamental solution on how this could be improved in regards to speed and legibility.</p> <p>The database has the equivalent of <a href="http://ark42.com/mtg/...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T04:57:00.940", "Id": "47541", "Score": "0", "body": "I think you need to stop for a moment and collect your thoughts. What *exactly* is it you want to optimize/improve? Is it slow? Is the code getting unwieldy?" }, { "Conten...
[ { "body": "<h1>Unnecessary <code>strcmp</code></h1>\n\n<p>Part of your code looks like this:</p>\n\n<pre><code>if(strcmp($colors[$j], $current_color) != 0) {\n</code></pre>\n\n<p><code>strcmp</code> is not necessary here; plain equality would work fine and be clearer:</p>\n\n<pre><code>if($current_color !== $co...
{ "AcceptedAnswerId": "29910", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T05:04:38.753", "Id": "29908", "Score": "5", "Tags": [ "php", "css" ], "Title": "Displaying images based on column colors" }
29908
<p>I forked <a href="https://github.com/tomchristie/webdriverplus/blob/0.2.0/webdriverplus/__init__.py" rel="nofollow">this repo</a> to be more concise. The code is <a href="https://github.com/capitalsigma/webdriverplus/blob/0.2.0/webdriverplus/__init__.py" rel="nofollow">here</a>. I'll paste it below since that seems ...
[]
[ { "body": "<p>It's not unknown: python is really good at this, although the more common approach would be to <a href=\"http://eli.thegreenplace.net/2011/08/14/python-metaclasses-by-example/\" rel=\"nofollow\">use a metaclass</a>. The immediate drawbacks are</p>\n\n<p>1) it introduces a state-changing dependenc...
{ "AcceptedAnswerId": "30111", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T07:43:49.170", "Id": "29914", "Score": "3", "Tags": [ "python", "classes", "python-3.x", "meta-programming" ], "Title": "Streamlining repetitive class definitions in python...
29914
<p>This is used to create a directed graph of type <code>T</code>. The directed graph has edges and vertices with values but is directional such that nodes can loop unto themselves or only go a single direction even though 2 vertices are connected. </p> <p>Things I am looking to get out of this review are:</p> <ul...
[]
[ { "body": "<p>Your use of <code>HashMap</code> is fine.</p>\n\n<p>I agree that your <code>copy()</code> method is overkill. Do you really need to clone the data? If not, then your copy constructor can just be</p>\n\n<pre><code>public DigraphNode(DigraphNode&lt;T&gt; other)\n{\n this.data = other.data;\n ...
{ "AcceptedAnswerId": "29929", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T08:32:53.030", "Id": "29915", "Score": "4", "Tags": [ "java", "graph" ], "Title": "Digraph Code in Java" }
29915
<p>I have a data structure called <code>ClientSession</code> which I convert to a <code>String</code> separated by <code>|</code> for each element and back to the data structure. </p> <pre><code> 18 data ClientSession = ClientSession ...
[]
[ { "body": "<p>First note that if your <code>username</code> contains a bar <code>'|'</code>, you won't be able to parse the output back. So be sure to check for this.</p>\n\n<p>Since you're already using a parser, it's much easier to read the whole <code>ClientSession</code> using the parser instead of splittin...
{ "AcceptedAnswerId": "29922", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-08-18T10:24:17.510", "Id": "29917", "Score": "2", "Tags": [ "strings", "parsing", "haskell" ], "Title": "Converting from ClientSession to String and back" }
29917
<p>Here is the SlimDX version:</p> <pre><code> var form = new SlimDX.Windows.RenderForm("Test"); form.Width = 1280; form.Height = 1024; SlimDX.Direct3D9.PresentParameters presentParams = new SlimDX.Direct3D9.PresentParameters { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T12:16:45.133", "Id": "47442", "Score": "0", "body": "Have you tried to profile the code? Is the slow part actually where you expect it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T22:11:11.343", ...
[ { "body": "<p>You seem to be timing this code:</p>\n\n<pre><code> var tx = SlimDX.Direct3D9.Texture.FromStream(device, ms, 0, 0, 0, SlimDX.Direct3D9.Usage.None, SlimDX.Direct3D9.Format.X8R8G8B8, SlimDX.Direct3D9.Pool.Managed, SlimDX.Direct3D9.Filter.None, SlimDX.Direct3D9.Filter.None, 0);\n</code></pre>\n\n<p>T...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T10:42:40.823", "Id": "29919", "Score": "-1", "Tags": [ "c#", "performance" ], "Title": "Drawing faster than SlimDX?" }
29919
<p>I wrote a PowerShell script for a <a href="https://superuser.com/a/528499/50173">superuser question</a>:</p> <blockquote> <p>list of all files and directories under a path recursively, without recursing into junction points or links</p> </blockquote> <p>I have a strong feeling that my code is way too complicated...
[]
[ { "body": "<p>Here's a shot at it: (Requires PowerShell v3 or higher)</p>\n\n<p>The idea here is to get all non-reparsepoint directories first.\nFor each directory, recurse into the subdirectory and then output the files at the current level.</p>\n\n<p>In it's simplest form, it looks like this:</p>\n\n<pre><cod...
{ "AcceptedAnswerId": "32435", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T17:51:39.003", "Id": "29930", "Score": "4", "Tags": [ "recursion", "windows", "powershell" ], "Title": "Recursive Windows Directory listing" }
29930
<p><em>Background info on <a href="http://en.wikipedia.org/wiki/Factorization" rel="nofollow noreferrer">factoring</a> and <a href="http://en.wikipedia.org/wiki/Prime_factorization" rel="nofollow noreferrer">prime factorization</a></em>.</p> <p>I've remade this program from my <a href="https://codereview.stackexchange...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T09:31:40.983", "Id": "49296", "Score": "2", "body": "One thing i can say right off, you could probably roughly double the speed of `Primes::calculate` by checking 2 independently, and then only checking odd numbers. (Once you've fa...
[ { "body": "<p>Yes. You can use template, if you use template, you won't be able to separate the declarations and definitions of member functions without explicit instantiations, which is exactly what you need. Only the instantiated types will then be allowed. For example;</p>\n\n<pre><code>//header file test.h\...
{ "AcceptedAnswerId": "31021", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-18T18:34:19.063", "Id": "29932", "Score": "8", "Tags": [ "c++", "primes" ], "Title": "Remake of factoring/prime factorization calculator" }
29932
<p>I'm looking to get some feedback on a small <code>printf</code>-like function I wrote that provides simplified behavior similar to <code>boost::format</code>:</p> <pre><code>#ifndef EXT_FORMAT_HPP__ #define EXT_FORMAT_HPP__ // ext::format // Implements a variadic printf-like function providing behavior similar to /...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T01:46:01.347", "Id": "47555", "Score": "0", "body": "I made some changes that hopefully makes the code easier to read. I refactored `format_helper` for clarity rather than trying to squeeze everything into the return call. I also re...
[ { "body": "<p>I find this to be a sweet demo, but I don't like the traps in it for the unwary. Like you mention, there is little validation of parameter counts. There is also a chance that the same location can be replaced multiple times, e.g. with a call to <code>ext::format(\"%1\", \"%2\", \"%3, \"%4\", \"hi!...
{ "AcceptedAnswerId": "35505", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-08-18T22:37:53.330", "Id": "29935", "Score": "9", "Tags": [ "c++", "c++11", "variadic" ], "Title": "A small printf-like function using variadic templates" }
29935
<p>I am making some basic temperature conversion methods, and I want the end result to look something like this: </p> <pre><code>double celsius = TemperatureConvert.convert(10, Temperature.FAHRENHEIT, Temperature.CELSIUS); // Where 'Temperature' is an enum with three values: FAHRENHEIT, CELSIUS, and KELVIN // This meh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T12:32:59.697", "Id": "47525", "Score": "0", "body": "+1 The question doesn't consist any codes but still serves the purpose of this site." } ]
[ { "body": "<p>The <code>java.util.concurrent.TimeUnit</code> enum class provides both a <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/TimeUnit.html#convert%28long,%20java.util.concurrent.TimeUnit%29\" rel=\"nofollow\">generic conversion method</a> and specific methods for each modeled ...
{ "AcceptedAnswerId": "29938", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T00:53:19.187", "Id": "29936", "Score": "3", "Tags": [ "java", "design-patterns" ], "Title": "How to implement a dynamic temperature conversion method based on given enums?" }
29936
<p>IS it possible to read directly from the TCPStream to get an image if I know the size and all that, without first saving it to a memorystream?</p> <p>My code currently works with putting the first 4 byte in the TCP stream as a length for the entire data, so first I send the length. And then I know the length so I r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T11:50:45.243", "Id": "47522", "Score": "0", "body": "Are you saying that the `NetworkStream` can contain multiple images?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T11:56:42.450", "Id": "4752...
[ { "body": "<p>my though is like this, though i didn't really test it</p>\n\n<ol>\n<li><p>You must keep the stream open for the lifetime of the Image. because the Image.FromStream wont read the data until it needs it, for performance purpose;</p></li>\n<li><p>you must make sure the all the data for that image ...
{ "AcceptedAnswerId": "29949", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T10:24:56.123", "Id": "29944", "Score": "1", "Tags": [ "c#", "stream" ], "Title": "Get Image From Stream, TCP Stream without converting to MemoryStream first" }
29944
<p>How can I make my library more flexible towards programmers? <a href="https://github.com/miguelishawt/pine" rel="nofollow">Here is my library.</a> It's a basic library that provides a simple interface to organise your game (with scenes, and engine/game connection). The only problem that I dislike about it, is the fa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T18:35:27.567", "Id": "80635", "Score": "0", "body": "I am not sure you got notified, but your question was closed a while ago because we require code to be included in the question itself. We don't like being dependent on third-part...
[ { "body": "<p>A few observations/thoughts from a quick look at the code and accompanying description. Feel free to explain/correct as appropriate:</p>\n\n<ul>\n<li><p>For starters, the <code>Game</code> class seems to delegate everything to the <code>GameLoop</code> class, why? It seems more logical that <code>...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T10:26:30.747", "Id": "29945", "Score": "0", "Tags": [ "c++", "c++11", "library", "library-design" ], "Title": "Improving the flexibility of my library/what can be improved?" }
29945
<p>My code looks like imperative style code. I want to make my code more functional. How I can rewrite my program so it become functional style code?</p> <pre><code> val _map = getMap(); if(_map.contains(x) &amp;&amp; _map.contains(y)) Right(_map(x) + _map(y)) else if(_map.contains(x + y)) Right(_map(x + y)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T15:52:13.393", "Id": "47539", "Score": "1", "body": "You realise that your error messages are inaccurate and incomplete? Firstly, it should be \"%d *and* %d not found\" (because a \"not found\" message will only be generated if _ma...
[ { "body": "<p>In this case, I'd utilize pattern matching. As an example:</p>\n\n<pre><code>def getMap(): Map[String, String] =\n Map[String, String](\"foo\" -&gt; \"bar\", \"baz\" -&gt; \"quux\", \"foobar\" -&gt; \"bazquux\")\n\n// Note that I've simplified this to take Strings\ndef getOption(x:String, y: Stri...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T11:51:45.037", "Id": "29946", "Score": "3", "Tags": [ "error-handling", "scala", "optional" ], "Title": "Adding two values in a map, if they exist" }
29946
<p>A picture says more than a thousand words, so here's a mock-up. The actual choices are different, this is just a sample.</p> <p><img src="https://i.stack.imgur.com/4HZDQ.png" alt="mock-up"></p> <p>A user first has to choose between <em>Red</em>, <em>Blue</em> and <em>Green</em>. Upon selecting an option, additiona...
[]
[ { "body": "<p>Well, i think, you should first ask yourself do you really want to complicate things? Is this something that you will re-use in other places? Because the feeling \"i need to create something reusable and extendable\" if familiar to every one of us, but the amount of code you'll need to write and d...
{ "AcceptedAnswerId": "29979", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T13:21:46.893", "Id": "29950", "Score": "1", "Tags": [ "c#", "asp.net-mvc-4" ], "Title": "Modeling a decision tree-like form" }
29950
<p>I am writing a Java app that gets the metadata of files in a directory and exports it to a .csv file. The app works fine if the number of files is fewer than a million. But if I feed in a path that has about 3200000 files in all of directories and sub-directories, it takes forever. Is there a way I can speed up thin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T14:45:53.253", "Id": "47532", "Score": "0", "body": "Which version of java do you use ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T14:53:34.533", "Id": "47533", "Score": "0", "body": ...
[ { "body": "<p>You are continually accessing the array for the current item, but never using the index for anything else. This is exactly what for-each loops are for.</p>\n\n<pre><code>for (File f : listOfFiles) {\n //use f instead of listOfFiles[i]\n}\n</code></pre>\n\n<hr>\n\n<p>The following code is full of ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T14:34:39.937", "Id": "29952", "Score": "4", "Tags": [ "java", "file-system", "file" ], "Title": "Java app for getting metadata of millions of files in a directory" }
29952
<p>I have several controls that are bound from database tables. Putting my OOP thinking cap on I figured since all of the controls will have a <code>SqlCommand</code> name and an associated <code>SqlDataReader</code> object I decided to make the following interface to program to.</p> <pre><code>public interface IBoun...
[]
[ { "body": "<p>The IBoundControl is good. It isolates the specific data calls. It's refreshing to see another approach than falling back to the repository pattern.</p>\n\n<p>IBoundControl implementation is on a class that also doubles as the DTO. This is breaking the <a href=\"http://en.wikipedia.org/wiki/Single...
{ "AcceptedAnswerId": "29977", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T15:24:58.230", "Id": "29955", "Score": "5", "Tags": [ "c#", "asp.net", "interface" ], "Title": "Interface programming with Data Access Layer" }
29955
<p>The code creates a Ruby bingo game for the console and works properly. I believe the code I wrote needs some work, though, as I am new to Ruby. Any help would be appreciated. </p> <pre><code>require "color_text" class Bingo def initialize #map of all places that are possible wins @columns = [ ...
[]
[ { "body": "<p>I think you could improve the readability of the code if you take advantage of objects. You can have at a minimum, classes for <code>BingoGame</code>, <code>Card</code>, and <code>Player</code>. Possibly <code>Ball</code> too. Having a Card object alone would tuck away a lot of the code related to...
{ "AcceptedAnswerId": "29960", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T16:37:14.410", "Id": "29958", "Score": "4", "Tags": [ "ruby", "beginner", "game", "console" ], "Title": "Small Ruby Bingo Game" }
29958
<p>I'm fairly new to scripting in Python. I'm looking for suggestions on improving any of the following in the below script: my coding style, performance, readability, commenting, or anything else.</p> <pre><code>""" META Author: James Nicholson Date: 8/16/2013 DESCRIPTION This script takes a list of groups from a te...
[]
[ { "body": "<p>The code looks good (it's short, which is always a good thing).</p>\n\n<p>Make sure to follow PEP 8. A <a href=\"http://hg.python.org/peps/rev/fb24c80e9afb\" rel=\"nofollow\">recent revision of PEP 8</a> allowed 99 characters lines to \"improve readability\", but your <code># Loop over ...</code> ...
{ "AcceptedAnswerId": "30010", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T18:47:54.343", "Id": "29961", "Score": "7", "Tags": [ "python", "windows" ], "Title": "Create CSV file of domain groups and their users" }
29961
<p>I am working on creating an interface gem that works with the <a href="https://github.com/sumoheavy/jira-ruby" rel="nofollow">Jira-Ruby gem</a>.</p> <p>I have several questions and would like a general review for both my code and my attempt at creating a gem (I've never written one before). Any advice on where to g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T21:16:24.820", "Id": "52978", "Score": "0", "body": "Aside from what I posted in my answer, your approach looks great. Naming could be improved, but like they say, it is hard.\n\nKeep the good work up!" }, { "ContentLicense"...
[ { "body": "<p>I suggest you take a close look at <strong><a href=\"https://github.com/sumoheavy/jira-ruby/tree/master/spec\" rel=\"nofollow\">how the gem you are using is tested</a></strong>. Those tests include <strong>mocks</strong> for all responses of the API (I assume) and is a good example for testing gem...
{ "AcceptedAnswerId": "33095", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T18:51:12.983", "Id": "29962", "Score": "5", "Tags": [ "ruby", "ruby-on-rails", "file-structure" ], "Title": "Creating a Ruby gem that talks to another gem" }
29962
<p>I have some problems in my View.ascx.cs file because I'm reusing my code and modified it based on the situation. For example, when I apply pagination I have different code in all places. I just want my code to be simpler.</p> <pre><code>using System; using DotNetNuke.Security; using DotNetNuke.Services.Exceptions; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T21:02:47.010", "Id": "53626", "Score": "0", "body": "you have a problem or the code works?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T21:04:50.223", "Id": "53627", "Score": "0", "body...
[ { "body": "<p>Your code duplication in <code>BindResourceRepeater</code> (2x in there) and <code>btnSearch_Click</code> is around the differences of how the keyword is handled and how the prev/next links are enabled/disabled.</p>\n\n<p>Lets look at the link enabling first.</p>\n\n<p>To me the logic of disabling...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T19:36:06.113", "Id": "29963", "Score": "5", "Tags": [ "c#", "asp.net", "pagination" ], "Title": "Pagination of repeater" }
29963
<p>I wrote a class that finds values in a huge search volume. I have a pretty strong feeling that my code is not good and would like to get your opinion on it. My experience with C++11 threading is very limited and I think I use the wrong features for my task.</p> <pre><code>#include &lt;iostream&gt; #include &lt;vect...
[]
[ { "body": "<p>There are definitely some problems if you want to make this threaded. Firstly, access to <code>m_searches</code> is not protected in any way. Since this is a shared bit of memory, it would need to be protected by something (say a mutex) before you modify it.</p>\n\n<p>Generally in situations like ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T19:49:56.113", "Id": "29964", "Score": "4", "Tags": [ "c++", "multithreading", "c++11" ], "Title": "Searching through a huge set with threads" }
29964
<p>I am working on hospital management system project. I have implemented it using the following design. Is it a good design?</p> <p>I have created four classes: <code>Patient</code>, <code>Doctor</code>, <code>Hospital</code>, and <code>Demo</code>. Inside the Hospital class are two <code>ArrayList</code>s of Patient...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T05:03:21.743", "Id": "47559", "Score": "2", "body": "`Hospital.showDoctors()` and `Hospital.showPatients()` should be `.getDoctors()` and `.getPatients()`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08...
[ { "body": "<ul>\n<li><p>Indentation: It's all over the place and kind of hard to follow. Try to be consistent.</p></li>\n<li><p>Braces: Same thing. For the most part you are putting them at the beginning of the next line. But sometime you are putting a line of code with the brace. This is not one of the standar...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T20:59:09.647", "Id": "29965", "Score": "3", "Tags": [ "java", "object-oriented" ], "Title": "Designing classes and methods for hospital management system" }
29965
<p>I've built a Twitter plugin recently and was wondering if I could get some feedback on it. There is also a PHP side that grabs the actual tweets and I can post that code if it's needed.</p> <p><a href="http://jsfiddle.net/cKfDd/" rel="nofollow">http://jsfiddle.net/cKfDd/</a></p> <pre><code>;(function ( $, window,...
[]
[ { "body": "<p>The code over all looks nice and clean and is very readable.</p>\n\n<p>What I'm not really a fan of is the handling of the template.</p>\n\n<ul>\n<li><p>Personally I'd prefer to define the template directly as an array instead of a comma separated string.</p></li>\n<li><p>The big if block building...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-19T21:46:44.743", "Id": "29967", "Score": "3", "Tags": [ "javascript", "jquery", "datetime", "plugin", "twitter" ], "Title": "Display Twitter timelines and lists on a website...
29967
<p>I have written below code for the famous <a href="http://en.wikipedia.org/wiki/Josephus_problem" rel="nofollow">Josephus problem</a>, or inky pinky ponky game, or many other names. Does this looks good or is there any loophole if anyone can highlight. I shall be looking forward to optimize it now as much as possible...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T05:04:45.937", "Id": "47560", "Score": "1", "body": "Your indentation is bad. It is inconsistent and makes it hard to read the code. Also adding comments at the end makes it hard to read the code. You could have placed it before the...
[ { "body": "<p>Sorry, but I don't think this code is very good. </p>\n\n<p>In <code>create_c_list</code>, the <code>first</code> node is allocated twice, leaking memory, and there\nare no checks for allocation failure. Parameters <code>n_k</code> and <code>n_w</code> are badly\nnamed and the latter is not used....
{ "AcceptedAnswerId": "37092", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T03:47:22.707", "Id": "29974", "Score": "2", "Tags": [ "optimization", "c", "linked-list", "circular-list" ], "Title": "Inky pinky ponky game / Josephus problem" }
29974
<p>I have recently written my first jQuery plugin. It is a responsive jQuery carousel plugin. It seems to be functioning well apart from on window re-size. Sometimes if the window is re-sized too fast I get the following console error <code>RangeError: Maximum call stack size exceeded</code>, despite a timer function b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T07:59:13.537", "Id": "47565", "Score": "1", "body": "We cannot address the error you're receiving (that's for Stack Overflow), but we *can* address the request for best practices." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>From a once over;</p>\n\n<ul>\n<li>Very well commented</li>\n<li><p>Assigning <code>element</code> to <code>element</code> is overkill here and does nothing:</p>\n\n<pre><code>var $element = $(element), // Reference to the jQuery version of DOM element\n element = element; // Reference to t...
{ "AcceptedAnswerId": "66696", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T07:52:05.047", "Id": "29982", "Score": "4", "Tags": [ "javascript", "jquery", "performance", "plugin" ], "Title": "jQuery carousel plugin" }
29982
<p>I have to create a class <code>Data</code> with dates and there should be some methods and constructor. Maybe some method can be done in another way, especially the method <code>wichIsEarlier</code>, because I made it <code>static</code> and I'm not really sure about it. Please take a look on this class and say what...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T14:25:16.097", "Id": "47582", "Score": "0", "body": "First thing, some of your methods name don't seems to be in English. You should change those because I have no idea what `ileDniWMiesiacu` is suppose to do. This will help to have...
[ { "body": "<p>As Marc-Andre mentioned, you should really use English for your methods and classes, so that we can review better.</p>\n\n<p>Still, I am fairly certain that</p>\n\n<pre><code>public boolean czyPrzestepny(){\n boolean rr = false;\n if(gcalendar.isLeapYear(gcalendar.get(Calendar.YEAR))){\n ...
{ "AcceptedAnswerId": "29995", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T13:53:34.267", "Id": "29992", "Score": "8", "Tags": [ "java", "datetime" ], "Title": "GregorianCalendar" }
29992
<p>I'm a beginner PHP developer and it's my first time using MySQLi. I'm not sure if this is a correct implementation of the connection and query because some people defend this method and some others not. I need a solid implementation for heavy database usage.</p> <p>Connection:</p> <pre><code>class bbddConnection {...
[]
[ { "body": "<p>Similar to this one: <a href=\"https://codereview.stackexchange.com/questions/29670/minimalistic-mysql-db-class/29685#29685\">Minimalistic mysql db class</a></p>\n\n<p>To answer your question: NO!</p>\n\n<p>The short answer: Throw away your code, burn it, do whatever you want with it but <strong>n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T15:56:03.077", "Id": "29997", "Score": "4", "Tags": [ "php", "beginner", "mysqli" ], "Title": "Database connection query" }
29997
<p>I have written a plugin loader in Ruby, and I would like to know if it uses the best technique to handle classes, or if anyone has any recommendations on how to improve my code.</p> <p>I have written a class called PluginManager, and an accompanying module named Plugin. The names of these are self explanatory, one ...
[]
[ { "body": "<h1>Formatting</h1>\n\n<h2>Indenting</h2>\n\n<p>The standard ruby indent is 2 spaces. For example:</p>\n\n<pre><code>def puts(string)\n if @@logger.nil?\n super(string)\n else\n @@logger.info string\n end\nend\n</code></pre>\n\n<h1>Design</h1>\n\n<h2>Class Variables</h2>\n\n<p>I would not u...
{ "AcceptedAnswerId": "39320", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T16:49:30.767", "Id": "29998", "Score": "4", "Tags": [ "optimization", "ruby", "classes", "modules" ], "Title": "Loading 'Plugins' in Ruby" }
29998
<p>I'm a beginner in C# and am doing a simple programming exercise. I would like to put the <code>Item.price</code> and <code>Item.Name</code> into <code>Listbox2</code>.</p> <p>Is it possible to put the array name into a variable and iterate with a <code>foreach</code> loop? This is to avoid a very long <code>if</co...
[]
[ { "body": "<blockquote>\n <p>Is it possible to put the array name into a variable and iterate by a foreach loop?</p>\n</blockquote>\n\n<p><strong>YES.</strong> </p>\n\n<pre><code>Array ProductItems = Drinks.ToArray();\nforeach(Product item in ProductItems)\n {\n Consol...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T17:37:31.783", "Id": "30000", "Score": "1", "Tags": [ "c#", "array", "beginner" ], "Title": "Putting array name in variable and shortening code" }
30000
<p>How could I make this code more efficient? Instead of using many <code>if</code>-statements, should I make a function, array, or <code>switch</code>? How would I do that?</p> <pre><code>&lt;form method="post" action="trivia2.php"&gt; &lt;ol&gt; &lt;li&gt;How many days are in a week? &lt;input type="text" name="da...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T02:19:06.340", "Id": "47613", "Score": "0", "body": "Security should be a far greater concern here." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T04:11:10.233", "Id": "47616", "Score": "0", ...
[ { "body": "<p>Theres nothing particularly unefficient about what you have, but there are a couple of things. instead of storing the variables like</p>\n\n<pre><code>$daysweek=$_POST['daysweek'];\n</code></pre>\n\n<p>just leave them in <code>$_POST</code> like </p>\n\n<pre><code>if($_POST['daysweek']==7){//..\n<...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T03:22:31.120", "Id": "30003", "Score": "3", "Tags": [ "php", "quiz" ], "Title": "Quiz form with random questions" }
30003
<p>I am running a timer for updating some of my operations, such as buffers. But I also want ping to be added.</p> <p>It is added, but I think it can be improved. This is because I think it's running on the GUI thread, which is not preferred as it will freeze the GUI if something goes wrong with it. I think such a t...
[]
[ { "body": "<p>As it is not really much code, let us just focus on the <code>label part</code> and a little naming. </p>\n\n<blockquote>\n<pre><code>TimesBufferClear++;\n</code></pre>\n</blockquote>\n\n<p>If this is a variable, we should use <code>camelCase</code> casing for the name. If it is a property it fol...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-20T23:49:49.747", "Id": "30013", "Score": "0", "Tags": [ "c#", "timer" ], "Title": "Ping and write the status of a timer on a GUI thread" }
30013
<p>I'm currently writing a <a href="https://github.com/sayonarauniverse/magic_server" rel="nofollow">pure ruby webserver</a>, and one of the things that I have to do is parse a HTTP request. The method I've pasted below takes a HTTP request, and puts it in a map keyed by the <a href="http://en.wikipedia.org/wiki/List_o...
[]
[ { "body": "<p>I don't know if this is the best method to parse an HTTP request. You probably should have a look into one of the simpler ruby http servers out there to get some ideas. I do know though that you're doing some strange things here:</p>\n\n<pre><code>headers['Heading'] = request.gets.gsub /^\"|\"$/, ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T01:42:41.027", "Id": "30014", "Score": "5", "Tags": [ "ruby", "parsing", "http" ], "Title": "Parsing a HTTP request" }
30014
<p>I've recently read <a href="http://aaditmshah.github.io/why-prototypal-inheritance-matters/" rel="nofollow">this article</a>, and I agree that the <code>new</code> keyword is not good practice.</p> <p>Thus, I've made an improvement on <em>John Resig's Simple JavaScript Inheritance</em> in order to use the <code>Cla...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T11:57:50.470", "Id": "47640", "Score": "1", "body": "you are still using the 'new' keyword..." } ]
[ { "body": "<ul>\n<li><p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments/callee#Why_was_arguments.callee_deprecated.3F\" rel=\"nofollow\"><code>arguments.callee</code> is deprecated</a> and suggest you actually avoid it.</p></li>\n<li><p>What you...
{ "AcceptedAnswerId": "30077", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T07:07:12.603", "Id": "30018", "Score": "4", "Tags": [ "javascript", "inheritance" ], "Title": "Improving on John Resig's Simple JavaScript Inheritance: avoiding `new`" }
30018
<p>I've answered the following question as best as I could, but I need some help with my design and am wondering if I've taken the correct approach. I would appreciate it if anyone could please point out any mistakes I've made and any improvements I could make.</p> <p>Question:</p> <p>Please implement an address boo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-02-05T08:58:11.057", "Id": "292212", "Score": "0", "body": "What is \"Serializable\" used for in your case. Why do you need it?" } ]
[ { "body": "<p>I would use a <code>Set&lt;Contact&gt;</code> in the <code>AddressBook</code> class. This way there cannot be any duplicates. \nA AddressBook is more like a Set than a List. \nIf you want it sorted by name you can use a <code>TreeSet</code>.</p>\n\n<p>Union, intersection and difference can be imp...
{ "AcceptedAnswerId": "30040", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T07:23:46.217", "Id": "30019", "Score": "5", "Tags": [ "java", "serialization" ], "Title": "Simple address book in Java" }
30019
<p>This works fine but I find it quite big and had hoped there was a cleaner/smaller "toggle" function or alike which I could use but it seems to be related to visibility only - and I want to set a variable (for later usage).</p> <p>Can this be optimized, if I want a toggle function which should be used to sort a colu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T17:20:24.943", "Id": "47667", "Score": "0", "body": "You don't have any `th` elements in your HTML code" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T08:39:32.807", "Id": "47710", "Score": "...
[ { "body": "<p>Mostly I'ma java developer, but I think that there are a couple of things that you can do to tidy the code up.</p>\n\n<p>If you do not want to store state in the DOM then you can remove the jQuery data statements and store in the global scope. If I were a jQuery developer I would probably wrap thi...
{ "AcceptedAnswerId": "30037", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T07:51:02.047", "Id": "30020", "Score": "2", "Tags": [ "javascript", "jquery", "html5" ], "Title": "jQuery toggle sort order and save to variable" }
30020
<p>I have a piece of code that has a bit of a problem. Not that it doesn't work, though. The problem I am having is figuring out the optimal way of working with the MemoryStream, which I find quite difficult to do in this case.</p> <pre><code>while (checkBox1.Checked &amp;&amp; tt1.Connected) { tcpstream.R...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-11-03T22:50:42.217", "Id": "202032", "Score": "0", "body": "I'm voting to close this question as off-topic because it has become very convoluted, but shouldn't be reversed as the answer has already addressed the updates." } ]
[ { "body": "<p><strong>Edit - rewrite my entire answer</strong></p>\n<p>First off, I kind of misunderstood the purpose of lenArray. I sort of get it now, although I don't fully understand why your app is designed like that. I would perhaps use other means of getting Length instead of embedding that value into th...
{ "AcceptedAnswerId": "30042", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T11:03:01.070", "Id": "30029", "Score": "1", "Tags": [ "c#" ], "Title": "Can this be improved by working directly with the MemoryStream?" }
30029
<p>I've written a text parser that extracts useful information from a given text. Texts are formatted different, so there are different specialized parsers. I've designed them so that they all must define the methods from the interface Parser.</p> <pre><code>class Parser: def parse(text): raise NotImplemen...
[]
[ { "body": "<p>You could achieve that like this:</p>\n\n<pre><code>class Parser:\n def __init__(self):\n self.parse = self._validated_parsing(self.parse)\n\n def parse(self, text):\n raise NotImplementedError\n\n def pre_validate(self, text):\n raise NotImplementedError\n\n def p...
{ "AcceptedAnswerId": "30105", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T11:10:18.317", "Id": "30030", "Score": "1", "Tags": [ "python", "inheritance" ], "Title": "Inheritance and forcing methods to be called inside another method" }
30030
<p>Since Qt still does not support to set timeouts on <code>QNetworkRequest</code> objects, I wrote this little wrapper class:</p> <pre><code>/** Usage: new QReplyTimeout(yourReply, msec); When the timeout is reached the given reply is closed if still running */ class QReplyTimeout : public QObject { Q_OBJECT publi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-10-05T11:13:44.323", "Id": "195332", "Score": "0", "body": "class is quick and concise. I see no problems there." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-06-23T12:30:27.610", "Id": "316958", "Score...
[ { "body": "<p>Here are my thoughts:</p>\n\n<ol>\n<li><p>It's a simple class that allocates quite a few times on the heap. You could minimize the number of implicit allocations it does. The <code>QTimer::singleShot</code> creates a temporary <code>QObject</code> instance and allocates a bunch on the heap. You ca...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T12:59:30.637", "Id": "30031", "Score": "11", "Tags": [ "c++", "networking", "timeout", "qt" ], "Title": "QNetworkReply network reply timeout helper" }
30031
<p>I wrote this jQuery code to animate the opacity (sort of Fadein) of certain elements on my page in consecutive order. It feels very inelegant, though. </p> <pre><code>(function($) { function animateFadin($delayedElement, delayTime) { $delayedElement.delay(delayTime).animate({ opacity: 1 ...
[]
[ { "body": "<p>I think the best way of animation is CSS.\nI think the right way is <a href=\"http://www.w3schools.com/css3/css3_transitions.asp\" rel=\"nofollow\">css transitions</a> in your case. Try to add css modificators like <code>.show {opacity:1}</code> or <code>.hide {opacity:0}</code> to your CSS, then ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T17:54:05.093", "Id": "30044", "Score": "2", "Tags": [ "javascript", "jquery", "animation" ], "Title": "Animating the opacity of certain page elements" }
30044
<p>I need to remove inline javascript for a given string. Examples:</p> <p>If user typed: <code>&lt;img onload="something" /&gt;</code></p> <p>I should need to convert into <code>&lt;img /&gt;</code></p> <p>I created this PHP code and it works(apparently without issues):</p> <p><a href="http://writecodeonline.com/p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T20:22:45.470", "Id": "47684", "Score": "0", "body": "Dear lord, let us pray that Cthulhu doesn't get word of this. Regex _is not the tool for the job_! Parse the markup, iterate the nodes, and check the attributes. If an `onload` or...
[ { "body": "<p>Parsing markup with regex is like building your house using lego... it's not the right tool for the job. HTML is not <em>a regular language</em>, therefore <em>regular</em> expressions don't cut the mustard. More than that: <a href=\"https://stackoverflow.com/questions/1732348/regex-match-open-tag...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T17:58:47.520", "Id": "30045", "Score": "4", "Tags": [ "php", "regex" ], "Title": "Regex to remove inline javascript from string" }
30045
<p>I am trying to write my first script that checks users against a database (MySQL right now) and if they aren't in the database, registers them. I've tried my best to sanitize and validate the form data before setting variables to be used from it. I would love any constructive criticism or critiques on any aspect of ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T23:02:42.050", "Id": "47690", "Score": "0", "body": "Do you view your error logs when you run this? It may be worth it to define variables you first define in try-catch blocks to dummy values before you enter the try{}. After the ...
[ { "body": "<p>Good job using the database library with parameterized statements.</p>\n\n<p>Your error messages need to be more detailed. For example, the user would not know what you consider to be a valid password.</p>\n\n<p>Your <code>register.php</code> is long. Consider breaking it up into functions.</p>\...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T22:15:02.603", "Id": "30053", "Score": "2", "Tags": [ "php", "security", "php5" ], "Title": "Trying out my first User Registration script" }
30053
<p>Below is the code that I would like to refactor in order to avoid if-else statements in <code>cellForRowAtIndexPath</code> and <code>numberOfRowsInSection</code>.</p> <p>Depending upon what user selects, section order and <code>numberOfSections</code> will differ each time. <code>numberOfRowsInSection</code> will ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T15:08:38.903", "Id": "47927", "Score": "1", "body": "I haven't done programming on `ios` but this looks like C. So I'll put a comment instead of putting an answer. In your `(UIView *) tableView:(UITableView *)tableView viewForHeader...
[ { "body": "<p>In reviewing the code I've identified issues with architecture, code repetition, and code style.</p>\n\n<p>The canonical architecture for iOS apps is the <a href=\"http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller\" rel=\"nofollow noreferrer\">Model - View - Controller</a> pattern...
{ "AcceptedAnswerId": "30212", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T03:04:28.887", "Id": "30059", "Score": "2", "Tags": [ "objective-c", "ios" ], "Title": "Refactoring to avoid if-else in numberOfRowsInSection and cellForRowAtIndexPath" }
30059
<p>I've made a Tic-Tac-Toe program (non-AI) for 2 human players. I will implement AI for a computer player later on. I am a beginner programmer and am also new to classes, which I've implemented in this program. I want to know how this could be optimized.</p> <pre><code>//the main class is all the way at the end #in...
[]
[ { "body": "<ul>\n<li><p><code>insert()</code> and <code>win()</code> don't need to return something like an <code>int</code>, so they can both be <code>void</code>.</p>\n\n<p><strong>For <code>insert()</code></strong>, on the other hand, you have another return option: <code>bool</code>. If the insertion was s...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T03:41:19.583", "Id": "30060", "Score": "6", "Tags": [ "c++", "beginner", "performance", "game", "tic-tac-toe" ], "Title": "Tic-Tac-Toe optimization" }
30060
<p>I'm just looking for someone to give a critique of my currency converter. I want to see if I could clean it up first before dummy-proofing. I know you want to avoid floating types for working with money, so I made a <code>Cents</code> class. I'm not fully confident in how I did it, so any pointers on that would be ...
[]
[ { "body": "<ul>\n<li><p>You're not using <code>using namespace std</code> in your classes, which is good. However, for <code>Main.cpp</code>, it's best to put it inside the function instead of making it global.</p></li>\n<li><p><code>getSymbol()</code>'s parameter should be a <code>const&amp;</code> since it's...
{ "AcceptedAnswerId": "30062", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T03:54:49.533", "Id": "30061", "Score": "5", "Tags": [ "c++", "converting", "finance" ], "Title": "Currency converter" }
30061
<p>I just wrote this fuzzy snippet to identify any 2-byte character in my data file which assumes only 1-byte characters (ANSI). Please review and suggest me any better solution!</p> <pre><code>File.open('data.txt', 'r') do |f| line_number = 0 while line = f.gets line_number = line_number + 1 l...
[]
[ { "body": "<pre><code>File.open('data.txt', 'r') do |f| ... end\n</code></pre>\n\n<p>Good job. This is indeed the preferred way to read a file in Ruby. You get to read the file as a stream, and the file gets closed automatically. One thing to note is that the <code>r</code> flag is the default and can be left o...
{ "AcceptedAnswerId": "30071", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T06:39:08.817", "Id": "30064", "Score": "1", "Tags": [ "ruby", "unicode" ], "Title": "Ruby code to identify 2-byte characters" }
30064
<p>I have figures - <strong>TriangleItem</strong> and <strong>CircleItem</strong>:</p> <pre><code>public abstract class BaseItem { protected int _id; protected string _description; } public sealed class TriangleItem : BaseItem { public int TriangleId { get { return _id; } set { _id = value; } } public string ...
[]
[ { "body": "<p>I assume you really need to distinguish Circle and Triangle.\nAny way you can use auto-properties of base class.</p>\n\n<pre><code>public abstract class BaseItem\n{\n public int Id { get; set; }\n public string Description { get; set; }\n}\n\npublic sealed class TriangleItem : BaseItem\n{\n ...
{ "AcceptedAnswerId": "30073", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T08:47:30.920", "Id": "30067", "Score": "1", "Tags": [ "c#", "generics" ], "Title": "How to remove duplicated code? AOP and Generics are Ok" }
30067
<p>I am embedding my size in a Stream in the first 4 byte. When I think about it, it should be possible to do it better, but that depends.</p> <p>Here is how I currently do it:</p> <pre><code>bsize = ms.Length; tcp.GetStream().Write(BitConverter.GetBytes(bsize), 0, intsize); tcp.GetStream().Write(ms.GetBuffer(), 0, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T17:09:50.940", "Id": "47758", "Score": "0", "body": "are you getting an error when you try to write to the `tcp.GetStream()`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T17:18:12.797", "Id": "...
[ { "body": "<p>if you take and create two <code>Byte[]</code> Variables and fill the first with the information that you want to send then you can figure the size add it to the second <code>Byte</code> array and then append the information to the second array as well then just send the second <code>Byte</code> A...
{ "AcceptedAnswerId": "30091", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T08:53:05.473", "Id": "30068", "Score": "3", "Tags": [ "c#", "stream" ], "Title": "Embedding of size in Stream" }
30068
<p>I am trying to create a web crawler for student research. I have already finish it, but I would like to tell me if the way I use is the best one. (probably it isn't :p)</p> <p>The crawler is for the cnn site and the only thing I want to get, is the text of the news.</p> <p>Here is an example link: <a href="http://...
[]
[ { "body": "<p>The code looks good! A few comments:</p>\n\n<ul>\n<li>I'd use the requests library instead of urrllib2.</li>\n<li>Make sure to follow PEP8 (second line has a trailing whitespace and a space after the dictionary key).</li>\n<li>Use more semantic variable names than <code>div</code>, <code>text</cod...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T09:26:08.313", "Id": "30069", "Score": "3", "Tags": [ "python" ], "Title": "Crawler with BeautifulSoup" }
30069
<p>When my Debian server deploys it can run a shell script so I wanted to make one to install postgreSQL, create a role, create two databases and then import a schema into one. </p> <p>Can anyone please look at this code and tell me if I have done an ok job?</p> <pre><code> # POSTGRES apt-get install -y postgresql ec...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T08:17:40.280", "Id": "47830", "Score": "0", "body": "Personally, I like to use long-options in scripts, even for \"obvious\" options." } ]
[ { "body": "<p>I recommend using <code>psql -c command</code> for the first invocation of <code>psql</code>, or better yet, just use the <code>createuser</code> command.</p>\n\n<p>For the second invocation, you might want <code>psql -f /etc/schema.sql</code>. I would also suggest using the <code>--single-transa...
{ "AcceptedAnswerId": "30113", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T10:15:22.727", "Id": "30072", "Score": "3", "Tags": [ "sql", "bash", "shell", "postgresql" ], "Title": "Automating the install of PostgreSQL from Shell" }
30072
<p>Some adjustments a reviewer may make when reviewing a beginner's code are:</p> <ul> <li>Common practices and code styles that "everyone knows" may be absent, and that's OK. The reviewer will probably make note of these common practices without being "harsh".</li> <li>Assuming that language constructs used in the co...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T12:26:03.547", "Id": "30074", "Score": "0", "Tags": null, "Title": null }
30074
Add this tag to your question to indicate that you are new to the language of your code. This will often be taken into consideration by reviewers when assessing your code.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T12:26:03.547", "Id": "30075", "Score": "0", "Tags": null, "Title": null }
30075
<p>I wrote a simple program in Haskell which takes Hex input from stdin, converts the input to ascii and writes it to stdout. An example use:</p> <pre><code>$ echo -n '48656c6c6f2c2043522e534521' | unhex Hello, CR.SE! </code></pre> <p>And here the source code:</p> <pre><code>import qualified Data.ByteString as B imp...
[]
[ { "body": "<p>Calling <code>error</code> is fine for a small program like this.</p>\n\n<p>For more advanced error handling see the <a href=\"http://www.haskell.org/haskellwiki/Failure\" rel=\"nofollow\">Failure page on HaskellWiki</a>.</p>\n\n<hr>\n\n<p>Some comments about your code:</p>\n\n<pre><code>unhex (x:...
{ "AcceptedAnswerId": "30687", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T13:00:30.263", "Id": "30076", "Score": "3", "Tags": [ "haskell" ], "Title": "Hex to ASCII conversion in Haskell" }
30076
<p>I have the following jquery mobile + phonegap app. I'm finding when I load the app, the images in the separate pages load pretty slowly. Any advice on how to speed up loading this app?</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;meta name="format-detection" cont...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T13:27:54.420", "Id": "47847", "Score": "0", "body": "Can you reduce your code to only the parts concerned?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-18T20:26:56.083", "Id": "109355", "Score...
[ { "body": "<p>Instead of doing a separate function for <code>loadspace</code> and <code>loadcity</code> and <code>loadearth</code> could you do a function for <code>LoadCanvas</code>? or something like that, it just seems like you are writing the same code for each load, see if you can make it one function t...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T14:15:11.117", "Id": "30080", "Score": "4", "Tags": [ "javascript", "jquery", "performance", "json", "phonegap" ], "Title": "Speed up slow loading images?" }
30080