body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>As part of <a href="https://codereview.stackexchange.com/a/40088/35408">this answer</a>, I created a mixin to generate some page-specific CSS for me.</p> <p>I need to style an element based on a class I assign to the <code>html</code>-element. I do this for four different classes on the root-element, which gives me...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T16:33:51.743", "Id": "68733", "Score": "0", "body": "Questions like this (ie. how do I make my mixin generate the desired output) are generally better suited for SO." } ]
[ { "body": "<p>This uses mappings, which are part of Sass 3.3. You can do the same thing without mappings, it's just not as pretty. In addition to allowing multiple selectors, it allows for more options than just light/dark colors (eg. background images, etc):</p>\n\n<pre><code>$themes:\n ( blog:\n ( d...
{ "AcceptedAnswerId": "40753", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-31T20:01:42.993", "Id": "40574", "Score": "8", "Tags": [ "optimization", "css", "sass", "scss" ], "Title": "Improve mixin that outputs page-specific CSS" }
40574
<p>Upon suggestion in the original question within Stack Overflow, I'm bringing <a href="https://stackoverflow.com/questions/21489330/complex-data-structure-organization-in-javascript?noredirect=1#comment32438189_21489330">this question</a> here.</p> <p><strong>Question Explained:</strong></p> <p>In a website that I ...
[]
[ { "body": "<p>While there's nothing completely wrong with what you did, if I were the programmer coming in behind you - I would certainly curse your name. Writing \"good\" code (to me of course) requires more than meeting the objectives. Readability and maintainability are just as important.</p>\n\n<p>My conc...
{ "AcceptedAnswerId": "40581", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-31T21:14:18.407", "Id": "40576", "Score": "1", "Tags": [ "javascript", "jquery", "array" ], "Title": "Complex data structure organization in javascript?" }
40576
<p>I'm looking for feedback on my library for extracting words from a text: <a href="https://npmjs.org/package/uwords" rel="nofollow">https://npmjs.org/package/uwords</a></p> <p>The extracted word is defined as sequence of Unicode characters from Lu, Ll, Lt, Lm, Lo groups. So the code of the main part is (<a href="htt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T00:47:33.750", "Id": "68424", "Score": "0", "body": "I have not used node js. However, I wonder if you could simply use string replace?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T01:58:28.003", ...
[ { "body": "<p>I have not used node js. However, I wonder if you could simply use string replace? For example, </p>\n\n<pre><code>v = 'I was walking down the park on day. I was running down the block'\nj = message.replace(/was/g, '')\n</code></pre>\n\n<p>The output would be the following. </p>\n\n<pre><code>'I ...
{ "AcceptedAnswerId": "40623", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-31T21:24:28.413", "Id": "40578", "Score": "0", "Tags": [ "javascript", "parsing", "node.js", "unicode" ], "Title": "node.js library for extracting words from a text" }
40578
<pre><code> function reg(email, pass){ $.ajax({ url: "uman.php", type: "post", data:{email: email, password: pass}, success: function(reply){ if (reply == "success"){ $("#signinup").hide(); ...
[]
[ { "body": "<p>What do you think about this?</p>\n\n<pre><code>var Request = {\n version: 1.0, //not needed but i like versioning things\n xproxy: function(type, url, data, callback, timeout, headers, contentType) \n {\n if (!timeout || timeout &lt;= 0) { timeout = 15000; }\n $.ajax(\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-31T22:00:09.070", "Id": "40583", "Score": "2", "Tags": [ "javascript", "jquery", "ajax", "authentication" ], "Title": "JQuery/AJAX registration" }
40583
<p>My teacher assigned us to do the recursive version of mergesort, yet I heard that the non-recursive version (bottom up) is a bit tougher, so I decided to this one as well. My main concerns are: </p> <ol> <li>Considering the way I coded it, does it still have the same efficiency?</li> <li>Did I do this in an accepta...
[]
[ { "body": "<p>I have not looked into it too deeply to be able to fully answer your first question. Althought for you to get a picture of efficiency I would suggest to take the normal recursive merge sort and time it using <code>System.nanoTime()</code> and compare it with this version on the same array to be so...
{ "AcceptedAnswerId": "40639", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-31T22:41:49.153", "Id": "40585", "Score": "7", "Tags": [ "java", "optimization", "algorithm", "recursion", "mergesort" ], "Title": "Is this non-recursive mergesort efficie...
40585
<p>I have built this conceptual design of a localization menu on this <a href="http://codepen.io/JGallardo/pen/jyqzo" rel="nofollow noreferrer">CodePen</a></p> <p><img src="https://i.stack.imgur.com/a7ruz.png" alt="Concept 2"></p> <p>I am wondering if I should have structured my <code>&lt;div&gt;</code>s better or if...
[]
[ { "body": "<p>This should be an <code>ul</code>. Even without CSS you will have a navigational structure. How about giving your nav a better suited name like <code>.nav-localization</code>?</p>\n\n<p>Also I guess the <code>div</code>'s inside your links will act like as sub navigations? These would be <code>ul<...
{ "AcceptedAnswerId": "40602", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-31T23:26:14.637", "Id": "40586", "Score": "5", "Tags": [ "html", "css" ], "Title": "Is this HTML structure and CSS DRY enough in this country selection menu?" }
40586
<p>A discussion arose not long ago <a href="http://chat.stackexchange.com/transcript/message/13486960#13486960">on the 2nd Monitor</a> about how much reputation has been lost due to the reputation caps. There are a number of queries on the SEDE which try to address this:</p> <ul> <li><a href="http://data.stackexchange...
[]
[ { "body": "<p>Going through this code again, it appears there are a few things that could be improved.</p>\n\n<h2>Use #Temp Table for User Selection</h2>\n\n<p>Instead of doing a cheap-shot UNION select to get the set of users to process, the right way would be to create a temp table, and then conditionally pop...
{ "AcceptedAnswerId": "40794", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T03:09:36.300", "Id": "40595", "Score": "22", "Tags": [ "sql", "sql-server", "t-sql", "stackexchange", "cursor" ], "Title": "Calculating Lost Reputation" }
40595
<p>I am a self taught coder taking a Programming Fundamentals class to work towards a degree. It's based on Python, which I'm not as familiar with as other languages. I added error handling like I would in javascript or php to be an overachiever. Professor gave online feedback (online course) not to use try-except, tha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T03:44:40.743", "Id": "68443", "Score": "4", "body": "[What makes a good question?](http://meta.codereview.stackexchange.com/questions/75/what-makes-a-good-question) suggests you start with a description of the problem which the code...
[ { "body": "<p>I don't think <code>try</code> <code>except</code> <code>else</code> is a standard python construction - does it even execute? In that sense this does not look 'well formed'. Does this execute? It does not work when copy pasted but I think that's just formatting issues.</p>\n\n<p>It's hard to wr...
{ "AcceptedAnswerId": "40638", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T03:29:10.897", "Id": "40596", "Score": "7", "Tags": [ "python", "exception-handling", "python-3.x", "converting", "validation" ], "Title": "Simple MPG calculator in Pyt...
40596
<p>I need to validate the form inside a table and change the class of a <code>td</code>-element when the value is not set. I don't have a button inside a form and I can't use the jQuery <code>validate</code> script.</p> <p>I have written this code but is there a way to do this in a simpler way?</p> <p>I have written ...
[]
[ { "body": "<p>Here are some minor refactoring tips. You should put this function into a class/object, if you are repeating your code. And then import the file onto each html page that requires this validation. </p>\n\n<p>You shouldn't check if the variable is empty this way</p>\n\n<pre><code>if ( cognome != '')...
{ "AcceptedAnswerId": "40626", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T10:19:26.043", "Id": "40606", "Score": "4", "Tags": [ "javascript", "php", "html5" ], "Title": "Validating a form without using a button and changing td class" }
40606
<p>I have a huge list of regexes (>1,000 but &lt;1,000,000) that I want to test against (many) single strings.</p> <p>It is unlikely and unintended that more than one such expression would match a single string. I could just maintain a big list of each compiled, individual regex and iterate over that for every input s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T11:43:16.010", "Id": "68466", "Score": "0", "body": "If you have > 1000 regular expressions to test, **are you really sure that you want to use regular expressions?** It sounds to me like you are building a parser of some kind, in w...
[ { "body": "<ol>\n<li>I think it's a neat idea, because you're indeed using well-tested code, which reduces the chance of errors.</li>\n<li>Looking at the <code>re</code> API, you do need to retrieve all possibles matches using <code>groupdict()</code>.</li>\n<li>Even that one is not a gotcha since you're naming...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T11:27:59.993", "Id": "40607", "Score": "6", "Tags": [ "python", "strings", "regex" ], "Title": "Trying multiple regexes against a single string" }
40607
<p>I've recently started to delve into the world of windows phone 8 dev, and as a learning experience I've decided to make a stopwatch application. Now, given I've been a web guy most of my career, I've never come across UI thread locking issues, so the solution I've come up with to ensure my stopwatch class is updatin...
[]
[ { "body": "<p><strong>Minor</strong></p>\n\n<ol>\n<li><p>You should get rid of the <code>Class</code> suffix. There is no value in attaching the type as a suffix to the name. </p></li>\n<li><p>You don't need to write <code>this</code> everywhere to access members.</p></li>\n<li><p>You have an <code>Elapsed</cod...
{ "AcceptedAnswerId": "40646", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T12:23:35.377", "Id": "40609", "Score": "5", "Tags": [ "c#", "task-parallel-library", "windows-phone" ], "Title": "Non locking UI code in WP8" }
40609
<p>I am building a Python app in which user can maintain wishlist of the products. I only support few e-commerce sites and do not support country specific sites (e.g I may support amazon.com but not amazon.in). I do not support mobile version of the URL (e.g. <a href="http://m.amazon.com" rel="nofollow">http://m.amazon...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T09:19:52.577", "Id": "68551", "Score": "0", "body": "You allow https but `get_url` always uses http. Is that right?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T09:39:39.007", "Id": "68553", ...
[ { "body": "<p>The two helper functions feel redundant to me; <code>'http://'+url</code> is clear enough as is, and there is an <code>urlunparse</code> in <code>urlparse</code> module.</p>\n\n<p>My proposal:</p>\n\n<pre><code>def get_vendor(url):\n parsed_url = urlparse(url)\n if not parsed_url.scheme:\n ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T13:26:07.837", "Id": "40612", "Score": "3", "Tags": [ "python", "url" ], "Title": "Finding e-commerce site of the product URL given and see if it is supported" }
40612
<p>I am a beginner in Java programming. Here is my simple calculator. I hope you could scan through my coding and let me know if there is any error in my coding or how I could simplify the code.</p> <pre><code>import java.util.Scanner; public class Decimal { /** * @param args */ public static void m...
[]
[ { "body": "<p>Looks good for a beginner. </p>\n\n<p>Couple tweaks if you want to make it look nicer. The name of the class should be somewhat describing the purpose so in your case <code>Calculator</code> would fit better. If you are familiar with <a href=\"https://docs.oracle.com/javase/tutorial/java/javaOO/en...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T14:32:37.603", "Id": "40615", "Score": "12", "Tags": [ "java", "beginner", "calculator" ], "Title": "Simple Java calculator" }
40615
<blockquote> <p>Write a pointer version of the function <code>strcat</code> that we showed in Chapter 2: strcat(s, t) copies the string <code>t</code> to the end of <code>s</code>.</p> </blockquote> <p>This is the version of <code>strcat</code> from Chapter 2:</p> <pre><code>void strcat(char s[], char t[]) { in...
[]
[ { "body": "<p>I don't know much, but I would change a few things.</p>\n\n<ul>\n<li><p>Functions usually have the first <code>{</code> in a new line</p></li>\n<li><p>Explicit check against <code>'\\0'</code></p></li>\n<li><p>Make the second parameter <code>const</code> since the function won't change the charact...
{ "AcceptedAnswerId": "40621", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T15:27:06.133", "Id": "40616", "Score": "10", "Tags": [ "c", "beginner", "strings", "pointers" ], "Title": "Pointer version of strcat" }
40616
<p>As usual I'm wondering if there is a better way to do:</p> <p>(The code extends a angular service)</p> <pre><code>(function(window, angular, undefined) { 'use strict'; angular.module('api.base', ['restangular']) .factory('Base', function(Restangular) { return function(ro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T18:34:32.077", "Id": "68494", "Score": "2", "body": "Please try to explain a bit more about what it is that your code is doing." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T19:08:04.850", "Id":...
[ { "body": "<p>At first sight, your code is short and there is nothing wrong with it.</p>\n\n<p>At second sight, there are a few things to improve:</p>\n\n<ul>\n<li>Your semicolons are all over the place; you have both missing and pointless semicolons.</li>\n<li>There is no point in declaring <code>id</code> in ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T18:25:20.437", "Id": "40628", "Score": "5", "Tags": [ "javascript", "angular.js" ], "Title": "Angularjs extends service" }
40628
<p>I've just created my first plugin, but I think I've written too much bloated code. Could you point me to the right direction?</p> <pre><code>$.fn.replaceme = function() { function add_essentials(element) { var native_btn = element; native_type = native_btn.attr('type'); native_btn.each...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T19:19:55.520", "Id": "68503", "Score": "0", "body": "`group` and `native_type` are globals to start. Edit, also if you'd construct a demo of what your code does on jsfiddle/bin I'd appreciate it" }, { "ContentLicense": "CC B...
[ { "body": "<p>Scanning your code I have a few recommendations to make. If you update your question with a demo I'll make a few more.</p>\n\n<p>As I mentioned in comments you have a few obvious issues with globals</p>\n\n<pre><code>var native_btn = element;\nnative_type = native_btn.attr('type');\n//should be\nv...
{ "AcceptedAnswerId": "40632", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T19:10:29.363", "Id": "40631", "Score": "4", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "Replace radio/checkbox plugin" }
40631
<p><a href="http://en.wikipedia.org/wiki/Java_Persistence_API" rel="nofollow">Java Persistence</a> consists of an API in the <code>javax.persistence</code> package as well as an SQL-like language named JPQL.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T22:48:21.190", "Id": "40641", "Score": "0", "Tags": null, "Title": null }
40641
The Java Persistence API (JPA) is a specification that describes the management of relational data in Java applications.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T22:48:21.190", "Id": "40642", "Score": "0", "Tags": null, "Title": null }
40642
<p>I want to know if I'm going about creating and calling two functions from my model to my controller in the simplest and cleanest way. </p> <p>Model:</p> <pre><code>public function getPosts() { $post = $this-&gt;paginate(4); return $post; } public function getMonth($post) { $post-&gt;month = date('M', ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-03T18:43:43.597", "Id": "80638", "Score": "0", "body": "please include your full class so that we can see if you have done other declaration and setting and if you are extending certain classes or not - because if you are not using elo...
[ { "body": "<p>PHP is not my area of expertise, so just some generic notes:</p>\n\n<ol>\n<li><p><code>4</code> is a magic number here:</p>\n\n<blockquote>\n<pre><code>$post = $this-&gt;paginate(4);\n</code></pre>\n</blockquote>\n\n<p>Why is it 4? What the purpose if this number? A named constant or local variabl...
{ "AcceptedAnswerId": "45080", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T02:34:55.917", "Id": "40651", "Score": "7", "Tags": [ "php", "mvc", "laravel" ], "Title": "Laravel model and controller interaction" }
40651
<p>I have written a function that launches the default editor set in <code>git config</code>, right now I have managed to get it working for Sublime, nano and Vim.</p> <pre><code>def launchEditor(editor): """ this function launches the default editor for user to compose message to be sent along wit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T11:52:45.033", "Id": "68564", "Score": "0", "body": "Isn't specifying core editor in git config good enough? Just trying to think a use-case or purpose of this. Thanks." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<h3>1. Comments on your code</h3>\n\n<ol>\n<li><p>The function is poorly specified in that it combines two tasks: (i) it gets input from the user via an editor; (ii) it replaces newlines in the input with <code>&lt;br&gt;</code>. But what I just want the input and don't want any HTML conversion (espe...
{ "AcceptedAnswerId": "40772", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T03:14:52.897", "Id": "40652", "Score": "6", "Tags": [ "python", "performance", "git" ], "Title": "Function launching default editor" }
40652
<p>After initially <a href="https://codereview.stackexchange.com/questions/40468/monopoly-creating-a-monopoly-board">struggling with the board size</a>, I have now decided the dimension. Please review my code. In the code I am generating HTML code using PHP and MySql. I have not added the database, please let me know h...
[]
[ { "body": "<p>DISCLAIMER: I don't know PHP. Also I haven't tested this.</p>\n\n<p>Running on the assumption that position is a number or number-like value I figure you could do something like:</p>\n\n<pre><code>function drawBoard($order = \"DESC\", $start = \"\", $stop =\"\"){\n\n include 'dbconnect.php';\n\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T04:19:26.680", "Id": "40654", "Score": "7", "Tags": [ "php", "html", "css" ], "Title": "Monopoly: Board creation" }
40654
<p>These two functions search for directories with a certain prefix that contain no files of a given type.</p> <ol> <li>Does the code adhere to Ruby standards and conventions?</li> <li>Am I doing something the hard way or the "non-Ruby" way?</li> <li>Should I use more/fewer/different comments?</li> </ol> <p></p> <pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T09:27:07.677", "Id": "68552", "Score": "1", "body": "Can you share a test case please? For example: an example directory structure and some files and what this script should find and ignore. This can be refactored and the test case ...
[ { "body": "<p>Looks alright.</p>\n\n<p>Your style is more spread out than is usually the case in ruby (though that's not necessarily a bad thing.) For example</p>\n\n<pre><code>is_num = num !~ /\\D/\nif is_num\n ...\n</code></pre>\n\n<p>could as well be one line sans assignments, without loosing clarity. <code...
{ "AcceptedAnswerId": "41261", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T04:46:17.810", "Id": "40655", "Score": "9", "Tags": [ "ruby", "beginner", "file-system" ], "Title": "Search for directories with a certain prefix that contain no files of a giv...
40655
<p>Would love some feedback on this. I'm coming from a Java background and kinda feel like I've just done exactly what I would do in Java. Is there a better way?</p> <pre><code>for (i &lt;- 1 to 100) { if ( i % 3 == 0 &amp;&amp; i% 5 == 0) println(i +" = FizzBuzz") else if (i % 3 == 0) println(i +" = Fi...
[]
[ { "body": "<ul>\n<li><p>Instead of using both 3 and 5:</p>\n\n<pre><code>if (i % 3 == 0 &amp;&amp; i % 5 == 0)\n</code></pre>\n\n<p>you can just use 15:</p>\n\n<pre><code>if (i % 15 == 0)\n</code></pre></li>\n<li><p>You're also supposed to print the number <em>by itself</em> if neither case applies:</p>\n\n<pre...
{ "AcceptedAnswerId": "40659", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T05:00:57.227", "Id": "40656", "Score": "26", "Tags": [ "scala", "fizzbuzz" ], "Title": "First Scala FizzBuzz implementation" }
40656
<p>I am scraping an online shop page, trying to get the price mentioned in that page. In the following block the price is mentioned:</p> <pre><code>&lt;span id="hs18Price" itemprop="price" title="New Baby Care Pack"&gt; &lt;span class='WebRupee'&gt;&amp;#x20B9;&lt;/span&gt;&amp;nbsp;999&lt;/span&gt; </code></pre> <p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T03:31:32.267", "Id": "68661", "Score": "0", "body": "I think you need `\\u20B9` instead of `\\U20B9` (lowercase for 4 instead of 8 nybbles). If that still doesn't work, I'd consider either dropping the raw string prefix, or splittin...
[ { "body": "<p>As it happens, there are positive answers to each of your questions:</p>\n\n<ol>\n<li><p>with Beautiful Soup you can remove the WebRupee <code>span</code> with <a href=\"http://www.crummy.com/software/BeautifulSoup/bs4/doc/#replace-with\" rel=\"noreferrer\">replace_with()</a> entirely....</p>\n\n<...
{ "AcceptedAnswerId": "40733", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T07:53:23.233", "Id": "40658", "Score": "15", "Tags": [ "python", "regex", "unicode", "web-scraping", "beautifulsoup" ], "Title": "Getting data correctly from <span> tag...
40658
<pre><code>function RegisterN() { if($_SERVER['REQUEST_METHOD'] == 'POST'){ if (isset($_POST["password"],$_POST["password1"]) &amp;&amp; $_POST["password"]!=$_POST["password1"]) { # Check if password and password1 are same echo "Your password confirmation is not equal to your password or it missing."; }...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T11:30:47.267", "Id": "68560", "Score": "0", "body": "What is the `PasswordHash` class you're using? It seems you're not salting the hash thus making it irresponsibly weak, but I can't know for sure without having more information." ...
[ { "body": "<p>Here are my recommendation,</p>\n\n<ul>\n<li>you could make sure users password have a minimum length. 8 alphanumeric characters is ideal If a users password is 1 char, it can easily be broken no matter how good the salt is</li>\n<li><p>move you database connection and setup into a different clas...
{ "AcceptedAnswerId": "40665", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T11:16:13.933", "Id": "40661", "Score": "6", "Tags": [ "php", "mysql", "security", "pdo" ], "Title": "Register script security and optimization" }
40661
<blockquote> <p>Write a function <code>strend(s, t)</code> which returns <code>1</code> if the string <code>t</code> occurs at the end of <code>s</code>, and <code>0</code> otherwise.</p> </blockquote> <p>Here is my solution:</p> <pre><code>unsigned int strend(char *source, char *pattern) { char *saver = patter...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T14:25:15.397", "Id": "68578", "Score": "2", "body": "The \"dependency\" on `strlen` in your second example is generally a good thing. Its reuse of existing functionality lets you focus on new problems, rather than ones that are alre...
[ { "body": "<p>I guess you have the naming problem because the code use the variable for multiple purposes. First, it points to the end of the <code>pattern</code>, then it's used for the pointer of the current character under test. (See below.)</p>\n\n<p>In the first snippet there two identical while loops:</p>...
{ "AcceptedAnswerId": "40670", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T12:33:03.853", "Id": "40664", "Score": "10", "Tags": [ "c", "beginner", "strings", "pointers" ], "Title": "strend, function that checks the occurence of a pattern at the en...
40664
<blockquote> <p><strong><em>PYTHON 2.7-</em></strong></p> </blockquote> <p>I want to make my code OOP. I also want feedback from you on correctness, tidiness, design patterns and so on.</p> <p><a href="https://www.dropbox.com/sh/7s57lruhc9ykoz6/QqE1HxXJ08" rel="nofollow">Here's the download link</a>. It's not per...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T13:41:13.357", "Id": "68573", "Score": "0", "body": "Hello and Welcome! Please add a short description to your question about what kind of game this is, it will be much easier to understand your code and will make it easier to give ...
[ { "body": "<p><em>I haven't played your game and I haven't understood much of the code but here are a few comments.</em></p>\n<p>A few things are not quite pythonic. You can make your code go through some automatic checks with <a href=\"http://pep8online.com/\" rel=\"nofollow noreferrer\">pep8online</a> (<a hre...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T13:11:04.497", "Id": "40666", "Score": "3", "Tags": [ "python", "object-oriented", "python-2.x", "pygame" ], "Title": "Making this Pygame code object-oriented" }
40666
<p>Can anyone please review the following <code>.htaccess</code> file and let me if it is correctly put together?</p> <p>What I think it does:</p> <ul> <li>So it direct to a custom 404 page</li> <li>Remove the extensions from the end of the urls (example <code>.php</code>)</li> <li>Remove <code>/index</code></li> <li...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2019-07-22T05:02:51.150", "Id": "435754", "Score": "0", "body": "in order for your custom error page to be directed properly you need to put a URL after it and remove the duplicate 404 ie ErrorDocument 404 `https://www.youdomain.something/erro...
[ { "body": "<p>This is basically a canonicalizing URL prettifier that redirects clients to a shorter URL.</p>\n\n<p>The <code>RewriteCond</code> operating on <code>%{THE_REQUEST}</code> is weird, since it works directly at the HTTP protocol level. I understand that you want to avoid redirecting POSTs, since a r...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T13:33:45.637", "Id": "40669", "Score": "4", "Tags": [ ".htaccess" ], "Title": "Review URL-prettifying .htaccess file" }
40669
<p><a href="http://projecteuler.net/problem=7" rel="nofollow">Project Euler problem 7</a> says:</p> <blockquote> <p>By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number?</p> </blockquote> <p>I believe that my code is working, but very...
[]
[ { "body": "<p>Your prime testing code is wrong. For example, it would consider <code>14</code> to be a prime! You cannot take a shortcut by only testing divisors > 13. Instead:</p>\n\n<pre><code>static bool IsPrime(Int64 p)\n{\n if (p % 2 == 0) return false;\n Int64 max = (Int64) Math.Ceiling(Math.Sqrt(p)...
{ "AcceptedAnswerId": "40675", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T14:59:00.957", "Id": "40673", "Score": "6", "Tags": [ "c#", "algorithm", "programming-challenge", "primes" ], "Title": "What is the 10001st prime number?" }
40673
<p>Is there a better way I can code this? It's old code and I'm not sure makes sense today. JSLint gives me a lot of errors too. I don't have experience with JavaScript and I would like to optimize this snippet. </p> <p>Any suggestion? Maybe I can achieve better code with JQuery? </p> <pre><code>&lt;script type="text...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T16:09:44.347", "Id": "68592", "Score": "1", "body": "@syb0rg A JSLint \"error\" does not necessarily mean that the code is broken." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T16:25:47.027", "I...
[ { "body": "<p>The <a href=\"http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-htmlevents\" rel=\"nofollow noreferrer\">modern way</a> to attach <code>onLoad</code> and <code>onUnload</code> handlers is to use <code>window.addEventListener('load', onloadFunction)</code> and <code>window.a...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T15:13:52.493", "Id": "40674", "Score": "7", "Tags": [ "javascript", "optimization" ], "Title": "Var scope on the same line" }
40674
<p>As a first step to attempting the <a href="https://codereview.meta.stackexchange.com/questions/1471/weekend-challenge-reboot">Weekend Challenger Reboot</a>, I decided to first implement a regular 'tic-tac-toe' game and then expand it later to be 'ultimate tic-tac-toe'.</p> <p>Below is the code for the tic-tac-toe b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T16:09:31.987", "Id": "68591", "Score": "1", "body": "Nice that you support multiple sizes, I'm loving it!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T18:55:45.270", "Id": "68608", "Score":...
[ { "body": "<p>It's <strong>method extraction</strong> time!</p>\n\n<p>But before that, I have to comment on your <code>Player</code> enum:</p>\n\n<ul>\n<li><code>str</code> is a bad name, <code>name</code> would be better.</li>\n<li>Speaking of name, all enums have a <code>name()</code> method by default. You d...
{ "AcceptedAnswerId": null, "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T15:36:02.860", "Id": "40676", "Score": "17", "Tags": [ "java", "algorithm", "game", "community-challenge" ], "Title": "Tic-tac-toe 'get winner' algorithm" }
40676
<p>This finds its origin in the following reflection. In their book from 1995, the so-called gang of four (GoF) described the state pattern. What they were actually telling us in their description, is that any object oriented language that implements dynamic polymorphism has an embedded finite state machine (FSM) engin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T16:05:17.010", "Id": "69973", "Score": "0", "body": "Here is a TM in C++: http://stackoverflow.com/a/275295/14065" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T19:32:54.420", "Id": "70012", ...
[ { "body": "<p>I don't have much to say.</p>\n<p>Your implementation is similar to the GoF's (<a href=\"https://web.archive.org/web/20151002171119/http://codewrangler.home.comcast.net/%7Ecodewrangler/tech_info/patterns_code.html#State\" rel=\"nofollow noreferrer\">posted here</a>) except that your machine instan...
{ "AcceptedAnswerId": "41369", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T19:10:45.347", "Id": "40686", "Score": "15", "Tags": [ "c++", "c++11", "state", "state-machine" ], "Title": "State pattern + C++ template" }
40686
<p>I am very new to PHP and I kind of sort of want to create the pages like I would in ASP.NET; it's just the way I am wired. I have been inserting the header/menu using a PHP Include and here is what the code looks like for just the first page.</p> <p>Am I doing this properly, or is there a better way?</p> <p><str...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T20:51:33.903", "Id": "68621", "Score": "0", "body": "I was surprised to see that you had a working example, `<?php include ('Menu.php') ?>` I would think would generate a fatal error with the semicolon." }, { "ContentLicense...
[ { "body": "<p>Going to some HTML5 stuff straight away.</p>\n\n<ol>\n<li><p>Replace your doctype with the HTML5 doctype. This is necessary for the next few steps</p>\n\n<pre><code>&lt;!DOCTYPE html&gt;\n</code></pre></li>\n<li><p>Use the shorter charset meta tag and the meta viewport tag inside your head area. T...
{ "AcceptedAnswerId": "40690", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T20:27:56.387", "Id": "40688", "Score": "11", "Tags": [ "php", "html", "beginner", "html5" ], "Title": "Review structure of PHP/HTML" }
40688
<p>The following code loads a YouTube video inside an iframe, where the tricky part is to sync the <code>onYouTubeIframeAPIReady</code> and <code>on('shown.bs.modal')</code> functions. The code works well in Firefox and decently in Chrome, but in Safari it is quite buggy. Any hints towards improvement would be apprecia...
[]
[ { "body": "<p>Don't remove the indentation inside of code blocks so that the code is on the same line as the signature. It makes the code harder to read as it's hard to piece together which <code>}</code> goes to which signature.</p>\n\n<p>For example, this:</p>\n\n<pre><code>function onYouTubeIframeAPIReady() ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T20:36:06.500", "Id": "40689", "Score": "1", "Tags": [ "javascript", "jquery", "twitter-bootstrap", "youtube" ], "Title": "Loading YouTube videos inside a bootstrap modal" }
40689
<p>I am currently using the Udacity Introduction to Java course. There was a topic on Algorithms and it gave an example Algorithm for comparing and purchasing two different cars in pseudo code. I decided to turn that into some Java code to see just how well I grasped the concept.</p> <p>The algorithm was:</p> <blockq...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-12T06:07:04.520", "Id": "68628", "Score": "0", "body": "@PradeepSimha I can't find how to migrate it to codereview.. odd" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-12T06:09:30.530", "Id": "68629", ...
[ { "body": "<p>Seeing that you are at the start of your programming career. You are all good to go! Everything is nicely laid out. There are a lot of ways to make this \"better\" to other developers. But for your phase of learning you are right where you need to be! Good work keep coding!</p>\n", "comments":...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-12T05:56:10.173", "Id": "40693", "Score": "2", "Tags": [ "java" ], "Title": "Comparing two cars via their lifetime price" }
40693
<p>I'm trying to get the average luma of an area in an YUV image in the Android camera. I have come up with the following code which I think is correct and produces consistent results.</p> <pre><code>private static final int AVERAGE_LUMA_SAMPLE_SIZE = 2; // sample the average luma // yuvImage is the byte data return ...
[]
[ { "body": "<p>One of the reasons that large 2d data sets are often reduced to a single 1D array is so that you can process the data in a single loop and the memory is contiguous. The trick to processing this data efficiently in a single loop is to be able to fiddle the single pointer in a way that makes sense.....
{ "AcceptedAnswerId": "40698", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T21:59:10.980", "Id": "40696", "Score": "4", "Tags": [ "java", "android", "image" ], "Title": "Calculating luma of a rect in an image of .yuv format" }
40696
<p>I'm starting to implement basic sorting algorithms. Criticisms on the implementation is welcome. </p> <pre><code>#import pudb; pu.db def bubble_sort(list_): """Implement bubblesort algorithm: iterate L to R in list, switching values if Left &gt; Right. Break when no alterations made to to list. """ not_...
[]
[ { "body": "<blockquote>\n<pre><code>for val, item in enumerate(list_):\n</code></pre>\n</blockquote>\n\n<p>You don't use <code>item</code>, so don't get it. Instead, use <code>xrange(len(list_))</code></p>\n\n<blockquote>\n<pre><code>if val == len(list_)-1: val = 0\n</code></pre>\n</blockquote>\n\n<p>This reche...
{ "AcceptedAnswerId": "40736", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T23:06:02.143", "Id": "40699", "Score": "11", "Tags": [ "python", "algorithm", "sorting", "reinventing-the-wheel" ], "Title": "Bubble sort algorithm in Python" }
40699
<p>Reference: <a href="https://stackoverflow.com/questions/21515940/is-this-a-faithful-rendition-of-the-selection-sort-algorithm">Is this a faithful rendition of the selection sort algorithm?</a></p> <p>I'm working through an elementary book on sort and search algorithms, and writing some sample code to test my unders...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T23:42:12.040", "Id": "68650", "Score": "0", "body": "Perhaps mention that `selection sort` is just one approach to doing a regular sort. Sample data not reqd. Also, you lost your link when moving the question from SO." }, { ...
[ { "body": "<p>Here are a couple of Ruby-like approaches you might consider:</p>\n\n<pre><code>def sort(unsorted)\n sorted = []\n until unsorted.empty? do\n smallest = [unsorted.first, 0]\n (1...unsorted.size).each do |i|\n v = unsorted[i]\n smallest = [v, i] if v &lt; smallest.first\n end ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T23:16:17.257", "Id": "40700", "Score": "11", "Tags": [ "algorithm", "ruby", "recursion", "sorting" ], "Title": "Selection sorter" }
40700
<p>I am new to HTML and CSS. I was wondering if anyone could give me some advice on my use of markup and CSS to achieve this result. I am trying to get a fixed full height sidebar with a list with sprite image for each item.</p> <p><a href="http://jsfiddle.net/spadez/JBuE6/40/" rel="nofollow">This</a> is the code I ha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-06T17:43:06.127", "Id": "70440", "Score": "0", "body": "What is supposed to happen with the green button at the right? the \"Create New\"? Will that send you to a different page, display a modal, etc?" }, { "ContentLicense": "C...
[ { "body": "<p>A few suggestions</p>\n\n<p>You were using this to pass classes to your main logo</p>\n\n<pre><code>.col_left img {\n float:right;\n display: block;\n line-height:40px;\n margin-left: auto;\n margin-right: auto;\n}\n</code></pre>\n\n<p>But that will create problems if you introduce ...
{ "AcceptedAnswerId": "41092", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-02T23:23:03.957", "Id": "40701", "Score": "3", "Tags": [ "html", "beginner", "css" ], "Title": "HTML and CSS markup to achieve desired result" }
40701
<p>A helper is a method commonly used in object-oriented programming to provide additional functionality to classes that not directly associated with the class. This is known as an Inversion of Responsibility.</p> <p>Helper methods are typically grouped into a single helper class through the delegation pattern.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T06:19:27.003", "Id": "40719", "Score": "0", "Tags": null, "Title": null }
40719
Additional functionality not defined in a class that the helper operates on.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T06:19:27.003", "Id": "40720", "Score": "0", "Tags": null, "Title": null }
40720
<p>I'm writing an object oriented package, and one problem I am trying to solve is a class that will get all PHP files in a particular directory and instantiate the classes but not abstracts or interface types.</p> <p>From an object oriented perspective, is this class SOLID?</p> <pre><code>&lt;?php namespace Masscula...
[]
[ { "body": "<p><em>README:</em><br>\nFirst off, I'll just focus on making this one class a tad more generic, and expandable <em>and</em> maintainable and... well, generally more OO. Then, though I'm not going to go into too much detail on the matter, I'll just list a few quick tips of how you could go about sepa...
{ "AcceptedAnswerId": "40732", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T06:36:23.263", "Id": "40721", "Score": "4", "Tags": [ "php", "object-oriented", "file-system" ], "Title": "Collecting files from a particular directory" }
40721
<p>I'm writing a twirling cursor, which is a cursor that twirls in place in the console. In Forth, this takes just 3 lines, whereas in Python3 I have this:</p> <pre><code>from time import sleep # sleep(sec) import sys def flash(c): """Shows character c momentarily.""" # backspace ($8) and sleep(sec) keep i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T16:45:27.050", "Id": "68738", "Score": "2", "body": "Python functions return `None` by default, so unless you are planning on returning a value, don't include a return statement." }, { "ContentLicense": "CC BY-SA 3.0", "...
[ { "body": "<p>Repetitive code should be put in a loop.</p>\n\n<p>Most programmers don't have the ASCII table memorized. Why not use literal characters instead?</p>\n\n<p>Flush can be handled by <code>print()</code> itself. I don't believe you need to flush after backspacing.</p>\n\n<p>The speed of the rotatio...
{ "AcceptedAnswerId": "40725", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T09:43:06.240", "Id": "40724", "Score": "3", "Tags": [ "python", "python-3.x", "console" ], "Title": "Twirling cursor" }
40724
<p>I'm learning basic algorithms and implementing them in Python. Critiques needed/welcome.</p> <pre><code>import pudb; pu.db import random def selection_sort(list_): """Implement selection_sort algorithm: iterate L to R in list, grab value if greatest and inserting into correct pos. After each loop, decrement...
[]
[ { "body": "<p>Most of my <a href=\"https://codereview.stackexchange.com/a/40736/11728\">comments on your previous question</a> apply here too, so I'll just summarize them quickly:</p>\n\n<ol>\n<li><p>Debugging code that you forgot to remove.</p></li>\n<li><p>Docstring written from the implementer's point of vie...
{ "AcceptedAnswerId": "40743", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T12:56:13.913", "Id": "40734", "Score": "5", "Tags": [ "python", "algorithm", "sorting" ], "Title": "Selection sort algorithm in Python" }
40734
<p>So I've been kind of irritated with my logging recently as I find myself copying and pasting the same kinds of generic messages around to lots of different methods or retyping them ever so <em>slightly</em> differently (when they ought to be identical).</p> <p>Hence, I created this kind of framework:</p> <pre><cod...
[]
[ { "body": "<p>Well,</p>\n\n<p>It does what it is supposed to and works fine. \nMy comment is more regarding the logger class than the enum of messages.</p>\n\n<p>You indicated you use this logger throughout your project, well if you change your messages add/remove some you would have to recompile a lot of stuff...
{ "AcceptedAnswerId": "40745", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T13:46:40.947", "Id": "40738", "Score": "3", "Tags": [ "java", "strings", "formatting", "logging" ], "Title": "Any recommendations to improve this logging framework? Or is i...
40738
<blockquote> <p>Write versions of the library functions <code>strncpy</code>, <code>strncat</code> and <code>strncmp</code>, which operate on the most <code>n</code> characters of their argument strings. For example, <code>strncpy(s, t, n)</code> copies at most <code>n</code> characters of <code>t</code> to <code>s</...
[]
[ { "body": "<p>I think you've misinterpreted the <a href=\"http://www.cplusplus.com/reference/cstring/strncat/\" rel=\"nofollow noreferrer\">definition of strncat</a>, which says,</p>\n\n<blockquote>\n <p>Appends the first <code>num</code> characters of source to destination, plus a terminating null-character.\...
{ "AcceptedAnswerId": "40747", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-02-03T14:09:26.330", "Id": "40741", "Score": "8", "Tags": [ "c", "beginner", "strings" ], "Title": "implementations of strncmp, strncat, strncpy" }
40741
<p>I am working on a small custom Markup script in Java that converts a Markdown/Wiki style markup into HTML.</p> <p>The below works, but as I add more Markup I can see it becoming unwieldy and hard to maintain. Is there is a better, more elegant, way to do something similar? </p> <pre><code>private String processStr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T19:29:44.610", "Id": "68772", "Score": "0", "body": "Could you provide implementation, at least some examples, of the different `set` methods you're calling?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-...
[ { "body": "<p>This sounds like a case where you should encapsulate the data with a <a href=\"http://en.wikipedia.org/wiki/Decorator_pattern\" rel=\"nofollow\">'Decorator Pattern'</a>.</p>\n\n<p>You should declare a simple interface such as:</p>\n\n<pre><code>public interface StyledString {\n public String to...
{ "AcceptedAnswerId": "40751", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T15:30:13.990", "Id": "40746", "Score": "12", "Tags": [ "java", "design-patterns", "strings" ], "Title": "Better way to manipulate this string in sequence?" }
40746
<p>I saw this UI for a mobile app, but I reverse engineered it for the web. This is how it looks in my <a href="http://codepen.io/JGallardo/pen/EHDme" rel="nofollow noreferrer">CodePen</a></p> <p><img src="https://i.stack.imgur.com/n2fOa.png" alt="live demo"></p> <p>This would be either a favorites or featured list l...
[]
[ { "body": "<p>The use of <code>ul</code> seems appropriate. My concern with using <code>&lt;img&gt;</code>s would be with the image dimensions. From what I can see above, unless you create your images specifically in those dimensions, it will become a pain to ensure they scale correctly.</p>\n\n<p>I've found th...
{ "AcceptedAnswerId": "40762", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T16:55:13.190", "Id": "40756", "Score": "5", "Tags": [ "html", "css", "mustache" ], "Title": "Was this use of <img> tags in this HTML over background images better?" }
40756
<p>I have a click event that calls a function which makes some CSS changes (acts on Text in 3 unique text elements). </p> <p>The function (below) works, but is lacking a 'restore default' function (to return the text to its original state), AND is in dire need of refactoring. </p> <p>Q: How can the original state of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T15:22:22.877", "Id": "68747", "Score": "0", "body": "Perhaps the note on refactoring could be de-emphasized but the main issue is that my text does not return to its original state (two of the paragraphs remain opacity = unreadable....
[ { "body": "<p>as a first step I would rewrite the last if statement</p>\n\n<pre><code>else if ((clicked =! \"Text1\") &amp;&amp; (clicked != \"Text2\") &amp;&amp; (clicked != \"Text3\") ) \n {\n $(\"#ActText, #AdaptText, #PlanText\").css(\"opacity\", \"1\"); // return to default state\n } \n</code...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-16T15:04:16.237", "Id": "40759", "Score": "4", "Tags": [ "javascript", "jquery", "css" ], "Title": "Changing text with a click event: how to restore default state of text in jQuery i...
40759
<p>I have started to try and work out the <a href="http://www.topcoder.com/">TopCoder</a> problems. The <a href="http://community.topcoder.com/stat?c=problem_statement&amp;pm=40">"StringDup" problem</a> asks us to:</p> <blockquote> <p>Create a class called StringDup. Given a string made up of ONLY letters and digi...
[]
[ { "body": "<p>Currently it returns <code>.</code> in case of an invalid input (empty string, for example). It's not in the specification, so I think it shouldn't do that. Crash early. It is rather a bug in the client code when it calls the method with invalid input. Clients might produce bigger side-effect on a...
{ "AcceptedAnswerId": "40771", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T17:43:39.017", "Id": "40763", "Score": "8", "Tags": [ "java", "beginner", "strings", "programming-challenge" ], "Title": "Finding the most common character in a string" }
40763
<p>I have a form, which uses AJAX to send POST data to the following controller method:</p> <pre><code>public function action_sendmail() { $jsonHelper=Loader::helper('json'); $answer = (int) $_POST['security']; if($answer &lt;= 0) $answer = 1; if($answer == 4){ ...
[]
[ { "body": "<p>Secure: Not yet, but it's a start. Your validation is too strict in some places, and may result in the wrong email address being used. In particular here:</p>\n\n<pre><code>$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);\n//a bit later on:\n$email = str_replace(array(\"\\r\", \"\\n\",...
{ "AcceptedAnswerId": "40834", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T17:57:14.703", "Id": "40766", "Score": "6", "Tags": [ "php", "security", "form", "email" ], "Title": "Security of a \"contact us\" form" }
40766
<p>Here's a PHP wrapper around a public OAuth2 REST API. I would love to hear your thoughts and comments. Testing was a bit frustrating since I tried for my first time. Not sure if I have done the mocking properly.</p> <p>You can see the whole project on <a href="https://github.com/stakisko/feedly-api" rel="nofollow">...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T07:38:27.987", "Id": "69897", "Score": "2", "body": "_Please_, __Please__ subscribe to the, as of yet, unofficial coding standards [as described here](http://www.php-fig.org/). The more people adopt these, the better. Symfony, Zend,...
[ { "body": "<p>Two minor notes:</p>\n\n<ol>\n<li><p>The following is not too easy to read:</p>\n\n<pre><code>curl_setopt($r, CURLOPT_ENCODING, 1);\n</code></pre>\n\n<p>Readers have to be really familar with curl parameters or have to check the documentation. It <a href=\"http://hu1.php.net/curl_setopt\" rel=\"no...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T18:21:11.457", "Id": "40767", "Score": "5", "Tags": [ "php", "unit-testing", "api", "wrapper", "mocks" ], "Title": "PHP wrapper around an API - best practices" }
40767
<p>After profiling my current script I've found that nearly 100% of the run time (and I'm not surprised) comes from the following function:</p> <pre><code>def rem_asc_by_pos(xmlFile, fileOut,removeIndices): fileIn = xmlFile.replace('.xml', '.asc') with open(fileIn, 'r') as fin: with open(fileOut, 'w') as fout: ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T20:20:02.167", "Id": "68782", "Score": "1", "body": "Can you explain what this function is supposed to do? Can you give examples of the input and output?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-0...
[ { "body": "<h3>1. Test case</h3>\n\n<p>You can't fix what you don't measure. So let's make a test case containing a million lines similar to the example input in your question:</p>\n\n<pre><code>&gt;&gt;&gt; with open('in.txt', 'w') as f:\n... for _ in range(10**6):\n... _ = f.write('511111 12 1.00...
{ "AcceptedAnswerId": "40796", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T20:07:30.047", "Id": "40773", "Score": "7", "Tags": [ "python", "python-3.x" ], "Title": "More efficient way of removing line indices?" }
40773
<p>I'm using Microsoft's <a href="http://msdn.microsoft.com/en-us/library/ms172831%28v=vs.100%29.aspx" rel="nofollow">example</a> for encrypting/decripting a string. In their example, they are using Tripple DES. I'm trying to convert their code to use AES. </p> <p>The modified code, listed below, works. However, I am ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-22T18:15:27.247", "Id": "68775", "Score": "0", "body": "Very minor notes: variables and fields should use lowercase (so use `aes` instead of `AES`. Futhermore you can make the code easier to understand by not relying on defaults, so se...
[ { "body": "<p>It seems you did a good job getting the same functionality using AES. The problem is that Microsoft is not using good practices themselves.</p>\n\n<p>They confuse a password with a key, and they do not use a good key derivation function such as PBKDF2 (implemented in .NET by the class <a href=\"ht...
{ "AcceptedAnswerId": "40775", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-22T16:40:35.323", "Id": "40774", "Score": "5", "Tags": [ "vb.net", "cryptography", "aes" ], "Title": "Encrypt Using AES" }
40774
<p>This is a very long solution I've been working on to a Number to Words problem. I've identified that there's a lot of repeating logic (e.g. 'if writing > 0', 'writing = integer /',).</p> <ul> <li>How would you refactor this? </li> <li>When refactoring is there a process you use?</li> <li>For readability sake would ...
[]
[ { "body": "<p>I would refactor by using a loop, which has the advantage of letting you easily add new words (i.e. billions). Here is a quick version I wrote up to demonstrate using a loop to reduce the repetition. Just did some basic testing and I'm sure it has some issues, but hopefully it sets you on the righ...
{ "AcceptedAnswerId": "40777", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-22T19:39:26.477", "Id": "40776", "Score": "5", "Tags": [ "strings", "ruby", "converting", "integer", "numbers-to-words" ], "Title": "Number to words problem" }
40776
<p>I wrote this function last year to convert between the two encodings and just found it. It takes a text buffer and its size, then converts to UTF-8 if there's enough space.</p> <p>What should be changed to improve quality?</p> <pre><code>int iso88951_to_utf8(unsigned char *content, size_t max_size) { unsigned ...
[]
[ { "body": "<p>Minor quibbles.</p>\n\n<ol>\n<li>I would prefer to see the variables assigned to when defined.</li>\n<li>Use a macro instead of the hard coded value of 0x80 or 0x3F. For someone who is not familiar with the ins and outs of UTF-8 or ISO-8895-1 naming them something like MASK_END or UPPER_VALUE make...
{ "AcceptedAnswerId": "40792", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T20:54:56.010", "Id": "40780", "Score": "10", "Tags": [ "c", "strings", "converting", "unicode", "utf-8" ], "Title": "Function to convert ISO-8859-1 to UTF-8" }
40780
<p>I am trying to get a better understanding of the modular design pattern and I am using Requirejs to manage my dependencies.</p> <p>I understand separating code into modules (using define with RequireJS) so they take on only single responsibilities and also splitting them into separate JavaScript files so Require JS...
[]
[ { "body": "<p>First, unless the <code>work</code> module is about force times distance in a physics simulator, it is a terribly over-generic name! What does the name <code>work</code> communicate to someone who is sitting down with your application for the first time? Name modules after what they do and be as s...
{ "AcceptedAnswerId": "40785", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T21:40:56.713", "Id": "40783", "Score": "7", "Tags": [ "javascript", "require.js" ], "Title": "Modular design with Require.js" }
40783
<p>I am reading a beginning Python programming book and in it the author says that you want to avoid accessing a class' attributes directly, but instead to create methods that return attribute values. However, I am finding there are times this seems a little redundant and I am wondering if am just going about this in t...
[]
[ { "body": "<p>As has been pointed out, overriding the <code>__call__</code> method is not the best way to improve the readability of your code.</p>\n\n<p>Using attributes is not, in itself, a problem.</p>\n\n<p>What you may want to consider is a trick you can play with Rock/Paper/Scissors.</p>\n\n<p>If you crea...
{ "AcceptedAnswerId": "40835", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T21:49:29.997", "Id": "40784", "Score": "7", "Tags": [ "python", "game", "classes", "rock-paper-scissors" ], "Title": "Directly accessing class attributes in Rock Paper Scis...
40784
<p>I have a test which looks like this:</p> <ul> <li>Create a base class <code>Human</code> </li> <li><code>Human class</code> needs to have a method <code>Talk</code></li> <li>The <code>Human</code> class needs to have to descendant class <code>Man</code> and <code>Woman</code></li> <li>Both <code>Man</code> and <cod...
[]
[ { "body": "<p>Some opinions:</p>\n\n<blockquote>\n<pre><code>function Woman(){\n Human.call(this);\n}\nWoman.prototype = new Human();\n</code></pre>\n</blockquote>\n\n<p><a href=\"https://stackoverflow.com/q/12592913/1048572\">Don't use <code>new</code> for prototype</a> (even when it doesn't matter here as ...
{ "AcceptedAnswerId": "40790", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-29T21:55:42.740", "Id": "40789", "Score": "1", "Tags": [ "javascript", "inheritance" ], "Title": "Subclasses instantiating superclass of class Human" }
40789
<p>I have three functions, each assigned to an anchor tag which gets called <code>onclick</code>.</p> <p>Is there a way to condense this code? It seems redundant to have three function calls which do the same thing except the value is different for each.</p> <pre><code>var winnings = 0; function add20() { winnin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-31T23:42:13.700", "Id": "68822", "Score": "1", "body": "Sure: `function addWinnings(amount) { winnings += amount; .. }` Generally, one should keep *data* out of identifiers - and the amount 20/40/60 (which is data) should likely come f...
[ { "body": "<pre><code>function add(val) {\n winnings += val;\n document.getElementById(\"winnings\").innerHTML = winnings;\n}\n</code></pre>\n\n<p>Calling it with</p>\n\n<pre><code>add(20); // Adding 20\n</code></pre>\n\n<p>Or</p>\n\n<pre><code>add(40); // Adding 40\n</code></pre>\n\n<p>Etc</p>\n", "c...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-31T23:36:49.103", "Id": "40802", "Score": "1", "Tags": [ "javascript" ], "Title": "Is it possible to condense this code?" }
40802
<p>I was looking for a review on my coding. Since I'm planning to get a job as a Android Programmer in the long run.</p> <p>This is my first calculator app, which I did by self learning Programming. I have no other Programming Langauge experience.</p> <p>So I would love to hear how bad my coding is? Which areas I nee...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T18:43:36.413", "Id": "70002", "Score": "0", "body": "Once you've fixed the things @rolfl suggested below, please post a [follow-up question](http://meta.codereview.stackexchange.com/questions/1065/how-to-post-a-follow-up-question) a...
[ { "body": "<p>You have a large amount of code duplication. The highly technical description of your problem is 'DRY' or Don't Repeat Yourself.</p>\n\n<p>I would say that fixing three issues in your code would make the rest of the code a lot simpler to manage. Once those three are done, you should bring your cod...
{ "AcceptedAnswerId": "40814", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-03T23:58:22.980", "Id": "40807", "Score": "6", "Tags": [ "java", "android", "calculator" ], "Title": "Calculator Android App" }
40807
<p>I feel like this bit of code could be condensed or made better in some way. It may in fact not be, but figured I'd get some people to have a look. I have multiple pages on my site and in certain pages I'm setting a JavaScript variable:</p> <pre><code>var header_check = "user-profile"; </code></pre> <p>Some pages I...
[]
[ { "body": "<p>First off, your code really breaks down to this logic and I find it helpful to write it out the longer version to full understand the logic flow before trying to shorten it:</p>\n\n<pre><code>var header_cookie, cookie_check, city_profile, state_profile;\nif (typeof header_check !== \"undefined\") ...
{ "AcceptedAnswerId": "40810", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T00:01:10.630", "Id": "40808", "Score": "6", "Tags": [ "javascript", "jquery" ], "Title": "Check if a JavaScript variable exists and checking its value" }
40808
<p>Implementing basic sorting algorithms to learn them, and coding, better. Criticisms/ critiques welcome. Also possible optimizations. </p> <pre><code>import unittest import random def insertion_sort(seq): """Accepts a mutable sequence, utilizes insertion sort algorithm to sort in place. Returns an ordered l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T05:39:16.103", "Id": "69891", "Score": "0", "body": "I don't know much python so this maybe don't apply, but usually instead of inserting things to the array, the correct approach is to build a new one from scratch." }, { "C...
[ { "body": "<p>Answers from <a href=\"https://codereview.stackexchange.com/users/11728/gareth-rees\">Gareth Rees</a> to your other questions about <a href=\"https://codereview.stackexchange.com/questions/40734/selection-sort-algorithm-in-python\">selection sort</a> and <a href=\"https://codereview.stackexchange....
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T00:18:21.600", "Id": "40809", "Score": "5", "Tags": [ "python", "beginner", "algorithm", "sorting", "insertion-sort" ], "Title": "Insertion Sort Algorithm in Python" }
40809
<p>I have a big in-memory collection of following simplified class:</p> <pre><code>public class Product { public int Id { get; set; } public string UserName { get; set; } public int CategoryId { get; set; } public string Title { get; set; } public string Description { get; set; } } </code></pre> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T11:52:10.100", "Id": "69926", "Score": "0", "body": "Im not entirely sure but doesnt .Where do some kind of hashing tables to speed up comparing? Possibly the hashing causes issues on massive collection." }, { "ContentLicens...
[ { "body": "<p>Using <code>ToString()</code> to compare expressions for equality might work in simple cases, but:</p>\n\n<ul>\n<li>It requires you to always use the same parameter name, for example, it would consider <code>x =&gt; x.Id</code> and <code>product =&gt; product.Id</code> to be different expressions....
{ "AcceptedAnswerId": "40818", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T00:33:13.897", "Id": "40811", "Score": "34", "Tags": [ "c#", "linq", "lookup" ], "Title": "Multiple indexes over an in memory collection for faster search" }
40811
<p>First off, here's the code:</p> <p><strong>main.m</strong></p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "PSBoard.h" #import "PSPlayer.h" #import "PSInputHandler.h" int main(int argc, const char * argv[]) { @autoreleasepool { NSLog(@"Enter Player 1 Name:"); NSString *playerO...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T03:30:48.583", "Id": "68871", "Score": "6", "body": "Hi and welcome to CodeReview. You have just passed the 'First Question' review with flying colours. Good question. You may, by the way, be interested in the current Ultimate-Tic-T...
[ { "body": "<p>I will update this post over the weekend as I go through your question more and come up with some examples to iterate over my points, but I thought for now, I'd answer some of the easier questions.</p>\n\n<hr>\n\n<p><strong>Question 1.</strong></p>\n\n<p>I'm not sure and cannot remember (I will tr...
{ "AcceptedAnswerId": "41188", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T02:47:09.880", "Id": "40820", "Score": "12", "Tags": [ "optimization", "game", "objective-c" ], "Title": "Tic Tac Toe implementation in Objective-C" }
40820
<p>Problem description. Returns strings with probability determined by the frequency of each of the strings. eg: if "foo" has weight of 50% and "bar" has weight of another 50% then both foo and bar should be 5 and 5 times each given that 10 tries were made.</p> <p>If question is unclear let me know I will reply asap....
[]
[ { "body": "<p>The code looks nice. A few minor improvements or ideas:</p>\n\n<ol>\n<li><p>You need only two simple methods to make it an <code>Iterator</code>:</p>\n\n<pre><code>public final class WeightedRandom&lt;T&gt; implements Iterator&lt;T&gt; {\n\n ...\n\n @Override\n public boolean hasNext() {\...
{ "AcceptedAnswerId": "40907", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T03:57:27.847", "Id": "40823", "Score": "5", "Tags": [ "java", "algorithm", "random" ], "Title": "Weighted probabilistic sampling" }
40823
<p>You guess a word, and if its letter(s) is in the same spot as a hidden word's, you add [] around the letter. If it's in the hidden word, but not in the same spot, you add()).</p> <p>As of now, I have a whole bunch of loops which I find makes the program un-compact. I would love to see some tips on how to shorten t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T06:35:08.350", "Id": "69893", "Score": "0", "body": "Compactness? Defined as Simplicity? reduction in lines of code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T06:36:34.603", "Id": "69894", ...
[ { "body": "<pre><code>def game(word):\n guesses = 0\n while True:\n user_string = prompt(\"What do you think the word is? \",\n lambda s: len(s) == len(word),\n \"Please guess a {}-letter word.\".format(len(word)))\n\n if user_string == w...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T06:17:58.667", "Id": "40827", "Score": "4", "Tags": [ "python", "beginner", "strings", "array", "game" ], "Title": "Lingo game using Python" }
40827
<p>The code runs fine and takes 100s to complete it for 5 iteration. I need to reduce it to take less time with the same number of iterations. </p> <p>h = 324 by 648 matrix</p> <p>The code is that of FFT Belief Propagation for LDPC codes over gf(8).</p> <pre><code>tic [a2,b2] = size(h); % h is the parity check matr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T12:30:12.717", "Id": "69928", "Score": "6", "body": "Please add an explanation about what the code does, it will be much easier to help you that way." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T21...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T12:21:19.773", "Id": "40838", "Score": "2", "Tags": [ "optimization", "matlab", "matrix" ], "Title": "Increasing speed of parity check matrix" }
40838
<p>This my solution to one of the practice problems from <em>Cracking the Coding Interview: 150 Programming Interview Questions and Solutions [Book]</em></p> <blockquote> <p>implement an algorithm to determine of a string has all unique characters. What if you cannot use additional data structures ?</p> </blockquote...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-07T11:44:10.940", "Id": "70600", "Score": "3", "body": "You quote says \"unique characters\" not unique letters. In Java `char` can have 2^16 = 65536 different values. What does your program return for this string \"?\"" }, { "...
[ { "body": "<p>You probably shouldn't call <code>toUpperCase()</code> twice on each character.</p>\n\n<p>If you wanted to split your code properly (if it was for a real-life project for instance), it would make sense to make the documentation a bit better and to define a method taking a <code>String</code> as an...
{ "AcceptedAnswerId": "40844", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T13:11:24.957", "Id": "40841", "Score": "9", "Tags": [ "java", "algorithm", "strings" ], "Title": "Algorithm to determine if a string is all unique characters" }
40841
<p>I am trying to read a single-columned CSV of doubles into <code>Java</code> with a string header. It is 11 megabytes and takes over 15 minutes to read, which is clearly unacceptable. In <code>R</code> this CSV would take about 3 seconds to load.</p> <p>This CSV file may contain strings so I am parsing it with this ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T13:35:25.150", "Id": "69936", "Score": "2", "body": "How is `NumberUtils.isNumber` implemented?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T14:03:06.097", "Id": "69939", "Score": "0", ...
[ { "body": "<p>As per Bobby's comment, Vector is your problem, but not for the reason he says...</p>\n\n<p>Vector is a <strong>synchronized</strong> class. Each call to any method on Vector will lock the thread, flush all cache lines, and generally waste a lot of time (in a situation where it's usage is in a sin...
{ "AcceptedAnswerId": "40851", "CommentCount": "13", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T13:24:44.663", "Id": "40842", "Score": "7", "Tags": [ "java", "parsing", "csv", "io" ], "Title": "Speed up CSV reading code (vector of doubles)" }
40842
<p>Like anything that <em>shouldn't</em> be done, I decided to see if it is possible to match <code>&lt;script&gt;</code> tags robustly using regexes in PHP. Since there is no arbitrary nesting, I figured it should at least be possible.</p> <p>This is what I came up with. It is designed to handle every edge case I cou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T17:34:06.170", "Id": "69989", "Score": "5", "body": "The <center> cannot hold." } ]
[ { "body": "<p>Probably not the review/answer you're looking for, but...</p>\n<blockquote>\n<p>Note: I am <strong>not</strong> using this in production.</p>\n</blockquote>\n<h1>Don't!</h1>\n<blockquote>\n<p><em>Some people, when confronted with a problem, think &quot;I know, I'll use regular expressions.&quot; N...
{ "AcceptedAnswerId": "40860", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T13:44:37.067", "Id": "40843", "Score": "11", "Tags": [ "javascript", "php", "html", "regex" ], "Title": "Matching script tags with regexes" }
40843
<p>My question concerns the following Python code which is already working. As far as I have seen, there are very elegant solutions of compacting code. Do you have any ideas on how to make the following code look smoother? </p> <pre><code>mom = [0.,0.13,0.27,0.53,0.67] strings = ['overview_files/root/file_' + str(e) f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T14:56:30.423", "Id": "69952", "Score": "1", "body": "Can you describe what you think is not smooth about this code? It is only 12 lines and is already fairly terse with liberal use of list comprehension." }, { "ContentLicens...
[ { "body": "<p>You may want to follow PEP8 a bit more closely to learn how to write code that is easily understood by most Python developers. Eg. <code>mom = [0.3, 0.13]</code> instead of <code>mom = [0.3,0.13]</code> and four spaces indentation.</p>\n\n<p>Try to be more careful about variable names. I couldn't ...
{ "AcceptedAnswerId": "41639", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T14:45:24.207", "Id": "40849", "Score": "6", "Tags": [ "python", "numpy", "matplotlib" ], "Title": "Prepare data for a contour plot with matplotlib" }
40849
<p>I have implemented a program to sort a file consisting of numbers. The program generates a different output file with all numbers sorted in it. I have implemented this program using <code>BitSet</code> and want to understand <code>BitSet</code>. </p> <pre><code>public class Application { public static void main...
[]
[ { "body": "<p>Overall your code is very well formatted and readable but I have some complaints at the moment:</p>\n\n<ul>\n<li><p>Don't declare all methods with <code>throws Exception</code>. Only declare the Exceptions you really need to declare, such as <code>IOException</code>. Declaring <code>throws Excepti...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T16:17:21.453", "Id": "40855", "Score": "8", "Tags": [ "java", "sorting", "file-system", "file", "bitset" ], "Title": "Sorting a set of numbers in a file using Java BitSet"...
40855
<p>I want to know if this can be trimmed down further. I am repeating myself with <code>this.title</code> and <code>this.position</code>. Also <code>this.position</code> is the corresponding array index, not sure if that is a good idea, if player throws 3 then perhaps I can just denote that as player is currently at <c...
[]
[ { "body": "<p>There are a few places that I think you could simplify the code, but I don't think you are too far off. Let me address each concern:</p>\n\n<ol>\n<li><blockquote>\n <p>I am repeating myself with <code>this.title</code> and <code>this.position</code>.</p>\n</blockquote>\n\n<p>You can set all of t...
{ "AcceptedAnswerId": "40870", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T17:23:23.337", "Id": "40862", "Score": "5", "Tags": [ "javascript", "game" ], "Title": "Monopoly: Positions" }
40862
<p>I've written a Python client for a new NoSQL database as a service product called Orchestrate.io. The client is very straightforward and minimal. It uses the <a href="http://docs.python-requests.org/en/latest/" rel="nofollow">requests</a> library, making the underlying code even more streamlined. </p> <p>I've been ...
[]
[ { "body": "<ol>\n<li><p>This is a very \"thin\" layer around the Orchestrate.io database. By \"thin\" I mean that it provides no abstraction and no mapping of concepts between the Orchestrate and Python worlds. Without your module, someone might have written a sequence of operations like this:</p>\n\n<pre><code...
{ "AcceptedAnswerId": "41074", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T18:11:21.517", "Id": "40865", "Score": "1", "Tags": [ "python", "api" ], "Title": "Orchestrate.io Client API Design" }
40865
<p>I'm in the process of structuring a model for conjugation tables for French. There are noun inflections, adverb inflections, and 19 verb conjugations. I'm trying to model the data so that every piece of data is accessible in the same manner as one would traverse the following XML tree (taken from my XML dictionary f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T18:53:52.307", "Id": "70004", "Score": "2", "body": "Theoretical upvote (ran out of votes!) - I somewhat hope this one doesn't get answered before I get home... for now I'll just say you need `enum`s and more descriptive naming. Ide...
[ { "body": "<p>Let's see what we've got here: a <code>NounTable</code>, inherited from a <code>ConjugationTable</code>. As I mentioned in the comments, this huge comment is unnecessary.</p>\n\n<p>You say you're worried about memory? <code>string</code> is a reference type, with the overhead it incurs. Consider t...
{ "AcceptedAnswerId": "40917", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T18:30:27.803", "Id": "40868", "Score": "5", "Tags": [ "c#", "lookup" ], "Title": "Conjugation tables for French" }
40868
<p><strong>Questions:</strong> </p> <ul> <li>How could this code be written better?</li> <li>Could this be written in less lines of code if constructed using classes?</li> <li>Also, If the user-created menu items were to be saved to a file for later use, which would be the best approach to use? (pickle? plain text fil...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-06T18:47:11.530", "Id": "70464", "Score": "0", "body": "Can you fix the indentation so that your initial code and intent can be undetstood ? Your code doesn't runs with current indentation. Start fixing with line#63" }, { "Cont...
[ { "body": "<p>Disclaimer : your code is not indented properly and I cannot run it. Also, it seems a bit convoluted to me so I haven't really tried to understand it. However, here are a few comments that might help you if you want to improve your code.</p>\n\n<hr>\n\n<p><strong>Keep it simple</strong></p>\n\n<pr...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T19:22:03.130", "Id": "40875", "Score": "1", "Tags": [ "python", "console" ], "Title": "Dynamic user-created menus with sub-menus in a command line script" }
40875
<p>I have this object wrapper class, which I will use to implement my Qt OpenGL scene. It is working, but I am looking for a way to:</p> <ul> <li>Improve the API.</li> <li>Remove extra OpenGL calls.</li> <li>Optimize it.</li> </ul> <p>I know that QGL stuff is deprecated and I should switch to newer Qt5 API, but it st...
[]
[ { "body": "<h3>GLObject</h3>\n\n<ol>\n<li><p>You seem to be using C++11, so don't assign <code>0</code> to pointers (in <code>QObject *parent = 0</code> for instance). Use <a href=\"http://en.cppreference.com/w/cpp/language/nullptr\" rel=\"nofollow noreferrer\"><code>nullptr</code></a>.</p></li>\n<li><p><code>G...
{ "AcceptedAnswerId": "85193", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T19:29:33.657", "Id": "40877", "Score": "7", "Tags": [ "c++", "object-oriented", "opengl", "wrapper", "qt" ], "Title": "OpenGL object wrapped in a Qt Widget" }
40877
<p><strong>Objective</strong> <br> Currently I have the flags hardcoded. But want to optimize my code for production. So I am wondering if I have this code done clean enough to leverage CSS inheritance while maintaining support for older browsers. </p> <hr> <p>I have this menu on my <a href="http://codepen.io/JGalla...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T20:10:38.533", "Id": "70021", "Score": "0", "body": "In my opinion, this is a misuse of the list element. Lists should only contain similar items (eg. groceries, colors, countries). The only appropriate markup choice here would be...
[ { "body": "<p>User \"cimmanon\" pointed out that lists would not be appropriate here. So I went with spans on this <a href=\"http://codepen.io/JGallardo/pen/BlgEe\">CodePen</a></p>\n\n<p><strong>HTML</strong></p>\n\n<pre><code>&lt;div class=\"international\"&gt;\n &lt;span class=\"intlFlag\"&gt;&lt;/span&gt;\n...
{ "AcceptedAnswerId": "40897", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T19:42:27.180", "Id": "40878", "Score": "4", "Tags": [ "html", "css", "json", "mustache" ], "Title": "How can this <ul> be set up to maximize inheritance if additional class...
40878
<p>I need to print this in Java, but I feel that my code is too big:</p> <blockquote> <pre><code>* ** *** **** *** ** * </code></pre> </blockquote> <pre><code>public static void main(String[] args) { for(int i=0; i&lt;=3; i++) { for(int j=0; j&lt;=i; j++) { System.out.print("*"); } ...
[]
[ { "body": "<p>Here is a lovely way to do it using only one nested for-loop:</p>\n<pre><code>for (int i = 0; i &lt; 7; i++) {\n for (int numStars = 0; numStars &lt; 4 - Math.abs(3 - i); numStars++) {\n System.out.print(&quot;*&quot;);\n }\n System.out.println();\n}\n</code></pre>\n<p>This uses th...
{ "AcceptedAnswerId": "40882", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T20:01:57.653", "Id": "40880", "Score": "14", "Tags": [ "java", "ascii-art" ], "Title": "Printing star greater symbol in Java" }
40880
<p>Reservoir sampling implementation. Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items from a list S containing n items, where n is either a very large or unknown number. If question is unclear let me know I will reply asap. Looking for code review, optimizations and bes...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T20:52:40.020", "Id": "70037", "Score": "0", "body": "You *could* add some short description at the top of your post about what exactly \"ReservoirSampling\" is (and please don't just link to the wikipedia article, make life easier f...
[ { "body": "<p>This is not an accurate implementation of the Reservoir Sampling algorithm.</p>\n\n<p>The Reservoir Algorithm creates a reservoir of size <code>k</code> and fills it from the first <code>k</code> items from the source data.</p>\n\n<p>It then iterates through the remaining source data, and selects ...
{ "AcceptedAnswerId": "40903", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T20:07:48.373", "Id": "40881", "Score": "1", "Tags": [ "java", "algorithm", "random" ], "Title": "Reservoir sampling" }
40881
<p>Here's my Python implementation of Conway's Game of Life:</p> <pre><code>class Game(object): def __init__(self, state, infinite_board = True): self.state = state self.width = state.width self.height = state.height self.infinite_board = infinite_board def step(self, count =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T19:02:08.470", "Id": "104433", "Score": "1", "body": "There seems to be a bug: the x and y variables passed to `State` will be ignored as you are redefining them when you use them as loop variables." }, { "ContentLicense": "...
[ { "body": "<p>This is excellent code for a Python novice.</p>\n\n<p>To address your questions:</p>\n\n<ol>\n<li>Rather than <code>x</code> and <code>y</code>, try naming your variables <code>row</code> and <code>col</code>. Then it wouldn't feel unnatural to write <code>self.state.board[row][col]</code>.</li>\...
{ "AcceptedAnswerId": "40898", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T20:36:28.020", "Id": "40886", "Score": "15", "Tags": [ "python", "beginner", "game-of-life" ], "Title": "Conway's Game of Life in Python" }
40886
<p>I've put together a board for <em>Ultimate Tic-Tac-Toe</em> (<a href="http://bejofo.net/ttt" rel="noreferrer">What's that?</a>). This is part of the current <a href="/questions/tagged/code-challenge" class="post-tag" title="show questions tagged &#39;code-challenge&#39;" rel="tag">code-challenge</a>: <a href="https:...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2020-04-01T20:07:25.913", "Id": "470361", "Score": "1", "body": "Looking back at this I can't help but think, this must be possible to do with CSS-grid these days...?" } ]
[ { "body": "<p>It looks good. I like the way it adapts to smaller windows.</p>\n\n<p>I'm not sure why (except as an aretfact of styling) you have a div around each button; maybe the button alone would do.</p>\n\n<p>Instead of using divs it might be possible/appropriate to use tables instead.</p>\n\n<p>You haven'...
{ "AcceptedAnswerId": "40894", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T20:43:32.837", "Id": "40888", "Score": "27", "Tags": [ "html", "css", "game", "community-challenge" ], "Title": "View for Ultimate Tic-Tac-Toe board" }
40888
<p>Can someone help me improve this code? I and trying to have a couple extension methods to convert strongly-typed lists to a <code>DataSet</code> and <code>DataTable</code> respectively.</p> <p>But... being so green to C#, I am not sure this is the most efficient way to do this.</p> <pre><code>using System; using ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-11-11T22:45:51.750", "Id": "126999", "Score": "0", "body": "Doesn't the using statement in the ToDataSet function call the Dispose method?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-11-12T14:27:16.247", ...
[ { "body": "<p>There are a few things I notice right off the bat.</p>\n\n<ol>\n<li><p>Your variable names while not bad, could be better. For instance <code>props</code> -> <code>properties</code>. Stuff like this makes the code easier to read.</p></li>\n<li><p>You have the properties, why not use a <code>fore...
{ "AcceptedAnswerId": "40893", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T21:04:19.510", "Id": "40891", "Score": "8", "Tags": [ "c#", "converting", "extension-methods", ".net-datatable" ], "Title": "Converting List to a DataTable and/or DataSet E...
40891
<p>I have a function that needs to evaluate some parameters to determine if they're valid or not. They all need to be evaluated individually, so I have some code like below.</p> <pre><code>#Configure widgets held in a layout def layoutConfigurer(name, widgetType, minW, minH, maxH, maxW, flat, focus, image, position=Fa...
[]
[ { "body": "<p>I don't see any simple way to generalize your <code>if</code> statements, since they result in very different actions. You might be able to push that complexity into the <code>widgetType</code> instead, if that code is under your control, but it won't reduce the total amount of code.</p>\n\n<p>Wha...
{ "AcceptedAnswerId": "40904", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-04T23:39:26.997", "Id": "40902", "Score": "4", "Tags": [ "python" ], "Title": "Alternative to multiple if statements" }
40902
<p>I want to get the shortest sequence to reach a number.</p> <p>Rules:</p> <ul> <li><code>A[0]</code> is always 1</li> <li>Either <code>A[i] = A[i-1]*2</code> or <code>A[i] = A[i-1]+1</code></li> </ul> <p>For example, if my input number is 17, my output should be 6, because</p> <pre><code>A[0]=1, A[1]=2, A[2]=4, A...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T06:53:12.843", "Id": "70111", "Score": "0", "body": "I believe I've interpreted \"minimum sequence\" correctly as \"shortest sequence\". If not, please revert my edit and let me know." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>My version of your code (other versions are a bit better; my version is more closely based on yours):</p>\n\n<pre><code>public static int GetMinimumSequence(int n)\n{\n if (n &lt;= 0)\n throw new ArgumentOutOfRangeException(); // or should return 0 when n == 0?\n\n if (n == 1)\n ...
{ "AcceptedAnswerId": null, "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T01:57:01.053", "Id": "40910", "Score": "8", "Tags": [ "c#", "algorithm", "pathfinding" ], "Title": "Getting the shortest sequence to reach a number" }
40910
<p>This is a very basic timer that can support multithreading with <code>std::thread</code> and <code>std::chrono</code>.</p> <p>The timer has the classic functions: <code>start()</code> and <code>stop()</code>.</p> <p>The <code>start()</code> method creates an independent thread (<em>if multithread support is enable...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T05:00:14.400", "Id": "70098", "Score": "0", "body": "Why would you use up all the resources required for a thread when you can set SIGALARM?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-06T03:20:52.35...
[ { "body": "<p>Basically you are working with these class members inside the thread functions <code>_temporize</code> and <code>_sleepThenTimeout</code>.</p>\n\n<ul>\n<li><code>timeout</code>, <code>_isSingleShort</code> and <code>_interval</code>, these three cannot be changed after the <code>start</code> funct...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T04:09:03.850", "Id": "40915", "Score": "6", "Tags": [ "c++", "multithreading", "c++11", "timer" ], "Title": "Simple Multithread Timer" }
40915
<pre><code>public class diceGame { public static void main(String[] args) { int dice1; int dice2; int count = 0; int theSum = 0; int lowest = Integer.MAX_VALUE; int finalSum = 0; int diceSum; int totalSum=0; while (count &lt; Integer.parseInt(a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T16:37:58.377", "Id": "70225", "Score": "0", "body": "as I commented on a previous question, `(6 - 1)) + 1) == 6`. To throw a dice, you want to use `new Random().nextInt(6) + 1`" } ]
[ { "body": "<ul>\n<li><p>As per Java naming convention, user-defined types should be capitalized. In this case, <code>diceGame</code> should be <code>DiceGame</code>.</p></li>\n<li><p>Prefer to have variables defined in the lowest scope possible. This is especially useful in not having to worry about whether o...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T05:09:25.717", "Id": "40919", "Score": "15", "Tags": [ "java", "beginner", "random", "simulation", "dice" ], "Title": "Basic Java dice game" }
40919
<p>I've created a linked list to use it in <a href="http://www.drdobbs.com/database/the-squarelist-data-structure/184405336" rel="nofollow">SquareList</a>. I've started to create a linked list based on just that. I want my class to follow the iterator pattern. How can it be improve to use vector iterator? </p> <pre...
[]
[ { "body": "<p>You define the copy constructor in terms of the assignment operator</p>\n\n<pre><code>Linkedlist( const Linkedlist &amp; rhs )\n{\n init( );\n *this = rhs;\n}\n</code></pre>\n\n<p>It is more traditional to do it the other way around. Normally you define the assignment in terms of the copy co...
{ "AcceptedAnswerId": "41039", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T06:00:11.773", "Id": "40922", "Score": "3", "Tags": [ "c++", "design-patterns", "linked-list", "iterator" ], "Title": "Creating linked list data with iterator pattern" }
40922
<p>I'm mixing <a href="http://developer.chrome.com/extensions/i18n.html" rel="nofollow">chrome.i18n</a> into my templates as <code>templateHelpers</code> with <a href="https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.view.md#viewtemplatehelpers" rel="nofollow">Backbone.Marionette</a>.</p>...
[]
[ { "body": "<p>I doubt performance will take much of a hit by passing <code>chrome.i18n</code> into your templates, but I still don't think you should do it.</p>\n\n<p>Templates should be solely for visualising data where possible, sometimes this requires a small amount of logic, but you should keep it out whene...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T06:01:01.120", "Id": "40923", "Score": "1", "Tags": [ "javascript", "template", "backbone.js", "i18n" ], "Title": "Mixing chrome.i18n (internationalization method) into templa...
40923
<p>I've been making a bot for Reddit that finds reposts (based on image MD5 comparing) and posts a small comment on the thread (that part will be later, right now it downloads images and compares MD5). If the image is original content, it will add it to its list of hashes. The source code is <a href="https://bitbucket....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T08:07:57.140", "Id": "70124", "Score": "2", "body": "You are aware that images which have been loaded and saved one time can be different (when looked at at the byte level)?" }, { "ContentLicense": "CC BY-SA 3.0", "Creat...
[ { "body": "<pre><code>public static bool DownloadImage(string url, bool isDirect) // returns if repost\n</code></pre>\n\n<p>C# supports something called <a href=\"http://msdn.microsoft.com/en-us/library/b2s063f7.aspx\" rel=\"nofollow noreferrer\">XML Documentation Comments</a> which allow you to document your c...
{ "AcceptedAnswerId": "40934", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T06:56:21.310", "Id": "40927", "Score": "7", "Tags": [ "c#", "image", "http", "reddit" ], "Title": "Reddit RepostFinder Bot" }
40927
<p>In CodeIgniter, I have created function (helper) to populate, store and retrieve checkbox group. I just wonder if I have written code is in proper way and optimized or needs some more finishing?</p> <p><strong>Function</strong></p> <pre><code>if ( ! function_exists('checkbox_group') ) { function checkbox_group...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T10:42:45.340", "Id": "70139", "Score": "1", "body": "Is this code is really optimized so there is no suggestion or feedback yet? :S" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-06T22:36:33.340", "...
[ { "body": "<p>I haven't worked with CodeIgniter before, so if I say something that argues their standards, please excuse me.</p>\n\n<p>It's such a basic piece of code that there isn't too much to be said. One things I notice right off the bat, your <code>checkbox_group()</code> function has a first parameter wi...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T07:51:37.377", "Id": "40932", "Score": "1", "Tags": [ "php", "codeigniter" ], "Title": "Checkbox Group Function and Usage" }
40932
<p>I am using jQuery to implement a basic quiz functionality. How can I improve this code snippet even more? Is there any better way of doing it?</p> <p>I am using jQuery 1.6.4.</p> <pre><code>/*jshint -W065 */ $(function () { var jQuiz = { answers: { q1: 'd', q2: 'd', ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T10:42:47.767", "Id": "70140", "Score": "0", "body": "Why are you binding two different functions to `$('.btnShowResult').click`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T11:12:54.510", "Id":...
[ { "body": "<p>Some suggestions</p>\n\n<ul>\n<li><p>If you ignore the <code>q</code> your questions object is a list of sequential integers so might as well be an array. This will simplify the logic later on.</p>\n\n<pre><code>answers: [\n 'd',\n 'd',\n 'a',\n 'c',\n 'a'\n]\n</code></pre></li>\n<l...
{ "AcceptedAnswerId": "41015", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T09:54:30.890", "Id": "40939", "Score": "2", "Tags": [ "javascript", "jquery", "game" ], "Title": "Basic quiz in jQuery" }
40939
<p>I have written the following function that takes an <code>address</code> object and builds a string using the object properties. It will later be used to display a tooltip</p> <pre><code>var getAddressTooltip = function (address) { var tooltip = ''; if (address.MasterAddress !== undefined &amp;&amp; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T14:15:54.130", "Id": "70193", "Score": "0", "body": "You're not taking things too far - you always need to validate your input. What you've done is copy/pasted the same checks on many different attributes. If you extract those int...
[ { "body": "<p>What about this:</p>\n\n<pre><code>var getAddressTooltip = function (address) {\n\n var tooltip = '';\n\n if (address.MasterAddress &amp;&amp;\n address.MasterAddress.Id) {\n tooltip += '[' + address.MasterAddress.Id + '] ';\n }\n if (address.PurchasingContact &amp;&amp;\...
{ "AcceptedAnswerId": "40953", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T11:03:45.553", "Id": "40941", "Score": "1", "Tags": [ "javascript", "strings", "cyclomatic-complexity", "null" ], "Title": "Reducing cyclomatic complexity in a simple strin...
40941
<p>I am sorting 2 arrays of object like this, but I know this is very bad. Any good approach, like using each method like so? ( I tried, but using each, I am unable to return the object )</p> <pre><code>var O1 = [{'name':'one'}, {'name':'two'}, {'name':'three'}, {'name':'four'}, {'name':'five'}, {'name':'six'}]; var ...
[]
[ { "body": "<p>There is nothing much inherently wrong with your code besides that you would want to extract that function so that you do not need to declare it twice:</p>\n\n<pre><code>function itemName( item ){\n return item.name;\n}\n\nvar sorted1 = _.sortBy(O1, itemName);\nvar sorted2 = _.sortBy(O2, itemName...
{ "AcceptedAnswerId": "41000", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T11:12:52.190", "Id": "40942", "Score": "2", "Tags": [ "javascript", "sorting", "underscore.js" ], "Title": "How to sort two array of objects using Underscore.js?" }
40942
<p>I have a function which verifies the "Password" field and suggests the user to enter a <em>strong password</em>. I also have a label named "Password Strength", referring to the strength of a password (<em>very weak, weak, medium</em>, etc).</p> <p>I'm just wondering if there is a better way to re-write this code.<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T11:48:50.867", "Id": "70161", "Score": "0", "body": "binding using `onkeyup=` the way you are is the same as using `eval`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T11:50:16.577", "Id": "701...
[ { "body": "<blockquote>\n <p><strong><em>Dislcaimer:</strong> I'm not a security researcher and the following answer is compiled from my own, humble knowledge. The math is very basic and there are many things to consider, if in doubt, <a href=\"https://security.stackexchange.com/\">pay Security a visit</a>. Al...
{ "AcceptedAnswerId": "40950", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T11:33:19.137", "Id": "40944", "Score": "54", "Tags": [ "javascript", "css", "validation" ], "Title": "Verifying password strength using JavaScript" }
40944
<p>Recently I set about to writing conversion functions in Haskell between decimal and <a href="http://en.wikipedia.org/wiki/Negabinary" rel="nofollow">negabinary</a>. I tried to write them in as much functional a style as possible, also aiming at brevity. Below I present my take at the task. I'd be interested in your ...
[]
[ { "body": "<p>A couple of things I noticed:</p>\n\n<p>xrem and xdiv are exactly the same except they use a different division function. You could therefore replace them with a single function that takes the type of division as a parameter:</p>\n\n<pre><code>dec2negbin :: Int -&gt; NegaBinary\ndec2negbin = rever...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T12:11:32.597", "Id": "40949", "Score": "5", "Tags": [ "haskell", "functional-programming", "converting", "integer" ], "Title": "Conversion from decimal to negabinary and vice ...
40949
<p>Aim: Import Excel to SQL</p> <p>Potential Issue: </p> <p>Wrong file type - this is handled in the 'upload' button by not allowing anything but *.xlsx files. The wrong type of Excel file (i.e. not 2003 onwards) would be good to be able to handle this as well.</p> <p>Notes:</p> <p>The below code does work. What I ...
[]
[ { "body": "<p>I'd suggest modularizing it, breaking it up into a few smaller functions that each do a small piece of the task. You might have one routine to open the file, one routine to establish the Excel connection, one to \"canonicalize\" the data (where you're fixing the Excel data), and one to write the ...
{ "AcceptedAnswerId": "40956", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T13:12:15.683", "Id": "40952", "Score": "1", "Tags": [ "sql", "asp.net", "excel" ], "Title": "Excel to SQL Upload" }
40952
<p>I wrote a function <code>split-seq-by-n</code> which accepts a sequence and a number and splits the sequence into subsequences of length n (the last subsequence getting the remaining elements). It works on all subclasses of <code>'sequence</code>, among others <code>'string</code>, <code>'cons</code>, <code>'vector<...
[]
[ { "body": "<p>It looks okay for a recursion exercise, but it's naive code. Not usable in 'production'.</p>\n\n<ul>\n<li>it conses like mad. It creates a lot of intermediate garbage. Splitting a string involves making lots of smaller strings.</li>\n<li>for lists it is not efficient, too</li>\n<li>CONCATENATE in ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T13:21:02.553", "Id": "40954", "Score": "4", "Tags": [ "recursion", "lisp", "common-lisp" ], "Title": "Generic sequence splitter in Common Lisp" }
40954
<p>The main impetus for this review is to determine if my ASP.NET Web API controller has too many dependencies. I'm of the opinion that 3-4 is okay, but 6 seems like too many. I have many controllers with similar layout. I've considered extracting all of the "PostPrimary" operations into a single wrapping dependency, b...
[]
[ { "body": "<p>I would consider inheritance when dealing with \"I have many controllers with similar layout\".</p>\n\n<p>When dealing with constructor overinjection, you could consider refactoring to aggregate services.</p>\n\n<p>I have also seen solutions where people use partial classes when dealing with const...
{ "AcceptedAnswerId": "40991", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T14:23:00.413", "Id": "40960", "Score": "3", "Tags": [ "c#", "dependency-injection", "controller" ], "Title": "Controller with too many dependencies?" }
40960