body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<blockquote> <p><strong>Goal:</strong></p> <p>Write a character creator program for a role-playing game. The player should be given a pool of 30 points to spend on four attributes: strength, health, wisdom, and dexterity. The player should be able to spend points from the pool on any attribute and should a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-25T18:25:46.937", "Id": "12943", "Score": "1", "body": "what do you mean by efficient? Running speed? This kind of program will never be slow, you should focus more about readability than speed. and the mandatory link: http://c2.com/cg...
[ { "body": "<p>One of the first things I would do is try and group your information into neater packages, rather than having a bunch of free variables. I assume you're not too familiar with classes, but try putting your character's attributes into a data structure like a List, or even better - a Dictionary:</p>\...
{ "AcceptedAnswerId": "8292", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-25T17:49:38.840", "Id": "8285", "Score": "14", "Tags": [ "python", "beginner", "python-2.x", "role-playing-game" ], "Title": "Character creator for a role-playing game" }
8285
<p>I'm generating a table to use on jQuery visualize plugin and generate a chart. The code is pretty good, but maybe there is a way to improve it. Maybe do more work on the LINQ query and less stuff on the rest of the code.</p> <p>The idea is get every content and the launch date of them for each region. Separate all ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T11:10:55.293", "Id": "13046", "Score": "1", "body": "I'd start by splitting the method into several smaller methods with descripting names. Makes the logic easier to follow, and hopefully also exposes possible refactorings, field ca...
[ { "body": "<p>A few general points:</p>\n\n<p>(1) <code>GlobalVariables.Regions</code> -- I don't know how big your application is, but if I'm looking at a code base and I see some static class called \"GlobalVariables\" that usually makes me leery. In a pure object-oriented language, all data can (and arguab...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-25T18:34:29.763", "Id": "8286", "Score": "4", "Tags": [ "c#", "linq", "asp.net-mvc-3", "entity-framework" ], "Title": "LINQ generating chart" }
8286
<p>I wrote a method that gathers data from an Oracle server, formats and encrypts the data then inserts it into a MS SQL server. The method moves about 60000 records and takes a bit long and is a little sloppy. Can anyone see places to clean it up and make it faster?</p> <p>Two of the areas that I see might need impro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T20:18:44.747", "Id": "13007", "Score": "0", "body": "Or try this http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=16742 and pray it works like they say it does." } ]
[ { "body": "<p>First of all, profile the code to find the bottleneck. </p>\n\n<p>Some other idea:</p>\n\n<ul>\n<li>Use threads. One thread retrieves the data from Oracle and one or more threads upload it to MSSQL.</li>\n<li>Use <a href=\"https://stackoverflow.com/questions/2099425/when-we-use-preparedstatement-i...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-25T19:58:36.690", "Id": "8290", "Score": "3", "Tags": [ "java", "sql-server", "oracle" ], "Title": "Oracle to MSSQL data migration is slow on INSERT" }
8290
<p>The model looks like this, with <em>no attributes</em>:</p> <pre><code>public class PersonalModel : Validatable { public string Name { get; set; } public string Email { get; set; } public override void Validate(dynamic item) { if (this.ValidatesPresenceOf(item.Name, "Name is required")) ...
[]
[ { "body": "<p>I wholeheartedly agree that the attributes are evil.\nBut in my opinion having to derive from a base class is just as bad as having to add attributes. Both makes you depend on framework infrastructure you don't need to depend on. (Models should be model logic, and model logic only.)</p>\n\n<p>In M...
{ "AcceptedAnswerId": "8315", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-25T22:11:18.660", "Id": "8293", "Score": "4", "Tags": [ "c#", "asp.net-mvc-3" ], "Title": "ASP.NET MVC models that can be validated without using attributes" }
8293
<p>Goal: Create a simple battleship game to test what I've learned so far.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; void buff_clr(void) { char junk; do{ junk=getchar(); }while(junk!='\n'); } struct coord { int y; int x; }coords; int randge...
[]
[ { "body": "<pre><code>#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;time.h&gt;\n\nvoid buff_clr(void)\n{\n char junk;\n do{\n junk=getchar();\n }while(junk!='\\n');\n}\n\nstruct coord\n{\n int y;\n int x;\n\n}coords;\n\nint randgen(int **ships_ptr,int n)\n</code></pre>\...
{ "AcceptedAnswerId": "8299", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-25T22:49:33.277", "Id": "8294", "Score": "13", "Tags": [ "c", "game" ], "Title": "Battleship game in C" }
8294
ActionScript is an object-oriented scripting language used for RIAs, mobile applications, web applications, etc. ActionScript was initially developed by Macromedia and then acquired by Adobe. It targets to compile for Flash Player runtime which can be deployed in various platforms, including mobile platforms.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-25T23:16:53.793", "Id": "8296", "Score": "0", "Tags": null, "Title": null }
8296
<p>I was wondering if it's normal/efficient to have this many static collections in my state based game? I started doing it for ease of access but it looks sloppy to me and I was just wondering what conventions other people use to maintain references to game objects?</p> <pre><code>public class DungeonDigger extends S...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T13:43:06.070", "Id": "12980", "Score": "0", "body": "[Single responsibility principle](http://en.wikipedia.org/wiki/Single_responsibility_principle)" } ]
[ { "body": "<p>Overall, separate your code, make it modular. Store state where it needs to be stored, but keep it separate, and expose the minimum amount of functionality that you have to.</p>\n\n<p>I would highly recommend that you read the book Effective Java, and then read it again. Feedback below, separate t...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T00:22:52.360", "Id": "8297", "Score": "7", "Tags": [ "java", "design-patterns" ], "Title": "Java Slick StateBasedGame managing resources across states" }
8297
<p>Model:</p> <pre><code>public class UserBean { @JsonProperty private String userId; @JsonProperty private int limit; @JsonProperty private int page; public String getUserId() { return userId; } public void setUserId(String userId) { this.userI...
[]
[ { "body": "<p>It would be easier to follow the <code>getProductListByUser</code> method if you use two <code>ResponseJSON</code> instance. One for normal execution and one for the exceptional cases:</p>\n\n<pre><code>try {\n ...\n\n final ResponseJSON responseJSON = new ResponseJSON();\n ...\n\n res...
{ "AcceptedAnswerId": "8313", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T01:15:38.477", "Id": "8300", "Score": "1", "Tags": [ "java", "api", "spring" ], "Title": "Java API code with Spring" }
8300
<p>Does this look right to you? What are its shortcomings? Strengths?</p> <pre><code>import Control.Monad import Control.Monad.Trans.Class import Control.Pipe.Common import Data.Conduit c2p :: (Resource m, Monad m) =&gt; Conduit a m b -&gt; Pipe a b m () c2p = do PreparedConduit push close &lt;- lift $ runResourceT...
[]
[ { "body": "<p>I can see three problems with this approach:</p>\n\n<p>1) Calling <code>runResourceT</code> at each step releases all the scarse resources allocated by the original conduit. This is not what you want, since a conduit can depend on the availability of those resources until the point where it termin...
{ "AcceptedAnswerId": "8333", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T03:32:18.430", "Id": "8302", "Score": "6", "Tags": [ "haskell" ], "Title": "Turning Conduits into Pipes" }
8302
<p>I am trying to solve a problem at <a href="http://www.codechef.com/problems/SUMTRIAN" rel="nofollow">Codechef</a>. As I am new to programming, I am not familiar with dynamic programming. However, I do know the basics of recursion and memoization. Hence I implemented a solution to the above mentioned problem. The pro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-25T19:38:52.630", "Id": "12963", "Score": "2", "body": "your solution overall looks Ok. You should extend the memoization for all values. Max no of lines is <=100 and `100X100` vector is Ok to have." } ]
[ { "body": "<p>Why only use memoization for \"small\" values of <code>i</code> and <code>j</code>?</p>\n\n<p>Without memoization, your program runs in exponential time. The problem, which memoization intends to solve, is that you tend to compute the same value many times along the way.</p>\n\n<p>So you memoize ...
{ "AcceptedAnswerId": "8328", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-25T19:24:33.497", "Id": "8303", "Score": "2", "Tags": [ "c++", "optimization", "algorithm", "memoization" ], "Title": "Memoization-based puzzle solution - sums in a triangle" }
8303
<p>In this new project I'm working on I need to create objects on runtime by data from the DB, right now I have two groups of classes, each group implementing a different interface.</p> <p>I started working on a factory class, <strong>which will map id to a type</strong>, an abstract one so I can extend with a factory...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T07:43:32.513", "Id": "12967", "Score": "1", "body": "I think that if you write and run some tests for this, you'll know whether or not it works, with far more confidence than you'll ever get from the well-meaning words of random str...
[ { "body": "<p>I'm not too familiar with C#, so just two general notes.</p>\n\n<ol>\n<li><p>Instead of structures like this:</p>\n\n<pre><code>if (idsToTypes.ContainsKey(id))\n{\n return Activator.CreateInstance(idsToTypes[id], args);\n}\nelse\n{\n return null;\n}\n</code></pre>\n\n<p>you could write this:...
{ "AcceptedAnswerId": "8586", "CommentCount": "13", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T06:46:00.237", "Id": "8307", "Score": "29", "Tags": [ "c#", "design-patterns" ], "Title": "Implementing factory design pattern with generics" }
8307
<p>I want to write a regular expression to determine whether a given string is uppercase and sorted in non-descending order.</p> <pre><code>^A*B*C*D*E*F*G*H*I*J*K*L*M*N*O*P*Q*R*S*T*U*V*Q*X*Y*Z*$ </code></pre> <p>I was just wondering if it is possible to improve the above regex.</p> <p>Examples of correct strings:</p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T13:50:03.190", "Id": "12981", "Score": "3", "body": "`I want to write a regular expression ...` now you have 2 problems. :) What do you want to improve? A working solution for UTF-8 like ÄÖÜ?" }, { "ContentLicense": "CC BY-S...
[ { "body": "<h2>No.</h2>\n<p>There is no way to express</p>\n<p>(xy)* | ∀(x, y) =&gt; x &lt;= y ∧ (x, y) ∈ {A..Z}</p>\n<p>with regular expressions in such an abstract way, at least not in popular regex usage I'm aware of. So you have to enumerate all characters explicitly.</p>\n", "comments": [ { ...
{ "AcceptedAnswerId": "8326", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T07:12:06.760", "Id": "8308", "Score": "4", "Tags": [ "regex" ], "Title": "How to determine the order of letters by regex?" }
8308
<p>The <a href="https://spring.io/projects/spring-framework" rel="nofollow noreferrer">Spring Framework</a> is an open-source application framework for the <a href="https://codereview.stackexchange.com/tags/java/info">Java</a> platform.</p> <p>Spring is a non-invasive, versatile, powerful <a href="https://en.wikipedia....
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-01-26T08:34:34.177", "Id": "8309", "Score": "0", "Tags": null, "Title": null }
8309
The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the "plumbing" of enterprise applications so that teams can...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T08:34:34.177", "Id": "8310", "Score": "0", "Tags": null, "Title": null }
8310
<p>I'm running into an issue while playing around with some models in a Rails app. Namely issues of the polymorphic variety. I think I may have solved it, more or less looking for an approval.</p> <p>I have the following models in my app:</p> <pre><code>class Issue &lt; ActiveRecord::Base belongs_to :creator, class...
[]
[ { "body": "<p>The foreign key is not needed for <code>belongs_to :creator</code> since rails will infer this foreign key from the association name. The source has to point to the relation for <code>UserIssue</code> (you pluralized this name but active record class names should be singularized in most cases) so ...
{ "AcceptedAnswerId": "8360", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T09:12:01.650", "Id": "8312", "Score": "3", "Tags": [ "ruby", "ruby-on-rails", "active-record", "polymorphism" ], "Title": "ActiveRecord model for users who have issues or wh...
8312
<p>Puzzle Description:</p> <blockquote> <p>A number is called lucky if the sum of its digits, as well as the sum of the squares of its digits is a prime number. How many numbers between A and B are lucky?</p> </blockquote> <p>How can I improve performance of the following code?</p> <pre><code>import java.util....
[]
[ { "body": "<p>You could use <a href=\"http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes\" rel=\"nofollow\">Eratosthenes sieve</a> to find the prime numbers &lt;= 1000 (or a proper value that can be the max sume of digits) before doing anything else, and not use isPrime function every time you need to check a n...
{ "AcceptedAnswerId": "8339", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T12:21:28.987", "Id": "8319", "Score": "7", "Tags": [ "java", "optimization", "primes" ], "Title": "Sum of the digits is prime or not" }
8319
A cache is a component that transparently stores data so that future requests for that data can be served faster.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T13:27:44.677", "Id": "8321", "Score": "0", "Tags": null, "Title": null }
8321
<p>I have written this <a href="https://github.com/DarkMantisCS/FileMaker-PHP-API-Interface/blob/master/class.fmdb.php" rel="nofollow">piece of code</a> to help the development of FileMaker developers having to use the dog-awful PHP API.</p> <pre><code>&lt;?php require_once ( 'fm_api/FileMaker.php' ); require_once ( ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T15:53:11.107", "Id": "12992", "Score": "0", "body": "Please include all relevant code in your post, as suggested in the [FAQ](http://codereview.stackexchange.com/faq)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<ol>\n<li><p><code>FMDB</code> - A longer class name would help a lot (as a reader).</p></li>\n<li><p>If the following fields are constants they shouldn't be public fields. I'd give them uppercase names too.</p>\n\n<pre><code>public $ltet = '≤';\npublic $gtet = '≥';\n</code></pre></li>\n<li><p>The fo...
{ "AcceptedAnswerId": "8349", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T15:16:08.960", "Id": "8331", "Score": "2", "Tags": [ "php", "object-oriented" ], "Title": "FileMaker PHP API Interface" }
8331
<p>Deleting folders programmatically is extremely dangerous. It is enough for somebody else to change a configuration file or constant variable including the target folder's name to, say C:\, and that's it: the workstation is paralyzed!</p> <p>The following suggested methods are to prevent such a situation. Their aim ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T18:46:41.820", "Id": "13002", "Score": "1", "body": "This of course won't prevent the program from deleting the folder that _it's_ running from... or the directory of the CLR either. It's also (at the moment) going to only 'work' o...
[ { "body": "<h2>When all you have is a hammer, every problem looks like a nail.</h2>\n<blockquote>\n<p>You're trying to do something with code, that's not the code's job. <strong>Delete all this code</strong> and tackle the problem at the root: <strong>make sure your code runs with the appropriate permissions</s...
{ "AcceptedAnswerId": null, "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T15:29:51.777", "Id": "8332", "Score": "6", "Tags": [ "c#", ".net" ], "Title": "Deleting folders is a risky business" }
8332
<p>The following method is designed to return <code>true</code> if it passes all of the rules for a password. Does anyone see a way to improve it? Performance improvements are welcome for sake of education.</p> <p>I already know password rules beside length are counter-productive. It's not my choice. Also, I know th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T20:09:58.567", "Id": "13005", "Score": "0", "body": "a1111111 will pass, is this the intention?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T20:55:28.353", "Id": "13019", "Score": "1", ...
[ { "body": "<p>Should this:</p>\n\n<pre><code> else if (ctype_digit($char)) {\n $foundLetter = true;\n</code></pre>\n\n<p>Not be:</p>\n\n<pre><code> else if (ctype_digit($char)) {\n $foundNumber = true;\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "8347", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T19:32:29.530", "Id": "8340", "Score": "5", "Tags": [ "php", "performance", "validation" ], "Title": "Validating password rules" }
8340
<p>I just finished chasing a <a href="http://en.wikipedia.org/wiki/Heisenbug" rel="nofollow">Heisenbug</a> that was entirely my fault. I'd like to avoid it happening again.</p> <p>I have a function which formats a date to a certain preset format. Turns out I was not allocating enough space:</p> <pre><code>char* Forma...
[]
[ { "body": "<p>It appears that if have access to the standard library version of snprintf you can do this:</p>\n\n<pre><code>char* FormatDate(DT dateTime)\n{\n size_t needed = snprintf(NULL, 0,\"%d,%d,%d,%d,%d,%d\", dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second...
{ "AcceptedAnswerId": "8343", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-26T19:44:59.647", "Id": "8341", "Score": "3", "Tags": [ "c", "memory-management" ], "Title": "Space to allocate before sprintf" }
8341
<p>This is my first attempt at a jQuery plugin. If someone could help me make sure that the code is clean, efficient, and formated correctly I would really appreciate it.</p> <p><strong>Background</strong></p> <p>So the reason I wrote this plugin is because I cannot find an easy to use code that has already been writ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-19T14:54:16.707", "Id": "20686", "Score": "0", "body": "first thing : Thank you trying to help Aicc users :) Do you have follow the Lars-Erik's advices ? I'm working on a scorm project and i could give you help to get a \"jquery-Friend...
[ { "body": "<p>I don't immediately see any efficiency issues with your code. It's simple and concise.\nBut I do notice that you don't follow all the best practices for plugin authoring described here:</p>\n\n<p><a href=\"http://docs.jquery.com/Plugins/Authoring\" rel=\"nofollow\">http://docs.jquery.com/Plugins/A...
{ "AcceptedAnswerId": "8356", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T00:36:48.163", "Id": "8352", "Score": "4", "Tags": [ "javascript", "jquery", "html" ], "Title": "Learning Management System/AICC project" }
8352
<p>I was finding myself frequently calling <code>getApplication()</code> and casting it as <code>MyApplication</code> so that I could call a method in <code>MyApplication</code>. I decided to declare the static variable <code>Current</code> in <code>MyApplication</code> and set it in the constructor. Now I don't have...
[]
[ { "body": "<p>With this solution there is a danger that somebody accidentally change <code>MyApplication.current</code> to <code>null</code> or an invalid reference.</p>\n\n<p>I'd override the <code>getApplication</code> method in the <code>MyActivity</code> class with a <a href=\"http://en.wikipedia.org/wiki/C...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T01:47:50.887", "Id": "8353", "Score": "3", "Tags": [ "java", "android", "static" ], "Title": "Static variable Current in Application" }
8353
<p>I'm fairly new to Python and currently building a small application to record loans of access cards to people in a company. I'm using wxPython for the GUI and SQLAlchemy for the CRUD. I'm loosely following <a href="http://www.blog.pythonlibrary.org/2011/11/10/wxpython-and-sqlalchemy-an-intro-to-mvc-and-crud/" rel="n...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-12-17T20:59:32.670", "Id": "134446", "Score": "2", "body": "Hi, I removed the external links are broken as of today. If you still have those scripts somewhere online, please re-add the working links. Btw, any code you want reviewed should...
[ { "body": "<p>Inline comments should only be used sparingly, and definitely not on already long lines. Your <code>#returns a list of objects</code> is pretty unnecessary both because it's overly long, but also because it's inferrable and doesn't seem to matter. You only pass the <code>loans</code> on unchanged ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T13:33:22.380", "Id": "8358", "Score": "6", "Tags": [ "python", "beginner", "mvc" ], "Title": "Recording loans of access cards to people in a company" }
8358
<p>I am relatively inexperienced with MySQL and have a query, which to my eyes appears relatively complex: </p> <pre><code>SELECT SQL_CALC_FOUND_ROWS songsID, song_name, artist_band_name, author, song_artwork, song_file, genre, song_description, uploaded_time, emotion, tempo, user, happiness, instruments, ...
[]
[ { "body": "<p>I don't know is it help or not (since it's a really complicated query) but it's usually worth caching computed values such as <code>rating</code> and <code>ratings_count</code> and updating them once a day or an hour for example. In the majority of the cases it's enough to provide non-real-time da...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T14:07:40.610", "Id": "8359", "Score": "3", "Tags": [ "performance", "sql", "mysql" ], "Title": "Song database query" }
8359
<p>I been working on getting the <code>SocketAsyncEventArgs</code> to work the way I want it to work. Now I was wondering: is this going to work how it should work?</p> <pre><code>/// &lt;summary&gt; /// The settings to use with this ServerSocket. /// &lt;/summary&gt; ServerSocketSettings Settings; /// &lt;summary&gt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-28T13:09:10.097", "Id": "74282", "Score": "2", "body": "I have found that reuse of the SAEA at extreme rates can actually cause the CLR to fail because of the underlying buffer. I would recommend using a queue of SAEA and process them ...
[ { "body": "<p>Just a couple observations, unfortunately not directly related to your primary concerns but still [hopefully] valuable input from a code review perspective:</p>\n\n<ul>\n<li>The class is <em>tightly coupled</em> with several other classes. This may or may not be problematic, just thought I'd point...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T15:01:40.813", "Id": "8361", "Score": "8", "Tags": [ "c#", ".net", "networking" ], "Title": "SocketAsyncEventArgs send and receive" }
8361
<p>This is my first forray into Java Swing and it's not exactly pretty. I have quite a few methods, and a lot of stuff going on (XML parsing, data conversion, etc) and I'm just wondering what kind of general improvements / redundancies I can eliminate from my code.</p> <p><strong>test.xml:</strong></p> <pre class="...
[]
[ { "body": "<p>Given that you <em>already</em> appear to have an error in your XML file (because the solution presented in the first week appears to be the answer to itself, not <code>lastWeekSolution</code> as claimed), I'd recommend revising your structure. It's also going to cause problems with your edge cas...
{ "AcceptedAnswerId": "8380", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T15:47:25.713", "Id": "8366", "Score": "4", "Tags": [ "java", "xml", "swing" ], "Title": "XML parsing and data conversion with Swing" }
8366
<p>Here is my solution for Project Euler 35. (Find the number of circular primes below 1,000,000. Circular meaning all rotations of the digits are prime, i.e. <code>197</code>, <code>719</code>, <code>971</code>.) The code takes about 30 minutes to run. Can you help me identify which parts of the algorithm are hogging ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T18:29:41.053", "Id": "19987", "Score": "0", "body": "See http://codereview.stackexchange.com/a/12389/13523" } ]
[ { "body": "<p>Your <code>p</code> is a list. Then you do <code>p.count(x)</code> to see if x is a prime. This does a linear search of the list, and in fact, has to examine every element of <code>p</code>, not just those up to the occurrence of <code>x</code>. Instead, change <code>p</code> to a set. It will...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T20:24:01.400", "Id": "8371", "Score": "6", "Tags": [ "python", "optimization", "algorithm", "project-euler", "primes" ], "Title": "Euler 35 - python solution taking too lo...
8371
<p>It's simple. <code>Person</code> is a superclass. <code>Student</code> and <code>Instructor</code> are its subclasses. The program suppose to allow user create a student or an instructor.</p> <p><strong>Run</strong></p> <pre><code>package com.exercise.inheritance1; import java.util.Scanner; import org.joda.time.L...
[]
[ { "body": "<p>It seems to be good enough but you can</p>\n\n<ol>\n<li>Add more comments</li>\n<li><p>Add more methods to your main. Examples: </p>\n\n<ul>\n<li><code>public Student createStudent()</code></li>\n<li><code>public Instructor createInstructor()</code></li>\n</ul>\n\n<p>This will help you have a clea...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T22:03:59.233", "Id": "8375", "Score": "3", "Tags": [ "java", "jodatime", "inheritance", "console" ], "Title": "Creating students and instructors" }
8375
<p>I have the following code that gets the difference in time between now and when an alarm is supposed to go off (i.e. "alarm goes off in 23 minutes, 56 seconds").</p> <pre><code>def time_to_alarm_in_words #AN EMPTY STRING WE WILL BE ADDING TO time_in_words = '' #THE TIME TO THE ALARM IN SECONDS total_second...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T18:34:28.187", "Id": "62830", "Score": "0", "body": "Use [distance_of_time_in_words](http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words)(Time.now, Time.now.end_of_day)" } ]
[ { "body": "<p>Courtesy of the clever helper method from this link:\n<a href=\"https://stackoverflow.com/questions/4136248/how-to-generate-a-human-readable-time-range-using-ruby-on-rails\">https://stackoverflow.com/questions/4136248/how-to-generate-a-human-readable-time-range-using-ruby-on-rails</a></p>\n\n<pre>...
{ "AcceptedAnswerId": "8379", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T22:28:24.750", "Id": "8376", "Score": "1", "Tags": [ "ruby" ], "Title": "Suggested refactorings of this Ruby time-to-string method?" }
8376
<p>I've implemented <a href="http://wiki.commonjs.org/wiki/Modules/1.1.1" rel="nofollow">CommonJS Modules 1.1.1</a> as a simple bash script with a bit of help from <a href="http://www.gnu.org/software/m4/" rel="nofollow">M4</a>.</p> <p>I'm interested in comments on the shell scripting and the javascript output. </p> ...
[]
[ { "body": "<p>Looks good with a quick scan-over. Except I think you should learn to use the bash regular expressions operator instead of using egrep... Didn't really look at your code well enough but you've used it in a test operator so... Yeah, might be better as a bash solution: <code>[[ $ARG =~ EXPR ]]</code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T22:40:04.473", "Id": "8378", "Score": "1", "Tags": [ "javascript", "bash", "shell" ], "Title": "CommonJS modules/require at build-time with bash and M4" }
8378
<p>I know there is probably a better way to have coded this. Can anyone be of help? I am not an expert JavaScript coder.</p> <pre><code>$(function() { $('#clientLoginText').hover(function() { $('#clientLoginBox').stop().animate({ "height" : '80px'}, 700); }, function() { //$('#clientLoginBox')....
[]
[ { "body": "<p>Well here is a tidied up version that shouldn't change the functionality at all:</p>\n\n<pre><code>$(function() {\n $('#clientLoginText').mouseenter(function() {\n $('#clientLoginBox').stop().animate({ \"height\" : '80px'}, 700);\n });\n\n $('#clientLoginBox').mouseleave(function()...
{ "AcceptedAnswerId": "8382", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T00:58:57.940", "Id": "8381", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Animating login screens" }
8381
<p>I want to do binary search and if the target is not there get the index of where it should have been. </p> <p>This is the code I came up with. It seems correct. Is there any problem? Can it be improved? </p> <pre><code>private int binarySearch(String[] sortedArray, String target, int start, int end) { if(star...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T19:12:31.823", "Id": "13137", "Score": "5", "body": "Is there a reason you don't use `Arrays.binarySearch` ?" } ]
[ { "body": "<p>2 minor things:</p>\n\n<ol>\n<li><p>Remove the unnecessary comparison. If</p>\n\n<pre><code>sortedArray[mid].equals(target)\n</code></pre>\n\n<p>fails, it will again compare the two strings in the next <code>if</code> condition. Instead, you can just do:</p>\n\n<pre><code>int c = target.compareTo(...
{ "AcceptedAnswerId": "8397", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T08:17:56.353", "Id": "8388", "Score": "7", "Tags": [ "java", "algorithm", "binary-search" ], "Title": "Java binary search (and get index if not there) review" }
8388
<p>I have the following routine that I would like to simplify:</p> <pre><code>public void SetUniform(RenderContext ctx, string uName, object value) { if (ctx == null) throw new ArgumentNullException("ctx"); if (value == null) throw new ArgumentNullException("value"); if (value is int) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T12:21:59.307", "Id": "13115", "Score": "0", "body": "Could you not have some class hierarchy where you can have Vertex2f, Vertex3f implementing SomeInterface. Put the SetUniform method on the interface, then have the implementations...
[ { "body": "<p>You can overload your SetUniform method with the different types of value:</p>\n\n<pre><code>public void SetUniform(int value)\n{\n\n}\npublic void SetUniform(Vertex2f value)\n{\n\n}\npublic void SetUniform(Vertex3f value)\n{\n\n}\n...\n</code></pre>\n\n<p>You could also try using the <a href=\"ht...
{ "AcceptedAnswerId": "8408", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T09:44:48.787", "Id": "8389", "Score": "4", "Tags": [ "c#", "reflection" ], "Title": "C# overload method simplification" }
8389
<p>I'm studying C on <em>K&amp;R</em> and I solved exercise 2.08:</p> <blockquote> <p>Write a function <code>rightrot(x,n)</code> that returns the value of the integer <code>x</code> rotated to the right by <code>n</code> positions</p> </blockquote> <p>I've tested my code with some bit patterns and it seems to work...
[]
[ { "body": "<p>Isn't it something like this?</p>\n\n<pre><code>#include &lt;limits.h&gt; /* for CHAR_BIT */\n\nunsigned\nrotate_right(unsigned x, int n)\n{\n int left_shift = ((sizeof x) * CHAR_BIT) - n;\n return x&lt;&lt;left_shift | x&gt;&gt;n;\n}\n</code></pre>\n", "comments": [ { "Con...
{ "AcceptedAnswerId": "8413", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T10:52:33.020", "Id": "8390", "Score": "5", "Tags": [ "c", "bitwise" ], "Title": "Bit rotations exercise" }
8390
<p>For quite a long, I have been using a pattern to make my life a bit easier. please help me evaluate how good or bad my approach is and how can I improve it.</p> <p>I have a static class for just returning values:</p> <pre><code> class ReturnValue { const STATUS_SUCCESS = "SUCCESS"; cons...
[]
[ { "body": "<p>I would prefer:</p>\n\n<pre><code>function add($left, $right) {\n if (!(isset($left, $right) &amp;&amp; is_numeric($left) &amp;&amp; is_numeric($right)))\n {\n throw new InvalidArgumentException(\n __METHOD__ . ' Left and Right arguments must be numeric.');\n }\n\n return $le...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T11:21:35.463", "Id": "8391", "Score": "3", "Tags": [ "php", "design-patterns" ], "Title": "Is the way I use my pattern good enough?" }
8391
<p>I'd want an advise about the following idea that I have for organizing JavaScript when it comes to creating an HTML page. My group will be starting a new project and the approach that I'm trying to come up with will be large scale because every HTML page will be using it. Below I'll show a sample code and I'd like i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T12:46:36.777", "Id": "13117", "Score": "0", "body": "@Raynos This is the stupidest comment I've ever seen. Can you please explain why your eyes are bleeding?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012...
[ { "body": "<p>You have globals everywhere. Your cross module communication strategy is \"uniquely named globals everywhere\". I assume you know globals are bad but <a href=\"http://clux.github.com/modul8/docs/modularity.html\" rel=\"nofollow\">modul8 has a good article about it</a></p>\n\n<p>Use a <a href=\"htt...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T12:33:07.480", "Id": "8393", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "JavaScript architecture example on an HTML page" }
8393
<p>I'm trying to solve the Spotify bestbefore programming challenge found here <a href="http://www.spotify.com/us/jobs/tech/best-before/" rel="nofollow">http://www.spotify.com/us/jobs/tech/best-before/</a></p> <p>I have written the code in Python but when I send it in, it says "Wrong Answer". I have checked my code fo...
[]
[ { "body": "<p>I'm not sure if you can use the <code>sys.stdin</code>. I know it works with <code>data = raw_input()</code>, so you should probably use that.</p>\n\n<p>Also, in you programs inputs and outputs, there's some wrong dates. For some reason the output is 2067 even though you inputed 2000. I cannot see...
{ "AcceptedAnswerId": "8407", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T15:56:08.583", "Id": "8398", "Score": "2", "Tags": [ "python" ], "Title": "Spotify Bestbefore Coding Challenge in Python" }
8398
<p>I'm creating a factory design for math problems. The purpose of the factory is:</p> <ul> <li>The problems must be generated with a certain difficulty (or <code>level</code>). To do this, I've got an abstract method called ConfigureLevels.</li> <li>I set an abstract method called <code>Generate</code>, this one must...
[]
[ { "body": "<p>If I keep giving feedback on this project, I'll have to start charging consulting fees. :P</p>\n\n<pre><code>protected Random Random = new Random();\n</code></pre>\n\n<p>You should be sharing your Random object between all your ProblemFactories. Basically, you should only have one new Random in yo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T20:27:03.907", "Id": "8401", "Score": "1", "Tags": [ "c#", "design-patterns" ], "Title": "How to add a random feature for a factory design" }
8401
<p>I have written a simple python program which takes a number from the user and checks whether that number is divisible by 2:</p> <pre><code># Asks the user for a number that is divisible by 2 # Keep asking until the user provides a number that is divisible by 2. print...
[]
[ { "body": "<p>Well, first of all, you should put code in an <code>if __name__ == '__main__':</code> block to make sure it doesn't run whenever the file is imported. Thus, just copy pasting:</p>\n\n<pre><code>if __name__ == '__main__':\n print 'Question 4. \\n'\n\n num = float(raw_input('Enter a number th...
{ "AcceptedAnswerId": "8404", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T22:25:57.030", "Id": "8403", "Score": "5", "Tags": [ "python" ], "Title": "Python 'check if number is divisible by 2' program" }
8403
<p>I wrote a little utility to check stdin for correct UTF-8, reporting any errors encountered, but I am concerned about its simplicity and performance. Could anyone take a look and suggest some improvements please?</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdint.h&gt; int in, msz_byte, state = 0, cpbytes...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T14:25:17.753", "Id": "13292", "Score": "0", "body": "The buffered version would fail to handle a multi-byte char crossing a 4k boundary unless needed_start and cp are part of parse_state, so that parse_block is essentially stateless...
[ { "body": "<p>Move all of these declarations into main where they are used (mostly) and pass them as arguments as needed elsewhere (like error).</p>\n\n<pre><code>int in, msz_byte, state = 0, cpbytes = 0;\nuint8_t byte;\nuint32_t cp;\nunsigned long long offset = 0;\n</code></pre>\n\n<p>Replace computations with...
{ "AcceptedAnswerId": "8485", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T01:11:36.730", "Id": "8406", "Score": "3", "Tags": [ "c", "performance" ], "Title": "Improving a UTF-8 'validator'" }
8406
<p>I have a very big class <code>Foo</code> that should be divided into <code>FooBar</code>, <code>FooUtility</code>, <code>FooBench</code>, <code>FooBranch</code>. Each of this "subclasses" should have different methods. So that if <code>Foo</code> has:</p> <pre><code>public function methodA(); public function method...
[]
[ { "body": "<p>With <a href=\"https://en.wikipedia.org/wiki/Composition_over_inheritance\" rel=\"nofollow noreferrer\">Composition</a>/<a href=\"https://secure.wikimedia.org/wikipedia/en/wiki/Aggregation_%28object-oriented_programming%29#Aggregation\" rel=\"nofollow noreferrer\">Aggregation</a>.</p>\n\n<p>first ...
{ "AcceptedAnswerId": "8411", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T14:10:11.230", "Id": "8410", "Score": "4", "Tags": [ "php", "object-oriented" ], "Title": "Divide big class in subclasses" }
8410
<p>I just wanted to share this script I wrote in that hopes that someone might find it useful and can hopefully simplify it(?).</p> <p>I'm very new to writing anything with jQuery, so this script is probably bulkier than it needs to be, but it does work. </p> <p>Here's the full HTML page:</p> <pre><code>&lt;!DOCTYPE...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T14:27:36.787", "Id": "13219", "Score": "2", "body": "Just one quick tip, I see you set the menu1 and menu2 divs to variables and you use those variables in the if statements. You may want to also use the variables in place of the an...
[ { "body": "<p>2 comments:</p>\n\n<ul>\n<li>Why are you passing the same function twice to <code>$.toggle()</code>? From the <a href=\"http://api.jquery.com/toggle/\" rel=\"nofollow\">documentation</a> it looks like it only takes 1 function, the <code>callback</code>.</li>\n<li><p>You can abstract out the common...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-27T23:51:29.550", "Id": "8412", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "jQuery horizontal slide out navigation" }
8412
<p>I have a collision detection for terrain setup (non-terrain is handled with a quadtree I implemented apart from this) and I was wondering how others have done it compared to mine and what I could learn from people's critiques here.</p> <p>My map is stored in a 2D array of "GameSquare"s</p> <pre><code>public class ...
[]
[ { "body": "<p>That really looks quite slow.</p>\n\n<p>First of, don't use HashSet in these situations. A HashSet is a HashMap with \"blind\" values - like using the key as a value, too. They guarantee uniqueness and fast access (as everyone knows!), but for a set of <strong>four objects</strong> in a tight and ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T04:22:10.227", "Id": "8414", "Score": "3", "Tags": [ "java", "design-patterns", "api", "collision" ], "Title": "Java Slick 2D Collision Detection Methodology" }
8414
<p>I have a multiview to insert and edit users. Users are listed in a gridview. In <code>selectedindexchanged</code> event of gridview I've placed this code:</p> <pre><code>protected void GrvList_SelectedIndexChanged(object sender, EventArgs e) { // EditView FrmaddEditUsers.ActiveViewIndex = 1; // Get User...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-29T07:43:22.657", "Id": "130768", "Score": "0", "body": "Depends upon whether you have the view state enabled or not and where you get the values of your list." } ]
[ { "body": "<p>It certainly wouldn't do any harm and if you users have a backend that does not do something like encode when the user's name goes into the database then this will prevent any nasties. </p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0...
{ "AcceptedAnswerId": "10441", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T07:53:07.157", "Id": "8417", "Score": "2", "Tags": [ "c#", "asp.net" ], "Title": "Multiview for inserting and editing users" }
8417
<p>I recently tried my hand at CodeSprint2 through Interview Street. Having not coded in quite some time, I wasn't surprised that I had difficulty writing optimized code, but on one problem in particular I can't find where I've gone wrong. I've compared my code to successful algorithms used by other programmers, and ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T21:42:49.473", "Id": "13251", "Score": "0", "body": "I was not able to find a \"Picking Cards\" problem from the link you provided. The closest I found was the 2011 challenge called \"Card Shuffling\"." }, { "ContentLicense"...
[ { "body": "<p>The immediate thing that jumps out to me is your use of an ArrayList for this. By continuously removing the first element, you force the array list to shift everything left one space each time (an O(n) operation assuming no underlying optimizations!)</p>\n\n<p>Instead of removing from the array li...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T12:31:40.467", "Id": "8419", "Score": "3", "Tags": [ "java", "ruby", "programming-challenge" ], "Title": "\"Picking Cards\" challenge" }
8419
<p>I'm trying to refactor some code for unit testing and was hoping you could critique it.</p> <p>This is the original method:</p> <pre><code>public class MyNonRefactoredClass { public List&lt;MyClass&gt; DoSomething() { List&lt;MyClass&gt; data = GetData(); if (data.Count == 0) return new L...
[]
[ { "body": "<p>Looking at your code I see three responsibilities:</p>\n\n<ul>\n<li>the Data Provider (component that hits the db)</li>\n<li>the Data Formatter</li>\n<li>the business service (your class) that uses the other two components to execute a business flow.</li>\n</ul>\n\n<p>According to the <a href=\"ht...
{ "AcceptedAnswerId": "8424", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T13:42:44.343", "Id": "8420", "Score": "3", "Tags": [ "c#", ".net", "unit-testing" ], "Title": "Refactoring legacy code for unit testing" }
8420
<p>I have just started reading through <a href="http://learnyouahaskell.com/" rel="nofollow">Learn you a Haskell</a> I got up to list comprehension and started to play around in GHCi, my aim was to make a times table function that takes a number <code>n</code> and an upper limit <code>upperLimit</code> and return a nes...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T17:06:17.597", "Id": "13182", "Score": "0", "body": "Note that `reverse [0..(n-1)]` (even though it isn't needed, as Nicolas' answer shows) could be written `[(n-1),(n-2)..0]`." } ]
[ { "body": "<p>Your function could be simplified a little, and I find it helpful to define functions using declarations, since type signatures are really helpful (although admittedly your example is simple enough that it doesn't matter):</p>\n\n<pre><code>timesTable :: Int -&gt; Int -&gt; [[Int]]\ntimesTable n u...
{ "AcceptedAnswerId": "8422", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T15:04:57.970", "Id": "8421", "Score": "4", "Tags": [ "beginner", "haskell" ], "Title": "Multiplication table using a list comprehension" }
8421
<p>I have been following <a href="https://stackoverflow.com/questions/4801242/algorithm-to-calculate-number-of-intersecting-discs">this</a> question on SO, copied below. I put together a solution, but which is \$O(n^2)\$. In order to get a more efficient \$O(n \log n)\$ or \$O(\log n)\$ solution, I tried to sort that ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T15:50:57.567", "Id": "13176", "Score": "0", "body": "Seeing as that question already has an answer explaining the method, why are you asking here?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T16:01...
[ { "body": "<p>Ajit,</p>\n\n<p>Essentially this is a problem of 1-dimensional collision detection.</p>\n\n<p>A useful tool for that is spatial-partitioning.</p>\n\n<p>The book <a href=\"http://rads.stackoverflow.com/amzn/click/1558607323\" rel=\"nofollow\">\"Real-Time Collision Detection\" by Christer Ericson (M...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T15:30:43.107", "Id": "8423", "Score": "2", "Tags": [ "algorithm", "c", "computational-geometry", "complexity" ], "Title": "Finding the pairs of intersecting discs" }
8423
<p>I had to replace all instances of scientific notation with fixed point, and wrote a Python script to help out. Here it is:</p> <pre><code>#!/usr/bin/python2 # Originally written by Anton Golov on 29 Jan 2012. # Feedback can be sent to &lt;email&gt; . """Provide functions for converting scientific notation to fix...
[]
[ { "body": "<pre><code>from re import compile\n\n\nexp_regex = compile(r\"(\\d+(\\.\\d+)?)[Ee](\\+|-)(\\d+)\")\n</code></pre>\n\n<p>Python style guide recommends that global constants be in ALL_CAPS. And what about numbers like \"1e99\"? They won't match this regex.</p>\n\n<pre><code>def to_fixed_point(match):\n...
{ "AcceptedAnswerId": "8429", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T18:24:19.200", "Id": "8428", "Score": "2", "Tags": [ "python", "regex" ], "Title": "Python program for converting scientific notation to fixed point" }
8428
<p>I wrote this program that recursively prints all the files and directories starting at the current directory:</p> <pre><code>import Data.Tree (Tree (..)) import System.Directory (doesDirectoryExist, getCurrentDirectory, getDirectoryContents) main :: IO () main = do currentDirectory &lt;- getCurrentDirectory tr...
[]
[ { "body": "<p>Paths should be manipulated with functions from <code>System.FilePath</code>. You can also move <code>let</code>'s inside the <code>do</code>'s, replace the <code>case</code> on <code>Bool</code> with an <code>if</code>, and squeeze out the helper function with <code>&lt;$&gt;</code>.</p>\n\n<pre...
{ "AcceptedAnswerId": "8438", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T20:15:22.770", "Id": "8431", "Score": "16", "Tags": [ "haskell", "file-system" ], "Title": "Recursive directory tree printer" }
8431
<p>I'm writing a JavaScript/PHP file uploader and I want to start this project off on the right track. I've started with this, a JavaScript <code>Uploader</code> object which will handle Ajax calls, display progress, show error messages, etc. I'm just hoping to get some feedback on the way I'm setting up my scripts.</p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T00:31:58.017", "Id": "13203", "Score": "1", "body": "Can you elaborate on how exactly you'll be using this `Uploader` object? The `_singleton` code at the very top and the code at the very bottom (as well as the use of a local `_thi...
[ { "body": "<p>Why not use an existing ajax file upload library, like <a href=\"https://github.com/valums/file-uploader\" rel=\"nofollow noreferrer\">Fine Uploader</a>?</p>\n<p>As for your code.</p>\n<h1>1)</h1>\n<p>I think you meant to return <code>_this.methods.init.apply(this, arguments);</code>.</p>\n<h1>2)<...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T20:57:29.273", "Id": "8433", "Score": "3", "Tags": [ "javascript", "object-oriented", "ajax", "file" ], "Title": "JavaScript/PHP file uploader" }
8433
<p>Is there a very short way to do this same thing in a pure LINQ based way? It seems like I should not have to do all of this below to get to the <code>OrderBy</code>.</p> <pre><code>Dictionary&lt;DataColumn, DateTime&gt; columns = new Dictionary&lt;DataColumn, DateTime&gt;(); int startIndex; int endIndex; for (int ...
[]
[ { "body": "<p>It's not an answer to the question, but a local variable for <code>table.Columns[i]</code> and <code>caption</code> would improve the readability.</p>\n\n<p>Additionally, <code>startIndex</code> and <code>endIndex</code> could be declared inside the loop. (<a href=\"https://codereview.stackexchang...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T21:11:46.103", "Id": "8434", "Score": "1", "Tags": [ "c#", "linq" ], "Title": "How to order DataColumns with LINQ?" }
8434
<p>I am creating a Minecraft like terrain engine in XNA, and am having problems when I render water, sayings that the "numVertices" passed should be greater then zero - which they should always be. The terrain is seperated into regions 32x32x32 in size and the vertex buffers are set as dirty when a block is added, but ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T04:00:21.350", "Id": "13208", "Score": "0", "body": "Could you please at least state what method is throwing the exception?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T09:52:57.857", "Id": "13...
[ { "body": "<p>Now that there is working code, we can review it. :)</p>\n\n<p>Comments:</p>\n\n<ul>\n<li>Class variables should use PascalCase;</li>\n<li>Local variables should use camelCase;</li>\n<li>You should avoid having <code>x</code> and <code>X</code> in the same scope, that is really asking for bugs...<...
{ "AcceptedAnswerId": "8495", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-29T23:13:08.167", "Id": "8436", "Score": "0", "Tags": [ "c#" ], "Title": "Water flow problems in Minecraft-like terrain engine" }
8436
<p>We have a setup script for setting up a development environment, and setting up the image libraries is getting a bit messy:</p> <pre><code># this is to get PNG and JPEG support working in PIL on Ubuntu if [ -d /usr/lib/x86_64-linux-gnu ] ; then # 64 bit ubuntu sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so...
[]
[ { "body": "<p>Seems like you can do the if statement to set a variable to the first part of the path, then put all the file copies at the end after that.</p>\n\n<p>(Warning: My bash is kind of bad. Haven't used it for a while. I think this is how it's done though... Might need quotes around the libpath assignme...
{ "AcceptedAnswerId": "113632", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T04:38:18.917", "Id": "8441", "Score": "6", "Tags": [ "file-system", "bash", "installer" ], "Title": "Symlinking shared libraries from a platform-specific directory" }
8441
<p>I'd like to check the following process relating to the uploading of data by FTP, after the data is read from a database. </p> <p>I have a stored procedure that returns data in the following pipe delimited format in a single column. It typically returns around 300 rows, each row has about 300 bytes. </p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-10T16:24:05.570", "Id": "13868", "Score": "0", "body": "Looks like you are not dealing with a lot of data, so speed is not a huge concern, thus you could separate code (FTP from DB) a bit. I personally would have a method that returns ...
[ { "body": "<p>In general it looks fine to me. <code>BufferedStream</code> would not help anything here, your data is already in memory by the time any streams get created.</p>\n\n<p>I would prefer to see the <code>MemoryStream</code> in a using block, although in this case it is being disposed when the <code>St...
{ "AcceptedAnswerId": "8843", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T12:28:29.073", "Id": "8450", "Score": "3", "Tags": [ "c#", ".net" ], "Title": "Data to FTP upload by stream copy" }
8450
<p>I'm trying to symmetrically encrypt some data using C#, and there seems to be a lot of misleading or incorrect information out there on the subject.</p> <p>I created a project on GitHub to act as some sort of standard for encrypting and decrypting data in C#: <strong><a href="https://github.com/jbubriski/Encryptama...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T15:30:50.633", "Id": "13224", "Score": "0", "body": "Why the `using` **inside** the namespace? Is that just style, or something else?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T16:30:32.610", ...
[ { "body": "<p>A not encryption related note: I'd change the following</p>\n\n<pre><code>AesManaged aesAlg = null;\ntry {\n aesAlg = new AesManaged();\n ...\n} finally {\n if (aesAlg != null)\n aesAlg.Clear();\n}\n</code></pre>\n\n<p>to a simpler one:</p>\n\n<pre><code>AesManaged aesAlg = new Aes...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T14:15:33.277", "Id": "8452", "Score": "11", "Tags": [ "c#", "security", "aes" ], "Title": "Symmetrical encryption in C#" }
8452
<p>I'd like to make this SQL scalar function more efficient. How can I do that?</p> <pre><code>CREATE FUNCTION [dbo].[fnFilterBySampleType] ( @context VARCHAR(10), @contextId INT, @sampleTypeId INT ) RETURNS BIT AS BEGIN IF ( @context = 'batch' AND @sampleTypeId = 247 AND EXISTS( ...
[]
[ { "body": "<p>I am rewriting my answer to be more clear... </p>\n\n<p>the way you have it written the exists clause will be executed many times...</p>\n\n<p>You should move the exists clauses inside the if block so that in the cases that the other parts don't match it will be forced to short circuit. You can't...
{ "AcceptedAnswerId": "8454", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-11-11T16:51:25.553", "Id": "8453", "Score": "2", "Tags": [ "optimization", "sql" ], "Title": "How can I make this SQL Bit scalar function more efficient?" }
8453
<p>I wrote <a href="https://github.com/becomingGuru/python-restconsumer" rel="nofollow">this</a>, which essentially acts as a single library for all possible REST services.</p> <p>Here is the main file, as of alpha version 1:</p> <pre><code>import requests, json class RestConsumer(object): def __init__(self,bas...
[]
[ { "body": "<pre><code>import requests, json\n\nclass RestConsumer(object):\n\n def __init__(self,base_url,append_json=False,**kwargs):\n self.base_url = base_url\n self.uriparts = []\n self.append_json = append_json\n self.kwargs = kwargs\n</code></pre>\n\n<p>Since you treat attri...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T14:58:53.893", "Id": "8455", "Score": "5", "Tags": [ "python", "rest" ], "Title": "A generic REST API consuming Python library" }
8455
<p>I'm doing a site at the moment (first Rails site, learning as I code) and I'm concerned that I'm over complicating the routes.</p> <p>My associations boil down to:</p> <pre><code>class Recipe &lt; ActiveRecord::Base has_and_belongs_to_many :categories belongs_to :book end class Category &lt; ActiveRecord:...
[]
[ { "body": "<p>This is probably fine, though there are other ways to do it like passing filters to /recipes (?category_id=x or ?book_id=x). Your controller action is probably fine too, though I may have considered making multiple controllers. </p>\n\n<p>Though i'm not sure why you're doing <code>find_by_category...
{ "AcceptedAnswerId": "8530", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T18:46:46.253", "Id": "8461", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Route structure for multiple associations in Rails" }
8461
<p>This code is for handling addition of two binary numbers, which can be as long as 100,000 bits... and up to 500,000 queries are performed.</p> <p>High-level pseudocode:</p> <ol> <li>First input <code>N</code>: number of bits in binary number <code>A</code> and <code>B</code>.</li> <li>Second input <code>Q</code>: ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T19:21:38.217", "Id": "13241", "Score": "4", "body": "Can you link the online judge for this problem?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T19:28:14.440", "Id": "13242", "Score": "0",...
[ { "body": "<p>Profile and you will find your bottlenecks, you can do that with gprof under gcc/g++. You have to set the <code>-g -pg</code> on compile and then run your program like you would do normally. It will then produce a gmon.out file which you can open with <code>gprof main gmon.out</code> (assuming mai...
{ "AcceptedAnswerId": "8464", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T18:51:52.657", "Id": "8463", "Score": "5", "Tags": [ "c++", "time-limit-exceeded" ], "Title": "Handling addition of two binary numbers" }
8463
<p>I'm new to Java. I'm trying to build a simple hierarchy of classes. </p> <pre><code>abstract class Vegetable { public Vegetable(double weight) { this.weight = weight; ... } ... } class Tomato extends Vegetable { public Tomato(double weight) { super(weight); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T09:21:21.517", "Id": "64508", "Score": "0", "body": "I would use dictionary instead of switch look at this question my answer\n[Factory design pattern](http://codereview.stackexchange.com/questions/5752/is-this-correct-factory-metho...
[ { "body": "<p>I would use an enum type instead of having to pass a class in. This way, it's impossible to pass something bad in, and you can catch errors at compile time instead of runtime.</p>\n\n<pre><code>enum VegetableType { CARROT, TOMATO, CUCUMBER };\n</code></pre>\n\n<p>Then your buy method would be simp...
{ "AcceptedAnswerId": "8481", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T20:54:21.080", "Id": "8467", "Score": "10", "Tags": [ "java", "design-patterns", "object-oriented" ], "Title": "Vegetable factory" }
8467
<p>Is there a better or easier way of doing this?</p> <pre><code>if array[1] and array[2] and array[3] and array[4] and array[5] == false then --somthing end </code></pre> <p>I have a lot of arrays to check and was wondering if there is a way to work with arrays where you can do something like <code>array[1-6]<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T22:58:07.327", "Id": "13245", "Score": "0", "body": "The code in the title is different than what you put in the text. Which one you you want to \"shrink\"?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-0...
[ { "body": "<p>I'm not sure of the lua syntax but something like</p>\n\n<pre><code>arrayAllFalse=TRUE;\nfor element in array\n if (element) then \n arrayAllFalse=FALSE\n end\n\nif (arrayALLFalse) then\n --something\nend\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", ...
{ "AcceptedAnswerId": "8471", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-28T21:13:24.950", "Id": "8468", "Score": "3", "Tags": [ "lua" ], "Title": "Consolidating array accesses" }
8468
<p>I have a custom validator that checks the min and max score of different sporting leagues -- e.g., MLB, NBA, NFL, NCAAB, etc.</p> <p>Here's short version of what it looks like:</p> <pre><code>class ScoreValidator &lt; ActiveModel::Validator def validate(event) if event.league_is_mlb? if event.total_s...
[]
[ { "body": "<ol>\n<li><p>You can refactor each condition using <a href=\"http://martinfowler.com/refactoring/catalog/extractMethod.html\" rel=\"nofollow\">extract method</a></p>\n\n<pre><code>def validate_mlb_score\ndef validate_nba_score\n</code></pre></li>\n<li><p>Also you can methods to determine min/max scor...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T18:11:04.417", "Id": "8473", "Score": "1", "Tags": [ "ruby-on-rails", "ruby" ], "Title": "Refactoring custom validator using lots of if's" }
8473
<p>I am looking for best practice on how I may write this function more efficiently. </p> <pre><code> var d = new Date(), time = d.getHours(), day = d.getDay(); if (day &gt; 0 || day &lt; 7){ if (time &gt; 18 || time &lt; 8){ // execute code } } </code></pre>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T19:20:28.423", "Id": "13253", "Score": "2", "body": "What makes you think your current code is inefficient?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T19:22:20.927", "Id": "13254", "Score...
[ { "body": "<pre><code>if ( (day &gt; 0 || day &lt; 7) &amp;&amp; (t &gt; 18 || t &lt; 8))\n</code></pre>\n\n<p>Is this what you want?</p>\n\n<p>Second condition will only be evaluated only if the first one is true. If the first one is true, then only the second one is evaluated.</p>\n", "comments": [ ...
{ "AcceptedAnswerId": "8477", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T19:18:53.440", "Id": "8476", "Score": "0", "Tags": [ "javascript" ], "Title": "Better way to determine date" }
8476
<pre><code>(defmacro with-condition-retries(retries expected-errors fail-function &amp;body body) "Attempts to execute `body` `retries` times, watching for `expected-errors`. Optionally, if `fail-function` is set, each time a failure occurs, prior to retrying, `fail-function` is executed. Other conditions beside `e...
[]
[ { "body": "<p>This is the sort of thing you want to get as many eyes on as possible. My gut tells me that you'd want to break it up into smaller functions, but I'm not entirely sure where I'd cut. Any chance of getting an example use or test case? Could you explain the reasoning behind using <code>tagbody</code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T07:46:33.843", "Id": "8488", "Score": "7", "Tags": [ "common-lisp" ], "Title": "Common Lisp macro: review for code quality & leaky name escaping" }
8488
<p>I need to determine a meeting date which convenes on the second Thursday of every month.</p> <p>I've written the following code to do this:</p> <pre><code>//Determine next monthly meeting (occurs on 2nd thursday of each month) define('MAX_POSSIBLE_SECOND_THURS', 14); define('JANUARY', 1); define('DECEMBER', 12); d...
[]
[ { "body": "<p>Try the <a href=\"http://www.php.net/manual/en/class.datetime.php\">DateTime class</a>. With this you can use <a href=\"http://www.php.net/manual/en/datetime.formats.relative.php\">relative formats</a>:</p>\n\n<pre><code>new DateTime('second thu of next month');\nnew DateTime('second thu of jul')...
{ "AcceptedAnswerId": "8496", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T10:53:05.303", "Id": "8493", "Score": "1", "Tags": [ "php" ], "Title": "Best way to get day-of-week occurance" }
8493
<p>I'm seeing a lot of code like this at my new site</p> <pre><code> try { Task.Factory.StartNew(() =&gt; { ... }); } catch (AggregateException ex) { ex.Handle((x) =&gt; { Log.Write(x); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T02:08:37.493", "Id": "13284", "Score": "1", "body": "That looks wrong to me. You should inspect the code base for other, subtler, worse mistakes or misconceptions. Threading is hard, and I have yet to see correctly multi-threaded ...
[ { "body": "<p>You are quite right. These exception handling blocks will never catch any task exceptions. The code should be modified to check the <a href=\"http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.isfaulted.aspx\" rel=\"nofollow\">Task.IsFaulted</a> flag in the continuation and check ...
{ "AcceptedAnswerId": "8562", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T02:04:10.870", "Id": "8494", "Score": "7", "Tags": [ "c#", "exception" ], "Title": "Is this the wrong way to handle AggregateException with Tasks" }
8494
<p>I've written this class for two purposes (I think only this fact shows that this code violates <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle" rel="nofollow">SRP</a>): convert weight from one unit to another and to represent them accurate or not accurate. So class methods can be used for calcu...
[]
[ { "body": "<p>First of all, don't use plural identifiers if the variable or constant doesn't hold multiple values (e.g. rename <code>DEFAULT_UNITS</code> to <code>DEFAULT_UNIT</code> and <code>units</code> to <code>unit</code>) as it can be very confusing.</p>\n\n<hr>\n\n<p>Why don't you just always store the t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T14:47:29.527", "Id": "8499", "Score": "4", "Tags": [ "ruby", "ruby-on-rails", "converting" ], "Title": "Temperature converter that seems to violate SRP" }
8499
<p>How can I code this in a better way, in one file? Output must be more than one (if there is more that one status_update with the given word &quot;online or performancedegradation&quot;), like:</p> <blockquote> <pre><code>#online System is operating at peak performance. #directonly Traffic is bypassing Smart CDN sys...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T15:05:33.043", "Id": "13296", "Score": "0", "body": "It must sort by first status_update found: Online => then #online\nSystem is operating at peak performance.\n\nperformancedegradation => #directonly\nTraffic is bypassing Smart CD...
[ { "body": "<p>I'll give you a hint. Try using a foreach loop:\n<a href=\"http://www.php.net/manual/en/control-structures.foreach.php\" rel=\"nofollow\">http://www.php.net/manual/en/control-structures.foreach.php</a></p>\n\n<p>You can store all your files and associated information in an associative array, such ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-01-31T14:59:54.710", "Id": "8502", "Score": "2", "Tags": [ "php", "html", "parsing", "regex" ], "Title": "Read a text file and print pre-defined html when specific keywords are foun...
8502
<p>I need some second or third eyes to look over this, since right now, the necessary actions to make this work sound just bad and I suppose I am missing something due to a lack of C# experience.</p> <p>I am currently working on a winforms c# application. More specifically, I am reworking a highly convoluted control f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T20:56:09.100", "Id": "13297", "Score": "0", "body": "Make sure you have tests in place (unit, integration, functional, etc) to ensure you don't break existing functionality" }, { "ContentLicense": "CC BY-SA 3.0", "Creati...
[ { "body": "<p>I implemented my own MVC (Model-View-Controller) framework. In order to reduce the number of view events the controller had to subscribe to, I made my views send messages. I.e. I created a <code>Message</code> class containing different useful pieces of information. One of them is a message type t...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-30T20:48:29.847", "Id": "8504", "Score": "2", "Tags": [ "c#", "user-interface" ], "Title": "How to refactor these C#-events or fix this architecture?" }
8504
<p>How can I script this in a better way?</p> <pre><code>// Tweets $twitter_username_string = "aasampat OR ashwinsampat OR somemore"; $twitter_number_of_tweets = 1; $twitter_hashtags = "ashwinsampat+OR+franq2+OR+franq2.net"; // Instantiate a Twitter object which will scan Twitter depending on the parameters $twitter...
[]
[ { "body": "<p>There is a lot of duplication here. The code </p>\n\n<ol>\n<li>downloads one tweet, then stores it in the <code>$tweetoutput</code> variable,</li>\n<li>downloads two tweets, then stores the second in the <code>$tweetoutput_secondline</code> variable,</li>\n<li>opens a file called <code>export_file...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T15:29:19.083", "Id": "8506", "Score": "2", "Tags": [ "php", "optimization" ], "Title": "Twitter scanner" }
8506
<p>This does the job, and it's pretty much all the functionality I need at the moment. However, I feel like it could be optimized a bit. Namely, is there a way I can do this without the <code>div#boundary</code>? Also, the drop down re-fires if I go back up into the menu, which not a big deal, but it would be nice to p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T13:46:16.240", "Id": "13336", "Score": "0", "body": "What do you think the purpose of the boundary is? It currently has both a visual and programmatic purpose; is the visual purpose important?" } ]
[ { "body": "<p>I've come up with two options, but I'm not sure if either are an acceptable replacement for you.</p>\n\n<hr>\n\n<p><strong>Option 1</strong></p>\n\n<p>Overlay the expanding menu on the original menu. This allows simplification of the eventing. Only tricky part is that by moving quickly, you could ...
{ "AcceptedAnswerId": "8560", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T17:14:53.620", "Id": "8509", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "jQuery drop down" }
8509
<p><strong>Background</strong></p> <p>I'm converting Unicode text to <a href="http://en.wikipedia.org/wiki/TeX" rel="nofollow">TeX</a> for typesetting. In the input, I'm allowing simple fractions like ½ and ⅔ using single Unicode characters and complex fractions like ¹²³/₄₅₆ using superscripted and subscripted numera...
[]
[ { "body": "<p><em>(Disclaimer: I don't know perl, just regular expressions)</em></p>\n\n<h3>First question</h3>\n\n<blockquote>\n <p>is there a way to avoid the alternation operator (<code>|</code>) and simply match on either <code>\\^</code> or <code>\\_</code>?</p>\n</blockquote>\n\n<pre><code> (?: \\$ \\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T17:16:22.247", "Id": "8510", "Score": "3", "Tags": [ "regex", "perl", "unicode", "tex" ], "Title": "Simplify regular expression? (Converting Unicode fractions to TeX)" }
8510
<p>I'm new to Rails/Ruby and I would like to get feedback on my little <code>ApplicationController</code> which is able to detect the visitor's language. I'm especially interested in optimizations on the control structure in the <code>set_locale</code> method (2 nested <code>if</code> statements and 3 assignments to on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-01-30T17:02:54.293", "Id": "143274", "Score": "0", "body": "Just a note: In Ruby, an empty string is `true`. Checking for `params[:local].empty?` is better than `nil?` since `nil?` returns false for empty strings, and the locale can be an...
[ { "body": "<p>You can do it in an \"one-liner\". Although one-liners are frequently associated with less readability, I honestly believe this is <strong>not</strong> the case. Something like this would work:</p>\n\n<pre><code>I18n.locale = params[:locale] || \n request.preferred_language_from(AVAIL...
{ "AcceptedAnswerId": "8529", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T18:14:07.940", "Id": "8511", "Score": "2", "Tags": [ "beginner", "ruby", "ruby-on-rails", "i18n" ], "Title": "Small: Setting locale" }
8511
Internationalization, also known as i18n, refers to the techniques and tools to make the software change its behavior based on the country or culture of the user running it. This is a matter not only of changing the language which the software presents (e.g. in its user interface), but of changing the date format, the ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T19:22:19.560", "Id": "8516", "Score": "0", "Tags": null, "Title": null }
8516
<h3>More readable way to do this?</h3> <pre><code>renderHtmlTable(function(tableItems) { var tableArray,_i,item,_len; tableArray = ['&lt;table id = sampleTable &gt;&lt;thead&gt;&lt;tr&gt;' + '&lt;th&gt;Header 1&lt;/th&gt;' + '&lt;th&gt;Header 2&lt;/th&gt;' + ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T14:56:33.800", "Id": "62858", "Score": "0", "body": "Could also use DataTables, a plugin for jQuery. Datatables.net" } ]
[ { "body": "<p>Use mustache.js! It's a js templating engine which will point you in the right direction :)</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T06:59:06.977", "Id": "8535", "ParentId": "851...
{ "AcceptedAnswerId": "8558", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T21:15:44.270", "Id": "8517", "Score": "3", "Tags": [ "javascript", "jquery", "html" ], "Title": "Building an HTML table using JavaScript" }
8517
<p>Today, I do not have a coding question, but just a general question about a piece of code that I have written.</p> <p>As you guys can see, I run the following JavaScript code every ten seconds. I tried to run it every second, but it started eating up the CPU of my hosting company like crazy. With it running every...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T21:18:48.650", "Id": "13312", "Score": "2", "body": "**Warning** your code seems to be susceptible to sql injection attacks." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T21:19:25.473", "Id": "1...
[ { "body": "<p>If you want to protect your server then your server should be the one dictating the interval.</p>\n\n<p>Since any JavaScript can be intercepted and modified you can't rely on <code>setInterval</code>.</p>\n\n<p>First you need some way to measure load on your server. A simple approach would be to c...
{ "AcceptedAnswerId": "8520", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T21:17:14.813", "Id": "8518", "Score": "2", "Tags": [ "php", "javascript" ], "Title": "setInterval loading data from server every 10 seconds" }
8518
<p>I want to do insert sort in a linked list without using dummy nodes. </p> <p>This is my code. How can this be improved? Any input is appreciated. </p> <pre><code>public static Node insertSort(Node node){ Node sortedList = null; while(node != null){ Node current = node; node = node.next; Node x...
[]
[ { "body": "<p>Algorithmically, your implementation seems fine. One improvement would be to initialize the sortedList to the first node right away. This necessitates some error checking up front, which I think is better style anyway.</p>\n\n<p>I would also run a check for the current node being the new sorted he...
{ "AcceptedAnswerId": "8527", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T21:41:05.847", "Id": "8521", "Score": "7", "Tags": [ "java", "algorithm", "sorting", "insertion-sort" ], "Title": "Insert sort on a linked list" }
8521
<p>Is there a more succinct way to write code like this that has a lot of sharing between branches of the case statement?</p> <p>(This is the main part of my solution to one of the Round 1 problems of the Facebook Hacker Cup 2012. The round is over.)</p> <pre><code>type Memoizable a = a -&gt; a recoveries :: Int -&g...
[]
[ { "body": "<p>Hm, why did you write <code>go</code> as a separate function? It is - as you state - the same as <code>recoveries</code>, why the local definition?</p>\n\n<p>For making it more succinct, I think it's easiest to have an intermediate data structure that carries both pieces of information you seek in...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T21:51:56.973", "Id": "8522", "Score": "5", "Tags": [ "haskell" ], "Title": "Safety, sharing, and laziness" }
8522
<p>Migrating to using prepared statements and would like some feedback on CRUD modules, concerned with syntax (usage and DRY) and speed:</p> <p><strong>START:</strong></p> <pre><code>&lt;?php // This page is for deleting a user record. // This page is accessed through view_users.php. $page_title = 'Delete a User';...
[]
[ { "body": "<p>First, I'd like to say it is good that you are swapping over to use prepared statements. This is definitely the way to go. However, you aren't using them correctly in your code. If you read the <a href=\"http://www.php.net/manual/en/mysqli.prepare.php\" rel=\"nofollow\">documentation on <code>m...
{ "AcceptedAnswerId": "8531", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T23:35:04.903", "Id": "8525", "Score": "5", "Tags": [ "php", "performance", "php5" ], "Title": "Prepared statements syntax review" }
8525
<p>I'm not the greatest at writing tests yet and I'm starting a new OSS project for learning and as part of it I want to tackle being more effective at writing tests, more specifically quality tests. I think I write a lot of tests that don't bring much value except maintenance pain sometimes.</p> <p>Can I improve thes...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T06:18:12.253", "Id": "13323", "Score": "2", "body": "One improvement is to use xUnit.net instead of MSTest which integrates with AutoFixture and allows you to parameterize those tests via data theories. Once you have parameterized t...
[ { "body": "<p>I think it's quite well written, would have only two ideas.</p>\n\n<ol>\n<li><p>For the repeating part of the fixture setup (given) I'd consider using a <a href=\"http://xunitpatterns.com/Standard%20Fixture.html\" rel=\"nofollow\">Standard Fixture</a>, probably via a setup helper method.</p></li>\...
{ "AcceptedAnswerId": "8570", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T05:49:22.553", "Id": "8528", "Score": "11", "Tags": [ "c#", ".net", "unit-testing" ], "Title": "Can these unit tests be improved?" }
8528
<p>I've got this all working, but it seems to be quite long-winded, and I thought I'd post here and see if I'm doing it wrong...</p> <p>I have a M:M relationship between an Installer and a MasterInstance. The classes (code-first) look like:</p> <pre><code>public class MasterInstance { .. rest of fields here .. ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T21:42:46.077", "Id": "14137", "Score": "0", "body": "This is exactly how ive approached this problem in the past, its a bit ugly but ive never fund a better way" } ]
[ { "body": "<p>I know this is an old question, but I think the problem is timeless. Many to many associations (i.e. without junction class) in Entity Framework are always independent associations, so you can only establish or remove them by manipulating object collections, not primitive key values. Inefficiency ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T08:47:44.777", "Id": "8537", "Score": "11", "Tags": [ "c#", "mvc", "entity-framework", "asp.net-mvc-3" ], "Title": "Efficient way to deal with maintaining Many:Many relationsh...
8537
<p>When I want to make some quick tests for my UITableViewControllers, I usually create an NSArray that holds some dummy data. I would like to know if I'm doing anything wrong here:</p> <p>First in <code>MasterViewController.h</code>:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class DetailViewController; @interf...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-08-17T13:28:21.353", "Id": "24026", "Score": "0", "body": "I agree, the code looks good to me." } ]
[ { "body": "<p>Yes. Everything seems correct here. </p>\n\n<p>Like you mention yourself: make sure you use <code>self.dataSourceArray</code> to assign new values, and the synthesized setter will take care of memory management.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "Conte...
{ "AcceptedAnswerId": "8540", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T09:11:21.803", "Id": "8538", "Score": "2", "Tags": [ "objective-c", "memory-management" ], "Title": "Am I using my data source array correctly?" }
8538
<p>I'm putting together some classes as a model for some information (that I'm currently pulling from a website).</p> <p>The classes are implemented in C# - because in the current version of F# there are no autoimplemented properties. The logic to fill these classes from the website is going to be writen in F#. (Becau...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T13:36:48.800", "Id": "13334", "Score": "0", "body": "So what's the question you would like answered?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T13:39:41.117", "Id": "13335", "Score": "1",...
[ { "body": "<p>This is what I program when I want \"immutable\" classes in C#. You do have an access leak right now though, in that <code>PopularClasses</code> and <code>UnpopularClasses</code> both set and get the underlying object, allowing modification of that object, thus making the class immutable. (This is...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T13:20:56.820", "Id": "8543", "Score": "4", "Tags": [ "c#", "f#", "immutability", "properties" ], "Title": "Immutable pure data classes with public setters on properties" }
8543
<p>What is the best practices to pass data from presentation to application layer?</p> <p>Currently I have something like this:</p> <p><strong>in presentation layer:</strong></p> <p>the controller:</p> <pre><code>public class ProductController : Controller { private readonly IProductService _productService; ...
[]
[ { "body": "<p>Overall, your code is very good, there is not much to review..</p>\n\n<p>In your ViewModel, you might want to use <code>DataAnnotations</code> to do client (using jquery unobstrusive script)/server validation ex : </p>\n\n<pre><code>public class ProductCreateViewModel : ICreateProductCommand\n{\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T15:10:51.187", "Id": "8549", "Score": "8", "Tags": [ "c#", "mvc", "asp.net-mvc-3" ], "Title": "Is this appropriate way to pass data from presentation to application layer?" }
8549
<p>I use the following code to populate my HTML with JSON. The problem is that I'm afraid this code will be inefficient if the number of records that I get from the service call are large (200 or more).</p> <p>Are there ways I can change my code to make sure this won't be an issue? Or is my code fine as it stands?</p...
[]
[ { "body": "<p>Just one suggestion, </p>\n\n<p>Select tbody before loop. Currently you are selecting it again and again in loop.</p>\n\n<p>Also, you should use,</p>\n\n<pre><code> $('#tableProducts').find('tbody').append(domStructure);\n</code></pre>\n\n<p><code>children()</code> search for direct descendants w...
{ "AcceptedAnswerId": "8554", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-31T06:30:53.620", "Id": "8550", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Optimizing javascript/jquery code for HTML creation with JSON" }
8550
<p>I have existing code that handles a tarball and would like to use that to process a directory, so I thought it would be reasonable to pack the directory up in a temporary file. I ended up writing:</p> <pre><code>class temp_tarball( object ): def __init__( self, path ): self.tmp = tempfile.NamedTemporar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T15:47:55.030", "Id": "13363", "Score": "0", "body": "What's your concern with it now?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T16:21:28.297", "Id": "13367", "Score": "0", "body": "@...
[ { "body": "<p>You could try:</p>\n\n<pre><code>def __init__(self, path):\n self.tmp = tempfile.TemporaryFile()\n self.tarfile = tarfile.open( fileobj=self.tmp, mode='w:' )\n self.tarfile.add( path, '.' )\n self.tarfile.close()\n self.tmp.flush()\n self.tmp.seek(0)\n self.tarfile = tarfile.o...
{ "AcceptedAnswerId": "10491", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T15:32:27.797", "Id": "8557", "Score": "3", "Tags": [ "python" ], "Title": "Using temporary file as backing object for a tarfile" }
8557
<p>First of all, I apologize for the length of this but I'm trying to show the data I'm working with and that I attempted to figure it out on my own.</p> <p>I'm building a social site for musicians. I would like to take the whole list of songs from the database and rank each one based on its relevancy to the logged in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T16:04:26.823", "Id": "13366", "Score": "0", "body": "What is `$cxn`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T16:22:38.700", "Id": "13368", "Score": "0", "body": "It's the MySQL dat...
[ { "body": "<p>Your function is way too long. This is a lot going on in one function and very likely has some good candidates for smaller, single-purpose functions to be abstracted out of it. This is very likely the first thing that I would work on, it would make the flow of your function a little better and w...
{ "AcceptedAnswerId": "8566", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T15:46:59.053", "Id": "8559", "Score": "3", "Tags": [ "php", "algorithm" ], "Title": "Personalized, weighted recommendations - Rank all content with PHP" }
8559
<p>Some time ago I wrote a small routine to run some quick n' dirty queries (and with that I mean it is not used for large queries) against an Oracle DB, but also wanted to do it a bit easier to parse errors.</p> <pre><code># Executes the query # # Will execute a query contained in the variable named # in the paramete...
[]
[ { "body": "<p>It seems like you might find this clause helpful:</p>\n\n<pre><code>WHENEVER SQLERROR EXIT SQL.SQLCODE\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-07T17:51:24.013", "Id": "40108", "Score": "0", "bod...
{ "AcceptedAnswerId": "25708", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T16:44:35.527", "Id": "8563", "Score": "3", "Tags": [ "sql", "oracle", "ksh" ], "Title": "Parsing Oracle errors with a ksh function" }
8563
<p>I'm a zeromq newb and have implemented the REQ/RES Lazy Pirate pattern with C#. It's essentially a port from the C example given in the documentation. It's harnessed by tests, and seems to be work to my expectations. I'm interested to know if I'm understanding the pattern correctly, or if I can improve the API. If a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-06T13:59:57.853", "Id": "13618", "Score": "0", "body": "Minor improvement, in c# class properties use `PascalCase`. So you would have `Address`, `Timeout`, `ResponseReceived`, etc. You also have a typo in `PermanentFailException`." }...
[ { "body": "<p>It seems zeromq will release sent data itself. With GC supported in C#, this feature is useless. The <code>byteProvider</code> parameter seems inappropriate, so why not just use <code>IEnumerable&lt;byte&gt;</code>?</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T17:11:11.543", "Id": "8564", "Score": "5", "Tags": [ "c#", "zeromq" ], "Title": "Lazy Pirate Request Response pattern using zeromq and C#/.NET bindings" }
8564
<p>This is a question regarding design of a service or business logic layer that returns or exposes messages meaningful to the user.</p> <p><code>RegisterUser</code> method that takes a user. What should it return? Should it always return</p> <ul> <li>a Service Information object?</li> <li>a newly created user?</li>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T17:55:24.650", "Id": "73036", "Score": "0", "body": "This question appears to be off-topic because it is about design and not a code review." } ]
[ { "body": "<p>The problem with returning a message like this is that you are \"hard coding\" the messages in the registration method. If you want to add localization (i.e. return a message in the users language as determined by the culture setting of the client) to the application later it will be much harder....
{ "AcceptedAnswerId": "8567", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T17:13:25.037", "Id": "8565", "Score": "1", "Tags": [ "c#" ], "Title": "Designing a service/business logic layer that returns useful/consistent messages" }
8565
<p>Here's what I have at the moment. Any ideas for improving on this?</p> <pre><code>public static Snapshot[] GetSnapshots() { var arrayedSnapshot = new { Id = Enumerable.Range(1, 9), ScenarioTimeInSeconds = new[] { 0, 0, 0, 60, 60, 60, 120, 120, 120 }, BearingInDegrees = new[] { 0, 120...
[]
[ { "body": "<p>As far as I can see, most of your data is fairly predictable. What about:</p>\n\n<pre><code>for (int i = 0; i &lt; 9; ++i)\n{\n int scenarioTimeInSeconds = 60*(i/3); // Intentional loss of fractional part\n int bearingInDegrees = (i % 3) * 120; // It's now 0, 120, 240\n int rangeInNauticalM...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T20:32:07.527", "Id": "8569", "Score": "4", "Tags": [ "c#" ], "Title": "Seeking a quick and dirty way to populate a list of entities for testing purposes" }
8569
<p>I know there is a lot of libraries with this built in <code>$.get()</code> etc... but as for writing this in pure JavaScript how does this look?</p> <pre><code>var get_request; ajaxRequest(function() { var activexmodes, i, _i, _len, _ref, _results; activexmodes = ['Msxm12.XMLHTTP', 'Microsoft.XMLHTTP']; ...
[]
[ { "body": "<p>There are a couple issues with this code:</p>\n\n<ol>\n<li><p>You don't define a function in Javascript with <code>ajaxRequest(function() { ... });</code> What you're doing there is calling function <code>ajaxRequest</code> and passing an anonymous function into it as the only parameter. It will t...
{ "AcceptedAnswerId": "8636", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-01T21:56:08.917", "Id": "8571", "Score": "2", "Tags": [ "javascript", "ajax" ], "Title": "AJAX call in JavaScript" }
8571
<p>I'm working on a jQuery plugin for a client. Instead of finding one that was already out there I wanted to practice writing plugins since I hadn't in awhile. This plugin grabs all the images in a UL, creates a overlay for the page, and puts them in a image zoomer that gets opened when a user clicks on a thumbnail ...
[]
[ { "body": "<p><strong>Little Stuff</strong></p>\n\n<ul>\n<li>One line functions that are only used once such as <code>scrollLeft</code> and <code>scrollRight</code> should get inlined.</li>\n<li>Functions that create divs like <code>getThumbs</code> could be called <code>createThumbs</code> instead</li>\n<li>To...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-02T00:15:36.647", "Id": "8573", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "jQuery Plugin for Detailed images" }
8573
<p>This works but feels like alot of code for what it accomplishes. I feel like I'm maybe missing something obvious.</p> <pre><code>// When current month is same as target month, then return the current day of the month. // Else return the number of days in the target month. static int DefaultDaysToSynch() { var n...
[]
[ { "body": "<p>It is hard to improve on Jesse's answer (there are only so many ways to write this method), but I will add my alternative, which is a matter of style. I personally tend to not use <code>var</code> in place of any of the built-in types listed here: <a href=\"http://msdn.microsoft.com/en-us/library/...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-02T04:19:39.913", "Id": "8578", "Score": "3", "Tags": [ "c#", "datetime" ], "Title": "Long calendar related function" }
8578
<pre><code>Image&lt;Bgr, Byte&gt; frame = _capture.QueryFrame(); Image&lt;Gray, Byte&gt; grayFrame = frame.Convert&lt;Gray, Byte&gt;(); grayFrame._EqualizeHist(); MCvAvgComp[][] facesDetected = grayFrame.DetectHaarCascade(_faces, 1.1, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.FIND_BIGGEST_OBJECT, new Size(20, 20)); i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T12:15:24.893", "Id": "21206", "Score": "0", "body": "You could using bit-shifting instead of division by 2 / 2^x, though the compiler may do this optimisation anyway." } ]
[ { "body": "<p>I think your code is already quite good. My guess is that the calls to DetectHaarCascade are the majority of the time. Can you run a profiler on it? The <a href=\"http://eqatec.com/Profiler/\" rel=\"nofollow\">Equatec profiler</a> is free. As for the lower loop you could preallocate your colors (a...
{ "AcceptedAnswerId": "13108", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-02T04:51:14.757", "Id": "8580", "Score": "3", "Tags": [ "c#", ".net", "performance" ], "Title": "How do I make this C# code more efficient, in terms of FPS and time complexity?" }
8580
<p>I am developing a small compiler like tool. In the process, I wrote a <code>Class&lt;?&gt;</code> wrapper, <code>JavaClass</code>:</p> <pre><code>public class JavaClass { ... public List&lt;GenericEntry&gt; getAllGenericEntries() { return GenericEntriesFinder.getAllGenericEntries(this); } } </...
[]
[ { "body": "<blockquote>\n <p>I know in a pure OO scenario one should look and strive for using instance methods, but as I've come to find, when writing a compiler everything tends to turn into a heap of functions [...]</p>\n</blockquote>\n\n<p>Object orientation is appropriate for a large set of projects, but ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-02T08:41:13.393", "Id": "8582", "Score": "1", "Tags": [ "java", "unit-testing" ], "Title": "Question on where to put code logic" }
8582
<p>I use this function in my wordpress site to add genres to an album: What is it that makes this code so bulky? Is it have for the server or it just looks like?</p> <pre><code>/** * Creates a genere. If one already exists it will return an error * @author Junaid Qadir Baloch &lt;shekhanzai.baloch@gmail.com&gt; * ...
[]
[ { "body": "<p>Remove global (this shouldn't need to be explained).</p>\n\n<p>Your code depends on the class ReturnValue with method doReturn. This is a tight coupling that makes it hard to test your code. For your code to be reused you must also include the ReturnValue. This is almost ok, when it is only 1 e...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-02T10:36:03.063", "Id": "8583", "Score": "2", "Tags": [ "php", "optimization", "exception-handling" ], "Title": "How can I improve CreateGenre() function?" }
8583
<p>I have written a class who is responsible for both enumerating primes and testing the primality of a number.</p> <p>Here is the code :</p> <pre><code>public static class Primes { private static ulong g_MaxTested; private static ulong g_MaxFound; private static readonly HashSet&lt;ulong&gt; g_KnownPrim...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-04T01:22:06.500", "Id": "62789", "Score": "0", "body": "Why not port this clever python code to your language? http://onlamp.com/pub/a/python/excerpt/pythonckbk_chap1/index1.html?page=2" } ]
[ { "body": "<p>How large are the numbers that you will be testing for primality? If you have an upper bound then it might be better to use a sieve of Eratosthenes to find all the primes up to <code>sqrt(upperBound)</code>. That way you don't need to keep checking whether you need to extend your explored range.</...
{ "AcceptedAnswerId": "8593", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-02T13:22:07.583", "Id": "8585", "Score": "4", "Tags": [ "c#", "primes" ], "Title": "Finding and testing primality" }
8585