body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Quite sometime back I had written an Android application which simulates the path of a pendulum. You can also have look at the complete discussion in my technical blog <a href="http://som-itsolutions.blogspot.in/2012/06/android-graphics-and-animation-pendulum.html" rel="nofollow">here</a>. </p> <p>Please review it ...
[]
[ { "body": "<h3>Boolean usage:</h3>\n\n<p>You have waaay too many explicit boolean flags, which are only a implicit variant of some others.</p>\n\n<blockquote>\n<pre><code>private boolean leftToRightMovement = true;\nprivate boolean rightToLeftMovement = false;\nprivate boolean atTheMiddlePositionWhileLeftToRigh...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T03:37:01.527", "Id": "49290", "Score": "5", "Tags": [ "java", "android", "simulation" ], "Title": "Simulating Pendulum Motion in Android" }
49290
<p>Physics is a science that studies the interactions of energy and matter.</p> <p>The physics tag should be used for questions about how physics can be simulated or implemented in programming. Please ask questions about physics in a non-programming context on the <a href="https://physics.stackexchange.com/">Physics s...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T04:17:49.360", "Id": "49294", "Score": "0", "Tags": null, "Title": null }
49294
Physics is a science that studies the interactions of energy and matter. The physics tag should be used for questions about how physics can be simulated or implemented in programming.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T04:17:49.360", "Id": "49295", "Score": "0", "Tags": null, "Title": null }
49295
<p>I am checking for particular keywords in a string, and then changing the foreground and background colors of substrings based on the keywords. Following is the snippet for checking the background code:</p> <pre><code>if(string.contains("[30;42m") || string.contains("[31;42m") || string.contains("[32;42m") || st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T07:31:20.487", "Id": "86693", "Score": "3", "body": "Could you please provide a little more conetext on the implementation inside the if-block? I strongly suspect the refactoring strategy will change, depending on how you impelement...
[ { "body": "<p>You can do it a little more generic but I'm afraid you still have to test each.</p>\n\n<p>I don't know if your case is always changing to green or not.<br/>\nIf not I suggest the following enum :</p>\n\n<pre><code>/**\n *\n * @author chillworld\n */\npublic enum ColorMapperEnum {\n GREEN(\"[30;...
{ "AcceptedAnswerId": "49304", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T06:40:31.063", "Id": "49301", "Score": "4", "Tags": [ "java", "strings", "console" ], "Title": "Changing the foreground and background colors of substrings based on ANSI escape...
49301
<p>I've written some code today to be able to dynamically execute prepared statements/parameterized queries.</p> <p>I need a fresh pair of eyes to look through my code for eventual performance gains that can be made.</p> <p>I've tested the code on up to 20 parameters without problems.</p> <p>For formatting I use thi...
[]
[ { "body": "<ol>\n<li><p>You use a very complicated way to extract the first element of an array. Just use <code>array_shift</code> instead.</p>\n\n<pre><code>$query = array_shift($arguments);\n</code></pre></li>\n<li><p>Use <code>foreach</code> instead of a <code>for</code> loop:</p>\n\n<pre><code>foreach ($pa...
{ "AcceptedAnswerId": "49322", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T08:21:37.060", "Id": "49305", "Score": "2", "Tags": [ "php", "mysqli" ], "Title": "MySQLi-extension class (parameterized queries)" }
49305
<p>I've tried to create application with MVC N-layer pattern. I asked my buddy for a shot review, and he said, "You should separate logic from controller". But my controller only work as a <code>ViewModel</code> creator. I'm sure I must not create <code>ViewModel</code> from <code>BusinessLayer</code>. I need to pass ...
[]
[ { "body": "<blockquote>\n <p>\"<em>You should separate logic from controller</em>\"</p>\n</blockquote>\n\n<p>Honestly if a colleague said that to me then I would immediately say. <em>Great thanks. What do you think I could move out and why</em>. </p>\n\n<p>It's great to offer feedback but generic feedback l...
{ "AcceptedAnswerId": "49320", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T08:50:00.703", "Id": "49309", "Score": "1", "Tags": [ "c#", ".net", "asp.net", "mvc", "controller" ], "Title": ".ASP controller code" }
49309
<p>In my program I call "granularity" the "minimum step" for a number. For example, if <code>granularity == 4</code> then I only work with numbers "0, 4, 8, 12 etc" (so normal <code>integer</code> has <code>granularity == 1</code>).</p> <p>I need a function to round an integer number to a certain granularity. So for e...
[]
[ { "body": "<p>Let me start with the usual:</p>\n\n<h2>Naming</h2>\n\n<ul>\n<li>myDecimal: Usually, the prefix \"my\" does not bear any sensible information. You should think about the information you want to pass by the types name. (For example Decimal is often the name for decimal fractions and the way in whic...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T08:56:51.257", "Id": "49310", "Score": "4", "Tags": [ "c++", "algorithm", "performance", "integer" ], "Title": "Rounding ints division result to certain \"granularity\"" }
49310
<p>I am fetching data from the database using Entity Framework and Linq queries. I am wondering about the performance of getting data. I just want to check whether or not a <code>well</code> exists in the database. The database table has 15 columns and the number of rows are unknown.</p> <pre><code>internal static boo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T09:51:48.063", "Id": "86707", "Score": "3", "body": "I suggest perhaps profiling the query and seeing what the underlying SQL is. LinqPad is quite good for this, or I believe you should be able to see the SQL in debugger. In spite...
[ { "body": "<p>You can try the <code>.Any</code> function on IQueryable. It is made for checking if there are any records.</p>\n\n<p>Remember that <code>.Any()</code> has an overload that takes an expression, making the solution </p>\n\n<pre><code>internal static bool WellExists(string name, DatabaseContext cont...
{ "AcceptedAnswerId": "49316", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T09:43:31.527", "Id": "49314", "Score": "4", "Tags": [ "c#", "performance", "linq" ], "Title": "Fetching data from a database" }
49314
<p>I am implementing a thread like the following. Is my implementation correct?</p> <p>It works well, but I need a check.</p> <pre><code>myList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, final View view, int position, long id...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T10:08:03.150", "Id": "86711", "Score": "0", "body": "android has background threads available (with options to callback the main thread when done) so there is no need to roll your own setup" }, { "ContentLicense": "CC BY-SA ...
[ { "body": "<p><a href=\"https://codereview.stackexchange.com/questions/49317/is-this-implementation-of-thread-available#comment86711_49317\">@ratchetfreak's comment</a> is correct, expanding on it here a bit:</p>\n\n<p><a href=\"http://developer.android.com/reference/android/os/AsyncTask.html\" rel=\"nofollow n...
{ "AcceptedAnswerId": "49323", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T09:57:19.583", "Id": "49317", "Score": "6", "Tags": [ "java", "optimization", "android", "thread-safety", "event-handling" ], "Title": "Is this Android click handler us...
49317
<p>I have an Entity Framework working with a SQL database. A Web Forms application is currently communicating directly with the Entity Framework model from code behind. I have been tasked with creating a 'middle layer' Business Logic Layer to sit between the UI and DAL (EF).</p> <p>I have come up with the below for th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T10:02:07.387", "Id": "86710", "Score": "1", "body": "Sidenote: Your methods should be in CamcelCase (to follow the general C# convention), and not the java convention with first letter in lower case. :-)" }, { "ContentLicens...
[ { "body": "<p>imho the business layer should be unaware of the persistence layer. What you got there is a big pile of mess.</p>\n\n<p>Here are a couple of issues:</p>\n\n<ol>\n<li><p>Why do the business layer ever know about the salt? It's information required for the persistence layer only.</p></li>\n<li><p>En...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T09:57:36.833", "Id": "49318", "Score": "2", "Tags": [ "c#", "entity-framework" ], "Title": "Seperating Entity Framework into BLL" }
49318
<p>I just solved <a href="https://projecteuler.net/problem=38" rel="nofollow">Project Euler 38</a> and was wondering if you guys could provide some suggestions on how to speed it up. I've tried adding extra conditions but they increase the time. Any ideas on how to optimize the numbers I'm checking would be appreciated...
[]
[ { "body": "<ul>\n<li>Checking <code>if len(num) &gt;= 5</code> is redundant because you only call the function with <code>k &lt; 10**5</code></li>\n<li>Instead of <code>sorted([int(x) for x in num])</code> you could compute just <code>sorted(num)</code> and compare that to a <code>DIGITS = [str(i) for i in rang...
{ "AcceptedAnswerId": "49329", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T10:15:01.520", "Id": "49321", "Score": "5", "Tags": [ "python", "optimization", "programming-challenge" ], "Title": "Project Euler 38: Pandigital Multiples" }
49321
<p>I am new to Python as well as threading and had to build an inline script routine for the use within a Open Sesame Experiment. The Routine should open a program, play tones and catch reaction times. It runs OK so far, but I would be glad for pointing out mistakes and any best practice that I did not follow as I want...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T14:24:04.890", "Id": "86750", "Score": "0", "body": "it = it+1 is the same as it+=1 and the latter is considered best practice. Other than that, I really can't complain about it too much." }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>Create a class <code>Sound</code> like this:</p>\n\n<pre><code>class Sound:\n nTones = 5\n soundLength = 60\n frequency = 1000\n attackTime = 0\n decayTime = 0\n shortest = 10\n longest = 15\n</code></pre>\n\n<p>Note that I have changed the name <code>soundlength</code> to <code>soun...
{ "AcceptedAnswerId": "49356", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T11:45:28.070", "Id": "49325", "Score": "3", "Tags": [ "python", "beginner", "multithreading" ], "Title": "Inline script routine for Open Sesame experiment" }
49325
<p>In a module of a win forms application I have a hierarchy of classes like <code>BaseRecovery</code>, <code>LoanRecovery</code> and <code>FineRecovery</code>. Both <code>LoanRecovery</code> and <code>FineRecovery</code> inherits from <code>BaseRecovery</code>. All these models have one view called <code>RecoveryForm<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T18:16:55.553", "Id": "86794", "Score": "0", "body": "What do `IBaseRecover` and `BaseRecovery` look like? It seems rather confusing that you need different types (i.e., `LoanRecovery`, `FineRecovery`, and `InsuranceRecovery`) if `I...
[ { "body": "<p>There are a number of typos in your code blocks, that lead me to believe the code wasn't taken from the working code in your IDE. I will assume the following:</p>\n\n<ul>\n<li><code>IBaseRcovery</code> is really <code>IBaseRecovery</code></li>\n<li><code>RecoveryPresenter( IBaseRecover model, ...<...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T12:53:45.420", "Id": "49330", "Score": "5", "Tags": [ "c#", "design-patterns", ".net", "dependency-injection", "mvp" ], "Title": "MVP win forms application" }
49330
<p>I started to learn Rust last night. Given its parallelization capabilities, I thought a good starting point would be porting my C++ AI for <a href="http://gabrielecirulli.github.io/2048/" rel="noreferrer">2048</a> to Rust. </p> <p>This is the function implementing the shift of one line (from high to low indices) of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-03T01:32:22.663", "Id": "112398", "Score": "0", "body": "Where is `SCORE_MERGE_FACTOR`, and what type is it? `f32?`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-03T09:07:25.663", "Id": "112436", ...
[ { "body": "<h1>With both scoring and merging</h1>\n\n<p>Oops! I did indeed neglect to include merging. This is my mistake; I'm not a big fan of returning values via mutable parameters, so I think my brain shut off. Fortunately, while working on the merging logic, I made the scoring logic shorter.</p>\n\n<pre><c...
{ "AcceptedAnswerId": "74912", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T13:08:14.323", "Id": "49331", "Score": "37", "Tags": [ "game", "rust" ], "Title": "Shift and merge numbers as in 2048 game code" }
49331
<h2>Before you request a review</h2> <p>Review the guidelines created for the <a href="https://blog.rust-lang.org/2017/05/05/libz-blitz.html" rel="nofollow noreferrer">The Rust Libz Blitz</a> as well as the <a href="https://github.com/brson/rust-api-guidelines" rel="nofollow noreferrer">API guidelines</a> used. These ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T13:24:45.290", "Id": "49332", "Score": "0", "Tags": null, "Title": null }
49332
Rust is a systems programming language focused on three goals: safety, speed, and concurrency. It maintains these goals without needing a garbage collector, making it a useful language for a number of use cases other languages aren't good at: embedding in other languages, programs with specific space and time requireme...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T13:24:45.290", "Id": "49333", "Score": "0", "Tags": null, "Title": null }
49333
<p>I want to know the best way (best performance and reaction time) to insert all rows of an SQL table into a Google BigQuery table. Actually, I am looping over a query result and insert the rows one by one into the BigQuery table.</p> <p>The query <code>GetShippingList</code> returns all <code>TShipping_ID</code> of ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-05-09T13:59:58.820", "Id": "49335", "Score": "2", "Tags": [ "sql-server", "coldfusion", "cfml", "google-bigquery" ], "Title": "Insert all SQL Server table rows in a Google BigQuery ...
49335
<p>I'm currently working on a wind farm design software and basically I have to analyze the incidence of certain wind turbines on other downwind, in order to calculate the velocity drop in the wind once the downstream turbine "sees" the flow.</p> <p>I have sorted out most of the code and it works, yet this particular ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T15:31:53.703", "Id": "86751", "Score": "2", "body": "Well, what have you tried so far to make it faster? In general, I'd ask myself if Python is the right language for such a computationally intensive problem.." }, { "Conten...
[ { "body": "<p>I suspect <code>copy.deepcopy</code> is costing you much time; try to avoid it if possible.</p>\n\n<p>Also you are only copying <code>self.list_for_direction[wd]</code>, is it necessary to do it multiple time <code>for ws in wind_speed_index</code>?</p>\n\n<p>I try at my best to guess what you are...
{ "AcceptedAnswerId": "49662", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T14:30:36.410", "Id": "49339", "Score": "4", "Tags": [ "python", "performance" ], "Title": "Draft version of wind farm design software" }
49339
<p>This is a class for storing memory on the stack when possible or in <code>std::vector</code> when it grows too much.</p> <p><strong>Note:</strong> Using <code>std::vector</code> with custom stack allocator would be arguably better but I did not want to depend on 3<sup>rd</sup> party allocators (and could not find o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T18:11:14.020", "Id": "86793", "Score": "0", "body": "[Leading underscores are reserved](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier)." }, { "ContentLicense": "CC B...
[ { "body": "<h3>1. Leading underscores</h3>\n\n<p>As Jamal pointed out in the comments, using a leading <code>_</code> is dangerous, since it easily uses a reserved identifier (for example, when followed by a capital letter). I think the leading underscores are not a problem here, but I'd advise against using th...
{ "AcceptedAnswerId": "49410", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T14:41:15.593", "Id": "49340", "Score": "6", "Tags": [ "c++", "c++11" ], "Title": "Stack buffer class" }
49340
<p>I call several WebServices which return each a different exception type:</p> <pre><code>try { //calling first WS1 here } catch (my.package1.FaultWS_Exception e) { StringBuilder sb = getMessageFromException(e); log(sb); } try { //calling first WS2 here } catch (my.package2.FaultWS_Exception e)...
[]
[ { "body": "<p>Simply use one method for all type of Exceptions. </p>\n\n<p>Make it <code>public static</code> and move into a utility class.</p>\n\n<pre><code>public static StringBuilder getMessageFromException(Exception e){...}\n</code></pre>\n\n<p>Why do you need overloaded methods for different type of Excep...
{ "AcceptedAnswerId": "49363", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T21:20:29.153", "Id": "49342", "Score": "1", "Tags": [ "java" ], "Title": "Refactoring a function with different signature" }
49342
<p>I was having a hard time finding out how to make this any faster. I broke down the code that I am playing with into more methods than necessary to try and see where things could increase. Can anyone think of any good ideas? I am not opposed to using different data structures. </p> <p>The main idea is receiving an ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T02:21:43.477", "Id": "86760", "Score": "0", "body": "What are you trying to achieve here? \n\nFrom what I see here you're trying to get a new list containing as many non-conflicting activities as possible. Is that right?" }, { ...
[ { "body": "<p>For speed: ignore the length, sort by start time, and if the start time of the current task is before the end time of the previous task, skip it.</p>\n\n<p>If you need the sort-by-length idea, then review the if-statement in <code>conflict()</code>, it doesn't handle cases where an activity's end ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T01:28:48.587", "Id": "49344", "Score": "1", "Tags": [ "java", "algorithm", "sorting", "interval" ], "Title": "Activity by length" }
49344
<p>I have a 'speed problem' with a program im currently developing. I already have encountered the methods which costs some time.</p> <pre><code>public void ConvertDataFrameToValueFields() { List&lt;byte[]&gt; items = new List&lt;byte[]&gt;() { new byte[2], new byte[2], new byte[2], new byte[2] }; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T13:08:58.767", "Id": "86766", "Score": "2", "body": "[Check this out](http://stackoverflow.com/questions/1027980/improving-performance-reflection-what-alternatives-should-i-consider)" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>first of all reflection is expensive when used often. What you can do is</p>\n\n<ul>\n<li><p>cache the properties to set</p>\n\n<pre><code>Dictionary&lt;Type, IEnumerable&lt;PropertyInfo&gt;&gt; _propertiesCache\n</code></pre></li>\n<li><p>remove the copying over by creating the result immediatly ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T12:50:51.823", "Id": "49346", "Score": "4", "Tags": [ "c#", "performance", "reflection" ], "Title": "Speed problems with SetValue, ToType and Reflection" }
49346
<p>I want to simulate, in C++, the fact that in a form with drop down (or combo boxes), you can filter by selecting items and then projecting on a given set of properties for these item.</p> <p>In a SQL-like query it could be:</p> <pre><code>select age, name from (select * from table t where isoncodereview = true) w...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T15:17:30.047", "Id": "49348", "Score": "1", "Tags": [ "c++", "performance", "c++11", "simulation", "template-meta-programming" ], "Title": "Template container simulating S...
49348
<p>I have the following code I would like reviewed. I was recently tasked with sorting products coming from SOLR. The sorting is not by description or by the product number but rather by the below criteria. Normally I use linq to use grouping and sorting, but in this case I have existing (older code) and <em>my approac...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T15:45:28.217", "Id": "86774", "Score": "1", "body": "I notice you're using `ArrayList`. Is this because of .NET version limitations?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T15:47:16.557", ...
[ { "body": "<h1>CompareTo</h1>\n\n<p>This </p>\n\n<pre><code>public int CompareTo(ProductSortAttribute other)\n{\n if (this.Index == other.Index)\n {\n return 0;\n }\n\n if (this.Index &gt; other.Index)\n {\n return 1;\n }\n\n return -1;\n}\n</code></pre>\n\n<p>can be shorten...
{ "AcceptedAnswerId": "49352", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T15:39:15.483", "Id": "49350", "Score": "9", "Tags": [ "c#" ], "Title": "Dynamically sorting with IComparer" }
49350
<p>I wrote this script to backup some important files. It backs up the files to a local folder as well as to an external hard drive. It creates a new subdirectory which has its name constructed with the current date and time. Works perfectly, but I'm just wondering if there are any Python best-practices I'm missing ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-01-13T08:18:55.210", "Id": "216707", "Score": "0", "body": "Check out https://sourceforge.net/projects/pycompry/\nYou can schedule it with crontab and use it for multiple directories, instead writing more lines mentioning directories in t...
[ { "body": "<p>You can simplify paths using forward slashes:</p>\n\n<pre><code>GOOGLE_DRIVE_DIRECTORY = 'C:/Users/Jeff/Google Drive/Manifest_Destiny'\nMAIN_BACKUP_DIRECTORY = 'C:/Users/Jeff/Desktop/Manifest_Destiny_Backups/md_backup_{0}'\nEXTERNAL_DRIVE_DIRECTORY = 'F:/My Files/Manifest_Destiny_Backups/md_backup...
{ "AcceptedAnswerId": "49353", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T15:47:57.567", "Id": "49351", "Score": "17", "Tags": [ "python", "python-3.x", "file-system", "windows", "network-file-transfer" ], "Title": "Python Back-Up Script" }
49351
<p>After reading the SFML Game Development book, I decided to put what was learned to the test by creating a simple Breakout clone. I have posted the source code to GitHub: <a href="https://github.com/andrewd440/breakoutsfml" rel="nofollow">https://github.com/andrewd440/breakoutsfml</a></p> <p>I wanted to see if I cou...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T17:45:18.163", "Id": "49358", "Score": "2", "Tags": [ "c++", "game", "sfml" ], "Title": "Breakout-Clone built in SFML" }
49358
<p>I have a PRNG-Class called <code>Generator</code>. Now, after creating a new instance of it:</p> <pre><code>var g:Generator = new Generator(); </code></pre> <p><strong>Custom function: <code>set_seed()</code> - Please review this approach.</strong></p> <p>I call <code>g.set_seed();</code> which has the followin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T18:17:46.697", "Id": "86795", "Score": "0", "body": "What's the request here? It doesn't appear that you're seeking a code review." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T18:20:19.903", "...
[ { "body": "<p>I would expect the generator to seed itself (using the current time) in its constructor.</p>\n\n<p>Therefore, I would <strong>not</strong> use a default parameter in your <code>set_seed</code> method.</p>\n\n<p>Also, in your current code, you treat all the negative values the same as zero. I would...
{ "AcceptedAnswerId": "49361", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T18:15:39.840", "Id": "49360", "Score": "1", "Tags": [ "design-patterns", "random", "actionscript-3" ], "Title": "Seeding a PRNG - Custom Setter" }
49360
<p>Given a string find the number of meaningful words which could be formed from the string for eg. programmerit forms:</p> <blockquote> <pre><code>pro+gram+merit program+merit programmer+it pro+grammer+it </code></pre> </blockquote> <p>Looking for code review optimizations and best practices. Also hoping for sugges...
[]
[ { "body": "<p>I only have one minor objection for the moment...</p>\n<p>...</p>\n<p>...</p>\n<h1>Why are you not using dependency injection??</h1>\n<p>OK, it turned out to be a major one. (I did consider using caps-lock!)</p>\n<p>Consider a situation where you would want to do this operation for English words, ...
{ "AcceptedAnswerId": "49368", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T19:31:22.853", "Id": "49366", "Score": "6", "Tags": [ "java", "algorithm", "strings" ], "Title": "Find meaningful words from the input string" }
49366
<p>I have an imperative programming background and I've decided to study functional programming by applying it to problems found on sites such as Project Euler and Rosalind. My language of choice is Scheme (I use CHICKEN). As can be seen, I'm only starting out.</p> <p>This is about the 3rd problem found on Rosalind, t...
[]
[ { "body": "<p>You could use a dictionary/hash but for 4 choices it is overkill.</p>\n\n<p>In my opinion, <code>apply-compliments</code> is just the map over <code>compliment-of</code>. I would call the core function <code>reverse-compliment</code>. As an aside, if I read the problem description correctly you re...
{ "AcceptedAnswerId": "49611", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T20:10:49.360", "Id": "49369", "Score": "3", "Tags": [ "beginner", "scheme", "bioinformatics" ], "Title": "Rosalind's 3rd problem in Scheme" }
49369
<p>I'm wondering how I could compose this program better allow it to grow more functionality without constant refactoring.</p> <p>This is my code sample for Hacker School, so I'm less married to the results but instead am looking to further my understanding of Clojure and functional programming.</p> <p>Basically, my ...
[]
[ { "body": "<h3>Let the side effects happen and return nil</h3>\n<p>The way you have your <code>fight</code> function has the potential to throw an exception when you try to use it. Notice how you start with two opening parentheses, <code>((</code> -- this should stick out like a sore thumb to any Lisper, and it...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T20:37:36.870", "Id": "49371", "Score": "4", "Tags": [ "game", "functional-programming", "clojure" ], "Title": "Clojure function composition: logging results of an action performed...
49371
<p>I'm sure that among you <em>(users of codereview)</em> there are many who are interested in <a href="http://codeforces.com/" rel="nofollow">Codeforces</a> problemset. I tried to solve <a href="http://codeforces.com/problemset/problem/427/B" rel="nofollow">427B: Prison Transfer tasks</a> but have <code>Wrong Answer</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T21:14:59.797", "Id": "86818", "Score": "1", "body": "What is the input and expected output on the 4th test?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T21:19:49.587", "Id": "86819", "Score...
[ { "body": "<p>I can't help you with the wrong result your code produce, but I would strongly recommend separating the input/output logic from the computational logic.</p>\n\n<p>Your current method is defined as:</p>\n\n<pre><code>protected static void calcTransferCombinations() throws IOException {\n</code></pr...
{ "AcceptedAnswerId": "49373", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T20:54:29.807", "Id": "49372", "Score": "3", "Tags": [ "java", "algorithm" ], "Title": "Codeforces 427B: Prison Transfer" }
49372
<p>Please critique my solutions to these simple exercises. I have no programming experience, so the more anal you are, the more I'll learn. I'm teaching myself, this is not for school:</p> <blockquote> <p>Write a function <code>translate()</code> that will translate a text into "rövarspråket". That is, double ever...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T00:08:45.333", "Id": "86827", "Score": "5", "body": "Welcome to Code Review! I've upvoted your question (+5!), but I think you should break this down into multiple questions - not because of the length (even more than that is still ...
[ { "body": "<p>Here one way to sum a list of integers using ECMAScript 5's functional support</p>\n\n<pre><code>// Sum all values in a list by reducing the list to a single value\narray.reduce(function(prev, curr) {\n return prev + curr;\n});\n</code></pre>\n\n<p>Not faster than your approach due to the repeate...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T23:28:59.943", "Id": "49375", "Score": "5", "Tags": [ "javascript" ], "Title": "Various simple JavaScript solutions" }
49375
<p>I created this testimonial section as a prototype. </p> <p><img src="https://i.stack.imgur.com/6e8T1.png" alt="testimonial concept"></p> <p><strong>HTML</strong></p> <pre><code>&lt;div class="testimonials"&gt; &lt;blockquote&gt; &lt;p&gt;This was pretty good.&lt;/p&gt; &lt;cite&gt; &lt;span class=...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T06:14:08.103", "Id": "86838", "Score": "2", "body": "What is your question about CSS inheritance?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T17:32:29.727", "Id": "87155", "Score": "0", ...
[ { "body": "<p>Everything looks clean. However, I found some things though:</p>\n\n<ul>\n<li><p><code>font-size</code> - Make the units consistent. You use <code>px</code> and <code>em</code>. I suggest you go <code>em</code> all the way.</p></li>\n<li><p><code>background-size</code> - Well, it exists for that r...
{ "AcceptedAnswerId": "49442", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-09T23:35:16.547", "Id": "49376", "Score": "3", "Tags": [ "css", "html5" ], "Title": "Testimonial section CSS inheritance and proper use of HTML5 elements" }
49376
<p>I have recently started working on a server software in Java and wanted to add a configuration option to the program. I have gone through a few revisions of this class because I never liked what I came up with. I finally made something that I'm somewhat happy about and it works better than past versions. I'm just...
[]
[ { "body": "<p>So far it's looking quite good, but I have a few comments:</p>\n\n<p>Which file to load?</p>\n\n<pre><code>private static final File file = new File(\"config.yaml\");\n</code></pre>\n\n<p>In my opinion it would be better to pass the File to load in to the <em>constructor</em> of this <code>Config<...
{ "AcceptedAnswerId": "49392", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T01:53:52.390", "Id": "49382", "Score": "5", "Tags": [ "java", "yaml" ], "Title": "YAML Configuration file" }
49382
<p>I have written this Sudoku Generator. How good/bad is this? How can I improve this?</p> <pre><code>import java.util.Random; public class SudokuUtility { static final int max = 8; static final int min = 0; static final int digitMax = 9; static final int digitMin = 1; static final int easyMin ...
[]
[ { "body": "<h1>Enums</h1>\n\n<p>Your mins and maxes (and difficulties) are all over the place. Consider grouping them into an <code>enum</code> like this:</p>\n\n<pre><code>public enum Difficulty {\n EASY(36, 49),\n MEDIUM(32, 35),\n HARD(22, 27);\n\n private final int min;\n private final int ma...
{ "AcceptedAnswerId": "49391", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T02:48:01.763", "Id": "49383", "Score": "9", "Tags": [ "java", "algorithm", "sudoku" ], "Title": "Sudoku generator in Java" }
49383
<p>Given below is code which I wrote to provide an easy access to Facebook graph API.</p> <pre><code>import simplejson as json import urllib class Facebook (): def __init__ (self, access_token): self.access_token = access_token self.id = None self.name = None def user_information (self, fbuser = "me"):...
[]
[ { "body": "<pre><code>import urllib\n</code></pre>\n\n<p>You should take a look at <a href=\"https://pypi.python.org/pypi/requests/0.13.0\">Requests</a>, a much simpler, cleaner module which is becoming the defacto standard for doing this sort of stuff.</p>\n\n<pre><code>self.id = str(profile[\"id\"])\nself.nam...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T03:18:34.457", "Id": "49386", "Score": "1", "Tags": [ "python", "classes", "twitter", "facebook" ], "Title": "Classes for Facebook graph API and Twitter access" }
49386
<p>I am very (very) new to programming, and today I (semi-)successfully wrote my first program that performs very basic things.</p> <p>My hope is that I can receive some constructive criticism around how I structured it all and if I am doing things in the most efficient and proper way possible for what I am trying to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T06:46:11.820", "Id": "86840", "Score": "2", "body": "Will first fix the indentation. Its hard to read. Second get rid of multiple empty lines." } ]
[ { "body": "<ol>\n<li>Fix indentation (at any block, indent once)</li>\n<li>I like infinite <code>while</code> loops instead of infinite <code>for</code> loops (personal preference)</li>\n<li>I don't believe you need the <code>break</code>s, you can replace them with an <code>if</code>/<code>else</code> <code>if...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T06:17:57.753", "Id": "49390", "Score": "3", "Tags": [ "c++", "beginner", "calculator" ], "Title": "Common calculator, birth date calculator, units converter, and data recorder" }
49390
<p>I've implemented a (version of) Merge Sort algorithm in Python. My goal here is two-fold:</p> <ol> <li>Improve understanding of Merge Sort and recursion in a language agnostic way.</li> <li>Improve understanding of Python conventions and idioms.</li> </ol> <p>The implementation recursively splits the given sequenc...
[]
[ { "body": "<p>If you have any expression like the one below</p>\n\n<pre><code>if(x == 0) \n</code></pre>\n\n<p>then you can rewrite it as</p>\n\n<pre><code>if not x\n</code></pre>\n\n<p>You can get rid of parenthesis and can make it more pythonic by writing like this.</p>\n\n<p>Similarly you an rewrite :</p>\n\...
{ "AcceptedAnswerId": "49411", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T10:10:04.957", "Id": "49395", "Score": "4", "Tags": [ "python", "recursion", "sorting", "mergesort" ], "Title": "How might we make this Python Merge Sort implementation mor...
49395
<p>I have a multi-module Android project built by Gradle with the new Android-plugin 0.10+.</p> <p>All modules are mainly configured from the root project.</p> <p>I've enable the new code coverage feature. The major problem is that only some modules contain test code and when I enable code coverage on modules that do...
[]
[ { "body": "<p>Let's see what we have here:</p>\n\n<pre><code>sourceSets.androidTest.allJava.each {\n ...\n}\n</code></pre>\n\n<ul>\n<li><code>sourceSets</code> leads to <a href=\"https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/SourceSetContainer.html\" rel=\"nofollow\">SourceSetContainer</a></li...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T11:00:08.877", "Id": "49397", "Score": "2", "Tags": [ "beginner", "android", "groovy", "gradle" ], "Title": "Android Gradle script in multi-module project" }
49397
<p>Am I on the right lines for connecting to my Database? If not could somebody help me improve it or point me in the right direction?</p> <p>Index.php:</p> <pre><code>use Acme\Foo\Database\Connector; use Acme\Foo\Database\MySQLConnector; $obj = new Connector(new MySQLConnector); echo $obj-&gt;db-&gt;connect(); </co...
[]
[ { "body": "<p>This feels quite over-engineered to me, when i can do the work of all three classes in one line of code.</p>\n\n<pre><code>echo new PDO('mysql:host=localhost;dbname=test', 'root', 'root');\n</code></pre>\n\n<p>The big question to ask here is: <strong>What do you gain?</strong></p>\n\n<p>Every clas...
{ "AcceptedAnswerId": "49406", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T12:49:15.343", "Id": "49401", "Score": "3", "Tags": [ "php", "pdo" ], "Title": "Is coding to an interface with regards to PDO the right thing to do?" }
49401
<p>I have a PRNG-Algorithm:</p> <pre><code>/** * Generates an integer. Min: 0 | Max: total - 1 * @param total The number of possibilities. * @return The generated number.*/ public function generate_normal(total:int):int { _seed = (_seed * MULTIPLIER) % MODULUS; return (_seed * total / MODULUS); } </code></p...
[]
[ { "body": "<p>There is no one answer.</p>\n\n<p><strong>Performance</strong></p>\n\n<p>How often is <code>generate_normal</code> called? Is it called on a program critical path or only during set up? </p>\n\n<p>Could you cache a bunch of numbers before hand and only replenish the cache when you run out?</p>\n\n...
{ "AcceptedAnswerId": "49408", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T13:49:16.793", "Id": "49403", "Score": "0", "Tags": [ "performance", "design-patterns", "actionscript-3" ], "Title": "PRNG - Algorithm: Performance vs Readability" }
49403
<p>My little program I'm working on generates charts (GUI) and (on another tab) lists the values my chart is fed from.</p> <pre><code>2011.01.01 0:00:00 456 2011.01.02 0:00:00 45 2011.01.03 0:00:00 46 2011.01.04 0:00:00 6 2011.01.05 0:00:00 1500 ... </code></pre> <p>When I click on the "Generate C...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T03:01:27.437", "Id": "86945", "Score": "0", "body": "I'm wondering if a simple List<string> to hold the data and IO.File.WriteAllLines to export it, would be just as efficient and a lot simpler to implement." }, { "ContentLi...
[ { "body": "<p>It looks like you are wasting your efforts on premature optimization. Which also results in a quite ugly code.</p>\n\n<p>I think you should separate your grid-filling logic from csv export. There should be no memory streams, steam writers, etc. in your first method. Also notice that you have code ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T14:12:44.240", "Id": "49404", "Score": "4", "Tags": [ "c#", "optimization", "memory-management", "stream" ], "Title": "Handling of memorystream with streamwriter efficiency" }
49404
<pre><code>class InvitationConfirmationValidator &lt; ActiveModel::Validator def validate(record) invitation = Invitation.find_by_url_suffix(record.id) if invitation if invitation.materialized? record.erros.clear record.errors[:base] &lt;&lt; "Invitation already materialized" end ...
[]
[ { "body": "<p>The first thing I would do is assign those strings to constants since they will never change throughout the life of the program.\nAlso, I'm not sure why you have to clear the errors out when you validate this part of the model. When I run <code>valid?</code> on a model, personally I would like to ...
{ "AcceptedAnswerId": "49412", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T14:16:43.297", "Id": "49405", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Invitation confirmation validator" }
49405
<p>I was asked to provide some example code for a job interview and didn't have anything to offer, so wrote the following function.</p> <p>A barcode generator may seem a bit basic, but there's some logic behind the choice:</p> <ul> <li>It's something I recently needed, so not entirely contrived.</li> <li>It's simple en...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T16:53:48.147", "Id": "87149", "Score": "2", "body": "I've removed the updated code from the question. Reviewing an additional code revision is not encouraged as it could make the review process (within the question itself) confusin...
[ { "body": "<p>The code generally looks pretty good, but I think there are some things you could fix up here.</p>\n\n<h2>Don't forget the stop code</h2>\n\n<p>You have the start code of <code>0000</code> but you've forgotten the stop code which is <code>100</code>. When you calculate, you could just tack it ont...
{ "AcceptedAnswerId": "49436", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-05-10T14:46:27.403", "Id": "49409", "Score": "5", "Tags": [ "python", "interview-questions", "converting" ], "Title": "Python Barcode Generator" }
49409
<p>I just finished <a href="http://projecteuler.net/problem=39" rel="nofollow">Project Euler 39</a>:</p> <blockquote> <p>If <em>p</em> is the perimeter of a right angle triangle with integral length sides, {<em>a</em>, <em>b</em>, <em>c</em>} … For which value of <em>p</em> ≤ 1000, is the number of solutions maximis...
[]
[ { "body": "<ul>\n<li>You are using a dictionary <code>data = {\"most\": 0, \"num\": 0}</code> where you could just as well use local variables. The locals would be more readable and faster.</li>\n<li><p>The built-in <code>max</code> function is convenient when looking for a maximum. You could write <code>find_m...
{ "AcceptedAnswerId": "49430", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T16:36:35.683", "Id": "49413", "Score": "3", "Tags": [ "python", "optimization", "programming-challenge", "python-2.x" ], "Title": "Project Euler 39: Integer right triangles...
49413
<p>I've been teaching myself programming in Python for about three months now using How To Think Like a Computer Scientist and a bit of the internet with the intention of being able to create video games someday (nothing huge, but something/stuff worth playing). What I'm looking for is an assessment on how I'm doing an...
[]
[ { "body": "<p>The most obvious thing you are missing is any use of Python's various container types, relying instead on too many individual variables. Two examples spring immediately to mind, using the most common containers: <a href=\"https://docs.python.org/2/library/stdtypes.html#sequence-types-str-unicode-l...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T16:42:40.793", "Id": "49415", "Score": "4", "Tags": [ "python", "beginner", "adventure-game" ], "Title": "A small text adventure in Python" }
49415
<p>Is this a good approach of designing a class or is there some other way that I am not aware of?</p> <p><strong>Student.h</strong> specification file</p> <pre><code>#ifndef STUDENT_H #define STUDENT_H #include &lt;string&gt; using namespace std; class Student { private: int ID; string name; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-05-16T08:22:16.337", "Id": "240196", "Score": "0", "body": "I think you should add '_' before your private members to help recognizing which member can be accessed publicly and which can not." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<h1>Student.cpp</h1>\n<p><strong>Initializer lists</strong></p>\n<p>You should use initializer lists in place of these constructors. They offer some advantages, such as being able to initialize <code>const</code> members. Normal constructors do not allow that.</p>\n<p>The initializer list is in thi...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T16:43:56.723", "Id": "49416", "Score": "13", "Tags": [ "c++", "classes" ], "Title": "C++ Student Class" }
49416
<p>I did this project last year, under some interesting constraints: it's a thin webserver which lives in a Raspberry Pi, which is networked to an embedded system in an industrial sign which is running a proprietary and heavily modified version of *nix. I didn't touch the embedded system in the sign at all. </p> <p>Th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T19:09:42.253", "Id": "87032", "Score": "0", "body": "I can't comment on the code, but a full Rails stack with Webrick runs fine on RP with no modification." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05...
[ { "body": "<p>Seems reasonable given your tools at hand and the constraints.</p>\n\n<p>Next time you want to programmatically drive SSH look into <a href=\"http://www.fabfile.org/\" rel=\"nofollow\">http://www.fabfile.org/</a>. It uses paramiko internally and makes all of the complexities much nicer.</p>\n", ...
{ "AcceptedAnswerId": "49579", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T17:07:37.343", "Id": "49417", "Score": "3", "Tags": [ "python", "web-services", "embedded", "raspberry-pi" ], "Title": "Small, embedded full-stack web server" }
49417
<p>How can I improve my code below for the following question? While it works, I am not satisfied with how it looks; I was hoping I can somehow keep it recursive, and have the ans filled up inside the function, and reduce the number of return statements that I have. Treat this like an interview problem.</p> <p>Worst...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T23:31:22.047", "Id": "86928", "Score": "2", "body": "Are all four inputs guaranteed to be non-negative?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T06:26:10.543", "Id": "86959", "Score": "...
[ { "body": "<h2>Making it pure recursive</h2>\n\n<p>It's fairly straightforward to turn your implementation into pure recursive:</p>\n\n<pre><code>public boolean ablehelper(int a, int b, int c, int d) {\n if (a != c &amp;&amp; (b + a) &gt; c) {\n return false;\n }\n if (b != d &amp;&amp; (b + a) ...
{ "AcceptedAnswerId": "49441", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T17:12:28.333", "Id": "49418", "Score": "22", "Tags": [ "java", "interview-questions" ], "Title": "Determining if an answer can be generated" }
49418
<p>This is a follow-up <a href="https://codereview.stackexchange.com/questions/49386/python-class-for-facebook">post</a></p> <p>I have taken some of the suggestions there and have made some changes from my side too. I think it looks better, but please look at it and lemme know if you think any more changes needs to be...
[]
[ { "body": "<p>Better! I can point out mostly style issues:</p>\n\n<p>I would drop intermediate variables in simple statements like this:</p>\n\n<blockquote>\n<pre><code>try:\n response = self.urlRead(url)\n return response\n</code></pre>\n</blockquote>\n\n<p>and do simply:</p>\n\n<pre><code>try:\n retu...
{ "AcceptedAnswerId": "49424", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T17:22:10.200", "Id": "49419", "Score": "1", "Tags": [ "python", "object-oriented", "facebook" ], "Title": "Follow up: Python class for Facebook" }
49419
<p>I'm writing three functions which iterate over lists, I want do this recursively, but I think this code is not as efficient as it could be.</p> <pre><code>def flatten(lst): if type(lst)==int: return [lst] elif lst==[]: return lst else: return sum([flatten(sub) for sub in lst], [...
[]
[ { "body": "<p>The flatten function will not handle any element other than integer or list. A better and simpler way of handling it is using a predefined function flatten.</p>\n\n<pre><code>import compiler.ast as cmp\nflatten = cmp.flatten\n\n&gt;&gt;&gt; flatten([1,2,[3,[4]]])\n&gt;&gt;&gt; [1,2,3,4]\n</code></...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T17:25:03.073", "Id": "49421", "Score": "3", "Tags": [ "python", "optimization", "recursion" ], "Title": "Optimizing a recursion code over lists" }
49421
<p>I'm trying to make a program that will shutdown my computer after a certain time that I will input via GUI. I'm wondering if I did it the correct way.</p> <p>Also, will this slow down my computer while it waits to shut off? Do you see anything wrong with the code?</p> <pre><code>import java.io.IOException; import ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T20:06:18.420", "Id": "86890", "Score": "3", "body": "Frankly, you're using the wrong language for this. It's trivial to do from a shell script, or even from the command line, neither of which requires wasting a thread. Hint: `at ...
[ { "body": "<p>Your questions at the end are the most important points here, so I answer those first:</p>\n\n<blockquote>\n <p>but will any of these operations harm my computer in any way?</p>\n</blockquote>\n\n<p>No, and how could it anyway?</p>\n\n<blockquote>\n <p>Will it be better if I just learn to do thi...
{ "AcceptedAnswerId": "49435", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T18:40:43.690", "Id": "49428", "Score": "7", "Tags": [ "java", "multithreading", "thread-safety", "timer" ], "Title": "Program to shutdown computer after a certain time" }
49428
<p>Some telephone operators have submitted their price lists including price per minute for different phone number prefixes.</p> <p>Some test data, 2 price lists, look like this:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>Operator A: 1 0.9 268 5.1 46 0.17 4620 0.0 468 0.15 4631 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T19:11:22.423", "Id": "86884", "Score": "3", "body": "Can you give an example of inputs and expected outputs? I find your question quite confusing" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T19:55:...
[ { "body": "<p>If I understand what you're looking for correctly, it's the cheapest rate for a particular phone number. </p>\n\n<p>If you already have the rates of each operator as a <em>dictionary</em> of key/value pairs, then you don't need a regex at all. The following code finds the cheapest rate in a set of...
{ "AcceptedAnswerId": "49450", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T18:44:05.407", "Id": "49429", "Score": "-1", "Tags": [ "python", "http" ], "Title": "Finding the lowest decimal number for a given integer" }
49429
<p>I'm writing a Python script to randomly generate C functions. This is my first time using classes in Python and I'm basically doing my best to pretend I'm using Java.</p> <p>I'm looking for a review of my OOP, Python style, and in general whether or not I'm doing things in the "Pythonic" way, whatever that means.</...
[]
[ { "body": "<p>In class <strong>Output</strong>:</p>\n\n<pre><code>def output(self, str):\n # start each line with tabs equal to nesting level \n if(self.__lineStart == True):\n for q in range(0, self.nestingLevel):\n self.__write('\\t')\n self.__lineStart = False\n\n self....
{ "AcceptedAnswerId": "49648", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T19:26:36.147", "Id": "49432", "Score": "5", "Tags": [ "python", "object-oriented", "random" ], "Title": "Python script for generating random C code" }
49432
<p>I'm unsure about how to simplify this method properly. The method is basically responsible to allocate data.</p> <p>The response object is a collection of objects. Each object contains an attribute called <code>order</code> and i have to distinguish between visible and invisible elements. Visible elements are repre...
[]
[ { "body": "<p>The only thing that stands out a bit is the fact that you do 2 very similar <code>angular.forEach()</code> calls. You could extract these functions out and do only 1 call. I would also make <code>-1</code> a named constant. I would also declare all variables on top.</p>\n\n<p>What you could consid...
{ "AcceptedAnswerId": "49539", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T19:26:41.040", "Id": "49433", "Score": "2", "Tags": [ "javascript", "design-patterns", "angular.js" ], "Title": "Filling two angular $scope variables with data" }
49433
<p>I wanted to get some feedback on this JS I am working on. It works wonderfully on my desktop, but on my and my friends' laptops (especially Safari) it is very slow. I need some pointers on improving the efficiency so it works nicely across browsers/computers.</p> <p><a href="http://www.dapper-apps.com" rel="nofollo...
[]
[ { "body": "<p>One thing I thought of is having a \"static\" interval rather than an individual timeout per element.\nWhat other things could I improve?\nI feel like i should definitely be getting better performance, especially in safari.\nIt's painful to watch there.</p>\n\n<p>Some thoughts: Is there a way to m...
{ "AcceptedAnswerId": "49616", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T21:05:35.190", "Id": "49437", "Score": "5", "Tags": [ "javascript", "optimization", "portability", "parallax" ], "Title": "JavaScript parallax cross-platform efficiency" }
49437
<p>This code's sole purpose is to create a very random password, using letters and numbers. </p> <p>I think that it fulfills its purpose, but I wonder, could it be done better? I'm not talking about efficiency, but security.</p> <p>In your eyes, how secure is this method for generating passwords, and if it is barely ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T22:34:21.543", "Id": "86918", "Score": "0", "body": "Depends in large part on the quality of the PRNG `random` implements, i imagine." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T22:37:09.370", ...
[ { "body": "<p>Copy&amp;pasting code multiple times does not make it more secure. If we clean up your <code>mutate_seed</code> method, we'd end up with this:</p>\n\n<pre><code>def mutate_seed(self):\n for x in range(self.seed):\n number_or_letter = r.randint(0, 1)\n if number_or_letter:\n ...
{ "AcceptedAnswerId": "49443", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T21:27:50.127", "Id": "49438", "Score": "7", "Tags": [ "python", "random", "python-2.x", "windows" ], "Title": "How random is this password-generating algorithm?" }
49438
<p>Here is a class vector in python 3, for n-dimmensional vectors. Please suggest ways to improve the code as well as fix bugs and errors.</p> <p><strong><em>The only rule is not using: numpy, sympy, scipy and so on. Only math, cmath, Rational, Decimal, ... Python 3 default packages.</em></strong>.</p> <p>This code i...
[]
[ { "body": "<p>Subclassing <code>tuple</code> makes Python treat your <code>Vector</code> objects as immutable. As such they should not have any mutable state and hence no <code>__init__</code> method. Do all initialization in <code>__new__</code> instead:</p>\n\n<pre><code>def __new__(cls, *V):\n if not V:\n...
{ "AcceptedAnswerId": "49457", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T06:59:24.823", "Id": "49454", "Score": "5", "Tags": [ "python", "python-3.x", "computational-geometry" ], "Title": "Class Vector with Python 3" }
49454
<p>I'm trying to learn proper C++ and algorithms at the same time. </p> <p>I particularly feel weird about my iterators usage in <code>merge</code> function. Is this a good way to handle it? I've modeled the signature after the STL <code>std::merge</code> method in <code>&lt;algorithm&gt;</code>.</p> <p>I've tagged i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T14:54:42.883", "Id": "87011", "Score": "1", "body": "One thing I noticed. You're treating the collection as one and breaking it down to it's smallest parts then doing the merge. If you treat the collection as elements and start me...
[ { "body": "<p>Looks good.</p>\n\n<p>Couple of things I would do differently (not that your way is wrong).</p>\n\n<p>Rather than pass references to the containers around I would pass iterators into the containers. This allows your sort algorithm to be container agnostic:</p>\n\n<pre><code>void merge_sort(std::ve...
{ "AcceptedAnswerId": "49479", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T10:22:24.730", "Id": "49459", "Score": "8", "Tags": [ "c++", "algorithm", "c++11", "sorting", "mergesort" ], "Title": "Merge sort algorithm implementation using C++" }
49459
<p>I want to improve this code to make it look more professional, be loaded quicker and make it cross-browser compatible. Do note that it is not a finished site. I want to know the best practice for doing certain things before I proceed any further.</p> <p><strong>HTML:</strong></p> <pre><code>&lt;!DOCTYPE html&gt; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T13:55:46.777", "Id": "86996", "Score": "3", "body": "Please don't make modifications to the supplied code based on the reviewer's suggestions, as it invalidates their answers." }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>You can start by:</p>\n\n<ul>\n<li>Standardize indentation. Use 4 spaces, each child element/new scope goes one indent.</li>\n<li>Limit newlines to at most 3. Don't leave too much blank lines.</li>\n<li><p>Chain if possible. Usually jQuery functions return the same object. In this case, we apply <...
{ "AcceptedAnswerId": "49463", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T11:11:20.590", "Id": "49460", "Score": "3", "Tags": [ "javascript", "html", "css" ], "Title": "Guild Wars: Knights & Dragons" }
49460
<p>The function below simple allows a logged in user to "star" another user for convenience when trying to find the that user another time. At the moment the function works as it should, it inserts the user giving the star and the user receiving the star into a database table, then grabs the first name and email from t...
[]
[ { "body": "<ul>\n<li>Lock the UI until a response comes back (or a reasonable timeout\noccurs) to prevent the multiple clicking.</li>\n<li>Don't send emails directly from the code, push them to spool or MQ and process separately</li>\n</ul>\n\n<p>As for the code itself - there's nothing much to comment except t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T11:33:22.410", "Id": "49461", "Score": "0", "Tags": [ "php", "mysql", "pdo", "email" ], "Title": "Add user star function triggering PHPmailer email optimisation" }
49461
<p>I've made a simple drawer using CSS3 and jQuery that works with hover and click. It seems to be working fine but surely there's a simpler way of writing the code.</p> <p><strong>Fiddle</strong>: <a href="http://jsfiddle.net/73MpU/" rel="nofollow">http://jsfiddle.net/73MpU/</a></p> <pre><code>$("#bottom-page").clic...
[]
[ { "body": "<p>You could try to group the <code>toggleClass</code> inside one <code>.hover</code>, like this: </p>\n\n<pre><code>var $top=$(\"#top-page\"); //save #top-page in $top var\n\n$(\"#bottom-page\").click(function () {\n $top.addClass(\"push\");\n}).hover(function(){ //c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T11:59:37.837", "Id": "49466", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "A simple drawer using CSS3 and jQuery" }
49466
<p>I'm currently working on a PHP component: "Filesystem handler". I've run into a problem where I want to call one exact method in both dynamic and static ways.</p> <p>I've ended up with this solution. Could you please give me a feedback ? I want to know, if there is a better or a simpler way to achieve the same resu...
[]
[ { "body": "<p>The first thing you should now is that magic methods are slow <code>__call</code> and <code>__callStatic</code>, that is. The second thing I'd like to point out is that, given that you declared the method as static, you should always call it as such. Failing to do so is just going to leave you wit...
{ "AcceptedAnswerId": "49473", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T12:34:08.720", "Id": "49468", "Score": "2", "Tags": [ "php", "object-oriented" ], "Title": "Calling one method both dynamically and statically" }
49468
<p>I wrote <a href="https://github.com/abitdodgy/words_counted">a Ruby gem</a> to analyse strings for word length, word density, and a few more hand methods...</p> <p>The <code>Counter</code> class accepts a filter (String). The class will remove any words from the original string that you include in the filter. Spec:...
[]
[ { "body": "<p>Since you call <code>filter</code> within each element in your word array, there is no point in each time building a <code>Proc</code> object and returning it - it would be easier to simply return whether the word should be rejected or not:</p>\n\n<pre><code>def initialize(string, options = {})\n ...
{ "AcceptedAnswerId": "49476", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T14:06:31.363", "Id": "49469", "Score": "6", "Tags": [ "ruby" ], "Title": "Correct use of procs in Ruby" }
49469
<p>I have the following Prolog code which samples n items from a list without replacement:</p> <pre><code>samp(0,_,Sample,Sample). samp(N,Domain0, Sample0, Sample):- N &gt;= 0, length(Domain0,L), RandomNumber is random(L), nth0(RandomNumber, Domain0, X), delete(Domain0,X,Domain1), append(Samp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T15:49:29.007", "Id": "87018", "Score": "1", "body": "Welcome to Code Review, thanks for understanding exactly what this site is about. As a thank you, I just helped making sure that you got the Association Bonus in the Stack Exchang...
[ { "body": "<p>In SWI-Prolog you could do this that way:</p>\n\n<pre><code>sample_swi(Domain, N, Sample) :-\n random_permutation(Domain, Permutation),\n length(Sample, N),\n append(Sample, _, Permutation).\n</code></pre>\n\n<p>Be careful, this predicate is not a true relation (just as in your code).</p>...
{ "AcceptedAnswerId": "49535", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T14:49:53.543", "Id": "49471", "Score": "6", "Tags": [ "prolog" ], "Title": "Sample n items without replacement in Prolog" }
49471
<p>Can you suggest ways of making this more efficient? I don't want to repeat this example for all of my tags that need a class added, if there is a better way. </p> <pre><code>$("#menu").find("div:nth-child(2), div:nth-child(3), div:nth-child(4), div:nth-child(5), div:nth-child(6), div:nth-child(7)").addClass("menuD...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T17:44:30.067", "Id": "87025", "Score": "0", "body": "Are there divs after the 7th that you don't want the class added to?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T17:45:29.053", "Id": "8702...
[ { "body": "<p>It's slow for the following reasons:</p>\n\n<ul>\n<li><p>You're using <a href=\"https://api.jquery.com/find/\" rel=\"nofollow\"><code>find()</code></a> which is a descendant lookup. jQuery will look for all descendants under an element and see if it's a match. If the DOM under that element is huge...
{ "AcceptedAnswerId": "49495", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T16:04:43.017", "Id": "49475", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Does this class-adding slow page rendering?" }
49475
<p>I did this code over one day as a part of a job application, where they wanted me to make a minimal webcrawler in any language. The purpose was to crawl a site, find all of the URLs on that page, and crawl on to other pages. The code had to be able to resume operation if shut down (that's why I saved the lists to te...
[]
[ { "body": "<pre><code>import urllib\nimport re\nimport os\n\n# The parameter is the url the crawler is gonna crawl.\n</code></pre>\n\n<p>That's a pretty useless comment. The parameter is named <code>url</code>. So I already know it is the URL.</p>\n\n<pre><code>def crawler(url):\n</code></pre>\n\n<p>Seeing as ...
{ "AcceptedAnswerId": "49483", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T20:16:00.707", "Id": "49480", "Score": "12", "Tags": [ "python", "web-scraping" ], "Title": "Minimal webcrawler - bad structure and error handling?" }
49480
<p>I'm looking to get some feedback on this program I wrote - ways I could make it simpler or best practices methods.</p> <p><a href="https://pine.fm/LearnToProgram/?Chapter=07" rel="nofollow noreferrer">Chapter 7:</a></p> <blockquote> <p>Let's write a program which asks us to type in as many words as we want (one word...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T05:14:35.230", "Id": "87053", "Score": "2", "body": "Ruby prefers snake_case over camelCase for variable names. That's all I see. Is the program's I/O dictated by the requirement, or can it be changed? I ask because the program c...
[ { "body": "<ol>\n<li><p>As Wayne Conrad pointed out in the comments, you should really use <code>snake_case</code> in Ruby. I'd also just call the array <code>words</code> instead of <code>input_array</code>. While <code>input_array</code> describes what sort of variable it is, it doesn't describe its content, ...
{ "AcceptedAnswerId": "49529", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T22:28:56.050", "Id": "49482", "Score": "6", "Tags": [ "ruby", "sorting" ], "Title": "Sorting an array in alphabetical order" }
49482
<p>Please review and suggest improvements for my <code>isPrefixOf</code> implementation.</p> <pre><code>isPrefixOf' :: (Eq a) =&gt; [a] -&gt; [a] -&gt; Bool isPrefixOf' [] _ = False isPrefixOf' _ [] = False isPrefixOf' (x:xs) (y:ys) | null xs &amp;&amp; x == y = True | x == y = isPrefixOf' xs ys | ot...
[]
[ { "body": "<p>That is very idiomatic Haskell code. The only thing I'd mention is that the empty list <em>is</em> a prefix of everything, so your first case should be</p>\n\n<pre><code>isPrefixOf' [] _ = True\n</code></pre>\n\n<p>With that change, you can remove</p>\n\n<pre><code> | null xs &amp;&amp; x == y = ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T00:14:54.397", "Id": "49485", "Score": "1", "Tags": [ "haskell", "reinventing-the-wheel" ], "Title": "isPrefixOf & isSuffixOf" }
49485
<p>Learn You a Haskell mentions the <code>partition</code> function:</p> <blockquote> <p>partition takes a list and a predicate and returns a pair of lists. The first list in the result contains all the elements that satisfy the predicate, the second contains all the ones that don't.</p> </blockquote> <p>How's ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T11:21:11.720", "Id": "87081", "Score": "1", "body": "Your current version is not equivalent to the `partition` of `Data.List`. `take 10 $ fst $ partition' (\\x -> (x \\`mod\\` 2 == 0)) [1..]` gives a runtime error. Where as `take 10...
[ { "body": "<p>Why not just use filter -- unless you are trying to avoid using filter? Filter would remove the need for <code>++</code>. </p>\n\n<p>Check out <a href=\"https://stackoverflow.com/questions/8712208/how-do-i-use-the-filter-function-in-haskell\">this SO question</a>.</p>\n", "comments": [], ...
{ "AcceptedAnswerId": "49508", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T00:42:54.023", "Id": "49488", "Score": "1", "Tags": [ "haskell", "reinventing-the-wheel" ], "Title": "Haskell's `partition`" }
49488
<p>For a form I got the markup below, it belongs to an input category and as there can be more than one insertion at it I includded an <kbd>Añadir</kbd> button (Add).</p> <p>I give <code>id="posgrado1"</code> to first <code>div</code> and using Java Script I increment the <code>id</code>'s to <code>posgrado2</code>, <...
[]
[ { "body": "<p>A better way is to use templates. <a href=\"http://handlebarsjs.com/\" rel=\"nofollow\">Handlebars</a> should be a good start for this.</p>\n\n<p><a href=\"http://jsbin.com/gecuface/1/edit\" rel=\"nofollow\">Here's a quick demo</a>:</p>\n\n<p>HTML:</p>\n\n<pre><code>&lt;!-- our target --&gt;\n&lt;...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T03:22:21.460", "Id": "49490", "Score": "1", "Tags": [ "javascript", "jquery", "html" ], "Title": "How to automatically insert HTML to a form and obtain the inputs?" }
49490
<p>I just have a small question. The code I wrote works well for the problem. But is it the best way, or can we make it better?</p> <pre><code>struct node * swapAdjacent(struct node * list) { struct node * temp,*curr,*nextNode; temp = list; curr = temp-&gt;next; if(curr == NULL) return temp; next...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T05:34:28.393", "Id": "87054", "Score": "0", "body": "I might pick a slightly more specific name. Like, say, `swapWithNext`." } ]
[ { "body": "<ul>\n<li><p>Consider having <code>swapAdjacent(NULL)</code> return <code>NULL</code>. Once it does, you can get rid of the whole <code>if (nextNode == NULL)</code> statement, and just unconditionally say <code>temp-&gt;next = swapAdjacent(nextNode);</code>.</p></li>\n<li><p>You might want to use a ...
{ "AcceptedAnswerId": "49498", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T04:35:30.873", "Id": "49491", "Score": "2", "Tags": [ "c", "linked-list" ], "Title": "Swapping adjacent nodes of a linked list" }
49491
<p>I wanted to play with value types for <a href="https://codereview.meta.stackexchange.com/a/1608/23788">Simon's challenge</a>; I came up with this quick-and-dirty, basic implementation of a card-fighting game:</p> <p>I started with a value type to hold <em>assets</em> - I'd reuse that type for player status, card co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-14T01:00:37.990", "Id": "87426", "Score": "1", "body": "`IsDead` should be calculated dynamically. No setter. It should be determined solely on internal state. You can ask me if I'm dead, but you can't tell me." }, { "ContentLi...
[ { "body": "<p>Not going to review this code just yet, but I've found a funny bug, by adding a 3rd player:</p>\n\n<pre><code>static void Main(string[] args)\n{\n var game = new Game();\n var players = new[] \n { \n new ConsolePlayer(\"Player1\", Game.StartAssets), \n ...
{ "AcceptedAnswerId": "49698", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T04:50:53.690", "Id": "49492", "Score": "11", "Tags": [ "c#", "game", "community-challenge", "role-playing-game" ], "Title": "Simplistic (dumb) Card Fighter" }
49492
<p>I have following stored procedure in a C# win forms application which calculates employee earnings based on attendance as follows. </p> <p>Note that a shift is 12 hours and employees mark attendance for in and out of each shifts. Also salary period is from beginning to end of a month (1<sup>st</sup> to 28<sup>st</s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-23T21:44:53.567", "Id": "89134", "Score": "2", "body": "It looks well made. I do think a procedure is suitable for this. Nothing really jumps at me other than the large number of `CONVERT()` functions. Guessing your source columns are ...
[ { "body": "<p>Here are my thoughts on your proc. </p>\n\n<p><strong>The Good</strong></p>\n\n<p>Good job on commenting out sections that are not so obvious to figure out. I had very little difficulty understanding it, your code is much cleaner than the average SQL post on this site. I would say a stored procedu...
{ "AcceptedAnswerId": "54530", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T06:29:49.850", "Id": "49496", "Score": "3", "Tags": [ "performance", "sql", "sql-server", "stored-procedure" ], "Title": "Stored Procedure calculating employee earnings" }
49496
<p>In a C# win forms payroll application I need to calculate employee salary based on their attendance. I've written a stored procedure which calculates earnings of all employees from the data available in attendance table. So when the application calls the SP the data will be shown on a data grid view and then immedia...
[]
[ { "body": "<p><strong>General point</strong><br/>\nIs there a strong reason for going with MVP? One of the downsides of an MVP approach is that a lot of the nice data-binding facilities within the architecture get bypassed. A <em>Presentation Model / Model-View-ViewModel (MVVM)</em> approach is pushed for WPF...
{ "AcceptedAnswerId": "49620", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T08:03:46.833", "Id": "49499", "Score": "5", "Tags": [ "c#", "object-oriented", "winforms", "mvp" ], "Title": "Calculating Earnings from attendance details" }
49499
<p>I have a need to process URIs in one of my applications, sometimes from <code>const char[]</code> literals.</p> <p>My API:</p> <pre><code>namespace net { class uri { ... }; // contains decomposed URI (path, parameters, etc) uri parse_uri(const std::string&amp; uri_str); // parse string and return uri inst...
[]
[ { "body": "<p>I would follow the way user-defined literals are used <a href=\"http://en.cppreference.com/w/cpp/string/basic_string/operator%22%22s\">in the C++14 standard library</a>: put them in a <code>literals</code> subnamespace that can be imported by the user. This subnamespace would be <code>inline</code...
{ "AcceptedAnswerId": "49504", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T09:05:34.667", "Id": "49502", "Score": "9", "Tags": [ "c++", "strings", "c++11", "namespaces" ], "Title": "User defined string literals and namespace use" }
49502
<p>The code is implemented to perform HTTP get with HTTP proxy. </p> <p>Future object is adopted to avoid blocking in current thread.</p> <p>I'm not quite sure about the usage of HTTP connection pooling manager and the way using Future obj to avoid blocking looks ugly.</p> <p>Can somebody review this?</p> <pre><co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T10:31:58.420", "Id": "87076", "Score": "1", "body": "what java version do you use?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T10:33:40.743", "Id": "87077", "Score": "0", "body": "java...
[ { "body": "<blockquote>\n<pre><code> @SuppressWarnings(\"deprecation\")\n</code></pre>\n</blockquote>\n\n<p>This is a big no from me. Deprecation is something that is there for a reason, I rarely advocate for comments but this would be a good opportunity to do so. If there is a good reason to use a deprecated f...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T10:20:22.500", "Id": "49506", "Score": "6", "Tags": [ "java", "http", "proxy" ], "Title": "HTTP Get with proxy" }
49506
<p>I used Nokogiri and a piece of ActiveSupport to parse an xml file from a given URL, format the data properly and return a JSON string. The script works as expected, so I'm only wondering if there are ways to make the code better from architecture/naming perspectives.</p> <pre><code>#!/usr/bin/env ruby $:.unshift F...
[]
[ { "body": "<p>It all seems really nice, I would change few things:</p>\n\n<p>Firstly, your <code>format_event_time</code> takes a node object as a param, which is counter-intuitive as I would expect it to accept Time object. I would rename it to 'parse_xml_date` or similar and give it text instead:</p>\n\n<pre>...
{ "AcceptedAnswerId": "49515", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T11:33:20.483", "Id": "49512", "Score": "6", "Tags": [ "object-oriented", "ruby", "parsing" ], "Title": "Refactor an XML to JSON parser class" }
49512
<p>I would like to find out if following usage of an <code>AtomicBoolean</code> as a flag variable is correct and good for a multi-threaded application. It is expected that data is going to be loaded only once and when the application is at very low load. It is also expected that the list of SomeObjects is going to be ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T12:06:39.863", "Id": "87091", "Score": "0", "body": "It's a quite interesting question you have here, could you provide some description or code about what the `replaceAll` method does? I imagine that the answer can be a bit differe...
[ { "body": "<p>I used to do that by checking the collection for null and initializing only if it is null otherwise returning the collection. Such bloc should be synchronized, of course:</p>\n\n<pre><code>synchronized (this) {\n if (someObjects == null) {\n someObjects = ...//initialize\n }\n return someObj...
{ "AcceptedAnswerId": "49574", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T11:53:58.607", "Id": "49514", "Score": "6", "Tags": [ "java", "multithreading" ], "Title": "Usage of AtomicBoolean" }
49514
<ul> <li>Is it a bad idea to use the <code>notfound</code> callback like this? If so, why not? (bad scope/closure? I'm a noob node.js dev.)</li> <li>Is it a bad idea to use the <code>saveCallback</code> callback like this? I have a feeling it's dangerous, but I don't want to declare <code>saveCallback</code> before <co...
[]
[ { "body": "<p>Interesting question,</p>\n\n<p>I would go with this:</p>\n\n<pre><code>create: function (registerDetails, found, notfound) {\n\n db.User.findOne({\n username: registerDetails.username\n }).exec(queryCallback);\n\n function queryCallback(err, user) {\n if (user != null) {\n ...
{ "AcceptedAnswerId": "49530", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T13:19:57.980", "Id": "49517", "Score": "1", "Tags": [ "javascript", "node.js", "closure" ], "Title": "Node.js callback closure/scope" }
49517
<p>I'm facing the issue of how to reconstruct data across a network in Java. As part of my Component based game engine (read about it <a href="http://www.raywenderlich.com/24878/introduction-to-component-based-architecture-in-games">here</a>, I have to encode components as XML on the server, send it to the client, and...
[]
[ { "body": "<p><em>Reflection</em> is not the correct way to do this. You will need <em>Serialization</em> for this. Another option is to use XML marshalling and unmarshalling, but I am not so familiar with that.</p>\n\n<p>For serialization I suggest you to pick up a copy of <em>Effective Java</em>, and read the...
{ "AcceptedAnswerId": "49519", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T13:20:09.713", "Id": "49518", "Score": "7", "Tags": [ "java", "reflection" ], "Title": "Using Reflection to Initialize Instance Variables" }
49518
<p>I am currently making a very big blogging system for my Website where I want really neat code! So, I was wondering: is this method safe/does it have any problems with security? Yes, I'll be encrypting the password anyway. I also want to know if there is a better way to achieve the same idea. Also any tips on impleme...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T13:39:52.290", "Id": "87106", "Score": "2", "body": "Please read the help section of this site: you are asked to post actual, working code... the constructor you've posted _can't possibly work!_. `$this->db = $db;` when `$db` is not...
[ { "body": "<p>Ok, just a few quick thoughts, will be adding to this answer later today (ie after work):</p>\n\n<p><strong><em>One class, One task</em></strong><br>\nChances are, you've already heard of the SOLID principles. Well, here they are again: your code is in violation of the SRP (Single Responsability p...
{ "AcceptedAnswerId": "49532", "CommentCount": "13", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T13:36:07.457", "Id": "49520", "Score": "2", "Tags": [ "php", "security", "database", "authentication" ], "Title": "Security of authentication check for a blog" }
49520
<p>I have 4 variables - say A, B, C and D</p> <p>Each variable can have 4 values - say 1, 2, 3 and 4</p> <p>I need to generate all possible combinations of values</p> <p>Example of Expected Output:</p> <pre><code> A B C D --------- 1 1 1 1 1 1 1 2 1 1 1 3 1 1 1 4 1 1 2 1 1 1 2 2 1 1 2 3 . . . 4 4 4 1 4 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T08:24:03.573", "Id": "87113", "Score": "0", "body": "@I-M-JM i have the solution but i can only display the result and not put them into arrays, and is also not sorted. anyway i'll try to solve this, this seems challenging for me." ...
[ { "body": "<p>I will answer for both cases (permutations with and without repetition)</p>\n\n<p><strong>first without repetition:</strong></p>\n\n<p>You could use this as a general function to obtain permutations of an array:</p>\n\n<pre><code>function permute($items, $perms = array( )) {\n$result=array();\n ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T06:52:08.193", "Id": "49522", "Score": "4", "Tags": [ "php", "combinatorics" ], "Title": "Better way to achieve looped output result" }
49522
<p>The setup of Backbone:</p> <p>1 Collection, 3 Models, 1 View for the collection, 1 View per Model.</p> <p>HTML:</p> <pre><code>&lt;div id="showit"&gt;&lt;/div&gt; </code></pre> <p>Template:</p> <pre><code>&lt;script id="item-template" type="text/x-handlebars-template"&gt; &lt;a class="item" href="#"&gt;{{b...
[]
[ { "body": "<p>First of all, Backbone views already have a cached version of <code>$(this.el)</code> in <a href=\"http://backbonejs.org/#View-%24el\"><code>this.$el</code></a> so you should use <code>this.$el</code> instead of <code>$(this.el)</code>.</p>\n\n<p>I find that things work better when views only touc...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-11T17:38:22.417", "Id": "49524", "Score": "1", "Tags": [ "javascript", "backbone.js" ], "Title": "Updating single view on change of a model in backbone" }
49524
<p>I want to implement a predicate of the form:</p> <pre><code>zipwithindex(?List1, ?List2) </code></pre> <p>which is true when the elements of <code>List2</code> are the same as in <code>List1</code> but are paired with the index of the element. </p> <p>This is what I have:</p> <pre><code>zipwithindex([],I,S,S). z...
[]
[ { "body": "<p>sure:</p>\n\n<pre><code>zipwithindex(List1, List2) :-\n findall(E/I, nth0(I, List1, E), List2).\n</code></pre>\n\n<p><em>Edit - after Tudor' comment</em></p>\n\n<p>bagof/3 it's much better than findall/3, as it doesn't introduce unwanted new variables. This can be of utmost importance when worki...
{ "AcceptedAnswerId": "49528", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-10T20:44:44.180", "Id": "49527", "Score": "4", "Tags": [ "prolog" ], "Title": "Implementing a zipwithindex predicate in prolog" }
49527
<p>I'm learning Entity Framework and I'm wondering if this code is the proper way of doing this. Basically this is my attempt at refactoring a very long controller in ASP.Net MVC 4. I'm using Entity Framework 5 as well.</p> <p>What I did was I separated out some code into a more common method (buildUpdatedAnswerDeta...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-14T06:59:05.757", "Id": "87458", "Score": "0", "body": "Why ou do not just use Unit of Work with Repository Pattern I can post for you an example this is very good to manage the multipe database Connections and give you a very good se...
[ { "body": "<p>This answer is just a little remark about this redundant part:</p>\n\n<blockquote>\n<pre><code>if (isLeader == true)\n{\n buildAdItem.Comment = item.LeaderComment;\n buildAdItem.AnswerOptionKey = item.LeaderAnswerOptionKey.Value;\n buildAdItem.UpdatedBy = userName;\n buildAdItem.Update...
{ "AcceptedAnswerId": "49537", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T14:13:26.390", "Id": "49531", "Score": "3", "Tags": [ "c#", "entity-framework", "asp.net-mvc-4" ], "Title": "Entity Framework with multiple connections open?" }
49531
<p>This is a continuation of the <a href="https://codereview.stackexchange.com/questions/47897/isostoragemanager/48426#48426">last thread</a>.</p> <p>I wanted to add a thread-safety and I was considering <a href="https://stackoverflow.com/questions/23582262/async-reader-writer-locker/23583283">AwaitableCriticalSection...
[]
[ { "body": "<pre><code>public static async Task&lt;T&gt; ReadJson&lt;T&gt;(String fileName)\n</code></pre>\n\n<p><a href=\"http://msdn.microsoft.com/en-us/library/hh873175\" rel=\"nofollow\">The Task-based asynchronous pattern</a> says that the names of <code>Task</code>-returning methods should end with <code>A...
{ "AcceptedAnswerId": "49853", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T14:51:19.073", "Id": "49536", "Score": "1", "Tags": [ "c#", "asynchronous", "file-system", "async-await", "windows-phone" ], "Title": "ThreadSafe IsoStorageManager" }
49536
<p>I have a Cache Helper Class.</p> <pre><code>using System; using System.Web; public static class CacheHelper { /// &lt;summary&gt; /// Insert value into the cache using /// appropriate name/value pairs /// &lt;/summary&gt; /// &lt;typeparam name="T"&gt;Type of cached item&lt;/typeparam&gt; /...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-14T16:16:25.400", "Id": "87539", "Score": "0", "body": "You can view updated version of code here: http://www.coderemarks.com/review/LIgmRrlPmwJ2PEuk" } ]
[ { "body": "<pre><code>try\n{\n if (!Exists(key))\n {\n value = default(T);\n return false;\n }\n\n value = (T) HttpContext.Current.Cache[key];\n} catch {\n value = default(T);\n return false;\n}\n\nreturn true;\n</code></pre>\n\n<p>This contains some duplicate logic. We can rewr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T15:37:05.050", "Id": "49541", "Score": "19", "Tags": [ "c#", "asp.net" ], "Title": "ASP.Net caching manager" }
49541
<p>I just finished <a href="http://projecteuler.net/problem=40" rel="nofollow">Project Euler 40</a> with a brute force method. As usual, any optimizations would be helpful. (I feel like I'm getting better at this scripting thing)</p> <pre><code>from timeit import default_timer as timer def product(n): from functo...
[]
[ { "body": "<p>This probably plenty fast enough, but a brute force method strikes me as a very inefficient approach. I can think of a way that should be faster and more efficient, and avoids you constructing a million-character string.</p>\n\n<p>Here are some suggestions/hints:</p>\n\n<ul>\n<li><p>You calculate ...
{ "AcceptedAnswerId": "49568", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T16:35:18.093", "Id": "49543", "Score": "2", "Tags": [ "python", "optimization", "programming-challenge" ], "Title": "Project Euler 40: Champernownes's Constant" }
49543
<p>I do not like this implementation as is seems too much complicated. My idea was to implement some BFS algorithm variant. </p> <p>Some points to notice:</p> <ol> <li>I use one queue. </li> <li>In the begining put the tree root in the queue and dummy <code>treeNode</code> delimiter which is recognized by its <cod...
[]
[ { "body": "<h2>General Notes</h2>\n\n<p>Let me preface this section with the fact that I have not looked at Java conventions in a while. Some of these suggestions may stray from classic Java conventions.</p>\n\n<p>With that off my chest, visually your code looks pretty good, though mixture of underscores in you...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T17:07:25.877", "Id": "49546", "Score": "5", "Tags": [ "java", "algorithm", "tree", "breadth-first-search" ], "Title": "Print binary search tree by levels function implementati...
49546
<p>I have a question about of the performance of using for loops (normal for, for each and for key in object) in JavaScript.</p> <p>Just now I created this code to test:</p> <pre><code>var stopwatch = function(){ var start; this.Start =function(){ this.start = new Date().getTime(); } this.ge...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T17:50:58.507", "Id": "87161", "Score": "2", "body": "You can check this link: http://jsperf.com/fastest-array-loops-in-javascript/24" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T20:05:46.083", ...
[ { "body": "<p>Well, here's some tips:</p>\n\n<ul>\n<li><p>Never use <code>for-in</code> for arrays. <code>for-in</code> runs through the array properties.</p>\n\n<pre><code>var a = [1,2,3]\na.foo = 'bar'; // arrays are still objects\nfor(var i in a){console.log(i)} // will run over foo\n</code></pre></li>\n<li>...
{ "AcceptedAnswerId": "49619", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T17:22:15.140", "Id": "49549", "Score": "4", "Tags": [ "javascript" ], "Title": "Performance for, foreach and for key" }
49549
<p>I am making an application which fetches tweets for a specified amount of time, then inserts those tweets in a database and when the user presses another button the top <code>n</code> words and the hashtags will be shown.</p> <p><strong>This is my <code>Twitter</code> package:</strong></p> <pre><code>[Package]Twit...
[]
[ { "body": "<p>The ideal package structure is one which indicates usage. Classes such as these which exclusively contain static methods are definitely utility classes, which I usually put in a <code>util</code> subpackage of your main application.</p>\n\n<p>From what it sounds like, you don't have a main package...
{ "AcceptedAnswerId": "49561", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T17:25:54.697", "Id": "49550", "Score": "1", "Tags": [ "java", "classes" ], "Title": "Putting in order my two packages and possibly merging them" }
49550
<p>I haven't done too many nested statements in MySQL and I was hoping to have the below SQL looked at and let me know if there is a better/more efficient way of doing what I am trying to accomplish.</p> <p>Through all of my tests it appears that everything is working properly, I just want to make sure I am meeting be...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-13T05:09:37.917", "Id": "87227", "Score": "0", "body": "Do you need 1 row that is returned or multiple rows may also?" } ]
[ { "body": "<p>Get rid of your Commented Code it's messy</p>\n\n<hr>\n\n<p>This bit of Code might be shortened</p>\n\n<pre><code>AND replace(replace(`contract_price`, ',', ''), '$', '') &gt;= 1500\nAND replace(replace(`contract_price`, ',', ''), '$', '') &lt;= 9999\n</code></pre>\n\n<p>to something like this, <s...
{ "AcceptedAnswerId": "49608", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T17:27:08.483", "Id": "49551", "Score": "2", "Tags": [ "mysql", "sql" ], "Title": "Nested SQL Statement" }
49551
<p>I wonder </p> <ol> <li><p>Is it appropriate to hide imported classes (collections and UserDict in this case) from Python IDE (e.g. IPython)?</p></li> <li><p>Is there a more efficient algorithm/implementation?</p></li> </ol> <p>Please feel free to comment on how you would improve this class.</p> <pre><code>import ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T20:00:36.663", "Id": "87171", "Score": "0", "body": "I will assume when you copied your code into this post the spacing got borked. Could you update the question so that it has (what I assume to be) the correct spacing?\n\nIt will b...
[ { "body": "<p>The message to <code>KeyError</code> could be defined with a triple quote string to avoid the addition.</p>\n\n<p>Instead of hiding the modules you should use explicit imports like</p>\n\n<pre><code>from collections import defaultdict\n</code></pre>\n\n<p>Instead of using <code>type</code> to chec...
{ "AcceptedAnswerId": "49676", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T18:31:23.763", "Id": "49555", "Score": "3", "Tags": [ "python", "database", "hash-map" ], "Title": "Managing and searching objects using tags" }
49555
<p>I'd like to be able to define Angular constants in terms of other constants.</p> <p>It's not possible to inject dependencies into Angular <code>constant</code> services. When I want one of my constants to depend on another of my constants, I use a <code>provider</code> service. This allows my constants to have de...
[]
[ { "body": "<p>Using an <a href=\"https://en.wikipedia.org/wiki/Immediately-invoked_function_expression\" rel=\"nofollow noreferrer\">IIFE</a> seems to be the tidiest way I've found to do it. This allows you to define your constant as a function (that is immediately invoked) that returns your constant object so ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T19:32:25.197", "Id": "49558", "Score": "5", "Tags": [ "javascript", "angular.js" ], "Title": "AngularJS constants depending on other constants - any established patterns?" }
49558
<blockquote> <p>Given a shape, get all triangles that can be possible by connecting the points.</p> <p>Example: given 3 points, only 1 triangle is possible, but given a pentagon, 10 are possible.</p> </blockquote> <p>Also the combination formula is \$\dfrac{n!}{r!(n-r)!}\$. Does it mean \$O(n!)\$ is the comple...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T20:21:16.710", "Id": "87174", "Score": "0", "body": "*... but given a polygon 10 are possible\"* <- makes little sense... what polygon?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T20:46:46.497", ...
[ { "body": "<p>No, it doesn't mean \\$O(n!)\\$ complexity. The \\$(n-r)\\$ in the denominator cancels most of the terms in the numerator. For choosing three points to make a triangle, \\$r\\$ = 3, and so your actual expression is \\$\\frac{(n)(n-1)(n-2)}{3!}\\$ => \\$\\frac{(n^3-3n^2+2n)}{3!}\\$ => \\$O(n^3)\\...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T19:41:13.797", "Id": "49559", "Score": "6", "Tags": [ "java", "algorithm", "combinatorics" ], "Title": "Given a shape, return all triangles that can be formed" }
49559
<p>At the time I try to write some code to handle an IRController, I got this following classes:</p> <pre><code>public class UsbDataInputListener implements UsbPipeListener { @Override public void errorEventOccurred(UsbPipeErrorEvent upee) { throw new UnsupportedOperationException("Not supported yet."...
[]
[ { "body": "<ol>\n<li><p>I would try to create a data structure which stores both event data and required action. Something like this:</p>\n\n<pre><code>Map&lt;byte[], Runnable&gt; commands = new HashMap&lt;&gt;();\ncommands.put(Keys.POWER, SHUTDOWN);\n...\n</code></pre>\n\n<p>Then you can iterate it over:</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T19:46:26.787", "Id": "49560", "Score": "3", "Tags": [ "java", "classes", "javafx" ], "Title": "Handling an IRController" }
49560
<p>I'm trying to make a loop where it returns whether or not a rectangle collides and then to which coords the rectangle should move to.</p> <p>I'm calling my function like this:</p> <pre><code>rectangles2[i].rect = rectangleupdated(i, rectangles2); </code></pre> <p>And this is inside my function:</p> <pre><code>pr...
[]
[ { "body": "<p>The only change I can recommend without knowing more about what you're trying to accomplish is to add in a conditional to the end of the foreach loop (E: actually it would be better to put this in after the if's in the conditionals, since the boolean values will only be different if that code has ...
{ "AcceptedAnswerId": "49569", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T20:21:29.683", "Id": "49563", "Score": "5", "Tags": [ "c#", "performance", "collision", "graphics" ], "Title": "Slow foreach loop to check for intersect" }
49563
<p>This Python main is what greets the user to a thrice nested super duper barebones OS. The entire rest of my code isn't bug free but this section is, and it feels dirty anyway. I'd like to know how to make it better, by adhering to conventions, or by removal of fatty code.</p> <p><em>NOTE: I am not looking to use ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T20:53:34.343", "Id": "87179", "Score": "0", "body": "The Python convention for variable names is `lowercase_with_underscores`. You can find the Python style guide in [PEP 8](http://legacy.python.org/dev/peps/pep-0008/)." } ]
[ { "body": "<p>So why not use functions for the steps?</p>\n\n<pre><code>work_to_be_done = True\n\nwhile work_to_be_done:\n if makeNew == \"c-na\":\n do_make_account()\n work_to_be_done = False\n elif makeNew == \"l-a\":\n result = login()\n if result:\n work_to_be_do...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T20:32:22.530", "Id": "49565", "Score": "4", "Tags": [ "python", "python-2.x", "authentication" ], "Title": "Thrice nested \"OS\" in Python" }
49565
<p>I have a Python script which parses a complicated CSV generated on election nights. Each row of the CSV represents a race. As I loop through the races, I store the candidates for each race into a list called <code>cnds</code>. The other variable to note is called <code>num_win</code>, and it holds the number of peop...
[]
[ { "body": "<pre><code># Make one more candidate than necessary into winners list\nwinners = sorted(cnds, key=lambda k: int(k['votes'], reverse=True)[0:num_win + 1]\n\n# A tie to be resolved happens when two last candidates have equal vote count.\n# if so, go backwards removing everybody with the same vote count...
{ "AcceptedAnswerId": "49573", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T21:29:56.317", "Id": "49570", "Score": "6", "Tags": [ "python", "algorithm", "array", "hash-map" ], "Title": "Parsing a complicated CSV generated on election nights" }
49570