body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
Geospatial pertains to the geographic location and characteristics of natural or constructed features and boundaries on, above, or below the earth's surface; esp. referring to data that is geographic and spatial in nature.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T17:29:06.193", "Id": "54744", "Score": "0", "Tags": null, "Title": null }
54744
<p>The code is the view part of my bookmarker - project for managing bookmarks by categories. It uses Python 3.4/Django 1.6. I have also included <code>models.py</code> for reference.</p> <p>The code does the following</p> <ul> <li>Providing relevant autocomplete JSON data</li> <li>Providing details of categories/boo...
[]
[ { "body": "<p>Overall, this is pretty nicely written.</p>\n\n<h3>Abstractions and code structure</h3>\n\n<blockquote>\n <p>I am mainly concerned with the quality of the abstractions. Other reviews are also welcome but I am mainly concerned with the structure of the code.</p>\n</blockquote>\n\n<p>The models are...
{ "AcceptedAnswerId": "74367", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T17:44:16.240", "Id": "54745", "Score": "5", "Tags": [ "python", "python-3.x", "django" ], "Title": "Personal Project for managing Bookmarks - View Part" }
54745
The quality of abstraction is high if using the object/function through the interface provided feels natural.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T17:51:17.947", "Id": "54747", "Score": "0", "Tags": null, "Title": null }
54747
<p>My application has a fairly important query that is used in a lot of places. Unfortunately it takes about 14 seconds to run, so I'd like to find a way of possibly improving it. </p> <p>The application receives incidents (right now there's about 70,000 total incidents, and about 16,000 incidents in this query), with...
[]
[ { "body": "<h1><strong>Native T-SQL</strong></h1>\n<p>I don't know enough about <a href=\"/questions/tagged/linq\" class=\"post-tag\" title=\"show questions tagged &#39;linq&#39;\" rel=\"tag\">linq</a> to do a proper code review for that, however as far as performance is concerned I think T-SQL would take care ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T18:37:13.263", "Id": "54749", "Score": "5", "Tags": [ "performance", "sql", "linq", "entity-framework", "sql-server" ], "Title": "EF query for calculating monthly trends" ...
54749
<p>I am posting this question for input on comparisons between other sieving methods and opinions on what I have discovered. I believe this might be the fastest (singular, non-threaded) array implementation of prime sieving to date, correct me if I am wrong.</p> <p>My rudimentary benchmark tests stand as follows:</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T20:10:01.077", "Id": "95674", "Score": "0", "body": "What exactly is your question? Are you looking for a code review of the implementation? Or a peer review of your math?" }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>Just some minor comments to the code style. Let's start with your fileheader...in these times and days it should be unnecessary. First it doesn't make sense to have the file/classname in the comment, it's only something that will get out of date because refactoring can't reach it. Second, the othe...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T19:32:04.877", "Id": "54753", "Score": "7", "Tags": [ "java", "primes", "sieve-of-eratosthenes" ], "Title": "A fast approach to prime number sieving (non-threaded array)" }
54753
<p>This is being used now, seems decent to me but I'm curious. </p> <pre><code> if (m=s.match(/^\s*(https?:\/\/[^\s&lt;&gt;"]+)\.(bmp|png|webp|gif|jpg|jpeg|svg)\s*$/)) { // example s: http://mustachify.me/?src=http://www.someImage.jpg return '&lt;img src="'+m[1]+'.'+m[2]+'"&gt;'; } if (m=s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T20:18:32.497", "Id": "95679", "Score": "0", "body": "Hi. Welcome to code review. You might get a better review if you include a little more context in your question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<p>The part of your code shown here does not look like it's vulnerable to XSS, but it could be cleaner. You seem to be doing 3 separate things:</p>\n\n<ul>\n<li><p>Ensuring that a URI looks like a path to an image.</p></li>\n<li><p>Ensuring that a URI doesn't contain certain characters like quotes an...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T19:35:17.783", "Id": "54754", "Score": "2", "Tags": [ "javascript", "parsing", "security", "regex" ], "Title": "Is this `img` creator decently secure from XSS?" }
54754
<p>I am working on a ground-up rebuild for an app that has a relatively simple purpose. Users can view/favorite entities that are backed by a RESTful API. I own both the client code as well as the API. For this rebuild, I wanted to refactor the networking code out of my view controllers and hopefully move my codebase t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T21:15:16.167", "Id": "95699", "Score": "0", "body": "I'm going to say upon first glance that this looks overly complicated, and the fact that we're using protocol-delegate pattern AND completion blocks AND notification center is a m...
[ { "body": "<p>For now, I'm going to focus my answer on the outermost level of your code--the level which I'd be dealing with if I'm one of your yet-to-be-hired developers. Hopefully, if the code works, no one will have to touch the inner levels, but this code is written with the intent to be re-used over and o...
{ "AcceptedAnswerId": "54842", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T19:47:56.713", "Id": "54755", "Score": "3", "Tags": [ "design-patterns", "objective-c", "web-services" ], "Title": "Model Implementation That Calls RESTful API" }
54755
<p>Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Formally speaking, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i &lt; j</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T02:15:42.343", "Id": "95733", "Score": "0", "body": "I'd add some bigger tests done by e.g. comparing to bubble sort. With a few such small tests I wouldn't trust the algorithm (and bubble sort is quickly done and testing with 100 r...
[ { "body": "<p>The code is well written. Some specific remarks are as follows.</p>\n\n<ul>\n<li>A better name of the class would be InversionCounter.</li>\n<li>You don't really need to create the temporary array temp every time merge is called. Since, merge is called recursively for every level you might start n...
{ "AcceptedAnswerId": "54817", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T19:54:43.757", "Id": "54756", "Score": "6", "Tags": [ "java", "sorting", "mergesort" ], "Title": "Counting inversions" }
54756
<p>I am looking for a review of my code that implements a MyQueue class which implements a queue using two stacks. </p> <pre><code>public class MyQueue&lt;T&gt; { Stack&lt;T&gt; stackNewest, stackOldest; public MyQueue() { stackNewest = new Stack&lt;T&gt;(); stackOldest = new Stack&lt;T&gt;(); } publ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T22:33:31.367", "Id": "95706", "Score": "1", "body": "a) Make the properties private. b) Keep the initialization with the declaration: `Stack<T> stackNewest = new Stack<T>();` There is no reason to defer the initialization until late...
[ { "body": "<p>Unfortunately your code does not implement a queue. It is relatively easy to produce circumstances which break the logic. Consider the following, for example:</p>\n\n<pre><code>MyQueue&lt;String&gt; q = new MyQueue&lt;&gt;();\n\nq.add(\"a\");\nq.add(\"b\");\nq.remove(); // should be \"a\", and is ...
{ "AcceptedAnswerId": "54766", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T21:59:59.487", "Id": "54762", "Score": "4", "Tags": [ "java", "interview-questions", "queue", "stack" ], "Title": "Class that implements a queue using two stacks" }
54762
<p>CSS and responsiveness in multiple columns with fixed and scaleable elements can be done in many ways.</p> <p>I have created a solution that seems to work, though I have no idea whether this is best practice.</p> <p><a href="http://jsfiddle.net/brandrally/ZDt6N/" rel="nofollow">Fiddle</a></p> <p>CSS</p> <pre c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T07:28:24.337", "Id": "95768", "Score": "2", "body": "It's not really a responsive layout if you need to scroll horizontally on a viewport that's less than 960px wide, is it?" }, { "ContentLicense": "CC BY-SA 3.0", "Creat...
[ { "body": "<p>To have a responsive web design, you need to do more than have no horizontal scrolling when viewed with a desktop browser. You have to adapt to the viewport of any device, from the really small (phone) to the really big (desktop). This code does not, sorry.</p>\n\n<p>Responsive web design is typ...
{ "AcceptedAnswerId": "55545", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T22:12:08.223", "Id": "54763", "Score": "2", "Tags": [ "html", "css" ], "Title": "Responsive / CSS fixed and variable widths" }
54763
<p>I was bored and burnt out on more serious projects.... until I saw <a href="http://youtu.be/7t_pTlH9HwA" rel="noreferrer">this Computerphile video on YouTube</a>. Now I'm inspired again. Now I feel like spending some time implementing that recursive algorithm in a little console program. Fortunately, recursion is un...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T01:01:03.533", "Id": "95716", "Score": "0", "body": "Check out this [Fibonacci](http://blogs.msdn.com/b/wesdyer/archive/2007/02/02/anonymous-recursion-in-c.aspx) implementation while you are at it :)" }, { "ContentLicense": ...
[ { "body": "<p>Indentation and formatting are fine, as is the algorithm itself.</p>\n\n<p>Your naming is inconsistent, compare <code>n</code> and <code>Value</code>; <code>_value</code> and <code>_FnMinus1</code>. There are a variety of conventions to follow, but consistency is the most important thing.</p>\n\n...
{ "AcceptedAnswerId": "54773", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T23:34:11.330", "Id": "54769", "Score": "40", "Tags": [ "c#", "beginner", "fibonacci-sequence" ], "Title": "Everyone loves Fibonacci" }
54769
<p>My concerns with this code:</p> <ol> <li>Is there a more efficient way to find files by pattern in Python? </li> <li>Does <code>os.walk()</code> work in Windows?</li> <li>Is this code pythonic?</li> <li>Should <code>search()</code> be broken down into 2 functions?</li> <li>Is it stupid to handle IOError exception...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T23:39:04.210", "Id": "95709", "Score": "1", "body": "Please no advice on using unix tools like: \n\"sed awk grep egrep find\"" } ]
[ { "body": "<p>Looks quite pythonic. However:</p>\n\n<ul>\n<li><code>_</code> stands for <em>don't care</em>, akin to famous <a href=\"https://github.com/cslarsen/mickey-scheme/blob/master/test/test-maclisp.scm\" rel=\"nofollow\">hunoz</a>. It is not expected to be used in expressions later on; it is a placehold...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T23:35:15.837", "Id": "54770", "Score": "1", "Tags": [ "python", "optimization", "search", "file-system" ], "Title": "Search a file system for files that match a given pattern"...
54770
<p>I recently made a webcrawler that I submitted here for a review:</p> <p><a href="https://codereview.stackexchange.com/questions/49480/minimal-webcrawler-bad-structure-and-error-handling">Minimal webcrawler - bad structure and error handling?</a></p> <p>With that help, I've made a much cleaner and better(?) webcraw...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T11:15:54.857", "Id": "95783", "Score": "1", "body": "Have you tried profiling it to find out where the time is taken?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T17:05:26.657", "Id": "95830", ...
[ { "body": "<p><strong>Edit</strong>:</p>\n\n<p>Analysis of posted profile results</p>\n\n<p>Of all the functions listed in the result, your code accounts for <code>0.041</code> seconds. However, the cumulative time for the entire execution is <code>14.169</code>. This has your code accounting for <code>.289%</c...
{ "AcceptedAnswerId": "54818", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-19T23:41:53.403", "Id": "54771", "Score": "7", "Tags": [ "python", "http", "web-scraping" ], "Title": "Improved minimal webcrawler - why is it so slow?" }
54771
<p>I've written a DNS tool in Node and would like to know if there's a better and more efficient way of handling the conversion from an IP to a long. I'm not too good at bitwise just yet and would like to hear any suggestions. Psuedo-code has been provided below.</p> <pre><code>var _parse = function (ip) { var octet...
[]
[ { "body": "<p>I wouldn't both prefixing 'internal' functions with an underscore. Instead, just put this in a module, and only export the functions you want to export.</p>\n\n<hr>\n\n<p>If you care about following the node style guide, you should know that node suggests ignoring Crockford's fetish for one <code>...
{ "AcceptedAnswerId": "54779", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T01:32:26.530", "Id": "54775", "Score": "24", "Tags": [ "javascript", "parsing", "node.js", "bitwise", "ip-address" ], "Title": "Converting an IP" }
54775
<p><code>ids</code> contains 100 <code>ids</code> that are comma delimited. Is it fine or does it need improvement?</p> <pre><code> def getFriendPoints(ids: String) = { DB.withConnection { implicit c =&gt; try { var pointMap:scala.collection.immutable.Map[String,String]=Map() var i=ids.split...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T15:58:32.130", "Id": "95966", "Score": "0", "body": "Am I missing something? You declare pointMap as null then try to call a method on it. How does this ever not return error?" }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>100 queries is not fine! It's slow. For each select statement there is a significant overhead required to set up and run the query.</p>\n\n<p>Instead you should use a <strong>single</strong> SELECT statement with a better WHERE clause:</p>\n\n<pre><code>SELECT point, privacy FROM `tablename` WHERE...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T05:47:27.303", "Id": "54783", "Score": "7", "Tags": [ "sql", "mysql", "scala" ], "Title": "Multiple SQL queries, one per ID" }
54783
<p>This particular example is verilog, but my question is more about the state machine structuring, which would be relevant to both VHDL and verilog. </p> <p>So if I have a state machine, this one is fairly simple:</p> <pre><code>always@(posedge m_axi_clk) begin if(m_axi_resetn == 0) begin current_state &...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T11:45:35.493", "Id": "95789", "Score": "0", "body": "Added tag. I know some people .... who know verilog really well. I will see if I can get them to have a look through this. FPGA-based wiring is otherwise a pretty slow section in ...
[ { "body": "<p>As with all questions on codereview, some of the comments below is just opinion and there are always several ways of doing things. However my personal style preferences have evolved over many years of debugging my own (and other people's) code!</p>\n\n<h2>First some style comments on the code it...
{ "AcceptedAnswerId": "58372", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T08:17:58.727", "Id": "54786", "Score": "7", "Tags": [ "state-machine", "hdl", "verilog" ], "Title": "Implementation of interface within state machine" }
54786
<p>I have written a small application that lets the user search drives for their given input string. I am only returning the full name of files. What I have now is the following method to retrieve those full names:</p> <pre><code>private IEnumerable&lt;string&gt; FindOccurences(string searchQuery, DriveInfo drive) { ...
[]
[ { "body": "<p>I really like this code. Let me explain why in a few short sentences:</p>\n\n<p><strong>Typechoice:</strong></p>\n\n<p>You return an <code>IEnumerable</code> and not a <code>List</code>. This is awesome, because a <code>List</code> implies sorted entries <strong>and</strong> blocks some Types, tha...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T09:47:36.757", "Id": "54792", "Score": "3", "Tags": [ "c#", "performance", "io" ], "Title": "Find all file occurences of a search term on drive" }
54792
<p>I have the following code which attempts to match all strings like "*SOMESTRING" (which can include numeric values), but <em>not</em> "*SOMESTRING*". For this I am using a negative lookahead as follows;<code>*SEX</code> and <code>*AN01ZORA</code> <em>should</em> match, <code>\*PCCL\*</code> should <em>not</em> match...
[]
[ { "body": "<p>Your regex is overly complicated, I must admit. The negative lookahead is going to do a lot of work to identify all the negative cases before even looking for (nearly) positive matches.</p>\n\n<p>I think the trick you are missing is <a href=\"http://msdn.microsoft.com/en-us/library/h5181w5w%28v=vs...
{ "AcceptedAnswerId": "54797", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T10:18:24.940", "Id": "54795", "Score": "5", "Tags": [ "c#", "regex" ], "Title": "Negative Lookbehind Regex" }
54795
<blockquote> <p>Consider this interview question:</p> <p>Given a Node with a reference to a child, its next, its previous, and a variable for its value (\$\frac{1}{2}\$ tree, \$\frac{1}{2}\$ doubly linked list structure), you have to find a way to flatten the structure. </p> <pre><code>1 = 2 = 3 = 5 | ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T12:29:30.070", "Id": "95797", "Score": "2", "body": "Welcome on CodeReivew.SE! Out of curiosity, what is supposed to be the logic to flatten a structure which cannot be flatten in an obvious way? Is the stategy always to apply \"chi...
[ { "body": "<p>Your current implementation is quite nice. </p>\n\n<p>The only way you are going to avoid using the <code>while</code> loop to find the right-most node is if you have each individual branch maintain its branch's tail <code>Node</code>. This is a [sort of] good approach to the problem. However, onc...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T11:23:36.280", "Id": "54796", "Score": "7", "Tags": [ "python", "interview-questions", "linked-list" ], "Title": "Flatten double-linked list" }
54796
<p>Based on my previous <a href="https://codereview.stackexchange.com/questions/52499/validator-readability-and-efficiency">post</a> I completely re-factored my code to make it object oriented.</p> <p>Anything I could improve when it comes to:</p> <ul> <li>Object oriented code;</li> <li>Efficiency;</li> <li>Readabili...
[]
[ { "body": "<p>Other points to consider:</p>\n\n<p>Localization: instead of</p>\n\n<pre><code>throw new Exception('Must be between 13 and 17');\n</code></pre>\n\n<p>go for</p>\n\n<pre><code>$e = new ValidationException('Must be between %s and %s');\n$e-&gt;setArgs([$this-&gt;min, $this-&gt;max]);\nthrow $e;\n</c...
{ "AcceptedAnswerId": "54806", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T12:13:32.353", "Id": "54799", "Score": "5", "Tags": [ "php", "optimization", "object-oriented" ], "Title": "Validator refactored to be OO" }
54799
<p>I have this piece of code I've been working on for quite some time. It's a ListView with a search filter. Inside each row, it contains a user Image, a User's name and how many friends they have in common. Also the row contains a button each, for actions.</p> <p>I'm just indeed of some code refactoring, maybe some g...
[]
[ { "body": "<p>Just a few quick thoughts rather than a full review:</p>\n\n<ul>\n<li>Your <code>onCreate</code> is too long. Way too long!</li>\n<li>What is <code>lv</code>? Abbreviations are usually a bad idea. IDEs will do the typing for you, so meaningful names are a must.</li>\n<li>What is <code>friendList2<...
{ "AcceptedAnswerId": "54885", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T12:51:30.607", "Id": "54804", "Score": "2", "Tags": [ "java", "android", "xml" ], "Title": "ListView with a search filter" }
54804
<p>How to do optimization and provide less of code here: </p> <pre><code> for _ in _get_valid_json(): if _['size'] != '': available_params = [ {'productSku': _['upcID']}, {'productUPC': _['upc']}, {'productColor': _['color']}, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T13:31:47.537", "Id": "95807", "Score": "2", "body": "Welcome on CodeReview.SE! Would you be able to tell us more about what you are trying to achieve ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T...
[ { "body": "<p>You can append to a list after it has been created.</p>\n\n<pre><code>for _ in _get_valid_json():\n available_params = [\n {'productSku': _['upcID']},\n {'productUPC': _['upc']},\n {'productColor': _['color']}]\n\n if _['size'] != '':\n available_params.append({'p...
{ "AcceptedAnswerId": "54807", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T13:26:34.750", "Id": "54805", "Score": "-4", "Tags": [ "python", "json" ], "Title": "Reading a product from JSON that may or may not have a size" }
54805
<p>My users may need to supply a 'disease category' to my site. I need to let them use all alphanumeric characters, hyphens and single quotes. Would someone review this to see if they feel it's reasonable safe? I'm very happy for suggestions to make it tighter,</p> <pre><code> $disease_category = "some user inpu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T05:50:16.583", "Id": "96176", "Score": "0", "body": "I don't think you've asked a good, clear question. The code doesn't really make sense (`$disease_category` _vs._ `$new_category`, the unexplained `\\s` in the regex, and the disca...
[ { "body": "<p>Well if having an underscore in your line could be acceptable, then</p>\n\n<pre><code>$reg = \"#[^\\w\\s-']#i\";\n</code></pre>\n\n<p>could be used. If you cannot have underscores, then</p>\n\n<pre><code>$reg = \"#[^a-z\\d\\s-']#i\";\n</code></pre>\n\n<p>could be correct.</p>\n\n<p>A conditional u...
{ "AcceptedAnswerId": "54830", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T14:36:15.907", "Id": "54809", "Score": "2", "Tags": [ "php", "security", "regex" ], "Title": "Preg_match pattern for user input filtering" }
54809
<p>I recently bought <a href="http://www.852kids.com/master-maths-educational-board-game.html">this math-based boardgame</a> for my little cousins, and am now trying to verify its design with some MATLAB code. The relevant parts of the game are:</p> <ul> <li>A board with numbers from 1 to 100 in one tile each, and eac...
[]
[ { "body": "<p><strong>Discussion</strong></p>\n\n<p>You have three dice, which you can assume to hold three places for <code>1, 2, 3, 4, 5, 6</code> and the four operations <code>+, -, *, /</code> would hold the two in-between places, which are shown as square brackets and round brackets respectively as shown i...
{ "AcceptedAnswerId": "54860", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T14:43:27.813", "Id": "54810", "Score": "8", "Tags": [ "game", "combinatorics", "matlab" ], "Title": "Verifying boardgame mathematics with MATLAB" }
54810
<p>On a programming contest I came upon this <a href="http://gyazo.com/38cd91da347dda01387bbfc9b6057c2c.png" rel="nofollow">question</a>:</p> <blockquote> <p>Given a partially played 3 × 3 tic-tac-toe configuration, write a program to determine which player will have a better chance of winning if the game is continu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T17:33:11.997", "Id": "95837", "Score": "0", "body": "\"I am aware that my code was obfuscated and variables should have been named properly.\" then why did you obfuscate it in the first place?" }, { "ContentLicense": "CC BY-...
[ { "body": "<blockquote>\n <p>What can I do to optimize reading the user input?</p>\n</blockquote>\n\n<p>Don't. For these kind of problems you will virtually never need to worry about time spent reading input.</p>\n\n<blockquote>\n <p>What can I do to optimize resource efficiency and how I am dealing\n with t...
{ "AcceptedAnswerId": "54821", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T14:54:58.030", "Id": "54811", "Score": "7", "Tags": [ "java", "optimization", "parsing", "contest-problem", "tic-tac-toe" ], "Title": "Optimizing this inefficient TicTa...
54811
<p>I am working on <a href="http://acm.timus.ru/problem.aspx?space=1&amp;num=1220" rel="nofollow">this problem</a>:</p> <blockquote> <h1>Stacks</h1> <p>Imagine, that you are employed by a software development company. You work now on the famous "D++ project", which is devoted to the creation of a new genera...
[]
[ { "body": "<p>The most obvious way to reduce memory usage of this program would be to use dynamic arrays instead of a linked lists for your stacks.</p>\n\n<p>As it stands right now, for every <code>int</code> you store in your stack, you're also storing two pointers. That will typically mean that you end up sto...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T15:06:45.097", "Id": "54812", "Score": "7", "Tags": [ "c++", "memory-management", "stack", "contest-problem" ], "Title": "Stack challenge - improving memory consumption" }
54812
<p>Also known as "Noughts and Crosses", <a href="https://en.wikipedia.org/wiki/Tic-tac-toe" rel="nofollow noreferrer">Tic-tac-toe</a> is a <a href="/questions/tagged/game" class="post-tag" title="show questions tagged &#39;game&#39;" rel="tag">game</a> in which players take turns placing X and O marks on a 3 × 3 grid. ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-06-20T17:40:45.170", "Id": "54819", "Score": "0", "Tags": null, "Title": null }
54819
A game, also known as "Noughts and Crosses", in which players take turns placing marks on a 3 × 3 grid in an attempt to form a line of three consecutive marks. You can also use this tag for variants of the game.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-06-20T17:40:45.170", "Id": "54820", "Score": "0", "Tags": null, "Title": null }
54820
<p><strong>I have a search-function, that searches for specific data within a huge Object.</strong></p> <p>Depending on how good a found entry matches, the finding gets "matchPoints" (or "Priority")</p> <pre><code>var findings = {}; for(var element in hugeObject){ var points = getMatchPoints( inputToSearchFor, hu...
[]
[ { "body": "<blockquote>\n <p>The .reverse() function sorts the priorities alphabetically, not numerically</p>\n</blockquote>\n\n<p>This is because <code>Object.keys</code> returns an array of strings.</p>\n\n<blockquote>\n <p>If 2 findings have the same amount of matchpoints, the findings-entry gets overwritt...
{ "AcceptedAnswerId": "54834", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T18:11:04.660", "Id": "54824", "Score": "2", "Tags": [ "javascript", "performance", "sorting" ], "Title": "Search for data and order by priority efficiently" }
54824
<p>I have a <a href="http://pastebin.com/iyGmTHF9" rel="nofollow">large file</a> that I want to refactor. My idea is to make helper classes with helper methods so that I can modularize methods.</p> <p>Is that a good idea? For instance before refactoring:</p> <pre><code>public void collision(PhysicsCollisionEvent eve...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T18:37:20.530", "Id": "95852", "Score": "1", "body": "In response to \"I don't know of specific refactoring patterns,\" http://sourcemaking.com/refactoring provides a handy guide to many different types of refactoring." }, { ...
[ { "body": "<p>A couple of simple things I notice right off the bat.</p>\n\n<ol>\n<li>If you have a method which only calls another method, why bother having the first method at all? I'm personally against these one-line wrapper methods and see them as unnecessary noise.</li>\n<li>Your methods should be verb ph...
{ "AcceptedAnswerId": "54827", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T18:20:13.820", "Id": "54825", "Score": "6", "Tags": [ "java", "object-oriented", "modules", "physics" ], "Title": "Physics particle collisions" }
54825
<p>Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum. On similar lines, Partition problem is to determine whether a given set can be partitioned into two subsets such that the sum of elements in both subsets is same. </p> <p>Complexity:<...
[]
[ { "body": "<p>This solution is very dependant on <code>m</code> for the space complexity.</p>\n\n<p>I worry that, with the inputs:</p>\n\n<pre><code>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2000000000]\n</code></pre>\n\n<p>and the target sum <code>2000000002</code> that your program will run out of memory (it will do: <...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T19:33:53.657", "Id": "54831", "Score": "2", "Tags": [ "java", "algorithm", "dynamic-programming" ], "Title": "Determine if subset in int array adds up to a given input integer" }
54831
<blockquote> <p>Given a set of \$n\$ integers, divide the set in two subsets of \$\frac{n}{2}\$ sizes each such that the difference of the sum of two subsets is as minimum as possible. If \$n\$ is even, then sizes of two subsets must be strictly \$\frac{n}{2}\$ and if \$n\$ is odd, then size of one subset must ...
[]
[ { "body": "<p><code>Set</code> is a wrong choice for data representation. Even though the problem statement talks about sets and subsets, they are not sets in the Java sense. Try to run your test against the second example (hint: in the second example <code>4</code> appears twice).</p>\n\n<p>Time complexity is ...
{ "AcceptedAnswerId": "54861", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T20:24:08.163", "Id": "54835", "Score": "0", "Tags": [ "java", "algorithm", "backtracking" ], "Title": "Partition array into 2 sets, such that different of sums in both subsets ...
54835
<h2>Background</h2> <p>My lab administers four computer programs in three separate appointments. At each appointment, the subject does the programs in a pseudo-randomized order. Also, three of the programs have subversions, which are also pseudo-randomized so that the subject could do type A of program 1 at the first ...
[]
[ { "body": "<h2>UI Code</h2>\n\n<p>The windows set a response variable as a string. However, in most cases, the response can only be one of two values. Strings like <code>\"Yes\"</code> and <code>\"No\"</code> are good when a UI displays something to a user, but a computer works much better with boolean values.<...
{ "AcceptedAnswerId": "54841", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T21:13:38.197", "Id": "54836", "Score": "7", "Tags": [ "python", "python-2.x", "csv", "gui", "tkinter" ], "Title": "Refactoring Tkinter GUI that reads from and updates c...
54836
<p>I like Ruby's string multiplication so I thought I'd see if I could do it in Swift. I came up with these implementations: </p> <pre><code>@infix func * (left: String, right: Int) -&gt; String { var result = "" for _ in 0..right { result += left } return result } operator infix ** {} @infix...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T21:34:07.457", "Id": "95899", "Score": "3", "body": "`join(\"\", Array<String>(count: right, repeatedValue: left))`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T21:50:36.853", "Id": "95902", ...
[ { "body": "<p>As Flambino points out, the method is very problematic for negative integers. </p>\n\n<p>You need to either change the function to only accept unsigned integers or come up with some solution that makes sense for negative numbers.</p>\n\n<p>In general though, I don't particularly like operator-ove...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-20T21:29:23.033", "Id": "54837", "Score": "12", "Tags": [ "strings", "swift" ], "Title": "Swift string multiplication" }
54837
<p>Today's code is a filtering streambuf (and associated stream type) to automate word-wrapped output in C++:</p> <pre><code>#include &lt;iostream&gt; #include &lt;streambuf&gt; #include &lt;iomanip&gt; class widthbuf: public std::streambuf { public: widthbuf(int w, std::streambuf* s) : indent_width(0), ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T03:08:39.247", "Id": "95921", "Score": "0", "body": "I would create `std::codecvt` facet specialization. Then you can apply it to any stream you like. [Here is one for indenting](http://stackoverflow.com/a/1397588/14065)" } ]
[ { "body": "<p>I looked over this code carefully and came up with a number of aspects that might be considered for future enhancements.</p>\n\n<h2>Write initializers in declaration order</h2>\n\n<p>Since initialization is done in declaration order rather than the order that initializers are written, it's helpful...
{ "AcceptedAnswerId": "57549", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T01:26:49.080", "Id": "54845", "Score": "6", "Tags": [ "c++", "stream" ], "Title": "Filtering Streambuf" }
54845
<p>Mostly asking for critiques of vulnerability. Am I using any functions or methods that are unsafe?</p> <pre><code>&lt;?php $menu = array( "page1","page2","page3" ); $defpage = "page1"; $section = $defpage; if ( isset( $_GET['section'] ) ) $section = $_GET['section']; if ( !in_array( $section, $menu ) ) $section = ...
[]
[ { "body": "<p>I think it is.</p>\n\n<p>In general, you should be careful when using any type of data that the user can set when that data is passed to a SQL query, to a fopen call, to the HTML document or to the system shell (or similar things), because you would be giving that user some control over those reso...
{ "AcceptedAnswerId": "54849", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T02:09:44.590", "Id": "54847", "Score": "6", "Tags": [ "php", "security" ], "Title": "Is this PHP code snippet safe?" }
54847
<p>I wrote a variation of the Caeser Cipher and would like some feedback. Is it idiomatic? Can you generally see anything that can be improved?</p> <p>Use example:</p> <pre><code>let e = enc "Hello World" "This is the key" in dec e "This is the key" </code></pre> <p>Instead of taking a single value as the offset, i...
[]
[ { "body": "<pre><code>type Direction = (Int -&gt; Int -&gt; Int)\n</code></pre>\n\n<p>These parentheses are superfluous, though they don't really hurt if they help you to read the code.</p>\n\n<pre><code>upperBound = 127 ; lowerBound = 32\n</code></pre>\n\n<p>It's not very common to put definitions on the same ...
{ "AcceptedAnswerId": "54859", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T04:23:26.977", "Id": "54851", "Score": "3", "Tags": [ "haskell", "caesar-cipher" ], "Title": "Haskell encryption tips" }
54851
<p>I'm in the process of working on a client's site. I have a section containing a <code>ul</code> with list items and a <code>div</code> containing the slides that are triggered when clicking on an <code>li</code> item.</p> <p>For instance, <code>&lt;li id="nav-one"&gt;Item One&lt;/li&gt;</code> triggers <code>&lt;di...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T09:27:59.493", "Id": "95937", "Score": "1", "body": "Welcome to codereview.stackexchange.com! You're more likely to receive an answer if you specify what you don't like about your current code or have a specific question about the c...
[ { "body": "<p>You could turn this into a general purpose plugin, but I'm not gonna go into that. There are also many good plugins that provide this functionality.</p>\n\n<p>I'd ditch the IDs and just use the index of the current element as the reference.</p>\n\n<p>You'll obviously still need a parent element wi...
{ "AcceptedAnswerId": "54864", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T04:34:36.493", "Id": "54853", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "jQuery solution for a client's site" }
54853
<p>Recently I've been wondering about ways of implementing objects in code that can be represented by other primitives. An example of this is a Vector, which can be represented by a Vector\$N\$D where \$N\$ is the dimension of vector, or it can be represented by an \$N\$-tuple. </p> <p>The reason this is causing me s...
[]
[ { "body": "<p>In its standard library, Python itself prefers using a free-ranging function that may call a method on the class. For instance, <code>len()</code> calls <code>o.__length__</code>, <code>str()</code> calls <code>o.__str__()</code>, etc.</p>\n\n<p>Following this precedent, you can design your module...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T05:00:04.880", "Id": "54854", "Score": "3", "Tags": [ "python", "object-oriented", "functional-programming" ], "Title": "Python Vector implementation that acts as a class and also...
54854
<p>In an attempt to practice conditional statements in SQL I decided to design a tic-tac-toe game with MySQL. Let me know if you think any of the steps could be done better. </p> <p>Step 1: Create the game board:</p> <pre><code>USE test; DROP TABLE IF EXISTS TicTacToe; CREATE TABLE TicTacToe ( ID INT NOT NULL...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T06:38:13.700", "Id": "95934", "Score": "0", "body": "I don't know how much the SQL can be optimized further, I would mainly like to hear from application/object-based programmers to see what checks & balances I may have missed." }...
[ { "body": "<p>There is one big thing that I don't agree with, and that's your SQL schema. In my opinion, it is not normalized.</p>\n\n<p>Each row should only contain one kind of information. One row in your <code>TicTacToe</code> table however, contains three pieces information: The tile A, the tile B and the t...
{ "AcceptedAnswerId": "54869", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T06:12:50.433", "Id": "54856", "Score": "10", "Tags": [ "sql", "mysqli", "tic-tac-toe" ], "Title": "SQL Tic-Tac-Toe attempt" }
54856
<h1>v2 of this question is <a href="https://codereview.stackexchange.com/questions/54933/platform-independant-thread-pool-v2">here</a> and v3 is <a href="https://codereview.stackexchange.com/questions/54986/platform-independant-thread-pool-v3">here</a></h1> <p>To get a better understanding of C++11/C++14, I thought I ...
[]
[ { "body": "<p>This does not really stop them spinning:</p>\n\n<pre><code>// rather than spinning, give up thread time to other things\nstd::this_thread::yield();\n</code></pre>\n\n<p>It may give up the core for another thread (temporarily). But it will come back just as quickly to check for more work. So I am n...
{ "AcceptedAnswerId": "54878", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T07:45:30.297", "Id": "54858", "Score": "10", "Tags": [ "c++", "multithreading", "thread-safety", "reinventing-the-wheel", "c++14" ], "Title": "Platform independant thre...
54858
<p><strong>Introduction:</strong></p> <p>The following two code samples are a direct comparison of performance between Cython and C++. I pieced them together with the help of others-- I barely understand how they work. Their speed in my computer is: 1.225s vs 3.989s (C++ being the faster). The purpose of this comparis...
[]
[ { "body": "<p><strong>C++ script:</strong></p>\n\n<ul>\n<li><p>The data member <code>a</code> in <code>MathObject</code> should be <code>private</code>. This is necessary because classes are supposed to hide their data members and maintain their state from within the class.</p></li>\n<li><p>Instead of assignin...
{ "AcceptedAnswerId": "54876", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T14:51:57.303", "Id": "54868", "Score": "7", "Tags": [ "python", "c++", "performance", "comparative-review", "cython" ], "Title": "Understanding the differences: A direc...
54868
<p>I updated my class with more functionality, but I kind if feel like it's a mess or that it can at least be improved by a bit readability, efficiency and/or DRY wise.</p> <p>Anybody who could see if that can be done?</p> <p>Any other suggestions are also welcome.</p> <pre><code>class Validator { private $error...
[]
[ { "body": "<p>Good work formatting and approaching styles in a fashionable method, it makes reading your code very easy! a couple things to note:</p>\n\n<ul>\n<li><p>It's common to see <code>private</code> variables prefixed with an underscore to improve readability. It's up to you if you want to implement this...
{ "AcceptedAnswerId": "54895", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T16:00:48.260", "Id": "54874", "Score": "5", "Tags": [ "php", "optimization" ], "Title": "Cleaning up validator class" }
54874
<p>I have the following <code>UserServiceProvider</code> and I'm wondering whether so much dependency injection is overkill:</p> <p> <pre><code>use Illuminate\Support\ServiceProvider, App\Repositories\Eloquent\User\EloquentUserRepository, App\Repositories\Eloquent\Profile\EloquentProfileRepository, App\Repositories\E...
[]
[ { "body": "<p>You should reconsider the responsibilities of class <code>UserServiceProvider</code>, too many responsibilities may lead to a lot of dependencies in many cases.<br>\nIt is quite possible that this class is doing a lot of work that it should not, for example populating <code>User</code> object with...
{ "AcceptedAnswerId": "54961", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T18:12:11.003", "Id": "54880", "Score": "2", "Tags": [ "php", "dependency-injection", "laravel" ], "Title": "Laravel - lots of dependency injection" }
54880
<blockquote> <p>Given an unsorted array of integers, you need to return maximum possible \$n\$ such that the array consists at least \$n\$ values greater than or equals to \$n\$. Array can contain duplicate values.</p> <p>Sample 1</p> <pre><code>input : [1, 2, 3, 4] output: 2 </code></pre> <p>Sample 2...
[]
[ { "body": "<p>Right now, after you sort the array, you're doing a linear search for the correct value. I believe you should be able to write that part of the task using a binary search instead of a linear search.</p>\n\n<p>The sorting has a minimum complexity of \\$O(N log N)\\$, so reducing the search from \\$...
{ "AcceptedAnswerId": "54883", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T19:11:55.930", "Id": "54881", "Score": "5", "Tags": [ "java", "array", "interview-questions" ], "Title": "Finding the value 'n' in an array that has 'n' or more larger values" ...
54881
<pre><code>#!/usr/bin/env python ''' Search for files using wildcards amd magic ''' import os from fnmatch import fnmatch import sys import argparse import magic def cmd_args(): ''' returns a argparse namespane ''' parser = argparse.ArgumentParser() parser.add_argument( '--root', default='.', ...
[]
[ { "body": "<p>Let's first dispense with PEP8: by and large, as far as I can tell, your code respects PEP8. On the other hand, I've been writing Python professionally for almost 20 years and have never read PEP8 before today. </p>\n\n<p>This code does a number of things that I wouldn't do, however. First, it use...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T20:46:27.350", "Id": "54886", "Score": "1", "Tags": [ "python", "parsing", "file-system" ], "Title": "Cross-platform command line tool for finding files" }
54886
<p>Given an array, print the Next Greater Element (NGE) for every element. The Next Greater Element for an element x is the first greater element on the right side of x in array. Elements for which no greater element exist, consider next greater element as -1.</p> <p>Examples:</p> <ol> <li>For any array, rightmost el...
[]
[ { "body": "<p>You have implemented a 'huge' data structure to solve the problem. In this case though, the solution is to use a relatively simple case of memoization. If you work backward from the end of the array, you can use what you have already learned for previous values.....</p>\n\n<p>... in essence, you c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T20:47:32.593", "Id": "54887", "Score": "7", "Tags": [ "java", "algorithm", "stack" ], "Title": "Find the Next Greatest Element" }
54887
<p><a href="http://learnyouahaskell.com/input-and-output#randomness" rel="nofollow noreferrer">Learn You a Haskell</a> gives an exercise to implement the following function:</p> <pre><code>-- make a function that simulates tossing a function 3 times import System.Random tossCoin3 :: Int -&gt; (Bool, Bool, Bool) tossC...
[]
[ { "body": "<h1>Converting a <code>Bool</code> to a <code>Bool</code> with an <code>if</code></h1>\n\n<p><code>if</code> tests <code>Bool</code> values and returns results. You’re using it to return <code>True</code> if the input is <code>True</code>, and <code>False</code> if the input is <code>False</code>:</p...
{ "AcceptedAnswerId": "54896", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T22:23:27.537", "Id": "54892", "Score": "10", "Tags": [ "haskell", "random" ], "Title": "Random Coin Toss in Haskell" }
54892
<p>I'm following up on <a href="https://codereview.stackexchange.com/questions/54769/everyone-loves-fibonacci">this question</a>. I made a few decisions about my model and implemented recommendations accordingly.</p> <p><strong>TL;DR the link</strong></p> <blockquote> <p>Uses a loop algorithm to return a Fibonacci ...
[]
[ { "body": "<p><strong>Class vs Method</strong></p>\n\n<p>This class is structured so that you give it an input (<code>OrdinalPosition</code>), and then from it you get an output (<code>Value</code>). Well, we already have something that's much more specifically suited for that than a class: a method! Instead of...
{ "AcceptedAnswerId": "54901", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T22:34:03.800", "Id": "54894", "Score": "12", "Tags": [ "c#", "fibonacci-sequence" ], "Title": "Does everyone still love Fibonacci?" }
54894
<p>I'm trying to optimize my code (time optimization) based on this problem:</p> <blockquote> <p>Let <code>S</code> be a set of strings. Each string in <code>S</code> is associated with a set of elements. Consider, for example, <code>S = {"home", "tree"}</code>. Implement a data structure that is a collection of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T23:10:42.190", "Id": "96004", "Score": "0", "body": "Each time you call [] on the map, it performs an expensive search. Store the result in a reference." } ]
[ { "body": "<p>Before you attempt to optimize this, I would recommend refactoring it to be easier to follow. It may seem easier to just put everything into <code>main()</code> and not have to worry about functions, but that's actually worse. Just by looking at this, I wouldn't be able to tell what the code is ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T23:04:47.533", "Id": "54897", "Score": "6", "Tags": [ "c++", "performance", "programming-challenge", "hash-map" ], "Title": "Implementing a data structure that is a collection...
54897
<blockquote> <p>Giving the following example list the task is: find out whether the second expression is in the first one. <code>*</code> shall be considered as a wildcard for any character and one should be able to escape it <code>\*</code></p> <pre class="lang-none prettyprint-override"><code>Hello,ell Thi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T23:47:37.300", "Id": "96010", "Score": "0", "body": "Should one be able to escape escapes?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T08:26:49.397", "Id": "96027", "Score": "0", "body...
[ { "body": "<p>Your solution seems like an overkill for what is asked. You only need to answer if the second expression is in the first one. In your solution, you are searching for ALL occurrences, no wonder why it takes some extra time :)</p>\n\n<p>For me, the most elegant solution would be like:</p>\n\n<pre><c...
{ "AcceptedAnswerId": "67365", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-21T23:29:16.017", "Id": "54900", "Score": "3", "Tags": [ "python", "strings", "regex", "escaping" ], "Title": "More Pythonic version of finding substring with one glob-like ex...
54900
<p>I'm playing <a href="https://www.codehunt.com/">Code Hunt</a> on level 2.06 (loops). This level is about counting the number of "a" in a String.</p> <pre><code>public class Program { public static int Puzzle(String s) { int ret = 0; for(int x = 0; x &lt; s.length(); x++){ if(s.charAt(x).equals('a')) r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T12:13:56.753", "Id": "96066", "Score": "1", "body": "Un-upvoting, and then Down-voting, because, as has been pointed out, the code does not compile. `s.charAt(x).equals('a')` is illegal." }, { "ContentLicense": "CC BY-SA 3.0...
[ { "body": "<p>I don't know which is the meter for elegance but whatever. </p>\n\n<ol>\n<li><p>Choose better names for you variables, what ret means? It's the sum of all \"a\" inside a String! Why not call it sumOfA or aCount? (They are terrible as nanes, but I can't get something better right now...)</p></li>\n...
{ "AcceptedAnswerId": "54906", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T00:54:18.033", "Id": "54903", "Score": "2", "Tags": [ "java", "strings" ], "Title": "Code Hunter 2.06: Count occurrences of 'a' in a string" }
54903
<p>Old code: </p> <p><a href="https://codereview.stackexchange.com/questions/54723/login-system-security/">Login system security</a></p> <p>This is an update on the code and suggestions I received from generous users on the old thread.</p> <p>So same rules apply, just check it out, tell me what you think. Is it bett...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T01:53:59.837", "Id": "96015", "Score": "0", "body": "Yes!! So much i can say here! I should finish my dinner before though :D" } ]
[ { "body": "<p>Notes:</p>\n<ul>\n<li>For the sake of reading it efficiently, I placed your code in my IDE to let it format the indentations.</li>\n</ul>\n<hr />\n<h2>Here's what looks good</h2>\n<ul>\n<li><p>Thorough comments. It helps!</p>\n</li>\n<li><p><code>password_verify($passtemp, $hash[0])</code>! Yes! B...
{ "AcceptedAnswerId": "54911", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T01:49:46.447", "Id": "54907", "Score": "4", "Tags": [ "php", "security", "authentication" ], "Title": "Login System Security Part 2" }
54907
<p><a href="http://learnyouahaskell.com/input-and-output#randomness" rel="nofollow">Learn You a Haskell</a> presents the <code>randoms</code> function. </p> <p>I implemented it as follows:</p> <pre><code>-- randoms that takes a generator and returns an infinite sequence -- of values based on that generator import Sy...
[]
[ { "body": "<p>Straight forward. Easy to follow. But this is clearly some kind of fold.</p>\n\n<pre><code>randoms' = unfoldr (Just . random)\n</code></pre>\n\n<p>works nicely.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T02:35:36.963", "Id": "54908", "Score": "3", "Tags": [ "haskell", "random", "reinventing-the-wheel" ], "Title": "Implementing `randoms`" }
54908
<p>The subset size should be greater than or equal to 2.</p> <p>How can I speed up this code?</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; #include&lt;math.h&gt; #include&lt;malloc.h&gt; #include &lt;iostream&gt; #include &lt;vector&gt; long long int set[100000]; long long int counter, j; long long...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T04:47:28.220", "Id": "96022", "Score": "0", "body": "This is very C-like, with the exception of `<iostream>` and `<vector>`. Are you still trying to implement it in C++ specifically?" } ]
[ { "body": "<p>There are a few points I'd make about this code.</p>\n\n<ol>\n<li><p>Choose your language. Right now, you're using a number of C++ headers, so a C compiler can't process your code. Unfortunately, you <em>don't</em> seem to be putting any C++ features to use to make the code more readable, understa...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T04:21:25.467", "Id": "54913", "Score": "3", "Tags": [ "c++", "performance", "combinatorics", "bitwise", "set" ], "Title": "Finding the 'Minimum' AND of all the possible su...
54913
<p>I am trying to implement Stack using a linked list. Looking for code-review, best practices and optimizations. </p> <pre><code>public class StackUsingLinkedList&lt;T&gt; { private Node&lt;T&gt; top; int size; public StackUsingLinkedList() { } private static class Node&lt;T&gt; { Node&...
[]
[ { "body": "<p>This is generally good code, with standards-conforming names and style.</p>\n\n<p>It appears that <code>size</code> is an afterthought variable. It is not scoped as being 'private', and it is not decreased in the <code>pop()</code> method, so it is buggy in two ways.</p>\n\n<p>Additionally, even i...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T04:31:51.083", "Id": "54915", "Score": "4", "Tags": [ "java", "algorithm", "linked-list", "stack" ], "Title": "Implement stack using a linked list" }
54915
<p>I've spent quite a bit of time studying the repository and entity patterns and this is what I came up with. I would appreciate it if you could post suggestions and critique.</p> <p><code>User entity</code>:</p> <pre><code>&lt;?php namespace App\Entities\Entities\User; use App\Entities\Abstracts\Abstra...
[]
[ { "body": "<p>Maybe I'm just thinking of a different approach, but I normally would've reversed the dependency between UserEntity and UserRepository. I would expect the UserEntity to represent a singular record in the database and that I would use the UserRepository to retrieve one.</p>\n\n<p>In this case, I w...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T06:41:05.640", "Id": "54919", "Score": "5", "Tags": [ "php", "design-patterns", "laravel", "repository" ], "Title": "Laravel - Repository and Entity patterns" }
54919
<pre><code>&lt;?php namespace Users; use mysqli; class Users { protected $db; public function __construct() { $this-&gt;db = new mysqli('localhost', 'root', 'php123', 'sms'); } public function login($username, $password) { $query = $this-&gt;db-&gt;prepare("SELECT username, password FR...
[]
[ { "body": "<ul>\n<li><p>Why are you starting a new database connection for each class? Pass in a database connection object to the constructor:</p>\n\n<pre><code>public function __construct(mysqli $dbConnection) {\n</code></pre>\n\n<p>This allows your class to work without worrying about actually doing the conn...
{ "AcceptedAnswerId": "54922", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T07:30:54.113", "Id": "54920", "Score": "7", "Tags": [ "php", "object-oriented", "mysqli", "authentication" ], "Title": "Classes for user registration and authentication" }
54920
<p>I have a satellite orbit simulation in Matlab (Using Runge Kutta 4). It seems ugly and I don't know how to fix it.</p> <p><strong>fx.m file:</strong></p> <pre><code>function v = fx(t,x,vx) v = vx; </code></pre> <p><strong>fy.m file:</strong></p> <pre><code>function v = fy(t,y,vy) v = vy; </code></pre> <p><stro...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T09:41:23.980", "Id": "54923", "Score": "4", "Tags": [ "mathematics", "matlab", "simulation", "geospatial", "physics" ], "Title": "Satellite orbit simulation in Matlab usin...
54923
<p>I previously <a href="https://stackoverflow.com/questions/24348820/css-and-positioning-with-multiple-divs">asked in StackOverflow</a> for help putting this together, and was told that I could improve the HTML and CSS.</p> <p>Could you help me?</p> <p>Here is my code, and the pictures I am using:</p> <h1>Code</h1>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T10:41:42.670", "Id": "96047", "Score": "0", "body": "Welcome to Code Review! Unfortunately, this doesn't appear to be the right place to ask your question, if the layout is not behaving the way you expect it to. (Here, we help impro...
[ { "body": "<p>There are a few things here that definitely can be improved/optimized. I'm not sure what your levels of support are but...</p>\n\n<p>I'd do something along these lines, This doesn't take into account mobile devices, and it was just thrown together really quickly, but you can take from it what you ...
{ "AcceptedAnswerId": "54962", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T09:54:35.630", "Id": "54925", "Score": "1", "Tags": [ "html", "css" ], "Title": "Getting topyellow, topred, slider, and navbar divs stacked" }
54925
<p>I hope that someone could review a module I wrote for bank card validation. I included a class that tests some of the methods, which is purely to show the methods work, rather than unit testing.</p> <p><strong>Validator</strong></p> <pre><code>import java.util.regex.Matcher; import java.util.regex.Pattern; /** *...
[]
[ { "body": "<p>There are three purposes to your code:</p>\n\n<ol>\n<li>Converting the human-friendly input string to a canonical digits-only format</li>\n<li>Verifying the plausibility of the number using the <a href=\"http://en.wikipedia.org/wiki/Luhn_algorithm\">Luhn Algorithm</a></li>\n<li>Classifying the typ...
{ "AcceptedAnswerId": "54929", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T10:05:23.357", "Id": "54926", "Score": "11", "Tags": [ "java", "beginner", "validation", "finance" ], "Title": "Bank card validation module" }
54926
<pre><code>/** * Class stringHelperK * Helper Class to deal with small string manipulations. */ class stringHelperK { public function normalizeStringK($string) { return $this-&gt;removeAccents( $this-&gt;replaceSpacesWithSlashes($string) ); } /** * @param $string ...
[]
[ { "body": "<p>This class looks like a utility class, and you could use static functions: you then wouldn't need to instantiate it:</p>\n\n<pre><code>class StringHelperK {\n\n public static function normalizeStringK($string) {\n return static::removeAccents(\n static::replaceSpacesWithSlashe...
{ "AcceptedAnswerId": "54930", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T10:28:53.593", "Id": "54927", "Score": "1", "Tags": [ "php", "object-oriented", "strings" ], "Title": "Is it possible to remove variable repetition here?" }
54927
<h1>This is a continuation of <a href="https://codereview.stackexchange.com/questions/54858/platform-independant-thread-pool">this</a> question, v3 can be found <a href="https://codereview.stackexchange.com/questions/54986/platform-independant-thread-pool-v3">here</a></h1> <p>Taking into account the advise given by Lo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T14:40:04.783", "Id": "96083", "Score": "0", "body": "*\"an implementation of the threadpool using a `std::continuation_variable`\"* You mean `condition_variable`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>OK some fixes to stop you getting trapped:</p>\n\n<p>You were getting stuck because you could <code>notify_all()</code> and wake the threads in the condition variable. Then after the notification another thread can set <code>wakeup_flag</code> to false thus trapping the threads in the condition va...
{ "AcceptedAnswerId": "54955", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T11:30:58.933", "Id": "54933", "Score": "3", "Tags": [ "c++", "multithreading", "thread-safety", "reinventing-the-wheel", "c++14" ], "Title": "Platform independant threa...
54933
<p>This is my first attempt to write a multithreaded application that downloads files from internet. I am looking for improvement in code, logic and better strategy for implementation.</p> <p>Please ignore the <code>pylint</code> messages which is not the focus at the moment.</p> <p>To manually test you can use the U...
[]
[ { "body": "<p>I gave this a quick code review. Please ignore anything you disagree with. I was trying to identify non-idiomatic things that would help improve readability, logic, etc. Hopefully some of this is helpful to you.</p>\n\n<p>I would sort the modules below. I usually add spacing between my import and...
{ "AcceptedAnswerId": "58149", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T11:45:43.470", "Id": "54935", "Score": "6", "Tags": [ "python", "performance", "multithreading", "logging" ], "Title": "Multithreaded file downloader using threading and si...
54935
<p>I am writing a recursive function based on the Travelling Salesman Problem.</p> <p>Is this a correct way of doing things, or am I creating memory leaks?</p> <p>Prerequisites are:</p> <ul> <li>a two dimensional matrix <code>distance_matrix[][]</code> to store the distances between the cities</li> <li>a global <cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T18:07:17.827", "Id": "98560", "Score": "0", "body": "What is the source of these prerequisites? Is it really a requirement that you use a global int to mark the current progress of the algorithm? Is it really required that you use Q...
[ { "body": "<ol>\n<li><p>As a brute force solution to the Traveling Salesman it seems to make sense. The algorithm seems to test every single combination of cities.</p>\n\n<p>The method used for listing remaining cities seems to be a simple one. You could avoid a lot of allocations and adding/removing to lists b...
{ "AcceptedAnswerId": "56006", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T13:37:58.807", "Id": "54940", "Score": "8", "Tags": [ "c++", "recursion", "memory-management", "qt", "traveling-salesman" ], "Title": "Travelling Salesman in Qt" }
54940
<p>Here is my full implementation of a generic Functor-like class:</p> <pre><code> #ifndef FUNCTIONHPP #define FUNCTIONHPP #include "Types.hpp" #include &lt;tuple&gt; #include &lt;utility&gt; BEGIN_NAMESPACE //This is a define in "Types.hpp" namespace FN_HELPERS { template&lt;int ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T18:55:17.723", "Id": "96122", "Score": "0", "body": "The cost of a virtual call is one extra load instruction. Are you really worried about that? Given that you are reading data out of a socket file descriptor before the call I doub...
[ { "body": "<p>I think you have re-designed large parts of the standard library.</p>\n\n<p>I would simply do this:</p>\n\n<pre><code>#include &lt;utility&gt;\n#include &lt;iostream&gt;\n#include &lt;unistd.h&gt;\n#include &lt;errno.h&gt;\n</code></pre>\n\n<h3>Structure to hold any function across a pipe.</h3>\n\...
{ "AcceptedAnswerId": "54967", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T14:11:16.170", "Id": "54943", "Score": "6", "Tags": [ "c++", "multithreading", "template-meta-programming", "type-safety" ], "Title": "Function object passing for a task sc...
54943
<p>I am using this jQuery code to get two carousels working in bootstrap, and it's working for me.</p> <pre><code>$('#image-gallery-carousel').carousel({ interval: 5000 }); $('#carousel-caption-text').html($('#slide-content-0').html()); // When the carousel slides, auto update the text $('#image-gallery-carousel'...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-24T03:25:47.150", "Id": "96415", "Score": "0", "body": "Can I get a review for this code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-02T20:43:37.710", "Id": "98296", "Score": "0", "body": "...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>Magic constants should go on top ( <code>5000</code> and <code>12000</code></li>\n<li>You use this construct <code>.html($('#slide-content-'+id).html());</code> 4 times, a helper functions might be in order.</li>\n<li>You don't need <code>e</code> in the event ha...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T14:14:51.790", "Id": "54944", "Score": "3", "Tags": [ "javascript", "jquery", "twitter-bootstrap" ], "Title": "Activating image and video carousels" }
54944
<p>Old Post: <a href="https://codereview.stackexchange.com/questions/54920/classes-for-user-registration-and-authentication">Classes for user registration and authentication</a></p> <p>This post is an update of the old post of mine. This is the code after suggestions were implemented in the review. Do you think I coul...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T14:24:57.580", "Id": "96265", "Score": "0", "body": "More criticizes except for Hashing please!" } ]
[ { "body": "<p>Right now, you're using the same salt for every user. This pretty much defeats the purpose of using salt in the first place.</p>\n\n<p>The point of using salt is to ensure that even if two users choose the same password, the hashed value will still be unique for each. So, to be useful, you compute...
{ "AcceptedAnswerId": "54947", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T14:19:15.457", "Id": "54945", "Score": "10", "Tags": [ "php", "object-oriented", "mysqli", "authentication" ], "Title": "Update of Classes for user registration and authent...
54945
<p>I am using this script to detect the most prefered language by the user.</p> <pre><code>function Get_Client_Prefered_Language ($getSortedList = false, $acceptedLanguages = false) { if (empty($acceptedLanguages)) $acceptedLanguages = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; preg_match_all('/([a-z]{1,8}(-[...
[]
[ { "body": "<p>The following is imho easier to read and should give you best performance.</p>\n\n<pre><code>&lt;?php\n\n/**\n * Get a sorted list of client accepted languages.\n *\n * @staticvar array $examined\n * Used to cache the sorted list for &lt;var&gt;$accept_languages&lt;/var&gt; strings.\n * @param b...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T15:01:22.983", "Id": "54948", "Score": "5", "Tags": [ "php", "http", "i18n" ], "Title": "Detect prefered language" }
54948
<p>On my website I want to offer some PDFs, ZIP files and images for download. They are all in the same folder and I could simply link to them like <code>&lt;a href="download/file.pdf"&gt;download file&lt;/a&gt;</code>. But instead I want to invoke a download dialog by sending an attachment header via php. The link wou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T15:39:37.140", "Id": "96091", "Score": "1", "body": "what happen if you try to change the ?f=X param? It allows you to download your application files?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T...
[ { "body": "<p>Take care to call <code>strpos()</code> correctly. If the <code>f</code> parameter contains a leading <code>/</code>, it sneaks through.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T16:03:47.503", "Id": "96098", "Sc...
{ "AcceptedAnswerId": "54953", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T15:09:47.553", "Id": "54949", "Score": "4", "Tags": [ "php", "security" ], "Title": "Simple file downloader" }
54949
<p>I have this function:</p> <pre><code>function Filer() { setTimeout(function () { $.ajax({ url: '/Pages/Handlers/filecheckerhandler.ashx', data: { id: GetMyId(), sid: GetSessionId() }, success: function (data) { if (data == "true") { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T15:49:29.613", "Id": "96094", "Score": "0", "body": "You should post all of your code here for review. With the little information you've given I can only suggest that you looked at websockets." }, { "ContentLicense": "CC BY...
[ { "body": "<p>You are polling <code>filecheckerhandler.ashx</code> regularly at two-second intervals. The fact that such polling is implemented using recursion, with <code>Filer()</code> calling itself, is irrelevant to your performance problem. You could improve the client code by using <code>setInterval()</c...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T15:37:15.180", "Id": "54952", "Score": "1", "Tags": [ "javascript", "jquery", "performance", "recursion", "ajax" ], "Title": "Polling AJAX client for P2P file sharing webs...
54952
<p>This code asks for letters and a number of letters per word and generates all possible permutations. Then compares those permutations with an English dictionary and creates a list with all the words that match with the dictionary. Finally, it prints the list on a new terminal. The problem is that when words are long...
[]
[ { "body": "<p>You're first building a list of all permutations of the input word, and then using that to filter the dictionary. The problem with this approach is that the number of permutations is huge — for 10 distinct letters, there are 10! = 3628800 permutations. In comparison, <code>/usr/share/dict/american...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T17:16:06.423", "Id": "54957", "Score": "4", "Tags": [ "python", "strings", "memory-management", "console", "combinatorics" ], "Title": "Permutations program in Python" }
54957
<p>This is a prepared statement (I think). Have I done this well?</p> <pre><code>function wyswietl($rekord, $tabela) { $lacz = lacz_bd(); if (!$zap_preparowane = $lacz-&gt;prepare("SELECT {$rekord} FROM {$tabela} where email = ?")) {echo "Prepare nieudane: (" . $zap_preparowane-&gt;errno . ")...
[]
[ { "body": "<p>Single line if statements combined with column aligned spacing:</p>\n\n<p>Never ever do this. Never. A quick glance at the code you posted looks like this:</p>\n\n<pre><code>function wyswietl($rekord, $tabela) {\n $lacz = lacz_bd();\n\n if (!$zap_preparowane = $lacz-&gt;prepare(\"SELECT {$re...
{ "AcceptedAnswerId": "54964", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T17:18:59.807", "Id": "54958", "Score": "5", "Tags": [ "php", "mysql" ], "Title": "Have I prepared this prepared statement well?" }
54958
<p>This is a module to implement a key value store in Python using SQLite3. Originally written to allow sharing of configuration among multiple threads that are already sharing a SQLite3 database, I have generalized for most use cases. The interface in Python is as similar to dictionary objects as possible.</p> <p>Dif...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-01T17:33:32.403", "Id": "97982", "Score": "1", "body": "Did you consider using the built-in [`dbm`](https://docs.python.org/3/library/dbm.html)?" } ]
[ { "body": "<p>First, the obligatory pointer to <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a>. In particular, your class names and some docstrings do not follow it. Variable names and line lengths arguably as well.</p>\n\n<p>Next, a couple of specific cases where you could ma...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T17:23:03.453", "Id": "54960", "Score": "6", "Tags": [ "python", "database", "python-2.x", "sqlite" ], "Title": "Persistent key value store for Python using SQLite3" }
54960
<p>Please review these activities which handle converting units in an Android app: </p> <p>I would appreciate any guidance and advice on code refactoring and different design patterns or strategies that I could use to improve the code. Thank you!</p> <p>AngleActivity:</p> <pre><code>public class AngleActivity extend...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T09:00:48.883", "Id": "96195", "Score": "0", "body": "Why `float` instead of `double` or even better some high precision type?" } ]
[ { "body": "<p>Here's some things I've found by skimming through your code a bit. There is more things that can be said, but this should get you started:</p>\n\n<hr>\n\n<pre><code>public float ratio[];\n</code></pre>\n\n<p>Don't use <code>public</code> fields. I expect you want this to be accessible to subclasse...
{ "AcceptedAnswerId": "54971", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T20:02:57.940", "Id": "54968", "Score": "7", "Tags": [ "java", "design-patterns", "android" ], "Title": "Unit conversion activities" }
54968
<p>I have spent a long time trying to find a way to do the following:</p> <ul> <li>Update a MySQL database with AJAX </li> <li>Reload the Page to show changes</li> <li>Show a success message</li> </ul> <p>I think I have finally found a way! Let me know of any improvements.</p> <p><strong>The method:</strong></p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T20:20:58.253", "Id": "96137", "Score": "0", "body": "Should have mentioned that i sanitise my I/O with a function but left it out for cleaner reading" } ]
[ { "body": "<p>What you're doing is extremely typical. So typical that a language was made specifically for it: Ajax!</p>\n<p>I'll make some comments here, starting from the top.</p>\n<h2>Your method</h2>\n<p>It's close, but it can be simplified <em>even</em> more. For reference, here's your method:</p>\n<blockq...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T20:10:18.503", "Id": "54969", "Score": "3", "Tags": [ "php", "jquery", "mysql", "ajax" ], "Title": "Update database, reload page then show a success message" }
54969
<p>Follow-up question: <a href="https://codereview.stackexchange.com/questions/55626/detect-if-a-tree-is-complete-binary-tree">Detect if a tree is complete binary tree</a></p> <p>Detect if a tree is complete binary tree or not. Looking for code review, optimizations and best practices.</p> <pre><code>public class Com...
[]
[ { "body": "<pre><code>import java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.util.Queue;\n\npublic class CompleteBinaryTreeDetection&lt;T&gt; {\n</code></pre>\n\n<p>why is this not final?</p>\n\n<pre><code> private TreeNode&lt;T&g...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T20:25:04.077", "Id": "54970", "Score": "4", "Tags": [ "java", "algorithm", "tree" ], "Title": "Detect a complete binary tree" }
54970
<blockquote> <p>Implement a queue using a linked list.</p> </blockquote> <p>I'm looking for a code review, optimizations and best practices.</p> <pre><code>public class QueueAsLinkedList&lt;T&gt; { private Node&lt;T&gt; front; private Node&lt;T&gt; rear; private int size; public QueueAsLinkedList(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T00:36:38.633", "Id": "96157", "Score": "0", "body": "I don't see any [`implements Queue<T>`](http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html) in your code, which I would expect to see from the \"implement Queue\" descr...
[ { "body": "<ul>\n<li><p>There is no point in having the constructor for Node require the 'next' node. It is never part of the constructor, in your code.</p></li>\n<li><p>The default constructor is useless code here. You may as well remove it, it does nothing.</p></li>\n<li><p>the method <code>getCount</code> sh...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T21:23:31.560", "Id": "54977", "Score": "6", "Tags": [ "java", "linked-list", "queue" ], "Title": "Implement a queue using a linked list" }
54977
<p>I work on ubuntu machine and my backup requirements are straightforward. My only requirement is the usual copy paste, but only changed files (ie. the files whose modification-time OR size has changed) should get replaced.</p> <p>Since I could not find such option in the default nautilus copy-paste (it only allows a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-26T14:28:21.153", "Id": "97936", "Score": "2", "body": "Why not just use [rsync](http://en.wikipedia.org/wiki/Rsync)? It automatically doesn't copy files that are the same at the destination." }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>I can't think of any way the file size could change without the mtime\nchanging too. On the other hand, it does no harm to check, aside from\nmaking the code a little more complex.</p>\n\n<p>You use the expression <code>backup_loc + subpath</code> quite often, so I would do\nthis:</p>\n\n<pre><cod...
{ "AcceptedAnswerId": "54983", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-22T22:10:17.673", "Id": "54980", "Score": "1", "Tags": [ "python", "python-2.x" ], "Title": "A small backup script in Python" }
54980
<h1>This is a continuation of <a href="https://codereview.stackexchange.com/questions/54933/platform-independant-thread-pool-v2/54955#54955">this</a> question, v4 can be found <a href="https://codereview.stackexchange.com/questions/55100/platform-independant-thread-pool-v4">here</a></h1> <p>Taking the advise given pre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T18:11:26.640", "Id": "96351", "Score": "1", "body": "`enqueue_task(std::function<T(Args...)> && task, Args... args)` -- `task` is not a universal reference. Universal references are **only** formed when using `template_parameter_nam...
[ { "body": "<p>Technically, this is off-topic as this isn't working code.</p>\n<p>That being said, it's quite a tricky problem, so I want to answer it anyway.</p>\n<p>First off, your <code>args</code> should be passed by <code>Args&amp;&amp;</code>:</p>\n<pre><code>template&lt;typename T, typename... Args&gt;\ns...
{ "AcceptedAnswerId": "55047", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T01:45:14.620", "Id": "54986", "Score": "4", "Tags": [ "c++", "template", "lambda", "c++14" ], "Title": "Platform independant thread pool v3" }
54986
<p>I'm just trying to create a binary tree, and a pretty printer for it:</p> <pre><code>#include &lt;stdio.h&gt; typedef unsigned long Leaf; struct NodeStruct { struct TreeStruct * left; struct TreeStruct * right; }; typedef struct NodeStruct Node; struct TreeStruct { char isNode; union { No...
[]
[ { "body": "<h3>Disclaimer: I am a C++ coder, but I researched to make sure none of that made it into this advise.</h3>\n\n<p>It looks alright, there are a couple little things.</p>\n\n<ul>\n<li><p>First, explicitly state that <code>main()</code> takes no arguments. This is applicable to all functions in C:</p>...
{ "AcceptedAnswerId": "54992", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T02:00:32.313", "Id": "54987", "Score": "2", "Tags": [ "c", "tree", "formatting" ], "Title": "Binary tree (S-Expression) pretty printer" }
54987
<p>So I have some code that works as PDO. But is it secure? I'm trying to prevent SQL injection. This is my first PDO script and was hoping to see if it was done correctly. Here it is. </p> <pre><code>&lt;?php echo 'Your query code has been submited'; $host = "localhost"; $pass = "root"; $user= "root"; $dbname = "use...
[]
[ { "body": "<p>It depends on what you're looking to be safe.</p>\n<p>If you're worried about the <a href=\"http://bobby-tables.com/\" rel=\"nofollow noreferrer\">bobby tables case</a>, you're fine. However, <a href=\"https://www.owasp.org/index.php/Category:Vulnerability\" rel=\"nofollow noreferrer\">there are m...
{ "AcceptedAnswerId": "54990", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T02:18:51.700", "Id": "54988", "Score": "4", "Tags": [ "php", "pdo", "form", "sql-injection" ], "Title": "POST security with PDO?" }
54988
<p>I've implemented the solution to <a href="http://projecteuler.net/problem=18">Project Euler Problem 18</a> in Haskell and I'd like to get some thoughts on my implementation. Its the dynamic programming solution, working from the bottom up.</p> <p>Basically, given a set of numbers in a triangular shape, the path wh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-04T05:35:57.680", "Id": "106060", "Score": "0", "body": "By the way, answer checking is now restored on http://projecteuler.net. Unfortunately, you still can't log in yet." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>I'll focus on <code>maxPathSum</code> as this is the core part of the algorithm.</p>\n\n<p>The approach of <code>zipWith max ys (tail ys)</code> is correct and very nice, this is the essence of the recursive step.</p>\n\n<p>But first, you're doing a lot of unnecessary computations at every step. I...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T02:54:48.013", "Id": "54991", "Score": "8", "Tags": [ "haskell", "programming-challenge" ], "Title": "Project Euler Problem 18 (Haskell) - Maximum path sum I" }
54991
<p>Is there a better way to do this?</p> <p>A time series,</p> <pre><code>data Model a where Variant :: [(Day, a)] -&gt; Model a deriving (Show) </code></pre> <p>... where type <code>a</code> in <code>[(Day, a)]</code> basically represents the "total balance" e.g. bank account.</p> <p>Some example data,</p> <...
[]
[ { "body": "<p>I think the issue is you are doing two things at once: merging the two day lists, and calculating an accumulation of a list. Note that I'm going to assume the Variant is always in order, as it will make everything much more efficient.</p>\n\n<p>Firstly, to join two variants, I used this:</p>\n\n<p...
{ "AcceptedAnswerId": "54997", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T03:51:58.680", "Id": "54993", "Score": "5", "Tags": [ "haskell" ], "Title": "Merging time series" }
54993
<p>I'm new to Go and looking for a review of my merge sort and bubble sort implementations. What can be done better? Can my code be cleaner/clearer? </p> <pre><code>// algos.go // (C) 2014 splashinn // Implement two types of sorting algorithms; merge sort and bubble sort package main import ( "fmt" "time" ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T14:27:29.787", "Id": "96267", "Score": "2", "body": "There is a mergesort implementation already in the stdlib (as well as quicksort), if you'd like to compare: http://golang.org/src/pkg/sort/sort.go" }, { "ContentLicense": ...
[ { "body": "<p>I don't see any major problems but there are a number of (really very minor) little nits.</p>\n\n<p>First, the trend seems to be for people to like very few blank lines. I think this trend is driven by the prevalence of syntax highlighting. I recently I had the occasion to program on a machine w...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T05:02:08.703", "Id": "54996", "Score": "4", "Tags": [ "algorithm", "beginner", "sorting", "mergesort", "go" ], "Title": "Implementation of merge sort and bubble sort" }
54996
<p>I spent a lot of time doing <a href="http://www.carlostristacci.com.br/blog/extreme-go-horse-xgh/" rel="nofollow">Go Horse Extreme programming</a>, but now I want to be a better person.</p> <p>How can I make this method smaller, better, more OOP? </p> <pre><code>/** * @return \Illuminate\Http\RedirectResponse */...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-24T17:06:46.590", "Id": "96601", "Score": "2", "body": "You could watch these videos, they will help you **https://laracasts.com/search?q=refactoring**" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-24T18:...
[ { "body": "<p>There are many ways you can refactor this method but since you are using Laravel things are pretty easy. Here is my attempt on refactoring (I'd rather call it re-writing) this method.</p>\n\n<p>First of all, this controller is overloaded with so many responsibilities, a controllers sole job should...
{ "AcceptedAnswerId": "55390", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T07:06:42.410", "Id": "55001", "Score": "5", "Tags": [ "php", "beginner", "object-oriented", "mvc", "laravel" ], "Title": "Controller for handling user registration" }
55001
<p>The new table feature on Excel is excellent and you can specify a column formula as well as exceptions on the column. However, if you want to change the column formula, Excel will rewrite the whole column including the exceptions. I've tried to avoid this issue with the following code:</p> <pre><code>Private Sub Wo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T14:55:20.760", "Id": "96271", "Score": "1", "body": "1. what is \"ugly\" about the code? 2. use meaningful names for your variables" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-24T08:12:53.230", "...
[ { "body": "<blockquote>\n<pre><code>Private Sub Worksheet_Change(ByVal Target As Range)\n</code></pre>\n</blockquote>\n\n<p>The <code>Worksheet.Change</code> event gets fired whenever <em>anything</em> changes <em>anywhere</em> in the worksheet. Code you write in a handler for that event <em>must</em> do its bu...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T07:35:07.337", "Id": "55002", "Score": "5", "Tags": [ "optimization", "performance", "vba", "excel" ], "Title": "Ignore exceptions when changing column formula in Excel table"...
55002
<p>I am writing my first jQuery plugin that converts <code>li</code> tags to horizontal responsive barcharts. I am looking for some feedback and suggestions regarding the implementation.</p> <p><img src="https://i.stack.imgur.com/LN2i5.png" alt="barcharts example"></p> <p><div class="snippet" data-lang="js" data-hide...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T11:13:32.853", "Id": "96205", "Score": "0", "body": "@Jack where should i post it then?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T11:16:17.527", "Id": "96206", "Score": "1", "body": ...
[ { "body": "<p>I'd recommend you to get rid of class selector here</p>\n\n<pre><code>// Gather\nvar $targets = $(this).find('.bar-group-item');\n</code></pre>\n\n<p>because you need you're HTML structure to use specific classes. You'd better find them by finding elements with data attributes inside plugin's targ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T08:44:17.450", "Id": "55004", "Score": "4", "Tags": [ "javascript", "jquery", "html", "css", "plugin" ], "Title": "Converting <li> tags to horizontal responsive barcharts"...
55004
<p>I could not find any definitions of the EventSource object that belongs to <a href="http://dev.w3.org/html5/eventsource/" rel="nofollow">Server-Sent Events</a>, so I create the definitions. That's how they look like:</p> <pre><code>declare var EventSource : sse.IEventSourceStatic; declare module sse { enum Re...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-09-19T11:44:54.650", "Id": "265759", "Score": "0", "body": "Does this definition mean that you're attaching to the events like\n`eventSource.on('onmessage', ...)` ? (note: I'm also a beginner in TS)" }, { "ContentLicense": "CC BY-...
[ { "body": "<p>According to your definition file, I'm assuming there's a global class called <code>EventSource</code></p>\n\n<p>If that's the case, I have the following improvements:</p>\n\n<ul>\n<li>Avoid <code>Function</code> (or <code>Object</code> or <code>Array</code>), describe the signature accurately (li...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T10:57:28.717", "Id": "55008", "Score": "4", "Tags": [ "beginner", "typescript" ], "Title": "TypeScript definitions for Server-Sent Events" }
55008
<p>I need to validate whether my regex is correct for below scenario. Suggestion's if the regex is correct:</p> <p><a href="http://en.wikipedia.org/wiki/E-mail_address#Local_part">Wiki Link <strong>Local_part</strong></a></p> <p>The local-part of the email address may use any of these ASCII characters.[4] RFC 6531 pe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T11:41:10.603", "Id": "96217", "Score": "2", "body": "What language are we talking about? Most languages have libraries for validating emails, and also, regex implementation differs between languages." }, { "ContentLicense": ...
[ { "body": "<p>I remember having read somewhere (possibly in another Code Review answer) that for an e-mail address, the simplest and most effective validation you can do is to make sure it contains an <code>@</code>. Making it more restrictive than that can often be a risk of invalidating some valid e-mails. Yo...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T11:36:23.157", "Id": "55009", "Score": "14", "Tags": [ "c#", ".net", "regex", "validation", "email" ], "Title": "Regex validation for Email Address" }
55009
<p>The simplest introduction to this code is to play it! Here's an <a href="http://sqlfiddle.com/#!12/25950/1">SQL Fiddle</a>. However, to enjoy it fully, you'll need a more interactive environment, like the <code>psql</code> command prompt. If you don't have PostgreSQL installed already, this may be the killer app ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-05-16T13:17:52.160", "Id": "374274", "Score": "1", "body": "I just wanna say this is amazing" } ]
[ { "body": "<p>In general, I have to say: \"fascinating\". I'm not the best SQL coder out there, but I'm pretty good at games, so I'm going to dare respond to at least one of your questions.</p>\n\n<p>You asked about scaling some of the heuristics. One thing I did not see in your code is a move tree. With 3x3...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T12:37:11.290", "Id": "55014", "Score": "15", "Tags": [ "game", "sql", "ai", "postgresql", "tic-tac-toe" ], "Title": "Tic-tac-toe in SQL with optimal AI" }
55014
<p>I've tried to refactor my program to single return statement at the end of the program, however, it ruins the end statements of the recursion because I want to return from function in specific line and not in the end of the function.</p> <p>I'd like suggestions on how this code can work and be elegantly designed to...
[]
[ { "body": "<p>Simplification time!</p>\n\n<pre><code>if(pal.charAt(0) == pal.charAt(1))\n{\n return true;\n}\nreturn false;\n</code></pre>\n\n<p>Can become:</p>\n\n<pre><code>return pal.charAt(0) == pal.charAt(1);\n</code></pre>\n\n<hr>\n\n<pre><code>if(pal.charAt(0) == pal.charAt(pal.length()-1))\n{\n re...
{ "AcceptedAnswerId": "55019", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T12:54:12.923", "Id": "55015", "Score": "10", "Tags": [ "java", "recursion", "palindrome" ], "Title": "Recursive implementation of palindrome string checker" }
55015
<p>I'm working on a game in C#, this game generate new chunk (infinite) when you move around. If I have > 1000 chunks in my list then it become laggy even though I only load the necessary chunks on my screen. Tried all things to improve the code but it did not improve.</p> <pre><code>Stopwatch ChunkDetect = new Stopwa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T13:40:03.643", "Id": "96254", "Score": "3", "body": "Welcome to Code Review! Can you please add the declaration of `allChunks` to your code? Can you also explain a bit about the purpose of your `gameBox` variable?" }, { "Con...
[ { "body": "<p>Your <code>allChunks</code> is a List. The Linq query to get the chunk with the right coordinates is going to scan the entire list, and check each chunk. This is a linear process, and the performance depends on the number of chunks in the list. As the list grows, the performance decreases.</p>\n\n...
{ "AcceptedAnswerId": "55029", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T13:27:54.133", "Id": "55020", "Score": "10", "Tags": [ "c#", "performance" ], "Title": "Chunk Generation Performance in C#" }
55020
<p>This isn't really much of an actual project, just something I threw together in about 5-10 minutes. I just want to know if it goes with the current Python standards, and if anything should be changed or fixed.</p> <pre><code>print(''.join([__import__('random').choice(['\033[7;1;32m \033[0m','\033[7;32m \033[0m','...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:09:43.227", "Id": "96272", "Score": "3", "body": "Is it a requirement that it is a one-liner (code-wise, not output-wise), and if so, why?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:11:22.7...
[ { "body": "<p>Of course, you’re violating the <a href=\"http://legacy.python.org/dev/peps/pep-0008/#maximum-line-length\">79 characters-per-line limit as per PEP 8</a>, but I guess you know that and thats hard to avoid when you want to stay on one line.</p>\n\n<ul>\n<li><p>You can save some characters and some ...
{ "AcceptedAnswerId": "55032", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T14:58:42.010", "Id": "55027", "Score": "4", "Tags": [ "python", "python-2.x" ], "Title": "Does this one-line text-based terrain generator go against standards?" }
55027
<pre><code>class AcmeFactory { public static function anvil() { $crud = new Crud; $productTypes = new ProductTypes($crud); $productImages = new ProductImages($crud); $product = new Anvils ($crud, $productImages); $productManager = new ProductManager ($productTypes...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:30:45.413", "Id": "96290", "Score": "0", "body": "why the new keyword? You can just do AcmeFactory::anvil();" } ]
[ { "body": "<p>Rather than doing it that way (separate methods for separate configurations) you should pass in the \"configuration\" to a single method and let that one handle it.</p>\n\n<pre><code>class AcmeFactory\n{\n public static function create($config)\n {\n $crud = new Crud;\n ...
{ "AcceptedAnswerId": "55034", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:05:06.720", "Id": "55030", "Score": "6", "Tags": [ "php", "factory-method" ], "Title": "Is this a fair use for a factory pattern?" }
55030
<p>I have this function that works fine, but it looks really ugly and repetitive...</p> <p>Basically I have a featured profile and underneath I have 4 smaller thumbnails, on click I want to populate the large profile. The code works fine it just doesn't look too good...</p> <pre><code>$('ul.teamProfiles li').click(fu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T16:59:25.163", "Id": "96339", "Score": "0", "body": "I don't like the `a.linkedinLink` etc. selectors. A rule in CSS is to use specificity so removing the target element type would be the first thing I do; i.e. `.linkedin-link`" }...
[ { "body": "<p>It's difficult to <em>really</em> clean it up, since a lot of it is \"manual\" translation from one piece of markup to another. Different elements, different attributes etc.</p>\n\n<p>However, there's the low-hanging fruit (and golden rule): Don't repeat yourself.</p>\n\n<p>So don't call <code>$(t...
{ "AcceptedAnswerId": "55045", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:30:26.677", "Id": "55033", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Better way to write 'bulky' function in jQuery" }
55033
<p>Is it a good practice to initialize the max to -100000 and min to 100000? Is there any other way to initialize both min and max to 0?</p> <pre><code> import javax.swing.*; import java.util.*; public class arrayTajba { public static void main(String[] args) throws Exception { String userStringIn...
[]
[ { "body": "<p>Java has a couple of constants available that are commonly used in situations like this:</p>\n\n<pre><code> int max = Integer.MIN_VALUE;\n int min = Integer.MAX_VALUE;\n</code></pre>\n\n<p>Using these two values ensures you cover the possible spectrum of valid input values.</p>\n\n<p>In addi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:43:55.860", "Id": "55035", "Score": "8", "Tags": [ "java", "array" ], "Title": "Min and Max initialization" }
55035
<p>Last time I made a website using PHP, I didn't know of PDO, so someone dropped all my tables. I think I've made an improvement now. I'm sorry if there's a lot to go through, but I want to make sure its <strong>safe</strong> <em>(most importantly)</em> and also using the <strong>best practices</strong>.</p> <p>Here ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:54:19.690", "Id": "96311", "Score": "1", "body": "Please post *all* of your code here. \"Some snippets\" are not enough for review." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:55:39.920", ...
[ { "body": "<p>Okay</p>\n\n<h2>All of them</h2>\n\n<ul>\n<li>Don't have multiple statements on the same line like that.</li>\n<li>Use either spaces or tabs, don't use both.</li>\n<li><code>&lt;?php something; ?&gt; &lt;?php somethingElse; ?&gt;</code> is pointless. Don't do that.</li>\n<li>Be consistent. Sometim...
{ "AcceptedAnswerId": "55112", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:51:09.943", "Id": "55037", "Score": "1", "Tags": [ "php", "security", "pdo" ], "Title": "Security of code snippets" }
55037
<p>I am newish to Python and I am looking for some extra eyes on a script I wrote. I wrote this script to learn more about web-scraping and using requests and Beautiful Soup. I use it to connect to the website wallbase.cc and save the top 32 wallpapers from the last 3 days into a directory where I later cycle through d...
[]
[ { "body": "<p>Your code is nice, well documented, properly formatted and easy to understand so I won't have to much to say.</p>\n\n<ul>\n<li>You can have a read at <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a> as your code is not exactly perfect for details like spacing (you...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T15:57:11.770", "Id": "55038", "Score": "4", "Tags": [ "python", "beginner", "python-3.x", "beautifulsoup" ], "Title": "Script for saving top wallpapers from wallbase.cc into a...
55038
<p>Interview question from the interwebz</p> <blockquote> <p><em>You have a set of envelopes of different widths and heights. One envelope can fit into another if and only if both the width and height of one envelope is greater than the width and height of the other envelope. What is the maximum number of env...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T17:02:47.833", "Id": "96340", "Score": "0", "body": "`envelopes.sort()` looks out-of-place.... should that be `enve.sort()`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-24T05:41:01.087", "Id": "9...
[ { "body": "<p>Using <a href=\"http://en.wikipedia.org/wiki/Longest_increasing_subsequence\" rel=\"nofollow\">LIS from Wikipedia</a>.</p>\n\n<pre><code>def max_russian_doll(seq):\n if not seq: return 0\n seq.sort()\n M = [0] * (len(seq) + 1)\n L = 1\n for i in xrange(len(seq)):\n lo = 1\n ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-23T16:42:05.907", "Id": "55044", "Score": "6", "Tags": [ "python", "optimization", "interview-questions", "complexity" ], "Title": "Russian doll envelops" }
55044