body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
VHDL (Very High Speed Integrated Circuit HDL) is a hardware description language (HDL) maintained by the 'VHDL Analysis and Standardization Group (VASG) and standardized as 'IEEE Standard 1076'.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T08:54:32.220", "Id": "28811", "Score": "0", "Tags": null, "Title": null }
28811
<p>Searching is one of the most common and important tasks in Computer Science.</p> <p>The most basic search algorithm is a linear search (also called "sequential search"). Each item in a collection of data is examined in sequence until the sought item is found.</p> <p>If the collection in question has already been ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T08:58:22.177", "Id": "28813", "Score": "0", "Tags": null, "Title": null }
28813
This tag is for questions about search algorithms, tools, and technologies.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T08:58:22.177", "Id": "28814", "Score": "0", "Tags": null, "Title": null }
28814
<p>From the <a href="http://www.numpy.org/" rel="nofollow">NumPy homepage</a>:</p> <p>NumPy is the fundamental package for scientific computing with Python. It contains among other things:</p> <ul> <li>A powerful N-dimensional array object.</li> <li>Sophisticated (broadcasting) functions.</li> <li>Tools for integrati...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T09:02:10.753", "Id": "28815", "Score": "0", "Tags": null, "Title": null }
28815
NumPy is the fundamental package for scientific computing with the programming language Python.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T09:02:10.753", "Id": "28816", "Score": "0", "Tags": null, "Title": null }
28816
<p>A dictionary is commonly implemented as a <a href="http://en.wikipedia.org/wiki/Hash_table" rel="nofollow">hash map</a> which allow <code>O(1)</code> amortized lookup. Alternatively they may be implemented as a sorted list, with lookup requiring a binary search and making the lookup <code>O(log N)</code> amortized i...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T09:06:06.647", "Id": "28817", "Score": "0", "Tags": null, "Title": null }
28817
A dictionary, in computer science, is a data structure that maps keys to values such that given a key its corresponding value can be efficiently retrieved.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T09:06:06.647", "Id": "28818", "Score": "0", "Tags": null, "Title": null }
28818
<p><strong>Arduino</strong> is a single-board microcontroller to make using electronics in multidisciplinary projects more accessible. </p> <p>The hardware consists of an open-source hardware board designed around an 8-bit Atmel AVR microcontroller, or a 32-bit Atmel ARM. </p> <p>The software consists of a standard p...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T09:07:51.467", "Id": "28819", "Score": "0", "Tags": null, "Title": null }
28819
Arduino is an open-source electronics prototyping platform.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T09:07:51.467", "Id": "28820", "Score": "0", "Tags": null, "Title": null }
28820
<p>I'm currently working through a series of bugs in an application. Our application is written in C#/ASP.NET (on the server) and HTML/CSS/JavaScript (on the client). We are using ELMAH to log any uncaught exceptions in the system so that we may identify it later and fix it, which is what I'm currently doing.</p> <p>T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T13:40:37.247", "Id": "45319", "Score": "0", "body": "Interesting - you seem to have independently re-invented the [error monad](http://www.haskell.org/haskellwiki/Exception#Exception_monad) - well done sir!" }, { "ContentLic...
[ { "body": "<p>I think that you are setting yourself up for horrible spaghetti code down the line if you don't catch and throw exceptions like the Lord intended.</p>\n\n<p>If you absolutely INSIST on returning an error, I would suggest adding two OUT parameters to the methods:</p>\n\n<pre><code>string myFunkyFun...
{ "AcceptedAnswerId": "28827", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T11:03:33.670", "Id": "28824", "Score": "4", "Tags": [ "c#", "object-oriented", ".net", "asp.net", "error-handling" ], "Title": "OOP methods/functions that can return a ...
28824
<p>Here is some code I've created to generate and use a list of prime numbers. This is some of the first Common Lisp code I've written, and I'd be grateful for any comments regarding style and its use or misuse of common idioms. I'm not really interested in improving the algorithm, but in making my implementation rea...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-10-09T04:52:15.840", "Id": "196241", "Score": "0", "body": "Good, but I'm not understanding since you have used very heavy language. It will be easier if you use simple language which can be understood by common people." } ]
[ { "body": "<p>for one thing, <code>(eq nil p)</code> is usually written <code>(not p)</code>. </p>\n\n<p>the variable <code>p</code> participating only in that <code>do</code> should be declared inside it, not outside it in the enclosing <code>let</code>. Everything should be in its proper place. Same with <cod...
{ "AcceptedAnswerId": "28840", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T12:46:47.657", "Id": "28826", "Score": "6", "Tags": [ "primes", "common-lisp" ], "Title": "Generating and using a list of prime numbers" }
28826
<p>I'm writing a C++ wrapper library for sockets which will hopefully be cross-platform.</p> <p>It's basically two headers:</p> <ul> <li>mizaru.hpp, which contains the wrapper classes themselves.</li> <li>trans_layer.hpp, which provides platform agnostic function prototypes. So far they only support Linux and TCP soc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T14:29:30.863", "Id": "45324", "Score": "2", "body": "I removed the licence notifications, as they are just clutter for this site. Note that by posting content you are releasing it under [cc-by-sa](http://blog.stackoverflow.com/2009/...
[ { "body": "<p>I don't have time to give any meaningful feedback about your design at the moment. I'll give some general feedback and try to answer your question about your error handling, however.</p>\n\n<h3>General feedback</h3>\n\n<ul>\n<li>Herb Sutter has <a href=\"http://www.gotw.ca/publications/mill22.htm\...
{ "AcceptedAnswerId": "28862", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T13:43:24.023", "Id": "28829", "Score": "2", "Tags": [ "c++", "error-handling", "linux", "library", "socket" ], "Title": "Wrapper library for sockets" }
28829
<p>I've created a simple jQuery plugin to allow developers to quickly create image hover effects with very simple markup. I also created an option to automatically create the mouseover or mouseout versions of the image via TimThumb.</p> <p><a href="http://concept211.github.io/hovr/" rel="nofollow noreferrer">Here is a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-30T22:16:14.673", "Id": "46086", "Score": "0", "body": "Simple to implement but essential - cache your `$(this)` selector. `var $this = $(this);`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-01T05:45:14....
[ { "body": "<p>As a rule of thumb, when you use a jQuery selection more than once, you should cache its value. When you do <code>$(\".someElement\")</code>, jQuery now has to go find that element in the DOM, wrap it in the jQuery object and return it. If you save what it returns, then you only do the search once...
{ "AcceptedAnswerId": "31167", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T14:40:19.683", "Id": "28832", "Score": "3", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "Allowing developers to quickly create image hover effects" }
28832
<p>I have these if-else statements that I am not able to refactor. I have used them for doing validations on server-side using asp.net.</p> <p>Would anyone please suggest ways to reduce these statements? Here, validation fields and validation types are <code>enum</code> lists.</p> <pre><code>else if (CheckNextItem(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T15:52:11.087", "Id": "45339", "Score": "0", "body": "Am I correct in assuming that each bracket 1 ID has only one valid bracket 2 ID? So, for instance, when ID 1 is \"FO\", then ID 2 must be \"P\"?" }, { "ContentLicense": "...
[ { "body": "<p>If each ID1 can only have one valid corresponding ID2, then I would recommend using a dictionary object to store the valid combinations, like this:</p>\n\n<pre><code>Dictionary&lt;string, string&gt; validIds = new Dictionary&lt;string,string&gt;();\nvalidIds[ValidationFields.FO.ToString()] = Vali...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T15:31:28.130", "Id": "28838", "Score": "1", "Tags": [ "c#", "asp.net" ], "Title": "How can I make only one if-else statement among all of these?" }
28838
<p>I have four methods like these (here are only two of them): </p> <pre><code> def checkLeft(clickedIndex: Int): Option[Int] = { val leftIndex = clickedIndex - 1 if (leftIndex &gt;= 0 &amp;&amp; clickedIndex % field.width != 0 &amp;&amp; isEmptyCell(leftIndex)) Some(leftIndex) else None } ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T16:44:41.543", "Id": "45345", "Score": "0", "body": "Does `bottomIndex` depend on `clickedIndex`? And what `something1` depends on?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T16:49:14.343", "...
[ { "body": "<p>For the LEFT case, you're checking that an index is above the low value of zero; for the RIGHT case, you're checking that it's below the high value of field.size. You can't really reconcile these except by combining them into a method that checks both boundaries - and there's nothing wrong with t...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T16:24:04.187", "Id": "28842", "Score": "4", "Tags": [ "scala" ], "Title": "Refactor to reduce code duplication" }
28842
<p>I went through lots of tutorial, and almost all of them were quite long, so I came up with my own code:</p> <pre><code> $page = $_GET['page']; $pg_count = $page-1; if ($page == 1) { $start = 0; } else { $start = $pg_count*15; } $limit = $page*15; $query = 'SELECT * FROM table LIMIT '.$st...
[]
[ { "body": "<p>This is a pagination code that I used in one of my old applications. You should change the mysql_ functions to pdo/mysqli here. This is based on a simple table with id, name fields. Change the queries according to your logic.</p>\n\n<pre><code>if (isset($_GET['page'])){\n $page = $_GET['page'];...
{ "AcceptedAnswerId": "28848", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T19:19:28.400", "Id": "28847", "Score": "1", "Tags": [ "php", "pagination" ], "Title": "Pagination Review" }
28847
<p>I have a question that may be easily answered, but the answer evades me. In regards to numeric operations, how come when I code this:</p> <pre><code>double celsius = 30; double fahrenheit = (celsius + 32.0) / (5/9); </code></pre> <p>I get an answer:</p> <pre><code>fahrenheit = infinity; </code></pre> <p>But, wh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T11:06:31.170", "Id": "45383", "Score": "0", "body": "This site is for reviewing working code to make it better. If you don't understand why your code does what it does, you should try to debug it (hint: what is the result of `5/9`?)...
[ { "body": "<p>Division by zero gets you infinity.</p>\n\n<p>Note that (5/9) is an int expression, and resolves to int 0!</p>\n\n<p>To fix things, make your literals doubles : </p>\n\n<pre><code>double celsius = 30d;\ndouble fahrenheit = (celsius + 32.0d) / (5d/9d);\n</code></pre>\n", "comments": [], "me...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T04:21:44.163", "Id": "28860", "Score": "0", "Tags": [ "java" ], "Title": "Simple Question about Numeric Operations" }
28860
<p>I am looking for feedback on a solution to the following problem posed from a book that I'm working through (<em>Java: How To Program</em>, 9<sup>th</sup> Edition):</p> <blockquote> <p>Write an application that reads a five-letter word from the user and produces every possible three-letter string that can be deri...
[]
[ { "body": "<p>Your program can be simplified to something like this:</p>\n\n<pre><code>System.out.println(\"Please enter a five letter word\"); \nScanner sc = new Scanner(System.in);\nString input = sc.nextLine();\n\nfor (int i = 0; i &lt; input.length(); i++) { // pos. of 1st letter\n for (int j...
{ "AcceptedAnswerId": "28868", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T08:24:55.163", "Id": "28864", "Score": "3", "Tags": [ "java", "beginner", "strings" ], "Title": "Generating three-letter strings from five-letter words" }
28864
<p>The 'Do' method is for prepared statements and returns (by fetchall()). I am also using two looping statements. Is there any better way to fetch two tables in one statement or query? If not, what can I do to improve this code?</p> <pre><code>// 'id' is index in 'userinfo' table and 'id' in 'election' table is a ...
[]
[ { "body": "<p><strong>SQL:</strong></p>\n\n<p>This is just a simple <a href=\"http://en.wikipedia.org/wiki/Join_%28SQL%29\" rel=\"nofollow\">join</a>.</p>\n\n<pre><code>SELECT e.Votes, e.Views, e.id, u.username \nFROM election as e, userinfo as u \nWHERE e.id= u.id WHERE e.ElectionId=? \nORDER BY e.id ASC\n</co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T08:50:59.977", "Id": "28866", "Score": "1", "Tags": [ "php", "object-oriented", "mysql", "array" ], "Title": "Is there any better way to fetch two tables in one statement or q...
28866
<p>The file is quite long, 1000 LOC so I want to separate it into smaller files.</p> <p><a href="https://github.com/anvoz/world-js/blob/v1.0/js/world.core.js" rel="nofollow">https://github.com/anvoz/world-js/blob/v1.0/js/world.core.js</a></p> <p>Here is a brief version of the code:</p> <pre><code>(function(window, u...
[]
[ { "body": "<p>I don't see the advantage of adding <code>Seed</code> and <code>Knowledge</code> into the prototype of <code>World</code> (unless you've got more code to tell me otherwise). If you don't need anything from the instance at all, then you don't need them in the instance. You can put them like <code>s...
{ "AcceptedAnswerId": "28878", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T10:12:33.870", "Id": "28870", "Score": "1", "Tags": [ "javascript" ], "Title": "Separate a module into smaller parts" }
28870
<p>I've solved <a href="http://projecteuler.net/problem=28" rel="nofollow">Project Euler #28</a> using recursion.</p> <blockquote> <p>If this 5 × 5 spiral pattern is extended to 1001 × 1001, what would be the sum of the red diagonals?</p> <p>$$\begin{matrix} \color{red}{21} &amp; 22 &amp; 23 &amp; 24 &amp; \col...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T14:08:52.953", "Id": "45394", "Score": "5", "body": "Where did you find it? Or do you mean that you wrote it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T06:18:34.740", "Id": "45453", "Sco...
[ { "body": "<p>Performance is okay (linear), but I think the code can be simplified by using a loop instead of recursion, and by going from the inside-out instead of from the outside-in.</p>\n\n<p>Here's how I did it, in pseudo-code:</p>\n\n<pre><code>sum = 1 # running sum\nlast = 1 # last number\ndelta = 2 #...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T12:11:23.673", "Id": "28873", "Score": "2", "Tags": [ "c#", "performance", "programming-challenge", "recursion" ], "Title": "Project Euler 28: sum of spiral diagonals using re...
28873
<p>I've got relation in my database as following :</p> <pre><code>Customer has many Orders Order has many Parts Order has many Upc </code></pre> <p>So my requirement is to copy all orders from one customer and <code>attach</code> or copy those orders (with their dependencies including parts and upcs) to another custo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-01T02:08:28.923", "Id": "46190", "Score": "0", "body": "Wouldn't it be better to simply point the second customer to the same order, rather than introducing duplication and a deep copy? Or do you want the orders to be updated independe...
[ { "body": "<p>The #dups are probably unnecessary. If you unset the ID ActiveRecord already \"thinks\" that the object is new, and #save will create a new one in the DB. But the main bottleneck is probably the amount of DB queries generated. The easiest way to gain some performance in such cases is to wrap the w...
{ "AcceptedAnswerId": "30423", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T13:38:15.047", "Id": "28879", "Score": "1", "Tags": [ "ruby", "performance" ], "Title": "Ruby on rails with active record perfomance" }
28879
<p>I wrote a small script to manipulate fields of a file based on the input of a user. Is there something I could've done better, or perhaps a better refactor? I do know however that I need a way to validate for empty fields.</p> <pre><code>view_column() { for i in "$file_name"; do cat "$i" | awk -v col="$1" '{ ...
[]
[ { "body": "<p>That's very elegant looking code. bash has a builtin <code>select</code> statement to present a menu to the user and get a response -- \nthe advantage of <code>select</code> is that the user is locked into it until a valid response is obtained. Plus, it seems that printing the menu and reading the...
{ "AcceptedAnswerId": "28945", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T14:01:58.577", "Id": "28880", "Score": "4", "Tags": [ "bash", "linux", "shell", "awk" ], "Title": "Input Columns with Awk" }
28880
<p>I am so sick of WYSIWYG editors being exclusively for the latest browser or being huge with every option under the sun. I tried to make my own, using code I found online as well as a little of my own handy work.</p> <p>This is what I came up with:</p> <p><a href="http://jsfiddle.net/spadez/RRBHw/1/" rel="nofollow"...
[]
[ { "body": "<p>Just three quick notes about clean code, not a complete review:</p>\n\n<ol>\n<li><p>You could extract out some functions which would make some comments unnecessary, like:</p>\n\n<pre><code>// IE selections\n// Mozilla selections\n</code></pre>\n\n<p>Just create functions for them, like <code>ieSel...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T15:25:13.227", "Id": "28882", "Score": "4", "Tags": [ "javascript", "jquery", "html", "text-editor" ], "Title": "Custom WYSIWYG Editor" }
28882
<p>I've taught myself some basic HTML/CSS over the past few weeks and just finished up my first horizontally scrolling single page site last night. I went for a clean minimal design and achieved the look I was going for, but am absolutely sure I did some things the hard way. Would really appreciate any advice on how I ...
[]
[ { "body": "<p>You've tried to declare both a <code>html</code> and a <code>head</code> element twice:</p>\n\n<pre><code>&lt;!DOCTYPE html&gt;&lt;html lang=\"en\"&gt;&lt;head&gt;&lt;meta charset=\"utf-8\"&gt;\n&lt;html&gt;\n &lt;head&gt;\n &lt;title&gt;stan's page&lt;/title&gt;\n ...\n</code></p...
{ "AcceptedAnswerId": "28894", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T16:54:44.703", "Id": "28887", "Score": "4", "Tags": [ "optimization", "html", "css" ], "Title": "Review on efficiency and correctness appreciated for my first single-page websi...
28887
<p>I have a <code>byte</code> array and a <code>List</code> of a custom object <code>ByteRule</code> and I'm needing to loop around and perform an operation on both but only as long as one of both is available, the original method is as follows:</p> <pre><code>private final List&lt;ByteRule&gt; rules; @Override publi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T06:36:00.977", "Id": "45454", "Score": "0", "body": "*Obviously the `this.rules.get(i)` on every iteration is inefficient* That is not obvious to me at all." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-0...
[ { "body": "<p>I would be happy with:</p>\n\n<pre><code>@Override\npublic boolean match(final InetAddress inetAddress)\n{\n final byte[] bytes = inetAddress.getAddress();\n int end = Math.min(this.rules.size(), bytes.length);\n for(int i = 0; i &lt; end; i++)\n {\n final int adressPart = bytes...
{ "AcceptedAnswerId": "28940", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T18:50:53.097", "Id": "28891", "Score": "1", "Tags": [ "java" ], "Title": "Iterating over an Array and an Iterable (List)" }
28891
<p>Can the metafunction below be implemented more elegantly, with less code? What I have now is not very elegant or smartly written.</p> <pre><code>#include &lt;type_traits&gt; namespace detail { template &lt;typename T, typename A, typename ...B&gt; struct max_type { typedef typename max_type&lt; typename std...
[]
[ { "body": "<p>How about this? It’s not all that much shorter, but IMHO quite a bit simpler:</p>\n\n<pre><code>#include &lt;type_traits&gt;\n\ntemplate &lt;typename A, typename... B&gt;\nstruct max_type\n{\n typedef typename max_type&lt;A, typename max_type&lt;B...&gt;::type&gt;::type type;\n};\n\ntemplate &l...
{ "AcceptedAnswerId": "28903", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T19:05:09.800", "Id": "28892", "Score": "4", "Tags": [ "c++", "c++11" ], "Title": "metafunction to determinate the biggest of all supplied types" }
28892
<p>To summarize from a previous question, the user selected a starting date, an ending date, and a region. From these choices, an array of weeks and regions are created, and users enter values ("points") that correspond to a particular week and region. This is what it looks like right now (some parts are hard-coded for...
[]
[ { "body": "<p>Try this:</p>\n\n<pre><code>&lt;?php\nif(isset($_POST['submit'])){\n foreach ($_POST as $k=&gt;$v){\n // use even and odd count to differentiate TRP and CPP\n if ($k != \"submit\") {\n // split the form input on _\n $input = explode(\"_\", $k);\n e...
{ "AcceptedAnswerId": "28895", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T19:07:07.250", "Id": "28893", "Score": "2", "Tags": [ "php", "html", "sql", "form" ], "Title": "Multiple input fields from PHP table" }
28893
<p>This code handles a response from an RSS feed. It organizes and appends to content. If there's a video embeded then separate it from the rest of the content. I would like a review mainly on performance/efficiency but I'm open to any other suggestions as well. That star selector is really nagging me but I don't know ...
[]
[ { "body": "<p>Late reply,</p>\n\n<p>this code is good, I can only find 2 faults:</p>\n\n<ol>\n<li><p>Your code should have error handling for the JSON call, things can go wrong</p></li>\n<li><p>Too much horizontal stretching, I would introduce some sugar for this:</p>\n\n<pre><code>for (var i = 0; i &lt; respon...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T19:53:04.577", "Id": "28896", "Score": "4", "Tags": [ "javascript", "jquery", "optimization", "ajax" ], "Title": "Improve AJAX response handling function" }
28896
<p>I'm developing a class to compare prices. For example, give me products which price are above 50 or under 50. Here's my API:</p> <pre><code>var indicator = new PriceIndicator(PriceComparison.Above, 50); var actual = indicator.Apply(listOfProductPrices); </code></pre> <p>I managed to design my code for the operat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T23:20:22.283", "Id": "45445", "Score": "0", "body": "Your code won't compile, there is no `Close` property on `int`. You should post (parts of) your real code, not something you didn't even bother compiling." }, { "ContentLi...
[ { "body": "<p>Here you go. I made <code>Range</code> inclusive only, but it's easy to modify. I also extracted a few interfaces for easy unit testing and use <code>IEnumerable&lt;T&gt;</code> instead of <code>IList&lt;T&gt;</code>.</p>\n\n<pre><code>public interface IPriceComparison\n{\n bool Evaluate(decima...
{ "AcceptedAnswerId": "28998", "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T20:12:06.417", "Id": "28897", "Score": "1", "Tags": [ "c#", "object-oriented" ], "Title": "Comparison with a range" }
28897
<p>I am given the following CSV file which I extracted from an excel spreadsheet. Just to give some background information which could be of assistance, it discusses AGI Numbers (think of it as protein identifiers), unmodified peptide sequences for those protein identifiers, and then modified peptide sequences with mod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T23:24:04.467", "Id": "45447", "Score": "2", "body": "“If anyone has a better solution in another language” That's not what this site is for. This site is specifically for reviewing code you have written (so the “If anyone can analyz...
[ { "body": "<p>I'd say in general I think you have the right idea.<br>\nHowever I'm stuck on:</p>\n\n<pre><code>cur.data.peptides.push({\n \"sequence\" : row[1];\n \"mod_sequence\" : row[2];\n if(row[5]){\n \"mod_indeces\" : \"[\" + row[3] + \", \" + row[4] + \"]\";\n \"spectral_count\" : row[5]; ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T21:44:32.157", "Id": "28899", "Score": "2", "Tags": [ "javascript" ], "Title": "Parsing through CSV file to convert to JSON format file" }
28899
<p>Other code review noted problems with commenting and non-C++ code. This post aims to follow up on those issues.</p> <p>Please check:</p> <ol> <li>Comments are appropriate</li> <li>Code is not C</li> </ol> <p>My test file contains:</p> <blockquote> <p>one two three four five six seven eight nine</p> </blockquot...
[]
[ { "body": "<p><strong>Comments:</strong></p>\n\n<ul>\n<li><p><em>The top comment block is good</em>. When writing a program, describing it at the top will tell the reader what it is expected to do output.</p></li>\n<li><p><em>Too much whitespace within some blocks</em>. Some of your comment text are too sprea...
{ "AcceptedAnswerId": "28934", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T21:47:41.537", "Id": "28900", "Score": "6", "Tags": [ "c++", "c++11", "file" ], "Title": "Printing certain number of words from file" }
28900
<p>I have this action and it works but looks rather clunky to me. Is there any way I could improve that?</p> <pre><code>transMit :: Serialize a =&gt; Socket -&gt; POSIXTime -&gt; KEY -&gt; a -&gt; TPSQ -&gt; TMap a -&gt; IO () transMit s time key newmsgs q m = do loopAction &lt;- atomically $ do ...
[]
[ { "body": "<p>I'm not familiar with the libraries and types you're using here, but I see a few general Haskell things:</p>\n\n<ol>\n<li><p>Instead of <code>loopAction &lt;- atomically $ ...; loopAction</code>, you can use <code>join $ atomically $ ...</code>. This removes the need for the entire outer <code>do<...
{ "AcceptedAnswerId": "28928", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-07-23T22:04:48.940", "Id": "28901", "Score": "1", "Tags": [ "haskell", "queue", "socket", "serialization" ], "Title": "Action to transmit queued messages over a socket" }
28901
<p>This is my Clojure code for finding prime numbers.</p> <p>Note: this is an advanced version which starts eliminating from <code>i*i</code> with step <code>i</code>, instead of filtering all list against <code>mod i == 0</code> <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="nofollow">(Sieve of Era...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T07:15:41.310", "Id": "45599", "Score": "0", "body": "it will be `n log (log n)` only if `(assoc v (dec i) di)` is O(1)." } ]
[ { "body": "<p><em>(non-Clojure-specific)</em> Gain performance, sure. Use packed array of odds, where index <code>i</code> represents value <code>2i+1</code>. Then you don't have to deal with evens, which are all non-prime a priori (except the 2 of course). Then you can increment by <code>2*p</code> for a prime...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-23T22:38:22.627", "Id": "28902", "Score": "1", "Tags": [ "primes", "clojure" ], "Title": "Clojure code for finding prime numbers" }
28902
<p>I wrote a little <code>PHP</code> wrapper class for <code>GeoIP</code> which looks like:</p> <pre><code>&lt;?php class GeoIP { private $ip; private $geo_ip_details; function __construct($ip) { $this-&gt;ip = $ip; $this-&gt;fetch(); } private function fetch() { if(fil...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T16:36:43.380", "Id": "45537", "Score": "0", "body": "This violates encapsulation. See: http://www.javaworld.com/jw-05-2001/jw-0518-encapsulation.html" } ]
[ { "body": "<ul>\n<li><p>I'm not a fan of magic getters. Without <em>really</em> good documentation, they're just a pain for consumers of your code. For example, when I first looked at your code, I had no idea at all what properties the class exposes. I basically had to follow the cURL request to find out. Prope...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T05:16:02.800", "Id": "28904", "Score": "2", "Tags": [ "php", "object-oriented" ], "Title": "PHP review of object oriented GeoIP class" }
28904
<p>I have a <code>float</code> in the <code>String strFloat</code>. I wanted to convert it to a rounded integer also stored in a <code>String</code>. This looks awful to me, so please offer some suggestions for improvement.</p> <pre><code>String strInteger = new Integer(Float.valueOf(strFloat).intValue()).toString()...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T04:55:47.157", "Id": "45590", "Score": "0", "body": "Could you please clarify where the float comes from and what is stored in this variable." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T07:07:59.3...
[ { "body": "<p>Instead of creating a new <code>Integer</code> and throwing it away, use <code>String.valueOf()</code> directly.</p>\n\n<pre><code>String strInteger = String.valueOf(Float.valueOf(strFloat).intValue())\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T07:33:45.427", "Id": "28908", "Score": "2", "Tags": [ "java", "converting", "integer", "floating-point" ], "Title": "Float string to integer string" }
28908
<p>I have written a shell script to process my huge data files (each one having around 7,000,000 lines ~ a weeks data in a single file).</p> <p>Here is a sample of my data file (i.e., input file) structure:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>808 836 204 325 148 983 908 836 203 326 14...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-18T09:56:24.283", "Id": "45463", "Score": "4", "body": "Sorry but shell script isn't the right tool if you want to get performance. You'll end up spending your time forking to call command like ``awk`` ``sed``. Try out a real programmi...
[ { "body": "<p>The details of your question are entirely unclear to me. I have understood, however, that you have a huge input file which you need to parse and translate into some output. The input is so large that it becomes important to do the parsing and translation in an efficient way.</p>\n\n<p>As you have ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-18T09:49:27.873", "Id": "28910", "Score": "2", "Tags": [ "csv", "linux", "shell", "geospatial" ], "Title": "Processing huge files of GPS data, extracting fields from five lines b...
28910
<p>I am writing simple code to accept/read a input of lines from a text file, split it into my class variables, sort them and finally display the input in the ordered form. But I have been struggling for the past couple of days to split the read line in appropriate manner.</p> <pre><code>static void Main(string[] args...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-19T07:51:48.603", "Id": "45473", "Score": "0", "body": "You probably have a problem in ` strFirst = Regex.Split(sr.ReadLine().Replace(\" \", \"\"), \"([0-9]+)\");\nstrFirst = Regex.Split(sr.ReadLine().Replace(\"|\", \">>\"), \"([0-9]+)...
[ { "body": "<p>Try this:</p>\n\n<pre><code>class Program\n{\n static void Main(string[] args)\n {\n //var input = File.ReadAllText(\"input.txt\");\n\n var input = \"5 string one | 5.2 string two | 5.2.1 string three\\r\\n\"+\n \"5 string four &gt;&gt; 5.6 string five &gt;&g...
{ "AcceptedAnswerId": "28915", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-19T07:46:37.290", "Id": "28914", "Score": "2", "Tags": [ "c#", "strings", "regex" ], "Title": "String compare, sort, regex split" }
28914
<p>I have a method to replace URL parameters in an URL. It receives url as mandatory parameter and prefix and/or hash as optional parameters. Examples:</p> <pre><code>url_replace( '/news?b=2', { b: nil } ) # =&gt; '/news' url_replace( '/news?b=2', { b: 3 } ) # =&gt; '/news?b=3...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T12:33:03.397", "Id": "45493", "Score": "0", "body": "out of curiosity: can you paste a URL that `URI.parse` does not like?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T12:40:46.157", "Id": "454...
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li><code>url_replace( '/news' )</code>: Each language has its formatting rules. In Ruby almost nobody inserts spaces after and before parens. </li>\n<li><code>hash = args.last.kind_of?(Hash) &amp;&amp; args.last</code>: I'd strongly discourage this kind of positional argu...
{ "AcceptedAnswerId": "28943", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T09:59:22.347", "Id": "28917", "Score": "3", "Tags": [ "ruby", "url" ], "Title": "Replace URL parameters with Ruby" }
28917
<p>I did a little function which is listening to hashchanges.</p> <p>What do you think about?</p> <pre><code>var onhashchange = function(code) { var checkHash = function(oldHash, code) { var hash = window.location.hash; var hashObject = hash.replace('#/','').split('/'); if (hash !== oldHa...
[]
[ { "body": "<p>First of and maybe a bit off-topic. The is this feature in all modern browsers now: <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/window.onhashchange\" rel=\"nofollow\">https://developer.mozilla.org/en-US/docs/Web/API/window.onhashchange</a> and the support is good: <a href=\"http://c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T10:11:52.233", "Id": "28919", "Score": "2", "Tags": [ "javascript" ], "Title": "Simple haschange event" }
28919
<p>Here's the situation: I've got several distinct objects, each with their own responsability and (therefore) each their own dependencies. As this is code that will be implemented in 2 existing applications, I've created my own namespaces, interfaces, abstract classes and so on... the works, basically.</p> <p>IMO, th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T12:55:29.700", "Id": "45500", "Score": "0", "body": "Please check [whats-wrong-with-overridable-method-calls-in-constructors](http://stackoverflow.com/questions/3404301/whats-wrong-with-overridable-method-calls-in-constructors) and ...
[ { "body": "<p>Ok, apparantly you are a professional programmer so let me look at your code first:</p>\n\n<p>the __construct in the class Granny:</p>\n\n<pre><code>public function __construct(array $vals = null)\n{\n foreach($vals as $name =&gt; $val)\n {\n $name = 'set'.ucfirst($name);\n if ...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T12:30:32.560", "Id": "28921", "Score": "4", "Tags": [ "php", "inheritance", "covariance" ], "Title": "\"fake\" covariance in PHP type-hinting" }
28921
<p>I'm currently working on a project that I had to create basically a running queue of items. My thought was to do this by a list, but surprisingly there weren't any methods to remove the first sequence or last sequence of items in a list that I found. I wrote the following class with extension methods for <code>List&...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T16:40:17.540", "Id": "45538", "Score": "2", "body": "Did you consider a queue (FIFO) or stack (LIFO) collection?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T17:39:39.290", "Id": "45543", "...
[ { "body": "<pre><code>if (list.Count &lt;= maxCount)\n{\n throw new InvalidOperationException(\"Items in list &lt;= maxCount, unable to trim list.\");\n}\n</code></pre>\n\n<p>This doesn't seem like an exceptional case to me. If the idea is to trim the list to a certain size and the list is already smaller th...
{ "AcceptedAnswerId": "28930", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T14:17:47.420", "Id": "28927", "Score": "1", "Tags": [ "c#", ".net", "collections", "extension-methods" ], "Title": "Extension Methods for Trimming List" }
28927
<p>Can anyone think of a way to DRY up this code or is there a way to make it more efficient or quicker. Its what authenticates a user with my API and i want to make it as fast as possible.</p> <pre><code>def authenticate! authenticate_or_request_with_http_basic do |access_key, secret_key| @current_app = App.fin...
[]
[ { "body": "<p>There is not much to say, just two notes:</p>\n\n<ul>\n<li><p>Common mistake of redundant boolean check: <code>some_boolean ? true : false</code> -> <code>some_boolean</code>. </p></li>\n<li><p>You can either use the bang find method or check the returned value, but not just use without a check.</...
{ "AcceptedAnswerId": "28931", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T14:59:27.180", "Id": "28929", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "active-record" ], "Title": "DRY Up Rails HTTP Basic Auth" }
28929
<blockquote> <p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.</p> <p>Find the sum of all the multiples of 3 or 5 below 1000.</p> </blockquote> <p>Can someone give me suggestions on how to improve this solution? Also, please ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T07:45:05.943", "Id": "52639", "Score": "1", "body": "A [similar question](http://codereview.stackexchange.com/q/31051/9357) has been asked later." } ]
[ { "body": "<ul>\n<li><p>Functions in C with no parameters should have a <code>void</code> parameter:</p>\n\n<pre><code>int main(void)\n</code></pre></li>\n<li><p>Variables should be declared/initialized on separate lines:</p>\n\n<pre><code>int a;\nint b;\nint c;\nint d;\nint sum3;\nint sum5;\nint sum15;\nint to...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T17:41:21.067", "Id": "28936", "Score": "3", "Tags": [ "c", "project-euler" ], "Title": "Project Euler #1 - Multiples of 3 and 5" }
28936
<p>What do you think about this variant class?</p> <p>Some hype: no RTTI needed, no heap allocation, supports copying.</p> <pre><code>#pragma once #ifndef VARIANT_HPP # define VARIANT_HPP #include &lt;cassert&gt; #include &lt;ostream&gt; #include &lt;type_traits&gt; #include &lt;typeinfo&gt; #include &lt;utility...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T04:41:04.670", "Id": "45588", "Score": "0", "body": "Quick comment: In your usage example, you should be able to write `v = std::string(\"AAAAAA\");` (without the `std::move`)." }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>I can think of one small improvement you can make.</p>\n\n<p>In the assignment operator (for both <code>variant</code> and <code>U</code> arguments), if the <code>typeid</code> of the argument is the same as <code>store_type_</code>, you can move the argument directly into store instead of deletin...
{ "AcceptedAnswerId": "28956", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T18:09:41.843", "Id": "28939", "Score": "6", "Tags": [ "c++", "c++11" ], "Title": "Movable and copyable variant" }
28939
<p>How can this be improved,to make it easier to maintain? There is so much boilerplate being thrown around, so is it possible to use annotations? I've seen one example from Stack Overflow, but it ended up using reflection in order to call the method.</p> <p>I was already planning on somehow annotating these "variable...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T07:14:10.450", "Id": "45598", "Score": "3", "body": "`event.getEvent().getPlayer().getWorld().getName()` Holy Demeter!:)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T10:18:33.860", "Id": "95323...
[ { "body": "<p>If you don't mind using a String switch, and can't use Java 8 yet (lambda expressions should greatly simplify your existing code), you could use something like the following (which replaces the use of inner classes with a single switch):</p>\n\n<pre><code>static {\n register(\"{worldname}\", \"...
{ "AcceptedAnswerId": "28960", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T19:02:34.750", "Id": "28942", "Score": "2", "Tags": [ "java", "performance", "parsing" ], "Title": "Towny chat formatter" }
28942
<p>The following is code I'm running to <code>FIRST</code>, <code>SECOND</code>, <code>THIRD</code> and so on until <code>SEVENTH</code> with a master query and a query of query.</p> <p>As it's clear that I'm using the master query for each of <code>FIRSTCONN</code>, <code>SECONDCONN</code> etc., I want to have only o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T15:33:38.597", "Id": "45621", "Score": "0", "body": "@Matt Busche I tested the dump of master query, it's not pulling up any details for SECONDCONN. That is I can only see three columns as of now, namely, timedetail, firstOccurances...
[ { "body": "<p>You could use a UNION to run one master query</p>\n\n<pre><code>&lt;cfquery datasource = \"XX.XX.X.XX\" name=\"master1\"&gt;\nSELECT DATE(Timedetail) as FIRSTCONN, COUNT(Timedetail) as FIRSTOccurances, EVENTS \nFROM MyDatabase\nWHERE EVENTS = \"FIRST\" \nGROUP BY FIRSTCONN\nUNION\nSELECT DATE(Tim...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T22:28:36.487", "Id": "28947", "Score": "2", "Tags": [ "sql", "mysql", "coldfusion", "cfml" ], "Title": "Running a master query and a query of queries" }
28947
<p>This is the first code of this type that I've attempted, so I'm wondering if anybody would be willing to critique it. It's "sort of" (I think) a factory class. I want to keep it as simple as possible (and still work, and be at least as elegant as Phyllis Diller - it doesn't have to be Elizabeth Taylor).</p> <p>The ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T12:22:12.367", "Id": "45603", "Score": "0", "body": "Interfaces cannot contain private fields (e.g. `private List<string> printerSetupCmds;`). The line `class IBeltPrinter BeltPrinter()` is also invalid syntax. These errors in you...
[ { "body": "<p>First off, I have to say this is a very clean and efficient design.</p>\n\n<p>I'm hoping <code>class IBeltPrinter BeltPrinter()</code> is a typo, because I've never seen C# code like that.</p>\n\n<p>Variable names for local variables (and parameters) should start with a lower case letter.</p>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T23:12:28.207", "Id": "28948", "Score": "3", "Tags": [ "c#", ".net", "factory-method" ], "Title": "RFC on \"Factory\" code" }
28948
<p>I am trying to write a function, where given a sorted array, and a number, it returns the FIRST index of that number.</p> <p>Is this correct? Code is in Ruby, but even if you don't know Ruby, you can pretty much understand the syntax.</p> <pre><code>def first(array, n) if(array.size == 0) return...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T04:32:27.300", "Id": "45585", "Score": "2", "body": "Could you post an example of input and output?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-30T13:10:04.427", "Id": "46032", "Score": "0", ...
[ { "body": "<p>Not exactly a code review, but did you know that ruby 2 introduces binary search for arrays ? </p>\n\n<p>See : <a href=\"http://ruby-doc.org/core-2.0/Array.html#method-i-bsearch\" rel=\"nofollow\">Array#bsearch</a>. </p>\n\n<p>your problem could be solved like this: </p>\n\n<pre><code>myarray.each...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T02:45:47.257", "Id": "28953", "Score": "2", "Tags": [ "ruby", "binary-search" ], "Title": "First Occurrence of Number in Binary Search?" }
28953
<p>I am tracking trains and trying to identify individual trains seen multiple times at different points through the IDs of the wagons on them when spotted.</p> <pre><code>// create a lookup of all tracked trains for each wagon IEnumerable&lt;Train&gt; trains = GetTrains(); var wagonTrains = new Dictionary&lt;int, Li...
[]
[ { "body": "<blockquote>\n <p>create a lookup of all tracked trains for each wagon</p>\n</blockquote>\n\n<p>That's pretty much what <a href=\"http://msdn.microsoft.com/en-us/library/bb549211.aspx\">the <code>ToLookup()</code> method</a> is for. You just need a bit more LINQ to get a collection of (train, wagon...
{ "AcceptedAnswerId": "28966", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T10:18:06.577", "Id": "28964", "Score": "3", "Tags": [ "c#", "linq" ], "Title": "Write nested loops as linq query" }
28964
<p>G'day Just before I submit this to CFLib, it'd be great to get feedback:</p> <pre><code>&lt;cfscript&gt; /** * @hint CFML implementation of Array.reduce(), similar to Javascript's one ref https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce * @array Array to reduce * @callba...
[]
[ { "body": "<p>I don't see any flaws in your logic... <strong>but...</strong></p>\n\n<p>I know you've basically just ported the referenced JavaScript example, but I'm not really fond of the implementation of <code>initialValue</code>.</p>\n\n<p>Instead, have a look at <a href=\"https://github.com/russplaysguitar...
{ "AcceptedAnswerId": "29049", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T12:52:35.913", "Id": "28968", "Score": "4", "Tags": [ "coldfusion", "cfml" ], "Title": "CFML implementation of Array.reduce()" }
28968
<p>I echo a rank of a student whose <code>regd</code> is equal to <code>$regd</code>. In fact, this is working code. However, I was advised by a friend that the MySQL statements <code>Distinct</code> and <code>Group By</code> should not be used together. But as a newbie, I could not figure out how I could implement it ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T15:26:00.140", "Id": "47932", "Score": "0", "body": "Why are you using `HAVING` instead of `WHERE`? Also, I think you probably intend to filter by `Name_of_exam` within the innermost query, rather than at the outermost query." } ]
[ { "body": "<p>Since you use it in a subquery, I don't see the problem. If you used both in the same query, that would be redundant. But the subquery needs to use it to obtain the required data.</p>\n\n<p>Did the person give a reason as to why he/she thinks this, or was it simply a general statement?</p>\n\n<p>T...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T13:42:20.670", "Id": "28971", "Score": "1", "Tags": [ "php", "mysql" ], "Title": "Echoing student ranks" }
28971
<p>After posting <a href="https://codereview.stackexchange.com/q/12197/3163">this question</a> I made some updates and changes to my code. My new demo for the game is located <a href="http://jsfiddle.net/maniator/XP9Qv/" rel="nofollow noreferrer">here</a>. Right now it is only one player.</p> <p>Is there anything I co...
[]
[ { "body": "<p>This is a lot of code to review so it might be a good idea to break it down into separate parts. This way it'll be easier to give a more detailed and tailored review. But anyways here are a few things you can do that should help your performance:</p>\n\n<p><strong>Minimize Paints and Reflows</stro...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T13:59:57.663", "Id": "28973", "Score": "1", "Tags": [ "javascript", "game" ], "Title": "Wheel of Fortune game - follow-up" }
28973
<p>I have this code that works fine, but I would like to create some unit test for this class. Most of the code is in <code>private</code> or <code>void</code> type methods. Please help me refactor my class to make it more testable.</p> <pre><code>namespace Insperity.HCRBlackBox.HCRServices.Biz { public class Orga...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T15:30:25.410", "Id": "45620", "Score": "2", "body": "**1.** I'd change the wording in your question. \"Please help me refactor\" gives the impression that you want other people to do your work for you. **2.** I recommend reading the...
[ { "body": "<p>I'm not too familiar with C#, so just a few generic notes:</p>\n\n<ol>\n<li><p>If you can, use a dependency injection (DI) framework and inject the <code>OrganizationChartRepository</code> instead of creating it inside the constructor. It would make the classes less coupled and therefore easier to...
{ "AcceptedAnswerId": "29011", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T15:26:04.450", "Id": "28979", "Score": "4", "Tags": [ "c#", "unit-testing" ], "Title": "Does my code need refactoring before adding unit tests?" }
28979
<p>I know using a UnitOfWork/Repository pattern in a normal class should work fine without any issues but how about using them in a static class/methods (I mean using a private static IUnitOfWork instance, refer CustomerService class). Will this work fine in multiple user scenario without overlapping with other request...
[]
[ { "body": "<p>It entirely depends on your implementation of the unit of works members. If the IDataRepository is using something like NHibernate and keeping open persistent connections (which, being part of a unit of work, I presume it might) you will absolutely run into weird database connectivity issues when ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T16:06:40.110", "Id": "28983", "Score": "0", "Tags": [ "c#", "design-patterns", "static" ], "Title": "Using UnitOfWork/Repository pattern in static class/methods" }
28983
<p>In JavaFX, the lifecycle of an <code>Application</code> is quite different than Swing. Your constructor must take no arguments so that the <code>Application</code> class can create an instance of your object. Once the instance has been created, it calls <code>start(Stage)</code>, which gives you a <code>Stage</code>...
[]
[ { "body": "<p>What you have implemented is the Singleton design pattern.</p>\n\n<p>Normally I would suggest that you make <code>public LJGM()</code> private, and <code>public static LJGM instance()</code> check if <code>instance</code> is null, and if so call the constructor to set it, but it looks like you can...
{ "AcceptedAnswerId": "29033", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T16:33:24.397", "Id": "28984", "Score": "1", "Tags": [ "java", "constructor", "javafx" ], "Title": "JavaFX design writes to static field from constructor" }
28984
<p>I'm looking for a way to make my code more simple. This code takes a list of vectors and returns all subset of that list that sum up to another vector.</p> <p>For example:</p> <blockquote> <p><code>{'a','b','c'}</code> is the subset consisting of: <code>a (1100000)</code>, <code>b (0110000)</code>, and <code>c ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T19:43:09.140", "Id": "45648", "Score": "0", "body": "What does your code do ? What is it supposed to do ? Does it work ? I've tried replacing `one` by `1` and it is now running fine but it doesn't seem to be doing much." }, { ...
[ { "body": "<p>Please have a look at <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a> giving the Style Guide for Python Code.</p>\n\n<p>Now, in <code>AddVectors</code> (or <code>add_vectors</code>), it seems like you assume that A and B have the same size. You could achieve the sam...
{ "AcceptedAnswerId": "28987", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T16:45:53.400", "Id": "28985", "Score": "-1", "Tags": [ "python", "python-3.x", "mathematics" ], "Title": "Find all subsets of a vector that sum up to another vector" }
28985
<p>I am using the <a href="http://zserge.bitbucket.org/jsmn.html" rel="nofollow">jsmn JSON parser</a> (<a href="https://raw.github.com/noct/jsmn/master/jsmn.c" rel="nofollow">source code</a>) to get extract data from a JSON string. jsmn stores the data in tokens that just point to the token boundaries in the JSON stri...
[]
[ { "body": "<p>There are a few issues with <code>getTextFromJSON</code> involving use of pointers, code\nduplication and use of an inappropriate function.</p>\n\n<p>Pointers first. In this code:</p>\n\n<pre><code>jsontok_t tokens[15];\njsontok_t key;\n...\nkey = tokens[i];\n</code></pre>\n\n<p>you are copying t...
{ "AcceptedAnswerId": "28991", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T17:10:00.663", "Id": "28986", "Score": "12", "Tags": [ "performance", "c", "parsing", "json" ], "Title": "More efficient way to retrieve data from JSON" }
28986
<p>The reason I asked about standing the test of time is that I previously used PHP echo to create a string and placed it into a div with .innerHTML, but modern browsers were not passing the value of the select box. (Went back and tested wit IE9 and the innerHTML version worked.)</p> <p>file:js_selecttest.php</p> <pr...
[]
[ { "body": "<p>To answer your question in the title: no\nFor multiple reasons. One being that the things we use today could be out-dated in a few years. who knows</p>\n<p>One question/remark:</p>\n<pre><code>sel_obj.options[i]=new Option(op_array[i], i);\nsel_obj.options[i].value=op_array[i];\n</code></pre>\n<p>...
{ "AcceptedAnswerId": "29026", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T17:23:28.303", "Id": "28988", "Score": "1", "Tags": [ "javascript", "php", "html" ], "Title": "Is this code likely to stand the test of time? (Add select box to DOM with JS)" }
28988
<p>Based on the post I made here: <a href="https://codereview.stackexchange.com/questions/28948/rfc-on-factory-code">RFC on &quot;Factory&quot; code</a> and its responses, and my (inner) response to those responses, I'm beginning to wonder if it would be just as well to simply switch based on the user's hardware, and f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T19:39:55.713", "Id": "45647", "Score": "6", "body": "Tip: Reduce the amount of text. The *tl;dr*-factor here is fairly high." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T22:44:59.657", "Id": "4...
[ { "body": "<p>Start from the simplest possible way to solve the problem, and add complexity if there is a reason. Reasons could be a specific need from the specifications, or something that your experience tells you will very likely be needed at some point.</p>\n\n<p>In this specific case, there would be a poin...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T18:24:28.880", "Id": "28990", "Score": "4", "Tags": [ "c#", "design-patterns", "factory-method" ], "Title": "\"Fancy-pants\" vs \"Cowboy\" coding" }
28990
<p>This is the code I wrote to find out the time spent by product in process represented by clockin and clock out. Time stamps X and Y (for example, 7/23/2013 7:00 AM and 7/23/2013 8:00 AM) reflect the time period where in I am calculating the time.</p> <p><code>X</code>, <code>Y</code>, <code>CLOCK_IN</code> and <cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-22T04:13:45.813", "Id": "88702", "Score": "1", "body": "This is vague, are you able to provide information about your data set, maybe some context of what this code is part of? Very difficult to suggest improvements without context..."...
[ { "body": "<p>I'll attempt to provide something helpful, even though this is old.</p>\n\n<ol>\n<li><p>To start with, just syntax-wise, <code>[brackets]</code> are only required if your column name contains a reserved character, such as a space or apostrophe. It looks less cluttered if you don't use them unless...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T18:50:07.103", "Id": "28993", "Score": "4", "Tags": [ "sql", "datetime", "ms-access" ], "Title": "Time spent by product in process represented by clockin and clock out" }
28993
<p>I'm just looking for feedback on correctness of my understanding of async/await. I'm curious about the <code>Task.Run</code> inside of the <code>StartReceive()</code> method. Resharper (or maybe just the compiler) warns against doing this without an await, but I think in this case, it's ok.</p> <p>After running, o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T11:00:05.737", "Id": "54017", "Score": "0", "body": "Is v3 is the final version of basic chat server? I would like to use it as my basis of scalable/robust client server application. Thanks." }, { "ContentLicense": "CC BY-SA...
[ { "body": "<pre><code>static void Main(string[] args)\n</code></pre>\n\n<p>If you're not using <code>args</code>, you can just remove them: <code>static void Main()</code>.</p>\n\n<pre><code>server.Start();\nConsole.WriteLine(\"Listening....\");\nConsole.ReadLine();\n</code></pre>\n\n<p>Running a server until E...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T23:21:16.837", "Id": "29000", "Score": "11", "Tags": [ "c#", "task-parallel-library", "socket", "async-await", "tcp" ], "Title": "Console chat server" }
29000
<p>Ramer-Douglas-Peucker is a great algorithm for reducing the number of samples in a given trace, and also for keeping its general shape (as much as he can).</p> <p>I have a trace with 32.000.000 samples, and I want to compute a reduced version in order to be able to plot it into my winform application.</p> <p>The f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T00:52:30.423", "Id": "45681", "Score": "1", "body": "wow, I did not even know you could do float* in c#" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T10:16:42.090", "Id": "45732", "Score": "...
[ { "body": "<p>You could initialize the capacity of the lists (via the constructor) you are generating. The closer you can get to the size the list will be after all points are added the better. </p>\n\n<p>The reason you would do this is that the list implementation is just a wrapper around an array starting at ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-25T23:25:12.770", "Id": "29002", "Score": "7", "Tags": [ "c#", "performance", "algorithm", "multithreading", "computational-geometry" ], "Title": "Ramer-Douglas-Peucker algor...
29002
<p>I am trying to mimic <code>std::stack</code> in my implementation (just the basic interface - no iterators / allocators). Since I was having trouble handling all the memory allocation/deallocation, I read <a href="https://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom">this</a>.</p> <p>Althoug...
[]
[ { "body": "<ol>\n<li><p>You may run a high risk of memory leaks when using raw structures, especially with pointers. Memory-management is not one of my strong points, so I won't say too much about that. For learning purposes, you should be okay as long you maintain good habits (accompany each <code>new</code>...
{ "AcceptedAnswerId": "29028", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T00:37:38.973", "Id": "29003", "Score": "7", "Tags": [ "c++", "optimization", "memory-management", "reinventing-the-wheel", "stack" ], "Title": "Mimicking the basic inte...
29003
<p>This is my first time messing with PHP and I tried to put together a simple address book that when the user fills out the form it would update a database table, then display the row data on the page after submission.</p> <p>It works fine, but I just want to make sure I'm headed in the right direction.</p> <p><code...
[]
[ { "body": "<p>I think there are two major issues you should address right in the beginning when you start with PHP.</p>\n\n<h1>Separation of Layout and Logic</h1>\n\n<p>This means in general that you shouldn't mix HTML and PHP code. Later this will lead you to the <a href=\"http://en.wikipedia.org/wiki/Model%E2...
{ "AcceptedAnswerId": "29009", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T03:02:42.367", "Id": "29008", "Score": "7", "Tags": [ "php", "beginner", "mysql" ], "Title": "Address book with database tables" }
29008
<p>I'm doing a BattleShip game in javascript with iio engine.</p> <p>I'm trying to play against a computer so I have to put a random position for the ships (I hope you know the game :) ).</p> <p>I have 5 ships that have to be placed in a grid (10x10). The problem is that the function is pretty slow, and sometimes the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T09:43:36.457", "Id": "45729", "Score": "0", "body": "The problem is the algorithm: you need something better than `while (!allPlaced) { do { pos = randPos(); } while (shipAt(pos)); positions.add(pos); }`. 5 ships on a 100 point grid...
[ { "body": "<p>This is not really a speed issue; there are a couple of problems with your code that prevent it from working properly.</p>\n\n<p>The most serious problem is that, if the position is not good you set <code>isok2 = false</code>. The <code>while</code> loop then picks another position. But nothing re...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T08:11:29.317", "Id": "29013", "Score": "2", "Tags": [ "javascript", "performance" ], "Title": "Improve performance Javascript function" }
29013
<p>I have sample database in <code>GES</code> files and I wrote importer in Ruby.</p> <p>Sample file: <code>WAR_APO.GES</code>: <a href="https://gist.github.com/regedarek/cd0ce73c5d1e14ff9818" rel="nofollow">https://gist.github.com/regedarek/cd0ce73c5d1e14ff9818</a></p> <p>I will have several of <code>GES</code> file...
[]
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li><p>As usual, I'd recommend a more functional approach. It's not a theoretical issue, functional code is more concise, more clear. When I see <code>@k = []</code> I get the shakes thinking that this variable can (and will) be modified just everywhere in the class (an in...
{ "AcceptedAnswerId": "29021", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T09:08:06.120", "Id": "29014", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "data-importer" ], "Title": "What are best practices of creating database importer in Rails?" }
29014
<p>As a beginner Python programmer, I wrote a simple program that counts how many times each letter appears in a text file. It works fine, but I'd like to know if it's possible to improve it.</p> <pre><code>def count_letters(filename, case_sensitive=False): alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS...
[]
[ { "body": "<p>Your coding style is good, especially if you're only starting to program in Python. But to improve your code, you should learn your way around the standard library. In this case, the <a href=\"http://docs.python.org/3/library/string.html\" rel=\"nofollow\"><code>string</code></a> and <a href=\"h...
{ "AcceptedAnswerId": "29043", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T13:43:09.550", "Id": "29024", "Score": "4", "Tags": [ "python", "beginner", "python-3.x", "file" ], "Title": "Counting letters in a text file" }
29024
<p>I'm working on a project where I need to map XML values to field names. Classic CS problem, I think I've got a pretty good approach but would like feedback.</p> <p>For example: <code>breachReportType</code> matches to <code>Breach Report Type:</code>. However, there are similar matches like: <code>breachType</code>...
[]
[ { "body": "<p>You could possibly improve it by using a fuzzy match algorithm such as the <a href=\"http://www.dotnetperls.com/levenshtein\" rel=\"nofollow\">Levenshtein Distance Algorithm</a> for your MatchStrings method. Then you could simply look for the smallest return value of all of the comparisons and use...
{ "AcceptedAnswerId": "29048", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T14:13:54.777", "Id": "29027", "Score": "3", "Tags": [ "c#", "strings", "regex", "xml" ], "Title": "String Interpolation / Word Matching with XML in C#" }
29027
<p>I wrote this form object to handle an e-commerce order form. My areas of concern are the verbosity of the <code>populate</code> method, and the repetition of the validations. I omitted some address fields and validations for brevity.</p> <pre><code>class OrderForm include ActiveModel::Model def persisted? ...
[]
[ { "body": "<p>I was about to propose some changes to your code to reduce the line-count (and get rid of those @cached objects, bad idea IMHO), but I think it's the big picture what it's failing here. Some notes:</p>\n\n<ul>\n<li><p>You are creating an <code>OrderForm</code> abstraction when in fact Rails gives ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T15:35:33.963", "Id": "29030", "Score": "3", "Tags": [ "ruby", "ruby-on-rails", "e-commerce" ], "Title": "Handling an e-commerce order form" }
29030
<p>I have two buttons on an ASP.NET page that have separate <code>OnClick</code> methods in the code behind. In one of the methods, if a certain condition is met, the entire process of the other method should be executed.</p> <p>Here is a simplified example of my code, which works as I intend in my actual implementati...
[]
[ { "body": "<p>I'd suggest something like the following which is simple enough for even a novice like me to understand. Is there a real need to simulate button click? You're not testing buttons, are you? </p>\n\n<pre><code>// OnClick=\"ThisButton_OnClick\" for ThisButton\nprotected void ThisButton_OnClick(object...
{ "AcceptedAnswerId": "29037", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T17:28:20.403", "Id": "29034", "Score": "1", "Tags": [ "c#", "asp.net" ], "Title": "Calling a button's OnClick method elsewhere - Good Practice?" }
29034
<p>In my web development company, we have many designers who have the following development knowledge:</p> <ul> <li>Client-side web languages (HTML, CSS, JavaScript)</li> <li>Basic database design (how to create tables, relationships, etc), and</li> <li>Basic SQL</li> </ul> <p>So we thought about giving them a simple...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T19:16:52.450", "Id": "45769", "Score": "2", "body": "What's the reason for not using controllers and repositories for interaction with the database?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T19:...
[ { "body": "<p>That coding style looks more like the WebMatrix <a href=\"http://www.asp.net/web-pages/tutorials/introducing-aspnet-web-pages-2/getting-started\" rel=\"nofollow\">Web Pages</a> pattern rather than ASP.Net MVC. If this coding style is desired then it would be preferable to go ahead and use the data...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T17:32:16.900", "Id": "29035", "Score": "1", "Tags": [ "html", "sql", "asp.net", "mvc" ], "Title": "Platform for creating data-oriented web apps" }
29035
<p>Here is my link to the <a href="http://jsfiddle.net/zq7rq/" rel="nofollow">JSFiddle</a> and the <a href="http://jsfiddle.net/zq7rq/embedded/result/" rel="nofollow">full screen description</a>.</p> <p><em>Note on the full mode screen</em>: the footer is not sticking, but it actually sticks if I check on my browser.<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T20:08:30.527", "Id": "45773", "Score": "0", "body": "Fixed width websites are pretty much a thing of the past thanks to a plethora of mobile and tablet resolutions. *Responsive design* is the way things are generally done now, even...
[ { "body": "<p>Unless your element is fixed or absolutely positioned, <code>top: 0</code> is doing nothing for you (<code>#header</code>). Unless your descendant elements are absolutely positioned (or you need to adjust the element's stacking order due to surrounding absolutely positioned elements), you probabl...
{ "AcceptedAnswerId": "29042", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-26T18:27:23.267", "Id": "29038", "Score": "0", "Tags": [ "html", "css" ], "Title": "I want to see if there is anything I don't need in my CSS file for my current layout" }
29038
<p>I have been working on a Bencoded string parser in order to improve my knowledge of Haskell. After running the code through hlint, I still have a few questions:</p> <ol> <li><p>As I noted in the comments, the key value in the definition of BMapT should always be a Bstr. Is there any way to enforce a particular data...
[]
[ { "body": "<p>Below is your code with some minor tweaks and the comments moved into standard Haddock form.</p>\n\n<pre><code>module Bencode (readBencodedFile, BencodedValue(..), bencode, bencodeBS) where\n\nimport qualified Control.Monad as Mon\nimport Data.ByteString (ByteString)\nimport Data.ByteString.Char8 ...
{ "AcceptedAnswerId": "45669", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T06:33:06.337", "Id": "29050", "Score": "2", "Tags": [ "haskell", "functional-programming" ], "Title": "Haskell Bencoded Dictionary Parser" }
29050
<p>I have a web layout that I created and then later wanted to add a dropdown menu to it. I found that my html was not quite optimum for that, so I wrote some jQuery that is now working quite nicely but I need this to be critiqued to see if and where I could have changed some things here.</p> <p>My dropdown menu is th...
[]
[ { "body": "<h2>HTML</h2>\n\n<p>Your html is <s><em>flawless</em></s> (to me) pretty good. Good job.</p>\n\n<h2>CSS</h2>\n\n<p><em>Also</em> <s>completely flawless</s> pretty good!. Well written, efficient, I wouldn't (personally) change a thing.</p>\n\n<h2>JQuery</h2>\n\n<p>You made a few formatting errors here...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T06:56:37.980", "Id": "29052", "Score": "5", "Tags": [ "javascript", "jquery", "css" ], "Title": "Implementation quality of my afterthought jQuery drop-down menu?" }
29052
<p>Code is below. I'd like to know if this is a solid/efficient implementation of the in-place quicksort algorithm and if my Python style is good (I know there are no comments for now). Code is also on Github here if you'd like: <a href="https://github.com/michaelrbock/data-structs-and-algos/blob/master/Sorts/quicksort...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T14:27:03.650", "Id": "45808", "Score": "0", "body": "Doesn't using `sorted` in a sorting function defeat the purpose of writing your own sorting function?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-...
[ { "body": "<p>Personally I like the style (especially the nice clear function and variable names). As its quicksort most of the code is straightforward enough that comments would probably only add meaning when it comes to the swapping. You should probably try and use four spaces, rather than tabs, for indenting...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T07:55:30.270", "Id": "29053", "Score": "5", "Tags": [ "python", "sorting", "quick-sort" ], "Title": "In-Place Quicksort in Python" }
29053
<p>I have started to learn Java and I need your critique for my first program. It is an interpreter that can calculate any expression including <code>abs()</code>, <code>sqrt()</code>, <code>min()</code>, <code>max()</code>, <code>round()</code> and <code>pow()</code>.</p> <p>What can you say about this? Are there any...
[]
[ { "body": "<h2>Formatting</h2>\n\n<ul>\n<li><a href=\"http://en.wikipedia.org/wiki/Naming_convention_%28programming%29#Java\" rel=\"nofollow noreferrer\">Your variable names should start with a lower case letter by convention.</a></li>\n<li>Try to have spaces around operators (<code>+</code>, <code>==</code> et...
{ "AcceptedAnswerId": "29060", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T10:10:44.937", "Id": "29055", "Score": "4", "Tags": [ "java", "beginner", "math-expression-eval" ], "Title": "Evaluating expressions with various mathematical methods" }
29055
<p>I'm making this web application that needs some very simple JavaScript/HTML5 related features integrated (hereby an upload feature). However, I'm not sure about whether I've overdone it, as it's the first time I'm writing JavaScript without just throwing it all into the same file, with no namespace.</p> <p>For exam...
[]
[ { "body": "<ol>\n<li>I think it will be better if all selectors will be in options for <code>init</code> method and all of that fields like <code>FileInputs</code> will be initialized also in <code>init</code>, so I can put <code>Upload.js</code> in header and call <code>init</code> after document ready.</li>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T12:49:14.013", "Id": "29058", "Score": "1", "Tags": [ "javascript", "jquery", "ajax", "network-file-transfer" ], "Title": "File uploader using XMLHttpRequest" }
29058
<p>I would really appreciate a review of my interpretation of MVC <a href="http://jsfiddle.net/zuVkt/" rel="nofollow">here</a>.</p> <p>It's as bare bones and clear as possible. I've based it on some in-depth reading but I don't know if I have understood everything correctly! </p> <ol> <li>For example, how have I wir...
[]
[ { "body": "<p>*\n<code>model.cbFns = []; //onChange callbacks</code></p>\n\n<p>I would rename this to callBacks, <code>cbFns</code> just feels wrong</p>\n\n<pre><code> set: function(props){\n //Set a node value\n var model = this,\n cbFns = model.cbFns;\n mixin(model.tree, props);...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T11:36:37.047", "Id": "29061", "Score": "3", "Tags": [ "javascript", "design-patterns", "mvc", "dom" ], "Title": "First attempt at MVC JavaScript pattern" }
29061
<p>I am creating a dynamic menu whose items appear depending on a set 'mode' (that is passed via AJAX). Off this it creates the menu, disabling and hiding icons that are not associated with that mode.</p> <p>The problem is, there are a lot of <code>if</code> conditions in my implementation. Can anyone show me a cleane...
[]
[ { "body": "<p>Your code has multiple bad practices.</p>\n\n<p>There is no speration of concern. Your code is handling display, logic and controlling. All in onde function.</p>\n\n<p>If I look at the function, it tells me it needs nothing (no arguments need to be passed in). So the only thing it should be using ...
{ "AcceptedAnswerId": "29487", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T16:37:33.750", "Id": "29064", "Score": "7", "Tags": [ "php" ], "Title": "Dynamic menu depending on a set mode" }
29064
<p>After reading about MVC pattern in <em>Head First Design Patterns</em>, I've decided to write a TicTacToe app.</p> <p>I will not reveal the source code of the classes <code>Matrix</code>, <code>Dimension</code>, and <code>Size</code> because they do not relate to the topic. All source code can be found <a href="htt...
[]
[ { "body": "<p>Note that the following line violates the principle of information hiding:</p>\n\n<pre><code> if (gameBoard.get(row, column) == Cell.EMPTY) {\n</code></pre>\n\n<p>Express this as:</p>\n\n<pre><code> if (gameBoard.isEmpty(row, column)) {\n</code></pre>\n\n<p>In the following:<...
{ "AcceptedAnswerId": "35938", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T20:16:32.133", "Id": "29070", "Score": "3", "Tags": [ "java", "design-patterns", "mvc", "android" ], "Title": "TicTacToe - introduction to MVC pattern" }
29070
<p><strong>Initial note:</strong> You do not need to have knowledge of LWJGL or OpenGL to review this code. The only parts of the code that require LWJGL knowledge are the <code>Game</code> class, and the rest, although it may contain some LWJGL/OpenGL/Slick-util code, it is rather self explanatory for anybody who's wo...
[]
[ { "body": "<p>General:</p>\n\n<p>Dont use <code>} else {</code> or <code>} catch(...) {</code> because it breaks the brace rule and it's not that readable.</p>\n\n<p>Do code a Vector class because it groups your coordinates together so the code gets more easily readable and managable.</p>\n\n<hr>\n\n<p><code>Sp...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-27T23:26:06.610", "Id": "29073", "Score": "3", "Tags": [ "java", "game", "opengl" ], "Title": "WIP platformer game" }
29073
<p>I'm trying to write a simple GTK GUI for the command line program auCDtect. It is supposed to take .flac files, convert them to .wav temporarily, pass the to the auCDtect command line program to check they are lossless and then delete the temporary .wav file and output the results.</p> <p>For around 10+ files it's ...
[]
[ { "body": "<p>A few random notes:</p>\n\n<ol>\n<li><p>If I'm right it's not thread safe.</p>\n\n<blockquote>\n<pre><code>progress = auCDtect.getProgress();\noutput = auCDtect.getOutput();\nsummary = auCDtect.getSummary();\n</code></pre>\n</blockquote>\n\n<p>I guess the calls above runs on an event dispatcher th...
{ "AcceptedAnswerId": "43745", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T05:14:22.027", "Id": "29075", "Score": "3", "Tags": [ "java", "gui", "audio" ], "Title": "Simple GTK GUI for the command line program auCDtect" }
29075
<p>I have written code to print a range of numbers using multi-threaded programming. It takes in the number of threads to spawn as input.</p> <p>It is working fine and giving the expected results. I just wanted you to check it and see if the code can be written a bit more efficiently.</p> <pre><code> #include&lt;std...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T16:01:29.790", "Id": "45861", "Score": "1", "body": "Please read [this about casting the result of malloc](http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc)." } ]
[ { "body": "<ul>\n<li>First of all, while reviewing your code the bad code formatting style really hurts my eyes. Good code formatting and indentation makes it easier to review and maintain code.</li>\n<li>Get rid of all unnecessary spaces and tabs.</li>\n<li>Your <code>main</code> function is doing many things ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-24T09:06:37.673", "Id": "29079", "Score": "1", "Tags": [ "c", "multithreading", "winapi" ], "Title": "Printing a range of numbers using configurable worker threads" }
29079
<p>Is this the best way of doing this? I wanted to make sure the grammar is correct when the array is output.</p> <p>1 car, 2 cars.</p> <p>The output is correct but is there an easier way generally? I just want to make sure I am doing this in a proper way. I don't have the benefit of the experience of the majority of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T11:34:28.120", "Id": "45904", "Score": "0", "body": "I've provided about 4 possible alternatives, but they're all geared towards _\"optimization\"_, sort of. You might get the impression I find your code terrible (which it isn't), b...
[ { "body": "<p>I also lack a bit of experiance.\nOften it is better to use classes.\nMy probosal would be:</p>\n\n<p>I did not test it.</p>\n\n<pre><code>&lt;?php\nclass products {// or wathever name you like\n\n public $products = array();\n\n protected function generate_random_number(){\n return m...
{ "AcceptedAnswerId": "29112", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T09:59:00.330", "Id": "29080", "Score": "1", "Tags": [ "php", "array", "random" ], "Title": "Am I on the right track with this random number array?" }
29080
<p>I just wrote some PHP to let a client lock off a their one-page site from the public using a password. No users and no database. Just checking the password the user enters and testing it against the chosen phrase. This should be simple (right?) but I havn't built this sort of thing before. Let me know what you think...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T15:44:07.223", "Id": "45859", "Score": "0", "body": "As far as I can tell it looks pretty good. Don't know why you bother to strip tags etc though?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T09:1...
[ { "body": "<p>A few things, mostly around <code>logged_in</code>:</p>\n\n<pre><code>private function check_login() {\n if (isset($_SESSION['logged_in'])) {\n // If logged in, take this action\n $this-&gt;logged_in = true;\n } else {\n // If not logged in, take this action\n $th...
{ "AcceptedAnswerId": "29139", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T10:43:43.893", "Id": "29081", "Score": "1", "Tags": [ "php", "session" ], "Title": "Password-Lock a Single Page with PHP - How did I do?" }
29081
<p>I was attempting to build a program using Ruby that asks the user to input at least three numbers, and it returns the mean, median, and mode of those numbers.</p> <p>A developer friend of mine glanced over it and said that the program was wrong, but didn't state specifically what was wrong with it. I have looked ov...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T11:20:34.907", "Id": "45854", "Score": "0", "body": "Please note that in this case, the mode is a single mode only. If there are multiple numbers that frequent the same number of times, the mode does not exist." } ]
[ { "body": "<p>It looks valid to me. Except you are not enforcing the '3 number minimum'. </p>\n\n<ul>\n<li>You can use x.odd? to check odd or even. </li>\n<li>You can total numbers with [1,2,3].inject(&amp;:+). </li>\n<li>The frequencies.to_a is not needed, as it's already an array after the sort_by. </li>\n<li...
{ "AcceptedAnswerId": "29111", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T11:19:14.993", "Id": "29083", "Score": "0", "Tags": [ "ruby", "statistics" ], "Title": "Program to find the mean, median, and mode of numbers" }
29083
<p>I've written this code to get input from a file and count the repetition of number of that file and give output to another file. How can I make this code better?</p> <pre><code>#include &lt;iostream&gt; #include &lt;cmath&gt; #include &lt;fstream&gt; using namespace std; int main() { ofstream outputFile("outP...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T15:27:17.767", "Id": "45858", "Score": "1", "body": "The first thing I would suggest to do is to improve the formatting of the code. Unneeded spaces like after the `#include`s you need 1 space so why use 3? It isn't that big a code....
[ { "body": "<p>By consistent style I meant something like this. If you use braces when a statement like <code>if</code>, <code>for</code> etc. contains single statement then use braces for <code>if</code>, <code>for</code> etc. containing single statements everywhere. </p>\n\n<pre><code>#include &lt;iostream&gt;...
{ "AcceptedAnswerId": "29087", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T15:12:26.327", "Id": "29085", "Score": "1", "Tags": [ "c++", "file" ], "Title": "Counting repetitions in a file" }
29085
<p>I'm just looking for some feedback on my implementation of a maxheap mostly relating to style. I'm trying to create good habits as I learn to program.</p> <p>Note: for the sort method I was given the precondition that the passed in array never has empty/null elements and that it must be sorted in place.</p> <pre><...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T13:27:24.723", "Id": "48390", "Score": "0", "body": "@Quonux Nice formatting! Turns out really great! I like the \"javadoc\" format!" } ]
[ { "body": "<pre><code>public class Heap12&lt;E extends Comparable&lt;? super E&gt;&gt; implements PQueue&lt;E&gt;{\n</code></pre>\n\n<p>Don't name your Generic Parameters with a single letter, give them meaningful names wit the end <code>Type</code> so you can differenciate between variables and the Generic Par...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-07-28T17:43:58.313", "Id": "29089", "Score": "5", "Tags": [ "java", "heap" ], "Title": "Max heap in Java" }
29089
<p>I was making an algorithm for a task I found in a book. It says that there is sorted array, that was swapped so it looks like "4567123", and was proposed to use binary search modification.</p> <p>Below is my solution in java.</p> <p>The thing is, I'm a bit cringed that I can't process cases for array size of 2, 3 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T17:32:56.020", "Id": "46815", "Score": "0", "body": "What is the purpose of your algorithm? Is it suppose to locate an element in the semi-sorted array? Is it supposed to sort the semi-sorted array? Please improve your problem descr...
[ { "body": "<h2>General Advise</h2>\n\n<ul>\n<li><p>Your methods are difficult to read because you chose to use predominantly single character variable names. Multi-character descriptive variable names are much easier to associate with a value, making the code magnitudes easier to read &amp; maintain. Also, when...
{ "AcceptedAnswerId": "29594", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T18:24:10.483", "Id": "29090", "Score": "5", "Tags": [ "java", "algorithm" ], "Title": "Binary search modification for \"swaped\" array" }
29090
<p>I am looking for feedback on a solution to the following problem posed from a book that I'm working through (<em>Java: How To Program 9th Edition</em>):</p> <blockquote> <p>Write an application that reads a line of text and prints a table indicating the number of occurrences of each different word in the text. Th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T18:52:46.143", "Id": "45871", "Score": "0", "body": "your code has a bug. Try to give `a b b b c` as input and see the result." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T19:39:28.597", "Id": ...
[ { "body": "<p>Both calls to replaceAll and the call to split could be replaced by 1 call to split. Remember that split accepts a regex and that regex patterns can endlessly combine matches for \"one or more occurrences\" of another pattern with matches for \"one pattern or another\", etc.</p>\n\n<p>In any case,...
{ "AcceptedAnswerId": "29138", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T18:25:55.477", "Id": "29091", "Score": "4", "Tags": [ "java", "beginner" ], "Title": "Number of occurrences of each different word in a line of text" }
29091
<p>I am working on creating a Makefile for my ProjectEuler solutions. I need to compile each solution into a separate binary for personal timing purposes. Is it possible to pass the name of the rule to the -o option to remove some repeated code?</p> <pre><code>CXX = g++ CXXFLAGS = -std=c++0x INC = -Iinclude/ -I../tool...
[]
[ { "body": "<p>You could use suffix rules (the .c.o part below) to tell make how to compile a c file. Then you can just tell the dependencies for each target.</p>\n\n<pre><code>CXX = g++\nCXXFLAGS = -std=c++0x\nINC = -Iinclude/ -I../tools/\n\nbinaries=01sum35\\\n 02evenfibs\\\n 03largestprimefactor\\\n ...
{ "AcceptedAnswerId": "29097", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T19:27:29.830", "Id": "29093", "Score": "2", "Tags": [ "c++", "makefile" ], "Title": "How can I improve this Makefile?" }
29093
<p>I am learning <code>PowerShell</code>, and created the following script <code>cmdlet</code>. </p> <p>It reads one or more specified script files, to discover special functions (UnitTests, or functions with the Verb 'UnitTest' or 'DataTest'.</p> <p>I designed the parameters to work like <code>Get-Content</code>, as...
[]
[ { "body": "<p>Looks good.\nPersonally, I would take:</p>\n\n<pre><code>foreach($curPath in ($LiteralPath + $Path | Where {$_} | Resolve-Path)) {\n</code></pre>\n\n<p>and break out the collection generation code.\nSpecifically into something like:</p>\n\n<pre><code>$PathList = Join-Path $literalPath $Path | Reso...
{ "AcceptedAnswerId": "29238", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-28T20:10:39.530", "Id": "29094", "Score": "1", "Tags": [ "powershell" ], "Title": "Test finder PowerShell cmdlet" }
29094
<p>I typed this up quickly as an intuitive solution for determining if a given number is a perfect square.</p> <p>How could I improve this? I already know that it doesn't handle the case where the number is 1. I'm wondering if I could generalize the calculation so it rounds up. What can I look into to develop a mindse...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T02:49:03.213", "Id": "45880", "Score": "1", "body": "try FIPS 186-3 Appendix C section 4 http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-08-28...
[ { "body": "<p>You can narrow down your search range. If a number requires <code>n</code> bits to represent, its square root is between <code>1 &lt;&lt; ((n-1) / 2)</code> and <code>1 &lt;&lt; ((n+1) / 2)</code>. You can determine number of bits with something like:</p>\n\n<pre><code>int numBits(long l) {\n for...
{ "AcceptedAnswerId": "29106", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T00:25:31.550", "Id": "29100", "Score": "5", "Tags": [ "java", "algorithm" ], "Title": "Checking if a number is a perfect square (without Math)" }
29100
<blockquote> <p><strong>Function: Trim</strong></p> <p>Returns a new string after removing any white-space characters from the beginning and end of the argument.</p> </blockquote> <pre><code>string trim(string word) { if(startsWith(word, " ")) return removeSpaces(word, "Front"); if(endsWith(word, " "...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-12-27T05:16:48.843", "Id": "136224", "Score": "0", "body": "Any particular reason why there isn't a `trim()` method available as part of the string library? [C#](http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28string_f...
[ { "body": "<ul>\n<li><p>Your absence of <code>std::</code> before your <code>string</code>s lead me to believe that you're using <code>using namespace std;</code>. <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">Don't do that</a>.</p></li>\n<li><p>If-s...
{ "AcceptedAnswerId": "29104", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T02:49:07.920", "Id": "29102", "Score": "2", "Tags": [ "c++", "strings" ], "Title": "Trimming a string" }
29102
<p>Considering the code that you can find at the bottom of this post, it's safe to say that this is a good example of how I can use different representations in different basefields correctly in C++ ?</p> <p>I'm referring to the use of:</p> <ul> <li><code>std::hex</code> in the <code>std::istringstream</code> case</l...
[]
[ { "body": "<blockquote>\n <p>it's safe to say that this is a good example of how I can use different representations in different basefields correctly in C++ ?</p>\n</blockquote>\n\n<p>I presume you <code>stream manipulators</code>.</p>\n\n<blockquote>\n <p>I'm referring to the use of:</p>\n</blockquote>\n\n<...
{ "AcceptedAnswerId": "29249", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T06:17:28.887", "Id": "29107", "Score": "6", "Tags": [ "c++" ], "Title": "Is this a correct use of the std::cout and std::cin basefields/conversions?" }
29107
<p>Can my <code>rand_int</code> function be improved?</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; #include&lt;time.h&gt; int rand_int(int a,int b) { //The basic function here is like (rand() % range)+ Lower_bound srand(time(0)); if (a &gt; b) return((rand() % (a-b+1)) + b); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T08:52:45.237", "Id": "45893", "Score": "0", "body": "I think that your main problem is in the concept, `rand()` is probably the most unreliable prng, but this is not the real downside, the real problem is that `rand()` in just defin...
[ { "body": "<p>First of all. Move <code>srand()</code> out of the function call. For now, it is not random at all if you manage to execute function twice in the same second. You will reset the random seed to the same value with <code>time(0)</code> as it normally has a <code>1s</code> resolution.</p>\n\n<p>Then ...
{ "AcceptedAnswerId": "29110", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T08:26:24.727", "Id": "29109", "Score": "2", "Tags": [ "c", "random" ], "Title": "Random integer generation in given range" }
29109
<p>I'm looking for an lib which can search an array of strings with multible search-strings (array). I want to get an int-array of all indexes/matches.</p> <pre><code>private int[] getIndexArray(String[] pArray, String[] pSearchStrings) { int[] indexes = new int[0]; for (String str : pArray) { if (Arra...
[]
[ { "body": "<p>If you use <code>pSearchStrings[]</code> for all <code>pArray[]</code>, you can transform <code>pSearchStrings</code> in a <em>Pattern</em> and use <em>matcher</em> method to avoid to load each time <em>ArrayUtils.contains(..)</em></p>\n\n<p><strong>EDIT</strong><br></p>\n\n<pre><code>private stat...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T10:14:08.773", "Id": "29113", "Score": "2", "Tags": [ "java" ], "Title": "Search Array of Strings in Array of String, receive Int-Array of indexes" }
29113
<p>This script takes the list of provided URLs and scrapes the present links in each URL. For each scraped link, Facebook share, tweet, Google Plus is found out.</p> <p>For example, if the provided URL is www.example.com, the URL is scraped and, let us say, 2 links are found:</p> <blockquote> <p>www.example.com/1.p...
[]
[ { "body": "<p>I can't comment on performance, as I'm not very familiar with the cURL library and web scraping techniques.</p>\n\n<p>However, I'd be happy to comment on other points! I'll point things out in the order the script is ran.</p>\n\n<ul>\n<li><code>&amp;&amp; (trim($_POST['urls'])!=\"\"))</code> is re...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T11:11:28.150", "Id": "29115", "Score": "1", "Tags": [ "php", "performance", "php5", "url", "web-scraping" ], "Title": "Scraping links from provided URLs" }
29115
<p>I have a method that checks whether an <code>addressCriteria</code> contains only certain fields or more. If it contains more fields, it should return false, otherwise true.</p> <p>I'm uncertain what the best way to write my if statement is. As far as I can tell, I see 2 options:</p> <ul> <li>Write them in 1 if s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-21T07:57:12.150", "Id": "47628", "Score": "0", "body": "Wow, so many responses have got the boolean logic inverted. Are Code Review users copying each others' mistakes? Or is `isShortAddress()` poorly named, such that it gives programm...
[ { "body": "<p>I think the second approach with <strong>multiple if statements</strong> is better because it is <strong>more readable</strong>. </p>\n\n<p>Having multiple exit points allows to faster read source code as Martin Fowler explains in his book <em>Refactoring: Improving the Design of Existing Code</em...
{ "AcceptedAnswerId": "29129", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T13:18:39.580", "Id": "29127", "Score": "11", "Tags": [ "java", "validation" ], "Title": "Check whether address criteria contain only certain fields or more" }
29127