body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Over the past week, we tried to make our AngularJS model layer more powerful and reduce complexity in our controllers and template by using the object-oriented programming pattern and the CoffeeScript class keyword. You can see the result here: <a href="http://plnkr.co/edit/c1uxN6ZorQzOVizlzU5Y?p=preview" rel="nofol...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T21:29:16.903", "Id": "86458", "Score": "0", "body": "It's been a few days. We've improved this class a lot. The current code is missing a lot of functionalities still. I should be able to post an updated version soon." }, { ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T03:04:23.610", "Id": "48954", "Score": "4", "Tags": [ "object-oriented", "coffeescript", "angular.js" ], "Title": "An Object-Oriented Programming pattern for AngularJS models usin...
48954
<p>I'm writing a program which determines how many bits are in a floating point value (this will be run on Unix).</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; void countbits(int k); int main(){ int input; // int a = (int) malloc(sizeof(int)); printf("Please enter a number: "); sc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T09:49:28.670", "Id": "85976", "Score": "0", "body": "I don't see how this code has anything to do with [tag:floating-point]. Please explain? I'm putting the question back on hold in the meantime." } ]
[ { "body": "<p>You should do the output in <code>main()</code>, not in <code>countbits()</code>. Functions should have only one primary purpose, according to the <a href=\"http://en.wikipedia.org/wiki/Single_responsibility_principle\" rel=\"nofollow noreferrer\">Single Responsibility Principle (SRP)</a>. In th...
{ "AcceptedAnswerId": "48957", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T03:49:38.220", "Id": "48956", "Score": "1", "Tags": [ "c", "homework", "floating-point" ], "Title": "Determine how many bits are in a floating point value" }
48956
<p>This is my first attempt at a login system! I've only had roughly 2 days of experience with MySQL and PHP so far and this is what I came up with:</p> <pre><code>&lt;?php session_start(); //Start Database $IP = ""; $user = ""; $pass = ""; $db = ""; $con = mysqli_conne...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-04-28T14:48:13.273", "Id": "159675", "Score": "0", "body": "It is my general opinion that new programmers should not be authoring login systems. A modern login system should have two-factor authentication, anti-phishing support, and a ho...
[ { "body": "<p>At a quick look:</p>\n\n<ul>\n<li><p>Your code is <strong>vulnerable to SQL Injection</strong>: assume the user wants to hurt you, so always parse superglobals <code>$_GET</code> and <code>$_POST</code></p>\n\n<p><a href=\"https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-i...
{ "AcceptedAnswerId": "48962", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T04:43:19.110", "Id": "48958", "Score": "9", "Tags": [ "php", "mysqli", "session", "authentication" ], "Title": "First PHP login system" }
48958
<p>Below is the code that I've written for matrix multiplication:</p> <pre><code>import java.text.DecimalFormat; import java.util.InputMismatchException; import java.util.Scanner; public class MatrixMultiplication { private static final String TERMINATED_MESSAGE = "Terminated" + "," + " "; private static fin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T12:52:34.170", "Id": "85993", "Score": "1", "body": "I can't say much of the code, but all the input that you require for a simple multiplication seems to make this very uncomfortable to use (you even request the 'middle' dimension ...
[ { "body": "<h1>Static and void</h1>\n\n<p><strong>All</strong> your variables are static. <strong>All</strong> your methods return <code>void</code>. This is not good.</p>\n\n<p>Java is an object-oriented language. You're not using it that way. You're using it more as a procedural language by having everything ...
{ "AcceptedAnswerId": "48972", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T11:36:19.840", "Id": "48969", "Score": "10", "Tags": [ "java", "optimization", "algorithm", "matrix" ], "Title": "Matrix multiplication" }
48969
<p>This question is a followup from my previous question <a href="https://codereview.stackexchange.com/questions/48869/my-eventbus-system">My EventBus system</a>, and incorporates most points from <a href="https://codereview.stackexchange.com/a/48889/32231">@rolfl's answer</a>.</p> <p>It includes, but is not limited t...
[]
[ { "body": "<p>While synchronization is correct now, <code>Collections.synchronizedSet(new HashSet&lt;&gt;()))</code> is still a fairly coarse grained way to synchronize. You can replace this with <code>Collections.newSetFromMap(new ConcurrentHashMap&lt;&gt;())</code> to benefit from the better locking strategy ...
{ "AcceptedAnswerId": "49053", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T11:37:25.680", "Id": "48970", "Score": "6", "Tags": [ "java", "thread-safety", "reflection", "event-handling" ], "Title": "My EventBus system followup" }
48970
<p>I have requirement to apply multiple filters on database. I will have multiple conditions in the front end where the user can select the conditions he wants to filter with and then see the output. This is similar to the filter that Freshdesk has or for instance similar to many ecommerece sites.</p> <p>This is my Co...
[]
[ { "body": "<p>I would advise you to implement search in Index action. If there are no search filters passed, then simply return everything (both for HTML and JSON).</p>\n\n<p>You should rebuild a bit of the form so search params are nested, and you won't have to filter them.</p>\n\n<p>Finally, you can move the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T11:59:32.133", "Id": "48971", "Score": "2", "Tags": [ "performance", "ruby-on-rails", "search", "coffeescript", "active-record" ], "Title": "Multiple search filter like th...
48971
<p>I wrote a short program for my exercise routine. It takes a JSON array of exercise names and duration (seconds) and puts it on the screen. The JSON looks like this:</p> <pre><code>var exerciseArray = [ { "desc": "Pushup/Pullup", "countdown": 30 }, { "desc": "Squat punch"...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T14:07:47.857", "Id": "86002", "Score": "0", "body": "Is your intent to have the code write some HTML, wait until that exercise timeout, and then write some different HTML and then wait for the next timeout, or are you doing updates ...
[ { "body": "<p>If you only need the entries once, you could simply keep using <code>shift</code> until there are no more entries:</p>\n\n<pre><code>var exercises = [\n {\n \"desc\": \"Pushup/Pullup\",\n \"countdown\": 30\n }, {\n \"desc\": \"Squat punch\",\n \"count...
{ "AcceptedAnswerId": "48984", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T13:13:12.113", "Id": "48978", "Score": "4", "Tags": [ "javascript", "timer", "iteration" ], "Title": "Iterate through series of timers" }
48978
<p>I was tasked with making a program that uploads a .csv to a NoSQL cluster. The files are larger (typically 2-17GB). My program works in batch mode and can process a 17GB file in 6 hours.</p> <p>I decided to make a consumer-producer multithreading structure. This caused it to be significantly slower. I want to know ...
[]
[ { "body": "<p>I'm not an expert in cluster operations, so I'll review the parts I do know.</p>\n\n<p><strong>Single-letter variable names</strong></p>\n\n<p>These are a big no-no unless the only thing you're worried about is not being fireable. Any maintenance programmer looking in the middle of a chunk of code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T13:53:18.517", "Id": "48981", "Score": "1", "Tags": [ "c#", "multithreading" ], "Title": "Uploading a .csv to a NoSQL cluster - batch faster than consumer/producer" }
48981
<p>As an exercise, I decided to create a simple Tic-Tac-Toe game. It is Ruby on Rails based, but as for now I'm not using the server side for anything (I intend to build up on it in the future, though).</p> <p>As I'm rather new with JavaScript, HTML5 and CSS, I'd like some feedback regarding what did I do wrong or wha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T23:57:09.997", "Id": "86934", "Score": "0", "body": "http://jsfiddle.net/sd563/" } ]
[ { "body": "<p>First, a (proper) HTML document looks like this:</p>\n\n<pre><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n &lt;head&gt;\n &lt;title&gt;Tic tac toe&lt;/title&gt;\n &lt;/head&gt;\n &lt;body&gt;\n &lt;!-- Stuff --&gt;\n &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n\n<p>Html, h...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T16:02:20.093", "Id": "48995", "Score": "11", "Tags": [ "javascript", "jquery", "game", "css", "html5" ], "Title": "HTML5 / JavaScript Tic-Tac-Toe" }
48995
<p>I have this basic Java code to find average of eight immediate neighbors of a matrix.</p> <p>Is there any way to simplify or merge any part of it, or can I refactor it?</p> <p>I'm a beginner in Java programming and am trying to improve myself. </p> <pre><code>// CODE STSRT import java.util.Scanner; import java.la...
[]
[ { "body": "<p>Welcome to CodeReview! </p>\n\n<h1>Class naming</h1>\n\n<p>Maybe it's a term I'm not familiar with but <code>Matrixer</code> does not seem to ring a bell. Is it supposed to identify a \"creator of matrixes\"? Is it the name of your project? If you haven't made a conscious decision for this name, I...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T16:46:52.080", "Id": "48996", "Score": "10", "Tags": [ "java", "beginner", "object-oriented", "matrix" ], "Title": "Finding average of eight immediate neighbors of a matrix" }
48996
<p>This is a simple GTK+ program that takes a spun article as input and shows a random output every time the user clicks the "Spin" button.</p> <p>It supports many levels of nested spinning like:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>The {car|automobile} is {{very |}fine|{really {pretty...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T18:48:25.267", "Id": "86055", "Score": "0", "body": "Tried to compile but apparently you've made some changes to the interface of `Dynamic_String`. Specifically, is there a new member `cstring`?" }, { "ContentLicense": "CC ...
[ { "body": "<p>This may be disappointing but: I didn't find much wrong with it. That said, there are a few small points that might be useful.</p>\n\n<h2>Reducing memory leaks</h2>\n\n<p>I almost didn't even write this one because the GTK library is notorious for leaking memory. With that said, there are a few ...
{ "AcceptedAnswerId": "49029", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T17:49:25.397", "Id": "49000", "Score": "4", "Tags": [ "c", "gui" ], "Title": "Spun article reader" }
49000
<p>In <a href="https://codereview.stackexchange.com/a/48987/23788">this answer</a> I suggested using a <em>fluent interface</em> "builder" to replace all the hard-coded, repetitive and quite error-prone inline XML string concatenations.</p> <p>This code might need a bit of tweaking to work <em>perfectly</em> with the ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T20:10:37.963", "Id": "86071", "Score": "3", "body": "I'm not sure I like the name `Where`. In LINQ, `Where` means filtering, here it means something quite different." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<p><code>ToString()</code> does too many things, it should only be calling <code>_xDoc.ToString()</code>; it has side-effects that make it dangerous to call more than once:</p>\n\n<pre><code>var foo = builder.ToString()\nConsole.WriteLine(builder.ToString());\nConsole.ReadLine();\n</code></pre>\n\n<p...
{ "AcceptedAnswerId": "49014", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T18:15:48.113", "Id": "49003", "Score": "7", "Tags": [ "c#", "xml", "fluent-interface" ], "Title": "Fluent Interface for a XmlQueryBuilder" }
49003
<p>I haven't done much .NET development in several years. Now I'm enjoying some of the new stuff with modern .NET. I just want to make sure I'm using things correctly. I'm a solo developer with no one else to bounce ideas off of.</p> <p>I have a new MVC web application. I'm using the Massive micro-ORM. I'm a big ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T20:22:53.313", "Id": "86233", "Score": "0", "body": "A question. If you are loading the enum from cache what happens if two different objects with the same enum type get cached. Will you lose information as one will overwrite the ...
[ { "body": "<ul>\n<li><p><code>MemoryCache</code> is actually thread-safe, so you don't need a double-check lock</p>\n\n<pre><code>public static class Caching\n{\n public static dynamic LoadFromCache(string cacheKey, int secondsToCache, Func&lt;object&gt; query)\n {\n object result = query.Invoke();...
{ "AcceptedAnswerId": "49354", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T18:33:24.443", "Id": "49005", "Score": "4", "Tags": [ "c#", "mvc", "cache" ], "Title": "ASP.NET MVC architecture questions" }
49005
<p>I would like to know what you think:</p> <pre><code>&lt;?php $nav_normal = array("1. Home","2. Read Me","3. License Agreement","4. General Information","5. Database Installer","6. Create an Account","7. Create Config","8. Successfully installed" ); $last_normal = array_pop(array_keys($nav_normal)); foreach($...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T20:45:51.083", "Id": "86080", "Score": "0", "body": "Thanks for editing it I guess just don't see why php is wrong and \"must\" be PHP" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T20:50:45.293", ...
[ { "body": "<pre><code>&lt;?php\n\n// first up i have removed the numbers, those numbers can be automatically added using an ordered list,\n// then if you add a menu option later you don't have to renumber everything and look through every file to check the $Nav_ID matches\n$nav_normal = array(\"Home\",\"Read Me...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T20:38:44.757", "Id": "49015", "Score": "3", "Tags": [ "php", "html" ], "Title": "Navigation bar using PHP" }
49015
<p>Is there a more efficient approach to this code?</p> <pre><code>// save associated tag let saveTag question = if question.Tag = null then () else let tagCount = query{ for row in db.Tags_Tags_Tags do where (row.Tag = question...
[]
[ { "body": "<p>You don't need the empty <code>if</code> branches. An <code>if</code> without an <code>else</code> automatically returns <code>unit</code>. So you can simplify it to:</p>\n\n<pre><code>let saveTag question = \n\n if question.Tag &lt;&gt; null then\n let tagCount = \n query{\n ...
{ "AcceptedAnswerId": "49021", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T20:54:56.210", "Id": "49016", "Score": "2", "Tags": [ "linq", "f#" ], "Title": "Check database for item and create it if it doesn't exist" }
49016
<p>I recently posted some sample code that I was providing students with and got great feedback so figured I post another one of the examples I will be providing students with. (See <a href="https://codereview.stackexchange.com/questions/48109/simple-example-of-an-iterable-and-an-iterator-in-java">Simple Example of an ...
[]
[ { "body": "<p><strong>General</strong> </p>\n\n<ul>\n<li><p>Use full JavaDoc for method comments. Instead of \"Throw X in case Y\" go for \"@throws X if Y\"</p></li>\n<li><p>You never need to call the <em>default</em> (zero-argument) superclass constructor. If the first statement of a constructor isn't a call t...
{ "AcceptedAnswerId": "49030", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T01:05:23.600", "Id": "49027", "Score": "8", "Tags": [ "java", "tree", "inheritance" ], "Title": "Basic Postfix Calculator in Java" }
49027
<p>Fellow students are supposed to review and tell what my code is doing for a grade, this is why I'm asking on here first. I want to see if its clear enough. </p> <pre><code>public class SpellParser { private static final String SPELL_PACKAGE_LOCATION = "edu.swosu.wordcraft.spells."; private Documen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T02:06:34.147", "Id": "86110", "Score": "0", "body": "Welcome to CR! I have edited the code block so as to include the fist few lines, feel free to edit the indentation to reflect what's in your IDE (might have to do with the fact th...
[ { "body": "<ul>\n<li><p>Your comments don't help much. They should explain why you're doing what you're doing, not just paraphrase the code. If you can't tell the reader anything more than the code already does, then a comment is pretty much just noise.</p></li>\n<li><p><code>setUpDom()</code> should probably...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T01:18:46.550", "Id": "49028", "Score": "6", "Tags": [ "java", "game" ], "Title": "SpellParser for a text-based RPG" }
49028
<p>I implemented the <code>group</code> function:</p> <pre><code>group' :: (Ord a) =&gt; [a] -&gt; [[a]] group' [] = [] group' xs = takeWhile (== head' xs) (sorted xs) : (group' $ dropWhile (== head' xs) (sorted xs)) where sorted ys = mergesort' (ys) ...
[]
[ { "body": "<p>You have made some uncommon stylistic choices which are not to your benefit, and a few things aren't doing what I think you think they're doing. </p>\n\n<p>First, the stylistic elements. Your whitespace is excessive, there's no need to push everything that far to the right and out of line with the...
{ "AcceptedAnswerId": "49045", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T01:56:45.807", "Id": "49031", "Score": "5", "Tags": [ "haskell", "reinventing-the-wheel" ], "Title": "Haskell's `group` Function" }
49031
<p>In the below example I have tried to show how we can break a long running background task running in a service into different states of a state machine and notify the front end UI about each and every stage as they occur in the service.</p> <p>Here I have used a service called <code>LongRunningService</code> which ...
[]
[ { "body": "<p>I would replace</p>\n\n<pre><code>private static final int CONNECTING = 1;\nprivate static final int CONNECTED = 2;\nprivate static final int DOWNLOADSTARTED = 3;\nprivate static final int DOWNLOADFINISHED = 4;\n</code></pre>\n\n<p>by an Enum which would add typesafety and also helps your IDE to d...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T02:20:37.667", "Id": "49032", "Score": "1", "Tags": [ "java", "android" ], "Title": "Implementation of Finite State machine in long running task in an Android service" }
49032
<p>I got three classes for MySQL Database access/manipulation:</p> <ol> <li><code>Conector</code>. It has got methods for connecting, disconnecting, querying and updating db.</li> <li><code>ConectorCliente</code>. It simply extends first and got its constructor receiving <code>user</code>, <code>password</code>, <code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T09:32:01.727", "Id": "86143", "Score": "3", "body": "May be pedantic to say, but I'd **really** advise against using non-english names (I'm guessing this is Spanish) in code." } ]
[ { "body": "<p>Just for starters...</p>\n\n<ul>\n<li>Method names in your <code>Conector</code> class should be in <code>camelCase</code> too</li>\n<li>There is no need for <code>ConectorCliente</code> if all it does is to extend <code>Conector</code> and use the same constructor.</li>\n<li>Your <code>try-catch<...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T05:12:20.053", "Id": "49036", "Score": "8", "Tags": [ "java", "mysql", "database" ], "Title": "Java and MySQL connection classes and method implementations" }
49036
<p>Is this a good approach or is there some other solution that I am not aware of?</p> <pre><code>//C++ program to count number of words in text file #include&lt;fstream&gt; #include&lt;iostream&gt; #include&lt;string&gt; using namespace std; int main() { ifstream inFile; //Declares a file stream object stri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T06:11:52.520", "Id": "86119", "Score": "2", "body": "Please do add some comment, like what your class have to do. Are there some specific things we need to review?" } ]
[ { "body": "<p>Your code has a few problems.</p>\n\n<ol>\n<li>You should learn to <em>not</em> use <code>using namespace std;</code>. It's generally frowned upon.</li>\n<li>You should <em>never</em> use <code>while(!inFile.eof())</code>. It's pretty much a guaranteed bug.</li>\n<li>You <em>should</em> use standa...
{ "AcceptedAnswerId": "49039", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T06:01:08.530", "Id": "49038", "Score": "14", "Tags": [ "c++", "file" ], "Title": "Count number of words in a text file" }
49038
<p>I am using PDO for the first time in my project. In my previous project someone suggested me to use PDO as my queries were wide open to inject. I am pasting a sample code of my project. Can you please let me know how safe my code and query is?</p> <pre><code>&lt;?php require('config.php'); try { $pid = $_GE...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T07:37:02.663", "Id": "86134", "Score": "1", "body": "It is still wide open to sql injection. This is never sanitized $pid = $_GET['pid']; and is used directly in your query." }, { "ContentLicense": "CC BY-SA 3.0", "Creat...
[ { "body": "<p>Not safe at all, I'm afraid. Sure, you're calling <code>PDO::prepare</code>, to create a prepared statement, and that's all fine and dandy, but you are directly concatenating unsanitized user data into the string form which the query is prepared:</p>\n\n<pre><code> $pid = $_GET['pid'];\n $sql = \"...
{ "AcceptedAnswerId": "49046", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T06:20:26.563", "Id": "49041", "Score": "1", "Tags": [ "php", "mysql", "pdo", "sql-injection" ], "Title": "How safe is my MySQL query?" }
49041
<p>I have a script that creates an active CSS on link, but I think there are a lot of <code>if</code> statements. Can someone help me refactor this?</p> <pre><code>var link = window.location.pathname; var currentPageName = window.location.href.match(/[^\/]+$/)[0]; var hl = $('#ih').val(); if (hl == 'True') { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T08:20:15.230", "Id": "86138", "Score": "0", "body": "Can you explain how you came up with this? That way we can find other ways to do it. I'm pretty sure setting an `active` based on the url isn't this long." } ]
[ { "body": "<p>Please consider that using Javascript might not be the best solution. If you use something like PHP, passing a variable to the file generating the html setting which one is active is a cleaner solution.</p>\n\n<p>Anyway..</p>\n\n<p>First it seems that the following variable is unused and can be re...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T07:01:45.050", "Id": "49043", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Script that creates an active CSS on link" }
49043
<p>I'm developing a win forms application in MVP pattern. In the application, there is a small module to show the branch offices (called points) where the attendance entering process has been completed. Those details should be shown in a data grid view. </p> <p>So I have a form (View), a presenter and a data service c...
[]
[ { "body": "<blockquote>\n <p><em>For the simplicity I'm not using a \"model class\" for this [...]</em></p>\n</blockquote>\n\n<p>Then it's not <em>Model</em>-View-Presenter you have here.</p>\n\n<blockquote>\n<pre><code>var Presenter = new AttendancePointPresenter(AttendancePointView, ds);\n</code></pre>\n</bl...
{ "AcceptedAnswerId": "49086", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T07:27:33.483", "Id": "49044", "Score": "4", "Tags": [ "c#", ".net", "winforms", "mvp" ], "Title": "Populating a Data Grid View in MVP" }
49044
<blockquote> <p><strong>Problem Statement</strong></p> <p>A group of farmers has some elevation data, and we’re going to help them understand how rainfall flows over their farmland. </p> <p>We’ll represent the land as a two-dimensional array of altitudes and use the following model, based on the idea th...
[]
[ { "body": "<p>I find this a nice piece of code.</p>\n\n<p>Still I found 1 minor and 1 bigger issue.</p>\n\n<h2>Bigger issue :</h2>\n\n<p>You say in the javadoc that if more then 1 bassin is found the biggest must be returned.<br/>\nYou implement nice testing but this I don't find back in the testings.<br/>\nAll...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T08:53:56.707", "Id": "49048", "Score": "10", "Tags": [ "java", "algorithm", "matrix", "backtracking" ], "Title": "Find biggest basin" }
49048
<p>In this function I'm parsing the page of the item in the online shop. Some items lack the picture, some lack price etc, so there are few <code>if-else</code> checks.</p> <p>My questions are:</p> <ol> <li>How to get rid of these ugly <code>if-else</code> checks?</li> <li>How I can "pythonize" my code further?</li> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T10:14:59.057", "Id": "86146", "Score": "1", "body": "Welcome to CodeReview.SE! I think we are missing the definition for (at least) `ids`. Am I right ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T...
[ { "body": "<p>You cannot get rid of those if-else checks, but you can get rid of the nesting. For example:</p>\n\n<pre><code>if foo:\n if bar:\n return foo + bar\n</code></pre>\n\n<p>could be flattened to</p>\n\n<pre><code>if not foo:\n return None\nif not bar:\n return None\nreturn foo + bar\n<...
{ "AcceptedAnswerId": "49059", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T09:47:05.880", "Id": "49052", "Score": "5", "Tags": [ "python", "beautifulsoup" ], "Title": "Parsing item page for an online shop" }
49052
<p>As part of a simple (naive) internationalization attempt in Go, I am trying to come up with a number formatting routine with customizable decimal and thousands separator.</p> <p>Is this approach alright? </p> <pre><code>var decLen = 1 var decSep = "." var thouLen = 1 var thouSep = "," func numberFormat(floatVal f...
[]
[ { "body": "<p>Your approach is ok, but I think it could make better use of some of the existing library functionality. Also, this looks like something that should be a user-facing function, so let's rename it to <code>NumberFormat</code> (since anything starting with a lower case letter is not exported from a p...
{ "AcceptedAnswerId": "49788", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T10:16:00.660", "Id": "49055", "Score": "4", "Tags": [ "formatting", "go", "floating-point", "i18n" ], "Title": "Number formatting" }
49055
<p>I'm looking to change a single jQuery plugin option when the window hits certain breakpoints.</p> <p>The code below works, however I'm conscious of repeating code and feel there is a more elegant way writing code for examples like this.</p> <p>My initial thoughts would be to store the first call in a variable.</p>...
[]
[ { "body": "<p>You might extract your code to a function to remove the repeated code, passing the values ​​that change as parameters:</p>\n\n<pre><code>$(window).smartresize(function () {\n\n if (config.wWidth &gt;= 768 &amp;&amp; config.wWidth &lt;= 1024) {\n createVaccordion(config, 2);\n\n } else...
{ "AcceptedAnswerId": "49094", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T10:45:32.890", "Id": "49057", "Score": "3", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "Changing a single jQuery plugin option on window resize" }
49057
<p>Now FizzBuzz itself isn't a big challenge but I agree that it can be a good tool to see if someone can code or not. I wanted to practice my LINQ a little bit so here's my single line FizzBuzz solution.</p> <pre><code>Enumerable.Range(1,100).Select( n =&gt; (n % 15 =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T12:14:59.637", "Id": "86154", "Score": "14", "body": "Would you care to ask a question? :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T14:21:13.307", "Id": "86178", "Score": "3", "body...
[ { "body": "<p>Overall, I like this. It is concise, and neat, and all. My only beef is the nested ternaries.</p>\n<p>In general, ternary operator precedence is complicated by the lack of blocks.... The need for the parenthesis on the modulo precedence makes the conditions clear ( <code>(n % 15 == 0)</code> ) and...
{ "AcceptedAnswerId": "49066", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T10:53:42.753", "Id": "49058", "Score": "24", "Tags": [ "c#", "linq", "fizzbuzz" ], "Title": "Single line FizzBuzz solution in LINQ" }
49058
<p>Can you give me some performance advice on how to optimize the time of execution of the following calculation of E?</p> <pre><code>package calculatee; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; public class CalculateE { static long start1 = System.nanoTime(); publ...
[]
[ { "body": "<p>you can split up the calculation in your <code>for</code> loop into threads and sum up the results afterwards: here an example for 4 Threads: Use as many Threads as you have <code>CPU</code>s. It's important to add the result inside a <code>synchronized</code> block, otherwise you result could be ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T11:15:08.307", "Id": "49060", "Score": "5", "Tags": [ "java", "performance", "mathematics" ], "Title": "Better performance in calculating E" }
49060
<p>Inspired by some older questions, I decided to create my own postfix calculator using Java 8. I'd like to have all aspects reviewed.</p> <pre><code>public enum Operator implements DoubleBinaryOperator { PLUS ("+", (l, r) -&gt; l + r), MINUS ("-", (l, r) -&gt; l - r), MULTIPLY("*", (l, r) -&gt; l * ...
[]
[ { "body": "<p>I like how the Functions have simplified the enum, but, you have put logic in the implementation class that belongs in the enum....</p>\n\n<p>The code:</p>\n\n<blockquote>\n<pre><code>private static final List&lt;String&gt; OPERATORS_LIST = Arrays.stream(Operator.values())\n .map(Operator::...
{ "AcceptedAnswerId": "49069", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T11:29:40.767", "Id": "49063", "Score": "15", "Tags": [ "java" ], "Title": "Simple Postfix Calculator using Java 8" }
49063
<p>I'm working on some teaching examples showing the perils of accessing the Dictionary class concurrently. In the code below each function is designed to do a word count across a number of files. (This isn't the best way of doing the count but it's there to make a point about Dictionary.)</p> <p>The first example, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T14:05:58.403", "Id": "86176", "Score": "0", "body": "Why _wouldn't_ it be thread-safe? Isn't that what `ConcurrentDictionary` is for?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T14:31:36.373", ...
[ { "body": "<p>If you just used your original code (<code>TryGetValue</code> followed by an indexer set) with <code>ConcurrentDictionary</code>, then that wouldn't be thread-safe.</p>\n\n<p>But you're using the <code>AddOrUpdate</code> method instead, which is guaranteed to be thread-safe (i.e. atomic), so this ...
{ "AcceptedAnswerId": "49079", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T11:36:11.860", "Id": "49064", "Score": "2", "Tags": [ "f#", "hash-map" ], "Title": "Is this use of ConcurrentDictionary truly thread safe?" }
49064
<p>I am writing some code in Ruby on Rails to <strong>Create an object</strong>.</p> <p>I am using <strong>Ruby 2.0</strong> and <strong>Rails 4.0.3</strong> in my Application.</p> <p>I have a Model called:</p> <pre><code>class GroupUsers &lt; ActiveRecord::Base belongs_to :users belongs_to :group </code></pre> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T17:54:59.897", "Id": "86215", "Score": "0", "body": "I suggest adopting a style guide appropriate to the Ruby version of your project and adhering to that. ruby-style-guide enforces Ruby 1.9 style hash syntax for Ruby 1.9+ projects...
[ { "body": "<p>Depends on the Ruby version you're using. If you're using Ruby 1.9.2+ then the second syntax is cleaner in terms of readability. </p>\n\n<p>If you're using Ruby 1.8 then you can't use the second syntax anyway and you have not choice.</p>\n", "comments": [ { "ContentLicense": "CC ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T13:32:02.673", "Id": "49071", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Which syntax is preferred to create a Hash in Ruby on Rails?" }
49071
<p>I'm creating a 2D tile based platformer with AABB (Axis aligned bounding boxes), and it works, I just want to organize and optimize my setup. Here are methods in my player class and entity class that are relevant to the collision. How could I make this better? I'm harshly looking at that <code>public boolean[]</code...
[]
[ { "body": "<p>You play around with different ordering (depending on you data) it may be faster to check absolutes first, or last.</p>\n\n<pre><code>if(leftTile &lt; 0 || leftTile &gt;= map.getWidth() || topTile &lt; 0 ||....\n</code></pre>\n\n<p>can become</p>\n\n<pre><code>if(leftTile &lt; 0 || topTile &lt; 0 ...
{ "AcceptedAnswerId": "49082", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T13:35:09.157", "Id": "49072", "Score": "6", "Tags": [ "java", "game", "collision" ], "Title": "Orginizing/Optimising my collision detection setup" }
49072
<p>It's a dynamic array, the elements can be accessed normally and it supports any type. I believe I'm relying on undefined behavior when I treat every pointer to pointer as <code>void **</code> and I would like to know if it will work on the main platforms.</p> <p>Every call to <code>da_reserve()</code> and <code>da_...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-28T04:42:59.123", "Id": "104485", "Score": "1", "body": "I don't have time to write a detailed answer right now, but to put your doubts to rest: yes, this implementation relies on undefined behaviour, not because of `void **` but becau...
[ { "body": "<h1>Nasty Hack</h1>\n<p>I grant that it's a hack but I'd like to know of a platform where the following doesn't fix the alignment issue:</p>\n<pre><code>typedef struct {\n size_t size;\n size_t position;\n size_t slots;\n size_t padding;//NOT USED.\n} Index;\n</code></pre>\n<p>The alignme...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T14:27:58.190", "Id": "49078", "Score": "7", "Tags": [ "c", "array" ], "Title": "Dynamic array in C" }
49078
<p>I had a jQuery program that displays some hover-over messages when touching an icon, in order to make it disappear the user needs to click again in the icon.</p> <pre><code>am.homepage.Index.prototype.touchableTitleBinding = function () { var that = this; $('.' + this.bindingClassForTouchableTitle).on('touc...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T14:45:14.487", "Id": "49080", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Hide element when clicking anywhere but some elements using jQuery" }
49080
<p>I'm creating an extension method that can be used on any type. The idea is that if this method is called, it checks if value is null. If null, it needs to return a default instance of the specified type.</p> <pre><code>public static dynamic CreateDefaultIfNull&lt;T&gt;(this object item) { if(item == n...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T14:57:22.823", "Id": "86193", "Score": "2", "body": "What will happen if the \"first\" constructor's parameter list has value types (such as `int`)? Will assigning `null` to it blow up?" }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>The biggest problem for me is that this is an extension method on <code>System.Object</code> and returns a <code>dynamic</code>.</p>\n\n<p>Because this is already generic on <code>T</code>, <code>T</code> can be inferred if used as the parameter and return type. It will make invocation simpler at ...
{ "AcceptedAnswerId": "49093", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T14:49:21.650", "Id": "49081", "Score": "6", "Tags": [ "c#", "extension-methods", "null" ], "Title": "Extension method to return a default value for any null value" }
49081
<p>I wrote this memory pool as a code sample for a job interview. It provides a per-class memory pool that can offer faster runtime performance for classes that need to be traversable and (de)allocatable during runtime.</p> <p>Specifically, it provides in-order traversal of the allocated data blocks, to improve cache ...
[]
[ { "body": "<blockquote>\n <p>Any suggestions? Obvious issues? Glaring mistakes?</p>\n</blockquote>\n\n<p>A few observations:</p>\n\n<ul>\n<li>you are including iostream ... consider removing it, since you have no i/o code (none that I could see)</li>\n<li>consider defining your allocation data as:</li>\n</ul>\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T16:32:48.613", "Id": "49084", "Score": "3", "Tags": [ "c++", "memory-management" ], "Title": "Traversable memory pool" }
49084
<pre><code>Student http://semisalsaja.com/sekolah/student.asmx?WSDL - studentList Mentor http://semisalsaja.com/sekolah/mentor.asmx?WSDL - mentorList study http://semisalsaja.com/sekolah/study.asmx?WSDL - studyList </code></pre> <p>I'm trying to get data from some SOAP resources (mentioned above):</p> <pre><code>cl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T12:49:04.363", "Id": "86510", "Score": "0", "body": "Hi Jamal,\nThank you for editing my question so can be more understandable for others." } ]
[ { "body": "<p>Ok, given that you're after some CR on your understanding (and usage) of OO techniques, I'll go through your code almost line by line. If my criticisms strike you as blunt, please keep in mind that my goal is to help, not to offend.</p>\n\n<p><strong><em>Coding standards</em></strong><Br>\nThis ha...
{ "AcceptedAnswerId": "49148", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T18:21:09.707", "Id": "49095", "Score": "2", "Tags": [ "php", "object-oriented", "classes", "prototypal-class-design" ], "Title": "Get data from some SOAP resources" }
49095
<p>Implemented observers in C++11 in a generic and statically accessible way. Though an instance is created, it's used only for cleanup and lifetime management.</p> <pre><code>template&lt;typename... Args&gt; class Observers { private: unordered_map&lt;int, vector&lt;function&lt;void(Args...)&gt;&gt;&gt; observers...
[]
[ { "body": "<p>Briefly, I find the following:</p>\n\n<ul>\n<li><p>The current static behaviour is not <em>intuitive</em> (what does <code>int ev</code> really mean? why numbers and not names?), not <em>efficient</em> (why search in an <code>unordered map</code> rather that direct access?) and not <em>thread-safe...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T18:32:48.493", "Id": "49096", "Score": "5", "Tags": [ "c++", "design-patterns", "c++11" ], "Title": "Generic observer pattern implementation in C++" }
49096
<p>I'm just starting out in Haskell and have been set an assignment for uni where I have to create a reverse index of words in a text file and find what line numbers they appear on. I also have to remove any stop words like "the" or "and" that aren't needed.</p> <p>So far I have this, but I feel that there should be a...
[]
[ { "body": "<p>Think carefully about what data structure you're using, lists aren't always the best choice. In this case you need to do two major things with your words.</p>\n\n<ol>\n<li>Associate words with the line number they first appear on.</li>\n<li>Remove words from one group using entries from another.</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T21:48:45.320", "Id": "49099", "Score": "2", "Tags": [ "haskell", "functional-programming" ], "Title": "Removing duplicates from list and filtering non-letter characters" }
49099
<p>This is an example of my filesystem:</p> <ul> <li>/code/ <ul> <li>internal/ <ul> <li>dev/</li> <li>main/</li> </ul></li> <li>public/ <ul> <li>dev/</li> <li>main/</li> <li>release/</li> </ul></li> <li>tools/</li> </ul></li> </ul> <p>/code/internal/dev/, /code/public/dev/ and /code/tools/ contain subdirectories for ...
[]
[ { "body": "<p>I'd lean towards <code>find</code>. I'll provide some code review type comments at the bottom, but first a rewrite:</p>\n\n<pre><code>search() {\n local extensions\n local pattern\n local find_cmd\n local OPTIND opt\n\n local usage=$( cat - &lt;&lt; END\nUsage: $FUNCNAME [OPTION] ....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T22:45:46.830", "Id": "49102", "Score": "4", "Tags": [ "bash", "console" ], "Title": "Shortcut script for elusive grep command" }
49102
<p>I use Gem in a Box, a Ruby project that allows to create personal self-hosted gem repositories. Gem in a Box uses <code>httpclient</code> to connect to the gem repository. After reviewing my server's TLS setup in the aftermath of the OpenSSL heartbleed bug, I decided only to allow protocol versions of TLSv1 and high...
[]
[ { "body": "<p>I've got a few things to say about the code, but having looked at the diff:</p>\n\n<pre><code>- @ssl_version = \"SSLv3\"\n+ @ssl_version = :auto\n</code></pre>\n\n<p>and:</p>\n\n<pre><code>- ctx.ssl_version = @ssl_version\n+ ctx.ssl_version = @ssl_version unless @ssl_version ==...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T00:01:30.053", "Id": "49106", "Score": "7", "Tags": [ "ruby", "security", "https", "openssl" ], "Title": "Let OpenSSL decide which TLS protocol version is used by default" }
49106
<p>I have a list of 6 items, and each one on click reveals a div that runs 100% wide under the row of list items. The code works, but the div opens very slowly and kind of choppy. Is there anything I can do to help it run more smoothly?</p> <p>My HTML is set up as such:</p> <pre><code> &lt;ul&gt; &lt;l...
[]
[ { "body": "<p>All this adding/removing classes are too much for this functionality. <strong>This makes it also very slow.</strong></p>\n\n<p><strong>You can iterate over all div elements, and say if div is !== hidden, than hide it.</strong> </p>\n\n<p>After that, you get the clicked element with $(this), and ju...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T01:27:00.650", "Id": "49110", "Score": "4", "Tags": [ "javascript", "optimization", "jquery", "performance", "html" ], "Title": "Hiding and revealing toggle responds very ...
49110
<p>I am wondering if I have overdone it with repositories in the following code, which is to save a sales order.</p> <p>I understand that the purpose of a repository is to decouple the domain layer from the persistence layer, but this code seems to be replicating what EF does anyway.</p> <pre><code>public SalesOrder ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T02:27:44.277", "Id": "86278", "Score": "1", "body": "Have you tried just returning the Sales Order? Typically if you have FK on your records EF will go off and fetch the values for you when you reference them later on i.e. SalesOrd...
[ { "body": "<p>I find it interesting that you want to <em>decouple</em> layers, but that the method you have here is <em>tightly coupled</em> with <code>UnitOfWork&lt;LogContext&gt;</code> (and thus with <code>LogContext</code> as well), <code>OrderLineRepository</code> and <code>OrderDetailRepository</code>.</p...
{ "AcceptedAnswerId": "52107", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T02:24:13.460", "Id": "49114", "Score": "4", "Tags": [ "c#", "entity-framework", "repository" ], "Title": "Saving a sales order - too many repositories?" }
49114
<p>I'm currently getting into MVC, and I'm working on a simple CRUD application but to make best use of relational database layout I need to use ViewModels so things look prettier on the UI.</p> <p>I have a ViewModel:</p> <pre><code>public class CreateAPIViewModel { [Display(Name = "Name")] public string Name...
[]
[ { "body": "<p>If you aren't considering using a mapping solution such as <em>AutoMapper</em>, you could make this code a bit more succient by removing some of the local variables and creating a couple of local methods that are responsible for creating the select lists.</p>\n\n<p>The end solution would look some...
{ "AcceptedAnswerId": "49130", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T07:54:17.437", "Id": "49123", "Score": "3", "Tags": [ "c#", "mvc", "asp.net-mvc" ], "Title": "View Model Filling Fields" }
49123
<p>Follow up for my initial question. Modified my earlier code and adding new changes. <a href="https://codereview.stackexchange.com/questions/48829/airline-hotel-reservation-system-in-python">Initial Question in Code Review</a></p> <pre><code>import random class Booking: def __init__(self): pass de...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T11:51:26.513", "Id": "86324", "Score": "3", "body": "I have got the feeling that you did not really take into account all of the advice from the previous review (*e.g.* using class attributes instead of instance attributes) :/" } ...
[ { "body": "<pre><code>def __init__(self):\n pass\n</code></pre>\n\n<p>The <strong>init</strong> call can be deleted.</p>\n\n<pre><code>def checkAvailability(self,**kwargs):\n booking_type = kwargs['booking_type']\n booking_class = kwargs['booking_class']\n</code></pre>\n\n<p>Be careful with <code>**kwa...
{ "AcceptedAnswerId": "49182", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T08:03:27.343", "Id": "49124", "Score": "7", "Tags": [ "python", "object-oriented" ], "Title": "Airline/Hotel reservation system in Python : Follow up" }
49124
<h2>Background</h2> <blockquote> <p>This is a problem from a programming contest. </p> <p>The Sharonians of planet Sharon, at the far end of our galaxy, have discovered various samples of English text from our electronic transmissions, but they did not find the order of our alphabet. Being a very organize...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T10:24:07.153", "Id": "86308", "Score": "0", "body": "Is stability actual requirement of the problem? I don't see it in the (partial?) problem statement you gave us." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>First of all, I would take advantage of the fact that the other commonly used implementation of sorting in .Net is stable: <a href=\"http://msdn.microsoft.com/en-us/library/vstudio/bb549422\" rel=\"nofollow\">the <code>OrderBy()</code> extension method from LINQ</a>. Though it requires <code>IComp...
{ "AcceptedAnswerId": "49137", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T09:08:10.483", "Id": "49127", "Score": "6", "Tags": [ "c#", "optimization", "sorting", "contest-problem" ], "Title": "Stable custom alphabetical order using List<T>.Sort" }
49127
<p>This post is a follow-up to <a href="https://codereview.stackexchange.com/questions/48187/bash-music-player">this</a>.</p> <p>I wanted further reviews since the code I provided became too old when I got replies, which is why I'm providing it again here.</p> <p>I'm hoping I could get reviews for the new code.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-17T19:21:54.657", "Id": "88040", "Score": "3", "body": "You could consider fixing issues pointed out by [automated tooling](http://www.shellcheck.net) first, and making the code more syntactically consistent (not putting some loops/ifs...
[ { "body": "<p>You completely ignored the first points from <a href=\"https://codereview.stackexchange.com/a/48520/12390\">the review your earlier question</a>, \nand they still apply here:</p>\n\n<blockquote>\n <p>Whitespace is not a precious resource: your code is far too dense for\n my taste</p>\n \n <ul>...
{ "AcceptedAnswerId": "63904", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T09:30:08.033", "Id": "49128", "Score": "10", "Tags": [ "beginner", "bash", "shell", "audio" ], "Title": "Bash Music Player 2" }
49128
<p>I'm using this function to replace UTF-8 characters representing numbers in text with 'normal' digits.</p> <p>I'm wondering if this is optimized code since this is using two <code>str_replace()</code>s.</p> <pre><code>public static function convertArabicNumbers($string) { //$engish = array(0,1,2,3,4,5,6,7,8,9)...
[]
[ { "body": "<p>You are right that this is not optimal (performance wise). You may want to consider two things:</p>\n\n<ol>\n<li>static variables (those values in there are constants no need to recreate them every time).</li>\n<li>merging the arrays.</li>\n</ol>\n\n<p>Consider the following code:</p>\n\n<pre><cod...
{ "AcceptedAnswerId": "49139", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T11:08:20.147", "Id": "49138", "Score": "3", "Tags": [ "php", "performance", "strings", "converting", "utf-8" ], "Title": "Replacing Perisan and Arabic digits" }
49138
<p>I have a 'speed problem' with a program I'm currently developing. I already have encountered the methods which costs some time.</p> <pre><code>public void ConvertDataFrameToValueFields() { List&lt;byte[]&gt; items = new List&lt;byte[]&gt;() { new byte[2], new byte[2], new byte[2], new byte[2] }; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T18:01:59.667", "Id": "86401", "Score": "1", "body": "Why is speed a problem? Are you calling these methods on the same type many times? If that's the case, you might benefit from using reflection once to generate code for that type ...
[ { "body": "<p><strong>Style</strong> </p>\n\n<p>Based on the <a href=\"http://msdn.microsoft.com/en-us/library/xzf533w0%28v=vs.71%29.aspx\" rel=\"nofollow\">naming guidlines</a> method names should use <code>PascalCasing</code> casing. </p>\n\n<p><strong>determineCanMessageValueFields()</strong></p>\n\n<p>Ins...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T13:05:06.103", "Id": "49141", "Score": "2", "Tags": [ "c#", "performance", "reflection" ], "Title": "Speed problems with SetValue, ToType and Reflection" }
49141
<p>I'm pretty new to multithreading. The code below is a simple implementation of a single consumer/single producer circular buffer that does not use any locking, that I wrote for fun. </p> <p>The question is, will this kind of container work in actual real world situation or would it crash miserably because of some ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T13:55:11.943", "Id": "86339", "Score": "1", "body": "This is actually off-topic cause you ask review of the actual working of your code. We do review on your code as in improve your code writing, sometimes a faster or better solutio...
[ { "body": "<p>A few notes, mostly unrelated to the actual lock-free nature of the code:</p>\n\n<ol>\n<li><p>Some of your names are a lot less meaningful than I'd like. A prime example is your template parameter <code>S</code> in: <code>template&lt;typename T, int S=5&gt;</code>. This should probably be renamed ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T13:15:17.177", "Id": "49142", "Score": "5", "Tags": [ "c++", "c++11", "multithreading", "circular-list", "lock-free" ], "Title": "Single consumer and single producer lock-...
49142
<p>I've created a generic data structure intended for game development entity management. It has some interesting properties:</p> <ul> <li>Entities are stored contiguously in an <code>std::vector</code>.</li> <li>Stored entities can be in one of three states: <em>alive</em>, <em>dead</em>, <em>unused</em>.</li> <li>Up...
[]
[ { "body": "<p>A few minor things I've found:</p>\n\n<ul>\n<li><p>This could be a maintenance issue:</p>\n\n<pre><code>inline void cleanUpMemory()\n{\n for(auto&amp; a : atoms) \n if(a.state != AtomState::Unused) \n {\n a.deinitData();\n a.state = AtomState::...
{ "AcceptedAnswerId": "49204", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T14:42:54.970", "Id": "49150", "Score": "4", "Tags": [ "c++", "c++11", "memory-management" ], "Title": "Handle-based entity manager (that stores entities contiguously)" }
49150
<p>As advised by many, I am using a client pool - specifically the Apache <a href="http://hc.apache.org/httpcomponents-client-4.3.x/httpclient/apidocs/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html">PoolingHttpClientConnectionManager</a>.</p> <p>For simplicity I wrap it in my own simple singleton c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T13:26:33.543", "Id": "86736", "Score": "0", "body": "Could you specify the version of the library you're using ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T13:34:00.527", "Id": "86738", "...
[ { "body": "<p>I'm not an expert in the library or multithreading, so maybe some advises will not be applicable. </p>\n\n<p><strong>TL;DR</strong><br>\nI didn't find anything in your code really wrong. In fact, the more I look at it, the more I can just find only nitpicking things, and I'm really forcing myself....
{ "AcceptedAnswerId": "49381", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T14:44:31.783", "Id": "49151", "Score": "31", "Tags": [ "java", "http", "client" ], "Title": "HTTP Client requests done right" }
49151
<p>I've been writing far too many routines in JavaScript that get a record from a an object or array based off a matching property, much like jQuery does with DOM elements. Since all the good names are taken, I called it <code>Hmm</code>.</p> <p>I went with the philosophy that if I don't need it yet, I wont provide fo...
[]
[ { "body": "<p>It's very nice. What few qualms I have are a result of me looking really hard for things to have qualms about (furrowing my brow and going \"hmm\", basically).</p>\n\n<p>Anyway, some thoughts:</p>\n\n<ul>\n<li><p>Your <code>unique</code> function relies on the assumption that there are no circular...
{ "AcceptedAnswerId": "50966", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T14:45:33.037", "Id": "49152", "Score": "15", "Tags": [ "javascript", "search", "query-selector" ], "Title": "Hmm, a thoughtful library" }
49152
<p>I am trying to build something similar to planning poker and am very new to Knockout and was wondering if anyone could help me improve on my very crude start?</p> <p>This is what I have so far:</p> <p>HTML</p> <p>Selected Card</p> <p>CSS </p> <pre><code> .profile { width: 50px; height: 80px; color: #FFF; backgr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T15:06:17.673", "Id": "86357", "Score": "2", "body": "The html part seems to be missing." } ]
[ { "body": "<p>A surprisingly good start, most knockout code looks terrible to me, but I can follow this, it's well laid out, JsHint has nothing to complain about.</p>\n\n<p>Only this bothered me: </p>\n\n<pre><code>var items = ko.observableArray([new Step(1), new Step(2), new Step(3), new Step(5),new Step(8),ne...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T14:54:30.550", "Id": "49154", "Score": "4", "Tags": [ "javascript", "css", "knockout.js" ], "Title": "Planning Poker Using Knockout" }
49154
<p>I need <code>roomId</code> (an <code>auto_increment</code> primary key) to locate a specific room to update chat info. My way of doing it right now is dumb.</p> <p>In <code>createRoom.js</code>, I use <code>roomName</code> from a form that a user has entered to create a room model and find its <code>roomId</code>, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T15:32:34.340", "Id": "86364", "Score": "1", "body": "It seems like your code does not work as it will not fire `socket.on('disconnect')`, which makes it off-topic for CR." }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>Interesting question,</p>\n\n<p>my first point is that it is not clear how you wrote the <code>Room</code> module, but ideally, that module should do 2 things:</p>\n\n<ol>\n<li>Provide the created room to <code>complete</code></li>\n<li>Provide a way to deal with failure</li>\n</ol>\n\n<p>Then, I ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T15:13:37.030", "Id": "49157", "Score": "3", "Tags": [ "javascript", "beginner", "jquery", "node.js", "socket" ], "Title": "Getting the current chat room ID" }
49157
<p>I'm writing Stringbuilder to file asynchronously. This code takes control of a file, writes a stream to it and releases it. It deals with requests from asynchronous operations, which may come in at any time.</p> <p>The <code>FilePath</code> is set per class instances (so the lock <code>Object</code> is per instance...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T19:56:53.090", "Id": "86422", "Score": "0", "body": "Can you elaborate on what your *requirements* are? That will make it easier to not over-engineer this." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05...
[ { "body": "<p><strong>I'm not sure why this is async.</strong></p>\n\n<p>Unless you have a good reason for write to the file asynchronously, this is wasted effort.</p>\n\n<p>If you <code>lock</code> properly, this will work fine. Your <code>locker</code> variable should be marked <code>static</code>. You can ...
{ "AcceptedAnswerId": "49161", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T15:20:39.193", "Id": "49158", "Score": "10", "Tags": [ "c#", "multithreading", "thread-safety", "file-system" ], "Title": "Writing to file in a thread safe manner" }
49158
<p><strong>Code Objective</strong><br> I need to create a <code>System.Data.DataSet</code> object from an Excel workbook. Each <code>DataTable</code> within the <code>DataSet</code> must correspond to a nonempty worksheet in the workbook. The top row of each sheet will be used as column names for each <code>DataTable</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T17:05:34.877", "Id": "86385", "Score": "1", "body": "As a short info, I am the OP of the second question you mention. FYI what I use is an Excel Macro (VBA). That would require you to recode your whole program, as vba != vb (!) != c...
[ { "body": "<blockquote>\n <p><em>The workbook I'm using to test my code has one worksheet which uses the Excel columns A through CO and uses rows 1 through 11361, so I don't expect it to be too blazing fast [...]</em></p>\n</blockquote>\n\n<p>Cell CO11361, in R1C1 notation, is R11361C93. You're reading the val...
{ "AcceptedAnswerId": "49170", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T16:55:48.300", "Id": "49162", "Score": "11", "Tags": [ "c#", "performance", "excel" ], "Title": "Extract Excel data using Interop.Excel from C#" }
49162
<p>My PHP contact form was recently being used to send spam. Some security measures have since been put in place (please refer to the comments below) and I'm seeking the collective wisdom of others to review the code and to check to make sure it is secure from injection attacks.</p> <pre><code>&lt;?php /* method for...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T17:15:45.023", "Id": "86388", "Score": "0", "body": "doing a security audit of this code is a bit difficult, as it features inconsistent formatting and a high cyclomatic complexity. Consider improving the formatting, and splitting t...
[ { "body": "<p>Some things I've noticed:</p>\n\n<ul>\n<li><code>subcategory_email</code> might be empty if a user would supply an index out of the array bounds.</li>\n<li>Why use <code>$_REQUEST</code>? It's almost always better to use <code>$_GET</code> or <code>$_POST</code> if you know what to expect (<code>P...
{ "AcceptedAnswerId": "49181", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T17:05:08.913", "Id": "49163", "Score": "1", "Tags": [ "php", "security", "email" ], "Title": "Is this PHP mailer file secure from injection attacks?" }
49163
<pre><code>#include&lt;iostream&gt; using namespace std; int partition(int arr[],int first,int last,int pivot) { int tmparr[100]; int left=first,right=last; for(int i=first;i&lt;=last;i++) { if(arr[i]&lt;pivot) tmparr[left++]=arr[i]; else if(arr[i]&gt;pivot) tmpa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T17:38:49.897", "Id": "86391", "Score": "0", "body": "\"I am aware of issues around it being limited to 5 elements instead of dynamic, and some variables not named properly\" then you should fix that first." }, { "ContentLice...
[ { "body": "<p>I know you haven't mentioned anything about this, but I think it should still be addressed.</p>\n\n<p>You should not be passing around C arrays in C++. The entire array is <em>not</em> passed; it merely decays to a pointer to the array.</p>\n\n<p>Instead, use a storage container such as an <a hre...
{ "AcceptedAnswerId": "49190", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T17:36:28.713", "Id": "49166", "Score": "2", "Tags": [ "c++", "algorithm", "beginner", "sorting", "quick-sort" ], "Title": "Is this reimplemented quicksort correct?" }
49166
<p>I have a complex directory structure on my web server that includes .tar files for download; I'm trying to create a report on the size distribution of these files (e.g. 10 are less than 1MB, two are 1-2MB, three are 2-3MB...)</p> <p>Is there a better way to organize this code? I started it as a console application...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T18:35:03.050", "Id": "86406", "Score": "1", "body": "Is `Foo` the actual name of the method?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T18:37:48.850", "Id": "86407", "Score": "0", "bo...
[ { "body": "<p>The biggest complaint I would have with this code is that you're essentially defining your size map twice. Imagine if you decide you don't want to report on files between 50 and 75MB - you remove the \"75\" entry from the dictionary, but forget to remove it from the MakeDictionaryKey method, and ...
{ "AcceptedAnswerId": "49228", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T18:27:52.943", "Id": "49174", "Score": "1", "Tags": [ "c#", "file-system" ], "Title": "Search a directory structure for tar files and report on their size" }
49174
<p>I have read several articles using Google, but I somehow do not really get what they do, and when it is needed. Below I'll give 2 pieces of code, in one using get/set and in the other without, and they both work (at least in this example).</p> <p>Example 1</p> <pre><code>public class Example { public int numbe...
[]
[ { "body": "<p>First of all, I'd make the texture and position fields private. They're set from the outside, and the outside doesn't need to change them.</p>\n\n<p>Then I'd extend that. Anything your class needs to be given, add to the constructor. If <code>Asteroid</code> makes it itself, make it private. If so...
{ "AcceptedAnswerId": "49183", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T20:04:14.453", "Id": "49179", "Score": "4", "Tags": [ "c#" ], "Title": "How to know when I need to use get/set and when not?" }
49179
<p>Working my way through <a href="http://rads.stackoverflow.com/amzn/click/032157351X">Algorithms, Fourth edition by Robert Sedgewick &amp; Kevin Wayne</a>. I implemented a generic version of the Quick-Union algorithm and added Path Compression (not described in the book) to it.</p> <p>Mainly I'm looking for feedback...
[]
[ { "body": "<p>In <code>find()</code> and <code>areConnected()</code>, you should be able to use <code>==</code> rather than <code>.equals()</code> since you are comparing references, not contents.</p>\n\n<hr>\n\n<p>Your <code>find()</code> loop is a bit inefficient:</p>\n\n<ul>\n<li>You do <code>components.get(...
{ "AcceptedAnswerId": "49197", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T21:34:11.583", "Id": "49186", "Score": "5", "Tags": [ "java", "algorithm" ], "Title": "Generic implementation of the Quick-Union algorithm with Path Compression" }
49186
<p>After changing all variables in <a href="https://codereview.stackexchange.com/questions/49179/how-to-know-when-i-need-to-use-get-set-and-when-not">this code</a> from <code>public</code> to <code>private</code> and adding <code>get</code>/<code>set</code> according to the need to get modified and/or read in another c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T21:49:04.907", "Id": "86466", "Score": "0", "body": "You may not have noticed, but you can remove the isVisible field. It isn't used. Or you could connect it to the IsVisible property." }, { "ContentLicense": "CC BY-SA 3.0",...
[ { "body": "<h1>Fields vs Properties</h1>\n\n<p>As discussed in the comments above, there's a problem with <code>IsVisible</code>:</p>\n\n<blockquote>\n<pre><code>private bool isVisible;\npublic bool IsVisible { get; set; }\n</code></pre>\n</blockquote>\n\n<p>When this code compiles, you'll basically get somethi...
{ "AcceptedAnswerId": "49202", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T21:43:56.423", "Id": "49188", "Score": "7", "Tags": [ "c#", "game", "xna" ], "Title": "Encapsulation, fields and properties for Asteroid class" }
49188
<p>This is the controller I created for my MVC framework, and I think I finally got it right.</p> <p>Anything I can do to make the code more efficient?</p> <p>Is this how a MVC controller is supposed to look like?</p> <pre><code>abstract class Controller { protected $requestHandler; public function __constr...
[]
[ { "body": "<p>The biggest thing that bugs me about this is that <code>Controller::__construct</code> is basically handling the whole request. A constructor should be doing as little work as possible -- ideally <em>only</em> getting the object ready to use.</p>\n\n<p>The problem is that otherwise, your request ...
{ "AcceptedAnswerId": "49208", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T21:44:04.300", "Id": "49189", "Score": "2", "Tags": [ "php", "mvc" ], "Title": "Is this how an MVC controller supposed to be?" }
49189
<p>I just finished <a href="http://projecteuler.net/problem=37" rel="nofollow">Project Euler 37</a> after a bit of debugging and can't figure out how to make it faster. Whenever I add extra tests that I want to speed the program up, it ends up just slowing it down. My primes test is from <a href="http://en.wikipedia.or...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T01:12:16.253", "Id": "86485", "Score": "1", "body": "Go to the Project Euler forum for that problem, page 8, a post by Cthuloid on April 16th, 2014 has Python code that finds the solution in 0.2 sec." } ]
[ { "body": "<p>There's no need to convert lists to ints every time. Truncation from the right is an integer division by 10. Truncation from the left is modulo certain power of ten; you can keep track of the modulo as the loop progresses.</p>\n\n<p>There's no need to run a very expensive primality every time. Kee...
{ "AcceptedAnswerId": "49199", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T23:30:04.277", "Id": "49195", "Score": "3", "Tags": [ "python", "optimization", "programming-challenge" ], "Title": "Truncatable Primes -- Project Euler 37?" }
49195
<p>I have two IEnumerable objects called <code>items</code> and <code>newItems</code>. I need to update the <code>Did</code> and <code>KeyDid</code> property of each element in <code>items</code> with the matching <code>Did</code> and <code>KeyDid</code> from <code>newItems</code>. I can't just call <code>items = new...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T00:58:04.393", "Id": "86483", "Score": "0", "body": "Not sure about the only enumerate once comment. You are possible already enumerating twice by doing the .Count() call earlier???" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<pre><code> if (arrItems.Length != newItems.Count())\n // --&gt; BAD throw new Exception(\"Item counts do not match.\");\n // Do not throw the Exception base here look for the real exception for example ArgumentException(if the arr come from arguments) or your custom exception:\n ...
{ "AcceptedAnswerId": "49213", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T23:51:38.540", "Id": "49196", "Score": "3", "Tags": [ "c#", ".net", "linq" ], "Title": "Copy two properties from one array item to matching index in another array" }
49196
<p>I'm trying to get my progress bar animated. I'd like it to smoothly transition in between the starting and destination values, but only be initiated by clicking the continue button.</p> <p>The code I currently have works great, but when clicking forward or backward, it brings you directly to the values:</p> <pre><...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T06:07:38.250", "Id": "86491", "Score": "0", "body": "It would be better if you set up a demo in JSFiddle or JSBin so we can verify." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T21:39:24.110", "...
[ { "body": "<p>Not sure if it is helpful, but since we are on codereview, allow me to give it a shot.</p>\n\n<ul>\n<li>there is a <strong>progress</strong> element available in HTML5 that works very easily and is fairly well supported (<a href=\"http://caniuse.com/progressmeter\" rel=\"nofollow\">http://caniuse....
{ "AcceptedAnswerId": "49277", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T02:06:05.210", "Id": "49201", "Score": "3", "Tags": [ "javascript", "jquery", "jquery-ui", "animation" ], "Title": "Updating a jquery progressbar via button clicks" }
49201
<p>Following code is supposed to identify a shift and then it should identify whether the shift is a night or a day shift. The method will take 'in time' and 'out time' as two parameters.</p> <p>These are the rules:</p> <ol> <li>Day shift - From 7AM to 7PM</li> <li>Night shift - From 7PM to 7AM (on the next day)</li>...
[]
[ { "body": "<p>First Things first:</p>\n\n<h3>Method Signature:</h3>\n\n<blockquote>\n<pre><code>public string IdentifyShift(DateTime inTime, DateTime OutTime)\n</code></pre>\n</blockquote>\n\n<p>C# conventions state, that public methods should be <code>PascalCased</code> (check), and local variables, as well as...
{ "AcceptedAnswerId": "49211", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T04:58:39.707", "Id": "49205", "Score": "3", "Tags": [ "c#", "optimization", "algorithm", ".net", "datetime" ], "Title": "Algorithm to identify a shift and its type base...
49205
<p>Below are two functions.</p> <p>The first is to set a cookie. This function is called on any product page on my website.</p> <pre><code>function setcookie() { $entry_id = $this-&gt;EE-&gt;TMPL-&gt;fetch_param('entry_id'); if (isset($_COOKIE['recently_viewed'])) { $currentSession = unserialize($_...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T21:09:19.707", "Id": "86627", "Score": "0", "body": "Why do you use cookies instead of sessions to store this data?" } ]
[ { "body": "<p>First of all, let me tell you that I have zero experience with Codeigniter, but I suppose it is an MVC / OOP based framework, and I have plenty of experience with those. I am not trying to declare myself an expert or anything, just trying to be helpful and constructive. So here we go...</p>\n\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T09:22:28.600", "Id": "49214", "Score": "2", "Tags": [ "php" ], "Title": "Functions for setting cookies and outputting their IDs" }
49214
<p>I've just finished creating this form validation but I want to make it public for beginner 'contact us forms'.</p> <p>I was wondering if I can have some peoples' input on if they can understand/read my JavaScript. Although I know my JS works, it's better to be safe than to have 20 people asking what this does. It'...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T11:27:55.123", "Id": "86501", "Score": "1", "body": "Welcome to Code Review! Asking *us* to provide the comments about what your code does makes me wonder: Do **you** know what your code does? We'd gladly review the readability of y...
[ { "body": "<p>Take care that I can read JavaScript but it was a whole time ago that I effectively wrote in that.</p>\n\n<ol>\n<li><p>I see you've created your own <code>isNumeric</code> function.</p>\n\n<p>Maybe you can use the <code>isNaN</code>. <a href=\"http://www.w3schools.com/jsref/jsref_isnan.asp\" rel=\...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T11:17:08.140", "Id": "49218", "Score": "10", "Tags": [ "javascript", "form", "validation" ], "Title": "Can people understand my form validation code?" }
49218
<p>I wrote the following groovy function for taking a string of multiple lines (or any other character for splitting the code into parts), and bringing each line/part to a specified number of characters, cutting too long lines and filling up too short lines with a fill character:</p> <pre><code>static final String adj...
[]
[ { "body": "<p>I think your approach is fine, and it's easy to understand. I have just a few improvement ideas:</p>\n\n<ul>\n<li>A more natural ordering of the method parameters might be: source, token, length, filler</li>\n<li>Instead of <code>Integer</code>, <code>int</code> should be enough and shorter</li>\n...
{ "AcceptedAnswerId": "49234", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T11:35:46.223", "Id": "49219", "Score": "4", "Tags": [ "strings", "formatting", "groovy" ], "Title": "Code for adjusting linelength" }
49219
<p>I am trying to learn Clojure for some time. In my experience, it has been rather too easy to produce write-only code.</p> <p>Here is a solution to <a href="http://code.google.com/codejam/contest/2974486/dashboard#s=p1" rel="nofollow">a simple problem</a> with very little essential complexity. Input and output forma...
[]
[ { "body": "<p>I have to admit, the actual \"solving the problem\" component of this is a little over my head. But, I thought I'd try to answer your questions and give you some style/structure feedback, for what it's worth :)</p>\n\n<p>You can simplify your <code>ns</code> declaration like this:</p>\n\n<pre><cod...
{ "AcceptedAnswerId": "49377", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T12:07:21.493", "Id": "49220", "Score": "2", "Tags": [ "clojure" ], "Title": "\"Cookie Clicker Alpha\" solution" }
49220
<p>I have to generate a lot of tables from different JSON files (up to 20 tables per page). Because it's a lot of data, I really want to keep loading speed in mind. I know it's better to use a non jQuery solution, but native is not in my skillset right now.</p> <pre><code>$(document).ready(function(){ (function get...
[]
[ { "body": "<p>Use <code>detach</code> to remove the elements from the DOM, append the tables to the detached nodes, then add them back to to DOM:</p>\n\n<pre><code>var table = $( \"#myTable\" );\nvar parent = table.parent();\n\ntable.detach();\n\n // ... add lots and lots of rows to table\n\nparent.append( tabl...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T12:30:56.020", "Id": "49223", "Score": "2", "Tags": [ "javascript", "jquery", "html", "json" ], "Title": "Generate HTML from JSON" }
49223
<p>Assume I have the following list (<code>List&lt;string&gt;</code>)</p> <p>G<br> G<br> M<br> T</p> <p>I'd like this to be in an order where the same letter will not occur twice, such as</p> <p>G<br> M<br> G<br> T</p> <p>(I appreciate other variations would also suffice)</p> <p>Please note, if I had the following...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T13:38:40.543", "Id": "86515", "Score": "6", "body": "This is an interesting problem in *unsorting*..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T14:20:39.980", "Id": "86519", "Score": "0"...
[ { "body": "<p>Here's an alternate way to do it. It doesn't involve modifying and reversing the existing list. Instead, it first groups and counts the items, then yields the one that wasn't printed last time and still needs to be yielded the most times. I'm not sure about actual runtime for large lists, but as l...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T13:25:08.440", "Id": "49225", "Score": "18", "Tags": [ "c#" ], "Title": "List with no sequential repeats (where possible)" }
49225
<p>I'm currently working on a Scala HTTP library, <a href="https://github.com/nrinaudo/fetch" rel="nofollow">fetch</a>, mostly because I have yet to find one that suits all my needs.</p> <p>As part of this library, I need a generic key / value store, which I intend to use both for request / response headers and URL qu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T21:03:53.197", "Id": "89892", "Score": "0", "body": "That link for your implementation class gets a 404." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-28T21:17:34.740", "Id": "89894", "Score":...
[ { "body": "<p>I don't see how to understand the <code>KeyValueStore</code> without understanding the <code>ValueFormat</code> implementation you reference. You don't have <strong>any</strong> substantial comments in either implementation, including \"why\". Their mutual dependency makes it very difficult to rev...
{ "AcceptedAnswerId": "52036", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T14:55:59.227", "Id": "49229", "Score": "4", "Tags": [ "scala" ], "Title": "Key / Value store with type classes for formatting / parsing" }
49229
<p>I'm not very good at JavaScript, so it would be great if somebody could review my jQuery Upvote plugin, and point out mistakes, bad practices, or anything suspicious.</p> <p>The repository is on <a href="https://github.com/janosgyerik/jquery-upvote">GitHub</a>. Here's a <a href="http://janosgyerik.github.io/jquery-...
[]
[ { "body": "<h2>This in JSHint</h2>\n\n<p>JSHint says \"Possible strict violation\" because you are using <code>this</code> inside something that, as far as it can tell, is not a method.</p>\n\n<p>In non-strict mode, calling <code>_click_downvote(5)</code> would bind <code>this</code> to the global object (<code...
{ "AcceptedAnswerId": "49336", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T15:23:22.910", "Id": "49231", "Score": "8", "Tags": [ "javascript", "jquery", "stackexchange" ], "Title": "jQuery Upvote, a simple Stack Exchange style voting plugin" }
49231
<p>I would like to find out if my current solution to the problem described below is &quot;<em>good enough</em>&quot; or if there is an alternative way of achieving it. All I care about is the length (no. of lines) of the code and its efficiency. I am trying to follow the &quot;DRY&quot; principle and come up with some...
[]
[ { "body": "<p>Since you need to multiply by another interest rate every year, why not precalculate this interest rate using a temp variable? You precalculate the interest in row 10 and then refer to the relevant field in the calculation column.</p>\n\n<p>It might also be worth to check out the default Excel for...
{ "AcceptedAnswerId": "49534", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T16:26:57.727", "Id": "49235", "Score": "12", "Tags": [ "performance", "algorithm", "vba", "excel", "finance" ], "Title": "Calculation of an inflation on volume/year" }
49235
<p>I am working with currencies, and so have been using the decimal module to rule out any floating point weirdness in the following maths.</p> <p>I have to add together a number of decimal amounts, find an average of them, add ten percent, and then round it to the nearest round £. I then need to do more decimal maths...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T22:00:27.747", "Id": "86637", "Score": "1", "body": "Don't use `decimal.Decimal(1.1)`. Always initialize decimal constants with strings, to avoid rounding error: `decimal.Decimal('1.1')`" } ]
[ { "body": "<p>I was actually unaware of the decimal module -- I've +1 your question just for that. </p>\n\n<p>Taking a quick look at the <a href=\"https://docs.python.org/2/library/decimal.html\" rel=\"nofollow\">docs</a>, Decimal is specifically designed to avoid artifacts of binary floats and work like \"peop...
{ "AcceptedAnswerId": "49238", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T16:33:03.370", "Id": "49236", "Score": "6", "Tags": [ "python", "python-2.x" ], "Title": "More elegant way to round decimals in Python?" }
49236
<p>The following piece of code will act as a single access to all social networks. It aims to connect different social networks to get a broader picture of the social life of a user. I have just committed the code for Twitter access, but similar access will be provided to Facebook and Github.</p> <p>The code is availa...
[]
[ { "body": "<p>You are inconsistent in naming. Some of your methods are in camelCase and some are in under_score format. Pick one.</p>\n\n<p>Where is the consistent API for the various social networks?? From your write up I expect to be able to write something like the following:</p>\n\n<pre><code>my_friends = [...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T17:17:38.440", "Id": "49241", "Score": "1", "Tags": [ "python" ], "Title": "Module for providing users easy access to all social networking websites" }
49241
<p>This works, but it's huge.</p> <p>We need to repeat each table column on each <code>UNION SELECT</code>, as well as the <code>WHERE</code> clause for <code>DATE</code> comparison.</p> <pre><code>( SELECT GROUP_CONCAT(APA_T.district), t.name FROM tbl_activity AS t INNER JOIN tbl_activity_package AS ap ON t.id = ...
[]
[ { "body": "<p>The nesting is incomprehensible without indentation. For your benefit and for the benefit of anyone attempting to review this code, I've reformatted the code, changing nothing but whitespace.</p>\n\n<pre><code>(\n SELECT GROUP_CONCAT(APA_T.district), t.name\n FROM tbl_activity AS t\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T17:36:59.143", "Id": "49243", "Score": "5", "Tags": [ "mysql", "sql" ], "Title": "Long SQL query with much duplication between two halves of a UNION" }
49243
<p>I have developed a few web applications according to my own coding style similar to MVC architecture. I'm a self learner. But there is no controller class or model class. In my way, I don't split the URL. I have mentioned below an example URL. Now I'm familiar with this process, but I know this is not a professional...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T19:02:57.213", "Id": "86599", "Score": "0", "body": "Regarding the last (removed) note: even if you get downvoted (which I doubt), you won't be blocked from asking questions as that system is not enabled on this site." }, { ...
[ { "body": "<h2>Code Review:</h2>\n\n<ul>\n<li><strong>Naming Convention</strong>: <code>$variableNames</code> and <code>functionNames()</code> should be in camelCase, <code>ClassNames</code> should be in CamelCaps. Keep this convention to make your code more readable!</li>\n<li><strong>Use an autoloader</strong...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T18:51:54.027", "Id": "49250", "Score": "3", "Tags": [ "php", "design-patterns", "mvc" ], "Title": "MVC architecture in PHP" }
49250
<p>Morris Inorder traversal - an algorithm for in-order traversal, of a tree, without recursion of extra memory. Looking for code review, optimizations and best practices.</p> <pre><code>public class MorrisInOrder&lt;T&gt; { TreeNode&lt;T&gt; root; /** * Takes in a BFS representation of a tree, and conv...
[]
[ { "body": "<pre><code>private void create (List&lt;? extends T&gt; items) {\n root = new TreeNode&lt;T&gt;(null, items.get(0), null);\n</code></pre>\n\n<p>This crashes if an empty list is passed in. And since you have this function...</p>\n\n<pre><code>public MorrisInOrder(List&lt;? extends T&gt; items) {\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T19:11:04.653", "Id": "49252", "Score": "4", "Tags": [ "java", "algorithm", "tree" ], "Title": "Morris inorder traversal" }
49252
<p>In a large project of mine, I've run into a situation where a client might need to run evaluated JavaScript code. I know, it makes me cringe too. One option is to manually parse it, but for future flexibility, I would like to evaluate the code safely.</p> <p>Everything I've seen and researched says, NO. Ah, the nay...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-01T00:28:17.950", "Id": "86604", "Score": "0", "body": "The character sequence `\"</script>\"` should be escaped using `\"<\\/script>\"` (and so should all other closing tags in string literals), the way you have it does nothing useful...
[ { "body": "<p>Yes, I can poke a few holes in this.</p>\n\n<p>Firstly, your <code>eval()</code> isn't actually doing much of anything here. From the perspective of the parser running the script, that line looks like this:</p>\n\n<pre><code>eval(party_size &lt; 5)\n</code></pre>\n\n<p>This means that <code>party_...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-01T00:11:55.347", "Id": "49253", "Score": "29", "Tags": [ "javascript", "security", "sandbox" ], "Title": "Sandbox or safely execute eval" }
49253
<pre><code>// Check horizontals for (int y = 0; y &lt; sGridHeight; y++) { Shape* groupShape = nullptr; int groupSize = 0; for (int x = 0; x &lt; sGridWidth; x++) { GridItem* gridItem = GetItem(x, y); Shape* shape = gridItem-&gt;GetShape(); if (shape == groupShape) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T19:25:18.637", "Id": "86613", "Score": "1", "body": "*I cannot use C++11* - [`nullptr` is in C++11](http://stackoverflow.com/questions/1282295/what-exactly-is-nullptr)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>Consider replacing:</p>\n\n<pre><code> groupSize++;\n if (groupSize == m_MatchSize)\n {\n g_Audio-&gt;PlaySound(m_GemDestroyedSound.c_str());\n m_Score += shape-&gt;GetScore();\n for (int tx = x - m_MatchSize + 1; tx &lt;= x; tx++)\n ...
{ "AcceptedAnswerId": "49262", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T19:23:32.533", "Id": "49255", "Score": "4", "Tags": [ "c++" ], "Title": "Removing duplication in horizontal and vertical checks" }
49255
<p>Web Browsers such as Chrome and Firefox using varying sandboxing techniques, to protect the users from malicious code infecting the system.</p> <p>Operating systems and language runtimes may also use sandboxing as a security measure. Examples include iOS and the Java Virtual Machine.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T19:25:06.680", "Id": "49257", "Score": "0", "Tags": null, "Title": null }
49257
Sandbox is a security mechanism for containing untrusted programs. Such programs could contain malicious code, which would harm the user's system.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T19:25:06.680", "Id": "49258", "Score": "0", "Tags": null, "Title": null }
49258
<p><strong>Summary:</strong></p> <p>I need to hide several (pre-determined) divs based on a child element's ID.</p> <hr> <p><strong>Caviats:</strong></p> <p>I can't alter the HTML directly in any way (by modifying the literal .html file). The IDs of the child elements for which the parents are to be hidden are kno...
[]
[ { "body": "<p>That is pretty close to the optimal way of doing it.</p>\n\n<p>Personally I would go for</p>\n\n<pre><code>//Hide items\n$(\"#item2, #item3, #item6\").parent().hide();\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T21:28:1...
{ "AcceptedAnswerId": "49264", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T19:40:17.997", "Id": "49259", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Hiding multiple elements' parent container (by child element id)" }
49259
<p>I've wrote some simple code to load a JSON file from the Twitter Streaming API, parse the data, and create relationships between users based on who mentions or retweets who. My ultimate goal is to have a file that I can load into a network analysis program to analyze.</p> <p>I wrote the code to first look for a re...
[]
[ { "body": "<p>I would suggest to create following new classes:</p>\n\n<ol>\n<li>User, which stores information about user, like user_id, user_location</li>\n<li>Text, which stores the tweet text, the language of the tweet, may be the keywords</li>\n<li>Tweet, which contains objects of User ,Text and some other ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T20:10:57.830", "Id": "49263", "Score": "2", "Tags": [ "python", "twitter" ], "Title": "Print Tweets/Mentions/Retweets" }
49263
<p>I am using Merton default model with complex iterative approach.</p> <p>I have already prepared my R codes but as I am quite new in R, they seem very inefficient, in sense that they runs almost 7 hours. My main problem is my for loop part.</p> <p>I kindly ask you review my R codes and give any corrections which co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T11:41:22.693", "Id": "86855", "Score": "0", "body": "duplicate of http://codereview.stackexchange.com/questions/49276/replace-for-loop-while-with-apply-family-function-in-r?" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T20:34:21.077", "Id": "49265", "Score": "2", "Tags": [ "r" ], "Title": "Merton default model with complex iterative approach" }
49265
<p>I am working on a class for encryption to use on my site. I have read through many examples of these functions and would just like to clarify a few points I have read and check if this code is worthy. It is for storing sensitive information in a database. I am aware that making this method secure does not mean that ...
[]
[ { "body": "<p>I'm no security expert, however I think answering this would be fun!</p>\n\n<p>I'll start off by doing my best answering your four questions:</p>\n\n<ol>\n<li><p>The salt is unnecessary.</p>\n\n<blockquote>\n <p>a salt is random data that is used as an additional input to a one-way\n function......
{ "AcceptedAnswerId": "56408", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T21:24:39.850", "Id": "49267", "Score": "6", "Tags": [ "php", "security", "cryptography" ], "Title": "MCRYPT - are there any flaws or areas for improvement in this class?" }
49267
<p>I have created a function which returns the number that corresponds to the given row and column from the pascal triangle. I have used the formula for this:</p> <blockquote> <p>n! / r! * (r-n)!</p> </blockquote> <p>The code:</p> <pre><code>def pascal(c: Int, r: Int): Int = { def factorial(number: Int): Int ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T05:12:06.397", "Id": "86675", "Score": "2", "body": "I'm voting against closure cause his code is working(one small case not), and asking for improvement. (also how to spot the bug but not asking to fix the bug)." } ]
[ { "body": "<p>There is a simpler solution. Consider this logic:</p>\n\n<ul>\n<li>if it's the first column, the value is always 1</li>\n<li>if it's the last column, the value is always 1. (You can check this based on the row!)</li>\n<li>otherwise, it's the sum of the value in the previous row previous column + p...
{ "AcceptedAnswerId": "49274", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T21:34:25.567", "Id": "49268", "Score": "3", "Tags": [ "recursion", "homework", "scala" ], "Title": "Pascal triangle algorithm is good but fails" }
49268
<p>I'm having trouble testing some code. It's laid out in such a way that the business logic relies on the persistence layer.</p> <p>Some classes require that an object be saved to a database. Some classes re-read the object they were working to get the "original" version of it. All of this tends to happen in what's b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T23:28:44.253", "Id": "86647", "Score": "0", "body": "The ADO.NET calls could very well be worth reviewing as well, feel free to edit them in! :)" } ]
[ { "body": "<blockquote>\n <p><em>Firstly and unfortunately, there isn't an immediate plan to replace the entity specific ADO.NET with an ORM.</em></p>\n</blockquote>\n\n<p>That's fine.</p>\n\n<p>This is more questionable:</p>\n\n<blockquote>\n<pre><code>private int GetSqlOutputParam() { return 1; }\n</code></p...
{ "AcceptedAnswerId": "49291", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T21:49:49.400", "Id": "49271", "Score": "5", "Tags": [ "c#", "object-oriented", ".net", "unit-testing", "ado.net" ], "Title": "Hard-to-test 3 Tier Architecture" }
49271
<p>I've made a prime number generator (for Project Euler). It uses Euler's Sieve (a modified Sieve of Eratosthenes), with a mod 30 step. I'd like to reduce the memory consumption to 4/15 what it currently is by keeping a boolean array only for the possibly prime remainders of 30. I can't get it to work and also fear...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T01:23:15.907", "Id": "86658", "Score": "0", "body": "[Follow-up question](http://codereview.stackexchange.com/questions/49284/reduce-prime-sieve-memory-consumption-2)" } ]
[ { "body": "<ul>\n<li><p>The <code>typedef</code> name <code>big</code> makes little sense, especially in regards to integer size. If <code>big</code> can resemble 64-bit, then I suppose <code>bigger</code> can resemble 128-bit.</p>\n\n<p>However, instead of having your own <code>typedef</code> for <code>unsign...
{ "AcceptedAnswerId": "49280", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T22:23:47.847", "Id": "49275", "Score": "3", "Tags": [ "c++", "array", "primes" ], "Title": "Reduce Prime Sieve Memory Consumption" }
49275
<p>I have trouble with for loop, my code runs very slowly. The thing I want to do is to use function from <code>apply</code> family to make my codes run faster (instead of using <code>for loop</code>and <code>while</code>). Here is an example and my loop:</p> <pre><code>require(data.table) require(zoo) K&lt;-seq(1,10...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T05:15:22.777", "Id": "86676", "Score": "0", "body": "I am unable to run the code because an object `logret` is not found. Is it a function? Could you please specify the package at the beginning? I have added loading of `data.table` ...
[ { "body": "<p>You <em>could</em> replace the <code>for</code> loop with a function + <code>sapply</code> like this:</p>\n\n<pre><code>reduce.errors &lt;- function(err) {\n while (err &gt;= 10^(-10)) {\n df&lt;-as.data.table(df)\n df[,K:= K1,by=c(\"a\", \"b\")] \n df[,assetreturn:=c(NA,diff(log(K))),by...
{ "AcceptedAnswerId": "49281", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T22:31:48.820", "Id": "49276", "Score": "3", "Tags": [ "r" ], "Title": "Replace for loop while with apply family function in R" }
49276
<p>I need feedback on this code regarding security issues.</p> <pre><code>&lt;?php if(!isset($_POST['submit'])) { //This page should not be accessed directly. Need to submit the form. echo "error; you need to submit the form!"; } $name = $_POST['name']; $visitor_email = $_POST['email']; $message = $_POST['mess...
[]
[ { "body": "<p>In your first validation, I think you forgot to exit, you probably meant:</p>\n\n<pre><code>if(!isset($_POST['submit']))\n{\n //This page should not be accessed directly. Need to submit the form.\n echo \"error; you need to submit the form!\";\n exit;\n}\n</code></pre>\n\n<p>To validate e...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T23:18:26.417", "Id": "49282", "Score": "5", "Tags": [ "php", "security", "form", "validation", "email" ], "Title": "Possible security issues in email validation" }
49282
<p>I've made a prime number generator (for Project Euler). It uses Euler's Sieve (a modified Sieve of Eratosthenes), with a mod 30 step. I'd like to reduce the memory consumption to 4/15 what it currently is by keeping a boolean array only for the possibly prime remainders of 30. I can't get it to work and also fear...
[]
[ { "body": "<p>You've posted some code, which shows what you told the computer to do.\nAnd it even has some comments.\nHonestly, that's a lot better than the average question.</p>\n\n<p>Then you realize that we aren't going to understand this blob of code, so you use phrases like \"I made\" and \"It uses Euler's...
{ "AcceptedAnswerId": "49302", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T23:27:44.347", "Id": "49284", "Score": "5", "Tags": [ "c++", "array", "primes", "sieve-of-eratosthenes" ], "Title": "Reduce Prime Sieve Memory Consumption 2" }
49284
<p>When I had to create a fixed header on scroll, I found a few examples on Stack Overflow but they were terrible in the sense that they relied on a fixed page height. Have a look at what I created which does not rely on a wrapper around the header and the content. </p> <p><strong>Default</strong></p> <p><img src="ht...
[]
[ { "body": "<h1>HTML</h1>\n\n<p>You might want to <code>id</code> that <code>nav</code>. It's because it might not be the only <code>nav</code> on the page, and the JS will pick it up and add <code>.fixed-header</code> to it. Something like:</p>\n\n<pre><code>&lt;nav id=\"main-navigation\"&gt;\n</code></pre>\n\n...
{ "AcceptedAnswerId": "49367", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T23:39:51.717", "Id": "49285", "Score": "7", "Tags": [ "jquery", "html", "css", "html5" ], "Title": "CSS and HTML5 for this fixed header on scroll" }
49285
<p>I took a little time and wrote the following code to produce enigma encryption. I don't normally write code in C so I would like to get feedback on the way it has been structured and any issues a more experienced C programmer might spot in the way I used structs, command line parsing, and the indexing around the s...
[]
[ { "body": "<p>During the command line parsing I would suggest using <code>else</code></p>\n\n<p>This</p>\n\n<pre><code> if (strcmp(argv[i], \"-d\") == 0) opt_debug = 1;\n if (strcmp(argv[i], \"-r\") == 0) {\n</code></pre>\n\n<p>Would be better written as</p>\n\n<pre><code> if (strcmp(argv[i], \"-d\") =...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T00:39:30.333", "Id": "49288", "Score": "3", "Tags": [ "performance", "c", "cryptography", "enigma-machine" ], "Title": "Structure and style of Enigma Machine" }
49288