body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Is it possible to shorten this piece of PHP code?</p> <p>Honestly, I think it does not look clean but like a mess.</p> <pre><code>if(Input::exists() &amp;&amp; $token) { if($validation-&gt;error('firstname') &amp;&amp; $validation-&gt;error('lastname')) { echo str_repeat(' ', 20), '&lt;div class="addit...
[]
[ { "body": "<p>You are repeating the same code:</p>\n\n<pre><code>echo str_repeat(' ', 20), '&lt;div class=\"addition error\"&gt;↳ You did not enter your name.&lt;/div&gt;', \"\\n\";\n</code></pre>\n\n<p>Replace it with a function which will do the job:</p>\n\n<pre><code>function message($content, $class = ''){\...
{ "AcceptedAnswerId": "47644", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T08:41:59.547", "Id": "47636", "Score": "3", "Tags": [ "php", "validation" ], "Title": "Shortening if-statements of displaying errors" }
47636
<p>I've tried this <a href="http://codeforces.com/contest/412/problem/C" rel="nofollow">problem</a> on Codeforces. Given a set of string patterns, all of which are the same length, and which consist of literal lowercase ASCII characters and <code>?</code> wildcards, find a pattern that satisfies them all.</p> <p>I wa...
[]
[ { "body": "<p>Use more meaningful variable names, for example:</p>\n\n<ul>\n<li><code>lines</code> instead of <code>t</code></li>\n<li><code>length</code> instead of <code>l</code></li>\n<li>Since <code>y</code> is a character position, I would rename to <code>pos</code></li>\n<li><code>let</code> to <code>lett...
{ "AcceptedAnswerId": "47763", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T09:31:30.203", "Id": "47638", "Score": "6", "Tags": [ "python", "programming-challenge" ], "Title": "String pattern riddle" }
47638
<p>My goal is to parse defines in Objective-C code:</p> <pre><code>#define wowFont [UIFont fontWithName:(DEV)?@"one":@"two" size:(DEV? 10: 12)] #define wowColor [UIColor colorWithRed:(DEV?240/255.0f:255.0f) green:((DEV)? 230.0f / 255.0f) blue: 10.0f] </code></pre> <p>I try to write grammar for it:</p> <pre><code>gra...
[]
[ { "body": "<p>It doesn't look like this code is currently working.</p>\n\n<p>AFAIK Objective-C uses the normal C preprocessor. The preprocessor works on a token level, and does not know about stuff like method calls. It is entirely irrelevant that <code>[</code> starts a method call or an array subscript, for t...
{ "AcceptedAnswerId": "47649", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T09:59:42.833", "Id": "47639", "Score": "3", "Tags": [ "parsing", "perl", "grammar" ], "Title": "Perl 6: Grammar issues (simple defines)" }
47639
<p>I have some old RAR files and I know the general format of passwords I used to use, so I have generated a dictionary file combining those words in a variety of ways. The dictionary file is 500mb and I've wrote a python program to use the dictionary. </p> <p>The issue is that the program has been running all night a...
[]
[ { "body": "<p>The line that jumps out at me as being a performance concern is this one:</p>\n\n\n\n<pre><code>words = [line.strip() for line in infile]\n</code></pre>\n\n<p>You’re generating a list that contains every word in <code>dictionary.txt</code>. This means a 500&nbsp;MB dictionary file will create a si...
{ "AcceptedAnswerId": "47643", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T10:38:38.583", "Id": "47640", "Score": "7", "Tags": [ "python", "performance", "beginner" ], "Title": "RAR dictonary attack" }
47640
<p>I implemented Aho-Corasick string matching in Haskell. It is a purely functional implementation compared to many other implementations.</p> <p>The input to build an automata is <code>[([a],b)]</code>. which is a list of <code>(pattern,output)</code> pairs. <code>b</code> has to form a monoid, so we know what to do...
[]
[ { "body": "<p>It would be nice if the code was ordered for exposed functions versus internal helpers. It looks like <code>buildAutomaton</code> is the exposed API along with the <code>Automaton</code> data type. However, <code>buildAutomaton</code> is the one function missing any comments or docs.</p>\n\n<p><co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T10:53:47.790", "Id": "47642", "Score": "5", "Tags": [ "algorithm", "strings", "haskell" ], "Title": "Aho-Corasick string matching in Haskell" }
47642
<p>I'm a beginner developer, I'm learning online (mostly from the Apple documentation guides), and couple a days ago I started a notes app project. It's the first app I'm building without a guide.</p> <p>It's very simple so I'd love to post it here and get your feedback on how to improve my code to be more efficient.<...
[]
[ { "body": "<p>Look into the NSFetchedResultsController to power your table view. It's something specifically designed to be used with UITableViews that are powered by Core Data. </p>\n\n<p>In essence, it uses a fetch request and returns how many objects are in each section, how many sections there are, what hea...
{ "AcceptedAnswerId": "47655", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T11:35:07.263", "Id": "47645", "Score": "3", "Tags": [ "beginner", "objective-c", "ios" ], "Title": "Simple iPhone Notes app" }
47645
<p>I implemented a throttled database service trait for wrapping my service code in a future, supplying a slick session and throttling the # of requests in accordance to the length of the thread pool queue.</p> <p>My main reason for this was to transfer the responsibility for database session / transaction handling aw...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T12:30:29.473", "Id": "47647", "Score": "3", "Tags": [ "beginner", "scala" ], "Title": "Slick database throttling trait based on the Playframework Slick plugin" }
47647
<p>It seems like there are many ways implementing inheritance in JavaScript. Which version do you prefer or would you suggest another solution?</p> <p>The code should run in IE8+ so my first version would not fit…</p> <pre><code>function Animal(name) { this.name = name } Animal.prototype = { eat: function() {...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T23:34:52.873", "Id": "83579", "Score": "0", "body": "It looks like you're looking for opinions as to which to use, and not a code review." } ]
[ { "body": "<p>As Joseph mentioned, opinion questions is not what CodeReview is about.</p>\n\n<p>I tend to review every OO approach with these 4 questions:</p>\n\n<p><strong>Approach 1</strong></p>\n\n<ul>\n<li>Does <em>instanceof</em> still work ? -> Yes, good</li>\n<li>Do you introduce new properties, causing ...
{ "AcceptedAnswerId": "47686", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T14:10:41.650", "Id": "47650", "Score": "1", "Tags": [ "javascript", "object-oriented", "inheritance" ], "Title": "Simple inheritance with functions in subclasses" }
47650
<p>I'm trying to get a better handle of code organization and how HTML5 (really HTML) stack works in general. I've worked mostly with ASP.NET Webforms and done some MVC as well. Let me say now, "I hate magic". I hate figuring out the magic. I just want it to work in the manner that it's supposed to. So I posted this li...
[]
[ { "body": "<p>On the HTML side, don't use <code>&lt;br/&gt;</code> to force the content to a new line. Place contents in <code>&lt;div&gt;</code> instead.</p>\n\n<pre><code>&lt;div&gt;\n &lt;label for=\"linedesc\"&gt;Description:&lt;/label&gt;&amp;nbsp;\n ...\n&lt;/div&gt;\n&lt;div&gt;\n &lt;input id=\"fruit...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T14:33:17.420", "Id": "47652", "Score": "4", "Tags": [ "c#", "javascript", "beginner", "jquery", "html" ], "Title": "Is my web site structured correctly?" }
47652
<p>I learned to program in Java and C# and in my free time I am using Ruby because it is fun. Unfortunately I have the feeling that I write Ruby code like I am making Java or C# code. I have learned to use regex instead of strings for comparison, using each instead of for-loops, keeping method names lowercase, and how ...
[]
[ { "body": "<p><strong>Succinctness</strong><br>\nAs rubyists, we love being succinct, and we love playing with enumerations.</p>\n\n<p>You will see very few literal <code>false</code> and <code>true</code> in ruby code, as well as very few explicit <code>return</code> calls.</p>\n\n<p>For example:</p>\n\n<p>Ins...
{ "AcceptedAnswerId": "47697", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T16:10:00.987", "Id": "47656", "Score": "8", "Tags": [ "ruby", "primes", "mathematics", "programming-challenge" ], "Title": "Make Project Euler 27 solution idiomatic Ruby" }
47656
<p><a href="http://projecteuler.net/problem=29" rel="nofollow">Here's a link to the problem.</a> Is there any way I could optimize/speed up this code, perhaps make it more Pythonic?</p> <pre><code>"""How many distinct terms are in the sequence generated by a^b for 2 &lt;= a &lt;= 100 and 2 &lt;= b &lt;= 100?""" impor...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T16:42:35.573", "Id": "83530", "Score": "1", "body": "What would you like to know about your code? It appears correct to me. Are you trying to speed it up?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-0...
[ { "body": "<p>You should check the data structure that you use. You are currently using a list, checking if the power exists, and then doing it again when you append unique entries.</p>\n\n<p>If you use a set then you can skip the check and do an add of the power. This is significantly faster... about 50 time...
{ "AcceptedAnswerId": "47659", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T16:30:21.190", "Id": "47657", "Score": "1", "Tags": [ "python", "programming-challenge" ], "Title": "Project Euler 29" }
47657
<p>I am using Spring Framework, Hibernate and JUnit. I am testing persisting of a UserEntity. </p> <p>The UserEntity has the following associations:</p> <ul> <li>ManyToMany - City</li> <li>ManyToMany - ActivityCategory</li> <li><p>ManyToOne - UserType </p> <pre><code>@Test public void testCreateNotExistingEmail(...
[]
[ { "body": "<p>The name of your test method is <code>testCreateNotExistingEmail</code> but I don't see how it's related to what you're testing.</p>\n\n<p>What is the purpose of the test? Is it that you can successfully create a user entity if there is no other user entity with the same email? If so, then I would...
{ "AcceptedAnswerId": "47666", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T17:03:24.100", "Id": "47660", "Score": "21", "Tags": [ "java", "unit-testing" ], "Title": "Writing better JUnit tests" }
47660
<blockquote> <p>Write a function <code>undef</code> that will remove a name and a definition from the maintained by <code>lookup</code> and <code>install</code>.</p> </blockquote> <p>Here is my solution:</p> <pre><code>void undef(char *name) { struct Nlist *tmp = hashtab[hash(name)]; if(!strcmp(tmp-&gt;na...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T19:31:15.393", "Id": "83559", "Score": "0", "body": "Who wrote the rest of the program especially the `lookup` and `install` functions?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T19:55:12.727", ...
[ { "body": "<p>It's not necessary to special-case the head of the list if you think about it in a different way. In particular, each entry in your <code>hashtable</code> is a pointer to an <code>Nlist</code> structure, so if you take the <em>address</em> of the <code>hashtable</code> entry, you can treat it jus...
{ "AcceptedAnswerId": "47680", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T17:12:33.647", "Id": "47661", "Score": "2", "Tags": [ "c", "beginner", "linked-list", "hash-map" ], "Title": "Implementation of the undef function" }
47661
<p>I am working on this project that has a reservation form which allow users specify which sort of service they require. I have a select menu with eight (8) options and I have two divs which would either show/hide depending on the value of the option been selected. Seen below is the select element:</p> <pre><code>&lt...
[]
[ { "body": "<pre><code>// You can use the document.ready as both encapsulation as well as\n// to make sure the DOM is ready for operation.\n$(function ($) {\n\n // Unless these are dynamic (the set could change), it's better to cache them\n var optionBox = $('.optionBox');\n var dropOff = $('#dropOff');\n va...
{ "AcceptedAnswerId": "47683", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T17:19:12.467", "Id": "47662", "Score": "3", "Tags": [ "javascript", "jquery", "html" ], "Title": "jQuery conditional statement to check if a select option has either of 4 value...
47662
<p>I've this function to list products from database by category. I'm using prepared statements, but wouldn't this make it pretty pointless to use them?</p> <pre><code>function getProducts($category,$search_param,$pdo){ $query = "SELECT * FROM renkaat INNER JOIN ajoneuvotyypit ON tyyppiID = ajoneuvotyyp...
[]
[ { "body": "<p>Yes, <code>$category</code> in your query string, coming directly from <code>$_GET</code> is a problem.</p>\n\n<p>You should validate <code>$category</code>, and that's not exactly the same as escaping. I assume you have a limited set of valid categories in your database, so validation should be s...
{ "AcceptedAnswerId": "47668", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T17:53:24.817", "Id": "47667", "Score": "10", "Tags": [ "php", "sql", "pdo", "sql-injection" ], "Title": "Listing products from a database" }
47667
<p>I'm building a port scanner as an exercise. It contains a method to separate the ports that the user wants to have checked, which can include single ports and port ranges, ex: 22, 23, 80-120, 443-500, 1024, etc. It discards wrong ports such as negative ports, wrong range such as 120-80 instead of 80-120 which is the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T20:27:44.447", "Id": "83565", "Score": "1", "body": "Your code treats, e.g., \"123-45-678\" as identical to \"123-678\". Is that intentional? Is there a reason your code doesn't throw exceptions for crummy input, like \"1,-,2\" or \...
[ { "body": "<p>First thoughts...</p>\n\n<ul>\n<li>Use an interface for your return type (e.g., <code>IEnumerable&lt;int&gt;</code> instead of <code>List&lt;int&gt;</code>)</li>\n<li>Use a <code>SortedSet&lt;int&gt;</code> internally to get rid of duplicates, and do the sorting too. That should get rid of most of...
{ "AcceptedAnswerId": "47678", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T19:51:59.107", "Id": "47673", "Score": "5", "Tags": [ "c#", "algorithm", ".net" ], "Title": "Method to separate a list of ports to scan" }
47673
<p>This function tells that elements of content either (maybe) match regexes that you like or match regexes that you don't like.</p> <p>This messy code requires <code>Data.Text.Lazy</code> but internally shuffles around internal and strict versions. Also list Monad code looks fishy to me.</p> <p>How can it be made si...
[]
[ { "body": "<p>To fix lazy/strict shuffling you need to import <code>Text.Regex.TDFA.Text.Lazy</code> module. It contains TDFA-related instances for <code>Data.Text.Lazy</code></p>\n\n<p>Some other things to consider.</p>\n\n<p>You can skip <code>maybeToList</code> because <code>(=~)</code> returns <code>m targe...
{ "AcceptedAnswerId": "47719", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T21:20:54.237", "Id": "47679", "Score": "3", "Tags": [ "haskell", "regex" ], "Title": "How to simplify Regex with Data.Text?" }
47679
<p>I found myself writing code to run at a specified frequency more than once, so I decided to make this simple timer. My main concern is that this is not the most efficient way of doing this since with <code>SDL</code> I would just ask for the time in ms and sleep in ms.</p> <p>I'm storing the current time in <code>t...
[]
[ { "body": "<p>Rather than looping around <code>goto</code>, why not calculate how much time is remaining and convert it into ticks and <code>sleep (ticks)</code>? It would also be better to find some way to generate an event rather than lopping continuously, if timing is not very strict.</p>\n", "comments"...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T01:40:23.157", "Id": "47688", "Score": "10", "Tags": [ "c", "timer" ], "Title": "Is this timer efficient?" }
47688
<p><a href="http://developer.android.com/training/basics/fragments/communicating.html">Android documentation</a> says: </p> <blockquote> <p>Often you will want one Fragment to communicate with another, for example to change the content based on a user event. All Fragment-to-Fragment communication is done through the...
[]
[ { "body": "<p>As the <a href=\"http://developer.android.com/guide/components/fragments.html\" rel=\"nofollow\">Fragments doc</a> says:</p>\n\n<blockquote>\n <p>You can think of a fragment as a modular section of an activity</p>\n</blockquote>\n\n<p>A fragment that assumes the existence of another fragment brea...
{ "AcceptedAnswerId": "47698", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T01:46:16.333", "Id": "47689", "Score": "5", "Tags": [ "java", "android" ], "Title": "Communicating with other fragments or to activity" }
47689
<p>I have this code:</p> <pre><code>public class RecurLoopTest { public static void main(String[] args) { printit(2); } private static int printit(int n){ if(n&gt;0){ printit(--n); } System.out.print(n+","); return n; } } </code></pre> <p>I have d...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-08T12:29:43.293", "Id": "514188", "Score": "0", "body": "Wow, this diagram visually clearly communicates your _recursive_ algorithm: illustrated call-stack plus count-down iterator-parameter" } ]
[ { "body": "<p>It would be better to add the method arguments in the diagram, for example:</p>\n\n<pre><code>printit(0) -- n=0, prints \"0,\", returns 0\nprintit(1) -- n=1, prints \"0,\", returns 0\nprintit(2) -- n=2, prints \"1,\", returns 1\nmain()\n</code></pre>\n\n<p>I don't think you need 4 drawings side by...
{ "AcceptedAnswerId": "47696", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-20T02:34:16.047", "Id": "47691", "Score": "3", "Tags": [ "java", "algorithm", "recursion", "data-visualization" ], "Title": "Execution flow diagram (call-stack) of recursive c...
47691
<p>This is how it handles input:</p> <ul> <li>if negative, terminate program</li> <li>if 0-2, display input without calculating</li> <li>if greater than or equal to 3, calculate and display result</li> </ul> <p>I have also used some macros from an included file:</p> <ul> <li><code>nwln</code>: outputs a newline</li>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T09:06:52.943", "Id": "83605", "Score": "0", "body": "Why do you prefer macros over functions? Worried about performance (I might understand you if you were running on a 80386)?" }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<blockquote>\n <p>Is my input validation reducing readability, or is that not important as long as the program proceeds with only the correct input?</p>\n</blockquote>\n\n<p>Usually, \"does it implement required functionality?\" is even more important than \"is it readable?\"</p>\n\n<p>A \"Hello wor...
{ "AcceptedAnswerId": "47750", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T03:04:39.990", "Id": "47692", "Score": "5", "Tags": [ "performance", "validation", "assembly" ], "Title": "32-bit factorial calculator in x86 NASM assembly" }
47692
<p>I have a text file and I was curious about what character appears how often in the text.</p> <p>Any review is appreciated.</p> <pre><code>public class CountLetters { public static void main(String[] args) throws Exception { TreeMap&lt;Character, Integer&gt; hashMap = new TreeMap&lt;Character, Integer&g...
[]
[ { "body": "<h3>Resources:</h3>\n<p>You should start using <a href=\"http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html\" rel=\"noreferrer\"><code>try-with-resources</code>.</a> This statment does some work for you with resources that implement <code>AutoCloseable</code>. It closes...
{ "AcceptedAnswerId": "47707", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T10:28:02.340", "Id": "47704", "Score": "15", "Tags": [ "java" ], "Title": "Counting characters in a text file" }
47704
<p>Is this an efficient way to handle page requests in MVC?</p> <p>index.php:</p> <pre><code>require 'Classes/Autoloader.php'; Autoloader::start(); Session::start(); new Bootstrap(); </code></pre> <p>Bootstrap.php</p> <pre><code>class Bootstrap { private $controller = null, $action = null, ...
[]
[ { "body": "<p>MVC is a concept that stems from good OOP practices. It's about seperating your application to three different parts: <strong>Input<sub>Controllers</sub>, Processing<sub>Model</sub> and Output<sub>View</sub></strong>.</p>\n\n<p>What you are describing is the bootstrap page, which, at least from my...
{ "AcceptedAnswerId": "51850", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T11:06:08.030", "Id": "47706", "Score": "3", "Tags": [ "php", "mvc" ], "Title": "Handling page requests in MVC" }
47706
<p>I have this common design in my application:</p> <pre><code>public class MyListener1{ MyTask1 task1; MyTask2 task2; public class MyListener1{ public MyListener1(){ task1 = new MyTask1(this); task2 = new MyTask2(this); task1.execute(); task2.execute(); } public void onRes...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T14:05:48.960", "Id": "83629", "Score": "1", "body": "Something is not quite clear: you say that MyTask1 and MyTask2 have a little bit more code, but then you just merge them in one class. Is the \"little bit more code\" the same fo...
[ { "body": "<p>You could directly use the source object. This is commonly used in Swing when the same <code>ActionListener</code> has been added to more than one button. When the listener's <code>actionPerformed</code> method is invoked, the <code>EventObject</code> object that is passed featrues a <code>getSour...
{ "AcceptedAnswerId": "47713", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T11:32:10.777", "Id": "47709", "Score": "7", "Tags": [ "java", "callback" ], "Title": "Identify Java Callback" }
47709
<p>Here's my solution for <a href="http://projecteuler.net/problem=30" rel="nofollow">Project Euler Problem 30</a>. Any optimizations in time, space, or style would be greatly appreciated.</p> <pre><code>from timeit import default_timer as timer def digit_powers(exponent): def power(k): return int(k) ** e...
[]
[ { "body": "<p>In looking at your code, it seems well written and solves the problem in a straight forward manner. The one thing I would do is to remove the else after your argument check and remove a level of indent. That just helps to keep things flat... Flat is better than nested.</p>\n\n<p>Now onto optimiz...
{ "AcceptedAnswerId": "47721", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T12:50:10.993", "Id": "47714", "Score": "5", "Tags": [ "python", "programming-challenge" ], "Title": "Project Euler 30 -- Digit fifth powers" }
47714
<p>I'm making a game battle system, where there are 2 players.</p> <ul> <li>Every player can have multiple units to control, but only one at a time.</li> <li>Every unit has an <code>int curSpeed</code> variable;</li> </ul> <p>I need to have in 2 variables who attacks first (<code>Player f</code>) and who attacks seco...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T19:50:41.960", "Id": "83669", "Score": "0", "body": "if you want to show the new code, please post another question. you would invalidate the answers if you edit in the changes to this question" }, { "ContentLicense": "CC B...
[ { "body": "<p>Your code is indeed confusing, primarily because of the naming:</p>\n\n<p><code>f</code> should be <code>firstPlayer</code>, <code>s</code> should be <code>secondPlayer</code> and <code>curSpeed</code> should be <code>speed</code> or <code>currentSpeed</code> (it depends on whether there are other...
{ "AcceptedAnswerId": "47729", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T17:49:31.423", "Id": "47723", "Score": "6", "Tags": [ "c#", "game", "random" ], "Title": "Initial starting player" }
47723
<p>I am fairly new to Python and programming in general so I hope the code in this post is not too messy. I have the following code which I use for taking images from an IP security camera:</p> <pre><code>def Camera(timecount, cam_name, stream_url, username, password, work_dir, x): x = x work_dir = work_dir ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T18:51:13.047", "Id": "83657", "Score": "0", "body": "If you do not have the daemon code working then it is not yet ready for review. Other parts of your code may in fact be working, but, at this point, the overall question is off-to...
[ { "body": "<p>These statements are pointless, you can safely remove them:</p>\n\n<blockquote>\n<pre><code>x = x\nwork_dir = work_dir\n</code></pre>\n</blockquote>\n\n<hr>\n\n<p>The second statement is pointless, you can safely remove it:</p>\n\n<blockquote>\n<pre><code> sys.exit(2)\n sys.exit(0)\n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T18:14:54.333", "Id": "47726", "Score": "3", "Tags": [ "python", "beginner", "linux", "image", "networking" ], "Title": "Script for obtaining images from an IP security cam...
47726
<p>Does my code look secure right now? I know that I still have the password hashing and so forth, but what about SQL injections? Do I have any? Are there any other security issues?</p> <pre><code>&lt;?php $con=mysqli_connect("localhost","root","xxx","s"); // Check connection if (mysqli_connect_errno()) { echo "Fa...
[]
[ { "body": "<ol>\n<li>Consider parameterized queries over building a query string.</li>\n<li>If you really want to use encoding, do the encoding directly before passing it to mysql</li>\n<li>Factor out the password strength rules into a separate function. This function could output an array of violations.</li>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T18:29:26.750", "Id": "47728", "Score": "3", "Tags": [ "php", "security", "form" ], "Title": "Password hashing/handling on a form" }
47728
<p>I have a function called <code>mult2</code> that takes in two square NumPy matrices and returns a matrix that is the result of a special multiplication:</p> <pre><code>p=P(1,344) PI,PIT=[],[] for i in xrange(344): PI.append(p**i) PIT.append((p**i).transpose()) def mult2(a,b): C=np.sum((a*b)**2,axis=1) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T20:08:26.880", "Id": "83675", "Score": "0", "body": "for anyone interested in the math: http://mymathforum.com/linear-algebra/42813-can-i-calculate-sum-using-matrix-multiplication.html" } ]
[ { "body": "<p>From what I can tell, you could combine all of the for loops into only 2 distinct loops:</p>\n\n<ol>\n<li>A loop to setup the matrices used for later calculations</li>\n<li>A loop to do the rest of the calculations</li>\n</ol>\n\n<p>Instead of performing list comprehension to create an array to pa...
{ "AcceptedAnswerId": "47781", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T19:08:29.693", "Id": "47733", "Score": "4", "Tags": [ "python", "performance", "matrix", "numpy" ], "Title": "Performing a special multiplication on two square matrices" }
47733
<p><em>This is the updated code using all suggestions from the previous question that I made <a href="https://codereview.stackexchange.com/questions/47723/initial-starting-player">here</a>.</em></p> <p>I have revised the naming of the variables, and i have included the classes that this part of code is using, in order...
[]
[ { "body": "<p>Do without the ternary expressions: because a ternary expression is very good for initializing one variable, but is much less good for initializing two variables.</p>\n\n<pre><code>// Declared but not initialized (to null), in order to guarantee that\n// they are each initialized in the subsequent...
{ "AcceptedAnswerId": "47740", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T20:17:14.550", "Id": "47737", "Score": "6", "Tags": [ "c#", "game" ], "Title": "Initial starting player - v2" }
47737
<p>Please be über brutal, and treat this as a technical interview question.</p> <p>I was wondering how this function that I wrote looks like. It groups together words that have the same alphabets (i.e anagrams). </p> <p>Time Complexity: \$O(n^2)\$</p> <p>Space Complexity: \$O(n)\$</p> <pre><code>private static Lis...
[]
[ { "body": "<p>Use the right abstractions in method parameters and local variables, for example instead of:</p>\n\n<blockquote>\n<pre><code>private static List&lt;List&lt;String&gt;&gt; groupAnagrams(ArrayList&lt;String&gt; words){\n AbstractMap&lt;String, String&gt; sortedWords = new HashMap&lt;&gt;();\n</...
{ "AcceptedAnswerId": "47746", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T20:39:52.550", "Id": "47739", "Score": "3", "Tags": [ "java", "algorithm", "interview-questions" ], "Title": "Grouping Anagrams" }
47739
<p>This is a Python solution for all general cases. Any suggestions at all would be appreciated; in my opinion it's already quite good! <a href="http://projecteuler.net/problem=31" rel="nofollow">Here's a link to the problem.</a></p> <pre><code>from timeit import default_timer as timer def count_coins(target, operand...
[]
[ { "body": "<p>It will be faster if you pre-generate the <code>ways_to_make</code> array:</p>\n\n<pre><code>def count_coins(sum, coins):\n ways_to_make = [0 for _ in range(sum + 1)]\n ways_to_make[0] = 1\n for coin in coins:\n for t in range(sum + 1):\n if t &gt;= coin:\n ...
{ "AcceptedAnswerId": "47748", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T22:24:14.257", "Id": "47744", "Score": "1", "Tags": [ "python", "optimization", "programming-challenge" ], "Title": "Any way to optimize this already fast Python solution to Pr...
47744
<p>I'm writing a program to differentiate functions (perform basic calculus) in Haskell. The program works, but there's one function that looks very ugly to me:</p> <pre><code>--some prerequisite definitions --a mathematical value is either... data Value = Literal Double --a number, such as...
[]
[ { "body": "<p>It is a matter of taste but I think <code>reduce</code> will be a bit more cleaner with <code>case</code>.</p>\n\n<pre><code>reduce exp = case exp of\n Literal{} -&gt; exp\n Variable _ (Just var) -&gt; Literal var\n Variable _ Nothing -&gt; exp\n FCall f a b\n | isDefined f m...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T22:25:24.913", "Id": "47745", "Score": "2", "Tags": [ "haskell" ], "Title": "Function with excessively complex \"where\" clause" }
47745
<p>I made this math script, where you enter an equation and it solves it for you. I was wondering what you thought of the code, and what I could have done better or what doesn't follow Ruby best practices. The code is also on Github <a href="https://github.com/INOVA-Technology/Math" rel="nofollow">here</a> if you want ...
[]
[ { "body": "<p>There is a bug in your quadratic formula. Watch your operator associativity!</p>\n\n<p>I'm not a fan of the method names <code>qudrtc_frml_with_a_b_c</code> and <code>pythgrn_thrm_with_a_b</code>, and I think that the poor naming is a symptom of a poor class design.</p>\n\n<p>First of all, drpng ...
{ "AcceptedAnswerId": "47767", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T23:00:26.177", "Id": "47749", "Score": "3", "Tags": [ "ruby", "mathematics", "meta-programming" ], "Title": "Math Equation Solver" }
47749
<p>Please be brutal and treat this as me coding this up for an interview.</p> <p>A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T00:10:57.293", "Id": "83693", "Score": "0", "body": "I don't really understand what does deleting means (mentioned in the last sentence). A few more examples and (with the expected output) would help." }, { "ContentLicense":...
[ { "body": "<ol>\n<li><p>Calling the method with an empty array throws a <code>java.lang.NegativeArraySizeException</code>. You should check that and throw an exception with a helpful error message.</p></li>\n<li><p>You could extract out a <code>createDifferenceArray</code> method for better readability:</p>\n\n...
{ "AcceptedAnswerId": "47834", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T23:28:29.847", "Id": "47751", "Score": "7", "Tags": [ "java", "algorithm", "interview-questions", "dynamic-programming" ], "Title": "Finding alternating sequence in a list ...
47751
<p>The following is an implementation of a tree in C++ designed for keys which do not have an order (otherwise a <code>std::map</code> could be used). <code>T</code> is a key type and <code>H</code> is a hash for <code>T</code>. </p> <pre><code>#include &lt;iostream&gt; #include &lt;memory&gt; #include &lt;utility&gt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T00:39:13.880", "Id": "83696", "Score": "0", "body": "What is the usecase for this? I have a suspicion that a custom container built on top of unordered_map might be more fitting. It seems rather odd to have a recursive map that neve...
[ { "body": "<p>At least as it stands right now, quite a bit of your code accomplishes nothing.</p>\n\n<pre><code>template&lt;typename T, typename H&gt;\nclass tree;\n\ntemplate&lt;typename T, typename H&gt;\nclass tree : public std::unordered_map&lt;T, std::shared_ptr&lt;tree&lt;T, H&gt;&gt;, H&gt; { };\n</code>...
{ "AcceptedAnswerId": "48155", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T23:36:40.163", "Id": "47752", "Score": "5", "Tags": [ "c++", "c++11", "tree" ], "Title": "Tree implementation for unordered keys" }
47752
<p>I'm making a simple Tetris clone and would like to know how's my code for the map and pieces. I'm using <code>x</code>, <code>y</code>, <code>x_before</code>, <code>y_before</code>, <code>t0</code>, <code>t1</code> to allow smooth movement.</p> <p><strong>colors.h</strong></p> <pre><code>#ifndef TETRIS_COLORS_H #d...
[]
[ { "body": "<p>Overall this looks very nice. It's easy to read, and is very refined. A few notes:</p>\n\n<ul>\n<li><p>You can remove the <code>Map</code> from the first line of your structure.</p>\n\n<pre><code>typedef struct\n{\n Color *blocks;\n int rows;\n int columns;\n} Map;\n</code></pre></li>\n...
{ "AcceptedAnswerId": "47803", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T00:10:46.857", "Id": "47754", "Score": "7", "Tags": [ "c", "game", "tetris" ], "Title": "Tetris code for pieces and map" }
47754
<pre><code>public void fizzbuzz(int count, int max, String fizzer) { fizzer += (count % 3 == 0) ? "fizz":""; fizzer += (count % 5 == 0) ? "buzz":""; fizzer += (count % 3 != 0 &amp;&amp; count % 5 != 0) ? count:""; if (count != max) { fizzer += "\n"; fizzbuzz(count+1,max,fizzer); } el...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T00:32:29.547", "Id": "83694", "Score": "2", "body": "Is there a requirement that it has to be recursive? Otherwise that is what I would first get rid of." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-2...
[ { "body": "<p><code>fizzer</code> and <code>max</code> don't change: instead they could both be member data of the class (passed to the class constructor).</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T00:34:14...
{ "AcceptedAnswerId": "47762", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T00:25:36.327", "Id": "47755", "Score": "12", "Tags": [ "java", "optimization", "recursion", "fizzbuzz" ], "Title": "Short Java FizzBuzz using recursion and parameters" }
47755
<p>There are n balls kept on a table and connected by same singe connected string (which can be cyclic or maynot). Write the code to select a ball such that after lifting the whole structure from that ball height will be minimum. (algo+code+ mathematical proof of correctness)</p> <p>Note, I do understand merits of uni...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T02:05:34.883", "Id": "83703", "Score": "4", "body": "What is E and what is V in your complexity comments?" } ]
[ { "body": "<p>Your assignment sounds like the <a href=\"http://en.wikipedia.org/wiki/Travelling_salesman_problem\" rel=\"nofollow\">traveling salesman problem (TSP)</a>.</p>\n\n<p>If you're looking for the exact shortest path, you have to pretty much brute force the answer, since TSP is NP-hard problem.</p>\n\n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T00:39:24.127", "Id": "47758", "Score": "2", "Tags": [ "java", "algorithm", "graph" ], "Title": "Lift ball which leads to shortest height" }
47758
<p>I'm reading <a href="http://freespace.virgin.net/hugo.elias/models/m_perlin.htm" rel="nofollow">this tutorial</a> and it's the first time I try something this new.</p> <p>Here is my attempt:</p> <pre><code>import sys import math import pygame import random pygame.init() windowwidth, windowheight = 900, 500 window...
[]
[ { "body": "<p>To begin with, you <em>cannot</em> use <code>random.uniform()</code> in your current design. The tutorial specifically emphasize that the noise function shall be seeded, that is, for the same argument it shall always return the same result.</p>\n\n<p>Second, the tutorial suggests that each octave...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T00:53:27.527", "Id": "47759", "Score": "3", "Tags": [ "python", "python-3.x", "pygame" ], "Title": "Write and control Perlin noise for 1D" }
47759
<p>I am a beginner and I have made Login Form in HTML. I'm pretty sure it will look horrible to any developer, but hey, that's why I've posted it.</p> <p>I'd like a general review of this. I'm especially concerned about the quality and enhancements of this form.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XH...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T11:13:58.597", "Id": "83731", "Score": "0", "body": "Since username and password fields are mandatory so you can mark these fields as required. <input type=\"text\" id=\"username\" name=\"username\" required>" }, { "Content...
[ { "body": "<p>Security-wise, you need to make sure you a) never trust the user and b) never trust the user.</p>\n\n<p>You should realise that anyone has access to the <code>GET</code> parameters, lines like </p>\n\n<pre><code>&lt;?php echo @$_GET['msg'];?&gt;\n</code></pre>\n\n<p>should thus be avoided. Always...
{ "AcceptedAnswerId": null, "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T10:57:29.703", "Id": "47771", "Score": "22", "Tags": [ "php", "html", "css", "form", "authentication" ], "Title": "Login Form in HTML" }
47771
<p>I have implemented Insertion sort in Java. Please review it.</p> <pre><code>public class InsertionSort { public static void main(String[] args) { int[] values = new int[args.length]; for (int i = 0; i &lt; args.length; i++) { values[i] = Integer.parseInt(args[i]); } fo...
[]
[ { "body": "<p>Consider this:</p>\n\n<blockquote>\n<pre><code>for (int i = 0; i &lt; values.length; i++) {\n if (i!=0 &amp;&amp; values[i] &lt; values[i - 1]) {\n</code></pre>\n</blockquote>\n\n<p><code>i</code> starts from 0, and then right after you use a condition <code>i!=0</code>. You could simplify to:<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T13:03:08.363", "Id": "47779", "Score": "4", "Tags": [ "java", "optimization", "sorting", "insertion-sort" ], "Title": "Insertion Sort implementation in Java" }
47779
<p>This is my code for reading a file with a delimiter. Any suggestions to help improve my code efficiency?</p> <p>I am not satisfied with using array data structure. Can any other data structure be used instead of an array?</p> <pre><code>bool read_file(char *p_file_name,char *file_content[FILE_NO_OF_ROWS][FILE_NO...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T15:51:03.840", "Id": "83757", "Score": "3", "body": "Since your delimiter is a char have you tried using the delimiter overload for getline, `std::getline(file_is_obj,buffer,delimiter);`, to return the string up to but not including...
[ { "body": "<p>Some comments:</p>\n\n<ol>\n<li>Use <code>std::vector</code> instead of an inflexible array. You're writing in C++, so you really ought to use the power of that language to write better code.</li>\n<li>Don't use <code>memset</code>. It's generally wise to avoid mixing old-style C library functio...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T14:34:10.200", "Id": "47784", "Score": "4", "Tags": [ "c++", "optimization", "performance", "file" ], "Title": "Reading a file and storing the contents in an array" }
47784
<p>I would like to submit a portion of my code for Code Review, and I have done my best to comment the code (and include essential parts that may aid understanding of the program) for your convenience! Any optimisation that would increase the speed of the running of the program would be appreciated!</p> <p>The program...
[]
[ { "body": "<p>First, some basics:</p>\n\n<ul>\n<li><p>Vector is a class that is deprecated.... actually, not deprecated, but discouraged....</p>\n\n<blockquote>\n <p>As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a member of the Java Collections Framework....
{ "AcceptedAnswerId": "47795", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T15:25:28.057", "Id": "47789", "Score": "10", "Tags": [ "java", "optimization", "xml" ], "Title": "Civilization 5 mod validator" }
47789
<p>Could you please review my script?</p> <pre><code>#!/bin/ksh T=/bb/bdap/bin/cms/tools U=$T/upgrader mv $T/conbase_updates $U/conbase_updates.br.drqs$1 cd $U grep "^BR" config.alpha &gt; config.br ./ConbaseUpgrader config.br conbase_updates.br.drqs$1 </code></pre>
[]
[ { "body": "<p>You might want to validate the value of <code>$1</code>, or at least that it's not empty, for example add a line like this near the top:</p>\n\n<pre><code>test \"$1\" || { echo usage: $0 param; exit 1; }\n</code></pre>\n\n<hr>\n\n<p>You are not checking for errors, for example what will happen if ...
{ "AcceptedAnswerId": "47794", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T16:10:04.353", "Id": "47793", "Score": "2", "Tags": [ "ksh" ], "Title": "ksh script to perform an upgrade" }
47793
<p>I am wondering if my current unit tests could be written better, I am most interested in whether it is possible to make the code look more concise, as currently it a <em>boiler-plated mess</em>.<br> I have full access to Java 8, if that would help by making it more concise.</p> <p>The <code>Arguments</code> class i...
[]
[ { "body": "<p><strong>Test Names</strong></p>\n<p><code>testRequirePositive_intIAE1()</code> doesn't tell me anything besides what function is being tested. It is helpful to give some context as to why you think it should throw an exception. What makes <code>testRequirePositive_intIAE1()</code> different from <...
{ "AcceptedAnswerId": "47802", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T17:00:15.030", "Id": "47797", "Score": "10", "Tags": [ "java", "unit-testing" ], "Title": "Unit tests for an argument-checking class" }
47797
<p>I often find myself doing this (or similar) with Lists and other collection types:</p> <pre><code>if (someList != null &amp;&amp; someList.Count &gt; 0) //take some action on the list </code></pre> <p>so I got lazy and wrote the following extension methods to do it for me:</p> <pre><code> public static boo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T17:35:17.930", "Id": "83782", "Score": "0", "body": "If you want to use the `.Count` property, you should extend `ICollection` directly, or else this could fail on otherwise valid collections. Use the `.Count()` method in an IEnumer...
[ { "body": "<p>It looks handy, but I have some thoughts on it.</p>\n\n<p>Firstly: when you create your own <code>IEnumerable&lt;T&gt;</code> and don't implement <code>ICollection</code>, you'll get a logical error. It will try to convert it with <code>as</code>, which will return <code>null</code> because the co...
{ "AcceptedAnswerId": "47805", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T17:18:08.633", "Id": "47800", "Score": "5", "Tags": [ "c#", "extension-methods" ], "Title": "Lazy man's IEnumerable extension verification method" }
47800
<p>Suppose I have a nested class structure like this:</p> <pre class="lang-cs prettyprint-override"><code>namespace My.Namespace { public class Foo { public class Bar { public class Baz { public string Test { get; set; } } } } } </code></pre> <p>I need...
[]
[ { "body": "<p>It sounds like this might be what you are looking for I think.</p>\n\n<p><a href=\"http://msdn.microsoft.com/en-us/library/system.type.reflectedtype%28v=vs.110%29.aspx\" rel=\"nofollow\">Type.ReflectedType Property (.NET 4.5)</a> </p>\n\n<pre><code>GetType(t).ReflectedType;\n</code></pre>\n\n<p>I...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T17:36:59.677", "Id": "47804", "Score": "7", "Tags": [ "c#", ".net", "reflection" ], "Title": "Get nested type name without namespace" }
47804
<p>How do I optimize this code further? Goal is to edit "js-tab" in one place. <a href="http://css-tricks.com/how-do-you-structure-javascript-the-module-pattern-edition/" rel="nofollow">This</a> is what I tried to follow.</p> <p>Full code <a href="http://codepen.io/TDogg137/pen/yKzlj/" rel="nofollow">here</a>.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T10:03:42.593", "Id": "83896", "Score": "0", "body": "Optimise for what - speed, memory, source file size? And what would be an acceptable value at which point you'll stop optimising? Unless you can answer these, you're wasting your ...
[ { "body": "<p>From a once over;</p>\n\n<ul>\n<li>You are selecting the content <code>div</code>s with a class name, you should select them with an <code>id</code> instead</li>\n<li>It is much more readable, to simply hide all content, and then show what you need.</li>\n</ul>\n\n<p>With that I would counter prop...
{ "AcceptedAnswerId": "47818", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T18:04:31.810", "Id": "47806", "Score": "8", "Tags": [ "javascript", "jquery" ], "Title": "Optimize this jQuery tab controller further" }
47806
<p>I finally managed to get the code to work properly. It makes the player object move faster if the user double taps the arrow key with a few 'ticks' (new frames) after the 1st stroke. - User presses and has a limited time to press again to sprint the object. If the time runs out the user has to try again.</p> <p>How...
[]
[ { "body": "<p>From a once over</p>\n\n<ul>\n<li>Indentation is terrible, consider using a tool like <a href=\"http://jsbeautifier.org\" rel=\"nofollow\">jsbeautifier.org</a>, it works for ActionScript as well</li>\n<li>Keep working with <code>Event.ENTER_FRAME</code> &lt;- It is the better approach in my mind</...
{ "AcceptedAnswerId": "47817", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T18:24:29.693", "Id": "47812", "Score": "4", "Tags": [ "beginner", "classes", "actionscript-3" ], "Title": "Character Sprint Spaghetti Code" }
47812
<p>I'm trying to code following requirements with lockfree in most-used-code-path that is to get a resource from pool.</p> <ol> <li><p>Same resource should be used n (<code>maxUsageCount</code>) number of times and then destroyed and create a new one.</p></li> <li><p>If there is an error with a resource, it should be ...
[]
[ { "body": "<p>Welcome to Code Review.</p>\n\n<p>You have posted an very good quality post and that's why it takes so long to get an answer.</p>\n\n<p>I have 2 minor remarks to make.</p>\n\n<h2>First :</h2>\n\n<pre><code>if (maxUsageCount &lt; 0) throw new IllegalArgumentException();\n</code></pre>\n\n<p>You do ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T18:48:13.027", "Id": "47816", "Score": "12", "Tags": [ "java", "concurrency" ], "Title": "java.util.concurrent bounded resuable resource implementation" }
47816
<p>I have a website where people can write articles and publish/unpublish them. This is done via single button on the page:</p> <pre><code>&lt;a id="publish-button" href="#" class="btn btn-default &lt;%= 'btn-success' if @article.published? %&gt;"&gt; &lt;span class="glyphicon glyphicon-globe"&gt;&lt;/span&gt; &lt...
[]
[ { "body": "<p>You could theoretically overload the <code>show</code> action to only return the partial <code>if request.xhr?</code>. So if it's an ajax request, only render that button partial. But that's inelegant.</p>\n\n<p>Alternatively, you can simply keep the default <code>show</code> action, send the enti...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T19:40:17.187", "Id": "47823", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Rails preventing ajax view duplication" }
47823
<p>I've got some architecture in my code similar to this. It is about the Construct method in the base class in the example below. This method contains the logic for constructing a building, which is the same in every building. Yet different buildings may want to do things differently, like a different roof. So I've us...
[]
[ { "body": "<p>This works but is very unusual. The standard way of doing this would actually be virtual methods</p>\n\n<pre><code>public abstract class building {\n ...\n protected virtual CreateWalls() {\n //create 4 walls by default\n }\n protected virtual CreateFoundation() {\n //straightforw...
{ "AcceptedAnswerId": "47831", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T19:55:06.663", "Id": "47825", "Score": "2", "Tags": [ "c#", "inheritance", "event-handling" ], "Title": "Can this architecture of base + derived classes be coded more efficient...
47825
<p>I've translated this code from <a href="/questions/tagged/c%23" class="post-tag" title="show questions tagged &#39;c#&#39;" rel="tag">c#</a> and would like it to be more idiomatic <a href="/questions/tagged/f%23" class="post-tag" title="show questions tagged &#39;f#&#39;" rel="tag">f#</a>:</p> <pre><code>namespace ...
[]
[ { "body": "<p>Your code seems like it's primarily plumbing. There are no algorithms or types that could be given the functional treatment. I have only two recommendations. </p>\n\n<ol>\n<li><p>Instead of <code>NinjectWebCommon</code> being abstract/sealed with static members you can make it a module with let-bo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T20:14:09.187", "Id": "47828", "Score": "3", "Tags": [ "f#", "ninject" ], "Title": "NinjectWebCommon implementation/translation - C# to F#" }
47828
<p>This is my first ever real 100% self made perl script, I'd like to know how I can improve it.</p> <pre><code>#!/usr/bin/env perl #this script takes a directory and sorts the files into folders by file ending use strict; use warnings; use File::Copy; sub sort_files { my $dir = shift || '.'; #cwd if no dire...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T22:36:48.270", "Id": "83848", "Score": "0", "body": "Also note that directory 0 cannot be specified as the argument." } ]
[ { "body": "<p>I've added a few comments in your source,</p>\n\n<pre><code>#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\nuse autodie; # automatic die/checks for http://search.cpan.org/~pjf/autodie/lib/autodie.pm#CATEGORIES\nuse File::Copy;\n\nsub sort_files {\n # my $dir = shift || '.';\n my $dir = sh...
{ "AcceptedAnswerId": "47852", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T21:10:26.513", "Id": "47833", "Score": "4", "Tags": [ "perl", "file-system", "file", "directory" ], "Title": "Perl file sorting script" }
47833
<p>I was asked to provide the solution of this rolling dice problem in an interview. When I showed him my solution, he said that there is another way to find the solution. I am looking for answer in PHP script only.</p> <blockquote> <p>Question:</p> <p>Two persons are playing a game of rolling 2 dices. Each person roll...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T02:39:25.457", "Id": "83865", "Score": "0", "body": "Couldn't you just compare the two arrays directly? Ideally after sorting." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-04T15:32:56.473", "Id": ...
[ { "body": "<p>Based on your use of <code>in_array()</code>, you don't appear to be concerned with the order of the elements. In that case, you can simply sort the arrays and compare them directly.</p>\n\n<pre><code>function compare($array1, $array2)\n{\n sort($array1);\n sort($array2);\n\n return ($arr...
{ "AcceptedAnswerId": "47843", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T21:30:34.447", "Id": "47835", "Score": "5", "Tags": [ "php", "array", "interview-questions", "php5", "dice" ], "Title": "Optimized solution for a rolling dice code puzz...
47835
<p>I've written a program to simulate a game of <a href="http://en.wikipedia.org/wiki/Mafia_%28party_game%29">Mafia</a> among several bots. Here's the directory structure the program lives in (to make understanding parts of the program easier):</p> <pre class="lang-none prettyprint-override"><code>/ start README.md ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T15:53:58.250", "Id": "85318", "Score": "0", "body": "Love the code looks awesome. You going to compile to exe so we can all play it?" } ]
[ { "body": "<p>Overall, it looks pretty good to me. I agree that you have good commenting and variable and function naming. I see just a few things to comment on.</p>\n\n<ul>\n<li><p>You have assign_roles() nested inside get_players(). Is there a reason for doing this? Unless there's a good one, I'd recommend pu...
{ "AcceptedAnswerId": "47936", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T21:32:26.777", "Id": "47836", "Score": "11", "Tags": [ "python", "game", "python-2.x" ], "Title": "Mafia game simulation engine" }
47836
<p><a href="https://codereview.stackexchange.com/q/39521/27623">I posted my audio recording program to Code Review before</a>, and received <a href="https://codereview.stackexchange.com/a/47694/27623">a stern review</a> along with the other reviews that caused me to rewrite the entire code base. Here is what I would li...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2019-11-03T14:16:16.580", "Id": "452212", "Score": "0", "body": "We are not aware of the duration we would like to record until silence. Please suggest ways to modify the code to record until silence of say a given duration." } ]
[ { "body": "<p>Few notes.</p>\n\n<p>First, you don't want to copy data in the loop. Call <code>memset()</code>/<code>memcpy()</code> instead. You need some very serious reason to <em>not</em> use standard library. Here is some example code:</p>\n\n<pre><code>dataSize = sizeof(*wptr) * data-&gt;numberOfChannels ...
{ "AcceptedAnswerId": "47844", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T00:04:12.543", "Id": "47840", "Score": "10", "Tags": [ "performance", "c", "audio", "portability" ], "Title": "Recording audio in C 2.0" }
47840
<p>My requirement is to convert a sequence of numbers into a display string as below.</p> <p>Example </p> <blockquote> <p><strong>Input</strong></p> <p>1,2,3,4,5,7,7,8,8,8,10,15,10,11,12,88,87,86</p> <p><strong>Output</strong></p> <p>1-5,7-8,10-12,15,86-88</p> </blockquote> <hr> <pre><code>void mak...
[]
[ { "body": "<p>State flags usually indicate a design problem.</p>\n\n<p>How about this instead (after vector is sorted) :</p>\n\n<pre><code>template &lt;typename I&gt;\nI get_sequential_range(I first, I last)\n{\n I end_range = ++first;\n while ((end_range != last) &amp;&amp;(*end_range &lt;= *first + 1)) ...
{ "AcceptedAnswerId": "47871", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T04:20:34.653", "Id": "47845", "Score": "7", "Tags": [ "c++", "strings", "c++11", "converting" ], "Title": "Convert sequence of number into display string" }
47845
<p>I've been looking for an implementation of Tarjan's algorithm in C#/C++ for a strongly-connected components in graphs, and couldn't find any implementation without use of additional Stack - most of them just follow <a href="http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm" rel="norefer...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T20:42:25.080", "Id": "84033", "Score": "0", "body": "It appears, upon my admittedly hasty reading of this code, that you've merely replaced an external stack with three external arrays. Is that an accurate observation? If so, I'm co...
[ { "body": "<h1>Brace Usage</h1>\n\n<p>It is generally considered best practice to always use braces with control statements (such as \"if\" and \"for\" statements). If you are concerned with whitespace, consider that placing the opening brace on the same line as the control statement means that the total increa...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T04:25:22.573", "Id": "47846", "Score": "8", "Tags": [ "c#", "algorithm", "graph" ], "Title": "Tarjan's algorithm for Strongly Connected Components without keeping SCC in stack" }
47846
<p>I have a site where user accounts can be created in two ways: by new users (sign up) and by admin users. Since the creation is handled differently in each case, I decided to split the logic into two separate functions. I have a working implementation but I'm pretty new to Rails so I don't know if it is robust and se...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T19:00:32.817", "Id": "84019", "Score": "0", "body": "You have a bug in your `#create` method: The `elsif` branch will _never_ be reached. If you're signed in, you'll trigger the first branch immediately; if you're not signed in, it'...
[ { "body": "<p>It's fine to create 2 methods to break up the logic a bit - however, there are other things I'd look into before tackling the user vs admin stuff:</p>\n\n<p>Firstly: Ruby style prescribes 2-spaces indentation - not tabs, not 4 spaces.</p>\n\n<p>Second, if you're going to use them, make those <code...
{ "AcceptedAnswerId": "47917", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T04:30:55.853", "Id": "47847", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Creating user accounts as an administrative user" }
47847
<p>I've been learning Java lately and had some great feedback from the previous threads (hangman and guess a number games). I was challenged by a user to try to get this code done, so I'm posting it here for further review. Basically my weakeast (among many) points are exception handling and proper documentation. What ...
[]
[ { "body": "<p>It's largely fine by me. :)</p>\n\n<p>Just one glaring point: your implementation would not return the first line, as <code>getRandomNumber()</code> will not return <code>0</code>.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T04:44:52.700", "Id": "47848", "Score": "8", "Tags": [ "java", "random", "file", "io" ], "Title": "Read from a file and pick a random line" }
47848
<p>I'm trying to make a backend for QuizUp like application: user connects to a server, sends credentials and gets paired up with another user. After that server handles each pair, periodicaly sending server messages to each user in a pair and also redirecting user's mesages between them.</p> <p>Server class:</p> <pr...
[]
[ { "body": "<h1>Blocking I/O doesn't scale well</h1>\n\n<p>Blocking I/O usually requires a 1:1 coupling between threads and streams. Thin clients can get away with using blocking I/O, because they're not going to have 100+ connections open. For servers with long-lasting connections, it's not workable.</p>\n\n<...
{ "AcceptedAnswerId": "47908", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T06:09:36.843", "Id": "47851", "Score": "8", "Tags": [ "java", "multithreading", "socket", "server" ], "Title": "Multi-threaded socket server high load" }
47851
<p>In case the table has class <code>'trans'</code> - run <code>dataTable()</code> and <code>columnFilter()</code>; otherwise just run <code>dataTable()</code>.</p> <p>Is it possible to <strong>not repeat</strong> the <code>dataTable()</code> part?</p> <pre><code>$('#dt_a').each(function() { if ($(this).hasC...
[]
[ { "body": "<p>Use some variables. You don't need to chain function calls; it's just a neat thing you <em>can</em> do when appropriate, but it's not required.</p>\n\n<pre><code>$('#dt_a').each(function() {\n var target = $(this), // store this \n table = target.dataTable({ // and store this too\n ...
{ "AcceptedAnswerId": "47858", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T08:03:56.540", "Id": "47857", "Score": "1", "Tags": [ "javascript", "jquery", "jquery-datatables" ], "Title": "Making a datatable, maybe also with column filters" }
47857
<p>A month ago I finished and posted my <a href="https://codereview.stackexchange.com/questions/45091/tic-tac-toe-feedback-requested">first version</a> of my Tic-Tac-Toe, I received a lot of good feedback and refactored it to more closely suit the MVP design pattern. </p> <p>I've done some further clean-ups and refact...
[]
[ { "body": "<pre><code>Grid -&gt; public Cell this[int index, int index2]\n</code></pre>\n\n<p>I'm not pro but I think that:</p>\n\n<ul>\n<li>you should create function for checking if index is validate - you use same ugly condition twice.</li>\n<li>you could not check if index is correct at all... Does it matte...
{ "AcceptedAnswerId": "47875", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T09:29:55.537", "Id": "47861", "Score": "7", "Tags": [ "c#", "object-oriented", "mvp" ], "Title": "Follow-Up Post Tictactoe now with AI" }
47861
<p>I have seperated my project into two projects. One is the web forms project and the other is the Model project with contains a generic repository implementation, a service class for each of my entities and a UnitOfWork class. All the code below apart from the last section is in my Model class library project.</p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T10:54:30.993", "Id": "83900", "Score": "1", "body": "Welcome. Nice complete question. Hope you find the answers your looking for." } ]
[ { "body": "<p>I've used the Generic repository solution myself in the past. At first I found it really great but after a while as the project got a bit bigger it started to feel a bit restrictive and didn't seem to offer much benefits for the amount of code written. </p>\n\n<p>The more I read the more it appe...
{ "AcceptedAnswerId": "47866", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T10:04:36.613", "Id": "47865", "Score": "6", "Tags": [ "c#", "design-patterns", "entity-framework" ], "Title": "Database first entity framework, repository, service, UnitOfWork ...
47865
<p>I am trying to build an efficient function for splitting a list of any size by any given number of indices. This method works and it took me a few hours to get it right (I hate how easy it is to get things wrong when using indexes).</p> <p>Am I over-thinking this? Can you help me minimize the code? I am just not se...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T11:26:10.060", "Id": "83906", "Score": "0", "body": "Welcome to codereview.stackexchange. In order to make reviewing easier for everyone, can you tell us a bit more about what your function is supposed to do and how it does it ? Als...
[ { "body": "<p>A few cosmetic changes to makes your code more beautiful/pythonic :</p>\n\n<p><strong>Fix formatting</strong></p>\n\n<ul>\n<li>Remove some line breaks as it makes the code harder to read</li>\n<li>Change variables name to follow <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"norefer...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T11:15:12.413", "Id": "47868", "Score": "15", "Tags": [ "python", "python-2.x" ], "Title": "Splitting a list by indexes" }
47868
<p>I am a fairly new (RubyonRails) developer. I desire to improve my coding skills so I used climate to do some review on my code. It gave me a flag for this method that its complex. Is it characterised as complex because of having several "actions/tasks" in a single method?</p> <p>Will it be better if I extract some ...
[]
[ { "body": "<p>I'd say to first make a service object to keep the controller lean and clean, and to give yourself a place to put all the logic without fear of polluting the controller. Plus: It's reusable!</p>\n\n<pre><code># app/services/user_search.rb\n\nclass UserSearch\n ORDER_MAPPING = {\n \"cost\" ...
{ "AcceptedAnswerId": "47899", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-22T12:15:17.063", "Id": "47872", "Score": "3", "Tags": [ "ruby", "ruby-on-rails", "active-record" ], "Title": "Filtering users by criteria in Ruby on Rails" }
47872
<p>I wrote a script that moves files older than two days over to a network share (via scheduled task). Windows Task Scheduler doesn't seem to like the script so much, but it works well by itself. </p> <ol> <li><p>Is there a faster way than what I have?</p></li> <li><p>Is there a way to programmatically make it a sched...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T13:51:07.633", "Id": "83933", "Score": "0", "body": "What happens if the destination folder already has a file with that name ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T14:15:42.820", "Id":...
[ { "body": "<p>Okay, I'll start by trying to answer your questions first.</p>\n\n<ol>\n<li><p>If there is a lot of files and you should look into using runspaces to run several copy-jobs in separate threads. Just be careful, you are still limited by the bandwidth of the network.</p></li>\n<li><p>We need to see s...
{ "AcceptedAnswerId": "60126", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T12:15:42.187", "Id": "47873", "Score": "6", "Tags": [ "file", "windows", "powershell" ], "Title": "Fastest Windows script to move files from one did to a network dir" }
47873
<p>Important fact: the number of the input is greater than 1. How do I use this fact to speed up this solution?</p> <pre><code>public class subSetSumR{ // Solving Subset sum using recursion public static boolean subSetSumRecur(int [] mySet, int n, int goal){ if (goal ==0){ return true;} if ((goal&lt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T21:51:45.473", "Id": "84042", "Score": "0", "body": "Consider switching to a [dynamic programming solution](http://en.wikipedia.org/wiki/Subset_sum_problem#Pseudo-polynomial_time_dynamic_programming_solution)." } ]
[ { "body": "<p>At times to speed up a recursion you can use <a href=\"http://en.wikipedia.org/wiki/Memoization\" rel=\"nofollow\">memoization</a> to cache the results of your previous known calculations, trading memory for speed. (Memoization is slightly different to dynamic programming.)</p>\n\n<blockquote>\n ...
{ "AcceptedAnswerId": "47880", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T13:18:19.403", "Id": "47878", "Score": "8", "Tags": [ "java", "algorithm", "performance", "recursion", "combinatorics" ], "Title": "Speeding up subset sum implementatio...
47878
<p>Based on the reply of this <a href="https://stackoverflow.com/questions/23111868/unit-of-work-pattern-implementation">question</a> I have created the following code. I need to check whether it's good or not.</p> <p>Here is my entity class:</p> <pre><code>public class Employee { public int Id { get; set; } ...
[]
[ { "body": "<p>The <code>Context</code> in this situation isn't correct. The <code>Context</code> should have all your <code>dbSets</code>. With the <code>UnitOfWork</code> pattern there is only 1 instance of the <code>Context</code>. It is used by your repositories (<code>DbSet</code>s) and by the <code>Unit...
{ "AcceptedAnswerId": "47904", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T13:18:44.260", "Id": "47879", "Score": "46", "Tags": [ "c#", "entity-framework", "asp.net-mvc" ], "Title": "Unit of Work and Repository with Entity Framework 6" }
47879
<p>I have a collection of phrases in a <code>List</code>. Each phrase is a <code>String Array</code> where each element in the array is a word.</p> <p>I create a <code>List&lt;Entry&lt;String, Integer&gt;&gt;</code> which holds the <code>words</code> as keys and the <code>times used</code> as value. Everything is sort...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T14:28:26.837", "Id": "83945", "Score": "2", "body": "Any special reason you are using a `List<Entry<...>>` instead of a `Map`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T14:30:36.560", "Id": ...
[ { "body": "<p>A few notes for now:</p>\n\n<p>You're not using generics for your iterator, if you use</p>\n\n<pre><code>Iterator&lt;Entry&lt;String, Integer&gt;&gt; entries = wordsMap.iterator();\n</code></pre>\n\n<p>and <code>Entry&lt;String, Integer&gt; entry = entries.next();</code></p>\n\n<p>you won't have t...
{ "AcceptedAnswerId": "47919", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T14:14:25.530", "Id": "47884", "Score": "11", "Tags": [ "java", "performance" ], "Title": "Printing the most used words from phrases" }
47884
<p>Below is a simple Trade class with minimal business logic: primarily a method to get market value associated with the trade. But the trade needs the following pieces of <em>core</em> functionality, orthogonal to any business logic:</p> <ul> <li>Need to be serializable to/from JSON (<code>toJson</code>/<code>fromJso...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T11:47:14.830", "Id": "85292", "Score": "0", "body": "Alex Tatumizer pointed out an issue with hashCode. It needs to apply mask to prevent going beyond smi. \n\nconst MASK=(1<<31)-1;\nresult = ((result*prime)&MASK + date.hashCode)&MA...
[ { "body": "<p>Here are some first pass thoughts:</p>\n\n<p>Initial thoughts...</p>\n\n<ul>\n<li><p>Your whitespace isnt consistent with the dart<a href=\"https://www.dartlang.org/articles/style-guide/\" rel=\"nofollow noreferrer\">style guide</a>.</p></li>\n<li><p>reflection probably is overkill here and has si...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T14:22:45.413", "Id": "47887", "Score": "2", "Tags": [ "dart" ], "Title": "Providing core functionality orthogonal to business logic in Dart" }
47887
<p>JavaScript's <code>setTimeout()</code> and <code>setInterval()</code> are evil and not precise:</p> <ol> <li><p><a href="https://andrewduthie.com/2013/12/31/creating-a-self-correcting-alternative-to-javascripts-setinterval/" rel="nofollow noreferrer">Both functions have a delay of a varying quantity of milliseconds...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T15:09:50.127", "Id": "83958", "Score": "4", "body": "`requestAnimationFrame` is called on average 60 times per second.. At first sight, your code is far eviler." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<h1>Update 4/23/2014:</h1>\n<p>Okay then, off to your updated code. Nothing much I can do here now. Here are some generic code optimization tips:</p>\n<ul>\n<li><p>Name stuff verbosely. It's one issue I find with others' code. They tend to name it like <code>t</code> for time, or <code>l</code> for l...
{ "AcceptedAnswerId": "47892", "CommentCount": "10", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-22T14:54:23.100", "Id": "47889", "Score": "17", "Tags": [ "javascript", "memory-management", "datetime", "animation" ], "Title": "Alternative to setInterval and setTimeout" }
47889
<p>I feel like just because the below works doesn't mean it is correct, I want to improve it but I can't really figure out how. Besides the fact it is down right ugly I feel the performance could be increased a lot also.</p> <p>Am I even using the Entity Framework and/or LINQ the way it is supposed to be used?</p> <p>S...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-01T21:12:21.187", "Id": "506618", "Score": "1", "body": "I [changed the title](https://codereview.stackexchange.com/posts/47890/revisions) so that it describes what the code does per [site goals](https://codereview.stackexchange.com/qu...
[ { "body": "<h1>Architecture</h1>\n<p>One thing that jumps forward is that you're going straight from the UI to your datasource. In a three-layer design (UI, Model, Persistence) or MVC (Model, View, Controller) there is always a layer between the UI and your datasource.</p>\n<p>A samplesetup would be this:</p>\n...
{ "AcceptedAnswerId": "47909", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-22T15:09:28.347", "Id": "47890", "Score": "5", "Tags": [ "c#", "design-patterns", ".net", "linq", "entity-framework" ], "Title": "Displaying information about an order whe...
47890
<p>I needed a super simple parser to get HTML attributes and their values. I didn’t want to load a big library or anything so I made this.</p> <p>I realize I am making assumptions here, mainly:</p> <ul> <li>Attribute values will be surrounded with either single or double quotes.</li> <li>The input string will end wit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T15:51:09.633", "Id": "83982", "Score": "1", "body": "“I didn't want to load a big library” Are you sure that's more work than an unreadable line-long regex that you're not sure actually works correctly?" }, { "ContentLicense...
[ { "body": "<ol>\n<li>Whitespace around <code>=</code> is allowed, your regex won't handle that.</li>\n<li>Characters in HTML can be encoded, some characters (like <code>&amp;</code>) have to be encoded. For example <code>name=\"AT&amp;amp;T\"</code> should return that the value of <code>name</code> is <code>AT&...
{ "AcceptedAnswerId": "47896", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T15:27:14.737", "Id": "47893", "Score": "1", "Tags": [ "c#", "html", "parsing", "regex" ], "Title": "Is this a safe way to parse out HTML tag attributes?" }
47893
<p>A manager for a speedy async saving objects to isolated storage, using serialization from Newtonsoft.Json. A project to play with is <a href="https://isostoragemanager.codeplex.com/" rel="nofollow">here</a>.</p> <pre><code>public static async Task&lt;T&gt; ReadJsonEx&lt;T&gt;(String filepath) { if (Stri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T17:23:16.767", "Id": "84972", "Score": "2", "body": "These edits can probably earn you some rep if you word them into an answer / \"selfie\" review ;)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T1...
[ { "body": "<p>This is very neat. Just a few code formatting nitpicks:</p>\n\n<blockquote>\n<pre><code> if (String.IsNullOrEmpty(filepath))\n return default(T);\n\n return await await Task.Factory.StartNew(async () =&gt;\n {\n using (var store = IsolatedStorageFile.GetUserStoreForApplicati...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T16:20:08.963", "Id": "47897", "Score": "4", "Tags": [ "c#", "json", "async-await", "windows-phone", "windows-phone-7" ], "Title": "IsoStorageManager" }
47897
<p>I just wrote this short little program to increment up the build number for my projects every time I build them.</p> <p>After compiling this exe, I just call it in the pre-build command line.</p> <p>I did take out the filename string because I used it thrice, and I figured I'd get some flack if I didn't.</p> <pre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T17:16:34.520", "Id": "84006", "Score": "0", "body": "How about just having `[assembly: AssemblyVersion(\"1.0.*\")]` in your *AssemblyInfo.cs* file?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T17:2...
[ { "body": "<p>There is way too much code in that last line. I'm not a stickler for wrapping at 80 character, but 280 characters seems like a bit much. Just because this is a build step script doesn't mean you code doesn't have to be readable. Write a real function to do this operation so I don't have to trust t...
{ "AcceptedAnswerId": "47910", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T17:07:28.650", "Id": "47900", "Score": "19", "Tags": [ "c#", "linq", "lambda" ], "Title": "Increment up the build number in AssemblyInfo.cs on every build" }
47900
<p>The goal here is to create a Top Level Menu that automatically pulls child pages without the need to manually add them to said menu. I didn't know any other way to accomplish this without a walker, of which I'm not very familiar with. </p> <p>I was playing around with it and was able to get the submenus to work wit...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T14:52:51.273", "Id": "47903", "Score": "2", "Tags": [ "php", "wordpress" ], "Title": "Automatic submenu" }
47903
<p>Here is another portion of the <a href="https://codereview.stackexchange.com/questions/47789/civilization-5-mod-validator">same program</a> that I would like optimizing (85-95% of the time running the program is spent within this class!!!) so that it runs faster, especially for users who have less powerful computers...
[]
[ { "body": "<p>Without the full program, I can't profile runs to prove where issues are and that my suggestions will improve them, so I'm guessing a bit. Further, I have no knowledge of Civilization 5's file structure so please gloss over misuse of terms. That said, I do have some suggestions and an angle or t...
{ "AcceptedAnswerId": "48368", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T19:21:03.433", "Id": "47911", "Score": "5", "Tags": [ "java", "optimization" ], "Title": "Civilization 5 Mod validator part 2" }
47911
<p>Dart is an open-source, class-based, optionally-typed programming language for building web applications--on both the client and server--created by <a href="/questions/tagged/google" class="post-tag" title="show questions tagged &#39;google&#39;" rel="tag">google</a>. Dart’s design goals are:</p> <ul> <li>Create a ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T19:22:36.213", "Id": "47912", "Score": "0", "Tags": null, "Title": null }
47912
Dart is a class-based, optionally-typed programming language for building web and command-line applications. Dart compiles to modern JavaScript to run on the client and runs natively on the Dart VM for server-side apps.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T19:22:36.213", "Id": "47913", "Score": "0", "Tags": null, "Title": null }
47913
<p>I am trying to make this code that creates accounts in a cpanel/whm account more secure.</p> <p>Could someone please let me know what needs to be done to make this more secure?</p> <pre><code>&lt;?php /////// YOUR WHM LOGIN DATA $whm_user = "username"; // reseller username $whm_pass = "password"; // the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T19:33:51.473", "Id": "84020", "Score": "0", "body": "@Jamal, I don't see the reason behind your edit! the code already creates accounts so that works fine. I just need to make it more secure!" }, { "ContentLicense": "CC BY-S...
[ { "body": "<p>Let's start with the easy fish - <code>$_REQUEST</code>. Going by the <a href=\"http://www.php.net/manual/en/reserved.variables.request.php\" rel=\"nofollow noreferrer\">PHP manual</a>, <code>$_REQUEST</code> is a combination of <code>$_POST</code>, <code>$_GET</code>, and <code>$_COOKIE</code>. <...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T19:26:32.143", "Id": "47915", "Score": "1", "Tags": [ "php", "security" ], "Title": "Creating accounts in a cpanel/whm account" }
47915
<p>Looking for help refactoring the following code to follow a Functional Programming paradigm.</p> <p>The first function builds a configuration object with default settings and optional presets, while the <code>buildResourcePath</code> will assemble a URL for the image service.</p> <p><code>getSizedUrl</code> and <c...
[]
[ { "body": "<pre><code>// Store everything in a scope. It's to preven you from polluting the global\n// scope as well as protect your code from collisions.\n;(function(ns) {\n\n // Pulling out constants into this scope. They only need to be declared once.\n var imgSvcPath = './imageSizer.svc';\n var defaults ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T20:50:53.737", "Id": "47918", "Score": "6", "Tags": [ "javascript", "functional-programming", "url" ], "Title": "Refactor module for calls to internal image service" }
47918
<p>I have a question regarding a program that is to run an alarm clock and display the time (HH:MM AM/PM) and also trigger the alarm and display "ringing" at 12:00 AM.</p> <p>I am a beginner in Java and I am a little lost. I believe I have most of the skeletal work done. This is much like another question asked on her...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T22:04:55.480", "Id": "84046", "Score": "2", "body": "Here on [codereview.se] we are used to long questions don't worry too much about it. Welcome, btw. I hereby also invite you to our [chat], feel free to drop in now and then ;)" ...
[ { "body": "<p>One bug is that your constructor initializes the clock to an invalid state: <code>amOrPm</code> is set to an empty string.</p>\n\n<p>You keep a seven state variables: <code>hour</code>, <code>minute</code>, <code>amOrPm</code>, <code>alarmHour</code>, <code>alarmMinute</code>, <code>alarmAmOrPm</c...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T21:51:03.340", "Id": "47921", "Score": "7", "Tags": [ "java", "beginner", "datetime" ], "Title": "Alarm clock with \"ringing\" functionality" }
47921
<p>Please be super brutal, and treat this as a top technical interview.</p> <p>Worst case analysis: \$O(n)\$ (please confirm)</p> <p>Space complexity: \$O(n)\$</p> <blockquote> <p><strong>Problem:</strong></p> <p>Given an absolute path for a file (Unix-style), simplify it.</p> <p>For example:</p> <pre><...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T22:59:05.220", "Id": "84061", "Score": "0", "body": "Have you though of 'cd /;cd ../../A/AA/' Where does that go? Or more specifically '/../../A/AA/'" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T23...
[ { "body": "<p>Overall, it is very easy to read and understand your code. I think that you make good choices of data structures.</p>\n\n<p>A few things:</p>\n\n<ul>\n<li><p>I'm not very fond of your spacing formatting, but at least you're consistent which makes this a minor issue. I prefer, and the Java styling ...
{ "AcceptedAnswerId": "47927", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T22:11:05.660", "Id": "47923", "Score": "7", "Tags": [ "java", "algorithm", "interview-questions" ], "Title": "Simplifying a path" }
47923
<blockquote> <p>We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.</p> <p>The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product ...
[]
[ { "body": "<p>As far as I know Project Euler problems, a brute force approach just doesn't work. So, we shouldn't code code, but rather an algorithm review.</p>\n\n<p>An immediate thing coming to mind is that you test too many knowingly impossible combinations of <code>a</code> and <code>b</code>. They together...
{ "AcceptedAnswerId": "47941", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T22:59:04.880", "Id": "47931", "Score": "4", "Tags": [ "python", "performance", "programming-challenge" ], "Title": "How to make Project Euler 32 in Python faster?" }
47931
<p>Some recursive code is part of a particularly slow path of a project. Out of curiosity I was playing around with reimplementing the code using stack context iteration instead of recursion. Below are snippets reduced to just the iteration patterns of tree elements using a DOM structure for simplicity. </p> <p>I was ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T00:13:35.967", "Id": "84072", "Score": "0", "body": "Have you tried profiling the routines, perhaps with Google Chrome's developer tools or something like that? That should tell you where most of the time is being spent." }, { ...
[ { "body": "<p>I would have completely agreed with the idea that iterative should be faster than recursive, I have seen proof to that effect many times in other languages. It is however harder to read. Here however, in JavaScript perhaps it is not, at least the benchmarks seem to suggest that the necessary obj...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T23:01:05.667", "Id": "47932", "Score": "29", "Tags": [ "javascript", "performance", "recursion", "tree", "iteration" ], "Title": "Recursion vs iteration of tree structure"...
47932
<p>I am creating a converter for use in a Windows 8 XAML app (MVVM). As you can see in the code below, the converter is used to convert a bool into one of two strings from a language resource file.<br> My question is, is it better to create one instance of <code>ResourceLoader</code> for the converter class or should ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T01:39:58.003", "Id": "84077", "Score": "2", "body": "Are you sure you should be newing up ResourceLoader objects at all? It seems like [Windows.ApplicationModel.Resources.ResourceLoader](http://msdn.microsoft.com/en-us/library/windo...
[ { "body": "<h1>Use an Attribute</h1>\n\n<p>The class should be tagged with:</p>\n\n<pre><code>[ValueConversion(typeof(Boolean), typeof(String))]\n</code></pre>\n\n<p>If it's of the normal, old-school .NET variety (desktop, client profile, WP8). Windows store apps don't appear to have an analogous attribute in t...
{ "AcceptedAnswerId": "47942", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T00:11:40.253", "Id": "47938", "Score": "3", "Tags": [ "c#", "performance" ], "Title": "Is it better to create a class instance, or create an instance each time a method is called?"...
47938
<p>I somehow acquired the idea that I should reduce the number of trips to the database as much as possible and so I use a lot of very long queries. </p> <p>For example, I had a function that does this:</p> <pre><code>$shelf = get_shelves($shop_id) foreach($shelf) { $weight = get_weight($shelf); } </code></pre> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T04:49:18.547", "Id": "84101", "Score": "0", "body": "If this is an optimization can only be decided by profiling." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T05:17:59.777", "Id": "84104", ...
[ { "body": "<p>You are on the right track about trying to reduce trips to the database. I think the rule of thumb would be: whatever gives the best overall performance ;-)</p>\n\n<p>A single query will almost always outperform <code>N</code> queries. Sometimes you may have the choice between two single queries: ...
{ "AcceptedAnswerId": "47948", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T04:27:16.227", "Id": "47947", "Score": "2", "Tags": [ "sql", "mysql", "mysqli" ], "Title": "Abusive use of long database query?" }
47947
<p>Recently, I wrote a Sudoku solver in C++. My program is very hard and was solved in a few seconds. In my opinion, this is slow.</p> <pre><code>#include &lt;iostream&gt; #include &lt;conio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; using namespace std; int tab_in[9][9] = {{0,0,0,0,0,0,0,1,0}, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T08:10:53.147", "Id": "84107", "Score": "1", "body": "First step is to profile, where the time is spent. Do not waste your time in optimizing parts that are not the bottleneck." }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>Here are some comments that will help you write a better program.</p>\n\n<h2>If you're writing C++, use C++</h2>\n\n<p>You have included a number of plain C headers, one of which (<code>conio.h</code>) isn't even a Posix standard. Instead, write C++ instead of C++ in a C style. There are many bo...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T06:40:50.267", "Id": "47949", "Score": "9", "Tags": [ "c++", "beginner", "sudoku" ], "Title": "Optimizing Sudoku solver in C++" }
47949
<p>The title is somewhat a misnomer; my apologies. The goal of the procedure is to partition a range of <code>first, last</code> by <code>mid</code> for the postcondition</p> <pre><code>max(first, mid) &lt;= min(mid, last) </code></pre> <p>The actual code (<code>best_n.h</code>):</p> <pre><code>#include &lt;algorith...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-18T09:27:01.833", "Id": "95293", "Score": "0", "body": "As I understand the algorithm the output is not sorted, it is only guaranteed to have the best n elements in some arbitrary order in the first n positions of the range. A fair com...
[ { "body": "<p>A couple of points on the style rather than the algorithm itself. </p>\n\n<p>First, I find the <code>#ifdef</code> for the typename peculiar, it detracts from clarity, and is a pointless use of macros, it may be fine for a small snippet but in a large project or a library header such a thing can w...
{ "AcceptedAnswerId": "47968", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T06:56:49.813", "Id": "47950", "Score": "6", "Tags": [ "c++", "algorithm", "c++11" ], "Title": "select_best: yet another partitioning algorithm" }
47950
<pre><code>private void log(MethodExecutionArgs args, string message, LogLevel level) { var calling_ip = ((System.Web.Services.WebService)args.Instance).Context.Request.UserHostAddress; string method = args.Method.Name; LogEventInfo logInfo = new LogEventInfo(level, logger.Name, message); lo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T11:17:57.260", "Id": "84131", "Score": "0", "body": "What kind of improvements are you looking for?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T11:38:17.797", "Id": "84134", "Score": "0", ...
[ { "body": "<p>One possible change would be to use object initializer to set up the properties:</p>\n\n<pre><code>var logInfo = new LogEventInfo(level, logger.Name, message)\n{\n Properties = { { \"method\", method }, { \"calling_ip\", calling_ip } }\n};\n</code></pre>\n\n<p>But I'm not sure this actually imp...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T07:53:23.817", "Id": "47954", "Score": "1", "Tags": [ "c#" ], "Title": "Logging the caller ip in a asmx web service using NLog" }
47954
<p>I find myself frequently trying to build up Seq's based on some conditionals, but the code I end up with feels verbose and clunky. An example:</p> <pre><code>def generateSeq(foo: Option[String]) = { Map("bar" -&gt; "baz") ++ ( if (foo.isDefined) { Map("foo" -&gt; foo.get) } else { Nil } ) } </...
[]
[ { "body": "<p>It is completely possible to write your Python code in the same style in Scala, just because you have an immutable collection doesn't mean you can't add elements to it - the syntax just looks differently.</p>\n\n<p>One example to rewrite your function:</p>\n\n<pre><code>def generateObject(foo: Opt...
{ "AcceptedAnswerId": "48007", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T07:59:32.573", "Id": "47955", "Score": "4", "Tags": [ "scala" ], "Title": "What is the best way to conditionally add to an immutable collection in Scala?" }
47955
<p>Please verify security from SQL injection attacks.</p> <p><strong>homepage.php</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;ul id="list"&gt; &lt;li&gt;&lt;h3&gt;&lt;a href="search.php?name=women-top"&gt;tops&lt;/a&gt;&lt;/h3&gt;&lt;/li&gt; &lt;li&gt;&lt;h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T08:34:19.760", "Id": "84110", "Score": "0", "body": "Is `$parts1` used at all ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T08:35:12.810", "Id": "84111", "Score": "0", "body": "no sir....
[ { "body": "<p>You are not validating and not escaping <code>$_GET['name']</code>.</p>\n\n<p>Although <a href=\"https://codereview.stackexchange.com/users/20270/wouter-j\">@wouter-j</a> pointed out in a comment that the prepared statement should protect you, <a href=\"https://security.stackexchange.com/questions...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T08:21:31.603", "Id": "47956", "Score": "-1", "Tags": [ "php", "sql", "mysql", "security" ], "Title": "Is this shopping site safe from SQL injection attacks?" }
47956
<p>I have defined some <code>DataTemplates</code> are similar. The templates are like this:</p> <pre><code> &lt;DataTemplate x:Key="DefaultCellTemplate"&gt; &lt;TextBlock Text="{Binding Value}"&gt; &lt;i:Interaction.Behaviors&gt; &lt;beh:AddErrorButtonAdornerToControlsBehavior ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T08:23:58.797", "Id": "101021", "Score": "0", "body": "Is there any difference expected between the data templates?" } ]
[ { "body": "<p>Real inheritance is not possible in <code>DataTemplate</code> through XAML, as far as I know. What you can do with is use a nested construction of <code>DataTemplate</code>s.</p>\n\n<p>The method boils down to using a <code>ContentPresenter</code> and setting the <code>ContentTemplate</code> prope...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T08:43:17.393", "Id": "47957", "Score": "0", "Tags": [ "wpf", "xaml" ], "Title": "Defining a DataTemplateBase" }
47957
<p>I’m trying to improve my code’s "signal to noise ratio", hence would appreciate any tips on improving this, what appears to be smelly code. Perhaps there could also be potential performance improvements to be made here:</p> <pre><code>public class PricingInfoDto { [DataMember] public decimal ListPrice { get...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T11:42:47.033", "Id": "84135", "Score": "2", "body": "I'm not sure if `decimal` is actually going to help you when the source data is in `float`s and `double`s." } ]
[ { "body": "<p>You are ignoring the whole point of decimals. Which is to avoid rounding errors from floating point caclulations.</p>\n\n<p>You must cast <code>TaxRate</code>, <code>ListPrice</code>, <code>ContributionPercentage</code>, etc. to <code>Decimal</code> and only then do your calculations using <code>D...
{ "AcceptedAnswerId": "47960", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T09:13:45.947", "Id": "47958", "Score": "4", "Tags": [ "c#", ".net" ], "Title": "Excessive number casting & conversion?" }
47958
<p>I have implemented quickly the quick sort algorithm in JavaScript using prototype based style.</p> <p>The code is rather short (<a href="http://jsfiddle.net/b8mfY/" rel="nofollow">http://jsfiddle.net/b8mfY/</a>):</p> <pre><code>&lt;script&gt; "use strict"; var Sort = function( inputArray ) { this.arrayTest =...
[]
[ { "body": "<p>Looks okay to me.</p>\n\n<ul>\n<li>I would probably go for <code>if ( i != j ) {</code> which could be faster than <code>if ( i &lt; j ) {</code></li>\n<li>You have a ton of short variable names, I guess that's ok for a sorting routine, though I would still rename <code>x</code> to <code>m</code>(...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T10:11:17.770", "Id": "47963", "Score": "2", "Tags": [ "javascript", "algorithm", "sorting", "quick-sort", "prototypal-class-design" ], "Title": "Quick sort implementation ...
47963
<p><strong>Background</strong></p> <p>I'm using MS Exchange 2013 in my environment, and have a separate siem box which analyze logs produced by different systems (i.e exchange). The logs for Exchange are internally stored and can however be extracted such as </p> <blockquote> <pre><code>Get-MailboxAuditLog -Identity ...
[]
[ { "body": "<p>You have multiple syntax errors. As a start, I would fix those. Also, fix up the indenting to make it easier to see what is going on. Which editor are you using? You could try using the PowerShell ISE. It will show you some of your errors with red wiggly lines.</p>\n\n<p>As a general strategy, I w...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T10:22:24.307", "Id": "47964", "Score": "2", "Tags": [ "windows", "powershell" ], "Title": "Writing a small script to extract MS Exchange audit logs in .csv format" }
47964
<p>I've realized JS callback hell and I started looking into Promises libraries. After reading some articles I decided to start with <a href="https://github.com/petkaantonov/bluebird" rel="nofollow">BluebirdJS</a>. I didn't realise how to properly use them yet, because documentation written with API examples, not real ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T17:23:33.150", "Id": "84196", "Score": "0", "body": "what is Api? Why are you creating new Promise when api.query already returns a promise?" } ]
[ { "body": "<ol>\n<li>Don't use explicit returns in CoffeeScript unless you have to (and you don't here)</li>\n<li>CoffeeScript may do automatic comma insertion, but I certainly didn't right away (i.e. add a comma yourself, right before <code>reject</code> - anything to make it easier to read)</li>\n</ol>\n\n<p>...
{ "AcceptedAnswerId": "48009", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T10:37:57.997", "Id": "47965", "Score": "1", "Tags": [ "node.js", "asynchronous", "coffeescript", "promise" ], "Title": "Promises and chained calls" }
47965