body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I wrote this code for a dynamic stack and would like to know what would be better if done differently.</p> <p>It can increase memory by a percentage and/or fixed value when needed. It can also be set to not increase automatically at all, so slots are only allocated by the user.</p> <p>The stack is just a structure...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T00:31:53.973", "Id": "63397", "Score": "0", "body": "Looks professional. Good job." } ]
[ { "body": "<p>Very Nice.<br>\nOnly small stuff</p>\n\n<ol>\n<li><p>Why <code>(float)</code> in <code>size_t new_slots = (float)stack-&gt;slots * stack-&gt;multiplier;</code>?</p></li>\n<li><p>Given <code>sizeof size_t</code> may not equal <code>sizeof float</code>, suggest grouping like types in <code>struct</c...
{ "AcceptedAnswerId": "38099", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-25T19:25:32.323", "Id": "38085", "Score": "6", "Tags": [ "c", "stack" ], "Title": "Dynamic stack implementation" }
38085
<p>I wrote this JS code with some jQuery and got a one-click-text-selection. Maybe someone can improve this code, because I think it's not "clean" and short engough ;) But I don't want to use an input field. Let me know if you have some ideas!</p> <pre><code>function SelectText(element) { var doc = document, ...
[]
[ { "body": "<p>You can further improve this by <a href=\"http://jsbin.com/oXetAcI/4/edit\" rel=\"nofollow\">making it a jQuery plugin</a> instead to make it reusable across any element.</p>\n\n<p><a href=\"http://gs.statcounter.com/#browser-ww-monthly-200807-201510\" rel=\"nofollow\">non-IE browsers, combined, a...
{ "AcceptedAnswerId": "38096", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-25T21:40:05.720", "Id": "38089", "Score": "5", "Tags": [ "javascript", "jquery", "performance" ], "Title": "Select text with just one click" }
38089
<p>I've created a variable order Markov chain built on top of a tree, but I can't train on datasets >1MB worth of text without running out of memory. I'm sure the tree can be replaced by something else more efficient, but I'm struggling with figuring that out. I've heard a linked list might work, but I'm not sure how.<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T11:26:35.660", "Id": "63489", "Score": "0", "body": "Can you git a source files and/or startup code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T11:34:47.737", "Id": "63491", "Score": "0",...
[ { "body": "<blockquote>\n <p>I'm sure the tree can be replaced by something else more efficient, but I'm struggling with figuring that out. I've heard a linked list might work, but I'm not sure how.</p>\n</blockquote>\n\n<p>Perhaps use the SortedList class instead of the Dictionary class.</p>\n\n<p>For example...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T00:33:03.023", "Id": "38092", "Score": "7", "Tags": [ "c#", "algorithm", "memory-optimization", "markov-chain" ], "Title": "Optimizing variable order Markov Chain Implementati...
38092
<p>I'm looking for corrections, optimizations, general code review, etc.</p> <pre><code>final class TreeData&lt;T&gt; { private T item; private boolean left; private boolean right; public TreeData(T item) { this.item = item; } public T getData () { return item; } publ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T12:24:09.030", "Id": "63418", "Score": "1", "body": "\"Serialization\" usually means to turn an object into a machine-readable string representation or byte stream. Do you mean \"traversal\" and \"reconstruction\"?" }, { "Co...
[ { "body": "<p>If your goal is to serialize the tree, then you want to repeatedly append node representations to a <code>StringBuilder</code> or write them to an <code>OutputStream</code>. For space efficiency, it would be better to do so a node at a time, rather than to build up the entire list.</p>\n\n<p>Ther...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T06:37:50.260", "Id": "38100", "Score": "1", "Tags": [ "java", "optimization", "tree", "serialization" ], "Title": "Serializing/deserializing binary tree in most space-efficien...
38100
<p>I want to optimize my Apriori algorithm for speed:</p> <pre><code>from itertools import combinations import pandas as pd import numpy as np trans=pd.read_table('output.txt', header=None,index_col=0) def apriori(trans, support=0.01, minlen=1): ts=pd.get_dummies(trans.unstack().dropna()).groupby(level=1).sum() ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T19:42:31.487", "Id": "83282", "Score": "0", "body": "You may want to check out pyFIM for an alternative approach: http://www.borgelt.net/pyfim.html" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-02-22T04:4...
[ { "body": "<p>First off, this is just a part of the Apriori algorithm. Here, you're just finding frequent itemsets. Apriori continues to find association rules in those itemsets.</p>\n\n<p>Also, using <code>combinations()</code> like this is not optimal. For example, if we know that the combination <code>AB</co...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T07:02:59.787", "Id": "38101", "Score": "6", "Tags": [ "python", "algorithm", "numpy", "pandas", "data-mining" ], "Title": "Apriori algorithm using Pandas" }
38101
<p>An interviewer asked me to write clean Java code for clockwise and counterclockwise spiral matrix traversal.</p> <p>e.g. <code>{{1,2,3}, {7,8,9}}</code> becomes <code>{1,2,3,9,8,7}</code> and <code>{1,7,8,9,3,2}</code></p> <p>I've tried many methods and wrote down the below code while keeping in mind that it shoul...
[]
[ { "body": "<p>A few remarks about your <strong>object-oriented design</strong>:</p>\n\n<ul>\n<li>It's odd that the <code>matrixCount</code> and <code>up/down/left/rightLimit</code>s are part of the state of the object, but <code>matrix</code> itself isn't.</li>\n<li>I think <code>matrix</code> should be an inst...
{ "AcceptedAnswerId": "38108", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T08:17:05.117", "Id": "38104", "Score": "3", "Tags": [ "java", "interview-questions", "matrix" ], "Title": "Clockwise and counterclockwise spiral matrix traversal" }
38104
<p>Can someone tell me if my code is too long for what it does?</p> <pre><code>package Tests; import java.util.Random; import java.util.Scanner; public class DuelMain { public static void main(String[] args) { Random battle = new Random(); @SuppressWarnings("resource") Scanner input = new Scanner(System...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-02-05T17:31:21.613", "Id": "292246", "Score": "1", "body": "I just want to say if you've only been coding for a few days, I'm impressed. Yes there's a *lot* you can do to improve the verbosity and maintainability of this code, but having ...
[ { "body": "<p>Yes it could be much smaller and therefore more easy to read.</p>\n\n<p>For example, you quite often set the fields:\n <code>attack, defense, health</code>. This could be moved to a method which sets them all three at once. </p>\n\n<pre><code> public setValues(int attack, int defense, int healt...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T09:54:11.813", "Id": "38105", "Score": "11", "Tags": [ "java", "beginner", "game" ], "Title": "Battle game simulation" }
38105
<p>I'm in doubts what approach to take here, please have a look on the code below:</p> <pre><code>private void processBarCodeResponse(String decodedQrCode) { JSONObject jsonObject = JsonUtil.composeJsonObject(decodedQrCode); SalePoint salePoint = parseSalePoint(jsonObject); if (salePoint == nul...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T19:21:55.210", "Id": "63441", "Score": "2", "body": "This question is on the very edge of being primarily opinion based. I am not voting to close but I am downvoting because of the way the question is formulated." } ]
[ { "body": "<p>I think the right thing to do would be to move the exception handler into <code>processBarCodeResponse()</code>.</p>\n\n<pre><code>private void processBarCodeResponse(String decodedQrCode) {\n JSONObject jsonObject = JsonUtil.composeJsonObject(decodedQrCode);\n try {\n SalePoint saleP...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T11:44:22.403", "Id": "38109", "Score": "1", "Tags": [ "java", "exception-handling" ], "Title": "What's better: return null or handle the Exception?" }
38109
<p>Rails AR. validate one field, with 4 validators &amp; 2 condition block</p> <pre><code>validates :inn, presence: { if: -&gt; { user.is_a?(Client) } }, inn: { if: -&gt; { user.is_a?(Client) } }, uniqueness: { if: -&gt; { user.is_a?(Client) } }, absence: { if: -&gt; { user.is_a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T13:44:48.300", "Id": "63494", "Score": "2", "body": "`inn` as an option of `validates`?" } ]
[ { "body": "<p>You can try something like this (obviously names can be shorter):</p>\n\n<pre><code>if_user_is_a = -&gt;(klass) { { if: -&gt; { user.is_a?(klass) } } }\nvalidates :inn, presence: if_user_is_a[Client], ..., absence: if_user_is_a[Department]\n</code></pre>\n\n<p>or</p>\n\n<pre><code>if_user_is_a = -...
{ "AcceptedAnswerId": "38377", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T12:35:40.080", "Id": "38112", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "validation" ], "Title": "Rails validating with condition block" }
38112
<p>I've encountered a problem that I have to solve using <code>dynamic_cast</code> to invoke different functions, depending on the type of class State family.</p> <p>I was re-factoring a Parser I wrote before, from a freaking nested class State inside Parser so that I could separate them and extract common parts using...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T16:01:26.073", "Id": "63424", "Score": "0", "body": "It is impossible to review this code: It is fake code (and appears not to compile), not the code you want reviewed. For problems like these, the specifics of the code are importan...
[ { "body": "<p>Maybe it's a result of your simplification for the example but your <code>ParserState</code> looks like an over-engineered enum to me. What do you gain from it over using an <code>enum</code> and a <code>switch</code> for the current state?</p>\n\n<p>In general whenever you need to check for the s...
{ "AcceptedAnswerId": "38144", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T13:16:17.860", "Id": "38114", "Score": "3", "Tags": [ "c++", "object-oriented", "singleton", "state-machine" ], "Title": "How do I avoid explicit type switching when operat...
38114
<p>I am working on a little project to visualize the algorithm for the Traveling Salesman Problem. I have cities, which are movable objects painted with AWT and Swing. Also I can make a connection between two cities in the form of a undirected edge. Each city should have at least one connection between another city.</...
[]
[ { "body": "<p>You might change from <code>ArrayList</code> to <code>HashMap</code>. That will give you better performance for large numbers of cities (for small numbers of cities, the overhead of using a HashMap can be more than what you gain over using the ArrayList).</p>\n\n<p>I would also suggest adding a n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T16:18:53.690", "Id": "38120", "Score": "7", "Tags": [ "java", "beginner", "algorithm", "gui", "traveling-salesman" ], "Title": "Visualization of the Traveling Salesmen Pro...
38120
<p>I'm just beginning web design, and I've come up with this code to scroll to a place in the same page. </p> <p>I don't know if this can or should be improved much longer, so I'm asking for any tips that can make this code better. </p> <p>I know it's messy, but I will clean it later. I just want to know if there's ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T18:20:43.260", "Id": "63435", "Score": "0", "body": "Is there are reason why you wouldn't want to move the whole `.Container` that contains `#Tecnologia` instead?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>You should declare these styles into classes, and use jQuery to toggle the classes. That way, you have good \"separation of concerns\". You end up with a smaller base code.</p>\n\n<p>Additionally, one should not use the <code>all</code> for transition. It's bad for performance. Ideally, one should...
{ "AcceptedAnswerId": "38378", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T17:42:24.240", "Id": "38123", "Score": "4", "Tags": [ "beginner", "jquery", "html", "css", "animation" ], "Title": "Animated scrolling to a place in the same webpage" }
38123
<p>I've created this PHP script to print a batch of usernames with encrypted passwords locally on my computer because the user/pass format is always the same.</p> <blockquote> <p>username = username</p> <p>password = username + &quot;admin&quot;</p> <p>example = homer / homeradmin</p> </blockquote> <p>Then paste them i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T18:30:38.250", "Id": "63436", "Score": "1", "body": "this is off-topic for this site in that it is asking for code to be written, we don't do that here." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26...
[ { "body": "<p>the first thing that came to my mind to make this cleaner was an array or rather several arrays.</p>\n\n<p>maybe something like this:</p>\n\n<pre><code>$user = array('admin','g','homer','marge','bart','lisa','maggie','dog');\n$admin = array('admin','23!bseEsF@','homeradmin','margeadmin','bartadmin...
{ "AcceptedAnswerId": "38179", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T18:20:09.863", "Id": "38124", "Score": "3", "Tags": [ "php", "cryptography" ], "Title": "Need Loops for PHP Username/Pass Encryption Script" }
38124
<p>In this code, I'm overriding the sorter and matcher for <a href="http://getbootstrap.com/2.3.2/javascript.html#typeahead" rel="nofollow">Twitter-Bootstrap's Typeahead</a> functionality. The reason for the override is to allow state (technically Jurisdiction) abbreviations to be used to match the full state name. I'v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-12T12:16:57.163", "Id": "76453", "Score": "0", "body": "which bootstrap version are you using ?" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T18:23:12.430", "Id": "38125", "Score": "3", "Tags": [ "javascript", "jquery", "beginner", "twitter-bootstrap" ], "Title": "Overriding sorter and matcher in Bootstrap Typeahead...
38125
<p><a href="http://getbootstrap.com/" rel="nofollow">Bootstrap</a> is a front-end framework from Twitter designed to kickstart the front-end development of webapps and sites. Among other things, it includes base CSS and HTML for typography, icons, forms, buttons, tables, layout grids, navigation along with custom-built...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T19:29:06.963", "Id": "38127", "Score": "0", "Tags": null, "Title": null }
38127
<p>I've created an admin login area for an application I am planning to code, and I've used the following login.html page to let the user type in his data (I left out parts like "id", "placeholder" etc. to make it shorter):</p> <pre><code>&lt;form method="post" action="login.php"&gt; &lt;input type="text" name="user...
[]
[ { "body": "<p>Tha major security issue I see is that you do not have any limiting or logs for wrong/success attempts. One can use automated brute force attacks trying all day/night long to guess your username and password. If lack of success, at least you might have your app slowed down, because of the billion ...
{ "AcceptedAnswerId": "38131", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T19:46:56.827", "Id": "38129", "Score": "4", "Tags": [ "javascript", "php", "security", "session" ], "Title": "Possible improvements on admin login area?" }
38129
<p>How can I reduce the amount of repetitive code in my Android app? A lot of the code seems to be doing the same thing twice. I think that there is a more compact way to do this. </p> <p>What are some ways that I can reduce lines of code in this program?<br> Is there a better way that I could write this program? I ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T07:51:08.587", "Id": "63474", "Score": "1", "body": "You should remove `// TODO Auto-generated method stub` as soon as you put any code in the method. It's just there to help you to find the method." } ]
[ { "body": "<p>This type of problem is conveniently solved with a <a href=\"http://en.wikipedia.org/wiki/Strategy_pattern\" rel=\"nofollow noreferrer\">Strategy Pattern</a>. But, first things first:</p>\n\n<ul>\n<li>you should search for efficient ways to convert bytes to hexadecimal-string values. This <a href=...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T19:55:58.783", "Id": "38132", "Score": "4", "Tags": [ "java", "android", "cryptography" ], "Title": "Reducing repetitive Android code" }
38132
<p>Drupal questions should involve code review as per the <a href="https://codereview.stackexchange.com/help/on-topic">Help Center</a>, otherwise they should be posted on <a href="https://drupal.stackexchange.com/">Drupal Answers SE</a>.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T20:48:16.077", "Id": "38135", "Score": "0", "Tags": null, "Title": null }
38135
Drupal is an open source CMS framework written in PHP.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-26T20:48:16.077", "Id": "38136", "Score": "0", "Tags": null, "Title": null }
38136
<p>Looking for code review, suggestions for improvement, best practices etc.</p> <p>The problem definiton is</p> <blockquote> <p><strong>Jump Game</strong> </p> <p>Given an array start from the first element and reach the last by jumping. The jump length can be at most the value at the current position in ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T15:39:08.227", "Id": "63628", "Score": "1", "body": "This is a off-topic, but I saw that you are not accepting a lot of answers to your questions. I answered the question nevertheless. However, please note that this is still a beta ...
[ { "body": "<p><strong>Coding style</strong></p>\n\n<p>Anytime when programming, but especially when you implement an algorithm, choose variable names that are a little more verbose. When you come back to your code after some time and you want to apply some changes to your implementation, you will at first only ...
{ "AcceptedAnswerId": "38222", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T00:02:01.383", "Id": "38142", "Score": "3", "Tags": [ "java", "dynamic-programming" ], "Title": "Jump game in Java" }
38142
<p>Below is a generic code for parsing strings (read from file for example) and converting them to .java types, such as primitives (and their wrappers), java.io.File, Enum etc. There is also possible to register custom made <code>TypeParser</code>'s, for non-standard java types (Or provide a static factory method named...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T00:32:42.547", "Id": "64497", "Score": "1", "body": "fyi. Have a look at this http://jodd.org/doc/typeconverter.html" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T22:53:10.163", "Id": "64796", ...
[ { "body": "<p>Overall, your code is very clean and looks good to me. However, I have some feedback, especially concering your use of reflection:</p>\n\n<ol>\n<li><p>In your <code>DefaultTypeParsers</code> class, you are enlisting all <code>TypeParser</code> implementations that are inner classes of your <code>D...
{ "AcceptedAnswerId": "38167", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T01:35:50.443", "Id": "38145", "Score": "7", "Tags": [ "java", "parsing", "serialization" ], "Title": "Parse strings and convert the value to .java types" }
38145
<p>The following code is my answer to a <a href="https://stackoverflow.com/questions/20745184/how-to-update-struct-item-in-binary-files/20794062#20794062">Stack Overflow question</a>:</p> <pre><code>#include &lt;string&gt; #include &lt;vector&gt; #include &lt;fstream&gt; #include &lt;cstdio&gt; #include &lt;cassert&gt...
[]
[ { "body": "<p>I'm going to focus on readability rather than performance for this review.\nI will also (hopefully) avoid C++11 features since you're using VS2008.</p>\n\n<ol>\n<li><p>Change <code>&lt;assert.h&gt;</code> to <code>&lt;cassert&gt;</code>.<br>\nUse the C++ headers instead of the C headers.</p></li>\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T03:25:50.657", "Id": "38148", "Score": "6", "Tags": [ "c++", "file", "stream" ], "Title": "Updating a file through C++ streams" }
38148
<p>I was playing around with Java Card and I try to do one of the examples.</p> <p>P1 is what it has to do (e.g. decrypt, encrypt, etc) and P2 is to select which key to use in P1. Here is what the code looks like - well, half of it anyway, since I'm not really used to formatting in this site and it takes awhile to cop...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T04:42:25.487", "Id": "63464", "Score": "0", "body": "Since it looks like your code is working, I'm going to send you in the direction of the friendly folks at [codereview.se]." }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>I would focus on eliminating the inner <code>switch</code> statements. You could try to eliminate the outer <code>switch</code> as well, but it's probably not worthwhile, especially for a resource-constrained environment.</p>\n\n<pre><code>byte[][] desKeys = new byte[][] {\n null, DESKey1, DES...
{ "AcceptedAnswerId": "38151", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T04:29:05.117", "Id": "38149", "Score": "6", "Tags": [ "java", "cryptography", "embedded" ], "Title": "Selecting an algorithm and key for Java Card encryption" }
38149
For code that targets an embedded device or some severely resource-constrained environment.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T06:30:36.227", "Id": "38153", "Score": "0", "Tags": null, "Title": null }
38153
<p><strong>Goal:</strong> To create a function that returns the relative time difference between two given timestamps, using the <a href="http://php.net/datetime" rel="nofollow">DateTime</a> class.</p> <p><strong>Current approach:</strong></p> <pre><code>function time_elapsed($date1, $date2) { $dt1 = new DateTime...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T07:05:36.287", "Id": "63469", "Score": "0", "body": "@MrLore: The `@` has nothing to do with error reporting (in this context). DateTime [can accept](http://www.php.net/manual/en/datetime.construct.php) a timestamp if you prepend it...
[ { "body": "<p>Since my initial answer, in which I asked the question <em>\"Why bother constructing 2 instances of <code>DateTime</code>?\"</em>, markegli has given me a reason why one would do this.<br>\nIn case the diff between 2 dates is likely to be >= 1 month, using <code>DateTime</code> <em>is preferable</...
{ "AcceptedAnswerId": "43849", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T06:53:16.963", "Id": "38154", "Score": "10", "Tags": [ "php", "datetime" ], "Title": "Display the relative time difference between two dates" }
38154
<p>I have two numbers: a and b. I want to put the smaller of them in one variable, and the larger in another variable (if they are equal, then any of them can be in any of the variables). Currently my code (in Javascript / Java) takes 7 lines:</p> <pre><code>if (a&lt;=b) { small = a; large = b; } else { sm...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T08:02:59.133", "Id": "63475", "Score": "4", "body": "Is this for Java or JavaScript? They're two different languages." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T09:38:09.170", "Id": "63478",...
[ { "body": "<pre><code>int t = a + b;\na = a &gt; b ? t - a : a;\nb = t - a;\n// a is the small one\n</code></pre>\n\n<p>Or </p>\n\n<pre><code>small = a;\nlarge = b;\nif (a&gt;b) {\n small = b;\n large = a;\n} \n</code></pre>\n\n<p>But I think it will be shorter in Python:</p>\n\n<pre><code>if a &gt; b:\n a...
{ "AcceptedAnswerId": "38161", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T07:57:40.337", "Id": "38156", "Score": "1", "Tags": [ "java", "javascript", "mathematics" ], "Title": "min and max simultaneously" }
38156
<p>I observe the same pattern in a number of my classes but can't extract/abstract it due the tight coupling inside each particular implementation.</p> <p>Having the class accepting an optional number of dependencies onto its constructor:</p> <pre><code>public Repository(IBuilder, IFormatter, ILoader, ISelector) </co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T10:57:25.990", "Id": "63485", "Score": "1", "body": "Do you use many different implementations of these interfaces, or always the same?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T15:55:58.797", ...
[ { "body": "<p>One option would be to create a generic method that accepts delegates to the methods:</p>\n\n<pre><code>var combined = Combine(_builder.Build, _formatter.Format, _loader.Load, _selector.Select);\nreturn combined(i);\n</code></pre>\n\n<p>The implementation would look like this:</p>\n\n<pre><code>pu...
{ "AcceptedAnswerId": "38194", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T08:20:15.320", "Id": "38158", "Score": "4", "Tags": [ "c#", ".net", "unit-testing", "revealing-module-pattern" ], "Title": "Extracting pattern and simplifying testing" }
38158
<pre><code>Storage.prototype.setExpire = function (arrObj) { var date, now, days, deletes, items, fa, ta, newItems = [], storage = localStorage.getItem('limitStorage'); items = JSON.parse(storage || "[]"); date = new Date(); date = date.toString()....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T01:36:01.693", "Id": "63594", "Score": "0", "body": "changed my code more. Now the code if you change `\"item1\":3` to less or more days `\"item1\":6` code will update the item." } ]
[ { "body": "<p>I think this code could use a lot of polishing.</p>\n\n<p><strong>Getting the localStorage</strong></p>\n\n<pre><code> storage =localStorage.getItem('limitStorage');\n getItems = storage !== null &amp;&amp; storage !== \"[]\" ? localStorage.getItem('limitStorage') : null;\n getItems = getItems !==...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T08:41:35.047", "Id": "38159", "Score": "5", "Tags": [ "javascript", "datetime" ], "Title": "localStorage setExpire code to add time expires" }
38159
<p>The SDL code example on the <a href="http://wiki.libsdl.org/SDL_Init" rel="nofollow"><code>SDL_Init</code></a> page seems to be overly verbose, creating an exception class entirely for <code>SDL_Init</code>. I wanted to tone it down a bit by making everything <code>std::runtime_error</code>s.</p> <ol> <li>Does it m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T22:21:32.140", "Id": "63724", "Score": "2", "body": "Putting the catch outside the body is extremely rare. You will confuse people by doing that. Also the catch happens after main has exited so the return is not doing what you think...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T10:42:22.790", "Id": "38162", "Score": "2", "Tags": [ "c++", "exception", "sdl" ], "Title": "SDL boilerplate" }
38162
<p>As per a <a href="https://codereview.stackexchange.com/questions/35502/multi-producer-consumers-lockfree-stack">similar question</a>, following a lockfree list implementation. Note that this list has a pre-defined maximum set of elements which can be inserted (<code>N</code> argument in the template declaration). Pl...
[]
[ { "body": "<ul>\n<li><p><a href=\"http://en.cppreference.com/w/cpp/memory/auto_ptr\" rel=\"nofollow\">As of C++11, <code>std::auto_ptr</code> has been deprecated</a>. Consider switching to another type of supported smart pointer, such as <a href=\"http://en.cppreference.com/w/cpp/memory/unique_ptr\" rel=\"nofo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T11:53:07.110", "Id": "38166", "Score": "3", "Tags": [ "c++", "multithreading", "linked-list", "lock-free" ], "Title": "Multi producer/consumers lockfree list" }
38166
<p>Is this correct? Or am I overloading the responsibilities of the view?</p> <pre><code>&lt;table class="table table-striped table-hover"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Estado&lt;/th&gt; &lt;th&gt;Prioridad&lt;/th&gt; &lt;th&gt;Responsable&lt;/th&gt; ...
[]
[ { "body": "<p>In my opinion, there is way too much logic in your view.</p>\n\n<p>Personally I would manipulate the data in the controller so that <code>$value</code> has a <code>label</code> and a <code>class</code> attribute, and then just loop over the data in the view.</p>\n\n<p>This way view and controller ...
{ "AcceptedAnswerId": "38198", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T15:18:20.150", "Id": "38175", "Score": "0", "Tags": [ "php", "codeigniter", "controller" ], "Title": "Codeigniter - in the view or in the controller?" }
38175
<p>I am working on an Android app that has an Abstract view controller class. I am using that Abstraction and implementing it for an <a href="http://developer.android.com/reference/android/widget/Spinner.html" rel="nofollow noreferrer">Android Spinner</a> view. It has a method that assigns the view to be controlled. I ...
[]
[ { "body": "<p>This is a relatively new area in Java, and best practice is not as well established....</p>\n\n<p>... but, as I think about it, I think your reviewer has a point.</p>\n\n<p>In your code base, consistency counts for a lot. If you check all your preconditions in a consistent way, and are disciplined...
{ "AcceptedAnswerId": "38244", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T16:05:13.237", "Id": "38177", "Score": "4", "Tags": [ "java", "android" ], "Title": "Android View Controller: Precondition vs ClassCastException" }
38177
<p>This questions is originally from <a href="http://contestcoding.wordpress.com/2013/06/28/fizz-buzz-bizz-fuzz/" rel="nofollow">http://contestcoding.wordpress.com/2013/06/28/fizz-buzz-bizz-fuzz/</a>.</p> <blockquote> <ul> <li>Print the integers from 1 to 100, </li> <li>but for the multiples of 3, print "Fizz" i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T18:45:16.517", "Id": "63548", "Score": "0", "body": "Wouldn't it simply make the most sense to have an acceptance test in place before just jumping right to code? As with the original fizz buzz, you should be able to know exactly w...
[ { "body": "<p>Overall, this is a pretty straightforward program. See the bottom of my answer for an <strong><em><a href=\"http://en.wikipedia.org/wiki/Extreme_Makeover:_Home_Edition\" rel=\"nofollow noreferrer\">Extreme Makeover: Code Edition</a></em></strong> of the program.</p>\n\n<hr>\n\n<p><a href=\"https:/...
{ "AcceptedAnswerId": "38183", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T16:19:49.267", "Id": "38178", "Score": "6", "Tags": [ "java", "programming-challenge", "fizzbuzz" ], "Title": "Fizz Buzz Bizz Fuzz in Java" }
38178
<p>Is there a better way of doing this?</p> <pre><code>// Definition: Count number of 1's and 0's from integer with bitwise operation // // 2^32 = 4,294,967,296 // unsigned int 32 bit #include&lt;stdio.h&gt; int CountOnesFromInteger(unsigned int); int main() { unsigned int inputValue; short unsigned int one...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T21:50:20.367", "Id": "63572", "Score": "3", "body": "Considering the title's reference to a bitwise operator, I was surprised to see `if (value % 2 != 0)` instead of `if (value & 1)`." } ]
[ { "body": "<p>Yes, there is a better way:</p>\n\n<pre><code>int CountOnesFromInteger(unsigned int value) {\n int count;\n for (count = 0; value != 0; count++, value &amp;= value-1);\n return count;\n}\n</code></pre>\n\n<p>The code relies on the fact that the expression <code>x &amp;= x-1;</code> remove...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T17:15:37.363", "Id": "38182", "Score": "26", "Tags": [ "c", "bitwise", "integer" ], "Title": "Counting number of 1's and 0's from integer with bitwise operation" }
38182
<p>I would like to improve code readability and reduce the complexity of my code to improve the maintainability of the source code.</p> <p>If you have any tips, please say so. I was also wondering if it would be a good feature to add a 2-player option to this game. Currently, the game runs off of a word list in which ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T17:47:20.597", "Id": "63540", "Score": "0", "body": "Is there a reason that you keep posting questions asking us to review similar code that you have had reviewed before?" }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>Review these <a href=\"https://codereview.stackexchange.com/a/26907/20611\">general concepts</a> for a Hangman game. Notice how LazySloth13's hangman game and your hangman game are not reusable. That is, there is no way to take your vision of hangman and get the vision from LazySloth13, or vice-ve...
{ "AcceptedAnswerId": "38193", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T17:39:05.263", "Id": "38187", "Score": "3", "Tags": [ "java", "optimization", "game", "hangman" ], "Title": "Complete Hangman game" }
38187
<p>I should preface this question by saying that I'm a Java programmer working on my first C++ application, so perhaps there are certain obvious things I don't know.</p> <p>Some background on the problem:</p> <p>Our application had data read from a socket stored in a character array, which was a fixed length message ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T22:34:28.497", "Id": "63575", "Score": "0", "body": "Do you have to call these functions multiple times for a single header? Have you considered having a couple of `int` variables in your `ApiHeader` class (assuming it's a class and...
[ { "body": "<p>First a question: why do you care that an extra string is being created? Is this function used <strong>a lot</strong>. If not, then I see no need to change. </p>\n\n<p>But beyond that, although I don't know about C++ cleverness, is your replacement function so much more efficient? You are calli...
{ "AcceptedAnswerId": "38204", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T18:26:49.110", "Id": "38189", "Score": "2", "Tags": [ "c++", "beginner", "strings", "error-handling" ], "Title": "Making a function which takes char* exception-proof" }
38189
<p>I'm kinda curious how I'd refactor this in the best way. I've only used Linq for simple queries.</p> <p><strong>What it does:</strong> </p> <p>Depending on the type that is submitted, we're grouping events or payments by duration (eg. every year, every month, every day (for the moment).</p> <p>I'd like to extend...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T04:29:24.550", "Id": "63872", "Score": "0", "body": "You turned that monster into a 4-liner! Well done! Remember that comments say *why*, the **code** says *what*. Also I'm not sure about calling a dictionary `GenerateChartByType` -...
[ { "body": "<p>The problem is that you have a method that does many, many, <em>many</em> things.</p>\n\n<p>The first thing I'd address is the <code>switch</code> blocks; a common way of refactoring those, is to use a <code>Dictionary&lt;TKey,TValue&gt;</code>.</p>\n\n<blockquote>\n<pre><code> DateTime i = vm....
{ "AcceptedAnswerId": "38196", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T20:08:55.950", "Id": "38192", "Score": "5", "Tags": [ "c#", "linq" ], "Title": "Refactoring chart generator in Linq" }
38192
<p>I'm playing around with switching some code to using <code>Parallel.ForEach</code> and I have a question about whether I need to be concerned about the effects of concurrency here. Here's a simplified version of what I'm doing:</p> <pre><code>public IList&lt;Item&gt; RetrieveAllItems(int paramValue) { var itemF...
[]
[ { "body": "<p>If you only need to return an <code>IEnumerable&lt;Item&gt;</code> you could simply enumerate to <code>List</code>s and then <code>Concat</code> the results.</p>\n\n<p>Otherwise you could consider using a linked list, enumerating in parallel and then again <code>Concat</code>enating for O(1).</p>\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T21:59:11.223", "Id": "38197", "Score": "6", "Tags": [ "c#", "task-parallel-library" ], "Title": "Is Concurrent Collection Needed Here?" }
38197
<p>I wrote my very first login/register PDO system today. I know there is still a lot of flaws, but I was wondering what tips and advice you have to help me improve this. I know that PDO is much more secure than MySQl, so would you say my code is secure? If so, to what extent, since I'm using PDO? Any tips and advic...
[]
[ { "body": "<p>Here are several tips:</p>\n\n<ul>\n<li>Use OOP - this way you could start the session only once</li>\n<li>Hash your passwords - this way no one can steal it from the db, or at least the chance is lower</li>\n<li>Use MVC - separate your HTML from the PHP code</li>\n<li>Move your db connect credent...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T23:43:40.290", "Id": "38202", "Score": "5", "Tags": [ "php", "mysql", "beginner", "security", "pdo" ], "Title": "PDO Login/Register system review" }
38202
<p>This week's <a href="https://codereview.meta.stackexchange.com/a/1324/23788">Code Review Weekend Challenge</a> is about implementing a simple console game.</p> <p>Here's my game loop:</p> <pre><code>class Program { static void Main(string[] args) { var player = new Player(); var intro = new...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T23:46:40.327", "Id": "63584", "Score": "0", "body": "Well that was fast... you only accepted the CRWEC a few minutes ago :P" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T23:48:47.633", "Id": "63...
[ { "body": "<p>Well, i am new to this weekend-challenge thing so I am not sure, from which stand point should i review such question. I'll give it a try.</p>\n\n<ol>\n<li><p>I like your game loop. Its simple and makes sense. It can be simlified further though:</p>\n\n<pre><code>var activeScreen = new IntroScreen...
{ "AcceptedAnswerId": "39357", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T23:45:10.930", "Id": "38203", "Score": "13", "Tags": [ "c#", "game", "console", "community-challenge" ], "Title": "Simple Text Adventure: Cleaning up after the party" }
38203
<p>I am using the <a href="http://curl.haxx.se/" rel="nofollow">cURL</a> tool in MATLAB 2013b with Ubuntu to download a whole bunch of files. The files have one of three possible versions: 1.0.0, 2.0.0, or 2.1.0. Using the HTTP, I first check the headers with three queries to see which version exists. Then whichever ex...
[]
[ { "body": "<p>Why don't you read the index from <a href=\"http://www.rbsp-ect.lanl.gov/data_pub/rbspa/MagEphem/def/\" rel=\"nofollow\">http://www.rbsp-ect.lanl.gov/data_pub/rbspa/MagEphem/def/</a> and use that to decide which files you want to download?</p>\n\n<p>Also, try to give multiple files (eg. 20) to eac...
{ "AcceptedAnswerId": "38218", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T01:09:08.583", "Id": "38205", "Score": "2", "Tags": [ "performance", "http", "matlab", "curl" ], "Title": "Downloading the oldest available version of some data files" }
38205
<p>I have a <code>myCon=getUnusedConnection()</code> method that gets a connection from <code>Connection</code> pool. I also have a <code>releaseConnection(myCon)</code> method to release <code>Connection</code> to the pool after finishing using it.</p> <p>When coding, I need to select data from the database many time...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T03:58:23.027", "Id": "63600", "Score": "0", "body": "http://www.javaworld.com/article/2077817/java-se/understanding-jpa--part-1--the-object-oriented-paradigm-of-data-persistence.html" } ]
[ { "body": "<p>There are a number of problems with your code. Let's go through the more important ones:</p>\n\n<ul>\n<li><p>you should close the PreparedStatement <strong>before</strong> you return the connection to the pool.... should be:</p>\n\n<pre><code>finally{\n closeStatement (preparedStmt);\n relea...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T03:35:41.570", "Id": "38209", "Score": "3", "Tags": [ "java", "exception-handling" ], "Title": "Passing around Connection" }
38209
<p>I am supposed to take this code (that I made):</p> <pre><code>public void showUpdatedStatus() { if(((itsUsersNumber - itsSecretNumber) &lt;= 2) &amp;&amp; ((itsUsersNumber - itsSecretNumber) &gt;= -2)) JOptionPane.showMessageDialog(null, "You're hot!"); if (((itsUsersNumber - itsSecretNumber) &lt;= ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T06:25:52.363", "Id": "63613", "Score": "1", "body": "this is a really good question.....I don't know how \"on-topic\" your question is though?" } ]
[ { "body": "<p>The concept you have going is 'OK' (cumbersome, but for a beginner it's OK). There are two bugs, and one recommendation that will help a lot.</p>\n\n<p>First the recommendation....</p>\n\n<p>Change <code>numLies</code> to be a boolean value like: <code>boolean canlie = true;</code></p>\n\n<p>Then,...
{ "AcceptedAnswerId": "38213", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T06:07:54.537", "Id": "38212", "Score": "4", "Tags": [ "java", "beginner" ], "Title": "How to make a program that lies one-third of the time?" }
38212
<p>Code review for best practices, optimizations, bug detection etc. Also please verify my complexity as mentioned within the function comments.</p> <pre><code>/** * Util class with 2 functions, * 1. find the next consecutive prime * 2. find the nth prime. */ public class PrimeUtil { private PrimeUtil() {} ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-13T21:58:45.810", "Id": "87398", "Score": "0", "body": "How long does it take to calculate the 10 billionth prime?" } ]
[ { "body": "<p>This question is very similar to the <a href=\"http://projecteuler.net/problem=7\" rel=\"nofollow noreferrer\">Project Euler #7</a> challenge. This was asked recently: <a href=\"https://codereview.stackexchange.com/questions/38084/suggestions-for-improvement-on-project-euler-7\">Suggestions for im...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T08:18:57.437", "Id": "38214", "Score": "2", "Tags": [ "java", "primes" ], "Title": "Find next consecutive prime and find nth prime" }
38214
<p>I've made lots of improvements on my text-editing app. Please review it again.</p> <pre><code>(function() { "use strict"; if (!window.File) document.body.innerHTML = "&lt;h1&gt;Sorry your &lt;a href='http://whatbrowser.org/'&gt;browser&lt;/a&gt; isn't supported :(&lt;/h1&gt;"; var textarea = document.getEl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T17:28:52.683", "Id": "63639", "Score": "0", "body": "Can you create a jsfiddle or jsbin ? This looks so much better than the first attempt." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T17:38:41.870...
[ { "body": "<p>I like your code</p>\n\n<ul>\n<li>\"Use Strict\" within a IFFE</li>\n<li>No warnings in JsHint, good indenting</li>\n<li>Correct casing and decent naming</li>\n<li>Nice size of methods</li>\n</ul>\n\n<p>I can only comment on the lack of comments in your source, though I admit the code is pretty se...
{ "AcceptedAnswerId": "38324", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T13:16:40.000", "Id": "38220", "Score": "3", "Tags": [ "javascript" ], "Title": "Text-editing app" }
38220
<p>I wrote <a href="https://github.com/RobertZenz/ClosedDoor">a simple text-templating/processing system which resembles PHP</a>, except that it works with Clojure. The main goal was to provide an easy way to use Clojure PHP-style for small files.</p> <p>This is a usage example, the following file</p> <pre><code>&lt;...
[]
[ { "body": "<p>Cool idea! I could definitely see this coming in handy in a variety of domains.</p>\n\n<p>I noticed that you have some <code>def</code> and <code>defn</code> statements within the function definition of <code>process-match</code>. It's generally considered un-idiomatic to use <code>def</code>/<cod...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T15:33:29.573", "Id": "38223", "Score": "5", "Tags": [ "clojure" ], "Title": "A text-templating system similar to PHP...but with Clojure" }
38223
<p>I'm working on an app for my school (not homework, an app that's going to be used by students), that's supposed to display our week schedules. I get the data from a webapp, but it has no API that I can use. So I have to parse the HTML. This HTML is a serious mess (and on top of that, they use Finnish in their pages)...
[]
[ { "body": "<p>At some point everyone ends up trying to parse HTML. And, in some of those cases, it is even unavoidable......</p>\n\n<p>... but, some suggestions (in order or preference):</p>\n\n<ol>\n<li>communicate with the server-side developers and try to create a better API for accessing the data (perhaps d...
{ "AcceptedAnswerId": "38334", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T16:31:12.220", "Id": "38227", "Score": "4", "Tags": [ "java", "html", "android", "parsing" ], "Title": "Simplifying HTML parsing" }
38227
<pre><code>int FindStr(char* str, int strsize, char* fstr, int from) { for(int i=from, j=0; i&lt;strsize; i++) { if(str[i]==fstr[j]) j++; else {i-=j; j=0;} if(fstr[j]=='\0') return i-j+1; } return -1; } </code></pre> <p>The function searches...
[]
[ { "body": "<p>Why is <code>fstr</code> treated as a null-terminated string, while the size of <code>str</code> has to be explicitly passed in?</p>\n\n<p>What is the expected behaviour when searching for an empty string?</p>\n\n<p>This is a pretty good simple string search. There are <a href=\"http://en.wikiped...
{ "AcceptedAnswerId": "38235", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T17:54:36.473", "Id": "38230", "Score": "6", "Tags": [ "c++", "optimization", "strings", "search" ], "Title": "Can this FindString function be optimized further, in terms of...
38230
<p>So I've read numerous tutorials on handling game states in XNA, and to each tutorial I've been read, it was different from the others. Now I want to ask which way is more efficient? I've created my own ScreenManager and what not, but it wasn't satisfying to me because it was inefficient since I didn't unload any unu...
[]
[ { "body": "<p>I can't be sure of this (I need to foster my XNA knowledge), but I would probably derive that class from <code>DrawableGameComponent</code> so that the <code>Update</code> and <code>Draw</code> methods would be overrides (not just methods that happen to be named &quot;Update&quot; and &quot;Draw&q...
{ "AcceptedAnswerId": "38238", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T18:29:39.270", "Id": "38232", "Score": "3", "Tags": [ "c#", ".net", "xna" ], "Title": "GameState Management efficiency" }
38232
<p>I wrote this code for dynamic strings and would like to know what mistakes I've made.</p> <p>It's just a struct that gets filled on the first call to <code>ds_allocate</code> and freed on the first call to <code>ds_free</code>. It uses <code>memcpy</code> for concatenation and supports a few basic operations.</p> ...
[]
[ { "body": "<p>The code is generally nice, so my comments are really just picking up crumbs.</p>\n\n<p>I'm not comfortable with your use of asserts to catch errors that could\nlegitimately occur at runtime. I consider asserts to be for asserting logical\nimpossibilities, not for catching runtime errors.</p>\n\n...
{ "AcceptedAnswerId": "38245", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T19:26:33.400", "Id": "38236", "Score": "7", "Tags": [ "c", "strings" ], "Title": "Dynamic Strings in C" }
38236
<p>I have used <a href="http://www.php.net/manual/en/pdo.prepared-statements.php" rel="nofollow">this guide</a> to implement prepared statements in order to avoid SQL Injection.</p> <p>I made some tests and no error was shown. However, I would like to ask you if you see any flaw in the code, so that I can improve it.<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-04T20:08:48.420", "Id": "64369", "Score": "0", "body": "Hope you don't mind, but I've gone ahead and _thoroughly_ reviewed your code. I know, criticism may come over as harsh and arrogant, but trust me, I'm only trying to help. And, IM...
[ { "body": "<p>Your code does not have an SQL injection vulnerability because you are using placeholders instead of interpolating the variables. The way you interface with the database is laudable.</p>\n\n<p>Other aspects of your code can be improved:</p>\n\n<ul>\n<li><p>The variables <code>$gdb</code>, <code>$s...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T19:39:53.233", "Id": "38237", "Score": "5", "Tags": [ "php", "security", "pdo" ], "Title": "Do you see any flaws in these prepared statements to avoid SQL injection?" }
38237
<p>A website I have designed uses a nav menu that shows submenus on <code>:hover</code>. The initial site did not use any responsive design: it targeted only the desktop environment. I am now using responsive-design techniques to target mobile devices and tablets, many of which are touch based rather than mouse based. ...
[]
[ { "body": "<p>First of all, lets clean up your code to really leverage the power of <code>.on()</code>:</p>\n\n<pre><code>$(function() {\n var touched = false,\n previous_touched;\n\n function updatePreviousTouched(e){\n if(typeof previous_touched !== 'undefined' &amp;&amp; previous_touched ...
{ "AcceptedAnswerId": "38292", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T20:13:58.270", "Id": "38239", "Score": "24", "Tags": [ "javascript", "jquery", "touch" ], "Title": "Handling Hover Events on a Touch Screen" }
38239
<p>I have a deck of flashcards that I want to shuffle. Here's the method I'm using to shuffle them:</p> <pre><code>func (deck *Deck) Shuffle() { rand.Seed(time.Now().UnixNano()) randomIndexes := rand.Perm(len(deck.Cards)) shuffledCards := make([]Card, len(deck.Cards)) for i := 0; i &l...
[]
[ { "body": "<p>I would recommend something closer to a Knuth shuffle, where you swap items in place in the array, rather then allocating a new one.</p>\n\n<p>This is untested and is based on the <a href=\"http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\" rel=\"noreferrer\">Fisher-Yates shuffle</a>:</p>...
{ "AcceptedAnswerId": "38243", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T20:29:27.627", "Id": "38241", "Score": "2", "Tags": [ "optimization", "go", "shuffle" ], "Title": "Shuffling an array of cards" }
38241
<p>I'm trying to learn Python and am working on a simple <a href="https://github.com/bjorn/tiled/wiki/TMX-Map-Format" rel="nofollow">Tiled Map Format</a> (.tmx) reader as practice. So as to not post too much code at once, I'm only publishing the <code>&lt;data&gt;</code> element which stores the tiles displayed in a ti...
[]
[ { "body": "<h3>1. General comments</h3>\n\n<ol>\n<li><p>You have a tendency to over-complicate things. As a result, your code is full of mistakes that you failed to spot. Keep code as simple as possible and it will be easier to inspect and test!</p></li>\n<li><p>The code you posted is missing a bunch of <code>i...
{ "AcceptedAnswerId": "38367", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T22:38:50.973", "Id": "38246", "Score": "4", "Tags": [ "python", "unit-testing", "python-3.x", "io" ], "Title": "Partial data reading implementation" }
38246
<p>The problem to the question is:</p> <blockquote> <p>Write a program that takes 3 integers as an input from the user using input dialog messages and sorts the three numbers.</p> </blockquote> <p>I just want to know: is there any major differences between my code and the book's code in terms of efficiency or anyth...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-02T09:24:07.167", "Id": "98084", "Score": "0", "body": "Be aware that this is not a real world solution. The simple way to solve this problem is to put the 3 numbers on a List<Integer> then call Collections.sort(myList)." } ]
[ { "body": "<p>The books solution, is definitely cleaner, and the biggest difference I can see is the books solution is actually sorting the variables, rather than just changing the display order.</p>\n\n<p>In terms of efficiency, displaying stuff to the console is more efficient than popping up message boxes. T...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T22:47:34.587", "Id": "38247", "Score": "5", "Tags": [ "java", "beginner", "sorting" ], "Title": "Inputting and sorting three integers" }
38247
<p>I am building a one-page JS app similar to redditinvestigator.com, and my goal is for it to be 100% done in JavaScript. Coming from a PHP/Java background, I'm more used to working in class oriented languages, so I just want to get a sense if I am implementing them correctly in JavaScript.</p> <p>My code works as ex...
[]
[ { "body": "<p>Your code is very clean, easy to understand and well written. My only comment for improving it would be to take advantage of a framework that does some of this lifting for you, such as:</p>\n\n<ul>\n<li>KnockoutJS</li>\n<li>BackboneJS</li>\n<li>AngularJS</li>\n</ul>\n\n<p>As well, coming from an O...
{ "AcceptedAnswerId": "38250", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T22:52:50.737", "Id": "38248", "Score": "1", "Tags": [ "javascript", "beginner", "jquery", "api", "reddit" ], "Title": "Reddit Investigator-like JS app" }
38248
<p>I am trying to print all the strings given in a N x N Boggle board. Its basically a N x N scrabble-like board where words can be made from a position - horizontally, vertically and diagonally.</p> <p>Here is my naive implementation. Is this correct? Any hints on optimizations? Any other useful links?</p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T23:36:25.840", "Id": "63664", "Score": "0", "body": "You have to mark the current position as unused as you return from recursion." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T23:38:33.723", "I...
[ { "body": "<p>I wouldn't consider that a Boggle solver, as you only consider words that start at [0, 0] and progress east, south, or southeast. (With coordinates that are always nondecreasing, you need not have bothered using <code>marker</code> to prevent backtracking.)</p>\n\n<p>A complete search will probab...
{ "AcceptedAnswerId": "38261", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T22:53:53.580", "Id": "38249", "Score": "4", "Tags": [ "java", "optimization", "algorithm", "strings", "recursion" ], "Title": "Printing all strings in a Boggle board" }
38249
<p>This was my first attempt at writing a program in LISP. Can anyone give any guides as to how it could be improved? The multiple loops in best-pattern seem awkward (I'd normally do that in just one loop but there doesn't seem to be a way of doing that with LOOP, although I'm told there's an iterate extension that can...
[]
[ { "body": "<p><em>I'm a Schemer, so my comments are not as detailed as they would be if I were reviewing a Scheme program.</em></p>\n\n<ul>\n<li>First, fix your indentation! There is a <a href=\"http://mumble.net/~campbell/scheme/style.txt\" rel=\"nofollow\">Lisp style guide</a> that most Lispers and Schemers a...
{ "AcceptedAnswerId": "38279", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T01:13:37.900", "Id": "38255", "Score": "5", "Tags": [ "beginner", "lisp", "common-lisp" ], "Title": "Calculating series of rows to use to play a melody on 5-row Bayan Accordion...
38255
<p>I am not wondering about error checking (I will add that soon). I would instead like to know about correctness, efficiency and simplicity.</p> <pre><code>#include &lt;pthread.h&gt; #include &lt;stdio.h&gt; #include &lt;unistd.h&gt; #define NTHREADS 7 #define RUN_N_TIMES 37 pthread_cond_t new_task_availa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T09:30:32.840", "Id": "63686", "Score": "2", "body": "Always a bit concerned seeing types like `pthread_t` assumed to be `sizeof(int)`. Check [How to print pthread_t](http://stackoverflow.com/questions/1759794/how-to-print-pthread-t...
[ { "body": "<p>Here are some comments on your program. Note that I am not a threads expert.</p>\n\n<p>Firstly, the code runs nicely. I'm running OSX and it compiles cleanly and\nexecutes correctly (as far as I can tell). I was a little surprised that\nthreads wake up in the same order each time - in other wor...
{ "AcceptedAnswerId": "38363", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T08:35:43.410", "Id": "38264", "Score": "2", "Tags": [ "c", "multithreading", "pthreads" ], "Title": "1 Producer, N Consumers working in parallel, each doing ~1/nth of a task" }
38264
<p>My entry for <a href="https://codereview.meta.stackexchange.com/a/1324/14625">Weekend Challenge #5</a>.</p> <p>In scope :</p> <ul> <li>Old Skool green on black text adventure</li> <li>Keyboard handling</li> <li>A story with 2 mini-quests</li> <li>2 endings</li> <li>Virtues ( Hi Ultima ) save the day</li> </ul> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T23:19:55.443", "Id": "63727", "Score": "0", "body": "It's an uplifting story for all Gastons out there ;)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-20T07:00:26.770", "Id": "66494", "Score":...
[ { "body": "<p>I enjoyed playing and won on my first attempt. I suppose that means I'm quite virtuous! :) </p>\n\n<p><strong>Quick Tips</strong></p>\n\n<ul>\n<li><p>Since <code>changeScene</code> calls <code>view.draw()</code> at the end, you can drop the same call at the end of <code>init</code> of the controll...
{ "AcceptedAnswerId": "39644", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T14:04:12.660", "Id": "38271", "Score": "12", "Tags": [ "javascript", "weekend-challenge" ], "Title": "Weekend Challenge - Belle's Christmas" }
38271
<p>I am trying to write some string algorithms which I want to work for any kinds of strings and/or locale. I managed to get some results that do work, but I am not sure that what I am doing is idiomatic or anything. Here is a function:</p> <pre><code>template&lt;typename String&gt; auto upper(String str, c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-01T20:59:06.870", "Id": "63967", "Score": "0", "body": "I am not sure std::locale{} will give you the C-Locale. It will give you the current locale (which will be C-Locale if not explicitly set (though on windows it may inherit from th...
[ { "body": "<p>I <em>think</em> I'd prefer to have the user pass a locale instead of a facet. In most typical cases, a user will deal only with locales, not with the individual facets that make up a particular locale. It's also relatively easy for a user to create a locale on demand, so the code looks something ...
{ "AcceptedAnswerId": "43254", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T15:01:01.180", "Id": "38272", "Score": "5", "Tags": [ "c++", "strings", "c++11", "localization" ], "Title": "String algorithms and locale" }
38272
<p>What are your thoughts on the following code? is it secure enough?</p> <p><strong>Note:</strong> <code>$password</code> is used to represent the secret, which would essentially be a SHA512 hash of</p> <pre><code>username . password . signupdate(unixtime) </code></pre> <p>Do you think I'm covered?</p> <p><a href=...
[]
[ { "body": "<p>No, it isn't secure.</p>\n\n<p>Inventing your own hashing algorithms is a horrible idea. When doing password hashing, use something invented by cryptographers that was made for password hashing, e.g. <em>bcrypt</em>. Because I'm not a cryptographer either, I can't give you a full explanation why y...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T15:45:00.600", "Id": "38274", "Score": "0", "Tags": [ "php", "security", "api" ], "Title": "Evaluating a hashing function used to create secure API key" }
38274
<p>I am trying to implement two simple convertors: date/time to time-stamp and vice-versa, without any dependencies on time library routines (such as <code>localtime</code>, <code>mktime</code>, etc, mainly due to the fact that some of them are not thread-safe).</p> <p>I have the following date/time structure:</p> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T16:03:53.393", "Id": "63699", "Score": "1", "body": "Your code will break for dates after 2100 (which is not a leap year), and you do not account for any timezones or daylight-savings." }, { "ContentLicense": "CC BY-SA 3.0",...
[ { "body": "<ol>\n<li><p>Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.</p></li>\n<li><p>Make <code>static unsigned short days</code> a <code>const</cod...
{ "AcceptedAnswerId": "38302", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T15:51:15.973", "Id": "38275", "Score": "14", "Tags": [ "c", "datetime", "converting", "embedded", "threadx" ], "Title": "Convert between date/time and time-stamp witho...
38275
<p>I have some questions regarding a common implementation of the UoW, Repository Pattern and EF:</p> <pre><code>public interface IAppUow { void Commit(); IRepository&lt;Customer&gt; Customer{ get; } // IRepository&lt;T&gt; IOrderRepository Order{ get; } // implements IRepository&lt;T&gt; } </code...
[]
[ { "body": "<p>This question is on the edge of being off-topic, there's really not much code to review here.</p>\n\n<p>However your <code>IAppUow</code> interface has a number of flaws:</p>\n\n<ul>\n<li><strong>Naming</strong>: I don't see a need for the <code>App</code> part. I think a better name would be more...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T16:33:16.133", "Id": "38277", "Score": "1", "Tags": [ "c#", "design-patterns", "entity-framework" ], "Title": "Unit of work and common implementation" }
38277
<p>I have an integer list <code>l</code> and a predefined integer value row (which is never manipulated inside the code). If value of row is 5, then I want the loop to exit if <code>l</code> contains 1,2,3,4. If it is 3, then <code>l</code> should contain 1,2 and so on for any value. I have devised a way of doing this...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T17:17:39.830", "Id": "63704", "Score": "0", "body": "You will need to post the contents of your `do...while` for this to make any real sense." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T17:42:15.2...
[ { "body": "<ol>\n<li><p><code>check</code> is not a good name for the function as it does not say what it checks. It returns false if all numbers below <code>row</code> are present and <code>true</code> otherwise. So a better name might be <code>numbersAreMissing</code>. </p></li>\n<li><p>You can make your loop...
{ "AcceptedAnswerId": "38281", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T16:50:12.813", "Id": "38278", "Score": "-2", "Tags": [ "c#" ], "Title": "An exit condition for a do-while loop using lists" }
38278
<p>I've been working on a website and Rails and am fairly proud of my HTML semantics. However, my CSS code has become enormous in size, which is largely unnecessary for such a small website.</p> <p>How could I shorten my code, make it easier to understand, and remove redundancy? I would prefer to have an automated pro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-23T18:36:40.590", "Id": "66953", "Score": "2", "body": "I don't see anything Sass specific here, is this just the compiled CSS?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-23T19:44:33.030", "Id": "6...
[ { "body": "<p>You may want to look at <a href=\"http://compass-style.org/reference/compass/css3/font_face/\" rel=\"nofollow\">Compass</a> for generating your font-face information.</p>\n\n<p>Your media queries are a bit excessive here. Other than your font-face block, there's not a spec of code that exists out...
{ "AcceptedAnswerId": "39902", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T18:07:13.087", "Id": "38283", "Score": "2", "Tags": [ "optimization", "ruby-on-rails", "sass" ], "Title": "Quickly fixing unmaintainable SCSS code in Rails" }
38283
<p>I have started working on my first open source project making an LDAP library in Python. I have coded quite a bit and am starting to think about a couple of the details related to design.</p> <p>I have been considering what to do is in regard to the protocol part of the library. </p> <p>Here is a sample of what ...
[]
[ { "body": "<p>A class represents a group of <em>things</em> with common behaviour and persistent instance data. But in the fragment of code you present here, there is no <em>thing</em>. Your example is:</p>\n\n<pre><code>bind = BindRequest(version, myname, mypassword)\nencoded = bind.encode()\n</code></pre>\n\n...
{ "AcceptedAnswerId": "38392", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T18:13:13.567", "Id": "38284", "Score": "3", "Tags": [ "python", "library", "ldap" ], "Title": "LDAP Library design, classes, functions, initialization?" }
38284
<p>ThreadX is a realtime operating system for <a href="/questions/tagged/embedded" class="post-tag" title="show questions tagged &#39;embedded&#39;" rel="tag">embedded</a> systems from Express Logic, Inc. of San Diego, California, USA.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T18:34:24.257", "Id": "38285", "Score": "0", "Tags": null, "Title": null }
38285
ThreadX is a realtime operating system for embedded systems.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T18:34:24.257", "Id": "38286", "Score": "0", "Tags": null, "Title": null }
38286
<p>I need to speed up the function below:</p> <pre><code>import numpy as np import itertools def combcol(myarr): ndims = myarr.shape[0] solutions = [] for idx1, idx2, idx3, idx4, idx5, idx6 in itertools.combinations(np.arange(ndims), 6): c1, c2, c3, c4, c5, c6 = myarr[idx1,1], myarr[idx2,2], myarr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T20:08:37.993", "Id": "63713", "Score": "2", "body": "What are you trying to achieve here?" } ]
[ { "body": "<p>Your algorithm is of time complexity <code>O(n^6)</code> in <code>ndims</code>. If your current code needs <code>65 s</code> for <code>ndims = 40</code>, then one could estimate the time for <code>ndims = 500</code> to be roughly <code>8 years</code>. Even an improvement of the most inner block's ...
{ "AcceptedAnswerId": "38299", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T18:59:02.007", "Id": "38287", "Score": "1", "Tags": [ "python", "performance", "python-3.x", "numpy", "combinatorics" ], "Title": "Fastest way for working with itertool...
38287
<p>Python 2.7.x is the final version of the Python 2.x series. Development on Python 2.7.x still continues, but no new features are being added.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T19:03:54.563", "Id": "38288", "Score": "0", "Tags": null, "Title": null }
38288
Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T19:03:54.563", "Id": "38289", "Score": "0", "Tags": null, "Title": null }
38289
<p>I have a large JavaScript function to calculate the number of chips, and which denomination of chips to show as the players chip stack. It's done on the base of 10.</p> <p>I have chip denominations worth 1, 10, 100, 1000, 10000, 100000, 1000000. For a total of 7 different chip values, and 7 for loops in my JavaScri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T22:05:52.623", "Id": "63722", "Score": "2", "body": "**7 for loops, 9 variables, 7 if statements, and one function** - doesn't it sound like you need more functions?" } ]
[ { "body": "<p>Perhaps you can use the mod operator (<code>%</code>)? Something along this line (I don't really know JavaScript; below is just the concept):</p>\n\n<pre><code>value = parsetInt( chips.toString() );\nbase = 0.1;\n\nwhile( value &gt; 0 ){\n stack = value % 10;\n value = Math.floor( value / 1...
{ "AcceptedAnswerId": "38298", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T20:23:29.177", "Id": "38293", "Score": "4", "Tags": [ "javascript", "optimization", "performance", "beginner" ], "Title": "Calculating number of chips and determining chip ...
38293
<p>I'm trying to refactor the following code and could use some suggestions. Basically, three functions generating random numbers in different ways are called:</p> <pre><code>import java.util.Random; public final class JP_RandomNumbers { /** * @param aArgs */ public static void main(String[] aArgs...
[]
[ { "body": "<p>The number generation technique is generally sound. I just have the following minor suggestions:</p>\n\n<ul>\n<li><p>The idiomatic way to repeat something 10 times is</p>\n\n<pre><code>for (int idx = 0 ; idx &lt; 10 ; ++idx) { … }\n</code></pre></li>\n<li><p>Use the <code>fRandom</code> instance ...
{ "AcceptedAnswerId": "38300", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T22:13:10.510", "Id": "38297", "Score": "5", "Tags": [ "java", "random" ], "Title": "Generating random numbers" }
38297
<p>I wrote the following code to parse some weak ciphers out of an nmap.xml report. I am wondering if there is a more elegant way to write this code in order to avoid the nested for loops with the double <code>if</code> loops. Also, I had to create the two queues. There has to be a better way using list comprehension ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T23:24:50.453", "Id": "63728", "Score": "0", "body": "Could you provide an example of the input XML so that we can see whether the way you extract information from the document is optimal?" }, { "ContentLicense": "CC BY-SA 3....
[ { "body": "<p>I don't believe that this does what you want, for a few reasons.</p>\n\n<p>First, I'm not 100% on interleaving <code>ElementTree</code> iterators, but this may pick up more elements than you want; for example, what happens when the document is something like</p>\n\n<pre><code>&lt;host&gt;\n&lt;add...
{ "AcceptedAnswerId": "38304", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T23:13:23.427", "Id": "38301", "Score": "2", "Tags": [ "python", "parsing" ], "Title": "Parse weak ciphers out of an nmap.xml report" }
38301
<p>I'm trying to improve my JavaScript (I'm usually a copy/paste guy but can do basic DOM stuff with jQuery too), so I decided to try and make a function to validate an email address without using Regex.</p> <p>The code seems to work, but I'm interested in hearing how it could be improved.</p> <p>I'll include the cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T02:45:00.017", "Id": "63748", "Score": "2", "body": "_\"I'm interested in hearing how it could be improved\"_ - With a regex. But if the point of the exercise is specifically to practice coding without regex, well, yes, you will end...
[ { "body": "<p>Read the <a href=\"http://en.wikipedia.org/wiki/Email_address#Syntax\" rel=\"nofollow\">(email address: syntax) article on Wikipedia</a> for what is allowed. Your current validation will produce a lot of fails for valid email addresses.</p>\n", "comments": [ { "ContentLicense": ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T02:10:15.130", "Id": "38305", "Score": "4", "Tags": [ "javascript", "validation", "email" ], "Title": "Validating email without Regex" }
38305
<p>Here is an API key gen script for a cryptocurrency trading platform I am building.</p> <p>First it checks to see if a key exists in the db for the user ID. If it does exist, it displays the key. If it doesn't, it creates one.</p> <p>Next it checks to make sure the key is unique, by polling the db for identical key...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T04:18:15.150", "Id": "63757", "Score": "1", "body": "Three quick comments besides answering the actual question on security... First, `mysql_query` is deprecated and you should use newer implementations suggested here http://us2.php...
[ { "body": "<p>An API key only have to be unique enough to avoid collison nothing more and here you are doing to much to achieve this. For example the rehashing will incrase the chance for a collison.</p>\n\n<p>I have created a class for generating unique keys for example an API key usage or simply for primary k...
{ "AcceptedAnswerId": "38316", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T03:04:13.440", "Id": "38309", "Score": "7", "Tags": [ "php", "mysql", "api", "cryptocurrency" ], "Title": "Security of API Keygen for a cryptocurrency trading platform" }
38309
<p>I wrote a simple android app to export the browsers history as JSON, but I do not know if the resulting JSON is a format that the user will easily be able to parse and use. </p> <p>Is there any way that i could improve the resulting format? Will it be easy for the user to use? </p> <p>I have the title of the pa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T12:33:00.113", "Id": "63789", "Score": "0", "body": "I'm not sure this question is in-topic. We do *code* reviews, not suggestions on how to make an *output format* better." } ]
[ { "body": "<p>If you want to use the JSON to be easily parsed, I would suggest using a JSONArray so your output is ordered the way it is in the browsers history (unlike the JSONObject, which are key/value pairs not in order). If you use JSONArray you should save the title inside the objects of course.</p>\n\n<h...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T04:12:56.693", "Id": "38311", "Score": "0", "Tags": [ "java", "android", "json" ], "Title": "Android export browser history as JSON" }
38311
<p>I have recently been looking into the concepts/patterns behind dependency injection, inversion of control, and registries/service locators. I have searched about the internet on the subjects and have come up with some decent understanding about them, but some things still seem a little cloudy. To start, I would li...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T07:26:23.617", "Id": "63764", "Score": "0", "body": "\"I know I will likely shamed and stoned\" Let me be the first to cast a stone at you." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T08:17:21.813...
[ { "body": "<p>First off: _steer clear of <code>static</code>'s as much as you can, especially in PHP.</p>\n\n<p>You seem unclear as to <em>what</em> IoC exactly is. It's perfectly simple, though: IoC has more to do with <em>how</em> your code works. How you generate the desired results. It doesn't define how yo...
{ "AcceptedAnswerId": "38320", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T06:34:39.203", "Id": "38312", "Score": "1", "Tags": [ "php", "design-patterns", "dependency-injection", "static" ], "Title": "Dependency injection and inversion of control"...
38312
<p>I have written this working block, but is it optimized? I am getting currency in this format: 1.234,25.</p> <pre><code>public static String convertCurrency(String value, String exchangeCurrencyId) { java.text.NumberFormat format = null; value = value.replaceAll("\\.", ","); char[] chars = value.toCharAr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T11:18:04.410", "Id": "63784", "Score": "0", "body": "Why do you replace `\\\\.` by `,`, change last `,` and replace all `,` by empty string? Why you can't immediately replace `.` by empty string and after that replace `,` by `.` if ...
[ { "body": "<p>This code has various issues. Here is what I understand your code does:</p>\n\n<blockquote>\n <p>The code takes a formatted number which consists of digits, separators (commas or periods). The last separator is used as the decimal separator, all other separators are deleted.</p>\n \n <p>Then it...
{ "AcceptedAnswerId": "38382", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T10:19:02.370", "Id": "38317", "Score": "4", "Tags": [ "java", "parsing", "floating-point", "i18n", "finance" ], "Title": "Optimize parsing of number for currency conver...
38317
<p>I would like to refactor code below and get rid of if statements for classes from view.</p> <pre><code>.container .tabbable.tabs-left %ul.nav.nav-tabs - @related_tasks.each do |task| %li{class: ("active" if @task == task)} = link_to task.name, "#tab#{task.id}", data: { toggle: 'tab' },...
[]
[ { "body": "<p>Helper methods are good for this. In your view's helper file:</p>\n\n<pre><code>def task_link_class(task)\n if @current_user_tasks.include?(task)\n ''\n else\n 'inactive'\n end\nend\n</code></pre>\n\n<p>Some would prefer the trinary operator instead:</p>\n\n<pre><code>def task_link_class...
{ "AcceptedAnswerId": "38625", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T13:55:39.550", "Id": "38322", "Score": "2", "Tags": [ "ruby", "ruby-on-rails", "haml" ], "Title": "Render dynamically vertical tabs and set classes depends on if statement" }
38322
<p>I have a complicated select procedure that I solved with a 5 query select, so I am posting it here to get suggestions on how I can shorten it up a bit. I am hoping that someone can help me make it a single query select. I'm using nhibernate query over here.</p> <p>I have 7 tables which are</p> <ul> <li><code>t_us...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T04:15:44.080", "Id": "67222", "Score": "0", "body": "Are you stuck with an NHibernate solution? Can you do a stored procedure/view/dynamic sql statement instead?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>If this is a web application, you can use an HttpModule to do your session management. Begin every web request by opening a session and beginning a transaction. At the end of every web request, commit the transaction and close the session.</p>\n\n<p>As long as you're wrapping all the hits to the d...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T16:28:33.223", "Id": "38330", "Score": "7", "Tags": [ "c#", "linq", "hibernate" ], "Title": "NHibernate select with Query Over optimization for user roles base case" }
38330
<p>This program attempts to solve the following challenge:</p> <blockquote> <p>There is a 2D grid of cells containing <em>N</em> lamps. Each lamp illuminates its own cell as well as its eight neighbours. How many lamps can you possibly remove such that each cell that was originally illuminated remains illuminated?<...
[]
[ { "body": "<pre><code>import java.util.*;\n</code></pre>\n\n<p>Importing whole packages is not a very good idea, especially of there are multiple identical named classes in the imported packages. You should only import what is needed.</p>\n\n<hr>\n\n<pre><code>class test\n{\n</code></pre>\n\n<p>Classnames in Ja...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T19:20:47.373", "Id": "38332", "Score": "6", "Tags": [ "java", "algorithm" ], "Title": "Minimizing number of field lamps" }
38332
<p>The following code will add to each code block a 'Select Code' button that will select the code belonging to that block. Please review for maintainability.</p> <p>In order to use this, visit <a href="http://codereviewcommunity.github.io/CodeReviewBookmarklet/">http://codereviewcommunity.github.io/CodeReviewBookmark...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T23:13:57.847", "Id": "63830", "Score": "0", "body": "Works on Safari 7." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T23:25:06.130", "Id": "63833", "Score": "0", "body": "How do you test...
[ { "body": "<p>You inject the button using <a href=\"http://api.jquery.com/prepend/\"><code>jQuery.prepend()</code></a>, which inserts the button as the first child of the <code>.prettyprint</code> code block. Therefore, when the bookmarklet is invoked, and it selects the contents of the code block, the \"Selec...
{ "AcceptedAnswerId": "38343", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T21:58:06.630", "Id": "38336", "Score": "13", "Tags": [ "javascript", "bookmarklet", "stackexchange" ], "Title": "Bookmarklet for selecting code snippets on Code Review" }
38336
<p>Due their nature they require a stricter coding style than simple JavaScript.</p> <ul> <li><p>All comments should be in the <code>/* */</code> form because the code can get concatenated in one line.</p></li> <li><p>There is a size limit for bookmarklets which gives some freedom to use single-letter variables, etc.<...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T22:00:27.233", "Id": "38338", "Score": "0", "Tags": null, "Title": null }
38338
A bookmarklet is a bookmark stored in a web browser that contains JavaScript commands to extend the browser's functionality.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T22:00:27.233", "Id": "38339", "Score": "0", "Tags": null, "Title": null }
38339
<p>I've just replaced <a href="http://linuxian.com/2013/12/30/bash-script-compressed-one-day-old-files/" rel="nofollow">my bash script</a> with a Python script, and this is my first script where I used <code>class</code>.</p> <p>Please review and give me suggestions.</p> <pre><code>#!/usr/bin/env python # This Scrip...
[]
[ { "body": "<p>First thing's first, instead of calling out to the <code>gzip</code> program with <code>os.system</code>, use the <code>gzip</code> module in Python. This will almost always be more portable: <a href=\"http://docs.python.org/2/library/gzip.html\" rel=\"nofollow\">http://docs.python.org/2/library/...
{ "AcceptedAnswerId": "38341", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T22:24:16.503", "Id": "38340", "Score": "1", "Tags": [ "python", "datetime" ], "Title": "Find and compress file in Python script" }
38340
<p>I'm curious if this is the right way of going about the issue: </p> <pre><code>function sortWordsByIncorrectAnswers(array) { array = array.slice(0) var sortedArray = array.sort(function (a, b) { a = a.fields.false; b = b.fields.false; return a &lt; b ? -1 : a &gt; b ? 1 : 0; }); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T23:45:41.220", "Id": "63838", "Score": "0", "body": "You are making a shallow copy, not a deep copy. That means you get a new array, but if the elements in the array are objects or arrays themselves, then they are the same objects ...
[ { "body": "<p><code>.slice()</code> does not actually do a deep copy, the easiest way to do a deep copy with simple objects is </p>\n\n<pre><code>array = JSON.parse( JSON.stringify( array ) )\n</code></pre>\n\n<p>Also, you can sort on a boolean in a simpler way:</p>\n\n<pre><code>function sortWordsByIncorrectAn...
{ "AcceptedAnswerId": "38346", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T23:01:17.830", "Id": "38342", "Score": "1", "Tags": [ "javascript", "reference" ], "Title": "Deep reference and object passing" }
38342
<p>I will admit that this code looks sloppy and repetitive. Which is why I'm asking how I can improve the efficiency and readability of this code.</p> <pre><code>// Sidebar tab highlight when clicked $("#sidebar-tabs-container table td").click(function() { $("#sidebar-tabs-container table td").removeClass("sidebar-t...
[]
[ { "body": "<p>This code can use quite a bit of work.</p>\n\n<ul>\n<li>Run this code through a beautifier, ideally prior to posting it to codereview ;)</li>\n<li>You are repeating yourself a lot, example : </li>\n</ul>\n\n<blockquote>\n<pre><code>// Sidebar tab highlight when clicked\n$(\"#sidebar-tabs-container...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-30T23:24:51.273", "Id": "38344", "Score": "1", "Tags": [ "javascript" ], "Title": "Menu and SideBar Slides, Fades, and Hides" }
38344
<p>I was trying to write some of the Haskell list functions into Java, and I realized that one of the key strengths for many of the functions was the ability to pass in a boolean expression. I decided to write a parser to facilitate this. It has worked perfectly as far as I have tested it, but <strong>I want to know ju...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T01:29:37.727", "Id": "63855", "Score": "2", "body": "Azar .... have you considered using the Rhino Javascript engine embedded in Java 7? [Consider these examples....](http://docs.oracle.com/javase/7/docs/technotes/guides/scripting/p...
[ { "body": "<p>You've written something quite impressive there, but it is an unorthodox\napproach and some of the code is rather impenetrable. I've laid out a few\npoints of issue and in some cases possible solutions and comments below.</p>\n\n<h2>Method documentation</h2>\n\n<p>Your methods could stand to have...
{ "AcceptedAnswerId": "38352", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T01:17:12.747", "Id": "38348", "Score": "13", "Tags": [ "java", "strings", "array", "haskell", "parsing" ], "Title": "Boolean expression parser" }
38348
<p>I've been working on a <a href="https://github.com/megawac/MutationObserver.js" rel="nofollow"><code>MutationObserver</code> es5 shim</a> and would appreciate some feedback on my technique for identifying changes between a <code>node</code> and its <code>clone</code> from earlier state. The reason I'm asking for thi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T14:48:46.617", "Id": "63907", "Score": "0", "body": "Can you not simply compare 2 nodes with `===` ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T17:58:25.193", "Id": "63918", "Score": "0",...
[ { "body": "<p>I assume you already scoured most resources on optimizing js, since you use most tricks ( including <code>~~</code> for <code>Math.floor</code> ). The only 1 I did not see is </p>\n\n<ul>\n<li>Store a reference to <code>Math.abs</code>: <code>var abs = Math.abs;</code> </li>\n</ul>\n\n<p>I have to...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T05:03:02.437", "Id": "38351", "Score": "6", "Tags": [ "javascript", "tree", "dom" ], "Title": "MutationObserver (shim): Finding differences between 2 DOM trees" }
38351
<p>Because the MLlib does not support the sparse input, I ran the following code, which supports the sparse input format, on spark clusters. The settings are:</p> <ul> <li>5 nodes, each node with 8 cores (all the CPU on each node are 100%, 98% for user model, when running the code). </li> <li>the input: 10,000,000+ i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-04T03:21:08.260", "Id": "64295", "Score": "0", "body": "If you'd like your added code to be reviewed, I recommend posting it as a new question with a link back to this question." } ]
[ { "body": "<p>It seems to me that if you have very sparse vectors, converting to a non-sparse vector will be very inefficient. E.g. you have a sparse vector with 4 non-zero elements and convert it into a flat vector with 1000000 elements, the array allocation will take the most time.</p>\n\n<p>You can of course...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T08:15:30.590", "Id": "38354", "Score": "5", "Tags": [ "performance", "scala", "machine-learning", "apache-spark" ], "Title": "Why does the LR on spark run so slowly?" }
38354
<p><a href="http://spark.incubator.apache.org" rel="nofollow">http://spark.incubator.apache.org</a></p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T10:00:45.763", "Id": "38356", "Score": "0", "Tags": null, "Title": null }
38356
Apache Spark is an open source cluster computing system that aims to make data analytics fast — both fast to run and fast to write.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T10:00:45.763", "Id": "38357", "Score": "0", "Tags": null, "Title": null }
38357
<p>I implemented an algorithm that gives me a list of points that should be drawn in order the get a line between two points. Please note: it works only in a coordinate system whose origin (0,0) is in the upper left corner.</p> <p>I'd like to get some review on my Haskell code, could it be improved in terms of the lan...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T10:22:11.733", "Id": "63891", "Score": "1", "body": "`where m`… what?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T10:26:24.847", "Id": "63892", "Score": "0", "body": "updated: `where m...
[ { "body": "<p>Thoughts.</p>\n\n<p>Define a <code>Line</code> type and rename <code>getLinePoints</code> to <code>mkLine</code>. A list of points may represent anything but a <code>Line [Points]</code> implies the <code>Point</code>s within the line. Where possible let the type system work for you. Of course you...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T10:16:26.617", "Id": "38358", "Score": "3", "Tags": [ "algorithm", "beginner", "haskell", "graphics" ], "Title": "Bresenham-like line algorithm" }
38358
<p>A <strong>signal</strong> is an information-carrying wave, but in the digital sense, a 'signal' refers to either received or transmitted streams/blocks of data, commonly representing real-world quantities such as audio levels, luminosity, pressure etc over time or distance. These real-world quantities usually comes...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T12:56:03.553", "Id": "38361", "Score": "0", "Tags": null, "Title": null }
38361
AKA digital signal processing (DSP). A signal is an information-carrying wave, but in the digital sense, a 'signal' refers to either received or transmitted streams/blocks of data, commonly representing real-world quantities such as audio levels, luminosity, pressure etc over time or distance. 'Processing' is the act o...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T12:56:03.553", "Id": "38362", "Score": "0", "Tags": null, "Title": null }
38362
<p>I need a special dictionary that would do as follows:</p> <ul> <li><p>if key is set to more than once, the values are a list of all set values. Such a list is returned as value on get.</p></li> <li><p>if key is set only once, it is set to that value, and returned as value as well.</p></li> </ul> <p>Sort of like Mu...
[]
[ { "body": "<p>I think the second requirement (return the value for a key with only a single assignment as itself) is a bad requirement. It goes against Guido's guidance that passing different values (of the same type) to a function should avoid returning different types, and you can see how it breaks simple cod...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T13:56:00.243", "Id": "38364", "Score": "2", "Tags": [ "python", "hash-map" ], "Title": "Special dictionary" }
38364
<p>I was solving Project Euler problem 16, which asks to find the sum of digits of the number 2 raised to the power 1000. Using Python, it can be solved in one line of code:</p> <pre><code>sum(map(int, list(str(2**1000)))) </code></pre> <p>It felt too easy so I decided to write a function in C to do the same job. Her...
[]
[ { "body": "<p>The problem calls for computing the sum of digits in 2<sup>1000</sup>. You did 2<sup>10000</sup>. Overachiever!</p>\n\n<p>There are a few things you could do to improve readability.</p>\n\n<p><code>char *arr</code> looks a lot like a string. One might initially think that you are storing the nu...
{ "AcceptedAnswerId": "38373", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T16:47:36.377", "Id": "38370", "Score": "4", "Tags": [ "c", "algorithm", "project-euler" ], "Title": "Function to find sum of digits in the number a^b where a, b are positive in...
38370
<p>I'm responsible for maintaining a web service project in c#. I have one service class with a bunch of methods that look a lot like this:</p> <pre><code> [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "v1/Login", ResponseFormat = WebMessageFormat.Json)] public string Login() { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-01T15:41:36.630", "Id": "63953", "Score": "0", "body": "Why are you parsing and creating the JSONs instead of using serialization? I think that would simplify your code quite a lot." }, { "ContentLicense": "CC BY-SA 3.0", "...
[ { "body": "<p>I'm not sure why your change all of a sudden would expose data to the business layer when it didn't before.</p>\n\n<p>If you have a pattern of methods which look like this:</p>\n\n<pre><code>public string MyServiceCall()\n{\n try\n {\n JObject incomingRequestJson = retrieveJson();\n ...
{ "AcceptedAnswerId": "38379", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-31T16:54:15.347", "Id": "38371", "Score": "1", "Tags": [ "c#", ".net", "asp.net", "wcf", "web-services" ], "Title": "Avoiding Duplicate Boilerplate Code in WCF Service" }
38371