body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I've written a cache class which implements a last-recently-used (LRU) cache. I would like to know what you think about it and whether it's worth using it or not (due to performance issues for instance).</p> <pre><code>#include &lt;functional&gt; #include &lt;iterator&gt; #include &lt;list&gt; #include &lt;utility&...
[]
[ { "body": "<ul>\n<li><p>For one thing, this is not gonna work if <code>m_idx</code> contains iterators into <code>m_stg</code>:</p>\n\n<pre><code>cache(cache const&amp; other)\n : m_cur_size(other.m_cur_size), m_max_size(other.m_max_size),\n m_drop(other.m_drop), m_scale(other.m_scale),\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T16:29:10.137", "Id": "5324", "Score": "8", "Tags": [ "c++", "cache" ], "Title": "Last-recently-used (LRU) cache container class" }
5324
<p>I am writing simple file validator for my java ee app and I am stack with my class api. I need specific error descriptions, but also I would like to have boolean values indicating whether file is valid or not. Please give me some hints how to do it 'smart'.</p> <pre><code>package pl.poznan.put.ims.business.attachme...
[]
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li>The <code>boolean validate(...)</code> method never returns <code>false</code> so it should be <code>void</code> method. </li>\n<li>I'd pass immutable <code>ValidationResult</code> objects to the clients. The clients could check the results and could signal to their cl...
{ "AcceptedAnswerId": "5584", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T18:31:43.517", "Id": "5326", "Score": "2", "Tags": [ "java", "exception-handling" ], "Title": "Validating files and returning errors messages/boolean values" }
5326
<p>I have three ways of reordering a list (think baseball order) and I am sure you can come up with more. What is a the best way?</p> <p>For example if input is list is 1,2,3,4 and current is 3 then the output should be 3,4,1,2. Another example list: 1,2,3,4 and current 4 output is 4,1,2,3.</p> <pre><code>public voi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T07:44:39.217", "Id": "198454", "Score": "0", "body": "You might consider other data structures, e.g. a [ring buffer](http://en.wikipedia.org/wiki/Circular_buffer)." } ]
[ { "body": "<p>The first thing you need to do is define what you mean with \"best\". Fastest to execute? Most readable? Best Java-ness?</p>\n\n<p>In any case neither solution is very \"nice\". The first one unecessarily removes the \"current\" item und re-adds it, the second one uses indexOf, thus indirectly has...
{ "AcceptedAnswerId": "5339", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T19:32:59.690", "Id": "5327", "Score": "2", "Tags": [ "java", "optimization" ], "Title": "reorder a list in java" }
5327
<p>I am attempting to build a small JavaScript library (similar to jQuery)</p> <p>The purpose behind this is mostly a learning exercise, so asking why I don't just use an existing library is moot.</p> <p>So far I have just got my basic constructor, a 'caller' function to invoke a new object, and some basic functions ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T21:19:46.453", "Id": "8035", "Score": "0", "body": "Why is your API identical to jQuery. Why not sit down and think what you need for this javascript library." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011...
[ { "body": "<p>There is quite a performance problem with your code: it will rebuild the <code>fn</code> object and all its methods every time the <code>lemon(selector, context)</code> constructor gets called. You can avoid that behavior by using the module design pattern: </p>\n\n<pre><code>this.lemon = (functio...
{ "AcceptedAnswerId": "5360", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T20:56:06.633", "Id": "5328", "Score": "2", "Tags": [ "javascript", "library" ], "Title": "jQuery-like library for learning purposes" }
5328
<p>I just wrote a small card game in JavaScript, CSS and HTML. This is kind of my first project that I have cared about front-end. So I got things to work, but I am sure that this is not the smartest way to do it.</p> <p>If someone could give me some guidelines on how this would have been done in a more professional w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T21:28:04.290", "Id": "8036", "Score": "3", "body": "My eyes. The code is far too procedural. Modularize it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-11-02T14:43:29.917", "Id": "8709", "Score"...
[ { "body": "<p>This is a great start. To Raynos' point you could modularize this into more manageable chunks. Here are a is jQuery Pattern article to help you get started: <a href=\"http://coding.smashingmagazine.com/2011/10/11/essential-jquery-plugin-patterns/\" rel=\"nofollow\">Essential jQuery Plugin Patterns...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T21:14:55.930", "Id": "5329", "Score": "4", "Tags": [ "javascript", "html", "css", "game", "playing-cards" ], "Title": "King's Cup game" }
5329
<p>I found this method kinda tough to get for a beginner like me, but I tried to do my best, and here's what I came up with.</p> <p>Is this good code regarding performance? Is there anything wrong with it?</p> <pre><code>var notPrime = [] ; var prime = [] ; var n = prompt("Enter n: "); for(var i = 2 ; i &lt; n ; i+...
[]
[ { "body": "<p>Lets say that there is room for improvement. ;)</p>\n<hr />\n<p>The <code>prompt</code> method returns a string, but you want a number, so you should parse the string:</p>\n<pre><code>var n = parseInt(prompt(&quot;Enter n: &quot;), 10);\n</code></pre>\n<hr />\n<p>Using <code>indexOf</code> on an a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-13T01:39:24.237", "Id": "5334", "Score": "4", "Tags": [ "javascript", "performance", "beginner", "sieve-of-eratosthenes" ], "Title": "Sieve of Eratosthenes in JavaScript" }
5334
<p>I'm trying to validate an HTTP Request, and first I want to get sure that all of the information has been posted (and then I'll check the correct format of each incoming data), so to get sure that no Form Spoofing attack is made. However, since this HTTP Post comes from a form, and that form contains almost 40 field...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-13T06:41:25.903", "Id": "8053", "Score": "1", "body": "Are you expecting them all to be null, if so a const array of strings might do it, if not a key/value pair should work." }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>Looks unreadable.</p>\n\n<p>I would normally extract such a condition to a private boolean function and reformat it for readability. That would be the first step.</p>\n\n<p>A second refactoring may present itself after this - perhaps having a list of string corresponding to the field names and ite...
{ "AcceptedAnswerId": "5345", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-13T06:37:21.793", "Id": "5343", "Score": "23", "Tags": [ "c#" ], "Title": "How many conditions in an \"if clause\" is acceptable?" }
5343
<p>This is a sample program that I intend to post as part of a series of beginner level Java tutorials. Please provide any feedback on improvements that would make example more clear or illustrate/emphasize best practices. The example drawns a ball object to a panel on a mouse click and then moves it randomly with an...
[]
[ { "body": "<ul>\n<li>Swing GUIs should be built inside the EDT, e.g. using <code>SwingWorker.invokeLater()</code>. See <a href=\"http://leepoint.net/JavaBasics/gui/gui-commentary/guicom-main-thread.html\" rel=\"nofollow\">http://leepoint.net/JavaBasics/gui/gui-commentary/guicom-main-thread.html</a> for details....
{ "AcceptedAnswerId": "5389", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-13T18:42:03.440", "Id": "5350", "Score": "2", "Tags": [ "java", "swing" ], "Title": "Bouncing ball - for swing event handling tutorial" }
5350
<p>Suppose we have an enum called "Planet" and it has a custom attribute of class "PlanetAttr", these methods will give you the attribute value for a given Planet value:</p> <pre><code>private static PlanetAttr GetAttr(Planet p) { return (PlanetAttr)Attribute.GetCustomAttribute(ForValue(p), typeof(PlanetAttr)); } ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T09:07:41.450", "Id": "8078", "Score": "4", "body": "I'm curious as to why you decided to use meta annotations to represent this data? Seems like an odd choice - attributes are designed to store meta data (data about data), but in th...
[ { "body": "<p>Make it general purpose using generics.</p>\n\n<p>Though I'd strongly suggest you rename your attribute to follow .NET guidelines. It should always be in the form <code><i>AttributeName</i>Attribute</code>. Enum values should be in CamelCase. And it is common to name classes containing extensio...
{ "AcceptedAnswerId": "5354", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-13T21:04:10.347", "Id": "5352", "Score": "54", "Tags": [ "c#", "enum", "extension-methods" ], "Title": "Getting the value of a custom attribute from an enum" }
5352
<p>I am using 2 nested SortedDictionaries to construct sparse matrix </p> <p>Here is the custom simularity(sim) function I wrote . Now it has O(n^2) complexity. I looking for suggestions to improve robustness and efficiency.Thanks for any help.</p> <pre><code> double a = 0, b = 0, sqrta...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T08:56:19.577", "Id": "8077", "Score": "0", "body": "`sim` is set to 0 in every iteration of the middle loop; isn't `sim` supposed to be the output value?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-1...
[ { "body": "<p>As you are doing calculations on all values where the result depends on both loops, there isn't much that can be done about the complexity, at least not without knowing what you do with the result (which seems to be just discarded in the code shown).</p>\n\n<p>There are some things that you can do...
{ "AcceptedAnswerId": "5359", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T08:06:48.277", "Id": "5357", "Score": "4", "Tags": [ "c#", "performance" ], "Title": "Cosine simularity perfomance c#" }
5357
<p>Is there anything you would change about the following function? I welcome any feedback on style, correctness, etc. Thank you for reading.</p> <p>Some of my questions are:</p> <ol> <li>Obviously, I catch the exception and convert it to a return value because I don't want to take down the application in case of an ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T23:10:47.213", "Id": "8107", "Score": "0", "body": "It's just about as idiomatic as it can be, just leave out the `Close()` call, it will be handled by the `using` block." } ]
[ { "body": "<p>I think this is more idiomatic but I think this style does not really add much benefit over calling <code>File.WriteAllText</code> directly. Consider what your client code will need to do to handle a single <code>bool</code> result with no other information as to why it failed.</p>\n\n<pre><code>p...
{ "AcceptedAnswerId": "5365", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T17:41:27.860", "Id": "5361", "Score": "3", "Tags": [ "c#" ], "Title": "More idiomatic way to handle simple file writing in C#?" }
5361
<p>My implementation:</p> <pre><code>Array.prototype.binarySearchFast = function(search) { var size = this.length, high = size -1, low = 0; while (high &gt; low) { if (this[low] === search) return low; else if (this[high] === search) return high; target = (((search - this[low]) / (this[...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T21:49:04.247", "Id": "8106", "Score": "0", "body": "I'm sorry, but information theory dooms your attempt. The only way to speed up the binary search is by making assumptions about the kind of data you are storing." }, { "Con...
[ { "body": "<p>Updated: based on your description, it's easy to derive a scenario where your algorithm turns into a linear search rather than a binary one. Just set up one equation per step that it would take and solve them simultaneously.</p>\n\n<p>Your code is still buggy, by the way. If you search for a value...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T18:05:34.410", "Id": "5363", "Score": "5", "Tags": [ "javascript", "algorithm", "search", "binary-search" ], "Title": "Efficient Binary Search" }
5363
<p>There are a several articles about true data access in MVC. I tried to make the best one according to the architecture flexibility. My way is following:</p> <ol> <li>ADO .NET Entity Data Model (*.edmx from Entity Framework) with default code generation.</li> <li><p>Common repository interface</p> <pre><code> publi...
[]
[ { "body": "<p>Your code seems really good, I would change the <code>ITestingRepository</code> methods to return <code>IEnumerable&lt;&gt;</code> instead of <code>List&lt;&gt;</code>. </p>\n\n<p>Also, I suggest you would add a method signature to your generic repository interface that would let you query your Db...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T18:06:34.750", "Id": "5364", "Score": "6", "Tags": [ "c#", "entity-framework", "asp.net-mvc-3" ], "Title": "The way to realise data access" }
5364
<pre><code>I need to insert multiple checkbox text into a column in a mssql database, I could use a single checkbox list and make this thing easier, however, the requirements are to display separate table columns with several checkboxes , kinda like Check all the conditions that apply , but for several criterias, so I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T19:10:54.413", "Id": "8094", "Score": "0", "body": "Not code review, as there is no code... This should go to StackOverflow instead." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T19:15:39.217", ...
[ { "body": "<p>I'm not sure that it's the best choise to store the items as text in the database, and to store them in a single field, but that's a different matter...</p>\n\n<p>You can put the checkboxes in an array and loop over it. Put the selected text in a list, and join it:</p>\n\n<pre><code>Checkbox[] che...
{ "AcceptedAnswerId": "5373", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T18:35:44.913", "Id": "5366", "Score": "3", "Tags": [ "c#", "asp.net" ], "Title": "Inserting multiple single checkbox controls text into a single column in db" }
5366
<p>I'm doing my first major jQuery development. It's a Widget for recurring events, and is as such a fairly complex beast. The full code is available at <a href="https://github.com/collective/jquery.recurrenceinput.js" rel="nofollow">https://github.com/collective/jquery.recurrenceinput.js</a> for those who want to chec...
[]
[ { "body": "<p><code>lib</code> is not really lib, but your project's dependencies. Normally you'd call it <code>vendor</code></p>\n\n<p><code>tests</code> -> <code>test</code>. This one is just a convention.</p>\n\n<p>I took a quick look at your code and the first thing I saw was snake_case. JS/jQuery conventio...
{ "AcceptedAnswerId": "5612", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T19:11:30.793", "Id": "5371", "Score": "5", "Tags": [ "javascript", "jquery" ], "Title": "Writing a jQuery widget: Code layout" }
5371
<p>I'm doing my first major jQuery development. It's a Widget for recurring events, and is as such a fairly complex beast. The full code is available at <a href="https://github.com/collective/jquery.recurrenceinput.js">https://github.com/collective/jquery.recurrenceinput.js</a> for those who want to check it out. I app...
[]
[ { "body": "<p>I agree, the string literal in JS is unwieldy. And requesting the HTML via Ajax is more than you need. </p>\n\n<p>The simplest thing is to insert the template on the page as HTML. Can you include the template on your page, not as Javascript, but as HTML? As in,</p>\n\n<pre><code>&lt;div style=\"d...
{ "AcceptedAnswerId": "7219", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-14T19:24:02.920", "Id": "5372", "Score": "7", "Tags": [ "javascript", "jquery", "ajax" ], "Title": "Writing a jQuery widget: Templating" }
5372
<p>I was given this assignment below and wrote the code below that as the solution. My instructor has been blasting me for writing inefficient code for my last several assignments, and rails at me for using strings as I do. She won't show me why its wrong but just states that it is wrong. I need to know why what I am w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-15T19:02:34.847", "Id": "8118", "Score": "3", "body": "Please learn to format your code so it is easier to read." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-16T06:24:44.347", "Id": "8128", "Scor...
[ { "body": "<p>My thoughts:</p>\n\n<ol>\n<li>Your variables are all declared at the beginning of the function: don't do that. Declare variables close to where they are used</li>\n<li>Your variable names are confusing and give little indication of what they are for</li>\n<li>You use magic numbers 100, 10, 1 to de...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-15T00:26:16.510", "Id": "5376", "Score": "6", "Tags": [ "c++", "beginner", "homework" ], "Title": "Garden sprinkler system" }
5376
<p>I have an assignment where I am required to verify if a car is a sports car or not by minimum max speed and minimum horse power. I have finished the program and it works great. I was just wanting to see if you can review my assignment and see if there is room for improvement.</p> <pre><code>using System; using Syst...
[]
[ { "body": "<p>You code looks reasonable, but I would have couple of relatively minor suggestions:</p>\n\n<ul>\n<li>Did you consider what happens when user enters an invalid number? I.e. a string that contains letters or even a string that can be interpreted as a number but is not in valid range (e.g. is negativ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-15T03:31:51.457", "Id": "5378", "Score": "10", "Tags": [ "c#", "homework", "validation" ], "Title": "Verifying if a car is a sports car based on speed and horse power" }
5378
<p>I have a string of numbers, like <strong>"31654918562314"</strong>, and I want to convert it into an array of integers. The code I've written is:</p> <pre><code>string source = "31654918562314"; int[] numbers = new int[source.Length]; for (int i = 0; i &lt; source.Length; i++) { numbers[i] = Convert.ToInt32(sou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-15T16:47:08.867", "Id": "8115", "Score": "0", "body": "One thing that jumps out at me is that you can just subtract the character value of `0` from each digit, rather than call `Convert.ToInt32()` or `Int32.Parse()`." }, { "Con...
[ { "body": "<p>I'm partial to using LINQ here. Jon has a point there on the conversion.</p>\n\n<pre><code>var str = \"31654918562314\";\nvar numbers = str.Select(c =&gt; c - '0').ToArray();\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0...
{ "AcceptedAnswerId": "5384", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-15T09:15:36.430", "Id": "5383", "Score": "4", "Tags": [ "c#", "javascript", "strings", "array" ], "Title": "Improving the code to turn a string into an array of numbers?" }
5383
<p>I am writing a <a href="https://github.com/rahmu/Agros" rel="noreferrer">Unix shell in C</a>, which uses a rather large switch in the main loop.</p> <p>It is used to handle built-in commands like 'cd' or'help'. The way it works is that it parses the user input and return a 'comand_t' struct, with 'name' being the f...
[]
[ { "body": "<h3>Function pointers</h3>\n\n<p>You want to use function pointers: <a href=\"http://www.newty.de/fpt/fpt.html\">http://www.newty.de/fpt/fpt.html</a></p>\n\n<pre><code>typedef void (*Command)(char const* args); // Modify as required\n // But something like ...
{ "AcceptedAnswerId": "5390", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-15T13:12:07.373", "Id": "5386", "Score": "6", "Tags": [ "c" ], "Title": "Avoiding a large 'switch' call in the main loop" }
5386
<p><strong>Goal</strong></p> <p>Convert the following into an <code>IEnumerable</code> of integers accounting for the <code>x-y</code> ranges:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>"1,2,3,0,7,8,9,10-15" </code></pre> </blockquote> <p>to</p> <blockquote> <pre class="lang-none prettypri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-13T00:31:23.147", "Id": "8119", "Score": "0", "body": "Can there be more than one range? Are non-ranged items sequential?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-13T00:38:52.520", "Id": "8120", ...
[ { "body": "<p>Ok, some comments:</p>\n\n<ul>\n<li>Code style\n\n<ul>\n<li>While there are no definitive laws about code style, most C# programmers are putting the opening brace <code>{</code> on a separate line. If someone else is going to read your code, they are likely to be annoyed.</li>\n<li>Consider breaki...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-13T00:14:41.197", "Id": "5391", "Score": "10", "Tags": [ "c#", "strings", "converting", "integer", "interval" ], "Title": "Converting a range of integers from a string to an ...
5391
<p>The C# code below, using LINQ to Entities, aims to merge all <code>Class</code> entities which have the same <code>SubjectId</code> and the same <code>Students</code>.</p> <pre><code>var sb = new StringBuilder(); var counter = 0; using (var ctx = new Ctx()) { var allClasses = ctx.Classes.Where(o =&gt; o.Subject...
[]
[ { "body": "<p>Your code is <em>very</em> difficult to read. (To give you an idea of <em>how</em> difficult it is, I've been looking at this for the past 2 hours so far)</p>\n\n<ul>\n<li>You are using traditional <code>for</code> loops when you instead should be using <code>foreach</code> loops.</li>\n<li>Your ...
{ "AcceptedAnswerId": "5402", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-16T07:54:45.283", "Id": "5396", "Score": "3", "Tags": [ "c#", ".net", "linq", "entity-framework" ], "Title": "Merge entities which have the same children" }
5396
<p>I've been teaching myself Python3 for about a week now and I decided to put my skills to the test by writing a simple Tic-Tac-Toe game. Here is what I came up with:</p> <pre><code>#!/usr/bin/env python3 import random board = [0]*9 def resetBoard(): for index, i in enumerate(board): board[index] = 0 ...
[]
[ { "body": "<p>Couple of comments on general style:</p>\n\n<pre><code>while(players != 1 and players != 2):\n players = eval(getPlayers())\n</code></pre>\n\n<p>I would expect getPlayers() to get the player information and do any error handling.\nThus in the main loop this should just be a single call:</p>\n\n...
{ "AcceptedAnswerId": "5399", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-16T17:27:43.593", "Id": "5397", "Score": "3", "Tags": [ "python", "optimization", "game", "python-3.x" ], "Title": "Improving and optimizing Tic-Tac-Toe game written in Python ...
5397
<p>How can I make the following PHP code better, more efficient, shorter, elegant, etc? While it already works, I am still learning PHP and want to improve upon my current code:</p> <pre><code>&lt;?php $query = 'psoriasis'; $eSearchQueryParameters = array( 'db' =&gt; 'pubmed', 'term' =&gt; $query, 'retm...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-12-15T10:13:53.103", "Id": "211213", "Score": "0", "body": "[Follow-up question](http://codereview.stackexchange.com/q/5485/9357)" } ]
[ { "body": "<p>In my humble opinion, the version below is more elegant, easier to read and to maintain.</p>\n\n<p>It uses a class to keep things more organized.</p>\n\n<p>I would consider the code below as a <strong>starting point</strong> to start being improved, with things like error checking, etc.</p>\n\n<p>...
{ "AcceptedAnswerId": "5408", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-16T20:12:45.433", "Id": "5400", "Score": "1", "Tags": [ "php", "web-scraping", "url" ], "Title": "Scraping PubMed query results" }
5400
<p>So I built a little baseball "scouting report" graphic that shows stats for players. As you page through the players, their images slide in and out of the graphic. I worked out a way to do this using a jQuery queue, and it works fairly well.</p> <p>The one hitch is when the graphic is changing from a player on one ...
[]
[ { "body": "<p>I think you need to keep it simple. This seems much more complicated than need be.</p>\n\n<p>For example why are you removing and then creating again?:</p>\n\n<pre><code>jQuery('#playerPhotoL img').remove();\njQuery('#playerPhotoR img').remove();\n\nvar playerName = testArray[playerID][0];\nvar pl...
{ "AcceptedAnswerId": "5412", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-16T20:42:07.587", "Id": "5401", "Score": "4", "Tags": [ "javascript", "jquery", "queue" ], "Title": "Trying to improve my jQuery animation queue" }
5401
<p>I'm somewhat new to Scala and am not sure if I'm doing things in a very Scala-esque way.</p> <p>In particular, I'm not sure if I'm using <code>Option</code> correctly, since by calling <code>.isDefined</code>, I'm basically just doing ye olde Java null check. Also, the <code>getMethodAndAnnotationFromInfaces</code>...
[]
[ { "body": "<p>You could write it like this:</p>\n\n<pre><code>for (val method &lt;- clazz.getMethods) {\n val methodAndAnnotation = method.getAnnotation(annotationType) match {\n case annotation: MessageHandler =&gt; Some((method, annotation))\n case _ =&gt; getMethodAndAnnotatio...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-16T23:07:20.170", "Id": "5404", "Score": "2", "Tags": [ "beginner", "scala" ], "Title": "Correct use of Option in scala?" }
5404
<p>Wouldn't it be nice to just chain assertions after a method call or is it just me? I was thinking that it'd improve readability.</p> <p>Instead of:</p> <pre><code>var myObject = _objectService.GetRandomObject(); Trace.Assert(myObject!=null); </code></pre> <p>it'll just be this:</p> <pre><code>_objectService.GetR...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T05:40:11.170", "Id": "8151", "Score": "0", "body": "One may overloads != and == operator doing some side effects while comparing, so be careful whe utilizing this operators directly" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>You may found it useful to support both coding techniques, by supplying both versions of a method call, generic and non-generic. One will be using an extension method parameters, mirrored and backed up with method using anonymous function references to as a parameters to static methods.</p>\n\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T02:12:40.070", "Id": "5407", "Score": "3", "Tags": [ "c#", "extension-methods" ], "Title": "Chained Assertions" }
5407
<p>I'm new to Clojure. How can I make this more idiomatic Clojure code? Among other things, there are three (do) blocks and I don't think using (def) as many times as I do is a recommended idea.</p> <pre><code>(defn add-phone "Add a phone number to a given service. There are a few steps we have to take: - Valida...
[]
[ { "body": "<p>There are several errors/bad styles here:</p>\n\n<ul>\n<li>First do isn't necessary, as body of function can contain several expressions</li>\n<li>instead of <code>def</code> inside function it's better to use <code>let</code> that allows to \"define\" several variables in one step, and they will ...
{ "AcceptedAnswerId": "5414", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T05:58:20.420", "Id": "5410", "Score": "2", "Tags": [ "beginner", "validation", "authentication", "clojure", "web-services" ], "Title": "Web service to add a phone number...
5410
<p>I am currently exploring the play framework. I'm about to replace the proposed templating system, using the powerful XML processing of the Scala library. Here is what I have come with:</p> <pre><code>import scala.xml._ import play.templates._ import play.mvc.results.ScalaAction object Gui { def asset (file:Stri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T06:38:58.503", "Id": "8154", "Score": "0", "body": "I would like to add \"playframework\" as a new tag... but don't have the right to do it... Could someone with such power create it for me, or better, give me the right to do it?" ...
[ { "body": "<p>I'm not that familiar with Play, but overall I can't say that there's anything here I actively dislike. The purpose, layout, variable names and all are quite reasonable and easy to follow. Over all, I would say \"Good job\".</p>\n\n<p>A couple of comments outside of that:</p>\n\n<ol>\n<li><p>It se...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T06:38:09.253", "Id": "5411", "Score": "8", "Tags": [ "mvc", "scala", "xml", "template" ], "Title": "Basic XML template" }
5411
<p>I was looking for a simple Event Aggregator to use in my app, but I found people get very complicated very quickly, so I thought this was easy enough to write myself. It seems to work, but I was wondering what you think and if you would change or add anything. (I know some of them raise events back on the same threa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T15:12:05.573", "Id": "8175", "Score": "0", "body": "I'll embarrassingly admit a bit of TL;DR for the moment, but at a quick glance, I'd make the two `private` variables `readonly` as well." } ]
[ { "body": "<p>I haven't thoroughly looked at it but these are my initial thoughts.</p>\n\n<p><strong>Minor points</strong></p>\n\n<p>I would initialise the private variables inline like this <code>private object _syncLock = new Object();</code> because they don't depend on parameters given to the constructor.</...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T09:34:35.857", "Id": "5416", "Score": "10", "Tags": [ "c#", "design-patterns" ], "Title": "What do you think of my EventAggregator implementation in C#?" }
5416
<p>I've been wondering about simple collision in C++ for a while now, and I've tried to make up my own code.</p> <p>The code posted below works when walls are placed in a perfect rectangle around the player. However, once you randomly place them in the array, as in the code, weird inconsistencies seem to occur. Someti...
[]
[ { "body": "<h3>Bug in your code</h3>\n<p>Here you are accessing the levelMap by 'Y' then 'X'</p>\n<pre><code> int tile = levelMap[indexY][indexX]; \n</code></pre>\n<p>In all other places you are accessing the levelMap by 'X' then 'Y'</p>\n<pre><code>if(levelMap[(pacmanPosX+32)/32][pacmanPosY/32] == 1) //...
{ "AcceptedAnswerId": "5421", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T13:04:11.497", "Id": "5420", "Score": "2", "Tags": [ "c++", "collision" ], "Title": "Collision detection inconsistencies" }
5420
<p>I have written a (dynamic) <code>TemplateArray</code> class, for purposes to be included as a baseline for a library I am working on, and I would like feedback on any of the following:</p> <ul> <li>How the code can be improved (even if it's just your subjective opinion)?</li> <li>How the code can be made more effic...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T15:59:14.587", "Id": "8176", "Score": "2", "body": "Wouldn't it be easier to simply do this as a wrapper around std::vector? And I don't see the point of many of the bool returns? Some are functions that should never fail (and coinc...
[ { "body": "<p>All your methods have corresponding functionality with std::vector. I suggest you write your class as a wrapper around std::vector.</p>\n\n<pre><code> template&lt;typename TemplateItem&gt;\nclass TemplateArray\n{\n public:\n // std::vector::empty\n const bool IsEmpty() const { r...
{ "AcceptedAnswerId": "5428", "CommentCount": "13", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T15:03:10.697", "Id": "5424", "Score": "5", "Tags": [ "c++", "template" ], "Title": "C++ TemplateClass" }
5424
<p>PHP doesn't have a built-in functions for <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard" rel="nofollow">AES</a> (specifically, AES-128) encoding/decoding, so I've had to implement my own, and this is what I have come up to (of course, taken from different many sources, mostly not coded by me).</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T18:44:53.563", "Id": "8192", "Score": "2", "body": "It is SO easy to create a broken implementation of encryption that \"some guy on StackOverflow\" doesn't realize is broken. Can you make a native call to a proven implementation o...
[ { "body": "<p>Implementing AES alone is very risky, mainly because it is very easy to make a mistake. I strongly recommend you use <a href=\"http://phpseclib.sourceforge.net/\">phpseclib</a> for this.</p>\n\n<p>Also you should not use ECB mode unless you are encrypting only 1 block.</p>\n", "comments": [], ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T18:42:07.423", "Id": "5432", "Score": "3", "Tags": [ "php", "security", "cryptography", "aes" ], "Title": "AES encryption in PHP" }
5432
<p>I am importing XML data to a MySql database using LINQ to Entities. The data represents which students are in which classes, and looks like...</p> <pre><code>&lt;studentClassesData&gt; &lt;studentClassEntry&gt; &lt;upn&gt;W432980573452&lt;/upn&gt; &lt;className&gt;8bcDn4&lt;/className&gt; &lt;/studentCl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-18T17:58:46.203", "Id": "16141", "Score": "0", "body": "What's taking 13 seconds? The parsing or the whole method? How big is your existing database? I suspect a lot of that time is coming from the fact that you're preprocessing the Cl...
[ { "body": "<p>Hard to say what's causing the extra load here. I had a similiar task which initially took a very long time, but with some adjustments and the use of HashTables, i got it to run within a second (3000 entities created from a 80mb large xml-file).</p>\n\n<p>I did however use XDocument (LINQ-TO-XML) ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T23:43:03.020", "Id": "5436", "Score": "2", "Tags": [ "c#", ".net", "linq", "xml", "entity-framework" ], "Title": "Importing XML to a database using LINQ to Entities" }
5436
<p>I've prepared a small C interface so the rest of my program can access relevant system functions. I am not a C programmer, though - just C++ and D, mainly. I want to make sure that everything here is "C-ish" before committing the rest of my code to this interface.</p> <p>This is just a plain old C file, compiled ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T03:07:52.120", "Id": "8198", "Score": "0", "body": "If you're compiling this with a C++ compiler, don't forget to use `extern \"C\"`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T03:08:58.530", ...
[ { "body": "<p>A few quick comments:</p>\n\n<ul>\n<li>You should declare all internal functions and variables <code>static</code> to avoid polluting the global namespace. (You'd do this in a C++ program as well, but would probably use an unnamed namespace. I'm not sure what the D equivalent is).</li>\n<li>Since ...
{ "AcceptedAnswerId": "5449", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T03:03:25.060", "Id": "5437", "Score": "2", "Tags": [ "c", "console", "unix" ], "Title": "Wrapper functions for terminal capabilities" }
5437
<p>I wrote a quick and dirty program to perform binary search with an ordered array (list) of C style strings. For example:</p> <p><code>{"1", "12", "23", "124"}</code> etc (though my input set is actually much different)</p> <p>NOTE:</p> <ol> <li><p>Apologies for the confusing names - <code>string</code> is not th...
[]
[ { "body": "<p>There is not enough information to give a real review.<br>\nIf you fill in all the type information and make it a compilable function I will review your algorithm, but based on the available code the only thing I can review is the style.</p>\n\n<ul>\n<li><p>C and C++ are two completely different l...
{ "AcceptedAnswerId": "5448", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T03:58:07.560", "Id": "5438", "Score": "3", "Tags": [ "c++", "c", "algorithm", "strings", "binary-search" ], "Title": "Binary search with strings" }
5438
<p>I have piece of code in C which removes any duplicate characters in a string. But I am doing it in two loops and would like it to optimize it to one loop. </p> <pre><code>void removeDuplicates(char* ptr) { int end = 1; int length = strlen(ptr); int current; int i; current = 1; for(end=...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-20T03:53:31.353", "Id": "8309", "Score": "3", "body": "Don't use `gets()` even in test code. Forget it exists; use `fgets()` instead." } ]
[ { "body": "<p>If you're optimizing for time, you could waste some memory and use an array of length <code>sizeof(char)</code> -- let's call it <code>seen</code> -- initialized with zeros.</p>\n\n<p>In the loop you'd a few things:</p>\n\n<ol>\n<li>if the <code>seen</code> count is greater than zero, increment an...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T09:12:08.240", "Id": "5441", "Score": "5", "Tags": [ "c", "strings" ], "Title": "Removing any duplicate characters in a string" }
5441
<p>It's long, repetitive, and hard to follow.</p> <pre><code> private void Map(object x, JToken json) { var objType = x.GetType(); var props = objType.GetProperties().Where(p =&gt; p.CanWrite).ToList(); foreach (var prop in props) { var type = prop.PropertyType; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-18T18:48:02.133", "Id": "66316", "Score": "2", "body": "I am downvoting this because there's no description of what the code does, it is basically a \"copy-paste\" question. Please at least include a short description of what the code ...
[ { "body": "<p>Step 1: extract the body of the loop into its own method that takes prop as a parameter. Now your primary method looks like</p>\n\n<pre><code>private void Map(object x, JToken json)\n {\n var objType = x.GetType();\n var props = objType.GetProperties().Where(p =&gt; p.CanWrite).T...
{ "AcceptedAnswerId": "5467", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T16:43:29.867", "Id": "5450", "Score": "7", "Tags": [ "c#" ], "Title": "How can I make this method shorter and easier to follow?" }
5450
<p>I need to take a month (defined as a start and end date) and return a set of date ranges for each week in that month. A week is defined as Sunday through Saturday. A good way to visualize it is if you double click on your Windows date in the start bar:</p> <p><img src="https://i.stack.imgur.com/JNusa.png" alt="en...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T18:14:00.327", "Id": "8232", "Score": "3", "body": "What happens when somebody flips the start and the end values? And what do you want when someone inputs dates over more than one month (dates in February and April, for example)? ...
[ { "body": "<p>Well, first of all your range only has to store the start date, as the weeks are always the same length:</p>\n\n<pre><code>struct Range {\n\n public DateTime Start { get; private set; }\n\n public DateTime End { get { return Start.AddDays(6); } }\n\n public Range(DateTime start) {\n Start =...
{ "AcceptedAnswerId": "5459", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T17:33:20.077", "Id": "5451", "Score": "14", "Tags": [ "c#", "algorithm", ".net", "datetime" ], "Title": "Listing the weeks in a given month" }
5451
<p>I have a flow where if a certain condition is true then I should take another approach. That condition can be triggered by different scenarios. But each condition test must be done only if the last one failed. Once a condition is true there is no further logical tests to do. My question is how to do that in an elega...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T18:24:30.483", "Id": "8234", "Score": "2", "body": "It looks like we're missing critical surrounding code. If not, it should be fairly easy to move the code into a function that can simply return the appropriate status code when an ...
[ { "body": "<p>Personally, I would separate this into multiple functions:</p>\n\n<pre><code>public StatusCode GetStatus( ... )\n{\n CardPort cardPort = findCardPort(card, port);\n if (cardPort == null) {\n return StatusCode.CARD_PORT_NOT_FOUND;\n } \n\n Sim sim = cardPort.getSim();\n if (si...
{ "AcceptedAnswerId": "5455", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T17:51:11.897", "Id": "5453", "Score": "6", "Tags": [ "java" ], "Title": "Indented if/else approach" }
5453
<p>I am working on an application that reads lots of data from the network and puts it in a grid. I noticed that I could save some memory by reusing existing strings instead of always using the new strings that came off the wire. So here is the class that I wrote to accomplish that. It is simple and it works. But I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-19T02:46:16.987", "Id": "8249", "Score": "0", "body": "Making it generic would only make sense if it's use could be limited to immutable reference types. Plus, I only have a use for it with strings." }, { "ContentLicense": "CC...
[ { "body": "<p>You might want to look into <a href=\"http://msdn.microsoft.com/en-us/library/system.string.intern.aspx\">string interning</a>:</p>\n\n<blockquote>\n <p>The common language runtime conserves string storage by maintaining a table, called the intern pool, that contains a single reference to each un...
{ "AcceptedAnswerId": "5461", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-19T02:28:33.747", "Id": "5460", "Score": "11", "Tags": [ "c#", ".net", "strings", "memory-management" ], "Title": "Reusing strings read from I/O" }
5460
<p>Activating jQuery tabs from URL #id is www.somedomain.com/index.php#tab3</p> <p>Given this my best shot, and it does work but I feel it could be far far better.</p> <p>Please tell me if this is totally shockingly bad JS.</p> <pre><code>$(document).ready(function() { //When page loads... $(".tab_content").hide(); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-11-18T17:22:06.670", "Id": "62837", "Score": "0", "body": "Have you considered using [jQuery BBQ](http://benalman.com/projects/jquery-bbq-plugin/)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-08-16T12:09:54.1...
[ { "body": "<p>Well, you could do some refactoring with this code, the only issue I see is that the low level functinality is implemented at the top level of your code. It would be better to extract the logic to separate functions, something like this (I also improved your code formatting a little bit):</p>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T18:06:23.053", "Id": "5468", "Score": "2", "Tags": [ "javascript", "jquery", "performance" ], "Title": "jQuery Select Tabs based on URL #ID" }
5468
<p>There is as of .NET 2.0 a generic <code>EventHandler</code> delegate type, which can be used to define an event in terms of the <code>EventArgs</code> type you wish to use, without having to create a redundant delegate type to use in the event declaration.</p> <p>Well, what about the <code>EventArgs</code>? I often...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-19T16:42:58.100", "Id": "8287", "Score": "0", "body": "You've only now just found out about it? It's been there since .NET 2.0. ;)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-19T16:50:32.847", "Id...
[ { "body": "<p>You could make it a little bit more useful if you added some supporting factory methods to create the arguments. That way you don't have to use the constructor and its somewhat awkward syntax (having to supply the types).</p>\n\n<pre><code>public static class EventHandlerExtensions\n{\n public...
{ "AcceptedAnswerId": "5472", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-19T16:10:24.130", "Id": "5470", "Score": "18", "Tags": [ "c#", "event-handling" ], "Title": "Generic EventArgs to go with generic EventHandler?" }
5470
<p>Empty Textboxes, <strong>class="loc"</strong> display <strong><em>"(City, State \ Country)"</em></strong> using <strong>italics and silver</strong>. Of course, Textboxes that do have data are displayed according to page defaults. <br><br> I noticed chaining and caching could be used. There are inheritances issues,...
[]
[ { "body": "<p>You should be using <code>input</code>'s <a href=\"http://developers.whatwg.org/common-input-element-attributes.html#the-placeholder-attribute\" rel=\"nofollow noreferrer\">placeholder</a> attribute instead of implementing the functionality by yourself.</p>\n\n<p>I suggest you read this article on...
{ "AcceptedAnswerId": "5483", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-19T16:21:12.837", "Id": "5471", "Score": "2", "Tags": [ "beginner", "jquery", "css" ], "Title": "Beginner jQuery – Coding Fundamentals / Performance" }
5471
<p>Goal: typesafe PropertyChanged events, minimum effort implementation for PropertyChanged events, runtime reflection of properties.</p> <p>Am I reinventing the wheel or have I created something worthwile? Would you use it in your next project?</p> <pre><code>public interface StaticProperty { public boolean canGet...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-21T09:34:40.497", "Id": "8338", "Score": "0", "body": "I don't quite understand why you have both `canReturnNull` and `canSetNull`. Why not a single `permitsNull` or so?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<p>I honestly think that your code suffers from over-engineering.</p>\n\n<p>As you can see in your <code>Woei</code> interface and <code>WoeiImpl</code> class, there is <strong>a lot</strong> of code that is required to <strong>use</strong> what you are building here. So to be blunt, I have to answer...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-19T19:30:30.610", "Id": "5475", "Score": "4", "Tags": [ "java" ], "Title": "Typesafe Java properties with events and runtime reflection" }
5475
<p>I recently posted a question looking for feedback on a script I wrote (see: <a href="https://codereview.stackexchange.com/q/5400">Scraping PubMed query results</a>)</p> <p>Since then I have re-written it into a class, which I have posted below. How does it look? How can I improve upon it?</p> <pre><code>class Pu...
[]
[ { "body": "<p>The first thing I might do is get rid of the email regex matching. PHP has this awesome functionality called <a href=\"http://www.php.net/manual/en/function.filter-var.php\" rel=\"nofollow\"><code>filter_var</code></a> that will take care of a lot of cool things for you, like <a href=\"http://www...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-20T12:43:24.287", "Id": "5485", "Score": "2", "Tags": [ "php", "object-oriented", "web-scraping", "url" ], "Title": "Scraping PubMed query results: follow-up" }
5485
<p>Is this useful or is there an obvious other way?</p> <p>The context is solving the problem of bubbling events in an asp.net site built with user controls and nested user controls. I found myself writing a ton of events.</p> <p>So instead of events, i'm using a technique to allow any client to watch an arbitrary s...
[]
[ { "body": "<p>What you have implemented is just a change event for the session value, but as you are using a delegate instead of event only one control at a time can register for the event.</p>\n\n<p>Use an event instead of a delegate, and you have a regular change event for session variables.</p>\n", "comm...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-21T01:08:46.620", "Id": "5495", "Score": "2", "Tags": [ "c#", "asp.net" ], "Title": "observing asp.net session" }
5495
<p>Using cakePHP, I would love to have your point of view about this large source code, i am not sure if its enought secure. <code>sha1()</code> will be removed with another script. I found this large script can be optimized but how ?</p> <p>i have many times </p> <pre><code>$this-&gt;Session-&gt;setFlash("You hav t...
[]
[ { "body": "<p>I answered you on SO but I'll repeat it here too.</p>\n\n<p>Please read the <a href=\"http://book.cakephp.org/\" rel=\"nofollow\">CakePHP Documentation</a>, preferably from the start because you really are getting a lot wrong here.</p>\n\n<ul>\n<li>There is no need to <code>addslashes()</code> eve...
{ "AcceptedAnswerId": "5502", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-21T11:20:13.690", "Id": "5501", "Score": "0", "Tags": [ "php", "optimization", "object-oriented" ], "Title": "Is my login function secure ? how to improve it?" }
5501
<p>Algorithm that I had to write is a perfect case for while, or do..while loop, however I found out that if I will implement it with a for loop I will save few lines of code and also scope of variables will be more appropriate. Take a look at the following code:</p> <pre><code> for ( var i = 1, offset = -1; cu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-21T19:16:33.297", "Id": "8362", "Score": "1", "body": "Too much magic in the loop condition." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-21T19:36:13.653", "Id": "8363", "Score": "0", "body":...
[ { "body": "<blockquote>\n <p>As you can see second parameter is very atypical as for for loops</p>\n</blockquote>\n\n<p>Which is why it shouldn't be a <code>for</code> loop, because as you write yourself(!) \"[it] is a perfect case for while, or do..while loop\". Saving a few lines of code and variable scope i...
{ "AcceptedAnswerId": "5509", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-21T19:09:57.367", "Id": "5508", "Score": "2", "Tags": [ "javascript" ], "Title": "What do you think about this usage of for loop in JavaScript?" }
5508
<p>In order to detect run-time integer casting problems, I've created this function*:</p> <pre><code>template&lt;typename TTo, typename TFrom&gt; static inline TTo int_cast(TFrom value) { TTo result = static_cast&lt;TTo&gt;(value); if (static_cast&lt;TFrom&gt;(result) != value || (result &gt;= TTo()) != (value...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-22T10:36:50.160", "Id": "8375", "Score": "0", "body": "If you are worried about casting problems why not stick to plain `int`s? It would be safer and faster." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-05-...
[ { "body": "<blockquote>\n <p>Are there any loopholes in this function I have not accounted for (e.g. undefined behavior)?</p>\n</blockquote>\n\n<p>No. Static cast will not result in undefined behavior.<br>\nIf it compiles then the cast is good (assuming integer/float types).</p>\n\n<p>Though some of your cast ...
{ "AcceptedAnswerId": "5519", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-22T01:25:56.970", "Id": "5515", "Score": "17", "Tags": [ "c++", "casting" ], "Title": "C++ int_cast<> function for checked casts?" }
5515
<p>I have a situation where I have six possible situations which can relate to four different results. Instead of using an extended if/else statement, I was wondering if it would be more pythonic to use a dictionary to call the functions that I would call inside the if/else as a replacement for a "switch" statement, li...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-22T13:27:38.397", "Id": "8377", "Score": "0", "body": "best practice questions are outside of the scope of code review" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T01:15:56.923", "Id": "8485", ...
[ { "body": "<p>In short, a dictionary of functions <em>IS</em> the Python equivalent of the switch statement.</p>\n\n<p>However, your implementation is awful. Start by dropping the \"switch\" in your variable names. It is not a switch, it is a dictionary. And there is no point in using \"dictionary\" in the name...
{ "AcceptedAnswerId": "5518", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-22T06:18:42.037", "Id": "5517", "Score": "1", "Tags": [ "python" ], "Title": "Is this a \"pythonic\" method of executing functions based on the values of a tuple?" }
5517
<p>I am running a math-oriented computation that spends a significant amount of its time doing <code>memcpy</code>, always copying 80 bytes from one location to the next, an array of 20 32-bit <code>int</code>s. The total computation takes around 4-5 days using both cores of my i7, so even a 1% speedup results in about...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-22T14:43:46.857", "Id": "8378", "Score": "7", "body": "Is it possible something else (other than the `memcpy`) can be optimized? What I see a lot is people think the problem is *here* when it's not. It's *there*." }, { "Content...
[ { "body": "<p>What is the assembly generated?</p>\n\n<p>I remember finding that using structs can speed things up:</p>\n\n<pre><code>typedef struct {\n int x[17] __attribute__ ((packed));\n int padding __attribute__ ((packed, unused));\n} cbytes __attribute__ ((packed));\n\n\nvoid *memcpyi80(cbytes* __restric...
{ "AcceptedAnswerId": "5536", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-22T09:35:44.380", "Id": "5520", "Score": "43", "Tags": [ "optimization", "c", "bitwise", "sse" ], "Title": "Copying 80 bytes as fast as possible" }
5520
<p>I find the TagBuilder written in C# little poor without the ability to "host" inside it sub tags (as objects not as strings).</p> <p>So I wrote a simple class that inherits TagBuilder and allow to save sub tags. I can navigate inside it and add things to it while I move across the application. And when I call the T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-23T00:44:16.007", "Id": "8389", "Score": "2", "body": "You have some fundamental issues in your code. Your `ToString()` method has some major problems. See what happens if you call it multiple times. It should only return a string repr...
[ { "body": "<p>I would make sure the list is not exposed publicly - the caller can then do whatever they want with that list, even assign <code>null</code> to it. So I've refactored it a little bit and implemented <code>Add()</code> (you may also want to implement <code>Remove()</code>, etc.):</p>\n\n<pre><code...
{ "AcceptedAnswerId": "5528", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-22T15:19:44.257", "Id": "5526", "Score": "5", "Tags": [ "c#", "design-patterns" ], "Title": "C# Multi level HTML TagBuilder object - Design pattern Review needed" }
5526
<p>I have this timer working already(<a href="http://jsbin.com/udozuk/3/edit" rel="nofollow">jsbin</a>):</p> <p>HTML:</p> <pre><code> &lt;input id="m" type="number" value="0" min="0" max="59"/&gt; &lt;input id="s" type="number" value="2" min="0" max="59"/&gt; &lt;input id="start" type="button" value="Start!" /&g...
[]
[ { "body": "<p><code>document.querySelector(\"#id\")</code> is just a costly version of <code>document.getElementById(\"id\")</code>. <code>document.getElementById</code> is the fastest way to select an element in your page (to the smartasses of you: besides <code>document.head</code>, <code>document.body</code>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-22T19:18:47.517", "Id": "5531", "Score": "4", "Tags": [ "javascript" ], "Title": "Most efficient JavaScript countdown timer implementation" }
5531
<p>Convert a decimal number to binary using only loops, strings, <code>if</code>/<code>else</code> statements. </p> <p>This is my first C++ project and it took me a while to do it. Let me know what you think.</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; using namespace std; string ConvertInt(int...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-23T20:40:28.040", "Id": "8412", "Score": "1", "body": "First comment learn how to format your code." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-23T21:34:56.443", "Id": "8413", "Score": "0", ...
[ { "body": "<p>It is considered bad practice (by most people) to declare more than one variable on a line.</p>\n\n<pre><code>double number, decValue;\nint remainder, intValue;\nstring binary1, binary2;\n</code></pre>\n\n<p>Though it is not a problem here there are some corner cases where the declaration gets con...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-23T17:33:31.340", "Id": "5542", "Score": "5", "Tags": [ "c++", "homework", "converting" ], "Title": "Decimal To Binary using only the basics" }
5542
<p>So I am working on an x86 Assembly program for Linux using NASM. This program basically asks the user for their name and their favorite color. After doing this and storing the two strings in variables declared in the .bss section, the program prints "No way <em>name of user</em>, <em>favorite color</em> is my favori...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-23T19:39:58.700", "Id": "8409", "Score": "0", "body": "The thing is, you can't really do that. You would either have to allocate enough memory for what you would expect at most, or you could ask the user for how much space should be a...
[ { "body": "<p>I have an answer in x86 tasm and written under Windows, so I'm not sure if this will help, apologies if it doesn't. Maybe the way its done will give you some ideas.</p>\n\n<pre><code>.model small\n.stack 100h\n.data\n\n\n colour db 00001111b\n input db 10, 0, \" \" ; \n\n.code\n\nmain:\n\n ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-23T17:49:10.750", "Id": "5543", "Score": "3", "Tags": [ "linux", "assembly" ], "Title": "Correct User Input - x86 Linux Assembly" }
5543
<p><em>(Originally posted on <a href="https://stackoverflow.com/questions/7867686/perl-script-to-find-all-unowned-files-and-directories-on-unix-how-can-i-optimi">Stack Overflow</a>)</em></p> <p>Following my findings and suggestions in my other post <a href="https://stackoverflow.com/questions/7854975/how-to-exclude-a-...
[]
[ { "body": "<p>Overall it looks clean and simple. Good job. Here are some things I noticed:</p>\n\n<ol>\n<li>You should use \"use warnings\" for production level code. Its odd that you use strict but not warnings.</li>\n<li>List::Util or List::MoreUtils should have a suitable replacement for your in_array() func...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-23T22:37:47.083", "Id": "5545", "Score": "1", "Tags": [ "perl", "file-system", "unix" ], "Title": "How can I further optimize this Perl script for finding all unowned files and direc...
5545
<p>I am a self taught programmer and, while I understand data structures at a theoretical level (as well as through optimizing my own code), I have never actually taken the time to write my own implementation of all the major ones.</p> <p>So, here is my linked list. I would appreciate any feedback you guys can offer ...
[]
[ { "body": "<p>My first bug bear is identifiers should not begin with an underscore:</p>\n\n<pre><code>typedef struct _node {\ntypedef struct _llist {\n</code></pre>\n\n<p>See: <a href=\"https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier/228797#228797\">what...
{ "AcceptedAnswerId": "5549", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-24T00:16:08.250", "Id": "5546", "Score": "7", "Tags": [ "c", "unit-testing", "linked-list" ], "Title": "Singly Linked List" }
5546
<p>I just started playing with Python and was hoping to get some feedback regarding the quality of the following snippet. Does this look like proper Python? What would you change? Is this small script well structured?</p> <p>Quick description of functional goal: reorder list such that each element is followed by the v...
[]
[ { "body": "<pre><code>while len(fcfs_working) &gt; 0:\n</code></pre>\n\n<p>is the same as</p>\n\n<pre><code>while fcfs_working:\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-20T14:58:03.417", "Id": "30048", "Score": "0", ...
{ "AcceptedAnswerId": "5554", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-18T05:02:50.907", "Id": "5548", "Score": "10", "Tags": [ "python" ], "Title": "Reorder list such that each element is followed by the value closest to it" }
5548
<p>As an excercise to "<a href="http://www.haskellcraft.com/craft3e/Home.html" rel="nofollow">Haskell: The Craft of Functional Programming</a>", I created some code to convert an Integer to Roman numerals.</p> <p>This is the first version and I think I'm probably not doing it in the "Haskell way" since my background i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-24T04:44:02.637", "Id": "8428", "Score": "1", "body": "Do you know about [hlint](http://community.haskell.org/~ndm/hlint/)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-25T02:03:56.213", "Id": "8444"...
[ { "body": "<p><strong>Booleans are normal values:</strong></p>\n\n<pre><code>lessThan n (a, b)\n | a &lt;= n = True\n | otherwise = False\n</code></pre>\n\n<p>Simply write:</p>\n\n<pre><code>lessThan n (a, _) = a &lt;= n\n</code></pre>\n\n<p><strong>Use pattern matching:</strong></p>\n\n<pre><code>toRoman' ::...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-24T01:16:45.197", "Id": "5550", "Score": "14", "Tags": [ "haskell", "roman-numerals" ], "Title": "Converting to Roman numerals" }
5550
<p>This is my architecture to EF4 using repository pattern and unit of work pattern with POCO. I believe I made some mistakes.</p> <p>I have a solution with 5 projects:</p> <ul> <li><code>MyApp.Common</code></li> <li><code>MyApp.Data.EF4</code></li> <li><code>MyApp.Domain.Company</code></li> <li><code>MyApp.Domain.Tr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-25T01:28:08.013", "Id": "8443", "Score": "1", "body": "Is there any way you can shorten the code snippets and provide links to the larger examples?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T08:52:4...
[ { "body": "<p>Without understanding too much of your scenario, here are a few pointers:</p>\n\n<p>I'm not that familiar with Entity Framework, but a common interface for UoW usually have the following behaviors:</p>\n\n<pre><code>public interface UnitOfWork : IDisposable {\n bool IsInTransaction { get; }\n bo...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-24T08:39:57.773", "Id": "5556", "Score": "33", "Tags": [ "c#", ".net", "entity-framework" ], "Title": "Entity framework with repository and Unit Of Work pattern and POCO architecture...
5556
<p>I am just wondering if this is a correct way to execute multiple query from a text file.</p> <pre><code>Connection conn = Utility.getConnection(); Statement stmt = null; try{ JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(chooser); if(returnVal == JFileChooser.APPROVE_...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-24T18:11:45.993", "Id": "8439", "Score": "0", "body": "well you should try to execute it, and you will have a first answer." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-24T18:18:05.317", "Id": "8440"...
[ { "body": "<p>Some ideas:</p>\n\n<ul>\n<li>Separate the GUI code from the logic.</li>\n<li>If you stay with your current mixed code fail fast. If <code>conn</code> is <code>null</code> there no sense to open the file or ask the user to choose one.</li>\n<li><code>JFileChooser.getSelectedFile()</code> returns a ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-24T18:08:53.097", "Id": "5558", "Score": "4", "Tags": [ "java", "sql", "swing", "file-system", "jdbc" ], "Title": "Execute multiple query from a text file" }
5558
<p>I know close to nothing about jQuery, but I swear I'm trying to learn. The thing is, I've got some code that works, but I know it's repetitive and probably not kosher for a real programmer, which is why I've turned to you all.</p> <p>What I want to do is show/hide (or toggle, whatever you think is best) some inform...
[]
[ { "body": "<ol>\n<li>You could have the hide/show divs inside a container, and then on <code>.ready</code> hide all its immediate children;</li>\n<li>You could then target all <code>a.close</code> inside this container, and on click hide the clicked anchor's grand-grandparent;</li>\n<li>And finally target all a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-25T07:36:42.640", "Id": "5563", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Show/hide function with multiple div ids" }
5563
<p>I have a private field called <code>individualProfile</code> (camelCase) and I've created a public property called <code>IndividualProfile</code> (PascalCase) on it:</p> <pre><code>private Profile individualProfile; public Profile IndividualProfile { get { if (individualProfile == null) { ...
[]
[ { "body": "<p>Looks perfect to me.</p>\n\n<p>The only comment I have is that, assuming an empty Profile makes sense, the <code>String.Empty</code> default on the properties could be set by the constructor - rather than you setting them explicitly.</p>\n", "comments": [], "meta_data": { "CommentCou...
{ "AcceptedAnswerId": "5570", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-25T10:31:32.103", "Id": "5565", "Score": "3", "Tags": [ "c#", "cache" ], "Title": "Public property, backing up by a private field, with caching and null checking inside" }
5565
<p>I'm teaching myself JavaScript and jQuery at the same time by trying to complete little projects that I come up with or my friends come up with. I have no official JavaScript training and am pretty much just OJT (without the job).</p> <p>I created a function below and was hoping I could get some feedback from the e...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-25T14:48:46.060", "Id": "8452", "Score": "0", "body": "It's only been 17 minutes, and you posted quite a bit of code." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-25T14:49:36.277", "Id": "8453", ...
[ { "body": "<p>here are some code optimization ( had not checked the algorithm , only syntax ).</p>\n\n<p><strong>#1</strong>\nThis : </p>\n\n<pre><code>var priceControlArray = new Array(), \npriceControlArrayMax = new Array(), \npriceControlArrayCount = new Array(), \nWKextras = 0, \nWKnewPrice = 0, \npriceCont...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-25T14:26:53.250", "Id": "5571", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Menu that updates a total price on option click" }
5571
<p>I am aware of it being frowned upon to do something like write C# in JavaScript. (see <a href="https://blog.codinghorror.com/you-can-write-fortran-in-any-language/" rel="noreferrer">this</a> if you don't know what I'm talking about)</p> <p>But as a judgement call, I think we could stand to have a relatively simple ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-25T19:50:38.630", "Id": "8458", "Score": "1", "body": "Aren't the first checks redundant after you've already tried to call `toString` on `value`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-25T20:04:37...
[ { "body": "<p>There are just a few revisions I would make. </p>\n\n<p>First, <em>always</em> use <code>===</code> instead of <code>==</code> in Javascript. You can read more about that <a href=\"https://stackoverflow.com/questions/523643/difference-between-and-in-javascript\">on Stack Overflow</a>.</p>\n\n<p>Se...
{ "AcceptedAnswerId": "5710", "CommentCount": "14", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-10-25T15:01:45.477", "Id": "5572", "Score": "56", "Tags": [ "javascript", "strings", "null" ], "Title": "String.IsNullOrEmpty in JavaScript" }
5572
<p>Please review this simple code. When I review it I decide to rewrite so that it doesn't write to a template, but instead directly to output since the whole HTML is fetched from the data layer. I used the tool <code>appengine_admin</code> to get editable HTML for simple html capabilities to an appspot project:</p> <...
[]
[ { "body": "<pre><code> application = webapp.WSGIApplication([ ('/page/([0-9]+)', PageHandler), ])\n</code></pre>\n\n<p>I'd put the list of urls as a global constant, I think that would make it easier to read.</p>\n\n<pre><code> class PageHandler(BaseHandler):\n def get(self, file_id):\n page = Pa...
{ "AcceptedAnswerId": "5578", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T02:26:09.710", "Id": "5577", "Score": "2", "Tags": [ "python", "google-app-engine" ], "Title": "HTML editor for Google App Engine" }
5577
<p>I say this is right because X might happen and Y modification to the code is possible in the future. More senior guy says the sorta similar thing, except along the lines "I'm right, you're wrong." Then I back off, b/c he is more senior. </p> <p>Here I implement a method <code>playMatingGameA(String)</code>. My more...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T04:20:12.860", "Id": "8469", "Score": "0", "body": "Of course, just a tad bit of refactoring on the A-metod wouldn't hurt. Separate helper method to check for bad arguments, and another one -- inside **catch (Exception e)** clause t...
[ { "body": "<p>I agree explicitly checking for error conditions (instead of a general catching of <code>Exception</code>) and failing fast or returning early are usually good practices, as you have done in your method. Some people don't like the break in logic flow, but there's no reason to continue on and it av...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T04:09:10.067", "Id": "5579", "Score": "5", "Tags": [ "java", "comparative-review" ], "Title": "Partner mating game" }
5579
<p>What difference does this make:</p> <pre><code>&lt;script type="text/javascript"&gt; //&lt;![CDATA[ ...code </code></pre> <p>Compared to this</p> <pre><code>&lt;script type="text/javascript"&gt; ...code </code></pre>
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T10:32:16.480", "Id": "67250", "Score": "5", "body": "This question appears to be off-topic because it is a \"What is the best practice regarding X?\" question. See [help/on-topic]." } ]
[ { "body": "<p>You should not use XHTML 1.0 anymore ( which is where you would use CDATA ). What is even more important, you should no have javascript inside your html files. Instead you should include external files via <code>&lt;script src=\"/my/js/file.js\"&gt;&lt;/script&gt;</code>.</p>\n", "comments": [...
{ "AcceptedAnswerId": "5583", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T06:24:08.197", "Id": "5582", "Score": "1", "Tags": [ "javascript" ], "Title": "Should I use CDATA in javascript?" }
5582
<p>I have created a really simple repository for some simple data retrieval and was wondering if i was going in the right direction. Has anyone got any thoughts on this?</p> <p><strong><code>interface</code></strong></p> <pre><code>public interface IRepository&lt;T&gt; where T : class { IEnumerable&lt;T&gt; GetA...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T13:26:39.200", "Id": "8475", "Score": "1", "body": "Why post the comments? Especially the summaries? 24 lines of comments (40%) in this simple piece of code carry completely redundant information and totally decrease readability." ...
[ { "body": "<p>Especially in such simple cases you don't want to create a repository over an EF (I assume it's EF -- but the same goes for Linq2SQL) context. </p>\n\n<p>The DbContext basically is an implementation of the repository pattern. Your repository on top just creates another layer of complexity without ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T13:11:28.033", "Id": "5586", "Score": "4", "Tags": [ "c#" ], "Title": "Repository for data retrieval" }
5586
<p>I'd like to know if i respect strlcat(3) behiour with my implementation, cause i'm not really sure to understand strlcat particular behaviour</p> <pre><code>int my_strlcat(char *dest, char *src, int size) { int i; int src_len; int dest_len; i = 0; dest_len = strlen(dest); src_len = strlen(src); if (s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T13:01:38.993", "Id": "8477", "Score": "2", "body": "In general, using signed types for sizes and anything but size_t for things of arbitrary size is a bad idea." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>You're basically right I think. Checking the man page for <code>strlcpy()</code> shows one discrepancy I can see - the null termination of the destination only happens if there's room in <code>dest</code> after the copying. Although that seems kind of dangerous to me, it depends how well you want ...
{ "AcceptedAnswerId": "5591", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T12:36:00.257", "Id": "5589", "Score": "2", "Tags": [ "c", "strings" ], "Title": "is it a good strlcat() implementation?" }
5589
<p>I have simple code, that draw graph of my histogram. But code looks ugly, do you have idea, how can I make it looks better ?</p> <pre><code> for (int i = 0; i &lt; hueCount - 2; ++i) { if( i % 6 == 0) g.DrawLine(borderPen, margin+ (width - 2 ...
[]
[ { "body": "<p>I had to fake a lot of your values but it seems like your DrawLine's is the same except for the color so just create a method to do the real draw line and pass in the colors etc.</p>\n\n<pre><code> for (int i = 0; i &lt; hueCount - 2; ++i)\n {\n if (i % 6 == 0)\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T18:09:16.837", "Id": "5594", "Score": "5", "Tags": [ "c#" ], "Title": "Make my draw graph looks better" }
5594
<p>I have the following code (for <code>Country</code> and <code>City</code> classes <code>key_name</code> is numeric id with addition of 'i' at the beginning):</p> <pre><code>def add_country(country, country_name): if country and country_namef and country_name != '': return Country.get_or_insert('i'+str(country...
[]
[ { "body": "<pre><code>def add_country(country, country_name):\n if country and country_namef and country_name != '':\n</code></pre>\n\n<p>I assume that country_namef is a typo. If so, there is no point in checking <code>country_name != ''</code> because empty strings are already considered False</p>\n\n<pre><c...
{ "AcceptedAnswerId": "5601", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T19:33:35.027", "Id": "5599", "Score": "0", "Tags": [ "python" ], "Title": "How to optimize the code to save data at GAE datastore?" }
5599
<p>I've coded a simple quiz game for Android, and currently Im having troubles with making questions not appear after they've been shown, i.o. I dont want it to ask me the same question twice..</p> <p>This is the method Im using</p> <pre><code> private void QBegin() { /* * Gets a random question */ que...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T11:34:10.540", "Id": "8503", "Score": "0", "body": "Duplicate over at Stack Overflow: [Creating Random Numbers with No Duplicates](http://stackoverflow.com/questions/4040001/java-creating-random-numbers-with-no-duplicates)" } ]
[ { "body": "<p>The usual way is to start with something like an array of indexes, then shuffle those into (pseudo-) random order with something like the Fisher-Yates shuffle.</p>\n\n<p>Another possibility is to use a random number generator whose range and period are exactly equal to the number of entries you ne...
{ "AcceptedAnswerId": "5604", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T21:32:54.177", "Id": "5602", "Score": "2", "Tags": [ "java", "android" ], "Title": "How to make a int not be used twice when it randomly generates them?" }
5602
<p>I need to compare some values of a Javascript object. If they fail to be identical, I want to pretty print to <code>console.log</code> the mismatch.</p> <p>The <a href="https://github.com/kaihendry/Chrome-Webview-experiments/blob/6494ed05f6527cd1c6a0d85f4fc1b765a7eb270a/sample.js" rel="nofollow">initial code I have...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T00:22:29.250", "Id": "8484", "Score": "0", "body": "Keep in mind that console.log does not exist in some versions of IE when not running the IE debugger. So, you should not ever be accessing console.log in your regular production c...
[ { "body": "<p>You could write it as:</p>\n\n<pre><code>function safeLog(s) {\n if (window.console &amp;&amp; window.console.log) {\n console.log(s);\n }\n}\n\nfunction assert(a, b, message) {\n if (a != b) {\n safeLog(\"Failed to match \" + message + \" \" + a + \" != \" + b);\n re...
{ "AcceptedAnswerId": "5613", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T22:16:57.520", "Id": "5605", "Score": "3", "Tags": [ "javascript" ], "Title": "Javascript assert function" }
5605
<p>I'm attempting to implement a calculator-like application in C#. But the way I've currently implemented it seems a little messy and inefficient. It works, but it's just I'm pretty sure it can be achieved in a more elegant solution.</p> <p>I looked to see if I could factor out any repeating code, such as the switch ...
[]
[ { "body": "<p>You should be able to use the conditional operator to get it down to 1 switch statement. I haven't done C# in a long time so I'm not sure if this will compile.</p>\n\n<pre><code>bool answer_zero = (bool)(answer != zero);\nswitch ((int)operators[index])\n{\n case (int)Operator.Plus:\n ans...
{ "AcceptedAnswerId": "5610", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-26T22:58:20.307", "Id": "5606", "Score": "7", "Tags": [ "c#", "calculator" ], "Title": "Calculator-like application" }
5606
<p>I've always wanted to come up with my own algorithm for encryption. Last evening I started writing "TreeShell" encryption algorithm that uses bit shifting and XOR operations on the bit level to do encryption. </p> <p>This algorithm allows arbitrary length of data and protection key. The key is not stored, but hashe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T17:06:34.113", "Id": "8511", "Score": "3", "body": "Just a note - Code Review can review your implementation of the algorithm, but as Chris Jester-Young says, we aren't cryptography experts. If you would like to discuss specifics of...
[ { "body": "<p>First, an important disclaimer: <strong>I am not a crypto expert (IANACE).</strong> Because of this, I will not be reviewing your code in specific. I also encourage you to only trust reviews from crypto experts.</p>\n\n<p>As I understand it, the most important thing to decide if your algorithm is ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T02:14:34.280", "Id": "5614", "Score": "3", "Tags": [ "php", "algorithm", "cryptography" ], "Title": "TreeShell PRNG and Encryption Algorithm Review" }
5614
<p>I try to replace multiple occurrences of a character with a single character.</p> <p>Input:</p> <blockquote> <p>hhiii!!! hooowww aaareee yyyooou???</p> </blockquote> <p>Output:</p> <blockquote> <p>hi! how are you?</p> </blockquote> <pre><code>public class CharSingleOccurrence { public static void m...
[]
[ { "body": "<p>Maybe I am wrong but I prefers to use the <code>regex</code> for this kind of text manipulation.\nHere is my code, </p>\n\n<pre><code>System.out.println(\"hhiii!!! hooowww aaareee yyyooou???\"\n .replaceAll(\"(.)\\\\1+\",\"$1\"));\n</code></pre>\n", "comments": [ ...
{ "AcceptedAnswerId": "5621", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T07:20:24.653", "Id": "5618", "Score": "8", "Tags": [ "java", "strings", "homework" ], "Title": "Replace multiple occurrences of a character" }
5618
<p>I'm running the below script on a WordPress powered site. It's very heavy on the animations and uses AJAX to fetch posts and load them into a <code>div</code>.</p> <p><strong>Three things I wanted to address:</strong></p> <ol> <li><p>Cleaning up the code so that it runs faster/better</p></li> <li><p>Sometimes the ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-04T23:47:52.057", "Id": "10170", "Score": "0", "body": "This would be much easier to review if it was broken down into bite-sized chunks. Just put an important part of the code here and link to the rest. Or make multiple questions with...
[ { "body": "<p>You should always cache your selectors, even if they're used only once.</p>\n\n<p>For example: <code>var $visit = $(\"#visit\");</code> etc.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T16:39:34.587", "Id": "8509", ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T15:36:45.387", "Id": "5629", "Score": "0", "Tags": [ "javascript", "jquery", "ajax" ], "Title": "Cleaning up & better AJAX response" }
5629
<p>In <a href="https://metacpan.org/module/Test%3a%3aVersion" rel="nofollow"><code>Test::Version</code></a> I want to add configuration settings that allow one to toggle certain features. I'm thinking about passing an anonymous hash to a custom <code>import</code> like so.</p> <pre><code>use Test::Version 1.2 qw( vers...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T22:03:11.707", "Id": "10822", "Score": "0", "body": "Check out [Sub::Exporter](http://p3rl.org/Sub::Exporter)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T08:00:20.040", "Id": "10858", "Sc...
[ { "body": "<p>I would stay away from changing the normal workings of <code>import()</code>. I've never seen a module mix exporting and configuration at the same time (maybe you have, though), so leave those out (options 1 and 3). I think you are right in thinking that option 2 isn't too pretty. That leaves us w...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T15:54:37.310", "Id": "5630", "Score": "2", "Tags": [ "perl" ], "Title": "How should I pass settings to a module in Perl that also exports symbols?" }
5630
<p>So this is my first time going over a pretty big nested object, was posting this up to see how I can possibly cut this down. (Some fears I have would be, I currently know the extent of the nesting (4) but could be more in the future. Which I'm not accounting for. ) </p> <p>The code below sits within a function:</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T21:45:10.620", "Id": "8518", "Score": "2", "body": "Your spidey-sense should go off whenever you find yourself with a variable named `countSubsSubsSub`. :P" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-1...
[ { "body": "<p>You could use a recursive function to traverse your object and generate the HTML.</p>\n\n<p>Something like:</p>\n\n<pre><code>function generateList(items, depth) {\n if (!depth) depth = 0;\n var ul = new Element('ul');\n if (depth) { ul.addClass('here' + depth); }\n for (var i = 0; i &...
{ "AcceptedAnswerId": "5639", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T19:11:37.677", "Id": "5633", "Score": "2", "Tags": [ "javascript", "json", "mootools" ], "Title": "Best way to iterate over JSON" }
5633
<p>I'm using the Model View Presenter (MVP) pattern in MFC that's not hugely relevant to my question but I mention it for context. I have some code that is designed to populate a list control with data from a list.</p> <p>I have two list boxes which have almost the same code except the type of list is different and t...
[]
[ { "body": "<p>To Generalize it:</p>\n\n<pre><code>class MyDialog\n{\n template&lt;typename T, typename A&gt;\n void SetCustomerList(T const&amp; customers, A action);\n ....\n};\n\n\ntemplate&lt;typename T, typename A&gt;\nvoid MyDialog::SetCustomerList(T const&amp; customers, A action)\n{\n .....\n...
{ "AcceptedAnswerId": "5635", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-27T22:07:52.340", "Id": "5634", "Score": "4", "Tags": [ "c++" ], "Title": "Generalize code that populates MFC list control?" }
5634
<p>I'm a student and I've created this MySQL database schema for my Service Order Management academic project. I want to know if I need to improve it and, if so, how I could do that.</p> <pre><code>/* * Table 'brands' */ CREATE TABLE `brands` ( `brand_id` INTEGER NOT NULL, `equipment_id` INTEGER NOT NULL, ...
[]
[ { "body": "<p>You could set the integers that act as an ID to 'unsigned'. It doesn't really improve much, it only gives you a wider range of integer values.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T06:31:3...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T05:43:34.067", "Id": "5645", "Score": "5", "Tags": [ "sql", "mysql", "homework" ], "Title": "Database schema for Service Order Management project" }
5645
<p>Is there anything that can be done differently for this function? Any way to make it faster?</p> <pre><code>public List&lt;Channel&gt; ChildrenOf(Channel startingChannel) { List&lt;Channel&gt; result = new List&lt;Channel&gt;(); foreach (Channel child in startingChannel.Children) { result.Add(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T07:31:05.467", "Id": "8526", "Score": "2", "body": "Looks to me like that's it. But maybe someone else has some other ideas." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T12:34:20.717", "Id": "8...
[ { "body": "<p>Share your result list would be one way of preventing allocations and esspecially collections to happen</p>\n\n<pre><code> public List&lt;Channel&gt; ChildrenOf(Channel startingChannel, List&lt;Channel&gt; result) \n { \n foreach (Channel child in startingChannel.Children) \n { \n...
{ "AcceptedAnswerId": "5650", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T07:26:06.660", "Id": "5648", "Score": "21", "Tags": [ "c#", "recursion" ], "Title": "Any way to make this recursive function better/faster?" }
5648
<pre><code> public List&lt;Channel&gt; Children { get { return myChannels.Where(c =&gt; c.ParentChannelId == this.Id).ToList(); } } </code></pre> <p>is this the right way to get children ? it does work, the question is if its the only way.</p> <p>could give me an e...
[]
[ { "body": "<p>Generally, you should return the items as abstract as possible. If you are just going to loop through the items and don't need it to be a list, you should use <code>IEnumerable&lt;Channel&gt;</code> as return type, even if you actually return a <code>List&lt;Channel&gt;</code>.</p>\n\n<p>Instead o...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T08:06:36.663", "Id": "5653", "Score": "0", "Tags": [ "c#" ], "Title": "Children property" }
5653
<p>I have a method to compare two byte arrays. The code is Java-style, and there are many <code>if</code>-<code>else</code>s.</p> <pre><code>def assertArray(b1: Array[Byte], b2: Array[Byte]) { if (b1 == null &amp;&amp; b2 == null) return; else if (b1 != null &amp;&amp; b2 != null) { if (b1.length != b2.length)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T10:18:27.763", "Id": "8540", "Score": "0", "body": "note : this question was first posted on SO (http://stackoverflow.com/q/7927404/112053). I think it should be migrated instead of copied, but I don't know how to do this." } ]
[ { "body": "<p>I am not fluent in Scala, but Array is just a thin layer over Java, so List might be cleaner.\nIn Java Arrays.equals(b1, b2) would be used, so delegate to java.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
{ "AcceptedAnswerId": "5672", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T09:37:49.623", "Id": "5655", "Score": "3", "Tags": [ "array", "scala" ], "Title": "Checking if two byte arrays are the same" }
5655
<p>We deliver content for different devices - web, smart tv, tablet and mobile - and I'm trying to provide a common JavaScript interface providing functions like play stream, alert, log etc without thinking of how the device actually do this.</p> <p>My question is: Is there a way to provide this like an interface, tha...
[]
[ { "body": "<p>Sure there is. They are called prototypes.</p>\n\n<p>You use prototypical inheritance.</p>\n\n<p>(Uses <a href=\"https://github.com/Raynos/pd#pd.new\" rel=\"nofollow\"><code>.new</code></a> and <a href=\"https://github.com/Raynos/pd#pd.make\" rel=\"nofollow\"><code>Object.make</code></a> because p...
{ "AcceptedAnswerId": "5657", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T11:28:25.697", "Id": "5656", "Score": "-1", "Tags": [ "javascript", "object-oriented" ], "Title": "Common interface for various devices (web, smart tv, tablet, mobile)" }
5656
<p>After finishing this article : <a href="http://coding.smashingmagazine.com/2011/10/27/lessons-from-a-review-of-javascript-code/" rel="nofollow">Lessons From A Review Of JavaScript Code</a></p> <p>I was wondering if my namespace</p> <pre><code>/** * The primary namespace object * @type {Object} * @alias BDDS */...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T15:19:04.483", "Id": "8565", "Score": "0", "body": "It won't throw a reference error, if that's what you mean." } ]
[ { "body": "<p>No your code is correct.</p>\n\n<p><code>!reference</code> only throws a reference error if its not defined.</p>\n\n<p><code>window</code> is defined and <code>window[\"not_defined\"]</code> just returns <code>undefined</code> for not defined variables.</p>\n", "comments": [], "meta_data":...
{ "AcceptedAnswerId": "5666", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T15:06:12.177", "Id": "5665", "Score": "2", "Tags": [ "javascript" ], "Title": "Namespacing patterns" }
5665
<p>Here is the problem:</p> <blockquote> <p>A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer <code>K</code> of not more than 1000000 digits, write the value of the smallest palindr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T21:12:07.797", "Id": "8578", "Score": "0", "body": "You could significantly speed it up if you convert the digit to an integer by hand instead of parsing it. e.g. `'5' - '0' == 5`." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Among other things:</p>\n\n<ul>\n<li><p>Knowing the right-side chars has exactly one purpose: it tells you whether the number you're making (when palindromized) can be returned as is, or whether you have to find the \"next\" one. So have a flag <code>needsBump</code> that starts out true. Before...
{ "AcceptedAnswerId": "5676", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-28T20:21:16.253", "Id": "5671", "Score": "6", "Tags": [ "java", "algorithm", "programming-challenge", "palindrome", "time-limit-exceeded" ], "Title": "Finding the next pali...
5671
<p>I decided to try and implement (a version of) the <a href="http://en.wikipedia.org/wiki/Simulated_annealing" rel="nofollow">simulated annealing</a> algorithm using just LINQ, just to see if I could.</p> <p>I'd love it if anybody could see any ways to improve it, or give advice on any cool tricks for doing this kind...
[]
[ { "body": "<p>You have a lot of small errors here.</p>\n\n<ul>\n<li>What is the purpose of <code>from res in Enumerable.Range(0, 1)</code>? It looks like you did it to force some local variables into 'let' queries, which makes no sense to me.</li>\n<li>Instead of using <code>OrderBy(X).First()</code> you should...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T03:15:11.423", "Id": "5677", "Score": "7", "Tags": [ "c#", "linq" ], "Title": "Linq version of the simulated annealing algorithm" }
5677
<p>There are quite a few things I am considering:</p> <ol> <li>I will have to check for <code>null</code> values</li> <li>I will have serious trouble persisting it in the database. </li> </ol> <p>How do I improve this or re-factor this for better results?</p> <pre><code>public class ErrorLog { public sta...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T12:28:09.667", "Id": "8596", "Score": "1", "body": "I dont know if there is any good way to log logging errors. Interesting question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T12:31:33.207", ...
[ { "body": "<p>Why would you have serious trouble with persistance?</p>\n\n<p>Just do null checks for InnerException and TargetSite, rest will be inserted as null or string empty depending on your db setup.</p>\n\n<p>And why not just simplify it as:</p>\n\n<pre><code>var innerExceptionMessage = e.InnerException ...
{ "AcceptedAnswerId": "5683", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T09:00:55.440", "Id": "5682", "Score": "5", "Tags": [ "c#", "logging" ], "Title": "How do I improve this logging mechanism?" }
5682
<p>I need some feedback here. Due to a weird issue on my server system, the network card disconnects from the network regularly. I'll fix this at a later date. But I wanted to know if the below script can be improved.</p> <p>It's comprised of two files. A python script (<code>autoConnect.py</code>), and a Bash script ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T16:33:29.003", "Id": "8601", "Score": "0", "body": "Welcome to Code Review, any code you want reviewed needs to be posted in the question itself." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T16:59:...
[ { "body": "<ol>\n<li>I'd move the contents of the script into a main function and then use the <code>if __name__ == '__main__'</code> boilerplate to start it.</li>\n<li>I wouldn't use external tools like bash/sed/grep to do additional logic. I'd implement that logic in python.</li>\n<li>I'd use the communicate ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T16:19:13.127", "Id": "5685", "Score": "6", "Tags": [ "python", "performance", "bash" ], "Title": "How to improve my auto-reconnection Python script" }
5685
<p>I want to make a form which looks like this:</p> <pre><code> Column A Column B 1 Textbox AA Textbox BB 2 Textbox AA Textbox BB </code></pre> <p>I've coded it like this:</p> <pre><code> &lt;form id="deps" name="deps" action="" method="POST"&gt; &lt;ul&gt; ...
[]
[ { "body": "<p>Divs of any kind are a bit of a \"lesser evil\" -- they carry no semantic info, and should be used only when (1) you need an element there and (2) there's no semantic equivalent.</p>\n\n<p>In this case, you do have a semantic equivalent. You have rows, columns, headers...data that must be arrange...
{ "AcceptedAnswerId": "5688", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T16:26:24.943", "Id": "5686", "Score": "8", "Tags": [ "html", "css" ], "Title": "Div in unordered list - good practice?" }
5686
<p>I'm new to Ruby. I normally sling code in C#. What could I do to make this simple Soundex class more Rubyesque?</p> <pre><code>class Surname attr_accessor :value def initialize(input) @value = input end def soundex result = '' @value.chars.drop(1).each do |s| number = soundex_value(s).to...
[]
[ { "body": "<p>First of all: install RSpec and write some tests if you haven't already. That will make sure you don't break anything while refactoring. (And then do all development test-first if you don't already.) Also, there are existing Ruby Soundex implementations. You might want to use one instead of writin...
{ "AcceptedAnswerId": "8180", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T20:52:06.693", "Id": "5689", "Score": "5", "Tags": [ "algorithm", "ruby" ], "Title": "Ruby implementation of Soundex algorithm" }
5689
<p>I created a simple function for swiftmailer to send two different messages for support and client. Not sure i did it the rigth way as I am using two different instances for message and one mailer instance. Everything works just fine but am I doing it the right way or I have to create separate mailer instance for eac...
[]
[ { "body": "<p><sub>Note: this is intended to be a Community wiki since it was taken from a deleted answer by <a href=\"https://codereview.stackexchange.com/users/4673/yannis\">yannis</a>; The suggestion to do this was <a href=\"https://codereview.meta.stackexchange.com/a/10625/120114\">here</a></sub></p>\n<hr /...
{ "AcceptedAnswerId": "255515", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T23:35:02.140", "Id": "5690", "Score": "5", "Tags": [ "php", "php5" ], "Title": "php swiftmailer two message instances with one mailer instance?" }
5690
<p>I got this code working with the <a href="http://plugins.jquery.com/project/countdown2" rel="nofollow">jQuery Countdown Plugin</a> to take a string input and output a countdown in a div. Is there a better way of implementing this? </p> <p><a href="http://jsfiddle.net/RN2zj/2/" rel="nofollow">JSFiddler</a></p> <p>...
[]
[ { "body": "<p>You may combine <code>var</code> statements and put them top of your function. Strip unused variables like <code>parity</code> and use <code>element</code> variable instead of using <code>#defaultCountdown</code> directly. And lastly, a little formatting will make your code much readable. <a href=...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-29T23:42:17.840", "Id": "5691", "Score": "4", "Tags": [ "javascript", "jquery", "strings", "datetime", "timer" ], "Title": "Outputting a countdown in a div" }
5691
<p>I have a <a href="http://swolepersonaltraining.com/beta/?page_id=67" rel="noreferrer">dynamic order page</a> which has to update multiple elements when a value is changed. </p> <p>Here is the main function that does that. Note it only updates the values if they are different from what is already there. So for examp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-11-04T16:49:06.617", "Id": "62827", "Score": "0", "body": "jQuery 1.7 better handles animations with increased performance. You could try updating jQuery if it helps. http://blog.jquery.com/2011/11/03/jquery-1-7-released/" } ]
[ { "body": "<p>for optimizing this function - will be better if you'll give an example of working code. Just upload some sample to <a href=\"http://jsfiddle.net/\" rel=\"noreferrer\">http://jsfiddle.net/</a>.</p>\n\n<p>Anyway, to reduce the load on any animations, use default CSS transitions.</p>\n\n<pre><code>-...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-30T00:36:06.353", "Id": "5692", "Score": "5", "Tags": [ "javascript", "jquery", "performance" ], "Title": "How to reduce load when fading in multiple elements in jQuery" }
5692
<p>This is the first time I have written Unit Tests. I am testing code that I have already written and would like to move to TDD once I have managed to get units written for everything that is already in my application. </p> <p>Just wanted to be sure that the tests that I have written look good, or if there is a diffe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-31T17:35:33.147", "Id": "8636", "Score": "0", "body": "Where does `$this->Player->GetPlayers(11, 'all', null);` get its data from in this test?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-11-07T23:38:18.96...
[ { "body": "<p>First of all, I'd create a distinct method for every <code>assertEquals()</code> call. It helps <a href=\"http://xunitpatterns.com/Goals%20of%20Test%20Automation.html#Defect%20Localization\" rel=\"nofollow\">defect localization</a>. If the first <code>assert</code> throws an error you'll have no i...
{ "AcceptedAnswerId": "5705", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-30T14:05:42.567", "Id": "5701", "Score": "4", "Tags": [ "php", "unit-testing" ], "Title": "Are my Unit Tests any good?" }
5701
<p>I have this function that should merge two array of classes when <code>id</code> of array1 is equal to <code>id</code> of array2.</p> <p>For simplicity I converted one array into an ArrayList so I can remove the occurrence merged into the other one..</p> <p>I'm looking a way to improve it, also in cpu-time, becaus...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-30T18:29:24.733", "Id": "8612", "Score": "0", "body": "Have you done any performance test which shows that this is a performance bottleneck? 20k item isn't so much..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": ...
[ { "body": "<p>Staying with your original code you can change <code>b</code> to a simple <code>break</code> and you can change the inner <code>while</code> to a <code>for</code> which is easier to read:</p>\n\n<pre><code>public Asset[] merge2(final Asset[] firstArray, final ArrayList&lt;CountR&gt; secondList) {\...
{ "AcceptedAnswerId": "5707", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-30T17:15:00.477", "Id": "5703", "Score": "6", "Tags": [ "java", "optimization", "performance", "array" ], "Title": "Merging two array of classes" }
5703
<p>well, as said in the title: We need to get a mac-address of a NIC that is providing the connection to a particular host. We use the mac-address during the login process using MSSQL and Entity Framework.</p> <p>technology: C#.NET 4.0, EF 4.1</p> <pre><code>private string _max_address; public string ConnectionString...
[]
[ { "body": "<p>I don't know about doing it more directly, but the code can definitely be cleaned up using linq as a start.</p>\n\n<pre><code>var addr = addres.First(e =&gt; e.AddressFamily == AddressFamily.InterNetwork);\nvar nic_addr = output.Split(new string[] { \"\\r\\n\" }, StringSplitOptions.RemoveEmptyEntr...
{ "AcceptedAnswerId": "5766", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-31T01:52:42.627", "Id": "5709", "Score": "4", "Tags": [ "c#" ], "Title": "C# .NET getting mac-address of a local NIC that's making a connection to a particular host" }
5709