body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>The following bit of code requires a <code>string.maketrans</code> table that is only used inside a single function.</p>
<p>I have written three versions of the program that place the table at different locations in the code. The differing placement of the table results in quite varying performance in the creation ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T15:37:44.693",
"Id": "76495",
"Score": "2",
"body": "As it stands, this post isn't asking for code to be reviewed, and could be closed as primarily opinion-based. You could remove versions 2 and 3, and ask for version 1 to be peer r... | [
{
"body": "<p>I will answer your question in an unexpected way : the better solution is, as far as I can tell, much more straightforward than what you are doing.</p>\n\n<p>Indeed, <a href=\"https://www.youtube.com/watch?v=o9pEzgHorH0\">you don't need a class</a> : your class has an <code>__init__</code> and a s... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T15:30:58.303",
"Id": "44164",
"Score": "3",
"Tags": [
"python",
"performance",
"constants"
],
"Title": "Where should I place the constant?"
} | 44164 |
<p>I've been working on a 3D mathematical vector class which should be as streamlined as possible for use in numerical simulations. It will be used to model 3D-physical vectors.</p>
<p>Here, 3D-vector should be taken in mathematical sense, meaning a tuple (a,b,c).</p>
<p>I hoped to design it in a modern and fast way ... | [] | [
{
"body": "<p>Your design is a little bit confusing. You define your class as a template class, but just about everything takes and returns a <code>double</code>. Generally, you should try and be consistent: will this class work for any numeric-like <code>T</code>? Then make sure it has constructors that take a... | {
"AcceptedAnswerId": "44212",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T16:30:50.847",
"Id": "44167",
"Score": "11",
"Tags": [
"c++",
"performance",
"c++11"
],
"Title": "3D mathematical vector class"
} | 44167 |
<p>I'm new to Python and I'm wondering is there a way to streamline this clunky code I've written. Maybe a built-in function I've never come across before?</p>
<p>I run through two lists of binary numbers and if the same number appears at the same index in list one and two, do x.</p>
<p>So in the example below the nu... | [] | [
{
"body": "<p>Your solution's time complexity is O(n<sup>2</sup>), which is far from optimal. Your lists contain 19 elements - so your solution performs an order of 361 operations. \nIn order to get a linear solution, you can simulate a \"<a href=\"/questions/tagged/c\" class=\"post-tag\" title=\"show questions... | {
"AcceptedAnswerId": "44171",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T16:42:16.880",
"Id": "44168",
"Score": "8",
"Tags": [
"python",
"beginner",
"python-2.x"
],
"Title": "Streamlined for-loop for comparing two lists"
} | 44168 |
<p>Attached is a generic code I wrote to create an Excel file with x number of worksheets.</p>
<p>The problem I am having is that it's pretty slow, like 5 seconds a sheet. It was my understanding that using a <code>for</code> loop when creating the tables was ideal, but the issue seems to be with tables containing ove... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T20:14:10.230",
"Id": "76819",
"Score": "2",
"body": "You're using the old COM style interaction with the office application, so it's not surprising. Have you looked into dropping this and using the [OpenXML SDK?](http://msdn.micros... | [
{
"body": "<h2>Comments</h2>\n<p>Your code has way too many comments, mostly redundant ones - some are even obsolete!</p>\n<p>Good comments should say <em>why</em>, not <em>what</em>.</p>\n<blockquote>\n<pre><code>// Create our new excel application and add our workbooks/worksheets\nWorkbooks workbooks = xls.Wo... | {
"AcceptedAnswerId": "44976",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-03-12T16:46:52.217",
"Id": "44169",
"Score": "15",
"Tags": [
"c#",
"performance",
"excel"
],
"Title": "Creating Excel document is very slow"
} | 44169 |
<p>I'm working with AutoFac to do some DI. I think I've got a decent grip on things, but just ran into a question I had with my code and thought I'd check:</p>
<pre><code>public class AutofacRegistrations
{
public static void RegisterAndSetResolver()
{
// Create the container builder.
var conta... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T17:04:08.077",
"Id": "76516",
"Score": "2",
"body": "Per *Design Patterns: Elements of Reusable Object-Oriented Software* (the famous GoF book), An *abstract factory* is often used as a *singleton*. I don't know [tag:autofac] very w... | [
{
"body": "<p>Just got one thing to say on your code:</p>\n\n<h3>Your Comments add close to no value!</h3>\n\n<p>your code is littered with comments and empty lines</p>\n\n<blockquote>\n<pre><code>//Create the Container Builder\nvar containerBuilder = new ContainerBuilder();\n</code></pre>\n</blockquote>\n\n<p>... | {
"AcceptedAnswerId": "44684",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T16:55:11.800",
"Id": "44170",
"Score": "10",
"Tags": [
"c#",
"dependency-injection",
"autofac"
],
"Title": "Should a Factory ever be generated per request?"
} | 44170 |
<p>I wrote a service object that emails a list of files to a list of email addresses.</p>
<p>I am unsure about my <code>emails</code> method. It splits a string into an array of emails. It then loops over the array and rejects any elements that do not match the email regex. The return value is an array of valid emails... | [] | [
{
"body": "<h1>Good job on</h1>\n\n<ul>\n<li>Tightly focused methods that do what their name says</li>\n<li>Non-surprising formatting</li>\n<li>Testable design</li>\n</ul>\n\n<p>This is pretty good code</p>\n\n<h1>Environment variable</h1>\n\n<p>There's a few things that bother me about this class's use of the ... | {
"AcceptedAnswerId": "44179",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T17:28:42.760",
"Id": "44173",
"Score": "3",
"Tags": [
"ruby",
"email"
],
"Title": "Creating a pure Ruby object (PORO) to email files in a Rails application"
} | 44173 |
<p>I wrote a couple reviews for this <a href="https://codereview.stackexchange.com/questions/36482/rpsls-game-in-c">CR post</a>. In my most recent review, I refactored @Malachi 's code to fit OO design. I'm looking for any advice/hints/criticisms on it.</p>
<p>A review is welcome for both the OO design I implemented a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T19:30:36.273",
"Id": "76563",
"Score": "0",
"body": "you should do that the other way around. post the update separate."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T19:41:36.813",
"Id": "76565... | [
{
"body": "<p>one thing to start with.</p>\n\n<p>I would get rid of your <code>playAgain</code> variable and replace the while statement like this</p>\n\n<h2>Original Code:</h2>\n\n<pre><code>do\n{\n Game.Play(me, computer);\n Console.WriteLine(\"Your scorecard: \" + me.GetScoreCard());\n int result;\n... | {
"AcceptedAnswerId": "44234",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T18:03:56.237",
"Id": "44177",
"Score": "8",
"Tags": [
"c#",
"game",
".net",
"community-challenge",
"rock-paper-scissors"
],
"Title": "RPSLS refactored to Object Oriente... | 44177 |
<p>I was using setTimeouts for a project where a callback will be called after a duration, but the user has the options of extending, pausing or stopping the timeout. I felt using the default setTimeout was a bit clunky, especially since I needed to remember the timeout ids, and I decided to create a timeout utility ob... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>I would not use <code>_</code> to prefix all your variables, it would make more sense to either actually use private variables or write a comment that this variables should not be touched by callers</li>\n<li><code>pauseTimer</code> lies, since you toggle. I woul... | {
"AcceptedAnswerId": "44194",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T18:35:14.047",
"Id": "44181",
"Score": "3",
"Tags": [
"javascript",
"object-oriented",
"timer"
],
"Title": "Utility object for setTimeout"
} | 44181 |
<p>I know there is a simpler way of doing this, but I just really can't think of it right now. Can you please help me out?</p>
<pre><code>String sample = "hello world";
char arraysample[] = sample.toCharArray();
int length = sample.length();
//count the number of each letter in the string
int acount = 0;
int bcount =... | [] | [
{
"body": "<p>Oh woah! xD It's just.. woah! What patience you have to write all those variables.</p>\n\n<p>Well, it's Java so you can use a HashMap.</p>\n\n<p>Write something like this:</p>\n\n<pre><code>String str = \"Hello World\";\nint len = str.length();\nMap<Character, Integer> numChars = new HashMap... | {
"AcceptedAnswerId": "44187",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T19:52:49.457",
"Id": "44186",
"Score": "16",
"Tags": [
"java",
"strings"
],
"Title": "Count number of each char in a String"
} | 44186 |
<p>I'm writing a simple remote PC app (mouse-keyboard). Android is client and is connect with WiFi to Java PC Server. I'm using TCP but I see a bit of latency compared to other remote apps. Then I used UDP and didn't see any latency or wrong data. UDP look like it's working well. I'm sending a String to Server like th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T20:24:33.127",
"Id": "76576",
"Score": "3",
"body": "From the looks of it, proper indentation should come before everything else. This looks quite messy and should really be improved."
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>I would expect UDP to be slightly faster in latency than TCP, but not so that you could measure it by 'feel'. I would expect the differences to be in the order of micro-seconds.</p>\n\n<p>Then, when I look at your code, i see that you are creating a new TCP socket for every single character that y... | {
"AcceptedAnswerId": "44211",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T20:09:41.493",
"Id": "44189",
"Score": "8",
"Tags": [
"java",
"android",
"tcp"
],
"Title": "Latency problem for keyboard remoting from Android phone"
} | 44189 |
<p>I've got the following code to find the shortest path between two nodes using almost-Dijkstra's-algorithm which was written for an exercise, and I'm looking for things to improve my general Scala style. What I currently have:</p>
<pre><code> object Graphs {
case class Node[T](value : T)
case class Edge[T](... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T22:01:54.367",
"Id": "76594",
"Score": "0",
"body": "Nice problem! Your search algorithm is quite custom. Is it okay if we change the implementation a bit? If not then could you please add comments of what you're doing to make it ea... | [
{
"body": "<p>There are a few things how this could be improved.</p>\n\n\n\n<p>First, a few minor quibbles about syntax:</p>\n\n<ul>\n<li><p>When using a type annotation, do not put a space before the <code>:</code> – <code>name: Type</code>, please. (<a href=\"http://docs.scala-lang.org/style/types.html#annota... | {
"AcceptedAnswerId": "44249",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T20:50:28.107",
"Id": "44195",
"Score": "6",
"Tags": [
"algorithm",
"scala",
"graph"
],
"Title": "Dijkstra-like routing algorithm"
} | 44195 |
<p>Here is my implementation of a simple 3 rotor Enigma machine in C++:</p>
<pre><code>#include <iostream>
#include <cstring>
using namespace std;
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char rotors[3][27] =
{
"EKMFLGDQVZNTOWYHXUSPAIBRCJ",
"AJDKSIRUXBLHWTMCQGZNPYFVOE",
"BDFHJLCPRTXVZNYEIWGAKMU... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-05-04T18:49:16.140",
"Id": "308726",
"Score": "0",
"body": "Which is faster: int, long, boolean, or double make your constants constant - saves time"
}
] | [
{
"body": "<p>I think you can improve the <em>'Inverse rotor pass'</em> a lot by hard-code the inverted rotors instead of searching the inverse function every time.</p>\n\n<p>Your <code>a</code> is never below <code>-26</code> so you could try to replace </p>\n\n<pre><code>long mod26(long a)\n{\n return (a%26... | {
"AcceptedAnswerId": "44221",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T20:52:10.690",
"Id": "44196",
"Score": "12",
"Tags": [
"c++",
"performance",
"cryptography",
"simulation",
"enigma-machine"
],
"Title": "Enigma simulator performance"
} | 44196 |
<p>Can someone please let me know if they see glaring issues with this code? I tested a handful of cases and it seems to work but in other threads. I often see much more concisely written versions of this. I just want to know if anything I have done is superfluous or just stylistically poor form.</p>
<pre><code>#inc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T21:48:27.753",
"Id": "76592",
"Score": "1",
"body": "As @syb0rg noted, you have a stray `if(value <0)` that causes compilation to fail. Furthermore, if you try with `int value = 34` instead of 5, it won't find it."
},
{
"Con... | [
{
"body": "<p>Your solution combines iteration and recursion, which means that a lot of unnecessary work is done. Normally you'll want to choose only one method.</p>\n\n<p>A simple iterative version:</p>\n\n<pre><code>int re_search(int value, int values[], int n)\n{\n int first = 0;\n int last = n-1;\n ... | {
"AcceptedAnswerId": "44205",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-12T21:14:58.537",
"Id": "44199",
"Score": "7",
"Tags": [
"c",
"recursion",
"binary-search",
"reinventing-the-wheel"
],
"Title": "Can this recursive binary search in C be made ... | 44199 |
<p>I have a situation where I need to store fields of differing types of some data structures along with some similar metadata (The application takes data from one of many sources, some data possibly coming from more than one source, and then does stuff with it).</p>
<p>The solution I came up with was to create a clas... | [] | [
{
"body": "<p>What you are doing appears to be sane. The use of generics is primarily as a compile-time validator (and it makes some code simpler, like not having to cast things).</p>\n\n<p>If you don't know the types of your data at compile time, then you can't use generics.</p>\n\n<p>So, you have run-time spe... | {
"AcceptedAnswerId": "44219",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T01:10:00.293",
"Id": "44216",
"Score": "11",
"Tags": [
"java",
"generics",
"type-safety"
],
"Title": "Pattern for storing object of varying type"
} | 44216 |
<p>I have a requirement to validate file names related to architecture <em>after</em> they are uploaded. Once they have been uploaded I must warn the user if the file name is <strong>not</strong> standards compliant.</p>
<p><strong>What's in a name</strong></p>
<p>To be standards compliant a file name must consist of... | [] | [
{
"body": "<h3>Issues you have with the code</h3>\n\n<ol>\n<li><p><em>The aforementioned classes for parts 2, 3, 5, and 6 have a lot of duplication. As mentioned, they are identical except for the hash of acceptable values. Maybe inheritance is a good option?</em></p>\n\n<p>You're right that they are repetitive... | {
"AcceptedAnswerId": "44232",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T03:11:02.473",
"Id": "44223",
"Score": "11",
"Tags": [
"ruby",
"design-patterns",
"file",
"formatting"
],
"Title": "Ruby format analyser"
} | 44223 |
<p>I am trying to create a method that reverses a string that will handle every case. So far the cases I have come up with are</p>
<pre><code>""
"abcdef"
"abbbba"
null
</code></pre>
<p>I haven't been able to handle these conditions however</p>
<p>escape characters</p>
<pre><code>"\n"
"\t"
</code></pre>
<p>Not sure... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T08:36:57.023",
"Id": "76663",
"Score": "0",
"body": "We can review your code, but questions about how you can add a new feature to your code is not the topic of this site."
}
] | [
{
"body": "<p>There is a good overview of string reversal algorithms in <a href=\"https://codereview.stackexchange.com/a/42985/36217\">this answer</a>. It should explain how special characters like é can be handled. I don't see what's your problem with \"\\n\" and \"\\t\". These are strings already.</p>\n",
... | {
"AcceptedAnswerId": "44233",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T05:19:12.403",
"Id": "44231",
"Score": "0",
"Tags": [
"java",
"strings"
],
"Title": "reversing a string test cases"
} | 44231 |
<p>I have written a system for handling the dispatch of events between objects. (I need this functionality for a larger project I am working on. Objects should be able to dispatch events without knowing anything about the objects that will receive them. If this indicates that there is something seriously wrong with my ... | [] | [
{
"body": "<p>In general an event listener is something used often in Java programs, that is why there are already a lot of event managers that you can use, for example the <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Observable.html\" rel=\"noreferrer\">Observable</a> pattern. So what you are b... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T08:15:49.223",
"Id": "44235",
"Score": "7",
"Tags": [
"java",
"event-handling"
],
"Title": "Event Handling system in Java"
} | 44235 |
<p>I have a generic extension method for validating my entities. The main idea is to be able to specify at runtime (context related) the criteria for validating a specific entity (with the end goal of saving it in the data base).</p>
<pre><code>public static Boolean IsValidEntity<T>(this T entity, List<Predic... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T13:24:31.117",
"Id": "76694",
"Score": "2",
"body": "There is no reason to use `List.ForEach()`, just use a normal `foreach`, it's actually even few characters shorter."
}
] | [
{
"body": "<p>You can simplify your extension method a bit as so:</p>\n\n<pre><code>public static Boolean IsValidEntity<T>(this T entity, IEnumerable<Predicate<T>> predicates)\n{\n return predicates.All(p => (bool)p.DynamicInvoke(entity));\n}\n</code></pre>\n\n<p>This is a bit better for... | {
"AcceptedAnswerId": "44243",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T09:17:56.537",
"Id": "44238",
"Score": "3",
"Tags": [
"c#",
"performance",
"validation",
"extension-methods"
],
"Title": "Validating an entity using a dynamic list of predi... | 44238 |
<p>I am refining my reliable UDP library, its at its 3rd iteration now. It is quiet a bit multi-threaded with almost all major operations having dedicated threads. I need your opinion on the following critical worker methods. </p>
<h3>Legend</h3>
<pre><code>TAgUDP : Indy UDP Server derived class.
TAgUDPPeer ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T07:47:20.710",
"Id": "77215",
"Score": "0",
"body": "Please at least comment, not just up vote!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-18T20:04:51.240",
"Id": "77661",
"Score": "0",
... | [
{
"body": "<blockquote>\n <p><strong>give some advice on improving them</strong></p>\n</blockquote>\n\n<p>Add some expository introductory comments describing how your library is to be used and called, what makes it \"reliable\", and how and why it's different from TCP (what most people think of for reliable U... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T09:24:18.093",
"Id": "44239",
"Score": "6",
"Tags": [
"optimization",
"multithreading",
"networking",
"delphi"
],
"Title": "Handling packets and peers in a reliable UDP librar... | 44239 |
<p>I'm using the Game of Life Kata to help me learn JavaScript. I've picked up the syntax through Codecademy tutorials, but my current skill level is Novice.</p>
<p>The example code has working functionality for initialising a <code>World</code> with live cells and asking it to 'tick'.</p>
<p>All suggestions for impr... | [] | [
{
"body": "<p>Looks quite good overall; not much to criticise. (I'm not looking at the overall structure or logic - just the style; the game of life can be written in so many ways)</p>\n\n<p>Anyway, what I have is very trivial:</p>\n\n<ul>\n<li>Missing indentation in the bodies of <code>tick</code> and <code>ge... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T09:29:48.190",
"Id": "44240",
"Score": "7",
"Tags": [
"javascript",
"game-of-life",
"scope"
],
"Title": "Conway's Game of Life - Conventional JavaScript?"
} | 44240 |
<p>I am building a backend to a mobile application that will be hosted on a Django site connected to a PostgreSQL database. </p>
<p>I have never built anything to accomplish this before and this is my first go at it. I have not studied this type of application before so please let me know if the below code follows bes... | [] | [
{
"body": "<h3>readJSON()</h3>\n\n<p>Returning HTTP 404 (\"Not Found\") is improper, unless you are deliberately sending obfuscatory responses as a kind of security-by-obscurity measure. If you require a POST, and the client sends anything but a POST, the proper response should <a href=\"http://www.w3.org/Prot... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T10:11:53.210",
"Id": "44244",
"Score": "8",
"Tags": [
"python",
"json",
"api",
"django"
],
"Title": "Django API Implementation"
} | 44244 |
<p>When running Code Analysis on my project I get the following warning:</p>
<blockquote>
<p>CA2202 : Microsoft.Usage : Object 'fs' can be disposed more than once in method</p>
</blockquote>
<p>I don't see the problem, and the code compiles fine and produces the expected results in all test cases.
If I remove the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T10:39:36.010",
"Id": "76675",
"Score": "5",
"body": "The normal way to use `IDisposable` objects is `using (FileStream fs = new FileStream(…)) { … }`, which removes much ugliness from that code."
},
{
"ContentLicense": "CC B... | [
{
"body": "<p>As @amon mentioned, the correct way of referencing <code>IDisposable</code> Objects in C# is the using-statement.</p>\n\n<p>In general you then have the try-catch block around the using statement to catch eventual initialization errors. This means your Code would look somewhat like this:</p>\n\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T10:24:55.377",
"Id": "44245",
"Score": "3",
"Tags": [
"c#",
"memory-management"
],
"Title": "MS CA2202: Object can be disposed more then once"
} | 44245 |
<p>I am relatively new to Perl and would like to check that the code I am writing docent have any major flaws in it or any bad practices.</p>
<p>This is a fairly simple sub but one that gets used often. Seems to work OK. Simply reads a text file that has parameters in it set by the user.</p>
<p>Config.txt</p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T11:11:49.423",
"Id": "76681",
"Score": "2",
"body": "Can you use CPAN modules? If yes (and it's not an excercise) use [`Config::Tiny`](https://metacpan.org/pod/Config::Tiny) or another module for reading ini files."
},
{
"Co... | [
{
"body": "<p>Well, here is how I'd write that subroutine. I thoroughly commented the code to explain my choices.</p>\n\n<pre class=\"lang-perl prettyprint-override\"><code>use strict;\nuse warnings;\nuse autodie; # automatic error handling for \"open\" and other builtins\nuse IO::Handle; # object oriented... | {
"AcceptedAnswerId": "44264",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T10:46:00.127",
"Id": "44246",
"Score": "3",
"Tags": [
"beginner",
"perl",
"file"
],
"Title": "Reading a config file"
} | 44246 |
<p>I want to find total word count in string. I have two methods as mentioned below.</p>
<pre><code>public static int Wordcount(string strName)
{
bool wordfound;
int ctr = 0;
for (int i = 0; i < strName.Length; )
{
wordfound = false;
while ((i < strName.Length) && (strNa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T12:31:18.983",
"Id": "76689",
"Score": "0",
"body": "Did you write those? What do you think?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T13:37:25.873",
"Id": "76698",
"Score": "0",
"bo... | [
{
"body": "<p>Let's analyze each approach:</p>\n\n<pre><code>public static int Wordcount1(string strName)\n{\n string temp = null;\n int ctr = 0;\n\n for (int i = 0; i < strName.Length; i++)\n {\n if (strName[i] != ' ')\n {\n if (temp == null)\n ctr++;\n\n ... | {
"AcceptedAnswerId": "44255",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T12:25:50.800",
"Id": "44250",
"Score": "3",
"Tags": [
"c#",
"strings",
"parsing"
],
"Title": "Which approach is preferable string parsing?"
} | 44250 |
<p>The array size is <= 16. The difference is defined as:</p>
<pre><code>diff[i] = array[i+1] - array[i];
</code></pre>
<p>I need to find the number of permutations of the original array, which have a difference that is a permutation of the difference of the original array.</p>
<p>This is my code:</p>
<pre><code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:38:09.120",
"Id": "76732",
"Score": "0",
"body": "Can you please provide some examples of input/output ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T17:48:06.117",
"Id": "76790",
"Score... | [
{
"body": "<p>You are using a class just to be able to able to mess with some kind of global values. This makes your code very hard to understand. It took me a while to unroll it all and get the following code :</p>\n\n<pre><code>import java.util.Scanner;\n\npublic class Main {\n\n public static void main(St... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T12:59:50.263",
"Id": "44253",
"Score": "0",
"Tags": [
"java",
"performance",
"combinatorics"
],
"Title": "Finding the number of permutations of an integer array with equaling diff... | 44253 |
<p>I have this currently working code, but it's extremely slow. I'm talking almost an hour to execute, if it executes at all (our server isn't all that great to start with). Is there a better way to write this?</p>
<p>Basically, I am wanting to return the Top 5 parts, that match a distinct pattern code within the same... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T14:32:06.297",
"Id": "76714",
"Score": "1",
"body": "If a query ever takes more than 30s to run, it's not being correctly done. (Usually, 1s is the limit for \"something is fishy\".)"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>You have three problems that I can see. Two performance, and one logic. In least-to-most significant order:</p>\n<ol>\n<li>Performance: You should no use the <code>NOT LIKE 'NOT FOUND'</code> statement, it should be <code> <> 'NOT FOUND'</code></li>\n<li>Potential logic problem: You should h... | {
"AcceptedAnswerId": "44267",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T13:39:25.383",
"Id": "44256",
"Score": "8",
"Tags": [
"performance",
"sql",
"sql-server",
"cursor"
],
"Title": "Return the top 5 of each kind of record"
} | 44256 |
<p>I'd like comments on the following code, explanations, etc. are given in the javadoc:</p>
<pre><code>package ocr.base;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.fi... | [] | [
{
"body": "<h2>Duration.of</h2>\n\n<p>With switch statements I find it <em>pleasing</em> to return-early, and avoid multiple lines of code. With switch statements especially, the early-return removes the need for an ugly <code>break</code> as well. Consider this method:</p>\n\n<pre><code> public static Durati... | {
"AcceptedAnswerId": "44318",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T13:56:05.060",
"Id": "44257",
"Score": "4",
"Tags": [
"java"
],
"Title": "Implementation of directory checking in Java 8"
} | 44257 |
<p>I have a small animation with Raphael using a large amount of code. Is there any way to reduce it?</p>
<p><a href="http://jsfiddle.net/V54hR/1/" rel="nofollow">Demo</a></p>
<pre><code>window.onload = function () {
var elements = document.querySelectorAll('.colbr');
for (i=0; i<elements.length; i++) {
... | [] | [
{
"body": "<p>I really like what you wrote there, though I am afraid at this point you ought to expand the code, not reduce it.</p>\n\n<ul>\n<li><code>r</code>, <code>r1</code>, <code>r2</code>, <code>cx</code>, <code>cy</code>, <code>beta</code> are all variables that need better ( more meaningful ) names</li>... | {
"AcceptedAnswerId": "44282",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:03:30.620",
"Id": "44261",
"Score": "3",
"Tags": [
"javascript",
"reinventing-the-wheel",
"raphael.js",
"animation"
],
"Title": "Small animation with Raphael"
} | 44261 |
<p>Please let me know what you think. Is the code well written? Am I using best practices (like when I chose <code>===</code> over <code>==</code>)? Is my script too verbose?</p>
<p>Note: I'm only asking because the tutorial I'm using is a little old.</p>
<pre><code>/* A login script to that checks two users and th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:21:41.577",
"Id": "76727",
"Score": "0",
"body": "I would add a bit of information in your post. What are looking for in a review (We do general stuff but is there something specific) ? Having a comment in the code explaining wha... | [
{
"body": "<p>This is tagged <a href=\"/questions/tagged/programming-challenge\" class=\"post-tag\" title=\"show questions tagged 'programming-challenge'\" rel=\"tag\">programming-challenge</a>, but just to be sure it's said: This obviously is <strong>not</strong> secure in any sense; the passwords are ... | {
"AcceptedAnswerId": "44276",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:13:15.290",
"Id": "44262",
"Score": "3",
"Tags": [
"javascript",
"beginner",
"html",
"programming-challenge",
"authentication"
],
"Title": "Login script that checks ... | 44262 |
<p>I am making this program that is going to calculate distance from randomly generated dots (with x and y coordinates) to 5 bigger ones and then its going to put each smaller dot into the group with bigger one that is nearest to it. So, i am making this with classes and every dot is made as an object. I made 2 arrays ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:25:28.013",
"Id": "76729",
"Score": "1",
"body": "This looks rather like Java. C# has properties, which are quite convenient for what you're doing, and has the convention that public members are PascalCase."
},
{
"Content... | [
{
"body": "<p>for OOP practice - its best to go from small to big.</p>\n\n<p>i.e.: a dot is x,y, the group is a collection of dot.</p>\n\n<p>And you are correct - regardless of syntax (ie programming language) this concept of nested/inheritance (aka subclass) is sometimes harder to pick from.</p>\n\n<p>the bott... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:14:11.030",
"Id": "44263",
"Score": "4",
"Tags": [
"c#",
"object-oriented",
"classes"
],
"Title": "Nested class or two separate classes?"
} | 44263 |
<p>I wanted to avoid running the code <code>HttpContext.Current.Server.MapPath</code> every time <code>file_path_includes</code> is called.</p>
<p>Is the below an effective way of doing so?</p>
<pre><code>private static string file_path_includes_;
public static string file_path_includes
{
get
{
if (fi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:53:27.163",
"Id": "76736",
"Score": "0",
"body": "This definitely looks like a valid way to lazily initialize a property, though I'm not a fan of the naming style."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<p>Is it best to initialize a static member once, in a static constructor. If that is not possible, then a lazy initialization can be done like this. (Similar code to yours, just using the null coalescing operator.)</p>\n\n<pre><code>private static string file_path_includes_;\n\npublic static string ... | {
"AcceptedAnswerId": "44268",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:46:19.397",
"Id": "44265",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Is it effective to use get; set; to avoid redundant processes?"
} | 44265 |
<p>I have created a small crypto extension and I want a deep review of it, such as possible fixes (for hidden problems) and tweaks...</p>
<ul>
<li><p>1- Crypto.cs</p>
<pre><code>public static class Crypto
{
public static Salt Salt = new Salt();
public static string GetMd5Hash(this string input)
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T20:19:00.403",
"Id": "76821",
"Score": "0",
"body": "I can think of a small enhancement. You could make overloads for `GetMd5Hash()` and any other method that uses hardcoded encodings such as UTF8, hex or base64. You could specify t... | [
{
"body": "<p>Lots and lots of badness. Please don't write crypto before you've spend some effort studying crypto. Take a look at jbtule's answer to <a href=\"https://stackoverflow.com/a/10366194/445517\">Encrypt/Decrypt string in .NET</a> for how to symmetric encryption.</p>\n\n<ol>\n<li><p>I don't get the wha... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:53:54.173",
"Id": "44266",
"Score": "3",
"Tags": [
"c#",
"cryptography"
],
"Title": "Cryptographic Extensions"
} | 44266 |
<p>Here is a code that guesses the number chosen by the user. I know that using goto is a bad practice, but it seems unavoidable here.</p>
<p>that's because using <code>do while</code> doesn't work, for example:</p>
<pre><code>do{
scanf("%c",&variable);
}while(variable == 'a' || variable = 'b' || variable = ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T16:15:47.043",
"Id": "76747",
"Score": "2",
"body": "If `goto` is inevitable, a label named `fff:` has to be ;)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T17:29:59.220",
"Id": "76783",
"S... | [
{
"body": "<p>Bad things happen when you use use GOTO.....</p>\n\n<p><a href=\"http://xkcd.com/292/\" rel=\"nofollow noreferrer\"><img src=\"https://i.stack.imgur.com/XEmOx.png\" alt=\"Velociraptor\"></a></p>\n\n<p>The problem with your while loop is that you are using <code>=</code> instead of <code>==</code> ... | {
"AcceptedAnswerId": "44271",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:57:10.533",
"Id": "44269",
"Score": "6",
"Tags": [
"c"
],
"Title": "Mini mind reader"
} | 44269 |
<p>I am beyond stuck in a half way point between PHP structural and OOP, but I can never achieve proper SOLID patterns despite reading DI, IOC, and reading about the interfaces.</p>
<p>Rather than to read logical examples (i.e. a storage class that takes a book class and you typecast an interface etc...). I want to k... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T17:06:42.400",
"Id": "76775",
"Score": "0",
"body": "There are lots of options, but this can be a bit tricky to optimize right as it depends a bit on how the class gets used. If you are storing _a lot_ of data, most of which never g... | [
{
"body": "<p>Reading through this code and your goals, it seems this class has two responsibilities:</p>\n\n<ul>\n<li>Provide a Key-Value store</li>\n<li>Get data from the database (potentially with caching)</li>\n</ul>\n\n<p>To make it more SOLID, you can pick one of these responsibilities for this class and ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T15:58:25.663",
"Id": "44270",
"Score": "3",
"Tags": [
"php",
"object-oriented",
"mysql",
"dependency-injection"
],
"Title": "Going from Spaghetti PHP OOP to SOLID OOP"
} | 44270 |
<blockquote>
<p>If we take 47, reverse and add, <code>47 + 74 = 121</code>, which is palindromic.</p>
<p>Not all numbers produce palindromes so quickly. For example,</p>
<pre><code>349 + 943 = 1292,
1292 + 2921 = 4213
4213 + 3124 = 7337
</code></pre>
<p>That is, 349 took three iterations to arrive at a pal... | [] | [
{
"body": "<h2>Hints</h2>\n\n<ol>\n<li><p>According to the example in the problem description, 349 is not a Lychrel number. As a hint for speeding things up, I'd like to point out that the example computation might also tell you something about, say, the number 1292.</p>\n\n<p>What I'm trying to say is that whe... | {
"AcceptedAnswerId": "44402",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T16:32:13.253",
"Id": "44272",
"Score": "7",
"Tags": [
"python",
"performance",
"programming-challenge",
"palindrome"
],
"Title": "Lychrel calculator (Project Euler 55)"
} | 44272 |
<p>This code was already reviewed, but the reviewer missed many points of my code. Most of the following question is from the previous review.</p>
<p>I have written a system for handling the dispatch of events between objects. I need this functionality for a larger project I am working on. <strong>Objects should be ab... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T17:27:06.987",
"Id": "76781",
"Score": "0",
"body": "One performance issue I see is that your `EventManager` uses a single `lockCount` variable, meaning that _every_ list is locked if I'm adding or removing. This would serialize wri... | [
{
"body": "<ol>\n<li><p>If I'm right you're planning to use these classes from multiple threads. If that's the case you should do some synchronization or use thread-safe classes to make it thread-safe.</p></li>\n<li><p>There are <a href=\"https://stackoverflow.com/q/10218895/843804\">existing event handling lib... | {
"AcceptedAnswerId": "44345",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T16:49:38.113",
"Id": "44273",
"Score": "4",
"Tags": [
"java",
"event-handling"
],
"Title": "Event Handling system in Java - follow-up"
} | 44273 |
<p>I've been programming with Python 2.7 for about six months now and if possible, I'd like some critique to see what I might have done better or what I might be doing wrong.</p>
<p>My objective was to make a script scraper that finds variables and functions, outputting them to a text file along with their line number... | [] | [
{
"body": "<p>A couple of suggestions:</p>\n\n<hr>\n\n<p><code>make_readable</code> has a very serious problem - what if two inputs have the same length? A dictionary can only have one value per key; I suggest making it a dictionary of lists of items (or a <code>collections.defaultdict(list)</code>) instead. Al... | {
"AcceptedAnswerId": "44279",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T17:06:24.410",
"Id": "44275",
"Score": "1",
"Tags": [
"python",
"optimization",
"python-2.x"
],
"Title": "Script scraper for outputting variables and functions to a text file"
... | 44275 |
<p>This is about my first backbone.js application. It is a small directory that fetches data and presents it in a search-like UI. </p>
<p><a href="http://nativomorphosis.cl/prui/index.html">Here</a> is a working (minified) example.</p>
<p>Here is the file that handles everything</p>
<pre><code>window.Directory = fun... | [] | [
{
"body": "<p>Interesting code. As you might have guessed, there's a lot wrong with it.</p>\n\n<ul>\n<li>Events instead of chaining. Makes it harder to follow the code, makes it harder on IDE's that know how to jump to a function, no added benefits. You have <code>this</code> basically as a holder of global va... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T18:11:55.933",
"Id": "44283",
"Score": "10",
"Tags": [
"javascript",
"backbone.js"
],
"Title": "Directory Searcher"
} | 44283 |
<p>Is there a better way to pass variables into a class?</p>
<pre><code>public class Truck
{
private int _wheels;
private string _color;
private bool _loaded;
public int wheels { get { return _wheels; } }
public string color { get { return _color; } }
public bool loaded { get { return _loaded; ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T18:49:38.537",
"Id": "76800",
"Score": "2",
"body": "This is a very effective way to make an immutable `Truck` class. What is it that you have a problem with?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014... | [
{
"body": "<p>A few observations.</p>\n\n<ol>\n<li><p>Properties should be PascalCase.</p>\n\n<pre><code>public class Truck\n{\n // ...\n public int Wheels { get {return _wheels; } }\n\n // ...\n}\n</code></pre></li>\n<li><p>The <code>this</code> keyword is not needed here. by having the '_' in front ... | {
"AcceptedAnswerId": "44290",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T18:43:25.013",
"Id": "44286",
"Score": "5",
"Tags": [
"c#",
"object-oriented"
],
"Title": "Truck class constructor"
} | 44286 |
<p>I have the following code which basically takes a list of sorted integer arrays and merges them together removing the duplicates. </p>
<p>I have tried to do the complexity analysis and came to a rough conclusion that it may be O(n<sup>2</sup>) order. Could you please see if my understanding is correct here. </p... | [] | [
{
"body": "<p>If <code>N == number of input arrays</code> and <code>M == length of the longest input array</code> then your outer while loop will run <code>M</code> times with the check condition being <code>O(N)</code> so your outer loop is O(M<em>N)<code>. The inner loop runs</code>N<code>times and the heap i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T18:51:36.280",
"Id": "44287",
"Score": "4",
"Tags": [
"c#",
"queue",
"complexity"
],
"Title": "Big-O complexity calculation for a merge and sort function"
} | 44287 |
<p>I'm writing a simple remote PC app (mouse-keyboard). Android is the client and is connected with WiFi to Java PC Server. I'm using TCP but I see a bit of latency compared to other remote apps. I'm sending a String to Server like these: "a","B","2".</p>
<p>Why am I getting latency sometimes? When I press any key, so... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T23:39:28.417",
"Id": "76849",
"Score": "0",
"body": "Please do not remove the code that was originally posted. The below answer corresponds to that code, so it should remain."
}
] | [
{
"body": "<p>The performance problem is still related to creating a socket each time you want to send data.</p>\n\n<p>Here is a revised version of your code... note how the socket is kept open all the time (unless there is a failure, at which point it will re-connect....):</p>\n\n<pre><code>Socket sockClient =... | {
"AcceptedAnswerId": "44293",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T19:05:01.760",
"Id": "44289",
"Score": "5",
"Tags": [
"java",
"android",
"networking",
"tcp"
],
"Title": "Latency problem for keyboard remoting from Android phone - follow ... | 44289 |
<p>This is just some test code I'm doing to learn C++11. It compiles and runs consistently. But is anything wrong that will eventually (or under slightly different circumstances) fail?</p>
<p>Besides additional refactoring for sheer cleverness, are there any notable improvements that can be made to remove lines (lik... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T18:04:08.067",
"Id": "77147",
"Score": "0",
"body": "Is this really working code? [`DnsRecordListFree`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682021.aspx) is documented to take two parameters, but you only pass o... | [
{
"body": "<p>As it stands, the code is somewhat fragile. It only builds as a wide-character build (i.e., with UNICODE and/or _UNICODE defined). I'd prefer to see code explicitly define things that need to be wide characters as wide characters.</p>\n\n<p>I'm also seeing the same problem with <code>DnsFree</code... | {
"AcceptedAnswerId": "45177",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T19:24:15.560",
"Id": "44291",
"Score": "6",
"Tags": [
"c++",
"c++11",
"memory-management",
"winapi"
],
"Title": "WinAPI code for DNS queries"
} | 44291 |
<p><a href="https://projecteuler.net/problem=3">Project Euler problem 3</a> asks for the largest prime factor of 600851475143.</p>
<p>I have gone from 96 lines to 17 lines taking hits at this one. This is what I am left with after all of that effort:</p>
<pre><code>public class IntegerFactoriseFive {
public sta... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T11:35:35.743",
"Id": "76897",
"Score": "0",
"body": "How has no one mentioned the upper bound of the search space is much lower: `i<(int)Math.sqrt(n);`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T... | [
{
"body": "<p>Reduce the number of System.out.println calls may give a little speedup:</p>\n\n<pre><code>public class IntegerFactoriseFive {\n\n public static void main(String[] args)\n {\n StringBuilder sb= new StringBuilder();\n long n = 600851475143L;\n for (long i = 2; i <= n; ... | {
"AcceptedAnswerId": "44305",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T20:33:48.110",
"Id": "44300",
"Score": "6",
"Tags": [
"java",
"performance",
"primes",
"project-euler"
],
"Title": "Speeding up my implementation of Project Euler #3"
} | 44300 |
<p>Someone asked if their singleton is good for OOP:</p>
<p><a href="https://codereview.stackexchange.com/questions/39382/using-a-singleton-class-to-get-and-set-program-wide-settings/44298#44298">Using a singleton class to get and set program wide settings</a>.</p>
<p>However, the answer just provides tweaks to his e... | [] | [
{
"body": "<p>I personally use defines for for settings rather than utilising arrays. </p>\n\n<p>A singleton is the correct route to go down and to help reduce your code and array you may want to use external files. </p>\n\n<p>This is my config loader class with some simple caching that supports both database a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T20:47:02.820",
"Id": "44301",
"Score": "8",
"Tags": [
"php",
"object-oriented",
"mysql"
],
"Title": "How is OOP achieved with configuration files in PHP?"
} | 44301 |
<p>This draws blocks on the screen from a grid to make a background for my game. I am wondering if anyone has any suggestions on optimizing it for speed.</p>
<pre><code>int blockwidth=blocksize-2;
//Draw coloured blocks
for (int x=0;x<sizex;x++){
int screenx=-(int)camerax+(x*blocksize);
if (screenx>-blo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T07:41:44.107",
"Id": "76877",
"Score": "0",
"body": "In which method is this? I assume `paintComponent` or similar? Have you checked how often that method is called? How often does the tiles actually change?"
},
{
"ContentLi... | [
{
"body": "<p>There are a few optimizations I can see in your code.</p>\n\n<ol>\n<li><p>creating a new Color every time is a little severe. You can do a few things here, for example, if your color palette is limited, then cache the individual Color instances. I know it sounds petty right now, but, when you add ... | {
"AcceptedAnswerId": "44317",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T22:51:49.050",
"Id": "44307",
"Score": "2",
"Tags": [
"java",
"game",
"graphics"
],
"Title": "Drawing blocks for a 2D game background"
} | 44307 |
<p>For practicing reasons I would like to write a method which inserts a character into a string.</p>
<p>I would like to know:</p>
<ol>
<li><p>What is the best practice concerning placement of a comment within methods? For example, is the way that I commented about what raises an exception fine, or are there better ... | [] | [
{
"body": "<ol>\n<li><p>The Javadoc style headers you have provided for this method are already more than enough. If you are adding comments to your method it should only be either for API documentation, or where the code is sufficiently complex to warrant an explanation that you cannot provide by simplifying o... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-13T23:30:10.823",
"Id": "44309",
"Score": "6",
"Tags": [
"java",
"strings",
"exception",
"immutability"
],
"Title": "Insert a character into a string"
} | 44309 |
<p>I'm creating a location-based reminder application in Android using proximity alerts, geocoder, Google Maps API and their Places API.</p>
<p>Currently there is a default <code>ListView</code> using a Cardlibs library and a button for a new reminder, which then asks for the 'subject' and 'location'. There is a butto... | [] | [
{
"body": "<h2>Reminder</h2>\n\n<ul>\n<li><p>there is no reason to have your Reminder fields <code>latitude</code>, <code>longitude</code>, .... as public fields, and there are good reasons to keep them private. You already have the getters and setters for them.</p></li>\n<li><p>The Parcelable constructor shoul... | {
"AcceptedAnswerId": "44316",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T01:40:59.220",
"Id": "44314",
"Score": "4",
"Tags": [
"java",
"object-oriented",
"android",
"database"
],
"Title": "Location-based reminder application"
} | 44314 |
<p>I have a method that reverse each word in a string. I want to know how I can increase it's performance and memory efficiency. Ideas I had in mind were simply using <code>char[]</code> instead of strings being that strings are immutable and each time I concatenate the Strings, I am creating a new String object which ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T06:05:24.130",
"Id": "76869",
"Score": "0",
"body": "possible duplicate of [Reversing words in a string](http://codereview.stackexchange.com/questions/37364/reversing-words-in-a-string)"
},
{
"ContentLicense": "CC BY-SA 3.0"... | [
{
"body": "<ol>\n<li><blockquote>\n <p>Ideas I had in mind were simply using char[] instead of strings being that strings are immutable and each time I concatenate the Strings, I am creating a new String object which is not efficient at all.</p>\n</blockquote>\n\n<p>Yes, that will be faster. Go ahead and write... | {
"AcceptedAnswerId": "44339",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T05:28:10.453",
"Id": "44320",
"Score": "7",
"Tags": [
"java",
"performance",
"strings"
],
"Title": "Reverse word by word efficiency"
} | 44320 |
<p>Could you please see if they are no bugs in this implementation? I am especially interested in knowing if there could be here any multithreading problems (such as race conditions).</p>
<p>It is written in C# for .NET 3.5.</p>
<pre><code>public interface IAsyncOperation
{
OperationToken Token { get; }
bool... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T14:35:11.427",
"Id": "76937",
"Score": "0",
"body": "As far as you can tell, does the code seem to work as expected?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T15:33:15.367",
"Id": "76949",
... | [
{
"body": "<ol>\n<li><p>For this:</p>\n\n<blockquote>\n<pre><code>protected void Complete()\n{\n if (!IsCompleted)\n {\n lock (CompletionLock)\n {\n if (!IsCompleted)\n {\n IsCompleted = true;\n Monitor.PulseAll(CompletionLock);\n ... | {
"AcceptedAnswerId": "44365",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T07:52:05.843",
"Id": "44326",
"Score": "6",
"Tags": [
"c#",
"multithreading"
],
"Title": "Simple asynchronous operation implementation"
} | 44326 |
<p>I've been programming for about 4 months now, just trying to learn by myself. I've tried my way with coding the Game of Life here, would like some general feedback as well as some pointers on how I can speed it up because right now it seems to run incredibly slowly. Keep in mind I'm a newbie so I would like some ea... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T12:10:52.610",
"Id": "76912",
"Score": "0",
"body": "I updated my answer after you accepted it, to point out another bug."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T15:19:00.670",
"Id": "7694... | [
{
"body": "<p>It looks well-written.</p>\n\n<hr>\n\n<p>You're hard-coding <code>10</code> in several places. What if you want to change it to <code>12</code>, or (worse) to <code>12.33333</code>? Instead of storing <code>Rect</code> and <code>Point</code> in <code>Cell</code>, I'd suggest storing the zero-based... | {
"AcceptedAnswerId": "44334",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T08:19:08.333",
"Id": "44327",
"Score": "7",
"Tags": [
"c#",
"object-oriented",
"beginner",
"game-of-life"
],
"Title": "Feedback on my Conway's Game of Life"
} | 44327 |
<p>To learn tree traversal i implemented <a href="http://docs.python.org/2/library/os.html#os.walk" rel="nofollow noreferrer"><code>os.walk</code></a>, <a href="http://en.wikipedia.org/wiki/Tail_call" rel="nofollow noreferrer">tail-recursive</a> and stack-based. Unfortunately Python doesn't support tail call optimizati... | [] | [
{
"body": "<p>Does this help? In your walk_iter, instead of using pop, grab the first element of the stack. Then do something like this ...</p>\n\n<pre><code>if first_element_has_sub_elements:\n new_stack = stack[0][1]\n new_stack.extend(stack[1:])\n stack = new_stack[:]\nelse:\n stack = stack[1:]\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T08:34:11.007",
"Id": "44328",
"Score": "6",
"Tags": [
"python",
"functional-programming",
"recursion",
"tree",
"stack"
],
"Title": "Functional, but not recursive, tree tra... | 44328 |
<p>I have a navigation controller set up with a user code and password and a log in button. When the user clicks on the Log In button or the return key on the keyboard on the password text box - the program checks if the user code and / or password is blank. It then goes off and calls a Web API running on a server to s... | [] | [
{
"body": "<p>Here is what I see in your code :</p>\n\n<h2>In <code>-(IBAction)txtUserDidEndOnExit:(id)sender</code></h2>\n\n<p>You don't need to <code>resignFirstResponder</code> before you make another view become first responder. Right now, the keyboard probably quickly hides/shows when you press the return ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T09:30:14.603",
"Id": "44329",
"Score": "6",
"Tags": [
"beginner",
"objective-c",
"ios",
"validation",
"cocoa-touch"
],
"Title": "iOS App - Interface for user log in using ... | 44329 |
<p>I've created a program to calculate Pascal's triangle:</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
void pascal(int limit)
{
int *begin;
begin=(int*)malloc(2*sizeof(int));
*begin=1;
*(begin+1)=1;
int* p,q,s,t;
int row=2,n=3,x;
p=begin;
q=begin+1;
for(n=3;n<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T10:04:21.440",
"Id": "76886",
"Score": "0",
"body": "Please format your code!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T10:09:08.350",
"Id": "76887",
"Score": "0",
"body": "Can someo... | [
{
"body": "<ul>\n<li><p>you don't free <code>s</code> which means you have a memory leak</p></li>\n<li><p><code>*(begin+1)</code> can be rewritten as <code>begin[1]</code>, which is much clearer</p></li>\n<li><p>1 char variable names are very hard to get into, use longer/descriptive names where needed</p></li>\... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T09:44:32.723",
"Id": "44330",
"Score": "10",
"Tags": [
"c",
"array",
"memory-management",
"pointers"
],
"Title": "Pascal Triangle program in C"
} | 44330 |
<p>Just a slug generator. I'm wondering if this can be simplified any further.</p>
<p>Many thanks.</p>
<pre><code><?php
function slug($string) {
// Replace all non letters, numbers, spaces or hypens
$string = preg_replace('/[^\-\sa-zA-Z0-9]+/', '', mb_strtolower($string));
// Replace spaces and dupli... | [] | [
{
"body": "<ol>\n<li><p>You could create a few explanatory local variables:</p>\n\n<pre><code>$lettersNumbersSpacesHypens = '/[^\\-\\sa-zA-Z0-9]+/';\n$spacesAndDuplicateHyphens = '/[\\-\\s]+/';\n</code></pre>\n\n<p>Usage:</p>\n\n<pre><code>$lettersNumbersSpacesHypens = '/[^\\-\\sa-zA-Z0-9]+/';\n$slug = preg_rep... | {
"AcceptedAnswerId": "44347",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T11:05:13.510",
"Id": "44335",
"Score": "4",
"Tags": [
"php",
"strings"
],
"Title": "Slug URL Generator"
} | 44335 |
<p>I have a list of months in which users are required to update some data. I want to determine at what date they should have updated their data. They must update in March, May and August. If today is March, I want to get back the 1st of March. If today is February, I want to get back last year's August. In reality the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T11:56:41.963",
"Id": "76908",
"Score": "0",
"body": "What if list of months is empty?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T12:19:57.047",
"Id": "76914",
"Score": "0",
"body": "T... | [
{
"body": "<p>You could use <a href=\"http://msdn.microsoft.com/en-us/library/system.datetime.addmonths%28v=vs.110%29.aspx\" rel=\"nofollow\"><code>DateTime.AddMonths</code></a> to simplify the code:</p>\n\n<pre><code>for (int i = 0; i < 12; i++) {\n var checkDate = curDate.AddMonths(-i))\n if (listOfM... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T11:50:49.473",
"Id": "44338",
"Score": "6",
"Tags": [
"c#",
"algorithm",
"linq",
"datetime"
],
"Title": "Determining expiration date based on list of months in which to refres... | 44338 |
<pre><code>var root = this;
root.node = function(path, type) {
root.type = type;
this.type = type;
this.parents = [];
this.children = [];
var components = path.split('/');
this.parents = parseParents(components);
this.name = components[components.length - 1];
this.addChild = function(path, type){
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T12:56:25.673",
"Id": "76926",
"Score": "1",
"body": "If leaf items are not populated and it goes into an infinite loop, then your code does not work and hence does not belong on CR."
}
] | [
{
"body": "<p>Not sure this question is valid, but there is reviewable code:</p>\n\n<ul>\n<li><code>node</code> is a constructor, it should be named with an uppercase <code>N</code></li>\n<li><code>curretnChild</code> is not properly spelled, and not used anywhere, drop it</li>\n<li>Since you set <code>parents<... | {
"AcceptedAnswerId": "44348",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T12:51:00.680",
"Id": "44344",
"Score": "2",
"Tags": [
"javascript",
"linked-list",
"file-system"
],
"Title": "Directory tree representation with double linked list"
} | 44344 |
<p>I'm extremely new to Python, and the Twitter API, but I found an example online that walked me through the process. Now that I've been playing around with it for awhile, I've begun to push the limits of what my laptop can handle in terms of processing power with my current code. I was hoping someone here could check... | [] | [
{
"body": "<ul>\n<li><p>Put all <code>import</code> statements at the top.</p></li>\n<li><p>You might leak a file descriptor, since you call <code>open(sys.argv[1])</code> without closing it. (Whether a leak actually occurs depends on the garbage collector of your Python implementation.) Best practice is to u... | {
"AcceptedAnswerId": "44410",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T13:27:35.613",
"Id": "44349",
"Score": "7",
"Tags": [
"python",
"beginner",
"csv",
"twitter"
],
"Title": "Printing out JSON data from Twitter as a CSV"
} | 44349 |
<p>I have recently forked/rewritten a SEDE query (<a href="http://data.stackexchange.com/codereview/query/174384/avid-users-rep-score-targets" rel="nofollow noreferrer">here</a>) that aims at figuring out where a site stands in terms of avid users and distribution of reputation scores, compared to a specific target (nu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T14:31:11.510",
"Id": "76936",
"Score": "4",
"body": "you should fix the indentation of the `q` query"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T17:58:12.713",
"Id": "76998",
"Score": "0",... | [
{
"body": "<p>It's a good habit to end each statement with an explicit semicolon.</p>\n\n<hr>\n\n<p>The innermost query <code>q</code> generates one row for each recent user. Since you have no interest in individual users, and only want counts and sums, you can collapse the two innermost queries <code>q</code>... | {
"AcceptedAnswerId": "44374",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T14:20:58.623",
"Id": "44353",
"Score": "7",
"Tags": [
"performance",
"sql",
"sql-server",
"t-sql",
"stackexchange"
],
"Title": "Aggregating Conditional Sums"
} | 44353 |
<p>We have two C-strings and for their concatenation we need to know the size of resulting string. And we want to calculate it at compilation stage. How can I improve this solution? </p>
<pre><code>char s1[] = "string1";
char s2[] = "string2";
constexpr auto SIZE =
sizeof(s1) / sizeof(*s1) + sizeof(s2) / sizeof(*s2) ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T16:27:44.603",
"Id": "76971",
"Score": "0",
"body": "In what way do you want to improve it? What's wrong with `char ss[] = \"string1 string2\";`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T16:32:... | [
{
"body": "<p>You could use a macro, for example <a href=\"https://stackoverflow.com/q/4415524/49942\">one of these ones</a>.</p>\n\n<p>And you shouldn't need to add <code>2</code>: because <code>sizeof</code> should already include the terminating <code>'\\0'</code> of each string. However you could add a comm... | {
"AcceptedAnswerId": "44372",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T15:02:14.477",
"Id": "44354",
"Score": "0",
"Tags": [
"c++",
"c",
"strings",
"c++11"
],
"Title": "Handling C-like strings in C++11"
} | 44354 |
<p>I have written a method that checks if <code>n</code> number of <code>true</code> <code>booleans</code> are present in a <code>boolean[]</code> array. Then I improved it to var args format which is as follows:</p>
<pre><code>public static boolean checkNTrue(int n, boolean... args) {
assert args.length > 0;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T03:49:56.227",
"Id": "77082",
"Score": "2",
"body": "Why assert that `args.length > 0`? If `args`has zero length, why not just return `n == 0`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-23T06:21:06... | [
{
"body": "<p>Premature optimization is a bad idea. Before you try to optimize anything, run a profiler to measure where your bottlenecks are. Unless you are running this function in a tight loop, it's unlikely that this function will be a bottleneck.</p>\n\n<p>The special cases that you would introduce don't... | {
"AcceptedAnswerId": "44358",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T15:34:04.140",
"Id": "44357",
"Score": "12",
"Tags": [
"java",
"optimization",
"design-patterns"
],
"Title": "Optimizing boolean checking method"
} | 44357 |
<p>Bit of background info first - I've been struggling with a problem for a while now. How could you have one single event handler to handle every control (or all of a particular type of control) on a form? I've never been able to find a complete solution online either. The two 'easy' methods have glaring issues. For s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T16:20:18.767",
"Id": "76968",
"Score": "1",
"body": "If anyone's wondering what the hungarian notation means: `i` this variable shouldn't be changed once initially set ('immutable'); `m` this variable is expected to be changed ('mut... | [
{
"body": "<p>I don't have lots of time, so I'll just make a couple of points:</p>\n\n<ul>\n<li>Drop the \"Hungarian\" notation altogether, it's not doing you any good. Instead declare variables close to their usage, and strive to keep procedures < 25 lines.</li>\n<li>If you <em>have to</em> stick to that no... | {
"AcceptedAnswerId": "44390",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T16:15:04.223",
"Id": "44361",
"Score": "11",
"Tags": [
"vba",
"ms-access"
],
"Title": "Form controls - Single event handler for multiple controls, without sacrifices"
} | 44361 |
<p>The following code is for mapping a dataRecord to a class. I don't like this solution since it requires to duplicate the logic of mapping for each field in every method which access to the same table.</p>
<p>What do you think about? What about using automapper?</p>
<pre><code>public IEnumerable<Model.Accounts.U... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T16:53:57.187",
"Id": "76983",
"Score": "1",
"body": "`Avoiding code duplication in mapping layer between dataRecord and` and what ?"
}
] | [
{
"body": "<p>I believe the easiest way to avoid duplication each time you read from the database is to create a <code>constructor</code> which receives a <code>DataRecord</code> as a parameter, and does the heavy lifting:</p>\n\n<pre><code>public class User {\n\n public User() {}\n\n public User(DataReco... | {
"AcceptedAnswerId": "44363",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T16:20:09.473",
"Id": "44362",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Avoiding code duplication in mapping layer between dataRecord and"
} | 44362 |
<p>I'm working on Google Book API to post a book's basic information. I notice that some of the books will always miss a value or two under <code>volumeInfo</code>, like this book <strong>(<a href="http://jsfiddle.net/KU7Zx/21/" rel="nofollow">Fiddle</a>)</strong> that has no publisher value. Do I need to repeat <code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T18:14:02.360",
"Id": "77005",
"Score": "0",
"body": "Please indent your code properly. In it's current form it's unreadable."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T18:26:39.140",
"Id": "7... | [
{
"body": "<p>You can define a hash of the possible field names and loop through them:</p>\n\n<pre><code>var fieldTitles = {\n description: \"Description\",\n Rating: \"Average Rating\",\n RatingCount: \"Rating Count\"\n};\n\nvar volumeInfo = item.volumeInfo;\nfor (var key in fieldTitles) {\n if (vo... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T16:43:06.070",
"Id": "44366",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"parsing",
"json"
],
"Title": "How to handle JSON's undefined value in a better way?"
} | 44366 |
<p>Is there any way to simplify the following C# helper class to numerate a string for Json.Net?</p>
<pre><code>internal static string CreateContact(string title)
{
var createContact = new {Title = title};
string output = JsonConvert.SerializeObject(createContact);
return output;
}
[JsonProperty(PropertyN... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T17:26:41.830",
"Id": "76990",
"Score": "0",
"body": "How is the class named? Is there more to it?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T08:34:16.950",
"Id": "77091",
"Score": "1",
... | [
{
"body": "<p>Just a quick point, regarding readability; the <code>switch</code> block would be better off written like this:</p>\n\n<pre><code>//remove \".\"\nvar titleRemoveDots = title.Replace(\".\", \"\");\nvar titleLowerCase = titleRemoveDots.Trim().ToLower();\nswitch(titleLowerCase)\n{\n case \"dir\":\... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T17:13:09.363",
"Id": "44369",
"Score": "5",
"Tags": [
"c#",
"strings",
"serialization",
"json.net"
],
"Title": "Helper class to change property of string when serializing for ... | 44369 |
<p>I'm currently developing a method which performs an update of some data; much like the following simplified logic:</p>
<pre><code>boolean updateRequired = (currentValue == null && newValue != null);
boolean deleteRequired = (currentValue != null && newValue == null);
if(updateRequired || deleteRequ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T17:24:50.003",
"Id": "76989",
"Score": "1",
"body": "Is it c#, java or php? Your question is off-topic too, you need working and complete code to be that you want reviewed. You can have a language independent answer even if you spec... | [
{
"body": "<p>You could always condense it as follows:</p>\n\n<pre><code>boolean needToDoSomething = currentValue == null ? newValue != null : newValue == null;\n\nif(needToDoSomething) {\n // ...\n}\n</code></pre>\n\n<p>This is probably less clear than what you have, and gains you very little. Also, if you ... | {
"AcceptedAnswerId": "44388",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T17:21:16.587",
"Id": "44370",
"Score": "7",
"Tags": [
"java"
],
"Title": "To update or to delete? That is the Query"
} | 44370 |
<p>I picked the first test (Tape Equilibrium) from Codility <a href="https://codility.com/train/">here</a>. </p>
<p>Question:</p>
<blockquote>
<p>A non-empty zero-indexed array A consisting of N integers is given.
Array A represents numbers on a tape. Any integer P, such that <code>0 < P < N</code>,
split... | [] | [
{
"body": "<p><strong>Naming</strong></p>\n\n<p>The Java naming convention for arguments is camelCase. You should rename this argument <code>A</code> here: </p>\n\n<blockquote>\n<pre><code>public int solution(int[] A) \n</code></pre>\n</blockquote>\n\n<p>It would be best to make it look like the following code,... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T17:26:58.943",
"Id": "44371",
"Score": "27",
"Tags": [
"java",
"algorithm",
"programming-challenge"
],
"Title": "Tape Equilibrium"
} | 44371 |
<p>I am currently using this code (and more) to deal with 2D matrices. I am not very proficient in C, so I am not quite sure, if this is a good way of doing it.
I've seen other people in similar situations using pointers to a struct, but I didn't want to complicate things... </p>
<pre><code>typedef struct CMatrix {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T19:39:10.043",
"Id": "77031",
"Score": "0",
"body": "What is the use of this `bzero` ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T19:45:25.813",
"Id": "77032",
"Score": "0",
"body": "... | [
{
"body": "<p><em>This answer replaces poor advice in a previous answer.</em></p>\n\n<p>You can use <code>calloc()</code> instead of <code>malloc()</code> and <code>bzero()</code>.</p>\n\n<p>Your <code>newCMatrix()</code> is otherwise fine. If you write a <code>newCMatrix(uint32_t, uint32_t)</code>, though, yo... | {
"AcceptedAnswerId": "44399",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T19:35:24.993",
"Id": "44387",
"Score": "11",
"Tags": [
"c",
"beginner",
"matrix",
"pointers"
],
"Title": "C struct or pointer to struct?"
} | 44387 |
<p>I've found myself wanting an easy way to implement chat into various apps, so I developed a set of classes for the firebase.com backend that make it easy for me to quickly set up the nuts and bolts of a chat system. To implement this, I have three classes:</p>
<h3>FSPresenceManager</h3>
<p>Current Connection / Ot... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T21:16:13.917",
"Id": "77050",
"Score": "0",
"body": "Generally speaking, singletons should be avoided where they can. With that said, there's not enough code here to determine whether or not the singletons are avoidable. There's n... | [
{
"body": "<p>There's very little code here to review, and I made some points in my comment to the question regarding this, however, on what is posted, here are some notes...</p>\n\n<hr>\n\n<p>First of all, Xcode now autosynthesizes, so you can eliminate this line:</p>\n\n<pre><code>@synthesize firebaseURL, cu... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T19:52:01.683",
"Id": "44391",
"Score": "4",
"Tags": [
"objective-c",
"ios",
"singleton"
],
"Title": "Singleton With Sub-Singletons"
} | 44391 |
<p>This code review is inspired by the <a href="https://stackoverflow.com/questions/22411299/sort-files-in-numeric-order">this StackOverflow question</a> and written in Java 8.</p>
<p>The code is supposed to:</p>
<ol>
<li>Order all files, with syntax <code>jobXXX.script</code>, where <code>XXX</code> is a number, by ... | [] | [
{
"body": "<h2>NewLine</h2>\n\n<p>The newline at the end is correct... at least according to your code.</p>\n\n<p><code>Files.lines(...)</code> ignores the last line of input files if it has no characters. This is a standard system to have for most operating systems (the last character in a text file is a newli... | {
"AcceptedAnswerId": "44401",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T20:10:13.670",
"Id": "44392",
"Score": "6",
"Tags": [
"java",
"io",
"lambda"
],
"Title": "Combining contents of files by reading them in a human ordering"
} | 44392 |
<p>For the implementation of the Playfair encryption I needed a custom struct called Cell. This is because I not only need an array of characters I also want to get Elements in a matrix based on their "cartesian" position.</p>
<pre><code>public struct Cell
{
public char character;
public int X;
... | [] | [
{
"body": "<ol>\n<li><p>Your <code>Cell</code> struct should be immutable - you can achieve that by making all the fields <code>readonly</code>.</p></li>\n<li><p>In <code>Cell</code> <code>character</code> should be <code>PascalCase</code>. </p></li>\n<li><p>You repeat the code for trimming and replacing charac... | {
"AcceptedAnswerId": "44419",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T20:37:13.917",
"Id": "44396",
"Score": "4",
"Tags": [
"c#",
"cryptography"
],
"Title": "How to optimize this Playfair encryption?"
} | 44396 |
<p>I created a class to prevent the default delay which happens when holding down the key on Windows Forms. It seems like the class is working correctly but I don't know if I'm using the best practice.</p>
<p>KeyboardController class;</p>
<pre><code>class KeyboardController
{
public event EventHandler kbEvent;
... | [] | [
{
"body": "<ol>\n<li><p><strike>The main issue is that the key event handler and the timer tick will run on different threads which means that someone could press a key while the timer tick fires - in which case the <code>HashSet</code> could be modified while you are trying to read it from another thread. You ... | {
"AcceptedAnswerId": "44418",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T21:30:03.540",
"Id": "44404",
"Score": "4",
"Tags": [
"c#",
"wpf",
"event-handling"
],
"Title": "Preventing keydown delay"
} | 44404 |
<p>As a first little Python exercise, I wrote an analyzer/summarizer for my nginx accesslogs. The code works fine but I'm not sure if I used the different types of sequences properly or made some other stupid things which could lead to bugs etc.</p>
<hr>
<p>Steps:</p>
<ol>
<li>read in access.log and heavily poke aro... | [] | [
{
"body": "<p>I find your <code>find_chars()</code> method amusingly creative. I'll comment on the big picture instead.</p>\n\n<ul>\n<li><p><strong>Class design:</strong> Passing all the parameters into the constructor makes the class less versatile. Those parameters don't need to be part of the object's stat... | {
"AcceptedAnswerId": "44417",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-14T23:01:38.290",
"Id": "44413",
"Score": "4",
"Tags": [
"python",
"beginner",
"parsing",
"logging"
],
"Title": "Diving into Python sequences: analyze an access.log"
} | 44413 |
<p>I've coded branch and bound to solve the knapsack problem, and use a <strong>greedy linear relaxation</strong> to find an upper bound on a node I'm currently exploring. What I mean by this is that I first sort the items by their respective <em>value density</em> (computed <code>value/weight</code>, for each item) an... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-18T13:57:06.070",
"Id": "77583",
"Score": "0",
"body": "Isn't `solve` supposed use the sorted list of items?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-18T14:01:47.790",
"Id": "77586",
"Score":... | [
{
"body": "<h2>Your first upper bound is buggy</h2>\n\n<pre><code>return value + (v * (self.capacity - w)/float(w))\n</code></pre>\n\n<p>should be:</p>\n\n<pre><code>return value + (v * (self.capacity - weight)/float(w))\n</code></pre>\n\n<p>If <code>w_i << W</code> you are overestimating the upper bound ... | {
"AcceptedAnswerId": "44757",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T07:19:06.043",
"Id": "44421",
"Score": "17",
"Tags": [
"python",
"optimization",
"algorithm",
"recursion"
],
"Title": "Knapsack branch and bound: forward filter"
} | 44421 |
<blockquote>
<p>Our version of getword does not properly handle underscores, string constants, comments, or preprocessor control lines. Write a better version.</p>
</blockquote>
<p>This is the exercise 6-1 and can be foud on K&R 2 at page 150.
<a href="http://net.pku.edu.cn/~course/cs101/2008/resource/The_C_Prog... | [] | [
{
"body": "<p>I <strike>don't</strike> didn't immediately see a bug in it and you're doing a lot of things well; so some minor comments.</p>\n\n<hr>\n\n<pre><code>while(isspace((c = getch())))\n ;\n</code></pre>\n\n<p>This will often cause a compiler warning \"possible missing or empty statement\". If you us... | {
"AcceptedAnswerId": "44431",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T08:31:10.590",
"Id": "44424",
"Score": "3",
"Tags": [
"c",
"beginner",
"parsing",
"pointers"
],
"Title": "getword that properly handles undersores, string constants, commen... | 44424 |
<p>Based on feedback on an <a href="https://codereview.stackexchange.com/q/44128">earlier question</a>, I decided to implement the addition of two big ints by putting multiple digits in a node of a linked list. Can somebody take a look at my code and let me know if I am on the right track.</p>
<pre><code>#include <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T13:19:40.960",
"Id": "77114",
"Score": "0",
"body": "@palacsint I don't think the compiler requires you to type-cast `void*` from malloc when it's C (not C++)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "201... | [
{
"body": "<p>Your calculator gives erroneous results due to incorrect partition alignment when converting the input into linked lists. For example:</p>\n\n<pre><code>$ cat input.txt\n122223\n45555555555555555556\n$ ./cr44425\nRead the line 122223\nPrinting the list containing the num1(it will be in reversed o... | {
"AcceptedAnswerId": "44436",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T08:33:31.970",
"Id": "44425",
"Score": "5",
"Tags": [
"c",
"linked-list",
"memory-management"
],
"Title": "Adding two BigIntegers by putting mutiple digits in a linked list"
} | 44425 |
<p>I need to find linear conflicts of 8 puzzle state, state is represented by <code>int[9]</code>, goal state is {1,2,3,4,5,6,7,8,0}. A linear conflict would be if in a line two tiles that are supposed to be in that line are reversed.</p>
<p>For example, in goal state, the first row is 1,2,3 if in the state the first ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T10:02:53.940",
"Id": "77094",
"Score": "1",
"body": "There are numbers from 1 to 8 in 3x3 grid, the leftover tile is empty one and you can exchange it with one of it's neighbors every turn. Like this http://en.wikipedia.org/wiki/Fif... | [
{
"body": "<p>I would have some tweaks how you could improve your code quality. Reading it from the top I would start adding a comment for your method linearConflict and mention that the array as the argument contains two dimensional matrix mapped into a 1D array. It is a short comment and then immediately you ... | {
"AcceptedAnswerId": "44433",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T09:49:59.860",
"Id": "44427",
"Score": "7",
"Tags": [
"java",
"algorithm",
"mathematics",
"matrix"
],
"Title": "Counting linear conflicts of the state of 8 puzzle for heuri... | 44427 |
<p>The purpose of this class is to read an IIS log (or multiple ones). One thing to note is that the columns can differ based on settings in IIS.</p>
<p>A couple of concerns that I have:</p>
<ol>
<li>Is The ILogReader Interface neccessary?</li>
<li>Is the IFileReader the right way to allow me to stub out the <code>Fi... | [] | [
{
"body": "<p>Let's take a look.</p>\n\n<blockquote>\n <p>Is The ILogReader Interface neccessary?</p>\n</blockquote>\n\n<p>It is not, as long as you reasonably expect that it will stay with just this one log reader. I think it is not out of the question that you might adapt your application to also account for... | {
"AcceptedAnswerId": "44435",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T10:19:11.737",
"Id": "44429",
"Score": "3",
"Tags": [
"c#",
"unit-testing",
"tdd"
],
"Title": "Read Lines From IIS Log"
} | 44429 |
<p>Is there any way of counting how many shifts would it take to count shifts while doing insertion sort? This is a Hackerrank problem. Here's my solution, but it takes more than 16 seconds.</p>
<pre><code>counts = []
for _ in range(int(input())):
size = int(input())
ar = list(map(int, input().split()))
c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-11-03T01:29:02.037",
"Id": "125394",
"Score": "0",
"body": "My code did 0.04s: https://github.com/LeandroTk/Algorithm_DataStructure/blob/master/insertion_sort.py I think your code takes more than 16 seconds, because of the 3 nested loops.... | [
{
"body": "<p>Insertion sort is an O(<em>n</em><sup>2</sup>) algorithm. There's only so much you can do to optimize it.</p>\n\n<p>This is a bit of trick question. It doesn't actually ask you to sort the arrays in question; it just asks you to count the number of shifts involved. So, for each element to be \"... | {
"AcceptedAnswerId": "44440",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T10:51:09.877",
"Id": "44430",
"Score": "3",
"Tags": [
"python",
"optimization",
"sorting",
"python-3.x",
"insertion-sort"
],
"Title": "Time optimization of counting shi... | 44430 |
<p>I consider these two options exactly the same. I prefer the first one but I'm not sure if it's better than the second option in terms of cyclomatic complexity or readability.</p>
<p>Assuming that this is not pure Ruby and I can call to the <a href="http://apidock.com/rails/Object/try" rel="nofollow"><code>try</code... | [] | [
{
"body": "<p>It's obviously subjective, but IMHO inline conditionals make code harder to understand, indentation is very important. So I'd definitely take the second approach, but writing it differently to use only one indentation level:</p>\n\n<pre><code>existing_transaction = database.find_transaction_by_id(... | {
"AcceptedAnswerId": "44443",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T13:25:51.250",
"Id": "44441",
"Score": "3",
"Tags": [
"ruby",
"comparative-review",
"cyclomatic-complexity"
],
"Title": "Readability and cyclomatic complexity of database trans... | 44441 |
<p><a href="http://easymock.org/" rel="nofollow">Easymock</a> is an open source mocking framework for Java. It is used for creating mock objects and stubs for unit tests.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T15:27:34.787",
"Id": "44446",
"Score": "0",
"Tags": null,
"Title": null
} | 44446 |
Easymock is a mocking framework for Java. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T15:27:34.787",
"Id": "44447",
"Score": "0",
"Tags": null,
"Title": null
} | 44447 |
<p><a href="http://stackoverflow.com/tags/jsf/info">JSF tag wiki on Stack Overflow</a></p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T15:30:31.127",
"Id": "44448",
"Score": "0",
"Tags": null,
"Title": null
} | 44448 |
JavaServer Faces (JSF) is a model-view-presenter framework typically used to create web applications.
Using the standard components and render kit, stateful HTML views can be defined using JSP or Facelets tags and wired to model data and application logic. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T15:30:31.127",
"Id": "44449",
"Score": "0",
"Tags": null,
"Title": null
} | 44449 |
<p><a href="http://stackoverflow.com/tags/jsf-2/info">JSF 2 tag wiki on Stack Overflow</a></p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T15:31:44.647",
"Id": "44450",
"Score": "0",
"Tags": null,
"Title": null
} | 44450 |
JavaServer Faces (JSF) is a model-view-presenter framework typically used to create web applications. Version 2.x is a major step ahead compared to JSF 1.x, significantly expanding the standard set of components and component libraries. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T15:31:44.647",
"Id": "44451",
"Score": "0",
"Tags": null,
"Title": null
} | 44451 |
<p>I have used Intel VTune in order to find the hotspots in my code. I wrote comments next to the worst lines.</p>
<p>Can you please review my code? General review or performance issues is more than welcome.</p>
<pre><code>void ALGO::computeSADs(int (&nbr_SAD_RES)[ALGO_NBR_SZ][ALGO_NBR_SZ], int (&SAD)[ALGO_... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T16:11:17.077",
"Id": "77126",
"Score": "0",
"body": "Did the change to `int temp1 ...` make a difference?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T16:11:56.887",
"Id": "77127",
"Score":... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T15:45:25.900",
"Id": "44452",
"Score": "3",
"Tags": [
"c++",
"optimization",
"algorithm",
"performance"
],
"Title": "Compute SAD values"
} | 44452 |
<p>I have written a C# file reader that reads a file converts the bytes of the file to hex and writes it out to another file. It works fine but it takes 7.2GB of memory when converting a 300MB file.</p>
<p>What can I do to this code to make it take less memory?</p>
<pre><code>using System;
using System.Collections.Ge... | [] | [
{
"body": "<p>Your problem is that you load the whole file into memory, convert each byte to three characters (that's the file size times 6), going through <code>Replace</code> and <code>ToCharArray</code>.</p>\n\n<p>To avoid holding all in memory, you should <em>stream</em> the data, converting and writing <em... | {
"AcceptedAnswerId": "44459",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T18:14:44.567",
"Id": "44457",
"Score": "7",
"Tags": [
"c#",
"optimization",
"memory-management",
"converting"
],
"Title": "Hex file converter"
} | 44457 |
<p>Sometimes I run across the problem of having two member function overloads that only differ in the constness of <code>this</code> (and the return type, but that is less important):</p>
<pre><code>int& operator[](int);
const int& operator[](int)const;
</code></pre>
<p>Most of the time these are one-liners, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T19:30:25.007",
"Id": "77159",
"Score": "1",
"body": "There are several good answers on StackOverflow: see [How do I remove code duplication between similar const and non-const member functions?](http://stackoverflow.com/q/123758/499... | [
{
"body": "<p>As ChrisW commented, this has been covered in depth <a href=\"https://stackoverflow.com/q/123758/49942\">at Stack Overflow</a>. You're very close, but you should actually have the non-const version cast away the const-ness of the const version rather than how you're doing it. </p>\n\n<p>If you're ... | {
"AcceptedAnswerId": "44472",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T18:54:08.900",
"Id": "44460",
"Score": "19",
"Tags": [
"c++",
"casting"
],
"Title": "Avoiding code duplication and retaining const correctness"
} | 44460 |
<p>I am trying to create an AngularJS directive that will give information to the user about the text they are inputting such as the number of characters they must or may enter and so on and so forth.</p>
<p>To cut a long story short, I would be very grateful if someone could help me <strong>improve the javascript cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-19T20:11:27.397",
"Id": "77929",
"Score": "0",
"body": "It looks like a duplicate of one of your own questions. http://codereview.stackexchange.com/questions/42543/simplifying-an-angularjs-directive-that-counts-the-number-of-characters... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T20:51:41.893",
"Id": "44467",
"Score": "2",
"Tags": [
"javascript",
"angular.js"
],
"Title": "Building a set of AngularJS directives to provide the user information about their input"... | 44467 |
<p>This is my first Haskell application, so any non-name-calling tips will be taken extremely well! It is just a beta reducer:</p>
<pre><code>data Term = Var Int | Lam Term | App Term Term | Num Int | Add Term Term
deriving (Show)
subs :: Int -> Term -> Term -> Term
subs depth value (Lam body) = ... | [] | [
{
"body": "<p>This looks reasonable and idiomatic to me.</p>\n\n<p>I don't recognise the reduction strategy, though. Specifically, the line</p>\n\n<pre><code>red (App a b) = App (red a) (red b)\n</code></pre>\n\n<p>looks like you're not reducing to a normal form, and you might be reducing, say, one redex in the... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T21:27:07.110",
"Id": "44470",
"Score": "6",
"Tags": [
"beginner",
"haskell",
"lambda"
],
"Title": "Beta Reducer in Haskell"
} | 44470 |
<p>I'm looking for code review, optimizations, best practices.</p>
<pre><code>/**
* Huffman encoding obeys the huffman algorithm.
* It compresses the input sentence and serializes the "huffman code"
* and the "tree" used to generate the huffman code
* Both the serialized files are intended to be sent to client.
... | [] | [
{
"body": "<ol>\n<li><p>Currently both <code>compress()</code> and <code>expand()</code> are static methods in the class which limits its usability. Only one thread can compress/expand only one string. It could have a better API which stores the encoded in memory and allows creating multiple encoded data at the... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-15T22:07:16.230",
"Id": "44473",
"Score": "12",
"Tags": [
"java",
"algorithm",
"compression"
],
"Title": "Huffman code implementation"
} | 44473 |
<p>I spent the past hour trying to optimize a block of code I wrote that renders a simple coloured line directly to a backbuffer.</p>
<p>I've compared it with one of the <code>DrawLine</code> method implementations of the WriteableBitmapEx project, and found that my algorithm isn't quite as fast (unless I use <code>Pa... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-03-17T01:39:58.493",
"Id": "417075",
"Score": "0",
"body": "You should probably check out the bresenham line drawing algorithm, it’s a classic in computer graphics and unless you want to do anti aliasing I think it’s still the go to for l... | [
{
"body": "<p>I'm curious about why the code starts with <code>if (x > -1</code></p>\n\n<p>Doesn't that mean you need to scan values of i which end up doing nothing?</p>\n\n<p>Perhaps you could skip those stages; something like:</p>\n\n<pre><code>var initial_i = 0;\nif (start.X < 0)\n // need a bigger ... | {
"AcceptedAnswerId": "44486",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-03-15T22:17:54.293",
"Id": "44474",
"Score": "7",
"Tags": [
"c#",
"performance"
],
"Title": "Line rendering optimization"
} | 44474 |
<p>Given an array start from the first element and reach the last by jumping. The jump length can be at most the value at the current position in the array. Optimum result is when u reach the goal in minimum number of jumps. </p>
<p>For example: </p>
<blockquote>
<p>Given array A = {2,3,1,1,4} <br/>
possible ways... | [] | [
{
"body": "<h2>Code-Style</h2>\n<p>For the most part, this is good:</p>\n<ul>\n<li>return types are good.</li>\n<li>Collections are well typed</li>\n<li>method names are good</li>\n<li>apart from <code>list</code>, <code>a1</code>, and <code>a2</code>, variable names are good</li>\n</ul>\n<p>The <code>list</cod... | {
"AcceptedAnswerId": "44491",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T00:52:29.883",
"Id": "44482",
"Score": "7",
"Tags": [
"java",
"algorithm"
],
"Title": "Jump game to find minimum hops from source to destination"
} | 44482 |
<p>I'm primarily looking for ways to increase the performance of my code. </p>
<p>It is used to transform mesh data from <a href="http://www.blender.org/documentation/blender_python_api_2_69_10/bpy.types.Mesh.html">blender</a> into a format I can use and then save it to a file. </p>
<p>First it collects the colors of... | [] | [
{
"body": "<p>You could try to replace some loops with string formatting, for example change this</p>\n\n<pre><code>for i in pol.vertices[:3]:\n out.write(str(i)+' ')\nfor i in pol.vertices[2:]:\n out.write(str(i)+' ')\nout.write(str(pol.vertices[0])+' ') \n</code></pre>\n\n<p>to this</p>\n\n<pre><code>o... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T01:10:17.637",
"Id": "44484",
"Score": "5",
"Tags": [
"python",
"performance"
],
"Title": "Formatting and writing data"
} | 44484 |
<p>This question is a follow up to these questions:</p>
<ol>
<li><p><a href="https://codereview.stackexchange.com/q/36482/18427">RPSLS Game in C#</a></p></li>
<li><p><a href="https://codereview.stackexchange.com/q/43965/18427">Ensuring user input is an integer in a range</a></p></li>
<li><p><a href="https://codereview... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T21:17:19.127",
"Id": "77287",
"Score": "0",
"body": "I did fail to mention that I gave in to peer pressure and used a do while loop for my main loop. Any feed back on that is also welcome, please also let me know what you think I am... | [
{
"body": "<p>I'm going to leave a broader review to other answers, and only focus on a single line of code:</p>\n\n<blockquote>\n<pre><code>throw new Exception(\"Gesture is sealed\");\n</code></pre>\n</blockquote>\n\n<p>Don't do that.</p>\n\n<p>There are really two alternatives to throwing exceptions.</p>\n\n<... | {
"AcceptedAnswerId": "44490",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T02:05:37.853",
"Id": "44487",
"Score": "7",
"Tags": [
"c#",
"game",
"community-challenge",
"rock-paper-scissors"
],
"Title": "RPSLS game revisited. Is my design better than... | 44487 |
<p>I have this conditional statement with use of regex:</p>
<pre><code>do_stuff if (@string.match(/<(?:ingr?)>/i) &&
@string.match(/<(?:prod:alchemy?)>/i)) ||
@string.match(/<(?:key?)>/i)
</code></pre>
<p>It's a 1-line conditional statement, but due to it's length, i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T05:57:19.557",
"Id": "77208",
"Score": "1",
"body": "I am not clear why you need the non-capture groups and why they need to be non-greedy (the `?` at the end of each). If, for example, you are just trying to see if the string '<ing... | [
{
"body": "<p>You <em>could</em> combine all the tests into one regular expression, but I don't recommend it. The following is equivalent to what you wrote:</p>\n\n<pre><code>do_stuff if @string =~ /(?'i'<ingr?>).*(?'a'<prod:alchemy?>)|\\g<a>.*\\g<i>|<key?>/i\n</code></pre>\n\n<hr... | {
"AcceptedAnswerId": "44495",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T04:08:35.877",
"Id": "44492",
"Score": "1",
"Tags": [
"ruby",
"regex"
],
"Title": "1-line conditional statement needs to be trimmed down"
} | 44492 |
<p>My main concern is code style. Could you review this?</p>
<pre><code>#pragma once
#include <time.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <functional>
#in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T09:09:45.103",
"Id": "77219",
"Score": "0",
"body": "You probably want a virtual destructor there (http://stackoverflow.com/questions/461203/when-to-use-virtual-destructors)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Crea... | [
{
"body": "<pre><code>#pragma once\n</code></pre>\n\n<p>This really only makes sense in a header, but the rest of your code doesn't really look like a header (but maybe it's intended to be one anyway--not really sure). If it is a header, I'd recommend adding normal <code>#ifndef</code>/<code>#define</code>/<cod... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T05:58:21.370",
"Id": "44494",
"Score": "3",
"Tags": [
"c++",
"beginner",
"c++11",
"contest-problem"
],
"Title": "Simple framework for Google Code Jam problems"
} | 44494 |
<p>I have a WCF service which should authenticate user against any bruteforce attack.
Below is the code to avoid any bruteforce attack. I have used <code>MemoryCache</code> to keep track of invalid attempts by a user.</p>
<p>Could you please review the code and let me know if there are any issues?</p>
<p>Following de... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T17:41:12.143",
"Id": "77257",
"Score": "0",
"body": "What type/class is `securityService`?"
}
] | [
{
"body": "<ol>\n<li><p>If I'm right it's not thread-safe. I suppose two browsers with the same username could login at the same time which means that the <code>AuthenticateUser</code> method runs parallel on two threads.</p>\n\n<p>Suppose the following:</p>\n\n<ul>\n<li>the user already has an invalid login at... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T09:06:26.727",
"Id": "44496",
"Score": "3",
"Tags": [
"c#",
"security",
"authentication"
],
"Title": "MemoryCache - Login Security"
} | 44496 |
<p>I read about W3C Web Components spec and JavaScript's libraries like polymer.js and others, so I tried to find something similar in PHP, but with no luck.</p>
<p>So I wrote a tiny class to work with custom tags in PHP and I'd like to know what do you think about it. Is the idea somehow reasonable?</p>
<p><a href=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-19T20:09:34.997",
"Id": "77927",
"Score": "0",
"body": "I'm not sure if there is much point to this library - the 'magic' of Web Components is partly that elements have methods, and that the inside code of an element can be hidden.Repl... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T09:57:58.657",
"Id": "44497",
"Score": "1",
"Tags": [
"php",
"html",
"template"
],
"Title": "PHP Web Components"
} | 44497 |
<p>I have a program that accesses a certain I/O controller using memory-mapped I/O. I currently store the base address of this controller in a <code>const</code> variable.</p>
<p>This leads to a code structure something like this:</p>
<p><strong>gpio.h:</strong></p>
<pre><code>int gpioFunc (unsigned int pin, unsigne... | [] | [
{
"body": "<p>You should make a small driver layer, so that the main doesn't know about the low level details of what is going on - and here in that .c file that you have implemented the driver in, the constants goes as well. </p>\n\n<p>Then you call your driver and all is good :)</p>\n",
"comments": [
... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-16T11:38:33.130",
"Id": "44503",
"Score": "4",
"Tags": [
"c",
"io",
"constants"
],
"Title": "Accessing a certain I/O controller using memory-mapped I/O"
} | 44503 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.