body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
WiX allows developers to create installers for Windows Installer, the Windows installation engine.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-16T20:50:30.007", "Id": "54442", "Score": "0", "Tags": null, "Title": null }
54442
<blockquote> <p>Ember.js is an open-source client-side JavaScript web application framework based on the model-view-controller (MVC) software architectural pattern. It allows developers to create scalable single-page applications by incorporating common idioms and best practices into a framework that provides...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-16T20:53:40.740", "Id": "54444", "Score": "0", "Tags": null, "Title": null }
54444
Ember.js is a JavaScript web application framework based on the model-view-controller (MVC) software architectural pattern.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-16T20:53:40.740", "Id": "54445", "Score": "0", "Tags": null, "Title": null }
54445
<p>I've created a rudimentary example of the issue I'm inquiring about: Object slicing. I followed a post on Stack Overflow which provided a similar template - and for all intents and purposes, this works. I was just wondering if this would get me into a trouble longer down the line? Is there anything here that jumps o...
[]
[ { "body": "<ol>\n<li><p>Initialise member variable outside the body of the constructor. e.g.,</p>\n\n<pre><code>Shape(string const&amp; name, int edges) : name(name), edges(edges) {}\nCircle(int radius) : Shape(\"Circle\", 1), radius(radius) {}\n</code></pre></li>\n<li><p>The <code>getName</code> function shoul...
{ "AcceptedAnswerId": "54464", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-16T21:31:00.983", "Id": "54449", "Score": "5", "Tags": [ "c++", "vectors" ], "Title": "Avoiding object slicing within abstractions and their derivations" }
54449
A variable with global scope, meaning that it is visible throughout the program. Use this tag when you're concerned about usage of global-scope variables.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T00:14:36.053", "Id": "54456", "Score": "0", "Tags": null, "Title": null }
54456
<p>Pascal is a purely procedural language and includes control statements with reserved words such as <code>if</code>, <code>then</code>, <code>else</code>, <code>while</code>, <code>for</code>, and so on. However, Pascal also has many data structuring facilities and other abstractions not included in <a href="http://e...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T00:16:58.257", "Id": "54457", "Score": "0", "Tags": null, "Title": null }
54457
Pascal is an imperative language from the Wirthian family created in 1969. It lives on in compilers like Free Pascal and Delphi.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T00:16:58.257", "Id": "54458", "Score": "0", "Tags": null, "Title": null }
54458
<p>Here is the function (along with its support functions):</p> <pre><code>def findAnglesBetweenTwoVectors(v1s, v2s): dot_v1_v2 = np.einsum('ij,ij-&gt;i', v1s, v2s) dot_v1_v1 = np.einsum('ij,ij-&gt;i', v1s, v1s) dot_v2_v2 = np.einsum('ij,ij-&gt;i', v2s, v2s) return np.arccos(dot_v1_v2/(np.sqrt(dot_v1_...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T01:10:31.897", "Id": "94984", "Score": "0", "body": "Can we use matplotlib/numpy, or do you want pure python?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T01:13:02.817", "Id": "94985", "Sco...
[ { "body": "<p>I had to write an roipoly in python/numpy/matplotlib as I use that a lot for my work (and I liked the one in Matlab). So here is my implementation of roipoly:</p>\n\n<pre><code>def roipoly():\n XY = ginput(-1)\n\n nrows = sum( abs( r_[ gcf().get_axes()[0].get_xbound() ] ) )\n ncols = sum...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T00:38:52.843", "Id": "54461", "Score": "4", "Tags": [ "python", "optimization", "numpy", "computational-geometry" ], "Title": "Calculating if a point is within a polygon, or o...
54461
<p>This is a draft implementation of a function called COMBINE. It's not intended to be a complex formatting dialect, just a replacement for REJOIN that has a better name and more useful behavior. Its purpose is laid out pretty thoroughly in this blog entry:</p> <p><a href="http://blog.hostilefork.com/combine-alte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T00:24:04.397", "Id": "95715", "Score": "0", "body": "`out: append out delimiter` => `append out delimiter`" } ]
[ { "body": "\n\n<p>Some thoughts:</p>\n\n<h2>Initialize String</h2>\n\n<pre class=\"lang-none prettyprint-override\"><code>unless into [\n out: make string! 10\n]\n</code></pre>\n\n<p>Don't know how else to discern the initial string allocation, perhaps just start with zero?</p>\n\n<p>OUT might be a strange w...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T02:25:35.433", "Id": "54466", "Score": "4", "Tags": [ "formatting", "rebol" ], "Title": "Interface and implementation of this replacement for Rebol/Red REJOIN" }
54466
<p>Per Learn You a Haskell, I implemented a simple command-line program, <code>Todo</code>, that accepts 1 of 3 arguments: <code>view</code> or <code>add</code> or <code>delete</code>.</p> <p>Please review my code for Haskell idioms &amp; overall quality.</p> <pre><code>-- view, add and delete tasks -- borrows delete...
[]
[ { "body": "<p>It looks good overall.</p>\n\n<p>I see two possible problems.</p>\n\n<h2>Race condition in <code>deleteTodo</code></h2>\n\n<p>Running the program twice at the same time you might lose one change because reading the old file, writing the new file and renaming is not atomic.</p>\n\n<p>You can avoid ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T02:38:03.860", "Id": "54467", "Score": "2", "Tags": [ "haskell" ], "Title": "Implementing Todo in Haskell" }
54467
<p>I want to know what needs to improve with my application. Maybe there is a better way instead of what I am using currently.</p> <p><strong>index.html:</strong></p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html lang="en" ng-app="MyApp"&gt; &lt;head&gt; &lt;meta http-equiv="x-ua-compatible" content="IE=9" char...
[]
[ { "body": "<p>Interesting,</p>\n\n<p>a readable Angular submission, I quite like it.</p>\n\n<p>The only trouble I see is that <code>controller.js</code> has some serious copy pastage, you might want to consider a helper function for this part:</p>\n\n<pre><code> $http.post('testws.asmx/AddUser', JSON.stringi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T06:38:44.947", "Id": "54475", "Score": "5", "Tags": [ "javascript", "html", "mvc", "angular.js" ], "Title": "Basic and simple view, add, edit and delete functionality" }
54475
<p>This is a script that I use to add a set of form fields on clicking an <kbd>Add More</kbd> button:</p> <pre><code>&lt;script&gt; $(document).ready(function() { var InputsWrapper = $("#InputsWrapper"); var AddButton = $("#AddMoreFileBox"); var x = InputsWrapper.length; ...
[]
[ { "body": "<p>Put the php code outside the form, run it once and create a variable with the options, something like:</p>\n\n<pre><code>$dropDownList = '&lt;select name=\"vat\" id=\"find\" data-required=\"true\"&gt;&lt;option value=\"\"&gt;Select Vat&lt;/option&gt;';\n\n$query = mysqli_query($con, \"SELECT * FRO...
{ "AcceptedAnswerId": "54478", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T07:24:34.270", "Id": "54477", "Score": "4", "Tags": [ "javascript", "php", "jquery", "html", "form" ], "Title": "Script for adding a set of form fields on clicking an A...
54477
<p>I'm working on <a href="http://www.talentbuddy.co/challenge/5233cc274af0110af382f4105233cc274af0110af382f40e" rel="nofollow">a Talent Buddy challenge</a> . In this challenge you have to design the autocomplete functionality of Twitter. You are given a list of queries and possible usernames. You have to return the mo...
[]
[ { "body": "<p><strong>Organisation of the function</strong></p>\n\n<p>You are doing many things in the same function which make the whole thing a bit confusing. First thing to do is to split the two main parts of the functions : one does preprocessing on <code>usernames</code>, one handles <code>queries</code>....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T08:48:25.823", "Id": "54480", "Score": "6", "Tags": [ "python", "performance", "programming-challenge", "autocomplete" ], "Title": "Typeahead autocomplete functionality challe...
54480
<p>I have to determine if an N sized list of coordinates defines a closed, exact rectangle.</p> <p>I start with the question "How do I check if a list of coordinates is in the shape of a rectangle?" <img src="https://i.stack.imgur.com/MG7id.png" alt="enter image description here"></p> <p>The answer is:</p> <ol> <li...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T11:47:18.713", "Id": "95057", "Score": "0", "body": "I do not understand the problem formulation." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T11:50:13.103", "Id": "95058", "Score": "0", ...
[ { "body": "<p>Regarding elegance, if your <code>BoardPosition</code> class is a plain data structure, make it so.</p>\n\n<pre><code>struct BoardPosition {\n int x;\n int y;\n};\n</code></pre>\n\n<p>Second, regarding efficiency, your <code>checkIfIsRectangle</code> function returns <code>(xIsValid &amp;&am...
{ "AcceptedAnswerId": "54503", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T11:12:29.800", "Id": "54488", "Score": "12", "Tags": [ "java", "computational-geometry", "coordinate-system" ], "Title": "Checking if a list of coordinates defines a closed, ex...
54488
<p>I completed some bit manipulation exercises out of a textbook recently and have grasped onto some of the core ideas behind manipulating bits firmly. My main concern with making this post is for optimizations to my current code. I get the hunch that there are some functions that I could approach better. Do you have a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T06:10:44.700", "Id": "95927", "Score": "0", "body": "Curious, why `~00` instead of `~0`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T06:17:51.147", "Id": "95929", "Score": "0", "body":...
[ { "body": "<p>The comment <code>\\\\ basically sizeof(int) using bit manipulation</code>\nis wrong. <code>sizeof(int)</code> gives the number of bytes (technically, \"storage units\"), but your function gives the number of bits.</p>\n\n<p>If you change the name of the function to something descriptive like <cod...
{ "AcceptedAnswerId": "54502", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T11:57:53.567", "Id": "54494", "Score": "4", "Tags": [ "c", "bitwise" ], "Title": "Is there a more optimal way to approach some of these bitwise functions?" }
54494
<p>It is a simple semaphore in Java. Although it passes all their tests with flying colors, I'm still not sure it's correct.</p> <p>For example, the last thing I wasn't sure about was <code>mLock.lockInterruptibly();</code> vs <code>mLock.lock();</code> in the method called <code>aquire()</code>. And I ended up using ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T12:13:18.973", "Id": "95065", "Score": "0", "body": "Correct as in \"Good style and efficient\" or \"I'm getting the expected results\"? I'm assuming you mean the prior. The way you worded your question could possibly lead people to...
[ { "body": "<p>You should put the lock statements <em>before</em> the <code>try{}finally</code>.</p>\n\n<p>For example if the thread is interrupted before your interruptible acquire then <code>lockInterruptibly</code> will throw and the <code>finally</code> will try to <code>unlock</code> a non-locked lock (whic...
{ "AcceptedAnswerId": "54501", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T12:07:12.240", "Id": "54495", "Score": "7", "Tags": [ "java", "multithreading", "locking" ], "Title": "A simple semaphore in Java" }
54495
<p>Am attempting to recreate a common feature, where a user can type several items in to a textarea, separated by commas and newlines and then submit them, i.e. for multiple record entry.</p> <p>The data does not come from a CSV file and is manually entered. </p> <pre><code>// data looks like this in the textarea: W...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T13:09:38.777", "Id": "95074", "Score": "0", "body": "Welcome to [codereview.se]! IMO your question is off-topic as of our [help/on-topic]. Here on [codereview.se] we do not help with the implementation of new features, as you descri...
[ { "body": "<p>Abstract class is ideal for this:</p>\n\n<pre><code>abstract class ProductsTextareaBase {\n\n protected abstract function getColumns();\n\n public function parse($productsTextarea) {\n $products = explode(\"\\r\\n\", $productsTextarea); // sanitize\n\n $y = 0; \n $productArray = array()...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T12:12:10.453", "Id": "54496", "Score": "5", "Tags": [ "php", "array", "csv" ], "Title": "explode textarea and commas" }
54496
<p>I am trying to make a nice set of items, which are equally spaced from each other. On example below, I set buttons between empty textview. Every button and text view has <code>height = 0dip</code> and <code>weight=1</code>. And it looks pretty nice. However, is there a way to clean up the layout file?</p> <pre><co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T13:32:00.080", "Id": "95089", "Score": "5", "body": "Can you add some screenshot of how this looks for you?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-10T21:53:47.863", "Id": "119801", "Scor...
[ { "body": "<p>I don't know what the standards are for Layout Naming on Android, but I can tell you that these names are not very good.</p>\n\n<ul>\n<li><code>textView2</code></li>\n<li><code>btn_distance_walked</code></li>\n<li><code>textView3</code></li>\n</ul>\n\n<p>none of these accurately describes what the...
{ "AcceptedAnswerId": "68412", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T12:25:42.757", "Id": "54498", "Score": "4", "Tags": [ "android", "xml", "gui", "layout" ], "Title": "Android layout with equal spacing between elements" }
54498
<p>Please review:</p> <pre><code>/// Fetch a value from the `map` or create a new one from the `fun` (memoization). /// Example: \code /// flat_map&lt;string, Frople&gt; fcache; /// Frople&amp; frople = getOrElseUpdate (fcache, id, [&amp;]() {return Frople (id);}); /// \endcode template&lt;typename M, typename K, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T13:10:35.767", "Id": "95075", "Score": "1", "body": "Related: http://codereview.stackexchange.com/q/35180/15094" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T13:26:26.723", "Id": "95085", "S...
[ { "body": "<p>Template parameters are not informative. Better do something like</p>\n\n<pre><code>#define Maptype typename\n#define Keytype typename\n#define Function typename\n\ntemplate &lt;Maptype M, Keytype K, Function F&gt;\n</code></pre>\n\n<p>I was seriously confused with <code>fun</code>. Better call it...
{ "AcceptedAnswerId": "54554", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T13:03:12.057", "Id": "54500", "Score": "5", "Tags": [ "c++", "c++11", "c++14", "memoization" ], "Title": "Memoization helper" }
54500
<p>We are using the Aspose PDF library to work with PDF files. Aspose requires the license to be set once per process. Accordingly, I have created the following common static method that sets the license. Any code that needs Aspose will call into this method.</p> <pre><code>public class ConfigurationService { priv...
[]
[ { "body": "<p>I think you can use a <code>Nullable&lt;bool&gt;</code> or <code>bool?</code> :</p>\n\n<pre><code>private static bool? isAsposePdfLicenseSet = null;\nprivate static bool IsAsposePdfLicenseSet\n{\n get\n {\n if (isAsposePdfLicenseSet == null)\n ConfigurationService.SetAspose...
{ "AcceptedAnswerId": "54513", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T13:54:05.520", "Id": "54506", "Score": "8", "Tags": [ "c#", "constructor" ], "Title": "Should I set a license in the constructor or a static constructor?" }
54506
<p>In my program, I have entities that I call "blobs", because they have a blobby shape. Blobs are polygons. If I have two blobs, then their information array would look like:</p> <pre><code>&gt;&gt;&gt; blobs np.array([ [ [x1, y1], [x2, y2], [x3, y3] ], [ [x1, y1], [x2, y2], [x3, y3] ] ]) </code></pre> <p>Each entry...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T14:43:30.153", "Id": "95107", "Score": "1", "body": "Follow the [Python Style Guide](http://legacy.python.org/dev/peps/pep-0008/)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T14:46:37.127", "I...
[ { "body": "<p>Your existing algorithm is a bit perplexing to me. In particular, the <code>returnBlobIndicesOfRelevantBlobs</code> doesn't really do much except cause the answer to occasionally be wrong. For example here's what I'm using to drive your code:</p>\n\n<pre><code>from timeit import default_timer as...
{ "AcceptedAnswerId": "54562", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T14:18:52.747", "Id": "54510", "Score": "4", "Tags": [ "python", "numpy", "computational-geometry", "clustering" ], "Title": "Calculating the distance between one point, and...
54510
<p>Is there any way of improving this code? (Here's a <a href="http://jsfiddle.net/wDRL7/3/" rel="nofollow">JSFiddle with an example and comments</a>)</p> <p>Example: A hotel greeter can greet guests and accepts tips, but it's impossible to see the total of tips a greeter has received. </p> <pre><code>&lt;!DOCTYPE ht...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T15:13:11.060", "Id": "95124", "Score": "0", "body": "by \"principle of least concern\" do you mean \"[principle of least knowledge](http://en.wikipedia.org/wiki/Law_of_Demeter)\"? or \"[principle of least effort](http://en.wikipedia...
[ { "body": "<p>From the comments, I guess you would like a theoretical review ;)</p>\n\n<ul>\n<li><p>This: </p>\n\n<pre><code>&lt;button onclick=\"javascript:alfred('greet')\"&gt;Arrive at Hotel&lt;/button&gt;\n&lt;button onclick=\"javascript:alfred('acceptTip', 10)\"&gt;Tip Alfred $10&lt;/button&gt;\n</code></p...
{ "AcceptedAnswerId": "55457", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T14:42:36.747", "Id": "54515", "Score": "5", "Tags": [ "javascript", "design-patterns", "mvc" ], "Title": "A hotel greeter named Alfred" }
54515
<p>I have a cookie where a number is stored. When I want to add "1" to the stored number and then overwrite it, I use this php code:</p> <pre><code>$temp = $_COOKIE['mycookie']++; $_COOKIE['mycookie']=$temp; </code></pre> <p>Is it the best way to do that?</p>
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T17:37:27.137", "Id": "95164", "Score": "1", "body": "You have edited to say your code is working, yet, in its current form, it can't be. `$temp` will be the value of the cookie prior to the [post-increment](http://www.php.net//manua...
[ { "body": "<p>There's nothing wrong with just</p>\n\n<pre><code>$_COOKIE['mycookie']++;\n</code></pre>\n\n<hr>\n\n<p>Note that this answer is incorrect. See the accepted answer.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T15:16:43.153", ...
{ "AcceptedAnswerId": "54519", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T15:01:28.167", "Id": "54517", "Score": "3", "Tags": [ "php" ], "Title": "Add \"1\" and overwrite the previous value" }
54517
<p>I have been translating a solution from C# into VB.Net, because I know more VB and wanted to understand it better. I have a version up and running that replicates the C# performance with small input files; however with an input file over ~8MB the memory usage skyrockets and it will keep chugging until it consumes al...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T15:49:31.597", "Id": "95141", "Score": "1", "body": "Just to be clear, the C# code works flawlessly with larger files?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T19:06:16.213", "Id": "95188",...
[ { "body": "<p>I haven't looked at the C# code, just a few quick remarks here:</p>\n\n<ul>\n<li><code>BuildSchedule</code> is doing too many things. I'd probably try to extract a method out of each <code>Case</code> block.</li>\n<li><code>If True Then</code> is useless clutter; don't even think, remove it.</li>\...
{ "AcceptedAnswerId": "54536", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T15:34:20.907", "Id": "54520", "Score": "5", "Tags": [ "performance", "memory-management", "vb.net" ], "Title": "Program falls over with larger input files" }
54520
<p>I'm working on a little django quiz taking app. Currently I'm making it's models. So far I've got <code>Quiz</code>, <code>Question</code>, <code>Answer</code>, and <code>Response</code> designed as follows:</p> <pre><code>from django.db import models from npage.mixins import TranslatedModelMixin from django.contri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T12:59:32.463", "Id": "101692", "Score": "1", "body": "Thank you for using my quiz app, I hope that it is helpful. I have added few changes which you might find useful: https://github.com/tomwalker/django_quiz/" } ]
[ { "body": "<p>You could have an abstract superclass <code>Response</code> which has concrete derived classes of <code>multipleChoiceResponse</code> and <code>freeResponse</code>. Then you can have a method such as <code>checkResponse</code> which is different for each type of respones.</p>\n\n<p>EDIT:</p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T15:41:46.193", "Id": "54522", "Score": "6", "Tags": [ "python", "mvc", "django", "quiz" ], "Title": "Improving models for a Django quiz" }
54522
<p>I'm trying to figure out a way to do the exercise 3.20 in the C++ primer book</p> <p>I have to create a program that reads input into a vector then use that data to create 2 outputs:</p> <ul> <li>one is the sum of each adjacent number</li> <li>one is the sum of the first and last number moving inwards (as in the 2...
[]
[ { "body": "<p>In order to print the sum of consecutive pairs, you sure could make things easier :</p>\n\n<ul>\n<li>instead of having <code>cnt</code> take the values [0], then [1, 2], [1, 2], [1, 2], etc (square brackets represents one loop), <code>cnt</code> could take the values [0], [1], [2], etc. Then, you ...
{ "AcceptedAnswerId": "54561", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T16:02:44.587", "Id": "54527", "Score": "8", "Tags": [ "c++", "c++11" ], "Title": "Using inputted data from vector to create two outputs" }
54527
<p>I didn't write this but I noticed it in our codebase at work.</p> <pre><code>var data = object &amp;&amp; object.attribute &amp;&amp; object.attribute.data ? object.attribute.data : {}; </code></pre> <p>I get that the programmer is trying to check that the variable <code>object.attribute.data</code>is defined befo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T17:20:25.120", "Id": "95155", "Score": "1", "body": "Welcome to Code Review! Are you asking for alternatives for a *ternary operator*? I'd bet your question would get more lovin' if you included the whole function instead, and menti...
[ { "body": "<p>Are you looking for this?</p>\n\n<pre><code>var data = object &amp;&amp; object.attribute &amp;&amp; object.attribute.data || {};\n</code></pre>\n\n<p>Alternatively, you could create a simple function to safely index objects that may not be defined, such as:</p>\n\n<pre><code>function resolve(valu...
{ "AcceptedAnswerId": "54532", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T17:10:40.043", "Id": "54531", "Score": "3", "Tags": [ "javascript", "validation" ], "Title": "Checking if variable is defined before accessing its properties" }
54531
<p>I am implementing a flood fill algorithm using Python and NumPy. I have written the following fill function which works fine:</p> <pre><code>def fill(self, data, xsize, ysize, x_start, y_start): stack = [(x_start, y_start)] while stack: x, y, stack = stack[0][0], stack[0][1], stack[1:] i...
[]
[ { "body": "<p>Instead of using a <code>list</code> to store your points (which has an \\$O(n)\\$ look-up time), you can use a <code>set</code> object which has an \\$O(1)\\$ look-up time. For more information regarding Pythonic time complexity, you can look <a href=\"https://wiki.python.org/moin/TimeComplexity\...
{ "AcceptedAnswerId": "54550", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T17:31:14.757", "Id": "54534", "Score": "4", "Tags": [ "python", "numpy" ], "Title": "Flood fill algorithm" }
54534
<p>I've written a simple class which should:</p> <ul> <li>get 10 top cars and 10 top bicycles from database</li> <li>write them into 2 different arrays</li> </ul> <p>It works, but I'm trying to find a simpler or clearer solution.</p> <pre><code>class TopVehicles extends Connection { private $sql1 = 'SELECT model...
[]
[ { "body": "<p>As far as I see the only difference is the type inside the SQL query. So why not pass that as parameter.</p>\n\n<p>You could also think of creating additional classes for car and bicycle which call the getTop method of another class with the right parameters or if you extend the vehicle class set ...
{ "AcceptedAnswerId": "54548", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T18:02:31.673", "Id": "54537", "Score": "3", "Tags": [ "php", "object-oriented" ], "Title": "Getting cars and bicycles from a database and writing them into two different arrays" }
54537
<p>The code that I am sharing here for you to review today, is a segment of a JavaScript library that I am going to write as time goes by for fun. It is only the two functions in the following code:</p> <pre><code>/*jslint browser: true, indent: 8 */ /*global console */ /* Sorts matrix like from something lik...
[]
[ { "body": "<p><strong>Partial answer.</strong> Wait around and I'm sure someone will do the actual reduction function justice. It's a bit much for me to digest right now.</p>\n\n<p>From a cursory glance, though, I'd suggest breaking things out into functions where possible. But again, I haven't delved too deep....
{ "AcceptedAnswerId": "54563", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T18:05:47.677", "Id": "54539", "Score": "5", "Tags": [ "javascript", "beginner", "mathematics", "matrix" ], "Title": "Linear algebra, reduced row echelon form" }
54539
<p>I had a ugly problem and wrote an ugly query. </p> <p>Query creates a cache that is used to get person id when I have {full_name, id_code?, birth_date?}. By question mark I mean that it is perfectly valid for person not to have {id_code, birth_date} entered.</p> <pre><code>var searchvalue1 = String.Format("{0} {1}...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T18:19:02.473", "Id": "95179", "Score": "0", "body": "I can also remove **o.DATE_CREATED** from pre-query." } ]
[ { "body": "<p>Code seemed obfuscated and I cleared it up. Now code gets used as :</p>\n\n<pre><code>.Where(ma =&gt; Find.Person(ma, out person, ctx) || Insert.Person(ma, out person, ctx))\n</code></pre>\n\n<p>I created a method and 3 overloads</p>\n\n<pre><code>public static bool Person(managersTypeManager ma, ...
{ "AcceptedAnswerId": "55207", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T18:16:11.273", "Id": "54540", "Score": "2", "Tags": [ "c#", "entity-framework", "oracle", "lambda" ], "Title": "Refactor Oracle Entity Framework lambda query" }
54540
<p>I've taken a crack at implementing <a href="https://github.com/paulgb/simplediff">Simple Diff</a> in Rebol (versions 2 and 3). Simple Diff works by finding the longest common sequence in two series, then recursively applies itself either side of this sequence until there is nothing further in common. It returns a ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T19:06:36.640", "Id": "95189", "Score": "0", "body": "I notice `diff [[=] [+] [-]] [[-] [+] [=]]` produces `[- [[=] [+] [-]] + [[-] [+] [=]]]`. Offhand I can't tell if `[- [[=] [+]] = [[-]] + [[+] [=]]]` would be more useful...? I...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T18:33:26.790", "Id": "54541", "Score": "8", "Tags": [ "algorithm", "rebol" ], "Title": "Implementing Simple Diff in Rebol" }
54541
<p>The test </p> <pre><code>PublicQuestion_ComplexTest </code></pre> <p>is taking around 1600ms (1.6 seconds) to run, but used to take 92ms. I have a feeling this is because of recent code changes that include <code>.Count()</code> in many places within these 2 functions:</p> <pre><code>RemoveSmallerLengthNumberList...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T18:59:45.663", "Id": "95186", "Score": "2", "body": "Only glanced at your code, but you should use `.Count` (property) on `List<T>`. The `.Count()` method works off the `IEnumerable<T>` and iterates the entire collection. You need t...
[ { "body": "<p>In <code>CropNumbersToBeWithinAllowances()</code> you do</p>\n\n<pre><code>newCombination.Where(x =&gt; x == currentValue).Count()\n</code></pre>\n\n<p>inside the <code>for</code> loop. <code>newCombination</code> is of type <code>List&lt;T&gt;</code> so calling <code>Count()</code> on that would ...
{ "AcceptedAnswerId": "54871", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T18:42:04.737", "Id": "54542", "Score": "5", "Tags": [ "c#", "performance", "array" ], "Title": "Tests using .Count() on Lists" }
54542
<p>Can anyone give me feedback please? I used what I have learnt so far, mainly methods, loops and arrays. I would like you view based on these topics, however, comments on how to improve are welcome. </p> <pre><code>/*ask the user for 10 numbers store them in an array print them "your numbers are:" print them "Averag...
[]
[ { "body": "<ul>\n<li><p>The Java standard dictates the use of the \"Egyptian braces\" style:</p>\n\n<pre><code>if (something) {\n // something...\n}\n</code></pre></li>\n<li><p>In <code>AvarageCalc()</code>:</p>\n\n<blockquote>\n<pre><code>int avarage = sum / population;\nreturn avarage;\n</code></pre>\n</bl...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T20:43:01.127", "Id": "54555", "Score": "7", "Tags": [ "java", "beginner", "array", "extension-methods" ], "Title": "Output in one window" }
54555
<blockquote> <p>Given a suffix array for a word, check if a pattern (consecutive chars) exists.</p> <p>Example:</p> <p>A suffix array constructed for "ameya" should return true for "ame" but false for "foo" or false for "ameyp".</p> <p>This algoritm is case sensitive.</p> </blockquote> <p>I'm looking ...
[]
[ { "body": "<p>Since you have a hidden implementation requirement that the suffix be sorted (i.e. binary search), you should sort the array before assigning it to the member variable.</p>\n\n<p>Your <code>compare</code> implementation differs from that of the String class in that it returns 0 if <code>str</code>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T20:49:28.653", "Id": "54557", "Score": "2", "Tags": [ "java", "algorithm", "strings", "array" ], "Title": "Given suffix array and a pattern, search if given pattern exists" }
54557
<p>I love making utility State enums, and giving them methods that do useful things based on which instance of the enum is provided. This works when the enum is very specific to the class I'm working on, but can often make no sense when I need to switch on the enum type but I don't want the enum itself to know anything...
[]
[ { "body": "<p>It's really hard to tell which parts of your code are the problem you are trying to solve, and which parts are the example. I think that's a hint that the solution has made things worse, rather than better.</p>\n\n<p>Attempting to summarize your constraint - you want to use an enum to select the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T21:32:30.360", "Id": "54560", "Score": "3", "Tags": [ "java", "design-patterns", "enum" ], "Title": "An attempt to extend an enum to prevent branching without violating the Open-C...
54560
<p>I have created a class that will manage my session. I am hoping to acomplish a class that will secure my site from all known attacks (ie. fixation, precedent, and capture.)</p> <p>The idea is to</p> <ol> <li>Change the session storage engine from files on the servers to a database.</li> <li>Create a random session...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T00:17:15.107", "Id": "95219", "Score": "0", "body": "IP verification can give false positives for mobile users. When moving between different service areas a cellular IP device may receive a new IP. You need to consider if you want ...
[ { "body": "<p>I like this question because I think it has a lot of answering potential. I'm going to touch on a few things, but my answer shouldn't be considered complete!</p>\n<h2>Security of custom sessions</h2>\n<p>There's one thing that's most important here: <strong>don't roll out a security system that's ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T22:11:07.893", "Id": "54564", "Score": "4", "Tags": [ "php", "security", "session" ], "Title": "How to regenerate my session ID often when using this class?" }
54564
<p>I have a project which should be thought of split into two layers: an IO layer which consists of sensors (input) and effectors (output), and a core layer which contains logic for determining which actions are desired from particular observations. The IO layer is dependent on the core layer, and the core layer is ign...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T07:51:20.380", "Id": "95258", "Score": "0", "body": "How is the observation created for use in `ProcessObservation`? What is its type? Do you have an example of a semi-functioning Robot that you could post." }, { "ContentLi...
[ { "body": "<p>From my understanding of the problem we have, <br />\n<UL>\n<LI>On the input side - a set of arbitrary observations. The data in each of which can/will be different. </LI>\n<LI>On the output side - a set of possible actions that can be effected. The action is decided based upon the observations a...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T22:26:15.467", "Id": "54566", "Score": "5", "Tags": [ "c#", "generics" ], "Title": "Defining instructions for a robot's movements" }
54566
<p>I am testing a quicksort implementation. Arrays of random size with random data are passed to quicksort and the return time is averaged out. The user is prompted to enter values for</p> <ul> <li>minimum length of array</li> <li>maximum length of array</li> <li>maximum value in array</li> <li>minimum value in array<...
[]
[ { "body": "<p>I'm not sure if you need all of that in <code>yes_no()</code>. The top answer to the commented question gives something a bit shorter (also no <code>OUTER</code>), and another states that you can just return <code>true</code> if the user inputs 'y', otherwise return <code>false</code>. I'd proba...
{ "AcceptedAnswerId": "54580", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T22:34:19.837", "Id": "54567", "Score": "6", "Tags": [ "java", "unit-testing", "sorting", "quick-sort", "user-interface" ], "Title": "Testing quicksort user input" }
54567
<p>I am trying to solve as many issues as possible with my Database Class and bind statements as far as possible without actually doing it in the front-end. The goal is to do all of the heaving lifting for PHP Developers and Web Designers as possible to make their job even more easier than other PHP frameworks.</p> <p...
[]
[ { "body": "<p>This may sound harsh, I meant to be friendly though :)</p>\n\n<p><strong>It's bad/unsafe/vulnerable</strong>. This type of situation comes around a lot, which is sort of understandable. However, <strong>what is your class really doing?</strong> It's essentially pointless to make this class. You've...
{ "AcceptedAnswerId": "54569", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T22:38:05.357", "Id": "54568", "Score": "5", "Tags": [ "php", "object-oriented", "design-patterns", "php5", "pdo" ], "Title": "Secure Functions in a Database Class" }
54568
<p>I want to see if this is as streamlined as possible. Most of the logic is accomplished through methods in the model. The controller does one of four things: </p> <ol> <li>redirects new users to registration</li> <li>sends locked users to reset password</li> <li>logs the user in and redirects them to where they sh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T23:41:48.143", "Id": "95217", "Score": "0", "body": "Since I don't actually use any of the other methods in the model until after I've already verified the account exists in the controller, I am wondering it would be safe to remove ...
[ { "body": "<p>Viewmodels from my understanding should be as lean as free of domain logic as possible. This is because they are a link from your domain model to your view and so can provide a layer/separation between the two if your view incorporates elements from various places/models.</p>\n\n<p>Hence, all the...
{ "AcceptedAnswerId": "54575", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T23:31:57.490", "Id": "54570", "Score": "3", "Tags": [ "c#", "beginner", "asp.net-mvc-3", "authentication" ], "Title": "User Login Logic" }
54570
<p>I have <a href="https://gist.github.com/hjpotter92/8a4ec34b1c58dadf74a1" rel="nofollow">the following function</a> which converts an integer (such as 103) to its string representation ("one hundred three"):</p> <pre><code>NumberToString = (function () local floor, abs, num, tens, bases = math.floor, math.abs, {...
[]
[ { "body": "<p>After a bit of dabbling with the script, I've updated the line <a href=\"https://gist.github.com/hjpotter92/8a4ec34b1c58dadf74a1/082602dcae9b31707de2146d4617171c0c4dda73#file-numbertostring-lua-L42-L53\" rel=\"nofollow\">#42 to #53</a> with a table iterator:</p>\n\n<pre><code>for _, ext in ipairs(...
{ "AcceptedAnswerId": "54613", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-17T23:49:30.490", "Id": "54572", "Score": "6", "Tags": [ "strings", "converting", "integer", "lua", "lua-table" ], "Title": "Converting the integers to their equivalent st...
54572
<p>I don't know why this is not in the .NET Library, but I need to be able to use an index against a list and not have it throw an exception if it is outside the bounds of the list.</p> <p>This is what I came up with:</p> <pre><code>public static class LinqHelpers { public static TListType IndexOrDefault&lt;TList...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T22:46:58.420", "Id": "95490", "Score": "0", "body": "If the `Count()` _were_ an issue (it isn't, see below) you could move the `if(index<0) return default(T)` above that to avoid calculating the count where you don't actually need i...
[ { "body": "<blockquote>\n<pre><code>public static TListType IndexOrDefault&lt;TListType&gt;(this List&lt;TListType&gt; list, int index)\n</code></pre>\n</blockquote>\n\n<p>You're extending a concrete type, and the type parameter's name is misleading - it's not the type of the <em>list</em>, it's the type of its...
{ "AcceptedAnswerId": "54577", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T00:10:17.833", "Id": "54574", "Score": "5", "Tags": [ "c#", ".net", "linq", "extension-methods" ], "Title": "IndexOrDefault that functions like FirstOrDefault" }
54574
<p>I have the below mentioned function written in plpgsql which is working fine. I want someone to review it and let me know how can I improve its performance.</p> <p>This function takes data from staging table and inserts into target tables. Before it inserts, it checks for the existing records, and if any records ex...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T11:00:36.080", "Id": "95338", "Score": "0", "body": "Note: Bill_id in bill_head_details is a foreign key to bills table" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T00:37:43.503", "Id": "95517"...
[ { "body": "<p>Let's take a quick look at your Delete query while we wait for your schema definition.\nI took the liberty of properly indenting the code block. Looks like we've got some arrow code here.</p>\n\n<pre><code>--delete from bills the records which are being updated\nDELETE FROM ccdb.bills\nWHERE bill_...
{ "AcceptedAnswerId": "54622", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T00:24:55.307", "Id": "54576", "Score": "3", "Tags": [ "performance", "sql", "postgresql" ], "Title": "Taking data from staging table and inserting into target tables" }
54576
<p>I posted this code in an answer earlier today, but thought it was worth seeing if somebody could suggest further improvements:</p> <pre><code>#include &lt;numeric&gt; #include &lt;vector&gt; #include &lt;iterator&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; template &lt;class InIt, class OutIt&gt; OutI...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T20:12:10.510", "Id": "95872", "Score": "0", "body": "Your `std::transform()` code misses the middle number on an odd-sized input." } ]
[ { "body": "<p>You're likely aware of these limitations and they're implicit pre-conditions to <code>adjacent_sum</code>, but just for the sake of it being CodeReview, I have two criticisms with regards to <code>adjacent_sum</code>, one fairly major, and the other minor.</p>\n\n<p>An explicit check for empty ran...
{ "AcceptedAnswerId": "54655", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T00:51:45.850", "Id": "54579", "Score": "11", "Tags": [ "c++", "c++11" ], "Title": "Code for sums in a vector" }
54579
<p>Please evaluate this function. It takes a list <code>[a]</code> and an <code>Int</code>, i.e. the index, and returns a new list with the selected item at the top of the list. Note that it returns <code>Maybe [a]</code> to account for bad indexes.</p> <pre><code>pushToTop :: [a] -&gt; Int -&gt; Maybe [a] pushToTop [...
[]
[ { "body": "<p>Yes, the guards make <code>!!</code> safe, but your code has other issues, stylistic and functional:</p>\n\n<h1>Unneeded pointful style</h1>\n\n<p>First, it's often a good idea to try running your code through <a href=\"http://community.haskell.org/~ndm/hlint/\" rel=\"nofollow\">HLint</a>. Doing ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T02:55:51.950", "Id": "54583", "Score": "4", "Tags": [ "haskell" ], "Title": "Push List Element to Top" }
54583
<p>I'm working on a basic strategy game for iOS and I have a question about the overall layout of the code in the program. I added some features to the game today and I had to add code to several different places to get the features to function properly. In general I think I am doing things correctly, but I fear I am...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T11:33:00.850", "Id": "95343", "Score": "1", "body": "`if (tempFloor.floorState == FloorUnderAttack)` and `if (tempFloor.floorState == FloorDestroyed)` -- you probably need to replace the `==` with `&` for your bitmask here." }, ...
[ { "body": "<p>On a quick scan of your code, I noticed that you missed a <code>break;</code> in the <code>case RoomBuildJob:</code>. Missing a break will cause control to fall through to the next <code>case</code>, which will probably do the wrong thing.</p>\n", "comments": [ { "ContentLicense"...
{ "AcceptedAnswerId": "54702", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T03:15:56.317", "Id": "54584", "Score": "5", "Tags": [ "object-oriented", "game", "objective-c" ], "Title": "Adding features to a strategy game" }
54584
<p>This is the function I've implemented in an answer to <a href="https://codereview.stackexchange.com/questions/30593/split-a-long-integer-into-eight-4-bit-values">this question</a>. I've tried to make this as simple and idiomatic as possible, using C++11. Could this still be improved in any way?</p> <pre><code>#in...
[]
[ { "body": "<p>The first problem I see is that you're doing a right shift on a signed integer type (<code>std::int32_t</code>).</p>\n\n<p>If a negative value is passed, the result will be implementation defined. When you're going to treat something as a collection of bits instead of treating the whole thing toge...
{ "AcceptedAnswerId": "54588", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T04:30:16.407", "Id": "54587", "Score": "3", "Tags": [ "c++", "c++11", "bitwise", "integer" ], "Title": "Function for splitting an integer into smaller values" }
54587
<p>Last semester in my Masters Program I developed this code for sieving. My professor wants me to write a report that he might use locally within the school, but I feel like I've done nothing that new, despite coming up with my algorithm without doing any research other than the bare numbers.</p> <p>Essentially it sk...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T10:27:27.833", "Id": "95327", "Score": "0", "body": "Can anyone provide insight as to the time complexity? I've found it to be quite fast but I think I got the time complexity wrong." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<ul>\n<li><p>I'd rename <code>Numbers</code> to <code>isPrime</code></p></li>\n<li><p><code>num</code> is not needed. <code>maxNumber</code> serves the same purpose.</p></li>\n<li><p>Termination condition in the elimination loops must be <code>&lt;</code>, not <code>&lt;=</code>. With an unfortunate ...
{ "AcceptedAnswerId": null, "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T05:07:26.290", "Id": "54591", "Score": "11", "Tags": [ "java", "algorithm", "primes", "sieve-of-eratosthenes" ], "Title": "Prime Number Sieving Algorithm" }
54591
<p>I'm becoming acquainted with ruby by taking some of my legacy shell scripts and rewriting them as .rb.</p> <p>The pattern that is emerging is that I have a number of different dumb tasks, that do what they are told, and a coordinator that is responsible for ordering the tasks, and providing to the tasks the data th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-24T14:11:58.023", "Id": "96511", "Score": "1", "body": "What's your question here? Also, why not use Rake as your task runner?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-06-26T00:58:46.767", "Id": "17...
[ { "body": "<p>The standard American English spelling is \"converter\", not \"convertor\". If it's different where you live, use the appropriate regional spelling, but if you live in America, use the American spelling. Since I do, I did.</p>\n\n<p>You have <code>@converter</code> and <code>@uploader</code>, but ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T05:57:26.317", "Id": "54593", "Score": "4", "Tags": [ "ruby" ], "Title": "Argument passing to dumb tasks" }
54593
<p>Please take a look at this <a href="http://jsfiddle.net/9mwCG/39/" rel="nofollow">Fiddle</a>.</p> <p>Is there a better way of building a table with titles in the first cell of each row, like this:</p> <pre><code>&lt;div id="area"&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;&lt;/th&gt; &lt;th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T07:06:36.830", "Id": "95254", "Score": "0", "body": "Hmm, well, I think your headline should be fixed by the HTML, and the rest arriving from JSON. Also, the first cell of each row should be a `<th>` if it's a title as well." } ]
[ { "body": "<p>you can merge </p>\n\n<pre><code> var item_html=\"\";\n\n item_html += \"&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;\"; \n</code></pre>\n\n<p>to</p>\n\n<pre><code>var item_html=\"&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;\"; \n</code></pre>\n\n<p>and i also cant see ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T06:36:03.587", "Id": "54595", "Score": "2", "Tags": [ "javascript", "jquery", "html", "ajax" ], "Title": "Simplifying AJAX success code" }
54595
<p>Finding the nearest polygon out of a list of polygons seems to be quite a challenge on performance, due to lack of optimization.</p> <p>Consider the following image:</p> <p><img src="https://i.imgur.com/zFEUcd0.gif" alt="Polygon Planets"></p> <p>I'll give the concept behind this. The "purple" pointer under the mo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T12:17:11.243", "Id": "95350", "Score": "0", "body": "Consider posting the full implementation, including helper functions, as you'll be more likely to get a good answer if reviewers can easily run your code." } ]
[ { "body": "<p>If shape and number of polygons do not change (or at least not often), I would add an extra step (the new first step) to your algorithm.</p>\n\n<p>Calculate the center and radius of the smallest surrounding circle for each polygon. This way you can calculate in a minimal and maximal distance of al...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T07:38:41.947", "Id": "54598", "Score": "10", "Tags": [ "performance", "computational-geometry", "clustering", "collision", "gml" ], "Title": "Finding the nearest polygon" ...
54598
<p>I have a own made grid system and made a jQuery function for that to check if there are not too many <code>column</code>s in each <code>row</code>. If so, delete the HTML code of the row.</p> <p>Normally in my grid system, there fits 12 columns in 1 row, but I can change that.</p> <p>In HTML, I've written them lik...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T09:11:09.303", "Id": "95278", "Score": "0", "body": "To be honest, this shouldn't be done with jQuery. This shouldn't be done at all in the first place. this smells of an XY problem, try defining what you are really trying to do" ...
[ { "body": "<p>You could try: </p>\n\n<ol>\n<li>Using <a href=\"http://api.jquery.com/multiple-selector/\" rel=\"nofollow\">Multiple selectors</a> </li>\n<li>Moving the calculation logic to a function so that you can re-use it elsewhere or refactor/change in a single place if the need be. </li>\n</ol>\n\n<p...
{ "AcceptedAnswerId": "54609", "CommentCount": "17", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T08:23:13.350", "Id": "54606", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Checking number of of columns in a row" }
54606
<p>How to make the following code more efficient?</p> <pre><code>""" Calculate the posterior distribution of p(pos|word) using Baye's rule: p(pos|word) \propto p(word|pos)p(pos). """ word_pos_dict = defaultdict(float) # Example, word|pos -&gt; 0.0012 pos_dict = defaultdict(float) # pos -&gt; 0.005 pos_word_...
[]
[ { "body": "<blockquote>\n <p>which make this calculation much slower.</p>\n</blockquote>\n\n<p>An immediate question is <em>much slower than what?</em></p>\n\n<p>Few optimisations are obvious, but they are just nitpicking. Asymptotics remains same no matter what.</p>\n\n<p>First, I'd make <code>word_pos_dict</...
{ "AcceptedAnswerId": "54619", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T08:58:11.913", "Id": "54610", "Score": "2", "Tags": [ "python", "optimization", "python-3.x", "hash-map" ], "Title": "The efficiency of looping over nested dictionaries in ...
54610
<p>First, I'm in no way an experienced PHP coder. This is my 5th time working with PHP, so if you see anything that can bee improve, please point them out for me.</p> <p>I have the code checking for the <code>$_GET</code> variable and use them to create the page title:</p> <pre><code>&lt;?php $pgeName = safeVal(basen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T10:38:53.850", "Id": "95330", "Score": "3", "body": "If you're having performance issues, isset() is not the problem. Focus on writing readable and maintainable code, if you (and others) find isset() readable, use isset()." }, {...
[ { "body": "<p>Isset should not affect performance.</p>\n\n<p>About code improvements I suggest you to write some kind of wrapper above Request to improve readability</p>\n\n<pre><code>&lt;?php \nclass RequestData {\n public function __construct($val) {\n $this-&gt;val = $val;\n }\n\n public function r...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T09:42:11.393", "Id": "54617", "Score": "8", "Tags": [ "php", "performance", "beginner", "php5", "null" ], "Title": "PHP isset over use? Good or bad?" }
54617
<p>I've just started learning Swift. I started with an example of RSS feed parser. I have a wrapper class written in Objective-C which converted the XML response into <code>NSDictonary</code>. I'm using the <code>NSDictionary</code> returned from my wrapper class. Then I need to iterate through the <code>NSDictionary<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T21:18:22.250", "Id": "95702", "Score": "0", "body": "What is your familiarity level with Objective-C and the Foundation framework? Also, is `enumerate()` a Swift method? Or is this one you've written yourself?" }, { "Conte...
[ { "body": "<p>Calling the <code>enumerate()</code> function here is completely unnecessary as we don't seem to care about the index of the objects. What <code>enumerate()</code> does is give you a tuple containing the index of the object in the array and the object at that index.</p>\n\n<p>Normally, <code>fori...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T09:53:46.753", "Id": "54618", "Score": "6", "Tags": [ "hash-map", "rss", "swift", "foundation" ], "Title": "RSS feed parser" }
54618
<p>From <a href="http://en.wikipedia.org/wiki/Swift_(programming_language)" rel="nofollow noreferrer">Wikipedia</a>:</p> <blockquote> <p>Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, iPadOS, macOS, watchOS, tvOS, Linux, and z/OS. Swift is designed to work ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-06-18T10:24:44.593", "Id": "54620", "Score": "0", "Tags": null, "Title": null }
54620
Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, iPadOS, macOS, watchOS, tvOS, Linux, and z/OS.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-06-18T10:24:44.593", "Id": "54621", "Score": "0", "Tags": null, "Title": null }
54621
<p>I am doing a validation and I believe that there are many things that can be reduced or removed. I am still re-working this. But I am looking for some experts to look at my code and offer the very best approach for both individual and form submit error handling.</p> <pre><code>(function(){ var calledIt = func...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T15:09:35.250", "Id": "95622", "Score": "0", "body": "In your title you mention memory-leak but not in the text of your question, are you sure there is such a problem ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDat...
[ { "body": "<p>The design problems in this code bother me a lot more than the code problems.</p>\n\n<ul>\n<li>Every single input type is mandatory, that seems not very useful, you should have a class or something other to identify which fields are mandatory</li>\n<li>Your text input fields dont have the <code>id...
{ "AcceptedAnswerId": "55486", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T11:24:09.910", "Id": "54623", "Score": "3", "Tags": [ "javascript", "jquery", "validation" ], "Title": "Can this form validation be simplified made to memory leak free for all ...
54623
<p>Wrapper:</p> <pre><code>internal static class Cache { private static ObjectCache InternalCache { get { return MemoryCache.Default; } } private static T CacheOrGetExisting&lt;T&gt;(string key, Func&lt;T&gt; valueFactory) { T value; object uncas...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T14:21:18.593", "Id": "95388", "Score": "1", "body": "I'd start getting worried long before I had this many `static`s in such a small area." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T14:27:33.480"...
[ { "body": "<p>As Magus pointed out in the comments, making everything static can present some issues. Using these static properties in other classes makes those classes tightly coupled to the <code>Cache</code> class. Why should you care? Consider this class:</p>\n\n<pre><code>public class Bar\n{\n public in...
{ "AcceptedAnswerId": "54650", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T11:48:10.250", "Id": "54624", "Score": "2", "Tags": [ "c#", "asp.net", "cache", "asp.net-mvc" ], "Title": "Is my ObjectCache wrapper sound?" }
54624
<p>This challenge is from <a href="http://www.talentbuddy.co/challenge/52a9121cc8a6c2dc91481f8d5233cc274af0110af382f40f" rel="noreferrer">Talent Buddy</a>:</p> <blockquote> <p><strong>Tweets per second</strong></p> <p>Japan Castle in the Sky airing broke a Twitter record on August 3, 2013. At one point during...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T12:41:33.433", "Id": "95352", "Score": "0", "body": "By 'fails' do you mean it errors? Or do you mean that it runs, just not in 2 seconds?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T12:42:10.370"...
[ { "body": "<p><strong>Making your solution better</strong></p>\n\n<p>You won't get a huge performance boost unless you change your algorithm.\nAnyway, let's try to see what could be done to improve your code.</p>\n\n<p>You are playing with a variable <code>start</code>. It is easy to check that a few properties...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T12:36:59.697", "Id": "54625", "Score": "5", "Tags": [ "python", "performance", "programming-challenge", "interval" ], "Title": "Tweets per second" }
54625
<p>I'm new to Python, with some background in Java and C# from a while ago, and more recently in scripting worlds like Bash and AppleScript.</p> <p>I wanted to be able to create classes that could</p> <ol> <li>report their instances</li> <li>limit their number of instances.</li> </ol> <p>Synthesizing various answers...
[]
[ { "body": "<p>Generally, that all looks pretty good - Pythonic and well laid out. A few possible improvements below.</p>\n\n<hr>\n\n<p>Per <a href=\"http://legacy.python.org/dev/peps/pep-0008/#imports\" rel=\"nofollow\">PEP-0008</a>, multiple imports from the same module can be done on one line, and I would rec...
{ "AcceptedAnswerId": "54628", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T12:42:06.403", "Id": "54627", "Score": "3", "Tags": [ "python", "beginner", "object-oriented" ], "Title": "Base class for subclasses that can track their own instances" }
54627
<p>I'm working on a photo website, the markup looks like this:</p> <pre><code>&lt;div class="gallery"&gt; &lt;figure&gt; &lt;img src="photo1.jpg" /&gt; &lt;figcaption&gt;Photo 1&lt;/figcaption&gt; &lt;/figure&gt; &lt;figure&gt; &lt;img src="photo2.jpg" /&gt; &lt;figcaption&g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T13:34:13.373", "Id": "95364", "Score": "1", "body": "Why do you think negative margins is a hack?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T13:36:15.903", "Id": "95365", "Score": "1", ...
[ { "body": "<p>First, I will start with the good:</p>\n\n<pre><code>&lt;figure&gt;\n &lt;img src=\"photo1.jpg\" /&gt;\n &lt;figcaption&gt;Photo 1&lt;/figcaption&gt;\n&lt;/figure&gt;\n</code></pre>\n\n<p>It is excellent that you use the HTML5 tag <code>figure</code> instead of a plain old <code>div</code>.<...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T13:29:08.933", "Id": "54631", "Score": "7", "Tags": [ "html", "css", "image", "sass" ], "Title": "Photo gallery layout" }
54631
<p>I have a Servlet that makes an EJB call to a backing server which takes about a second to return some data that changes reasonably regularly.</p> <p>I can't cache the data on the servlet-side, so I have decided to put the call to the EJB into a separate thread and use a Future to get the data as late as possible. T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T14:05:35.953", "Id": "95381", "Score": "0", "body": "I am not sure this compiles: `private RosterEJB rosterEJB=...;`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T14:07:45.873", "Id": "95384", ...
[ { "body": "<p>The concurrency looks complete to me in the sense that I cannot see any places it can fail, or block significantly. The static <code>LOCK</code> and <code>Future</code> make sense. The <code>getLocalRosterRequest</code> itself is technically correct in the sense that it returns the right results, ...
{ "AcceptedAnswerId": "68364", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T14:01:06.313", "Id": "54635", "Score": "3", "Tags": [ "java", "multithreading", "locking", "servlets" ], "Title": "Mutualising multi-threaded calls to EJB from Servlet" }
54635
<p>In a Win Form I'm doing initial validation in the Form. So before saving data, I want to validate whether all the required fields are filled (Text Boxes) by the user. There are about 18 such Text Boxes in the Form. Currently I'm doing it as follows. To make the code short only three fields are shown in the code.</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T14:37:50.413", "Id": "95394", "Score": "6", "body": "Look into `string.IsNullOrEmpty()` or `string.IsNullOrWhiteSpace()`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T19:24:20.430", "Id": "9545...
[ { "body": "<p>You have some extra stuff here that you don't need.</p>\n\n<p>like 3 if statements worth of nesting. reduce it like this</p>\n\n<pre><code> private void cmbSave_Click(object sender, EventArgs e)\n {\n if(IsFilled (txtApplicationNumber.Text) &amp;&amp; IsFilled (txtEmployeeID.Text)...
{ "AcceptedAnswerId": "54682", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T14:35:15.183", "Id": "54636", "Score": "5", "Tags": [ "c#", ".net", "validation", "winforms", "mvp" ], "Title": "Input validation for text boxes in a Form" }
54636
<p>I'm the the process of adding change auditing to my existing <code>DB</code> class which encapsulates database calls.</p> <p>Previously I would just pass in a <code>String</code> and a <code>SqlParameter</code> array but now I've added the class 'DBData' to contain the values required for the auditing.</p> <p>I'm ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T15:15:48.903", "Id": "95410", "Score": "0", "body": "Welcome to Code Review! This is a nice detailed question, I hope you'll have good reviews!" } ]
[ { "body": "<p>What you could do is create a class that will create a factory and take parameters when it is constructed so that you don't have to assign all the properties the way you are, you just give the new factory wrapper all the information and then call what you need built, with a simple method call from...
{ "AcceptedAnswerId": "54664", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T14:48:02.853", "Id": "54638", "Score": "10", "Tags": [ "c#" ], "Title": "Extending database factory class to use auditing class" }
54638
<p>I would like to give an Integer to whatever demands it. For that I use the following code</p> <pre><code>public class IntIDGenerator { private static int sequence = 1; public synchronized static int generate(){ sequence++; return sequence; } } </code></pre> <p>It is thread-safe becau...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T15:40:52.183", "Id": "95411", "Score": "6", "body": "What do you perceive to be a problem with this implementation, and how is using AtomicInteger susceptible to that same problem?" } ]
[ { "body": "<p>And what's wrong with :</p>\n\n<pre><code>public final class SDGIntIDGenerator {\n\n private static final AtomicInteger sequence = new AtomicInteger(1);\n\n private SDGIntIDGenerator() {}\n\n public static int generate(){\n return sequence.getAndIncrement();\n }\n\n}\n</code></p...
{ "AcceptedAnswerId": "54643", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T15:11:04.183", "Id": "54641", "Score": "13", "Tags": [ "java", "multithreading", "thread-safety", "integer" ], "Title": "Thread-Safe Integer Sequence" }
54641
<p>Assuming an app has many display styles, fonts, colors, etc., and that we never want to hardcode values, I've created an <code>AppVariables</code> object that houses properties for all of the necessary styles in my app:</p> <pre><code>class AppVariables: NSObject { /** * Fonts */ let UIFontPrimar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T00:34:56.577", "Id": "95516", "Score": "0", "body": "Why not static so you don't create them everytime?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T16:13:33.440", "Id": "95632", "Score": "...
[ { "body": "<ol>\n<li><p>I think that you would be better off using static methods on a struct or class. This removes the need for you to access your style through the App Delegate. The App Delegate should only be concerned with handling the delegate callbacks from the OS, storing globally accessible values in i...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T15:29:46.283", "Id": "54642", "Score": "11", "Tags": [ "constants", "swift" ], "Title": "Storing global styles and utilizing them throughout view controllers" }
54642
<p>This is my solution to the competitive coding question on SPOJ <a href="http://www.spoj.com/problems/ADDREV/" rel="nofollow">here</a>. It gives a runtime of 0.24 but the best solutions posted have a 0.0 runtime. How could I possibly achieve better results than this?</p> <pre><code>#include&lt;iostream&gt; #include...
[]
[ { "body": "<p>A faster method would avoid the numeric divisions. Instead, it would load the number in a string (through the sprintf function), reverse the string, and finally recast the string into a number (with the help of the sscanf function).</p>\n\n<p>I'm attaching a function named fastrev which in turn us...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T16:10:14.317", "Id": "54645", "Score": "3", "Tags": [ "c++", "performance", "beginner", "programming-challenge" ], "Title": "Adding reversed numbers" }
54645
<p>We all know that math notation is idiosyncratic. Canonical representation of math objects often have irregular grammar rules to improve readability. For example we write a polynomial \$3x^3 + x^2\$ instead of more uniform but more verbose \$3x^3 + 1x^2 + 0x^1 + 0x^0\$. When a coefficient equals 0, you don't write th...
[]
[ { "body": "<p>Your <code>enumerate2</code> is a nice touch but I am not quite convinced that this is necessary : if you are to play with the length manually, you might as well compute the power from the index manually.</p>\n\n<p>Also, if you were to handle the negative with a minus instead of the plus, you'd be...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T16:21:23.367", "Id": "54646", "Score": "8", "Tags": [ "python", "formatting", "symbolic-math" ], "Title": "String representation of a polynomial" }
54646
<p>I wrote a simple generic <code>intercalate</code> function (that should be semantically equivalent to the Haskell <a href="http://hackage.haskell.org/package/base-4.7.0.0/docs/Data-List.html#v%3aintercalate">intercalate</a>).</p> <pre><code>template &lt;typename Fwd_It, typename Out_It&gt; auto intercalate(Fwd_...
[]
[ { "body": "<p>I would not cram in the <code>if</code> statement like that:</p>\n\n<blockquote>\n<pre><code>auto intercalate(Fwd_It first, Fwd_It last, Out_It destFirst,\n Fwd_It whatFirst, Fwd_It whatLast) {\n if (first == last) return destFirst;\n *destFirst = *first;\n // ...\n</code>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T18:49:40.080", "Id": "54656", "Score": "9", "Tags": [ "c++", "algorithm", "c++11", "generics", "c++14" ], "Title": "C++(11/14) intercalate implementation" }
54656
<p>This is a TalentBuddy <a href="http://www.talentbuddy.co/challenge/52a9121cc8a6c2dc91481f8d5233cc274af0110af382f40f">Challenge</a></p> <blockquote> <p><strong>Your task is to</strong> write a function that prints to the standard output (stdout) the highest number of tweets recorded between each second in the ar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T21:09:05.543", "Id": "95481", "Score": "3", "body": "Probably a naive question but what is `back = back.Next = value;` supposed to do ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T21:15:26.310", ...
[ { "body": "<p>First of all, I think there is an off-by-one error in your code. From my understanding of the question, the correct output for</p>\n\n<pre><code>var tweetsPerSecond = new[] { 1, 3, 2 };\nvar windowSize = 1;\n</code></pre>\n\n<p>would be <code>{ 1, 3, 3 }</code>, while your code gives the answer <c...
{ "AcceptedAnswerId": "54674", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T20:17:01.967", "Id": "54662", "Score": "10", "Tags": [ "c#", "performance", "linked-list", "programming-challenge", "interval" ], "Title": "Tweets per second, using lin...
54662
<p>I am solving linear advection equation in order to learn parallel programming. I am running this code on Xeon Phi co processor. Below is a plot of how it scales up with increasing number of threads. I am still in learning process and this is my first "parallel" code. I am also not very familiar with architecture spe...
[]
[ { "body": "<ul>\n<li><p>You should first check for the number of command line arguments via <code>argc</code>. If there are too few, print an error message and then terminate the program.</p>\n\n<pre><code>if (argc &lt; 3) {\n // print an error message...\n return EXIT_FAILURE;\n}\n</code></pre>\n\n<p>In...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T23:00:19.207", "Id": "54666", "Score": "4", "Tags": [ "optimization", "performance", "c", "openmp" ], "Title": "Increasing performance of OpenMP based advection equation solve...
54666
<p>This is a derivative post from <a href="https://codereview.stackexchange.com/questions/54539/linear-algebra-reduced-row-echelon-form">here</a>.</p> <p>This is just a general review, so the question is the same:</p> <p>Is there something...</p> <ol> <li>That you would consider as a bad practice and why?</li> <li>T...
[]
[ { "body": "<p>There's a lot of meat here; I'll try to do it justice. I've focussed on the core reduction logic, and <strike>haven't looked at the \"post-processing\" stuff that sorts the reduced matrix</strike> update: I lied - see bottom of answer.</p>\n\n<h3>Minor stuff</h3>\n\n<ul>\n<li><p>There are a few co...
{ "AcceptedAnswerId": "54774", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T23:17:58.457", "Id": "54667", "Score": "6", "Tags": [ "javascript", "beginner", "mathematics", "matrix" ], "Title": "Linear algebra, reduced row echelon form - function 1" ...
54667
<p><a href="http://www.yoyogames.com/" rel="nofollow">GameMaker: Studio</a> (originally named Animo and later Game Maker) is a proprietary game creation system created by Mark Overmars.</p> <p><a href="http://docs.yoyogames.com/source/dadiospice/002_reference/001_gml%20language%20overview/401_03_assignments.html" rel=...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T23:28:48.777", "Id": "54668", "Score": "0", "Tags": null, "Title": null }
54668
GameMaker is a Windows and Mac OS IDE which allows users to easily develop computer games without the requirement of prior computer programming experience.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T23:28:48.777", "Id": "54669", "Score": "0", "Tags": null, "Title": null }
54669
<p>The following script is being run with a cron. It runs once a minute to see if there is a reminder that needs to be sent.</p> <p>Should I make this run once every 30 minutes? The choices to send a reminder are, up to 12 hours:</p> <ul> <li>30 minutes</li> <li>60 minutes</li> <li>90 minutes</li> <li>2 hours</li> </...
[]
[ { "body": "<p>I don't know how important everything is, but ideally, you don't need to check everything every minute, and even if you do, you could 'queue' up a cron job from another cron.</p>\n\n<p>For instance</p>\n\n<ul>\n<li>cron-1 runs every week and moves reminders that need to run into a reminder file.</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T23:35:20.597", "Id": "54671", "Score": "5", "Tags": [ "php", "mysql", "php5", "pdo" ], "Title": "Optimizing cron job for sending reminders" }
54671
<p>I was just wanting a code review on this image slider I made. I don't have anyone else to give me their opinion on the code I write outside of work.</p> <p>Is this sloppy? Is it wrong? Is it ineffective? Does it have bad performance?</p> <p>You can see my repo on the slider <a href="https://bitbucket.org/bradyl...
[]
[ { "body": "<p>In general, I think it is fine.</p>\n\n<p>In a few places, you create an element, append it, then go and find it:</p>\n\n<pre><code>slider.appendChild(document.createElement(\"div\")).className = \"deity-directionNav\";\nslider.getElementsByClassName('deity-directionNav')[0].innerHTML += '&lt;a cl...
{ "AcceptedAnswerId": "56494", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T00:19:52.240", "Id": "54673", "Score": "9", "Tags": [ "javascript", "image" ], "Title": "Pure JS Image Slider" }
54673
<p>I was tasked today with cleaning up data from a SSRS report put together by a DB programmer. The original report was to find duplicate serial number sales within a user-defined period of time. I was given an Excel file with the result data set and it smelled really funny, so I decided to go into SSRS and find out wh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T03:43:45.943", "Id": "95532", "Score": "0", "body": "So there's a discrepancy between your results and your DBA's query's results? Which one is right?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T0...
[ { "body": "<p>I'm going to focus on the SQL in your question.</p>\n\n<p>While it's easier to let the machine define temporary tables for you, it is generally better to define the #temp tables yourself. Avoid the <code>Select Into</code> syntax if you know the datatypes. There are several benefits to this.</p>\n...
{ "AcceptedAnswerId": "54679", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T01:24:45.317", "Id": "54676", "Score": "12", "Tags": [ "sql", "sql-server", "xml" ], "Title": "Find records with duplicate serial number" }
54676
<p>I completed a challenge of codeeval called BayBridges. It can be found <a href="https://www.codeeval.com/public_sc/109/" rel="nofollow noreferrer">here</a>. I have uploaded my code on GitHub <a href="https://github.com/sudhirv20/Challenges/blob/master/BayBridges.cpp" rel="nofollow noreferrer">here</a>.</p> <p>In s...
[]
[ { "body": "<p>Don't need to <code>typedef</code> struct in C++ like you did in C. struct are already in the normal namespace (not their own). Also its nice to indent the code to make it nice to read.</p>\n\n<pre><code>struct Bridges {\n int number;\n double x1;\n double y1;\n double x2;\n double ...
{ "AcceptedAnswerId": "54728", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T01:54:40.560", "Id": "54677", "Score": "8", "Tags": [ "c++", "optimization", "computational-geometry", "complexity" ], "Title": "Finding largest subset of line segments tha...
54677
<p>I'm doing a small FastCGI application in C and I've created this template system to keep the design away from the code.</p> <p>There's a binary tree containing all possible first characters, each node points to another binary tree containing all characters that can appear after it. Some nodes have the replacement, ...
[]
[ { "body": "<p>A couple notes:</p>\n\n<ul>\n<li><p>This looks fishy to me:</p>\n\n<pre><code>//Try to find the character\nif(comparison &gt; 0){\n switch(word_tree_insert(&amp;(*root)-&gt;greater, word, replacement)){\n case WT_DUPLICATE:\n return WT_DUPLICATE;\n\n case WT_ERROR:\n ...
{ "AcceptedAnswerId": "54681", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T02:09:37.883", "Id": "54678", "Score": "6", "Tags": [ "c" ], "Title": "Template system for FastCGI app in C" }
54678
<p><img src="https://i.stack.imgur.com/hyUby.jpg" alt="enter image description here"></p> <p><strong>HTML</strong> code for <kbd>Add New</kbd> button:</p> <pre><code>&lt;div&gt; &lt;a data-toggle="modal" href="#addnewDepartment" id="add-new-department-btn"&gt;Add New&lt;/a&gt; &lt;/div&gt; &lt;div&gt; &lt;a data...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T05:24:33.513", "Id": "54685", "Score": "1", "Tags": [ "javascript", "jquery", "html", "ajax", "twitter-bootstrap" ], "Title": "Modal dialog and jQuery AJAX calls based on ...
54685
<p>I tried to recreate a mini game (not sure about its name, I call it b10k) with 2048 looks, therefore it looked better if I use html elements, and I really am not good at working with them, but I tried: <a href="https://github.com/Cicada3301/b10k" rel="nofollow">https://github.com/Cicada3301/b10k</a></p> <p>I could ...
[]
[ { "body": "<p>I'll primarily do the JS:</p>\n\n<ul>\n<li>Spacing and code style: Everything is perfect except for one line.</li>\n<li><code>if(this.map[this.y-1]) if (this.map[this.y-1][this.x] ===0){</code> - <code>if if</code>? Why not use <code>&amp;&amp;</code>? See <strong><a href=\"https://developer.mozil...
{ "AcceptedAnswerId": "54688", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T07:47:41.397", "Id": "54687", "Score": "2", "Tags": [ "javascript", "html", "dom" ], "Title": "b10k minigame problems" }
54687
<p>Actually, I just have no ideas.</p> <p>How can I make breaklines to make it more readable?</p> <p>Can anyone suggest ways on improving this?</p> <pre><code>module TestingDataLoad def get_files_from(search_target) Dir[search_target].each do | d | testing_files={} if File.directory? d Dir...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T06:20:19.810", "Id": "95763", "Score": "0", "body": "When checking a string against different regexes, it is sometimes handy to use a `case` statement. For example, `case str; when /ab/;...; `when /cd/, /ef/;...end`. This works bec...
[ { "body": "<p>I have no idea what your code does--never used ruby or json--but if you're going for readability, space your if statements:</p>\n\n<pre><code>// Pseudo Code(!!):\nif expression\n if expression\n result\n end\n\n if expression\n result\n end\nend\n</code></pre>\n\n<p>That ...
{ "AcceptedAnswerId": "54693", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T08:37:48.790", "Id": "54691", "Score": "3", "Tags": [ "ruby", "file-system" ], "Title": "How can I prettify blocks with more than 2 of each block?" }
54691
<p>I made this method that takes any string and transforms it into a multiline text l; each line having the max (character) length specified by the <code>rowLength</code> parameter.</p> <p>How can I make this better, functionality and code wise?</p> <p>There is currently one known issue. It sometimes adds an empty li...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T11:18:15.750", "Id": "95584", "Score": "1", "body": "Welcome to Code Review! Even though we can help you make this cleaner, Code Review is not the place to ask for how to fix unwanted behavior in your code (the empty line that you a...
[ { "body": "<p><strong>First Impressions</strong> <br />\nI haven't gone through the functionality in detail but a few things strike me immediately.</p>\n\n<p>Why explicitly include <code>StringSplitOptions.None</code>. They default value is none.</p>\n\n<p><code>IsNullEmptyOrWhiteSpace()</code> seems to be a (n...
{ "AcceptedAnswerId": "118482", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T10:50:03.887", "Id": "54697", "Score": "14", "Tags": [ "c#", "performance", "strings", ".net", "formatting" ], "Title": "Convert string to multiline text" }
54697
<p>In input validation I'm using this validation method in my all Forms. Here I have a single handler for all <code>TextBoxes</code> in my Form and if I have other controllers like <code>ComboBoxes</code> I would use a separate <code>handler</code> for all <code>ComboBoxes</code> and so on. </p> <p>My only doubt in th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T13:22:48.257", "Id": "95600", "Score": "1", "body": "Personally I think users would rather be reminded of an omission right away rather than waiting until all the rest of the inputs are done. One thing you can do is put a label wit...
[ { "body": "<p>Just a few random observations:</p>\n\n<blockquote>\n<pre><code>foreach (TextBox tb in this.Controls.OfType&lt;TextBox&gt;().Where(x =&gt; x.CausesValidation == true))\n</code></pre>\n</blockquote>\n\n<p><code>tb</code> is a bad name; without the explicit <code>TextBox</code> type one would have t...
{ "AcceptedAnswerId": "55373", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T11:29:00.837", "Id": "54699", "Score": "2", "Tags": [ "c#", ".net", "validation", "winforms", "mvp" ], "Title": "Using a single validation handler for all controllers i...
54699
<p>I wish to locate the closest matching NxN block within a WxW window centred at location (x,y) of a larger 2D array. The code below works fine but is very slow for my needs as I need to run this operation many times.</p> <p>Is there a better way to do this?</p> <p>Here N = 3, W = 15, x =15, y = 15 and (<code>bestx<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T11:49:11.757", "Id": "95593", "Score": "0", "body": "What constitutes the 'closet matching block'?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T12:30:36.750", "Id": "95595", "Score": "0", ...
[ { "body": "<p>Using <a href=\"https://docs.python.org/2/library/functions.html#sum\" rel=\"nofollow\">sum</a>, you can make your code more concise and slightly more efficient :</p>\n\n<pre><code>cost = sum(abs(Data[Wy+py-1,Wx+px-1] - CurPatch[py,px]) for py in xrange(3) for px in xrange(3))\n</code></pre>\n\n<h...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T11:30:36.050", "Id": "54700", "Score": "6", "Tags": [ "python", "performance", "algorithm", "numpy", "edit-distance" ], "Title": "Finding the best matching block/patch in ...
54700
<p>I have produced a working menu component for a project I'm working on, but would like to reduce the amount of code used and improve the methods - especially in the Paint implementation - still further, I feel like the function I've used and the way I've passed the variables to it is a bit 'hacky' - IOW, I bodged it....
[]
[ { "body": "<p>First, I'll go on about how the code looks, since it displays the most obvious issues.</p>\n\n<p><strong>You have redundant comments all over the place.</strong></p>\n\n<pre><code>// Rectangle drawing function\nFunction DrawRect\n</code></pre>\n\n<p>The name <code>DrawRect</code> makes it clear en...
{ "AcceptedAnswerId": "68752", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T12:46:34.270", "Id": "54704", "Score": "7", "Tags": [ "delphi", "pascal" ], "Title": "Drawing and Painting a Menu Component" }
54704
<p>Following code validates NIC number of a person (National Identity Card, no like SSN) Requirements are...</p> <ol> <li>Length should be 10 digits or characters</li> <li>All should be digits except the last one</li> <li>Last one would be x or v in simple letters</li> </ol> <p>Currently I'm using following method an...
[]
[ { "body": "<p>I don't like hardcoding values like this. I'm sure you'll be ok, because I doubt the format of your NIC will ever change, but for clarity's sake...</p>\n\n<p>This:</p>\n\n<pre><code>if (letter[9] == 'v' | letter[9] == 'x')\n</code></pre>\n\n<p>Should be this:</p>\n\n<pre><code>if (letter[letter.le...
{ "AcceptedAnswerId": "54751", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T13:01:50.983", "Id": "54706", "Score": "4", "Tags": [ "c#", ".net", "validation", "winforms" ], "Title": "Validating a string under few conditions" }
54706
<p>I want to create a form with a country drop down list so I can just google and get all the countries but the question should I just encode it statically or generate dynamically with PHP. (Note it doesn't have to be necessary country list just any static list with lots of data)</p> <p>HTML Example:</p> <pre><code>&...
[]
[ { "body": "<p>Well, it is unlikely for the countries to change much, and even if they do, you might as well change it in HTML rather than in PHP. It really doesn't matter much, there's no point in abstracting these.</p>\n\n<p>I'd go with making this static HTML, and save some performance (although probably negl...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T13:03:14.107", "Id": "54708", "Score": "3", "Tags": [ "php", "html", "form" ], "Title": "Form with a country list statically or dynamically generated" }
54708
<p>I'm following <a href="http://fsharpforfunandprofit.com/posts/designing-with-types-single-case-dus/" rel="nofollow">this</a></p> <pre><code>let StringOfLengthConstructor&lt;'c&gt; (input:string, length:int, defaultConstructor:string-&gt;'c) = match input with | null -&gt; None | x when x.Length = length...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T17:22:54.500", "Id": "95641", "Score": "3", "body": "Could you explain what are you trying to do and why?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T18:00:25.137", "Id": "95653", "Score":...
[ { "body": "<p>The solution can be made cleaner by re-arranging the order of the arguments and using pointfree style.</p>\n\n<pre><code>let StringOfLengthConstructor&lt;'c&gt; (length : int) (defaultConstructor : string -&gt; 'c) (input : string) =\n match input with\n | x when x &lt;&gt; null &amp;&amp; x...
{ "AcceptedAnswerId": "54989", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T13:24:10.110", "Id": "54713", "Score": "3", "Tags": [ "strings", "f#" ], "Title": "Defining a zip code string" }
54713
<p>I'm curious whether checking for <code>null</code> is redundant in this concrete example.</p> <pre><code> public LoginJob(@NotNull String login, @NotNull String password) { super(new Params(Priority.NORMAL).requireNetwork().persist()); Preconditions.checkNotNull(login, "login is null or empty"); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T16:02:07.657", "Id": "95631", "Score": "1", "body": "The only time null checks are unnecessary is if you ban null from your entire code base. Then you only need to check for null where your code interacts with third party code." }...
[ { "body": "<p>You said it yourself in your question : </p>\n\n<blockquote>\n <p>it can't prevent him/her of doing so though.</p>\n</blockquote>\n\n<p>That settle it for me. You still have the responsibility to prevent that <code>null</code> value are pass to your classes. The annotation seems to be about preve...
{ "AcceptedAnswerId": "54717", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T14:22:09.207", "Id": "54716", "Score": "4", "Tags": [ "java", "null" ], "Title": "Is checking for null redundant while using Contract Annotator from JetBrains?" }
54716
<p>I've recently made a calculator using Java and Swing. I'm okay with the results but I'm curious what are the major flaws I've made (assuming there are, because it is my first program making GUI). I can't think of a fancy way for not duplicating code in the function action listeners classes.</p> <p>Which other good-...
[]
[ { "body": "<p><code>tempNumbers</code> isn't a very explanatory variable name. Let the variable itself describe what it is temp for. For a simple calculator though, perhaps <code>number1</code> and <code>number2</code> would suffice.</p>\n\n<p>You're using strange indentation in your constructor. It's good that...
{ "AcceptedAnswerId": "54725", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T15:23:02.740", "Id": "54720", "Score": "15", "Tags": [ "java", "swing", "calculator" ], "Title": "Swing calculator - first GUI program" }
54720
<p>How would you name this function (I gave in a name <code>pipe</code> in the example) which constructs combines a chain of functions with a single attribute into a single callable:</p> <pre><code># Python def pipe(*functions): """ pipe(c, b, a)(value) == a(b(c(value))) """ if len (functions) == 1: ...
[]
[ { "body": "<p>The function performs <a href=\"http://en.wikipedia.org/wiki/Function_composition\" rel=\"nofollow\">composition</a>, so the name should be <code>compose</code>. Or rather <code>reverse_compose</code>, because it applies functions in the order reversed from natural composition.</p>\n", "commen...
{ "AcceptedAnswerId": "54741", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T15:25:26.163", "Id": "54721", "Score": "1", "Tags": [ "python" ], "Title": "Chaining a number of callables into a single function" }
54721
<blockquote> <h3>Exercise 5-4</h3> <p>Write the function <code>strend(s,t)</code>, which returns one if the string <code>t</code> occurs at the end of the string <code>s</code>, and zero otherwise.</p> </blockquote> <pre><code>#include &lt;stdio.h&gt; int str_end(const char *, const char*); int main(void) { ...
[]
[ { "body": "<p>Unfortunately your code has a bug. If there is a mis-match on the end-string, you roll-back the pointer for the end-string to the <code>init</code> value. You should also roll-back the pointer in the <code>s</code> string so that you can look for cases where the actual result starts part-way throu...
{ "AcceptedAnswerId": "54726", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T15:31:19.270", "Id": "54722", "Score": "14", "Tags": [ "c", "strings" ], "Title": "Determine if one string occurs at the end of another" }
54722
<p>Here is a login system I am working on. I just want an opinion on it and whether I am going in the right direction or am just completely missing something.</p> <p>The main thing I would like to know is: am I initializing my user session IDs correctly? Basically once the user enters their credentials, the system go...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T08:18:50.617", "Id": "95769", "Score": "0", "body": "Rather than reinventing, try to find how it's solved in PHP frameworks. I would be more critical then Alex, I would say you are going wrong direction. And `$GLOBALS['adminPage'] =...
[ { "body": "<p>First off, when posting a question, try to give it some natural IDE formatting if you can. this improves readability and you're more likely to get more/better answers!</p>\n<h2>Code</h2>\n<p>Technically, you can call</p>\n<pre><code>$_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;\n</code>...
{ "AcceptedAnswerId": "54772", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T15:39:51.037", "Id": "54723", "Score": "4", "Tags": [ "php", "security", "authentication" ], "Title": "Login system security" }
54723
<p>I have a shell script to configure Synaptics touchpad settings at login.</p> <h2>Background</h2> <p>You configure the touchpad with the <code>synclient</code> command. Its usage is</p> <blockquote> <p>synclient [-lV?] [var1=value1 [var2=value2] ...]</p> </blockquote> <p>For example:</p> <ul> <li><code>synclie...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T16:21:33.077", "Id": "54732", "Score": "2", "Tags": [ "sh" ], "Title": "Script to configure Synaptics touchpad" }
54732
<p>I am not sure if I am approaching this task the correct way. I have a view model with multiple string properties. I pass the model through an interface to a service class that contains a void to repopulate the user input with my desired format.</p> <pre><code>using System.Globalization; using System.Text.RegularE...
[]
[ { "body": "<p>This seems pretty clean to me. It's very testable, which is a definite must-have. It also decouples the reformatting of user input from the view-model. Looser coupling between layers is a positive thing. The downside is that you'd need to create a service for each view model. I'm going back and fo...
{ "AcceptedAnswerId": "54735", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T16:28:59.633", "Id": "54733", "Score": "3", "Tags": [ "c#", "beginner", "mvc", "interface" ], "Title": "Cleaning User Input" }
54733
<p>Calculating probabilities in Minesweeper might sound like an easy task, but I've seen so many probability calculators that's either incorrect, horribly slow, or with ugly code (or all of them) so I have to share my code for this.</p> <p>This code is used within my <a href="http://www.minesweeperflags.net" rel="nore...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-24T11:27:01.607", "Id": "96468", "Score": "0", "body": "getGroups will call this.getRules which will create a new ArrayList with all rules of `List<FieldRule<T>> rules = new ArrayList<FieldRule<T>>();` It's really needed to create a ne...
[ { "body": "<p>One of the first rule I try to always follow is to be consistent. You're not always following the same pattern in your code for brackets. </p>\n\n<blockquote>\n<pre><code> if (recursive == null) {\n return null;\n }\n</code></pre>\n</blockquote>\n\n<p>vs</p>\n\n<blockquote...
{ "AcceptedAnswerId": "55179", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T16:55:14.823", "Id": "54737", "Score": "57", "Tags": [ "java", "performance", "algorithm", "combinatorics", "minesweeper" ], "Title": "Analyzing Minesweeper Probabiliti...
54737
A set is a collection in which no element is repeated, which may be able to enumerate its elements according to an ordering criterion (an "ordered set") or retain no order (an "unordered set").
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T17:25:35.580", "Id": "54740", "Score": "0", "Tags": null, "Title": null }
54740