body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Before going out and learning a full fledged framework I'm trying to understand the MVC pattern coding basic stuff, at the moment I'm testing with MVC applied to form validation.</p> <p>After reading a good amount of articles and code examples I came out with my own version, nothing too elaborate as it's mostly for...
[]
[ { "body": "<p><strong>Directory Structure</strong></p>\n\n<p>When implementing a heavy design pattern like MVC, the best thing to do is set up your directory structure to support it. For example, you currently have, at the very least, your Model and Controller in the same directory. When dealing with just a few...
{ "AcceptedAnswerId": "15546", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T05:06:31.340", "Id": "15530", "Score": "5", "Tags": [ "php", "design-patterns", "mvc", "form" ], "Title": "Correct MVC pattern implementation for form validation" }
15530
<p>This is just my simple structure. I want to know if there is a better way than this because I have so many lines of code already.</p> <pre><code> &lt;?php $p1speed = 5; $p2speed = 3; //way for next turn: 1 for turn $p1 = 0; $p2 = 0; if($p1speed&gt;$p2speed) { $p1 = 1; $p2 = 0; } else if($p2speed&gt;$...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T07:09:47.347", "Id": "25206", "Score": "0", "body": "What are you trying to achieve? Is the 5 in the while loop fixed?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T07:13:12.027", "Id": "25208",...
[ { "body": "<p>If the 5 in the while loop is fixed you can simply unroll it as: [C code, but I hope you get the idea]</p>\n\n<pre><code>void turn(int player);\n\nvoid foo(){\n int p1speed = 3;\n int p2speed = 5;\n\n int first_player;\n int second_player\n\n if(p1speed &gt; p2speed){\n first...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T06:58:56.220", "Id": "15531", "Score": "2", "Tags": [ "php" ], "Title": "\"P1 attacks P2\" and \"P2 attacks P1\"" }
15531
<p>I have a java based server application that needs to support multiple clients. In the main class I have a method that runs in an infinite loop and waits for client connection. Following is this method:</p> <pre><code>public void listen() { try { serverSocket = new ServerSocket(portNo); while (tr...
[]
[ { "body": "<p>I think it's possible to test this method with another threads and some helper code which passes fix requests to your server and checks the server's answer. It definitely requires some work and I'm not sure how should we call this test: unit test, module test or integration test? Anyway, make sure...
{ "AcceptedAnswerId": "15541", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T10:04:00.810", "Id": "15534", "Score": "3", "Tags": [ "java", "unit-testing", "junit" ], "Title": "Designing a listener method and making it Testable" }
15534
<pre><code>/* Create a random maze */ package main import ( "fmt" "math/rand" "time" ) const ( mazewidth = 15 mazeheight = 15 ) type room struct { x, y int } func (r room) String() string { return fmt.Sprintf("(%d,%d)", r.x, r.y) } func (r room) id() int { return (r.y * mazewidt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T14:12:36.663", "Id": "25222", "Score": "2", "body": "Looks very good to me. To be perfect you could produce the test and benchmark files too..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-10-09T08:20:06...
[ { "body": "<p>General notes:</p>\n\n<ul>\n<li>the code would benefit from splitting it into more methods,</li>\n<li>go uses camelCaseConvention, not onlylowerletters.</li>\n</ul>\n\n<p>Now, some particulars.</p>\n\n<pre><code>stack = append(stack, room{0, 0})\n</code></pre>\n\n<p>You can use <code>start</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T13:57:54.650", "Id": "15539", "Score": "11", "Tags": [ "random", "go" ], "Title": "Creating random maze in Go" }
15539
<p>This is my C# class, which takes 2.6s:</p> <pre><code>class Snake { readonly Symbol _mySymbol; readonly int _multiplier; readonly int _hit; readonly int _payout; readonly Snake _bestSnake; public Symbol MySymbol { get { return _mySymbol; } } public int Multiplier { get { return _multipl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T16:00:49.010", "Id": "25223", "Score": "2", "body": "Could you also provide the code that you used to measure the performance? What exactly did you measure?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-0...
[ { "body": "<p>There are a few small differences in your translation. I would start with as literal a translation possible, then optimize/make idiomatic from there. If done incrementally it should be easy to spot performance problems as they occur. Here's a starting point:</p>\n\n<pre class=\"lang-ml prettyprint...
{ "AcceptedAnswerId": "15547", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T15:39:15.317", "Id": "15542", "Score": "5", "Tags": [ "c#", "performance", "f#" ], "Title": "Rewriting C# implementation of Snake class in F#" }
15542
<p>For something I'm doing, it would just make things so much easier, quicker, and cleaner to have C# style events. I've written a class I believe should replicate a C# style event using reflection. Since I've never actually used reflection before in any meaningful sense, I'm very much not happy using it without, at th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T20:05:13.083", "Id": "25234", "Score": "0", "body": "Have you considered creating an anonymous class that call the event handler instead of string method names?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>Your listener is pair {object, method name}.\nIn Java, typical approach is to represent listener as a single object, which implements specific interface. This way we do not need reflection, things work faster, and errors are discovered at compile time, not run time.</p>\n", "comments": [ ...
{ "AcceptedAnswerId": "15602", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T19:27:50.853", "Id": "15549", "Score": "5", "Tags": [ "java", "event-handling" ], "Title": "Replicating C#-style events in Java using reflection" }
15549
<p>Recently I have written an <code>SslStream</code> class asynchronously authenticate clients and receive message from them. I still would like anyone to suggest improvements for my code.</p> <pre class="lang-c# prettyprint-override"><code>using System; using System.Collections.Generic; using System.Linq; using Syste...
[]
[ { "body": "<p>I like the layout</p>\n\n<p>First thing, move your using statements out of the namespace declaration, and remove unused references (I use Resharper, but there is a command in VS that will do this for you, I just can't remember it):</p>\n\n<pre><code>using System;\nusing System.Collections.Generic;...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T21:37:55.913", "Id": "15550", "Score": "3", "Tags": [ "c#", "asynchronous", "console", "socket", "authentication" ], "Title": "Asynchronous SSLSTREAM" }
15550
<p>I have recently received some feedback on a project I did called <a href="https://github.com/rlemon/Notifier.js" rel="nofollow">Notifier.js</a>, in which you can see I have included all of the source images and styles in the JavaScript file. The feedback I received was that having it all bundled up together may be <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T22:27:28.797", "Id": "25246", "Score": "1", "body": "At the very least for option 1) you can use tools to bundle all your js into one minified file when loading onto the live site, and for test sites leave them separated for debuggi...
[ { "body": "<p>Site loading performance depends on the number of HTTP request in many cases. The less of them, the better. This rule justify your reasoning to keep everything in one file that is being loaded with one request.</p>\n\n<p>There are, however, two things that should also be considered:</p>\n\n<ol>\n<...
{ "AcceptedAnswerId": "15595", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T22:19:59.823", "Id": "15551", "Score": "5", "Tags": [ "javascript", "performance" ], "Title": "Single and multiple files" }
15551
<p>Totally new to MVP and Spring, and I have what seems to be typical MVP application that uses Spring, where the presenter is instantiated like: </p> <pre><code>IApplicationContext ctx = ContextRegistry.GetContext(); presenter = (clsPresenter)ctx.GetObject("clsPresenter"); </code></pre> <p>I hate using strings to ca...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-13T09:11:15.107", "Id": "25279", "Score": "0", "body": "Isn't Spring for Java? Or do you mean Spring.Net? Or something else?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-13T14:32:20.973", "Id": "2530...
[ { "body": "<ol>\n<li><p>Not sure if that is just the case in your example but it's rather uncommon in C# to prefix classes with <code>cls</code> or <code>class</code>. In fact the only commonly used type identifier as part of the type name is usually the <code>I</code> prefix for interfaces.</p></li>\n<li><p>Me...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T23:25:59.423", "Id": "15554", "Score": "4", "Tags": [ "c#", "spring" ], "Title": "Avoiding using strings when using Spring.Net by incorporating instantiation in class" }
15554
<p>I have written following code to find the minimum difference from a list of numbers.</p> <p>Because I am using a loop once and LINQ again to find the minimum, the algorithm is O(N<sup>2</sup>).</p> <p>Can you please tell me if I am using the framework in the most optimal way (speed and memory utilisation) to achie...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-11T16:26:31.783", "Id": "25249", "Score": "5", "body": "O(N2) == O(N) so don't worry. Your main cost here is I/O, not the calculations." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-11T16:38:33.477", ...
[ { "body": "<p>First of all using LINQ method <code>Min</code> is not making this algorithm \\$O(n^2)\\$. If you want to avoid this call, you can calculate min \"in-place\":</p>\n\n<pre><code>//...\n\nvar min = int.MaxValue;\n\nfor (int k = 0; k &lt; intList.Count-1; k++)\n{\n min = Math.Min(min, intList[k + ...
{ "AcceptedAnswerId": "15573", "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-11T16:12:22.530", "Id": "15555", "Score": "3", "Tags": [ "c#", "performance", "algorithm", "linq" ], "Title": "Finding the minimum difference in a list of numbers" }
15555
<p>In other languages, I prefer to arrange source files so that simpler and more widely useful concepts are introduced before implementation details, and I try where possible to make complex implementation details top-level functions so that I can separate them out and let the main function read like a high-level algor...
[]
[ { "body": "<p>It's not idiomatic OCaml indeed.</p>\n\n<ol>\n<li>\"and\" is an effective way to say \"watch out for mutual recursion\".</li>\n<li>OCaml encourages you to use nested functions instead! As <a href=\"http://mirror.ocamlcore.org/ocaml-tutorial.org/the_structure_of_ocaml_programs.html\">The Structure ...
{ "AcceptedAnswerId": "15562", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T23:46:27.463", "Id": "15558", "Score": "3", "Tags": [ "ocaml" ], "Title": "Is this use of (let ... and ...) in OCaml poor style?" }
15558
<p>The need is to get the possibility to differentiate between a Barcode-Scanner (which behaves like a keyboard) from a human pressing keys in a...let's say a Textbox (the use case would be all over everything, wherever I expect a barcode scanner).</p> <p>The basic idea was to create a buffer which holds the typed str...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-06-04T03:13:40.220", "Id": "168217", "Score": "0", "body": "so i'm assuming this is a HID scanner. Is there a SDK that came with it? if there is you might have a better way of checking if the scanner was used. Another possibility is if y...
[ { "body": "<p>Using DateTime to check the timespan is not as accurate or as good as just using the <code>System.Diagnostic.Stopwatch</code> class. Plus the stopwatch class has a <code>ElapsedMilliseconds</code> already. So you can switch out <code>LastChange</code> with a stopwatch, and everytime you set it to ...
{ "AcceptedAnswerId": "92760", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-13T12:55:20.547", "Id": "15570", "Score": "3", "Tags": [ "c#" ], "Title": "Differentiate a Keyboard-Scanner from Keyboard: TimeoutBuffer" }
15570
<p>I've made a simple program that can calculate the area of various 2D shapes. I'd like your expereanced eyes to asses my code. Be as harsh as you want but please be <strong>specific</strong> and offer me ways in which I can improve my coding.</p> <pre><code>shape = ("triangle","square","rectangle","circle") ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-13T16:55:24.913", "Id": "25319", "Score": "1", "body": "The `if start_up != (\"yes\" or \"no\"):` is still wrong; `('yes' or 'no')` is `'yes'`. You're looking for `not in` or 2 inequality tests." } ]
[ { "body": "<p>Since you're not using shape extensively I would get rid of that data structure all together. It would be easier to read inline then having to look to the margin for comments.</p>\n\n<p>For example:</p>\n\n<pre><code> if target_shape == 'square': \n l = flo...
{ "AcceptedAnswerId": "15581", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-13T13:48:37.777", "Id": "15572", "Score": "5", "Tags": [ "python", "beginner", "computational-geometry" ], "Title": "Calculating the area of various 2D shapes" }
15572
<p>I just figured out <a href="http://projecteuler.net/problem=12" rel="nofollow">Project Euler problem #12</a>. This the first one I've done in Python, so I'm putting my code out there to hopefully get some constructive criticism. </p> <p>If anyone is interested, would you mind looking over my solution and letting me...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T04:02:03.143", "Id": "25305", "Score": "0", "body": "I quick run through the [`pep8`](http://pypi.python.org/pypi/pep8) program should point out any style improvements. [PEP-0008](http://www.python.org/dev/peps/pep-0008/) is the \"s...
[ { "body": "<pre><code>from math import*\n</code></pre>\n\n<p>Missing space?</p>\n\n<pre><code> for i in range(1, integerSqrt - 1):\n if n % i == 0:\n nDivisors += 2\n</code></pre>\n\n<p>I'm not saying it's better here, but you can achieve a lot with list comprehensions. For example, <code>2...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-12T03:57:28.800", "Id": "15577", "Score": "2", "Tags": [ "python", "project-euler" ], "Title": "Python Code Review - Project Euler #12" }
15577
<p>Goal:</p> <ol> <li>Extract all Appendix Titles</li> <li>If Appendix Title is Answer Key call custom solutions template</li> <li>If Not Answer Key call default appendix template</li> </ol> <p>XML:</p> <pre><code>&lt;appendix&gt; &lt;title&gt;Appendix A&lt;/title&gt; &lt;section&gt;data&lt;/section&gt; &lt;/app...
[]
[ { "body": "<p>I don't see how that <code>&lt;xsl:otherwise&gt;</code> would ever do anything based on your sample xml. The template matches on <code>appendix/title</code> so your context would be the title element. Applying templates to appendix children of title would be a no-op. I think something like this wo...
{ "AcceptedAnswerId": "18279", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-13T17:21:21.780", "Id": "15582", "Score": "3", "Tags": [ "optimization", "beginner", "xml", "xslt" ], "Title": "Appendix answer key template" }
15582
<p>I'm in the process of doing some mapping of POCOs via IDataReader. I'd love to hear thoughts on the approach and if they are any good ways to improve what I have done. </p> <pre><code>public class Code { public int Id { get; set; } public string Type { get; set; } public string Value { get; set; } p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T20:53:05.193", "Id": "25449", "Score": "0", "body": "I agree with the posted answer except you should only catch specific exceptions or at best ApplicationException. Wrapping a System exception such as insufficient permissions or a...
[ { "body": "<p>Most of it looks good. That is until I get to your catch statement:</p>\n\n<pre><code>catch (Exception)\n{\n throw new Exception(\"Error creating Code objects from reader.\");\n}\n</code></pre>\n\n<p>really does not explain why you are having. I would suggest either creating your own exceptio...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-13T17:24:36.897", "Id": "15583", "Score": "3", "Tags": [ "c#", "asp.net" ], "Title": "Using C# generics and factory classes to map IDataReader to POCO?" }
15583
<p>One of the things I wanted to do was make it impossible to forget to initialise or forget to cleanup WSA. Often the network examples will return as soon as an error occurs (say an socket didn't bind) this means you have to remember to add <code>WSACleanup()</code> before each return and I don't like that.</p> <p>I ...
[]
[ { "body": "<p>Without looking at the details, it seems that you have too many classes. A base class for all sockets that takes care of freeing the resources is fine. A listen socket that waits for incoming connections is fine, too.</p>\n\n<p>But I don't get the need for AcceptingSocket and TransmittingSocket, b...
{ "AcceptedAnswerId": "15866", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-13T20:39:50.400", "Id": "15589", "Score": "5", "Tags": [ "c++", "classes", "networking", "socket" ], "Title": "Simple Socket class hierarchy" }
15589
<p>I've just coded a hex to integer converter in C and want my code criticized. I did not cover switch statements so I know that can be improved. I am also planning to truncate "0x" in the beginning of the input if the user enters that.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;ctype.h&gt; #include &lt;mat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T19:31:10.597", "Id": "25405", "Score": "0", "body": "If you're going to include ctype.h, you might as well use isxdigit, or at least isdigit in the places where you do the '0' and '9' comparisons." } ]
[ { "body": "<ul>\n<li><p>Your <code>hexArray</code> has a static size of <code>MAXCHAR</code> but you never check if you didn't exceed this size when reading input. Consider what would happen if someone enters <code>MAXCHAR+1</code> characters at input.</p></li>\n<li><p>When you set last character in your <code>...
{ "AcceptedAnswerId": "15605", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T08:08:11.760", "Id": "15604", "Score": "2", "Tags": [ "c", "converting" ], "Title": "Hex to integer converter" }
15604
<p>I'm writing a monadic parser instance that transforms Data.Map.Map's:</p> <pre><code>instance (Ord a, FromEDN a, FromEDN b) =&gt; FromEDN (M.Map a b) where parseEDNv (E.Map m) = mapMmap parseEDNv parseEDN m parseEDNv v = typeMismatch "Map" v </code></pre> <p>Data.Map doesn't provide it's own mapM version l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-28T04:51:53.413", "Id": "74212", "Score": "0", "body": "Have you considered traverseWithKey?" } ]
[ { "body": "<p>There is <code>keys</code> library which implements </p>\n\n<pre><code>mapWithKeyM_ :: (FoldableWithKey t, Monad m) =&gt; (Key t -&gt; a -&gt; m b) -&gt; t a -&gt; m ()\n</code></pre>\n\n<p>and related functions for <code>Data.Map</code>.</p>\n\n<p>There is also <code>Data.Traversable.mapM</code>,...
{ "AcceptedAnswerId": "15609", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T08:53:34.937", "Id": "15606", "Score": "3", "Tags": [ "haskell" ], "Title": "mapM for both keys and values of Data.Map" }
15606
<p>Consider the following code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; using namespace std; struct test { int j; test&amp; operator&gt;&gt;(int &amp; i) { i = ++j%26; return *this; } operator bool() { return j%26; } }; int main () { test t; int i; while (t &gt;&gt; i...
[]
[ { "body": "<p>For simple 10 lines 10 programs you can get away with this:</p>\n\n<pre><code>using namespace std;\n</code></pre>\n\n<p>Anything bigger and it starts to be a pest more than a help. Thus it best not to get into the habit of using it. Anyway it is simpler even in this case just to prefex cout with s...
{ "AcceptedAnswerId": "15624", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T12:44:04.517", "Id": "15613", "Score": "2", "Tags": [ "c++" ], "Title": "Custom stream-like classes" }
15613
<p>I have the following:</p> <pre><code> public class ContentsController : BaseController { private IContentService _content; private IPageService pageService; private IReferenceService _reference; private ISequenceService seqService; public ContentsController( IC...
[]
[ { "body": "<p>IMHO, member variables should begin with an underscore and be descriptive</p>\n\n<p>This is fine</p>\n\n<pre><code>private IContentService _content;\n</code></pre>\n\n<p>This is better</p>\n\n<pre><code>private IContentService _contentService;\n</code></pre>\n\n<p>BTW, using '<code>this.</code>' i...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T13:01:02.493", "Id": "15614", "Score": "3", "Tags": [ "c#", "asp.net-mvc-3" ], "Title": "What standard should I use for the naming of my MVC controller services?" }
15614
<p>I have the following code:</p> <pre><code> public string GetRefStat(string pk) { return RefStat[pk.Substring(2, 2)]; } private readonly Dictionary&lt;String, int&gt; RefStat = new Dictionary&lt;string, int&gt; { {"00", REF.MenuType, } // Menu {"01", REF.ReferenceSta...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T14:10:19.677", "Id": "25372", "Score": "2", "body": "Your code won't compile. The dictionary contains `int`s, but the method returns `string`s. Also, some commas in your definition of the dictionary are misplaced (they should outsid...
[ { "body": "<p>Your code is short, readable and efficient, so I don't think it needs much improvement. And I don't think adding a static class would give you anything (although changing the field and the method to <code>static</code> could make sense).</p>\n\n<p>Another way to write your code would be to use <co...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T13:42:02.587", "Id": "15617", "Score": "2", "Tags": [ "c#" ], "Title": "Simplifying dictionary of constant values" }
15617
<p>I am trying to figure out a better way to attach the icons based on the class id.</p> <p><a href="http://jsfiddle.net/fLZKc/2/" rel="nofollow">Here</a> is the link.</p> <pre><code>var bubble = "M16,5.333c-7.732,0-14,4.701-14,10.5c0,1.982,0.741,3.833,2.016,5.414L2,25.667l5.613-1.441c2.339,1.317,5.237,2.107,8.387,2....
[]
[ { "body": "<p>You could also create a utility function that takes a class selector and a path and then does the needful. Furthermore you repeat very much <code>{\"fill\": \"#fff\"}</code>, that should be well named variable.</p>\n\n<p>Given these 2 observations, you could write the code this way:</p>\n\n<pre><c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T14:24:44.187", "Id": "15620", "Score": "3", "Tags": [ "javascript", "jquery", "raphael.js" ], "Title": "Generate Raphael icons on a page" }
15620
<p>I am making a query in mysql to import users in our marketing system and need for this a lot of data like for example :</p> <ul> <li>Date of last order</li> <li>Date of last cheque created</li> <li>...</li> </ul> <p>This are all left joins where I just want the last result with conditions. For the moment I do just...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T19:28:16.497", "Id": "62840", "Score": "0", "body": "Add this:\norder by left_table.required_field limit 1" } ]
[ { "body": "<p>Can you use temp tables? I think that's generally the best idea... using a lot of subqueries can get nasty real quick. Here's my version:</p>\n\n<p>(I'm not able to test it so use it at your own risk. Also if you use temp tables, you'll still probably want to define your datatypes in the CREATE...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T15:30:39.670", "Id": "15622", "Score": "1", "Tags": [ "performance", "mysql", "sql" ], "Title": "Mysql left joins last row" }
15622
<p>I have the following function to confirm if a directory contains files:</p> <pre><code>/** * Check if the directory is empty * * Function to ascertain if the specified directory contains files. * Comparing to two, because parent and current are present inside * the returned array. Only 3+ denotes files on the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T19:20:18.087", "Id": "25404", "Score": "0", "body": "As a side note, depending on the file system, a million files in a directory might be a bad idea." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T1...
[ { "body": "<p>Why is there a catch for a PDOException? Also, why are you masking it with another exception? That doesn't make much sense. How is the final catch block supposed to know what it's actually catching?</p>\n\n<hr>\n\n<p>Anyway, you need to use a lower-level method than scandir. You could use a <a...
{ "AcceptedAnswerId": "15628", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T16:12:27.987", "Id": "15623", "Score": "2", "Tags": [ "performance", "file-system", "php5" ], "Title": "Checking if a directory is empty when having over a million files inside...
15623
<p>I've done some tinkering about with Knockout in search for a better solution on how to bind select lists (dropdowns). I came up with a extender in combination with a binding.</p> <p>Extender:</p> <pre><code>ko.extenders.selectList = function (target, params) { var result = ko.computed({ ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-07T16:16:18.187", "Id": "70623", "Score": "0", "body": "This is an old question, but still, it would be great it you could update your fiddle, right now it stopped working because it relies on http://cloud.github.com/downloads/SteveSan...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>Your indentation in <code>ko.extenders.selectList = function (target, params) {</code> should be 4 spaces to make it far more readable</li>\n<li><p><code>write</code> could use a ternary approach:<br></p>\n\n<pre><code>write: function (newValue) {\n target( newV...
{ "AcceptedAnswerId": "41161", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T16:48:34.300", "Id": "15625", "Score": "3", "Tags": [ "javascript" ], "Title": "Knockout selectlist binding" }
15625
<p><strong>Router</strong> is a <strong>generic class</strong> that manage multiple contracts that. It is able to find out wheter it's an online or offline situation, on the very moment when an <strong>operation</strong> is being made. </p> <p>There's a really easy way of doing it: a class for each Online-Offline pair...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T17:37:56.973", "Id": "25388", "Score": "1", "body": "I'm not familiar with Unity, but this seems like something you should be able to do in your `ICallHandler`. I'm quite sure you could do this with Castle, which has something very ...
[ { "body": "<p>Ok, finally, I have the solution for this. I'll share it because I find this really helpful in such Online-Offline scenarios. There's a little improvement that would be nice to do: this way, Online will always be hitted first, it would be nice to set whom has to be used first. But that's for the r...
{ "AcceptedAnswerId": "15872", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T17:02:50.387", "Id": "15626", "Score": "6", "Tags": [ "c#", "generics" ], "Title": "Online-Offline Class Manager" }
15626
<p>This is a simple script to make ls output first folders, then files, then other stuff (symlink). I think this is really neat and would like to share the script in exchange for comments.</p> <p>It should be noted that I'm working with <em>GNU findutils</em> and <em>coreutils</em>.</p> <p><strong>Some basic criteria...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T18:45:30.370", "Id": "25399", "Score": "0", "body": "Alright, done. Good points." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T14:09:50.920", "Id": "67492", "Score": "0", "body": "The co...
[ { "body": "<ol>\n<li>If you use <code>getopt</code> or <code>getopts</code> to parse the options, you can use multiple options together, and it would simplify your code quite a bit. <a href=\"https://github.com/l0b0/tilde/blob/e48ba0c2c892ac2426a1e6b6e5f9930253398b70/scripts/make-links.sh#L67\" rel=\"nofollow\"...
{ "AcceptedAnswerId": "15983", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T17:11:08.057", "Id": "15627", "Score": "5", "Tags": [ "bash" ], "Title": "An attempt at making a neat ls" }
15627
<p>I there a better way to write this query? I feel sure it can be done in one statement with joins, but I couldn't get it, and I'm afraid I've made it too slow. What suggestions do you have? I'm running it in SQL Server 2000 (yeah, I know, upgrade is coming).</p> <p>Basically, I want to match estimated and actual ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T21:10:54.050", "Id": "25418", "Score": "1", "body": "Small remark: why are you doing something like `'' as Est` rather than `null as Est`? I think you are forcing an unnecessary cast. I do not think a join will help. Algorithmically...
[ { "body": "<p>First off, it's not a stored procedure, it's a view.</p>\n\n<p>That said, the main change I would make is to use a CTE, once you have upgraded.</p>\n\n<pre><code>ALTER view [dbo].[JobCost_EstVsAct]\n --SELECT * FROM JobCost_EstVsAct Where jobnumber = '122773'\nAS\nWITH cte1 as (\n SELECT Job...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T19:44:35.797", "Id": "15630", "Score": "3", "Tags": [ "optimization", "sql", "sql-server" ], "Title": "SQL view, better way?" }
15630
<p>I've just got a Raspberry Pi, so I thought I'd try my hand at some Python. This is my first ever Python program (hurrah!).</p> <p>It's a very simple command-line implementation of noughts and crosses. The computer opponent's strategy is simply to pick at random, the code is very verbose in places and there's no way...
[]
[ { "body": "<h3>1. Introduction</h3>\n\n<p>If this is your first Python program, then it's not too bad at all. There are a whole host of things that can be improved, but there are also a good few things you got right. For example, your code is pretty well-commented. Also, I liked the response \"Invalid input. Ty...
{ "AcceptedAnswerId": "15634", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T21:08:37.983", "Id": "15631", "Score": "13", "Tags": [ "python", "beginner", "game", "console" ], "Title": "Command-line noughts and crosses" }
15631
<p>After reading Herb Sutter's <a href="http://www.drdobbs.com/windows/associate-mutexes-with-data-to-prevent-r/224701827" rel="nofollow noreferrer">Associate Mutexes with Data to Prevent Races</a>, I found that my solution was superior in several aspects, least important first:</p> <ul> <li>The code is cleaner, witho...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T23:14:18.330", "Id": "25431", "Score": "7", "body": "<quote>I found that my solution was superior in several aspects</quote> Brave words." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T20:57:48.010",...
[ { "body": "<p>Since the only place you should be creating a <code>LockedProxy</code> from is within the call <code>Lockable::GetLockedProxy()</code> you should therefore make the constructor private and friend this function. You don't actually want to give people the ability to make objects of this type themsel...
{ "AcceptedAnswerId": "15654", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-14T21:16:49.013", "Id": "15632", "Score": "15", "Tags": [ "c++", "c++11", "locking", "boost" ], "Title": "Force locking for thread-safety" }
15632
<p>I am looking for pointers / comments / critiques regarding the below code. One major flaw I know is that I need to define Nodes first and then manually join them to create a List.</p> <p>Are there any flaws apart from that? C++ programming style errors? RAII?</p> <pre><code>#include&lt;iostream&gt; template&lt;ty...
[]
[ { "body": "<p>First of all, <code>Node</code> should definitely be a nested type of <code>List</code> -- there's no need to ever expose nodes to the users of the list. You should also be the one to manage the lifetime of the node. You definitely don't want users of the list to be able to assign the <code>next...
{ "AcceptedAnswerId": "15653", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T01:52:42.317", "Id": "15636", "Score": "3", "Tags": [ "c++" ], "Title": "LinkedList in C++" }
15636
<p>I have the following function to insert a new row into a table:</p> <pre><code>/** * Insert row into the designated table * * Function to add a new row into the designated table * * @param str $table Table name to insert the row * @param arr $data Array with values * * @return int ...
[]
[ { "body": "<p>As long as the <code>$table</code> variable is properly scrubbed / initialized you are fine as far as secure goes.</p>\n\n<p>However, I don't care for the insert statement format where you do not specify the column names. For this to work for any insert statement for any table you would have to m...
{ "AcceptedAnswerId": "15639", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T03:12:56.103", "Id": "15637", "Score": "3", "Tags": [ "optimization", "security", "php5", "pdo" ], "Title": "Secure row insertion using a position-based prepared statement"...
15637
<p>Please comment on the same. How can it be improved?</p> <p>Specific improvements I am looking for:</p> <ol> <li>Memory leaks</li> <li>C++ style</li> <li>Making code run faster</li> <li>RAII</li> </ol> <p></p> <pre><code>#include&lt;iostream&gt; #include&lt;algorithm&gt; template &lt;typename T&gt; class Stack {...
[]
[ { "body": "<p>First of all, I would specify that your stack is using a \"dynamically allocated array\", as opposed to just an array, as I at first expected a C array when looking at the title. That varies from person to person, though.</p>\n\n<p>On to more important things:</p>\n\n<ul>\n<li>I would not print a...
{ "AcceptedAnswerId": "15644", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T04:41:46.070", "Id": "15640", "Score": "4", "Tags": [ "c++", "array", "stack" ], "Title": "Stack implementation using arrays" }
15640
<p><img src="https://i.stack.imgur.com/uXeQb.png" alt="enter image description here"></p> <p>I'm designing a client (UI made with WPF) and server (WCF) that communicates with a device known as DDC (Direct Digital Control). A user on the client side can make requests to adjust the state of the DDC, then the server rece...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-25T08:22:46.480", "Id": "116688", "Score": "0", "body": "Any final _solution_ with **full source code** sample application ? _IMHO, better samples for minimize learning curve are real \n\napplications with full source code and good pat...
[ { "body": "<p>Rather than based on return types or parameters I think it would be best to base it on the functional grouping of the operations so that those more closely related are all grouped into one contract. Much like you might consider when naming namespaces and putting classes in there. </p>\n\n<p>It's ...
{ "AcceptedAnswerId": "15652", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T12:08:53.940", "Id": "15646", "Score": "5", "Tags": [ "c#", ".net", "wcf" ], "Title": "Allowing a client and server to communicate with a DDC" }
15646
<p>I have a custom class for Smarty that was partially borrowed. This is how the only example reflects the basic idea of using it across my current project:</p> <pre><code>class Template { function Template() { global $Smarty; if (!isset($Smarty)) { $Smarty = new Smarty; } ...
[]
[ { "body": "<p>Well, there's a few things wrong here, but let's go over it together and I'll try to steer you in the right direction. Let's start with globals. Globals are extremely bad and should be avoided at all costs. If you have a variable that needs to be available in multiple parts of your script, then yo...
{ "AcceptedAnswerId": "15658", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T13:44:54.510", "Id": "15648", "Score": "3", "Tags": [ "php", "beginner", "smarty" ], "Title": "Assigning defaults for Smarty using object-oriented style" }
15648
<p>I created a script to allow a user to drag a <code>div</code> around the page and save it's position and style to <code>localStorage</code>, and I'm wondering if there's anything I can do to make the script more efficient. I have posted the code below, but I left out the drag functionality because I'd like to work o...
[]
[ { "body": "<p>Looks ok so far. Here are some tips.</p>\n\n<h1>1)</h1>\n\n<p>Only provide comments for sections arounds complex code. Also, it's best to place comment directly above the statements and not side by side.</p>\n\n<p>Bad:</p>\n\n<pre><code>$(\".base\").each(function () { // (1) Find each div with the...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T21:44:06.103", "Id": "15656", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Feedback on JS that drags elements around page and saves styles to localStorage?" }
15656
<p>I am trying to teach myself haskell by means of project Euler</p> <p>i sovled <a href="http://projecteuler.net/problem=9" rel="nofollow">problem #9</a> by means of this code which is on the brute force side I was wondering if there is a more elegant/haskell/efficient solution</p> <pre><code>let project_euler_9 = [...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-16T07:56:17.163", "Id": "25469", "Score": "0", "body": "Your solution main not be the fastest one but it's easy to read. Here's another [solution](http://scrollingtext.org/project-euler-problem-9). Also, shouldn't you return the produc...
[ { "body": "<p>As already mentioned there are formulas for enumerating the pythagorean triples, but your solution can be made quite fast by bounding the search space more. You have already taken care of the symmetry in the solutions by letting <code>a</code> be less then <code>b</code> (<code>a &lt;- [1..b]</cod...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T22:21:35.003", "Id": "15657", "Score": "5", "Tags": [ "haskell", "project-euler", "programming-challenge" ], "Title": "Project Euler #9 in haskell" }
15657
<p>Just for fun, I want to try to write this Ruby function more succinctly. I imagine it can be done, I'm just not knowledgeable enough with Ruby yet to know how. Any suggestions?</p> <pre><code> def tags return ['Cancelled'] if cancelled? tags = [] tags &lt;&lt; 'Filled' if filled? tags &lt;&lt; 'In ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T12:31:45.963", "Id": "25460", "Score": "3", "body": "@Mark: The question is indeed in the frontier with codereview. But this thing is, a code review is usually broader, on longer code that may have many things to address. Here is ju...
[ { "body": "<p>Functional approach:</p>\n\n<pre><code>def tags\n if cancelled?\n [\"Cancelled\"]\n else\n [(\"Filled\" if filled?), (\"In Progress\" if in_progress?)].compact\n end\nend\n</code></pre>\n\n<p>Ideas behind the snippet:</p>\n\n<ul>\n<li>Don't perform imperative side-effects on arrays (unles...
{ "AcceptedAnswerId": "15663", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-15T11:10:51.337", "Id": "15660", "Score": "14", "Tags": [ "ruby" ], "Title": "Is there a more succinct way to write this Ruby function?" }
15660
<p>I'm about a week into learning pdo. I've created, with help from an example online, a database connection function. I have a config file with all my info (username, pass, database, host) and a function inside a file called <code>db.php</code>. Everything works great with the function below. </p> <p>Though, I ha...
[]
[ { "body": "<p>Globals are indeed a bad thing. They are old and full of security issues as well as being nearly impossible to debug. Stay away from them at all costs. Instead, pass those variables as a parameter into any function that needs them and have the function return any modifications if necessary. Once y...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-16T01:02:02.763", "Id": "15666", "Score": "2", "Tags": [ "php" ], "Title": "Better Database Connection Function" }
15666
<p>I have a set of Service, and I want to partition them into ServiceClass, and have a reference from a Service to the Service class its belong. I am storing the reference in <code>Dictionary&lt;Service, ServiceClass&gt;</code>.</p> <p>In the code below, I want to split into five service classes. I feel the code below...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-16T20:40:31.303", "Id": "25482", "Score": "0", "body": "For naming guidelines check out microsofts link at http://msdn.microsoft.com/en-nz/library/ms229002%28v=vs.100%29.aspx. That should help you tidy up your code a bit." } ]
[ { "body": "<p>First off, as dreza said, work on your variable names. Secondly, you should really think about using more than one method for solving these types of problems.</p>\n\n<p>All of my suggestions are assuming this is inside a class meant to hold this information.</p>\n\n<p>Now to your code.</p>\n\n<p>...
{ "AcceptedAnswerId": "15676", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-16T15:03:53.323", "Id": "15672", "Score": "4", "Tags": [ "c#", "object-oriented" ], "Title": "Divide List into groups" }
15672
<p>I've prepared a function using cURL to get a remote file to the local storage:</p> <pre><code>/** * cURL - Get Remove File * * Function using CURL the get a remote file to the local storage. * * @param str $url Full remote URL * @param str $xml_path Internal path to the storage the file...
[]
[ { "body": "<p>I'm not very familiar with cURL either, but looking at the documentation I noticed a <a href=\"http://www.php.net/manual/en/function.curl-setopt-array.php\" rel=\"nofollow\"><code>curl_setopt_array()</code></a> function that may be worth looking into.</p>\n\n<pre><code>$options = array(\n CURLO...
{ "AcceptedAnswerId": "15682", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-16T19:21:44.297", "Id": "15673", "Score": "2", "Tags": [ "php", "curl" ], "Title": "Getting a remote file to local storage" }
15673
<p>Does this looks ok to everyone?</p> <pre><code>NSFetchRequest *oldFetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *oldEntryEntity = [NSEntityDescription entityForName:@"Entry" inManagedObjectContext:oldContext]; [oldFetchRequest setEntity:oldEntry...
[]
[ { "body": "<p>The first big problem I see with this code is here:</p>\n\n<pre><code>int i = 0;\n\nfor (NSManagedObject *media in mediaSet) {\n // stuff\n newMedia.positionInEntry = [NSNumber numberWithDouble:i + 1];\n // more stuff\n i++;\n}\n</code></pre>\n\n<p>First of all, if <code>positionInEntr...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-16T21:46:13.720", "Id": "15674", "Score": "2", "Tags": [ "objective-c", "ios" ], "Title": "Core Data code for manually creating a lot of entries from old ones" }
15674
<p>I'm architecting a basic SSO solution to pass a user between two sites.</p> <p>Site A handles authentication against a user database and then generates links to Site B which pass a HMAC token comprising a nonce and the user's ID. The HMAC is hashed with a shared secret between the two sites.</p> <p>The following s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T14:00:52.267", "Id": "25505", "Score": "1", "body": "You are not likely to get too many answers to this as a number of these security questions seem to go unanswered. If after a few days you have not received any helpful advice, I w...
[ { "body": "<p>This looks good. </p>\n\n<p>I do almost exactly the same thing as a password reset mechanism. I am including it here in case it will help you with adding a timer to help prevent replay attacks. </p>\n\n<p>The user receives an email with a link to click to reset their password (the <code>$oldpassw...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T09:44:25.490", "Id": "15677", "Score": "8", "Tags": [ "php", "security" ], "Title": "Is this the correct way to implement a HMAC token system?" }
15677
<p>Recently I've tried to teach myself basic things about MySQL databases, however I received some help on <a href="https://stackoverflow.com/questions/12415548/i-need-a-good-mysql-database-structure">Stack Overflow</a> with creating a good database structure trying to avoid redundancy as much as possible.</p> <p>I fi...
[]
[ { "body": "<p>Just a couple of suggestions.</p>\n\n<p>First, <code>artists</code> and <code>producers</code> are both <code>persons</code> and a person can be both an artist and a producer (even on their own songs).</p>\n\n<p>Second, more than one <code>persons</code> can work together on a song, but in lots of...
{ "AcceptedAnswerId": "15680", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T10:44:47.770", "Id": "15678", "Score": "6", "Tags": [ "sql", "mysql" ], "Title": "Music categorization database" }
15678
<p>I implemented a fixed sized priority queue. How can I improve my code?</p> <pre><code>public class FixedSizedPriorityQueue { private final int capacity; private boolean sorted = false; private double smallest = Double.POSITIVE_INFINITY; private ArrayList&lt;Double&gt; list; protected static fin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T06:29:56.600", "Id": "25532", "Score": "2", "body": "You may want to implement the [Queue](http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html) interface as well" } ]
[ { "body": "<ol>\n<li><p>The following is used multiple times and it could be extracted out:</p>\n\n<pre><code>if (!sorted) {\n Collections.sort(list, comparator);\n sorted = true;\n}\n</code></pre>\n\n<p>to a helper method:</p>\n\n<pre><code>private void sortIfNeccessary() {\n if (sorted) {\n re...
{ "AcceptedAnswerId": "15692", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T16:15:34.210", "Id": "15683", "Score": "6", "Tags": [ "java", "priority-queue" ], "Title": "My implementation of FixedSizedPriorityQueue" }
15683
<p>I found <a href="http://nvie.com/posts/a-successful-git-branching-model/" rel="nofollow noreferrer">nvie's git branching model</a> simple enough to grasp and suitable for my projects - but the frontend supplied at GitHub was far too complex for me to understand. Hence, I wrote this script to start and finish tasks, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T09:54:10.853", "Id": "25538", "Score": "3", "body": "I've revised this post and script several times, only to discover a new shortcoming each time it has been submitted. I don't expect myself to write a perfect piece of text or code...
[ { "body": "<p>The following is one of my favorite \"rosetta stone\" like references:</p>\n\n<p><a href=\"http://hyperpolyglot.org/unix-shells\" rel=\"nofollow\">Unix Shells</a></p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T16:16:47.337", "Id": "15684", "Score": "8", "Tags": [ "shell", "git", "sh" ], "Title": "Shell script to assist with branch management for tasks in git" }
15684
<p>I connected to the db, pull the data using <code>fetch_assoc()</code> (<code>fetch_all(NUMB)</code> is not available on the machine we are working with else this would be less of an issue). I get the returned data and load it into an array. However, it ends up in as an numeric array embedded inside another assoc arr...
[]
[ { "body": "<p>First off, there is no need to check if <code>$conn</code> is an object, simply use the proper procedure for checking if the connection was successful.</p>\n\n<pre><code>if( ! $conn ) {//MySQL\nif( $conn-&gt;connect_error ) {//MySQLi\ntry {\n $conn = new PDO( $dsn, $user, $pass );\n} catch( PDO...
{ "AcceptedAnswerId": "15688", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T16:20:15.873", "Id": "15685", "Score": "5", "Tags": [ "php", "array", "mysqli" ], "Title": "Handling data returned from fetch_assoc()" }
15685
<p>I have a feeling I might be doing it wrong, what major things would you improve in this code?</p> <p>The code is basically handling a tour on first login, showing it only for first login users (activated externally via calling <code>activate</code>) and preventing the step to apear again if the user has already see...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T17:04:14.827", "Id": "25737", "Score": "1", "body": "I don't see anything wrong with your code." } ]
[ { "body": "<p>Alternative Approach:</p>\n\n<p>In your case, I believe that the use of a model is not really necessary for this task. I would construct this using a master view with child views for each step:</p>\n\n<p>A TourView that contains a variable tracking which step is currently active and listenting fo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T16:24:05.657", "Id": "15686", "Score": "3", "Tags": [ "javascript", "jquery", "backbone.js" ], "Title": "First attempt incorporating backbone.js in my code" }
15686
<p>I have this JavaScript to make a sidebar widget stick to a fixed position once the page is scrolled down, once you scroll to the bottom of the page where the footer div is I then un-sticky it so that the stickied div does not overlap the footer.</p> <p>It works great but I am not very good with JavaScript, so I am ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T18:07:24.840", "Id": "25520", "Score": "0", "body": "@ANeves You are right I fixed that but you should of also noticed that I only had 4 questions and some only with 1 answer which wasn't good at all. I'm not new I have nearly 8k s...
[ { "body": "<p>I can make a small improvement in your logic structure that may make a very small improvement in performance. If <code>limit &lt; currentPosition</code>, all you need to do is that code block, and you can use else if and remove testing its opposite. See code:</p>\n\n<pre><code>$(window).load(funct...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T17:12:46.947", "Id": "15687", "Score": "3", "Tags": [ "javascript" ], "Title": "Sticky element for a sidebar widget" }
15687
<p>I've just finished coding a Shunting-Yard algorithm implementation, following Wikipedia's C code example and I've got it to finally work.</p> <p>However, looking at my code now, the two "worker" methods seem bloated. I was wondering what your opinion was regarding the current code stubs and whether or not they need...
[]
[ { "body": "<p>I would recommend creating a <code>Token</code> class with specialized sub-classes for things like operators, parenthesis and values/identifiers. Your pre-defined tokens can all be saved in a Map so that you can access them quickly. The big loops that go through the token stream and \"if it's an ...
{ "AcceptedAnswerId": "15733", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-17T19:32:29.950", "Id": "15690", "Score": "6", "Tags": [ "java", "algorithm" ], "Title": "Shunting-Yard algorithm implementation" }
15690
<p>I'm working on a fairly mundane ASP.NET MVC app that allows users to do basic CRUD operations on a number of different domain objects. I'm trying to minimize duplicate code and boring, monkey code as much as possible, so I'm using <code>AutoMapper</code> to map types and MVC's scaffolding feature to spit out forms. ...
[]
[ { "body": "<p>I think your first instinct was right. When I see</p>\n\n<pre><code>public class StandardService&lt;TEntity, TIndexModel, TRowModel, TDisplayModel, TEditorModel&gt; : ServiceBase\n where TEntity : class, IEntity\n where TIndexModel : IIndexModel&lt;TRowModel&gt;\n where TDisplayModel : ID...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T01:24:10.197", "Id": "15695", "Score": "5", "Tags": [ "c#", "object-oriented", "design-patterns" ], "Title": "A base class to handle mapping between entities and view models" }
15695
<p>Pseudocode:</p> <blockquote> <pre><code>// B = nxn binary matrix // Bm = resulting matrix for (i=1; i&lt;=n; i++) { for (j=1; j&lt;=n; j++) { if (B[i,j] == 1) { for (k=1; k&lt;=n; k++) { Bm[i,j] = B[i,j] | B[k,j]; } } } } </code></pre> </blockquote> <p>This is the Warsha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-07T13:48:37.517", "Id": "40082", "Score": "0", "body": "Did you mean `Bm(i,j) = B(i,k) | B(k,j)`?" } ]
[ { "body": "<p>This post may help you in removing a loop:\n<a href=\"http://mathforum.org/kb/message.jspa?messageID=845980\" rel=\"nofollow\">http://mathforum.org/kb/message.jspa?messageID=845980</a></p>\n\n<p>Furthermore, one way to speed up your code is to use a short circuit logical operator:</p>\n\n<pre><cod...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T01:47:12.257", "Id": "15696", "Score": "3", "Tags": [ "algorithm", "matrix", "matlab" ], "Title": "Getting B+ matrix (Warshall algorithm) in Matlab" }
15696
<p>I found out the hardway that access to DbContext in .NET is not threadsafe. I have a singleton for logging things using a dbcontext. The original version uses something like</p> <pre><code>public Logger{ private MyContext context; private static Logger instance = new Logger(); private Logger(){ //init st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T15:05:55.110", "Id": "25563", "Score": "1", "body": "+1 for the con, although if you are looking at logging as 'mondaine' then why do you need a dbcontext with it? If you are actually logging to a database then in all honesty use a ...
[ { "body": "<p>I believe that the dbcontext shouldn't be shared between multiple threads - I remember reading about that somewhere, but I can't find the link.\nSharing a context between threads can lead to all sorts of problems, though in your case (a logger) that should be limited, cause as I understand it woul...
{ "AcceptedAnswerId": "15818", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T12:38:12.080", "Id": "15703", "Score": "9", "Tags": [ "c#", "multithreading", "entity-framework", "singleton" ], "Title": "Threadsafe DBContext in singleton" }
15703
<p>Below is my method in checking if entity already exist.</p> <pre><code>public boolean isExist(String genreName) throws PersistenceException{ EntityManager em = EMF.get().createEntityManager(); boolean flag = false; try{ Genre genre = em.find(Genre.class, genreName); if (genre != null) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T23:47:03.210", "Id": "25578", "Score": "0", "body": "see http://meta.codereview.stackexchange.com/questions/598/google-application-engine-tag-synonym-request for tag synonym request." } ]
[ { "body": "<p>It looks fine. You could omit the boolean flag if you return immediately when you know the answer:</p>\n\n<pre><code>public boolean isExist(final String genreName) throws PersistenceException {\n final EntityManager em = EMF.get().createEntityManager();\n try {\n final Genre genre = e...
{ "AcceptedAnswerId": "15706", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T13:02:01.207", "Id": "15704", "Score": "5", "Tags": [ "java", "google-app-engine", "jpa" ], "Title": "Checking if entity exist in Google App Engine Datastore using JPA 1" }
15704
<p>This is a code automatically converted from VB 6.0 to C#.net What is a safe and correct way to get rid of that <code>GOTO</code> statement?</p> <pre><code>public bool IsDirty(bool checkChildrenInd) { bool result = false; //Determine if this object is 'dirty', or has been updated since it was created. i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T14:05:55.220", "Id": "25553", "Score": "7", "body": "are you sure this is all? checkChildren will always return false. The whole thing could be rewritten as `public bool IsDirty(bool checkChildrenInd){ return Parent.NewId || backup ...
[ { "body": "<p>EDIT: FIXED</p>\n\n<p>This <em>specific</em> instance can be rewritten as</p>\n\n<pre><code>public bool IsDirty(bool checkChildrenInd) {\n return ! ( Parent.NewId ||\n backup == null ||\n String.Equals(MissingDataValue, backup.MissingDataValue) ||\n String....
{ "AcceptedAnswerId": "15725", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T13:57:07.320", "Id": "15707", "Score": "3", "Tags": [ "c#" ], "Title": "Rewriting the code without use of GOTO" }
15707
<p>I am pretty new to TDD and is following problems on spoj.pl for practice. I need help with following code; it was my first attempt.</p> <p>Problem: Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to...
[]
[ { "body": "<p>This wouldn't be the way I'd develop it, your class is used more as a module (a library of functions) and not in OOP, ie: you're not using instance variables. I'd rather go for something like the following:</p>\n\n<pre><code>class Life\n\n def input\n puts \"List comma (',') seperated numbers....
{ "AcceptedAnswerId": "15731", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T15:51:58.707", "Id": "15711", "Score": "5", "Tags": [ "ruby", "rspec" ], "Title": "Spoj's 1st problem in tdd using Ruby" }
15711
<p>I wrote this MySQL stored procedure to emulate <code>DROP USER IF EXISTS</code> (not available in MySQL). Any comments or identified bugs?</p> <pre><code>DROP PROCEDURE IF EXISTS DropUserIfExists; DELIMITER $$ CREATE PROCEDURE DropUserIfExists(MyUserName VARCHAR(100)) BEGIN DECLARE foo BIGINT DEFAULT ...
[]
[ { "body": "<p>I would say you are wrong!!!</p>\n\n<p>Let me explain...</p>\n\n<p>If there is a user named <code>'tempuser'@'localhost'</code> and you are trying to call <code>DropUserIfExists('tempuser')</code>, the above procedure may produce error something like:</p>\n\n<p><code>Error Code: 1396 Operation DRO...
{ "AcceptedAnswerId": "15745", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-18T20:51:58.293", "Id": "15716", "Score": "7", "Tags": [ "sql", "mysql" ], "Title": "Emulating \"DROP USER IF EXISTS\"" }
15716
<p>Is this a good method to Read\Write packets</p> <pre><code>using System.Text; namespace namespace { public unsafe class DataPacket { public DataPacket(byte[] buffer) { _buffer = new byte[buffer.Length]; System.Buffer.BlockCopy(buffer, 0, _buffer, 0, buffer.Length); ...
[]
[ { "body": "<p>At first glance, I can see several problem with this code (why are you even using pointers? what happens with non-ASCII characters in <code>WriteString()</code>?). But my main issue is that <a href=\"http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx\" rel=\"nofollow\"><code>Binar...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T01:46:06.143", "Id": "15720", "Score": "4", "Tags": [ "c#" ], "Title": "Packet Read\\Write" }
15720
<p>The following code is from a university assignment of mine to write a classification algorithm (using nearest neighbour) to classify whether or not a given feature set (each feature is the frequency of words in an email) is spam or not. </p> <p>We are given a CSV file (the training data) with the frequencies, and a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-10-08T00:27:46.290", "Id": "26500", "Score": "0", "body": "small suggestion: don't use sqrt. Comparing squared distances won't change the answer." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-10-10T17:34:38.247...
[ { "body": "<p>One helpful function is <a href=\"http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/Data-Ord.html\" rel=\"nofollow\"><code>Data.Ord.comparing</code></a>:</p>\n\n<pre><code>comparing :: (Ord a) =&gt; (b -&gt; a) -&gt; b -&gt; b -&gt; Ordering\ncomparing p x y = compare (p x) (p y)\n...
{ "AcceptedAnswerId": "16315", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T04:05:17.380", "Id": "15721", "Score": "5", "Tags": [ "algorithm", "performance", "haskell", "homework", "clustering" ], "Title": "Nearest Neighbour classification algo...
15721
<p>I am trying to read a line ending in <code>\r\n</code> from a <code>Handle</code>. This is an HTTP header.</p> <p>I’m fairly new to functional programming, so I tend to use a lot of case expressions and stuff. This makes the code very long and ugly.</p> <pre><code>handleRequest :: HostName -&gt; Handle -&gt; IO ()...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T09:20:06.793", "Id": "25580", "Score": "0", "body": "The answer depends on your goal. If you want high performance or an elegant HTTP parser, you should choose different algorithm and libraries.\n\nIf you just want to see how your c...
[ { "body": "<p>Here I assume you just want to see how your current code can be improved without changing the algoritm.</p>\n\n<p>First of all, give HLint tool a chance to suggest you obvious improvements. In your case the only improvement was that <code>do</code> in <code>do readHeaderLine' \"\"</code> was redun...
{ "AcceptedAnswerId": "15753", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T08:16:39.473", "Id": "15722", "Score": "15", "Tags": [ "haskell", "parsing", "functional-programming", "http" ], "Title": "How to shorten this terrible HTTP header parser?"...
15722
<p>I am a single developer on a numerics project. As it is growing, I would like to improve </p> <ul> <li>the Makefile</li> <li>the general organisation of the project</li> <li>structuring of the files</li> <li>workflow</li> </ul> <p>As it stands now I have a few classes (where a few depend on each other) and a <code...
[]
[ { "body": "<p>Note that some of the commands below may be specific to GNU Make - you haven't said what tools you're using (although I guess you're on Windows since you mention .obj files).</p>\n\n<h2>Rules and object files</h2>\n\n<p>Currently, you have <code>$(RESULT): $(SRCS)</code>, so it has to re-run your ...
{ "AcceptedAnswerId": "15738", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T10:24:57.907", "Id": "15724", "Score": "7", "Tags": [ "c++", "makefile" ], "Title": "Improving Makefile and general C++ project structure" }
15724
<p>I am developing a meta-data framework for monitoring systems such that I can easily create data adapters that can pull in data from different systems. One key component is the unit of measurement. To compare datasets which have different units I need to convert them to a common unit. To build adapters I need to have...
[]
[ { "body": "<pre><code>raise TypeError, \"Units derived from %s and %s are incompatible.\" % (self.base_unit)\n</code></pre>\n\n<p>The python style guide recommends raising exceptions in the <code>raise TypeError(message)</code> form. TypeError is also questionable as the correct exception to throw here. The err...
{ "AcceptedAnswerId": "15734", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T11:24:08.107", "Id": "15728", "Score": "2", "Tags": [ "python", "object-oriented" ], "Title": "OOP design of code representing units of measurement" }
15728
<p>I'm looking at some code that goes a bit like this:</p> <pre><code>class Foo { public int Frob; public int Frib; } class Bar { public Foo Left; public Foo Right; } public void ProcessBars(Bar[] bars) { this.LeftFrobs = new int[bars.Count]; this.RightFrobs = new int[bars.Count]; this.LeftFribs = new int...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T12:40:34.223", "Id": "25590", "Score": "2", "body": "I don't understand, why do you have *27* more lines like that? Do you mean `Foo` and `Bar` have more properties? How exactly do you use the arrays after you create them? I mean, w...
[ { "body": "<p>That method is immense, and is surely impossible to easily read and maintain. Once you break it into smaller methods you will be able to work with it (\"just like those acorns, one at a time\").<br>\nThis will also help avoid repetitions of code.</p>\n\n<p>I propose creating a class to hold all th...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T12:13:06.390", "Id": "15729", "Score": "2", "Tags": [ "c#", "linq" ], "Title": "Converting 'list of Foo' into 'lists of Foo properties'" }
15729
<p>I've created this very small header that allows direct creation of threads from lambdas. I can't find anything else similar on the net so I want to know whether there are any problems with this that I have not thought of. It is based on <a href="http://tinythreadpp.bitsnbites.eu/">tinythread++</a>, but can easily be...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-03T23:17:04.880", "Id": "46357", "Score": "1", "body": "What if `(*f)();` should throw? You get a leak." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-05T10:39:20.420", "Id": "46461", "Score": "0",...
[ { "body": "<ol>\n<li><p>surely you can just use <code>std::function&lt;void()&gt;</code> instead of templating on the function type?</p></li>\n<li><p>capturing by reference can go horribly wrong. It's not a bug in your library, just an observation ...</p>\n\n<pre><code>tthread::thread* startthread(size_t a, siz...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T15:13:35.570", "Id": "15736", "Score": "11", "Tags": [ "c++", "multithreading", "c++11", "pthreads" ], "Title": "Threading lambda functions" }
15736
<p>These two methods do the exact same thing (or at least they are supposed to!). They both pass a simple test based on a mock context. Neither has been exposed to any integrated testing yet. </p> <ul> <li>Would one of the methods be preferred over the other (and why)?</li> <li>Does anyone see any glaring mistakes ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T20:19:27.873", "Id": "25622", "Score": "1", "body": "What library are you using in the first version of the method?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T21:02:16.177", "Id": "25626", ...
[ { "body": "<p>I personally like the Second option, like you said it is cleaner, easier to read, and looks fairly simple and straight to the point. </p>\n\n<p>I don't see any obvious mistakes in your code.</p>\n\n<p>I can only suggest that you test it vigorously and perhaps check out the option given by @Jignesh...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T15:28:07.350", "Id": "15737", "Score": "10", "Tags": [ "c#", "linq", "entity-framework" ], "Title": "Multiple repository calls or LINQ query" }
15737
<p>I couldn't find an example on how to have a custom function inherit jQuery's functions while leaving the original jQuery function I'm inheriting from unchanged (I wanted my function to have a <code>read</code> but didn't want it to get added to <code>$.Deferred</code>)</p> <p>This works, but I really suspect it isn...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T19:51:28.853", "Id": "25618", "Score": "0", "body": "Did you try using [jQuery.sub](http://api.jquery.com/jQuery.sub/)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T20:27:26.063", "Id": "25623"...
[ { "body": "<h2>Tips:</h2>\n\n<h1>1)</h1>\n\n<p>Returning <code>this</code> from a function of an object instance allows for the method to become chainable.</p>\n\n<p>Example:</p>\n\n<pre><code>var File = function(){\n this.readCallCount = 0;\n return this;\n};\nFile.prototype.readLine = function(){\n t...
{ "AcceptedAnswerId": "15776", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T19:00:07.700", "Id": "15743", "Score": "4", "Tags": [ "javascript", "jquery", "asynchronous" ], "Title": "Custom function extending jQuery.Deferred" }
15743
<p>I'm upgrading/rewriting our online client portal and wondering if my log in page code looks okay so far. during this rewriting/learning process I am upgrading a number of things: PHP 5.2 to 5.3.5, MYSQL 4.1 to 5.5, md5() to SHA512 using pbkdf2, salt and multiple iterations, MySQL functions to PDO, HTML4 to 5. I'm le...
[]
[ { "body": "<p>Since you are updating anyways, you should just update to the most recent version of PHP if you can. I believe its supposed to be faster in addition to offering a bunch of new toys to play with, but I haven't gotten IT to update me yet and I haven't gotten around to playing with it in my spare tim...
{ "AcceptedAnswerId": "15774", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T21:52:36.337", "Id": "15750", "Score": "5", "Tags": [ "php", "mysql", "pdo" ], "Title": "moving from->to: mysql->pdo, md5->pbkdf2, procedural->oop" }
15750
<p>This is my first Wordpress plugin. I would love some input from the WP/PHP/JavaScript gurus out there. It's a simple plugin that saves a post using <kbd>ctrl</kbd>-<kbd>Q</kbd> and opens a preview in a new or current window.</p> <pre><code>&lt;?php add_action('admin_menu', 'plugin_admin_add_page'); add_acti...
[]
[ { "body": "<p>Well, I can't help you with the WordPress specifics, or the jquery, which means not much at all really. But here are a few things that might help you with your PHP.</p>\n\n<p>Foremost, I would definitely consider separating your HTML from your logic. Or at the very least separate your escapes from...
{ "AcceptedAnswerId": "15770", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T01:24:26.600", "Id": "15752", "Score": "6", "Tags": [ "javascript", "php", "wordpress" ], "Title": "First Wordpress plugin for saving a post" }
15752
<p>my connection code:</p> <pre><code> &lt;?php try { $pdo = new PDO("mysql:host=localhost;dbname=game; charset=utf8", "root"); } catch(PDOException $e){ echo $e-&gt;getMessage(); } ?&gt; </code></pre> <p>my class code:</p> <pre><code> &lt;?php include './database/config.php'; class DB { publi...
[]
[ { "body": "<p>No, you can't bocouse you relying on a global object which is bad try dependency injection at you class constructor.</p>\n\n<pre><code>&lt;?php \ninclude './database/config.php'; \n\nclass DB { \n\n private $_pdo;\n\n public function __construct(\\PDO $pdo) {\n $this-&gt;_pdo = $pdo;\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T06:56:17.660", "Id": "15755", "Score": "1", "Tags": [ "php", "sql", "mysql", "pdo", "battle-simulation" ], "Title": "Storing, fetching, and deleting battle simulation resu...
15755
<p>How can I improve this code?</p> <p><strong>jQuery:</strong> </p> <pre><code>$.ajax({ url: "get_attributes.php", type: "post", datatype: "json", data: { wtype: red_type }, success: function (data) { var toAppend = ''; if (typeof data === "object") { toAppend += "&l...
[]
[ { "body": "<p>There are a few improvements that come to my mind for the given code:</p>\n\n<ol>\n<li><p>you may want to return an status code for your JSON output instead of checking whether the result is an object. It would allow you to handle error messages and such in a more convenient manner.</p></li>\n<li>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T07:06:24.700", "Id": "15756", "Score": "3", "Tags": [ "javascript", "php", "jquery" ], "Title": "Getting JSON and putting it in a table using jQuery and PHP" }
15756
<p>I plan to use the following approach to audit the tables that represent user-editable configuration of an automated system (over the course of system's life these will be inevitably extended in their numbers and stuffed with more columns). This approach will not be applied to main data tables as those are automatica...
[]
[ { "body": "<p>Looks Like a nice, straight forward solution.</p>\n\n<p>The only suggestion that I have , and while this is an unlikely situation, if the database were hosted on a failover cluster and the user were to connect to the instance locally (i.e. from anyone of the servers in the cluster), you wouldn't k...
{ "AcceptedAnswerId": "18351", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T08:47:57.763", "Id": "15760", "Score": "7", "Tags": [ "sql", "sql-server" ], "Title": "Auditing a complex mix of reasonably small tables" }
15760
<p>I am using <a href="http://scrapy.org/">scrapy</a> framework for data scraping and dumping item in MySQL database.</p> <p>Here is my pipeline that is inserting output to MySQL, but its taking so much time. Any suggestions on how to optimize this?</p> <pre><code>class MysqlOutputPipeline(object): def __init__(sel...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-25T16:31:44.650", "Id": "25885", "Score": "0", "body": "What makes you think this code is the bottleneck?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-25T16:34:13.647", "Id": "25886", "Score": "0...
[ { "body": "<p>It's hard to analyze the bottle neck without performance data on where the bottleneck is occurring. You should consider running the program several ways and comparing. Ie </p>\n\n<ul>\n<li>run program as is</li>\n<li>run program spider only with no db</li>\n</ul>\n\n<p>This should tell you the pro...
{ "AcceptedAnswerId": "16008", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T10:20:07.620", "Id": "15763", "Score": "7", "Tags": [ "python", "optimization", "mysql", "scrapy" ], "Title": "How to optimize a pipline for storing item in mysql?" }
15763
<p>I have two classes one base Foo class and one derived Bar class. </p> <p>Each class has its own associated settings class that can create a new instance from the Load method. This way all derived class settings can be stored in one list of FooSettings.</p> <pre><code>public abstract class FooSettings { publi...
[]
[ { "body": "<p>I think this is the right way to do it. If you have some code that should be used from the base class and all its derived classes, it should be in the base class. Which is exactly what you're doing.</p>\n\n<p>But I would make a modification in your code. You don't need to use <code>ref</code>. In ...
{ "AcceptedAnswerId": "15765", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T10:27:30.570", "Id": "15764", "Score": "4", "Tags": [ "c#", "classes" ], "Title": "Avoid explicitly writing base class state in a derived class. Suggestions for my method" }
15764
<p>please review my implementation of a FIFO data structure that guarantees thread-safe access without locking.</p> <p>I removed the license header block and all Doxygen comments. The original version (along with some tests) is available from here: <a href="https://github.com/fat-lobyte/atomic_queue">https://github.co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T17:52:05.730", "Id": "25659", "Score": "0", "body": "Note: By posting code on this site you are making it available under the creatives common license (see the bottom line on the page)." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>Pretty sure this is broken in multi-threaded code:</p>\n\n<pre><code> do\n {\n // Point A.\n if (!old_front) return nullptr;\n new_front = old_front-&gt;next; \n }\n while(!front_.compare_exchange_weak(old_front, new_front));\n</code></pre>\n\n<p>What happens if:<...
{ "AcceptedAnswerId": "15775", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T13:53:10.520", "Id": "15768", "Score": "8", "Tags": [ "c++", "multithreading", "c++11", "atomic" ], "Title": "atomic_queue - thread-safe and lock-free implementation of the...
15768
<pre><code>def sieve_of_erastothenes(number): """Constructs all primes below the number""" big_list = [2] + range(3, number+1, 2) # ignore even numbers except 2 i = 1 # start at n=3, we've already done the even numbers while True: try: # use the next number that has not been remove...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T22:36:05.073", "Id": "25666", "Score": "0", "body": "I know this could do with more tags but I'm not allowed to create them" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T05:01:23.687", "Id": "25...
[ { "body": "<p>The problem is that the way this is set up, the time complexity is (close to) \\$O(n**2)\\$. For each remaining prime, you run over the entire list.</p>\n\n<p>In the last case, where you want to check for prime numbers up to 1,000,000 you end up iterating over your list 78,498 ** 2 times. 6,161,93...
{ "AcceptedAnswerId": "15790", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T22:35:29.987", "Id": "15777", "Score": "8", "Tags": [ "python", "optimization", "performance", "primes", "sieve-of-eratosthenes" ], "Title": "Why does my implementation...
15777
<p>I'm teaching myself code using Zed Shaw's <a href="http://learnpythonthehardway.org/" rel="nofollow"><em>Learn Python The Hard Way</em></a>, and I got bored during one of the memorization lessons so I thought I would make a random D20 number generator for when I play RPGS. </p> <p>How can I make this code better? I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-04-09T20:58:44.750", "Id": "38503", "Score": "0", "body": "Maybe incorporate some of the stuff in this answer: http://gamedev.stackexchange.com/questions/24656/random-calculations-for-strategy-based-games-in-java/24681#24681" } ]
[ { "body": "<p>Here's my take:</p>\n\n<pre><code>from random import randint\nname = raw_input('Please Type in your name &gt; ')\n\nprint \"\"\"\nHello {} &amp; welcome to the Random Number Generator by Ray Weiss.\n\"\"\".format(name)\nupper = int(raw_input('Enter the upper limit &gt; '))\nn = int(raw_input(\"How...
{ "AcceptedAnswerId": "15779", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-20T19:02:05.540", "Id": "15778", "Score": "12", "Tags": [ "python", "beginner", "random", "simulation", "dice" ], "Title": "Random D20 number generator" }
15778
<p>I've written a Base64 encoder/decoder, which works great. Now I want to see if I can get it working better. I've optimized as much as I can think of, but it may be missing some things. The encoder can encode a 160 MB file in 30 seconds, but the decoder takes nearly 60.</p> <p>So far the optimizations I've done are:...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-06-30T20:54:20.397", "Id": "318129", "Score": "0", "body": "Have a look at the Java source code for the java.util.Base64, java.util.Base64.Decoder and java.util.Base64.Endoder for ideas." } ]
[ { "body": "<p>FOA, code looks clear and clean, well indented and formatted. Thumbs up!!</p>\n\n<p>Now, to the comments:</p>\n\n<ul>\n<li>Some of the variable names might have more significant names: <code>is</code> can be changed to <code>input_stream</code>, for instance.</li>\n<li>File size: it looks like you...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T00:54:13.800", "Id": "15780", "Score": "9", "Tags": [ "c++", "performance", "base64" ], "Title": "Base64 encoder/decoder optimizations" }
15780
<p>This function is used to get the mime type of any given file. The intended purpose was to have it working within any of our servers that vary from the latest PHP version down to PHP 4.</p> <pre><code>/** * Get the mime type for any given file. * * @param str $filename Path to the file including the filename * ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T04:54:00.297", "Id": "25681", "Score": "0", "body": "In my opinion, this code is broken and should be revised before being reviewed. In particular: `@return mixed bol|arr Either false or the array provided by the PHP function` That...
[ { "body": "<h2>General Issues</h2>\n<p>If you are going to call something getMimeType then it should return exactly that. This is probably best defined by Multipurpose Internet Mail Extensions <a href=\"https://www.rfc-editor.org/rfc/rfc2046\" rel=\"nofollow noreferrer\">RFC 2046</a>. Read the <a href=\"http:...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T02:00:19.020", "Id": "15782", "Score": "3", "Tags": [ "php" ], "Title": "Detecting the mime type using an agnostic method" }
15782
<p>I have written an code to find if a given tree is a BST. Need help in refactoring it. Some of the things I am looking are.</p> <ol> <li>Getting Rid of temp variables (As suggested by Martin Fowler)</li> <li>Combining leftTreeMax and RighTreeMin methods</li> <li>Better naming of methods.</li> </ol> <p>Also it will ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T07:27:05.057", "Id": "25690", "Score": "0", "body": "You're returning 0 as a flag that the level failed (and thus the tree is not a BST). That's problematic though since 0 is a possible value." } ]
[ { "body": "<p>1) You would like to get rid of the <code>System.out.println()</code> inside methods. Noone expects a method to write to the console unless the method has <code>print</code> in the name.</p>\n\n<p>2) Just comparing the <code>root</code> with <code>left tree max</code> and <code>right tree min</cod...
{ "AcceptedAnswerId": "15787", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T05:59:21.053", "Id": "15785", "Score": "4", "Tags": [ "java" ], "Title": "Refactoring code finding if Binary Tree is BST" }
15785
<p>Problem statement:</p> <blockquote> <p>Write a <code>CashWithDrawal</code> function from an ATM which, based on user specified amount, dispenses bank notes. Ensure that the following is taken care of:</p> <ul> <li>Minimum number of bank notes are dispensed</li> <li>Availability of various denominatio...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-23T06:52:00.223", "Id": "25790", "Score": "1", "body": "`ATM` stands for Automatic Teller Machine, so your class is called `Automatic Teller Machine Machine`?" } ]
[ { "body": "<p>First of all, it's considered better practice to implement <code>isCorrectAmount</code> as follows:</p>\n\n<pre><code>private boolean isCorrectAmt(int amt){\n return amt%10 == 0;\n}\n</code></pre>\n\n<p>Next, if you want to update the value of an existing key in a <code>Map</code>, it's not nec...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T06:15:55.120", "Id": "15786", "Score": "1", "Tags": [ "java", "multithreading", "collections", "finance" ], "Title": "ATM problem using collections" }
15786
<p>Between .NET's built-in collection libraries and LINQ extension methods, I never have to use arrays. An unfortunate consequence of this is that I am probably less competent in working with this very important Type than I should be. To help myself get a better grip on the <code>Array</code> class, I wrote some C# h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T08:45:11.160", "Id": "25695", "Score": "1", "body": "As a learning excercise, this is valid. But for production, [**Arrays are usually the wrong approach**](http://blogs.msdn.com/b/ericlippert/archive/2008/09/22/arrays-considered-so...
[ { "body": "<p>Your code seems fine to me, just a few things I would do differently:</p>\n<ol>\n<li><p>Your usage of <code>ConstrainedCopy()</code>, instead of normal <code>Copy()</code>, doesn't make sense to me. This method is useful if you want to guarantee that the target array is in a consistent state even ...
{ "AcceptedAnswerId": "15798", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T07:53:07.697", "Id": "15789", "Score": "3", "Tags": [ "c#", "javascript", "optimization", "array", "thread-safety" ], "Title": "C# Array Mutator Methods to mimic JavaSc...
15789
<p>I have created this extension method that can be used to run a function with a timeout applied to it. Is this a sensible way of doing it?</p> <pre><code>public static class FuncExtensions { public static T RunUntil&lt;T&gt;(this Func&lt;T&gt; predicate, TimeSpan timeout, string taskName) { var resul...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T13:15:50.110", "Id": "25715", "Score": "1", "body": "I don't see the code which should stop the task if it goes over on time." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T14:43:13.810", "Id": "...
[ { "body": "<p>I think that his question would suit more on SO as it doesn't require explicitly a code review. This question is more about of how to correctly cancel a task instead of fixing apointing good pracrises, etc.. However you have made a great quest that deserves an answer: </p>\n\n<blockquote>\n<pre><c...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T09:12:20.737", "Id": "15796", "Score": "14", "Tags": [ "c#", ".net", "timeout" ], "Title": "Timing out a method" }
15796
<p>First I tried to fetch this program as close to pseudo code where I must follow all imported items, all method definitions, and all defined variables; anything else was my choice.</p> <p>After I created working program that best represent the sample run of output we were provided in my homework documentation, I dec...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T10:33:03.783", "Id": "25705", "Score": "7", "body": "I'll put this as a comment as it's not really answering your question of idiot-proofness, but money shouldn't be represented in `double` or `float`, because they can't accurately ...
[ { "body": "<p><code>mustBeNumeric</code> is a regular expression that will not change. It is better declared as a <code>static final</code> field, rather than a mutable variable within a method scope.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-2...
{ "AcceptedAnswerId": "15826", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T10:09:07.760", "Id": "15800", "Score": "10", "Tags": [ "java", "homework", "finance" ], "Title": "Payroll calculator" }
15800
<p>The following program is supposed to be a (command line) calculator that parses expression following syntax similar to <a href="http://en.wikipedia.org/wiki/S-expression" rel="nofollow noreferrer">Lisp's S-expressions</a>.</p> <p>Some examples:</p> <blockquote> <p>$ echo &quot;(+ 5 5)&quot; | ./a.out</p> <p>10.00000...
[]
[ { "body": "<p>I don't know why nobody commented on this question as there is lots to be\nsaid. I'll go through what I found from the top down:</p>\n\n<p>Your typedef for the functions should be complete with the types of call\nparameters. The name <code>doublefun_t</code> is the operation to be performed, so ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T10:50:19.280", "Id": "15802", "Score": "3", "Tags": [ "c", "parsing", "console", "math-expression-eval", "calculator" ], "Title": "Calculator parsing S-expressions" }
15802
<p>I'm quite new to Python and would love to gather feedback on my code. I've written a piece a script that allows me to search all file or directory names within a folder matching a particular pattern. The caller can specify if the function should be recursive or not.</p> <p>It's only a basic script I would love to k...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T14:39:47.710", "Id": "25728", "Score": "0", "body": "The only problem I found with your script is that you shouldn't name your variable `dir` as it is the name of a global function." } ]
[ { "body": "<p>What if the script renames file \"a.zip\" to \"b.zip\", and both files \"a.zip\" and \"b.zip\" exist in the same directory?</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-22T21:45:17.960", "Id":...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T13:08:23.867", "Id": "15805", "Score": "4", "Tags": [ "python", "file-system" ], "Title": "Renaming Files and/or Directory" }
15805
<p>I am a high-school freshman who is kinda new to Ruby, and I am doing a small project on Ruby. One of the big things that I want to get out of this project is how to follow the "Ruby standards" that programmers should follow. Being as new as I am, I have no clue what I should/shouldn't do with this program. Can an...
[]
[ { "body": "<p>You should define arrays with <code>[]</code> not <code>Array.new</code></p>\n\n<p><code>circs</code> should be <code>$circs</code> in case you wrap your loop in some function.</p>\n\n<p>Before drawing can be turned into this :</p>\n\n<pre><code>def before_drawing()\n temp_a = $point_B[0] ** 1 ...
{ "AcceptedAnswerId": "15810", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T14:24:03.223", "Id": "15806", "Score": "3", "Tags": [ "beginner", "ruby", "graphics", "tk" ], "Title": "Drawing colored circles using Ruby and Tk" }
15806
<p>I saw that one of the interview questions could be building a <a href="http://en.wikipedia.org/wiki/Pascal%27s_triangle">pascal triangle</a>. Is there anything wrong with this particular solution I came up with?</p> <pre><code>function pascal_r($r){ $local = array(); if($r == 1){ return array(array(1...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-28T15:17:08.090", "Id": "26025", "Score": "0", "body": "Edited my post with new information you might find interesting." } ]
[ { "body": "<p>In regards to the comments: Yes, this is a good place for this so long as it works as is and you are asking about the code and not the algorithm. If you are asking about the algorithm this should have stayed on programmers.SE. If you are asking if this will work, then you should test it first, the...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T17:11:12.550", "Id": "15812", "Score": "7", "Tags": [ "php", "interview-questions", "recursion" ], "Title": "Pascal's triangle for an interview in PHP" }
15812
<p>This is sort of a follow up to my post <a href="https://codereview.stackexchange.com/questions/15778/how-can-i-make-this-code-better">yesterday</a>. I'm a relative newbie to Python and before I made a d20 dice roller for RPGs. Now I've made a dice roller for any type of dice, and I would love some feedback on this...
[]
[ { "body": "<p>I think the big thing here is to <strong>beware of external data</strong>. Assume that it could be garbage.</p>\n\n<p>For instance:</p>\n\n<ul>\n<li>What happens if the user doesn't enter a name? -> Actually, not much apart from 2 spaces (rather than 1) in messages - relatively benign.</li>\n<li>W...
{ "AcceptedAnswerId": "15821", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T19:11:14.383", "Id": "15816", "Score": "6", "Tags": [ "python", "beginner", "random", "simulation", "dice" ], "Title": "RPG Dice Roller" }
15816
<p>I'm learning C, specifically OOP in C. As practice, I wrote a dynamically-expanding array.</p> <p><strong>dynarray.h</strong></p> <pre><code>#ifndef DYNARRAY_H #define DYNARRAY_H typedef struct DynArray { int length, capacity, *arr; void (*extend)(struct DynArray *dynArr); void (*inse...
[]
[ { "body": "<p>My 2 cents:</p>\n\n<ol>\n<li>I believe <code>createDynArray</code> should return something.</li>\n<li>The returned value of <code>createDynArray</code> might have a special value of <code>NULL</code> in case that one of the <code>malloc</code>s calls failed (this scenario should be covered by the ...
{ "AcceptedAnswerId": "15822", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-21T20:17:50.170", "Id": "15819", "Score": "6", "Tags": [ "c", "object-oriented", "array" ], "Title": "Dynamically-expanding array in C" }
15819
<p>I recently started to learn more about OOP in PHP and I created a website for testing. I have 4 classes: <code>database</code>, <code>user</code>, <code>posts</code>, <code>comments</code>. This is a simple <code>database.class.php</code>:</p> <pre><code>class DB { protected $pdo; protected $engine = 'm...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-23T06:14:48.453", "Id": "25787", "Score": "1", "body": "I'm too lazy to write a full response, especially since Yannis covered it very well, but your DB class shouldn't exist. It's basically a glorified PDO factory, but I really doubt...
[ { "body": "<h2>What happens if you change your database credentials?</h2>\n\n<p>Right now your class is tied to a specific set of database credentials, and you'll need to change it if:</p>\n\n<ul>\n<li>you want to use a different engine,</li>\n<li>or a different host,</li>\n<li>or a different user,</li>\n<li>or...
{ "AcceptedAnswerId": "15827", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-22T05:39:56.027", "Id": "15825", "Score": "2", "Tags": [ "php", "object-oriented", "classes" ], "Title": "Help improve my first PHP class" }
15825
<p>I could use some review on this Auth class, as I'm sure it could use many improvements!</p> <p>I wrote this fairly quickly, so please forgive any overseen bugs.</p> <p><strong>Example usage:</strong></p> <pre><code>// Login a user if (Auth::attempt($_POST['username'], $_POST['password'])) { echo 'You have suc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-22T09:51:41.817", "Id": "25767", "Score": "1", "body": "What's up with static? It's really unnecessary, this reads like you are writing procedural code with classes." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<h2>What's up with static?</h2>\n<p>Your class is build like a <a href=\"http://c2.com/cgi/wiki?UtilityClasses\" rel=\"noreferrer\">utility class</a>:</p>\n<blockquote>\n<p>UtilityClasses are classes that have only static methods that perform some operation on the objects passed as parameters. Such c...
{ "AcceptedAnswerId": "15829", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-22T09:48:11.977", "Id": "15828", "Score": "11", "Tags": [ "php", "object-oriented" ], "Title": "PHP Authentication Class" }
15828
<p>I really don't like the so many <code>return</code> statements. Anyone think that this could be refactored more?</p> <pre class="lang-php prettyprint-override"><code>public function validate($value, Constraint $constraint) { if('' === $value || null === $value) { return; } if(!preg_match('/^[0-...
[]
[ { "body": "<p>Ah, the yoda syntax, don't see that too often. Anyways, on to the subject at hand. Here are a few ways you can refactor it, I'll address your specific question towards the end.</p>\n\n<p>You can use the <code>empty()</code> function in your first comparison, it will return TRUE if the value is any...
{ "AcceptedAnswerId": "15877", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-22T14:20:00.937", "Id": "15833", "Score": "3", "Tags": [ "php", "php5" ], "Title": "Would be possible to refactor this PHP code more?" }
15833
<p>I'm trying to come up with a scalable way of TDD'ing my Scala code, in particular managing dependencies. In this example, I've TDD'd part of the classic river crossing problem where we have people on each side of a river and move people from one bank to another.</p> <p>I wanted to unit test the smaller functions on...
[]
[ { "body": "<p>I'm no Scala Pro, but I'll try to give my two cents anyway:</p>\n\n<p>Your decision to \"inject the functions\" (pass them as parameters) in order to be able to test them resulted in awkward code, and complicated an otherwise simple method.</p>\n\n<p>As for the tests you chose to make of the resul...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-22T14:46:25.863", "Id": "15834", "Score": "16", "Tags": [ "unit-testing", "scala" ], "Title": "TDD and function injection" }
15834
<p>I understand that this animation code is outdated:</p> <pre><code>[UIView beginAnimations:@"Move" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationDelay:0.08]; self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); [UIView commitAnimation...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T00:13:08.023", "Id": "94974", "Score": "0", "body": "In the future, please leave a comment on what version of iOS the code comes from and what version of iOS you're looking to upgrade to. Nearly 2 years later, this question-and-ans...
[ { "body": "<p>In iOS 4 and later you are encouraged to use <a href=\"http://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/AnimatingViews/AnimatingViews.html#//apple_ref/doc/uid/TP40009503-CH6-SW4\">animation blocks</a>.</p>\n\n<pre><code>[UIView animateWithDuration: 0.5f\...
{ "AcceptedAnswerId": "15847", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-22T17:15:54.853", "Id": "15835", "Score": "7", "Tags": [ "objective-c", "ios", "animation", "cocoa-touch" ], "Title": "Upgrading animation code" }
15835
<p>I have two projects, a native C++ DLL (pinvokelib.dll), and a C# console application (pinvoketest.exe) which calls the DLL. I'm curious if the way I do P/Invoke is considered best practice.</p> <p>Here is my C++ code:</p> <pre><code>extern "C" __declspec(dllexport) int test(int val); int test(int val) { retur...
[]
[ { "body": "<p>If you don't call your function recursively from C, you don't need to have separate defition and declaration:</p>\n\n<pre><code>extern \"C\" __declspec(dllexport) int test(int val)\n{\n return val * 2;\n}\n</code></pre>\n\n<p>And if you have more than one function you want to export, you can us...
{ "AcceptedAnswerId": "15839", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-22T20:00:57.007", "Id": "15836", "Score": "3", "Tags": [ "c#", "c++" ], "Title": "Is this P/Invoke code standard?" }
15836
<p>How can I improve this?</p> <p><strong>jQuery</strong></p> <pre><code>$(function() { $('button').button(); $('#tabs').tabs(); $('.ui-state-error').hide(); $('.btnlogin').click(function() { $('#login .ui-state-error').hide(); if($('#login_email').val().trim() == ''){ $('#...
[]
[ { "body": "<p>One thing I would recommend is to put all of the login code into a distinct function called <code>login()</code>, for example. Then the click binding would look like this:</p>\n\n<pre><code>$('.btnlogin').click(login)\n</code></pre>\n\n<p>This would do a few things for you. First, it would impro...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-22T23:09:56.757", "Id": "15843", "Score": "0", "Tags": [ "javascript", "jquery", "html", "validation", "jquery-ui" ], "Title": "jQuery login code" }
15843
<p>I am working on a Rails 3.2.6 app for a friend which implements some message board functionality. Users can post messages into a categories. Each user also has a list of other users they have friended.</p> <p>I got a feature request recently to display the number of unread posts made by the current user's friends n...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-19T01:17:01.310", "Id": "15845", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Displaying number of unread posts for a message board" }
15845
<p>Currently, I have this code snippet, but it's a little bit slow:</p> <pre><code>% input image input_matrix = imread('placa.bmp'); [rows cols] = size(input_matrix); % rotation degree = 30; radians = (pi * degree) / 180; theta = radians; % output matrix t_matrix = input_matrix; t_matrix(t_matrix == input_matrix)...
[]
[ { "body": "<p>Rather than looping over all x and y values you could put them into a vector, that should speed things up considerably.</p>\n\n<pre><code>y=repmat(1:cols,rows,1)\nx=repmat((1:rows)',cols,1)\n\nM=[x(:) y(:) ones(rows*cols,1)];\n</code></pre>\n\n<p>Now you just need to multiply <code>M</code> or <co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-23T00:46:33.607", "Id": "15846", "Score": "7", "Tags": [ "matrix", "image", "matlab", "coordinate-system" ], "Title": "Using homogeneous coordinates to rotate an image" }
15846
<p>I am doing a project where I use DLL's as run-time modules or plugins. To do this, I use the Windows <code>LoadLibrary()</code> and <code>FreeLibrary()</code> API calls to call two functions exported by the DLL. I decided to make a class so dealing with the DLL's would be easier. Is there anything I can add to my cl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-10-03T06:08:04.013", "Id": "26239", "Score": "0", "body": "I don't think anyone mentioned this, but those double underscores in `SAMODULE_H__` cause the identifier to infringe upon the reserved ones. Even if you've seen this, read the dou...
[ { "body": "<p>Just a couple of quick thoughts.</p>\n\n<ol>\n<li><code>DoScan</code> and <code>GetName</code> probably should be initialised to NULL as well.</li>\n<li><code>Load</code> doesn't call <code>Unload</code> for any previous loaded dlls. If Load should be called once only per <code>SaModule</code>, th...
{ "AcceptedAnswerId": "15849", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-23T05:09:14.337", "Id": "15848", "Score": "2", "Tags": [ "c++", "object-oriented", "windows" ], "Title": "Windows DLL Module Class" }
15848