body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Given a list, find the longest non-repeating (in other words I mean unique) string in the input list. Looking for code review, pointers on best practices, optimizations etc.</p> <pre><code>public final class LongestUniqueWord { /* * do not initialize this class */ private LongestUniqueWord( ) {} ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T06:11:36.213", "Id": "67039", "Score": "0", "body": "What happens if the two longest unique words are the same length?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T06:24:59.453", "Id": "67041",...
[ { "body": "<p>I'm on my phone so can only give pointers. </p>\n\n<ul>\n<li>In the first loop you can use <code>Map.get</code> and switch on its value:\n<ol>\n<li><code>null</code>: put <code>True</code> and add to <code>wordsByLength</code></li>\n<li><code>True</code>: put <code>False</code> and remove from <co...
{ "AcceptedAnswerId": "39935", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T05:47:10.437", "Id": "39933", "Score": "4", "Tags": [ "java", "strings", "hash-map" ], "Title": "Find the longest unique string in the input list" }
39933
<p>I am reading <em>Cracking the Code Interview</em> and I am getting a bit confused at the bit using 'previous'. In this problem, the method deletes duplicate nodes in a Linked List. </p> <p>My assumption is that <code>head</code> is used to scan through the linked list while previous is used to update the linked lis...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T09:29:10.003", "Id": "67059", "Score": "4", "body": "This question is off-topic because it contains code lifted from a book rather than [code you wrote yourself](http://meta.codereview.stackexchange.com/q/1294/9357)." } ]
[ { "body": "<p>You are right about <code>head</code>, it is used to move through the list. <code>previous</code> is a temporary pointer that is needed to perform the delete. You need it because the delete process means taking the <code>next</code> value of the Node to the left, and making it 'skip' the deleted N...
{ "AcceptedAnswerId": "39941", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T06:57:58.530", "Id": "39937", "Score": "4", "Tags": [ "java", "linked-list" ], "Title": "Delete duplicates in a linked List" }
39937
<p>I've created a simple game, in which the user needs to guess 4 digits number between 0-9, generated randomly using <code>Random()</code> Each of the 4 digits are different from each other, with no repeated digits. The user has 5 attempts to guess, and each failed (almost correct) guess will tell the user in which p...
[]
[ { "body": "<p>Just focusing on one specific point for the moment:</p>\n\n<pre><code>int temp = randy.nextInt(9);\n</code></pre>\n\n<p>This will never generate the digit <code>9</code>. </p>\n\n<p>If you want to be generating digits 0 through 9 inclusive (that is 10 different digits) you need to do:</p>\n\n<pre>...
{ "AcceptedAnswerId": "40028", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T06:59:15.047", "Id": "39938", "Score": "26", "Tags": [ "java", "game", "random", "number-guessing-game" ], "Title": "Guessing a unique 4 random digits number" }
39938
<p>I have a <code>textarea</code> and <code>iframe</code> whose sizes should change dynamically and in reverse directions. I'd like to achive this effect without using a <code>frameset</code> or jQuery plugin. Here's the result of my attempt:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta...
[]
[ { "body": "<p>Perhaps add <code>overflow:hidden;</code> to the CSS of the <code>textarea</code> and <code>iframe</code>, and add <code>scrolling=\"no\"</code> as an attribute of the HTML <code>iframe</code> element: because otherwise, a scrollbar will appear when the slider is very big or very small.</p>\n\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T07:49:45.217", "Id": "39942", "Score": "5", "Tags": [ "javascript", "html", "css" ], "Title": "Resize iframe & textarea in reverse directions" }
39942
<p><a href="http://projecteuler.net/problem=23" rel="nofollow">Project Euler Problem 23</a> asks:</p> <blockquote> <p>A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which mea...
[]
[ { "body": "<p>Your first problem is that you're trying to cram too much information onto one line. As a result, you loose the overview. Here is a simple refactoring:</p>\n\n<pre><code>def is_abundant(n):\n max_divisor = int(n / 2) + 1\n sum = 0\n for x in range(1, max_divisor):\n if n % x == 0:\...
{ "AcceptedAnswerId": "39954", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T09:50:40.890", "Id": "39946", "Score": "10", "Tags": [ "python", "optimization", "programming-challenge", "python-3.x" ], "Title": "Optimizing solution for Project Euler Pr...
39946
<p>I am wondering what a better solution would be for this bit of code:</p> <pre><code>public static void main( String[] args ) { String name = "hello, ddd"; boolean[] success = new boolean[ name.length() ]; for( char character: VALID_CHARS ) { for( int index = 0; index &lt; name.length(); index +...
[]
[ { "body": "<p>Instead of two for loops and checking the names chars with each char of VALID_CHARS i used one for..loop and check validness by checking, if the name contains the char by using the String.indexOf() method.</p>\n\n<pre><code>public static void main(String[] args) {\n String name = \"hello, ddd\"...
{ "AcceptedAnswerId": "39957", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T10:30:35.777", "Id": "39953", "Score": "10", "Tags": [ "java", "optimization", "strings", "validation" ], "Title": "Checking if a string matches an array of valid character...
39953
<p>Given <em>this kind of code</em>:</p> <pre><code>public static final int DEFAULT_MASK = Mask.BASE | Mask.SECTOR | Mask.GROUP | Mask.INDUSTRY | Mask.NAME | Mask.COUNTRY; </code></pre> <p>Sonar raises a warning:</p> <blockquote> <p>Boolean expression complexity is 5 (max allowed is 3).</p> </b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T11:23:40.547", "Id": "67066", "Score": "5", "body": "In a vacuum, I'd say that your original code is better than your workaround. However, to do a proper code review, we need more context to understand the root cause of the code sme...
[ { "body": "<p>Without any more information than in your question, this is just a thought. I have no idea what Sonar would say about this approach:</p>\n\n<pre><code>private static final int part1 = Mask.BASE | Mask.SECTOR | Mask.GROUP;\npublic static final int DEFAULT_MASK = part1 | Mask.INDUSTRY | Mask.NAME | ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T11:10:03.407", "Id": "39956", "Score": "10", "Tags": [ "java", "bitwise" ], "Title": "Boolean expression complexity and bitwise operators" }
39956
<p>When creating objects to be added to a list in Python, we can avoid the <code>if</code> statement by changing our <code>create_object</code> function to return a list.</p> <p>Is this a good idea or not? Why?</p> <p>(assume <code>create_object</code> is called in multiple places and is always added to a list)</p> ...
[]
[ { "body": "<p>Avoiding an <code>if</code> statement is not a useful goal. Occasionally it is the correct means towards a goal, such as making code easier to write or to understand. Thus I think your question is too narrowly focused, or oversimplified. The problem here is that the wrapper function <code>_create_...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T12:05:18.210", "Id": "39959", "Score": "2", "Tags": [ "python" ], "Title": "Creating objects to be added to a list" }
39959
<p>A couple of hours ago I asked a question on Stackoverflow to find out if there is <a href="https://stackoverflow.com/questions/21328328/delete-files-only-if-all-are-deletable-spare-the-innocent">a good way to delete files in a folder only if all files are indeed deletable</a> and I got some good answers that led me ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T12:20:18.783", "Id": "67072", "Score": "0", "body": "Try to rename the whole directory, if that works, create a directory with the old name and delete the moved one. Of course assumes that the OS does not do something fishy with fil...
[ { "body": "<p>Why not use a class to hold both the file and the lock, so you don`t need to manage two Lists like:</p>\n\n<pre><code>public class SafeDirectory {\n\n private File directory = null;\n private FileLock lock = null;\n private List&lt;SafeFile&gt; deleteableSafeFiles = new ArrayList&lt;&gt;(...
{ "AcceptedAnswerId": "39964", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T12:05:49.100", "Id": "39960", "Score": "5", "Tags": [ "java", "optimization", "locking" ], "Title": "Operations on files and their locks - code too bulky?" }
39960
<p>See <a href="http://en.wikipedia.org/wiki/Multiton_pattern" rel="nofollow noreferrer">Wikipedia - Multiton Pattern</a> for details on the intent.</p> <p>Here's the class:</p> <pre><code>/** * Holds a thread-safe map of unique create-once items. * * Contract: * * Only one object will be made for each key pre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T14:28:32.353", "Id": "67080", "Score": "0", "body": "Hmmm, a `Prayer` class with a `prey` method. Now that's not the same thing, is it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T14:29:16.440", ...
[ { "body": "<p>I think your use-case and the Wiki description are different. Technically, the Multiton should return the exact same intance for the exact same key, always, but, because your <code>multitons</code> Map is not a <code>static</code> instance, you can simply create multiple instances of the <code>Mul...
{ "AcceptedAnswerId": "39973", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T14:11:21.437", "Id": "39965", "Score": "11", "Tags": [ "java", "thread-safety", "multiton" ], "Title": "Utilization of the Multiton pattern" }
39965
<p>See <a href="http://en.wikipedia.org/wiki/Multiton_pattern" rel="nofollow">Wikipedia - Multiton Pattern</a></p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T14:14:08.137", "Id": "39966", "Score": "0", "Tags": null, "Title": null }
39966
In software engineering, the multiton pattern is a design pattern similar to the singleton, which allows only one instance of a class to be created. The multiton pattern expands on the singleton concept to manage a map of named instances as key-value pairs.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T14:14:08.137", "Id": "39967", "Score": "0", "Tags": null, "Title": null }
39967
<p>The first piece of code should cover the standard expected data. But as you can easily see, the data not always conveys to this standard. The code works great but I wonder if this is thought be a miss-use of the try/except clause. Better to go with if/else? </p> <pre><code>try: short_name = short_name.upper() ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T16:44:50.687", "Id": "67108", "Score": "2", "body": "Can you provide something that can be executed/tested properly and/or some information about the intended purpose." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDat...
[ { "body": "<p>I would discourage this particular usage. Not exactly because it's a risk or a hack—in other circumstances it might even be the right choice for good performance—but because I find it quite obfuscatory. (This happens to echo the usual guidance to avoid using exceptions for flow control, although i...
{ "AcceptedAnswerId": "40021", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T14:41:57.877", "Id": "39969", "Score": "4", "Tags": [ "python", "exception" ], "Title": "Generator expression in combination with StopIteration: kind of a hack?" }
39969
<p>I recently came across code that looked something like this (generates 4 random numbers in an array, this is not the actual code, I just wrote this up now, so it's untested):</p> <pre><code>var uniqueNumbers = new Array(); var count = 4; var max = 10; function main() { for (var i = 0; i &lt; count; i++) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T15:33:53.887", "Id": "67092", "Score": "0", "body": "In the first code, you should use a [do...while](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while)." }, { "ContentLicense": "CC BY-S...
[ { "body": "<p>Your first attempt is indeed in danger of getting into an infinite loop if a certain value never gets returned from rand (but any half decent PRNG will return all of them eventually).</p>\n\n<p>Your second attempt is very close to the (most optimal) <a href=\"http://en.wikipedia.org/wiki/Fisher%E2...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T15:08:48.977", "Id": "39970", "Score": "5", "Tags": [ "javascript", "random" ], "Title": "Could random unique selection using while cause an infinite loop?" }
39970
<p>I'm looking for suggestions on how to select properties on the child level or deeper dynamically. </p> <p>For example, here is the method that I am currently using. The method parameters is the <code>object</code> and either a <code>string</code> or <code>array</code> for the property name. If a <code>string</code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T18:37:53.100", "Id": "67123", "Score": "0", "body": "That is a really roundabout way of doing things." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T19:32:47.567", "Id": "67139", "Score": "0"...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li><p><code>getMappedDataProperty</code> is a clumsy name, how about <code>getProperty</code>.</p></li>\n<li><p>receiving a string is functionally the same as an array with 1 entry, so you could <br>\n<code>map = (typeof map === 'string') ? [map] : map;</code></p></...
{ "AcceptedAnswerId": "39988", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T18:17:59.223", "Id": "39979", "Score": "2", "Tags": [ "javascript" ], "Title": "What is the best to select a javascript object property at any depth?" }
39979
<p>This is my program code for comparing if 2 images are the same. It basically uses the open dialog and opens 1 image at a time and puts it in 1 picture box. </p> <p>I heard that <code>GetPixel()</code> method may be slow. Is there a more efficient and faster way to compare 2 if 2 images are the same?</p> <pre><code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T18:45:09.140", "Id": "67124", "Score": "1", "body": "Note that `Bitmap` inherits from `Image`, which implements `IDisposable`. This means you very much better call `Dispose()` on those objects are you are done with them (way many pa...
[ { "body": "<p>You can use the <code>LockBits</code> method and pointers to access the image data directly.</p>\n\n<p>Example for 24 bpp images:</p>\n\n<pre><code>bool equals = true;\nRectangle rect = new Rectangle(0, 0, bmp1.Width, bmp1.Height);\nBitmapData bmpData1 = bmp1.LockBits(rect, ImageLockMode.ReadOnly,...
{ "AcceptedAnswerId": "39987", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T18:22:36.273", "Id": "39980", "Score": "23", "Tags": [ "c#", "image" ], "Title": "Determining if 2 images are the same" }
39980
<p>I am creating an API for consumption by other developers to interface with an internal framework. My goal is to be able to have the developers type something like:</p> <pre><code>profile.setPreference(new GroupPreference(id)); </code></pre> <p>or</p> <pre><code>UserPreference preference = new UserPreference(); p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T20:31:23.587", "Id": "67160", "Score": "0", "body": "`Preference` should be an Interface instead of an Abstract class?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T21:11:02.567", "Id": "67168",...
[ { "body": "<p>Your design seems incredibly specific and inflexible. Any enhancement to the application is likely to require your <code>Preference</code> class to be modified. Furthermore, you will probably have to write a lot of custom code to implement persistence for the settings. Anytime you modify that c...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T18:25:08.833", "Id": "39982", "Score": "12", "Tags": [ "java", "object-oriented", "api" ], "Title": "Java API without exposing implementation details" }
39982
<p>I'm writing a PHP tutorial and I would like to display some forms where the users could enter values that are displayed in the same webpage, just as a demonstration. </p> <p>The forms do nothing special, they only use print instructions to display the input. </p> <p>I would like to know if these apparently innofen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-23T16:48:51.330", "Id": "67117", "Score": "0", "body": "I think it would be helpful to include the relevant code in your question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-23T16:51:07.233", "Id":...
[ { "body": "<p>The Short answer is yes you are vulnerable to injection. XSS to be precise which you can read more about here <a href=\"https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet\" rel=\"nofollow noreferrer\">https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevent...
{ "AcceptedAnswerId": "39984", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-23T16:28:55.310", "Id": "39983", "Score": "8", "Tags": [ "php", "security" ], "Title": "Are my forms a danger towards code injection?" }
39983
<p>I'm showing and hiding 4 svg paths based on the value of a slider, all is working as expected, but it still feels a little cumbersome. Does anyone know a way to "<a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a>" it out a little more?</p> <p><a href="http://jsfiddle.net/apaul34208/F9Wz7/18/">js...
[]
[ { "body": "<p>I am guessing that the '.volume' elements are like volume indicators, the louder the sound, the more you show.</p>\n\n<p>You can iterate over the '.volume' elements, compare the <code>index / elementCount</code> to <code>ui.value</code> and decide to <code>hide</code> or <code>show</code> per that...
{ "AcceptedAnswerId": "39992", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T18:35:27.237", "Id": "39986", "Score": "7", "Tags": [ "javascript", "jquery", "jquery-ui", "user-interface" ], "Title": "DRY multiple if statements used to show/hide elemen...
39986
<p>I am trying to learn to create controllers for my own HTML5 audio tags, which I often have several of on the same page. The js.jQuery code below is a simple beginning to this; it works to apply a play/pause button to each corresponding audio tag with a class of my_audio. </p> <p>I'm a new coder though, so I imagine...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T20:22:53.533", "Id": "67157", "Score": "1", "body": "Please note that JavaScript itself can't __style__ anything. This is done with CSS." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T20:25:31.443", ...
[ { "body": "<p>This is good code for a new coder.</p>\n\n<p>Some observations:</p>\n\n<ul>\n<li>I am not sure why you add a pause button through JavaScript, you could have this button declared simply in the HTML.</li>\n<li><code>doAudios</code> -> misnomer, since it deals with 1 audio at a time, so <code>doAudio...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T20:06:13.220", "Id": "39993", "Score": "4", "Tags": [ "javascript", "jquery", "html5" ], "Title": "javascript for controllers of multiple audio tags" }
39993
<p>I need to write a bit of code that will get a list of the RGB colours in an image and then translate them into a NumPy array of lab colours. I have managed to do this, but I would like to learn how I can do it more efficiently. </p> <pre><code>from skimage.color import rgb2lab from skimage.io import imread import n...
[]
[ { "body": "<ol>\n<li><p>There's no docstring for <code>get_histogram</code>. What does this function do? What kind of object should I pass for the <code>img</code> argument?</p></li>\n<li><p>You import <code>skimage.io.imread</code> and <code>PIL.Image</code> but you don't use either of them.</p></li>\n<li><p>T...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T21:00:56.563", "Id": "39997", "Score": "6", "Tags": [ "python", "beginner", "image" ], "Title": "Getting list of colours from image in lab format" }
39997
<h2>Class To Test</h2> <p>Some methods hidden for clarity</p> <pre><code>namespace RiPS.Infrastructure.UA { public class UAWorkflowManager { private readonly IContextIOAPI _api; private readonly IUAjoinedRepo _dbJoinedRepo; private readonly IRemindersSystem _remindersSystem; ...
[]
[ { "body": "<p>Your first test, CanSetup, will never fail; a .NET constructor can never return null.</p>\n\n<p>All of your tests have the same basic setup: create a \"manager\", create a \"workflow\", invoke the Assign() method w/ the same arguments. All that changes is how the WF is constructed. Consider:</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T21:22:56.967", "Id": "39998", "Score": "2", "Tags": [ "c#", "unit-testing", "moq", "nunit" ], "Title": "Multiple Services and Test Setup" }
39998
<p>This is how I handle this situation right now:</p> <p>For example, I have service that returns <code>UserDto</code> by user ID: <code>GetUserById</code>.</p> <ul> <li>Service never returns null or throws exceptions. </li> <li>Service always returns DTO objects derived from the base class (<code>DtoBase</code>).</l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T04:07:59.607", "Id": "67221", "Score": "7", "body": "I think it would be more natural to return a generic response object (Response<UserDTO>) that contains the DTO result as a property. It just seems more straightforward to reason a...
[ { "body": "<p>I only quickly glanced at your code, so this isn't going to be a thorough review, but I think the basic idea is surprising:</p>\n<blockquote>\n<p>Service never returns null or throws exceptions.</p>\n</blockquote>\n<p>I think this approach is error-prone. When I call a method called <code>GetUserB...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T21:24:45.553", "Id": "39999", "Score": "10", "Tags": [ "c#", "design-patterns", ".net", "client" ], "Title": "Telling a client that there is no result via the DTO pattern" }
39999
<p>I wanted to try out writing an minimalistic connection pool implementation (out of curiosity and for learning). Could you all please review the code and provide feedback? </p> <p>There are two classes (class names are hyperlinked to code): </p> <ol> <li><a href="https://github.com/sharmaak/crashlabs/blob/master/Mi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-08-27T07:52:29.910", "Id": "330320", "Score": "0", "body": "Lets say a client calls `surrenderConnection(connection)` but still keeps a reference to the conenction he can still go ahead and call methods like `createStatement()` and `prepa...
[ { "body": "<p>A few random notes:</p>\n\n<ol>\n<li><p>If I were you I'd check the source and API of <a href=\"http://commons.apache.org/proper/commons-pool/\" rel=\"noreferrer\">Apache Commons Pool</a>. You could borrow ideas about possible errors, corner cases, useful API calls, parameters etc.</p></li>\n<li><...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T22:27:21.597", "Id": "40005", "Score": "31", "Tags": [ "java", "jdbc", "connection-pool" ], "Title": "Connection pool implementation" }
40005
<p>I've been working on a version of Conway's Game of Life for about a week now. It has loads of features like drawing onto the screen and saving/loading images. The problem is that ever since I added mouse support, it seems to start running pretty slowly. I don't know if it is due to the mouse or if it's something e...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T23:40:51.350", "Id": "67196", "Score": "0", "body": "If you comment-out the mouse-support code, does it run quickly again?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T00:46:12.663", "Id": "671...
[ { "body": "<p>As @ChrisW mentioned: if you comment out the mouse support code, does it run quickly again? If this is the case, then changing from using a MouseMotionListener to a simple MouseListener, and check for a click instead of a drag. </p>\n\n<p>Another thing that might help is if you move complicated ...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T23:24:10.713", "Id": "40008", "Score": "8", "Tags": [ "java", "optimization", "beginner", "game-of-life" ], "Title": "Game Of Life optimization in Java" }
40008
<p>For some reporting, I need to print a human readable date string for the week covered by the report, using just the standard python module library. So the strings should look like:</p> <blockquote> <p>Dec 29, 2013 - Jan 4, 2014</p> <p>Jan 26 - Feb 1, 2014</p> <p>Jan 19 - 25, 2014</p> </blockquote> <p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-24T22:17:17.790", "Id": "67451", "Score": "0", "body": "`datetime` is part of the standard library, so they wouldn't need to install anything aside from basic Python" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>You have a bug: if <code>dt</code> is a Sunday, then it outputs the date range starting from the previous Sunday. That is because <a href=\"http://docs.python.org/2/library/datetime.html?highlight=isocalendar#datetime.date.isocalendar\"><code>datetime.isocalendar()</code></a> represents the day o...
{ "AcceptedAnswerId": "40151", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T00:24:10.703", "Id": "40012", "Score": "8", "Tags": [ "python", "strings", "datetime" ], "Title": "Printing a week range string in Python" }
40012
<p>Here is my functional approach to split a list into sub lists, each having non-decreasing numbers, so the input </p> <p>\$[1; 2; 3; 2; 4; 1; 5;]\$</p> <p>computes to</p> <p>\$[[1; 2; 3]; [2; 4]; [1; 5]]\$</p> <p>The code works, but I need a while to understand it. I would prefer a solution that is more clear. ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T02:00:54.930", "Id": "67216", "Score": "1", "body": "\"Consecutive\" would mean two integers (a, b) such that b = a + 1. It doesn't change the essence of the problem, though." }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>Haskell:</p>\n\n<pre><code>import Data.List.HT -- or Data.List.Grouping\n\ntakeruns xs@(x:xss) = map (map fst) pss\n where pss = segmentAfter (uncurry (&gt;)) $ zip xs xss\n</code></pre>\n\n<p><strong>EDIT</strong><br>\nExample:</p>\n\n<pre><code>xs = [1, 2, 3, 2, 4, 1, 5]\nxss = [2, 3, 2, 4, 1, ...
{ "AcceptedAnswerId": "203933", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T00:44:25.273", "Id": "40013", "Score": "10", "Tags": [ "functional-programming", "f#" ], "Title": "Functional approach to splitting list into sub lists" }
40013
<p><em>EDIT: Here's my totally-revised PHP...</em></p> <pre><code>$text = preg_replace("~[^ a-z0-9'-]~"," ",strtolower($INPUT)); for($i=1;$i&lt;strlen($text)-1;$i++) { if(preg_match("~['-]~",$text[$i]) &amp;&amp; ( !preg_match("~[a-z0-9]~",$text[$i-1]) || !preg_match("~[a-z0-9]~",$text[$i+1])) ){ $text[$i]...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T01:02:44.683", "Id": "67200", "Score": "0", "body": "And I just found one exception: \"a--b\" should be changed to \"a b\" but is left unchanged. Hmm." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T0...
[ { "body": "<p>Do it in two steps. First replace all the stuff you deem to be \"junk\" with spaces, then collapse the spaces and hyphens down to a single space. You can express this with a reduce through a series of patterns that collapse to a space.</p>\n\n<p>Some output from a play in Boris.</p>\n\n<pre><code>...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T00:44:39.973", "Id": "40014", "Score": "3", "Tags": [ "php", "regex" ], "Title": "Regex to clean text in preparation for word count in PHP" }
40014
<p>Is this an OK way to handle access to database connection both inside and outside of classes?</p> <p>I used to include a PHP file -- database.detl.php -- at the very top of my index.php file containing the following code:</p> <pre><code>try{ $dbh_options = array(/*...*/); $dbh = new PDO('mysql:host=localho...
[]
[ { "body": "<p>I think you've over-complicated this and locked yourself into using inheritance (which you should avoid until you actually need it). I'm going to suggest you use a singleton, which others will incidentally say to avoid, however database connection access is a great place to use a singleton. Since ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T04:37:35.230", "Id": "40022", "Score": "4", "Tags": [ "php", "classes", "pdo" ], "Title": "Handling access to database connection both inside and outside of classes" }
40022
<p>The problem: I want to find the word in a string that has the most repeats of a single letter, each letter is independent. Does not need to be consecutive.</p> <p>Currently I am jumping each character and checking, which doesn't seem very efficient. Do you have any ideas that might improve the number of processes t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T08:52:45.883", "Id": "67241", "Score": "0", "body": "I posted and answer but then I tested your code and didn't get the same output so I deleted it. What word should win between \"helllo\" and \"aabbcc\"? The first one has 2 repeate...
[ { "body": "<p>I liked that you split the string into words using a regular expression. That helps a lot.</p>\n\n<p>Your code formatting (indentation and braces) is haphazard. It shouldn't be that hard to follow the standard conventions for code formatting, and it will make things easier for yourself if you do...
{ "AcceptedAnswerId": "40031", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T07:15:29.270", "Id": "40027", "Score": "7", "Tags": [ "javascript", "optimization", "beginner", "strings" ], "Title": "Find the word in a string that has the most repeated ...
40027
<p>Please review the code quality of this JavaScript Quiz App.</p> <p>Code improvement tips and simplify are welcome.</p> <p>Demo - <a href="http://jsbin.com/eRiSUhIB/1/">http://jsbin.com/eRiSUhIB/1/</a></p> <pre><code>var quiz = [{ "question": "What is the full form of IP?", "choices": ["Internet Provider", "I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T10:03:12.450", "Id": "67247", "Score": "0", "body": "If you rightclick you can see the correct answers.some time ago i wrote a script like this that loads the questions with ajax(but without the answers)... http://stackoverflow.com/...
[ { "body": "<p>Quite nice!</p>\n\n<p>A general thought is that you could always store the correct answer first, and then show the possible answers in a random manner to make your code more DRY.</p>\n\n<p>Furthermore:</p>\n\n<ul>\n<li>Since you do not use the <code>id</code> anywhere, you can leave this out: <cod...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T08:35:44.003", "Id": "40032", "Score": "10", "Tags": [ "javascript", "game" ], "Title": "JavaScript Quiz App" }
40032
<p>The form updates a spreadsheet with agents (employees) hours worked for a specific date. The form has 4 pages, a first page where the date and office is picked. After which the form continues to one of 3 pages which has the agent names for their particular office, and a field to enter hours.</p> <p>The form submiss...
[]
[ { "body": "<p>The only thing I can suggest is to turn your array-lookups in to object-property lookups.</p>\n\n<pre><code> function createAgentLookupTable( agents ) {\n var table = {};\n for (var i = 0 , length = agents.length; i &lt; agents.length; i++) {\n agents[i].index = i;\n table[agents[...
{ "AcceptedAnswerId": "40194", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T10:32:38.017", "Id": "40034", "Score": "5", "Tags": [ "performance", "google-apps-script", "google-sheets" ], "Title": "Google Spreadsheet form script for employee work hours" ...
40034
<p>I have a question about the Repository pattern:</p> <pre><code>public abstract class RepositoryBase&lt;T&gt; : IDisposable, IRepository&lt;T&gt; where T : class, IEntity { /// &lt;summary&gt; /// For iterations using LINQ extension methods on the IQueryable and IEnumerable interfaces ///...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T20:00:09.680", "Id": "67282", "Score": "0", "body": "Is `IEntity` just a *marker interface*?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T20:16:45.793", "Id": "67283", "Score": "0", "bo...
[ { "body": "<p>Firstly I would consider injecting the DbContext into the repository. Even though your RepositoryBase class is abstract I would have a protected constructor</p>\n\n<pre><code>protected RepositoryBase(Context dbContext) {\n _context = dbContext;\n}\n</code></pre>\n\n<p>I would then look at inject...
{ "AcceptedAnswerId": "40060", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T13:55:35.850", "Id": "40038", "Score": "11", "Tags": [ "c#", ".net", "database", "repository" ], "Title": "Disposing the Context in the Repository pattern" }
40038
<p>I have another issue: I'm trying to handle connections made by local socket along with data from serial port. Here is my concept:</p> <ol> <li>Serial port is opened and monitored by select</li> <li>Local socket is opened and put in Listen state</li> <li>inside loop I call my function accept_connection periodically...
[]
[ { "body": "<p>On your questions:</p>\n\n<ol>\n<li><p>There are some oddities in your code, for example, the use of non-blocking\nsockets.</p></li>\n<li><p>Detecting disconnected clients is difficult. I'm not that familiar with\nUNIX-domain sockets, but I imagine they are much the same as Internet-domain\nsocke...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T14:17:32.427", "Id": "40039", "Score": "6", "Tags": [ "c", "serial-port" ], "Title": "Handling serial port with select and local socket" }
40039
<p>I have some VB code that connects to a MySQL database to update every control on every page of a form in our database.</p> <p>I am told this is taking longer than it should to run. The 'Setup MySql connection' comment is where it starts. I am wondering if there are any obvious optimisation tricks I am missing here,...
[]
[ { "body": "<p>I'm hoping all that's missing from your code is <code>Sub DoSomething</code> at the top and <code>End Sub</code> at the bottom. That's a <strong>very</strong> lengthy procedure you have here, and aside from the length itself, one sign is the &quot;need&quot; to append numbers to your identifiers (...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T15:47:19.403", "Id": "40042", "Score": "7", "Tags": [ "optimization", "performance", "mysql", "vb.net" ], "Title": "Updating every field of every page in a form" }
40042
<p>I have some Node/Express.js controllers which implement the exports.method Node module convention. This particular controller also has a few helper methods. The code works fine! </p> <p>However, I'm a stickler for conventions, best practices etc. and recently I've been going back over one of my project with jshi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-31T08:33:46.927", "Id": "69990", "Score": "0", "body": "What's your jshint configuration? You can set `\"node\": true`.\nSee the full list of options here: http://www.jshint.com/docs/options/" }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>Like I mentioned in my comment, adding var will probably not solve the problem. The <code>parseQueryString</code> function is declared as a variable. Therefor it should be placed earlier in the file than the call to that function. Like explained here <a href=\"https://stackoverflow.com/a/336868/32...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T16:26:45.137", "Id": "40043", "Score": "6", "Tags": [ "javascript", "node.js", "express.js" ], "Title": "Express.js controller with Node.js style exports.methods" }
40043
<p>Below is code that will compile when <code>INT_MAX</code> is equal to 2<sup>32</sup>. It will generate a compiler error when <code>INT_MAX</code> is not equal to 2<sup>32</sup>.</p> <pre><code>#include &lt;iostream&gt; #include &lt;climits&gt; namespace NBitCheck { template&lt;bool&gt; struct CTAssert; tem...
[]
[ { "body": "<p>In C++, <code>sizeof</code> returns the size of a number relative to the size of char.</p>\n\n<p>So, <code>sizeof(int)</code> should give you how many chars each int takes.</p>\n\n<p>Next, we need to know how many bits each char has. <code>CHAR_BIT</code> has that information.</p>\n\n<p>So try thi...
{ "AcceptedAnswerId": "40049", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T18:48:20.800", "Id": "40046", "Score": "5", "Tags": [ "c++", "c++11", "template", "integer", "assertions" ], "Title": "What might be another way to test if int is 32 bi...
40046
<p>I've started learning F# and functional programming in general, but the code I wrote doesn't seems to be really <em>functional</em>. Could you take a look and say how to make it more as it should be in functional programming?</p> <pre><code>type internal CsvReader(source : Stream) = // input stream let st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T22:38:12.227", "Id": "67294", "Score": "0", "body": "What's the point of all this code, why won't you just use `StreamReader.Read()`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T22:40:25.390", ...
[ { "body": "<p>Your first F# code isn't too bad. I've made some small simplifications to streamline your code a bit and take advantage of some built-in F# functions:</p>\n\n<pre><code>type internal CsvReader(source : Stream) = \n\n // input stream\n let stream = source\n\n // reader\n let mutable rea...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T19:52:01.593", "Id": "40048", "Score": "5", "Tags": [ "beginner", "functional-programming", "f#", "stream" ], "Title": "Read text from stream char by char" }
40048
<p>This is a chat using Node.js, socket.io and MongoDB for storage.</p> <p>I'd appreciate any feedback on what can be improved. I understand that this allows for non-unique usernames to be used, and it's currently a JavaScript prompt, however this is simply a demonstration for entering a username to test the functiona...
[]
[ { "body": "<p>You should only open one connection to mongodb. Otherwise if you have 10 users connected on your chat, you'll have 10 opened connections to mongodb.</p>\n\n<pre><code>var mongo = require('mongodb').MongoClient;\nvar sio = require('socket.io');\n\nmongo.connect('mongodb://127.0.0.1/chat', function(...
{ "AcceptedAnswerId": "44536", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T20:20:51.080", "Id": "40050", "Score": "4", "Tags": [ "javascript", "node.js", "mongodb", "chat", "socket.io" ], "Title": "Node.js chat client" }
40050
<p>I have this function:</p> <pre><code>int sort(book *data, int books, char mode, char sortBy) { int i, j; book aux; aux.cat = malloc(sizeof *(aux.cat)); if(sortBy == 'n') { for(i = 0; i &lt; books; i++) { for(j = i; j &lt; books; j++) { if(mode == 'a') { if(strcmp((data + i)-&gt...
[]
[ { "body": "<p>The code for the two cases (sorting by name and sorting by price) have nearly nothing in common. You may be better off writing two functions. Even if you really like this interface, it might make sense to have the master function to call a sort-by-name function or a sort-by-price function to do ...
{ "AcceptedAnswerId": "40056", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T20:55:14.367", "Id": "40051", "Score": "5", "Tags": [ "c", "sorting", "memory-management", "pointers" ], "Title": "Shorten a sorting function" }
40051
<ul> <li>Website: <a href="http://www.pubnub.com/" rel="nofollow">http://www.pubnub.com/</a></li> <li>Stack Overflow tag wiki: <a href="http://stackoverflow.com/tags/pubnub/info">http://stackoverflow.com/tags/pubnub/info</a></li> </ul>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T21:03:20.483", "Id": "40052", "Score": "0", "Tags": null, "Title": null }
40052
PubNub offers a publish/subscribe API for real-time messaging in the cloud.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T21:03:20.483", "Id": "40053", "Score": "0", "Tags": null, "Title": null }
40053
<p>I'm wondering if anyone would like to give me some solid advice on how to better organize my main.js file. I have a hunch that I should probably break the file into multiple files and decrease the amount of global variables. Maybe my naming is not so great either? I'm using codekit so I can prepend if that won't scr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T22:25:06.430", "Id": "67293", "Score": "3", "body": "please fix your indentation, it's horrific and makes reading it difficult especially in Post formatting. I already removed the white space. I would get rid of it if it is in you...
[ { "body": "<p>Two random thoughts:</p>\n\n<ol>\n<li><p>In the <em>Category Dropdown</em> part the <code>$(this).html()</code> could be extracted out to a named local variable.</p></li>\n<li><p>The following code is duplicated, it could be extracted out a separate function:</p>\n\n<pre><code>$('.transport_popup'...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T21:30:30.393", "Id": "40055", "Score": "5", "Tags": [ "javascript", "video" ], "Title": "Streaming media server" }
40055
<p>I'm basically redoing a piece of reactive C# code <a href="https://stackoverflow.com/questions/19499469/how-to-extend-throttle-timespan-in-middle-of-a-long-running-query">posted in SO</a> code in F#, please, see below. The translation is fairly literal, I've just written the infinite loop as a recursive function and...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T22:47:57.240", "Id": "67297", "Score": "1", "body": "So you want `throttleDuration` to mutate, but not be mutable? That doesn't make much sense to me." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T0...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T22:02:58.593", "Id": "40057", "Score": "4", "Tags": [ "f#", "system.reactive" ], "Title": "F# and Rx code that throttles; can it be done without ref cells (and possibly with active pa...
40057
<p>I want to learn how to write clean code from the start. This is my first project, a 'Minimum Viable Product' implementation of Conway's Game of Life in C#. Mostly I want to know if my code is readable, clean, understandable, etc.</p> <pre><code>using System; using System.Collections.Generic; using System.Componen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T02:28:23.937", "Id": "67322", "Score": "3", "body": "MVP? Wait, what? What does that stand for in this context? I don't think you're trying to figure out who was the most valuable player in the Game of Life..." }, { "Content...
[ { "body": "<p>Just a few random notes:</p>\n\n<ol>\n<li><p>Instead of <code>i</code> and <code>j</code> the variables could be called as <code>rowNumber</code> and <code>columnNumber</code>.</p>\n\n<p>Update for Thomas's comment: Reading (and understanding) code usually takes time but it's usually not because o...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T22:13:46.953", "Id": "40059", "Score": "11", "Tags": [ "c#", "beginner", "game-of-life" ], "Title": "Minimal Game of Life in C#" }
40059
<p>As part of a fun project to help build my knowledge of PHP. I've written a Data Access Class here to bridge the site to the database. I know there are a lot of posts and articles out there explaining this type of thing, but I needed some individual feedback from people.</p> <p>It does work, but I'm open to all sort...
[]
[ { "body": "<p>Just a few random notes:</p>\n\n<ol>\n<li><p>Correct me if I'm wrong but if you throw an exception the statements after the <code>throw</code> statements won't be run. So here <code>return FALSE</code> never runs, therefore it's unnecessary:</p>\n\n<pre><code>throw new Exception('Database connecti...
{ "AcceptedAnswerId": "40085", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-25T23:00:34.117", "Id": "40061", "Score": "7", "Tags": [ "php", "classes", "pdo", "formatting" ], "Title": "Specific PHP Data Access Class" }
40061
<p>I'm trying to come up with an alternative to the <code>gmean</code> implementation in <code>scipy</code>, because it is awkwardly slow. To that end I've been looking into alternate calculation methods and implementing them in <code>numpy</code>. My only issue is that a method that in the two methods I'm implementing...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T01:40:03.310", "Id": "67313", "Score": "2", "body": "Let's start with: why did you think the first method would be faster?" } ]
[ { "body": "<h3>1. Checking your claim</h3>\n\n<p>You claim that \"these both outperform <code>scipy</code>'s <code>gmean</code> implementation\", but I can't substantiate this. For example:</p>\n\n<pre class=\"lang-none prettyprint-override\"><code>&gt;&gt;&gt; import numpy\n&gt;&gt;&gt; data = numpy.random.exp...
{ "AcceptedAnswerId": "40163", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T00:06:02.613", "Id": "40067", "Score": "4", "Tags": [ "python", "numpy" ], "Title": "Optimizing numpy gmean calculation" }
40067
<p>I have a local database in <code>Windows Phone 8</code> app. The app includes a lot of queries to the database and I don't want bad effect on the responsiveness of UI.</p> <p>For example I have a table of users and method to get a user from database by id. </p> <p><strong>Current variant</strong></p> <pre><code>p...
[]
[ { "body": "<p>Before even addressing the actual question, have you actually proven that database queries are harming your responsiveness? Since the queries are to local storage it's possible that they are fast enough to not require using asynchrony, particularly if they are simple queries or the database is sma...
{ "AcceptedAnswerId": "40793", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T00:06:14.343", "Id": "40068", "Score": "8", "Tags": [ "c#", "database", "thread-safety", "async-await", "windows-phone" ], "Title": "Using keywords async/await in datab...
40068
<p>Having so many loops running concurrently obviously can't be good, and the code seems overly complicated. There has to be a simpler, more efficient way to</p> <ol> <li>Turn the designMode of all iFrames on</li> <li>Find the three "buttons" ('a' link elements) - that when clicked affect its corresponding iFrame - de...
[]
[ { "body": "<p>There is a quite bit wrong with this code, the loops are possibly the least of it.</p>\n\n<ul>\n<li>A ton of commented out code and <code>console.log</code> statements, please clean this up</li>\n<li>Inconsistent indenting, you indent with 1, 4 or 0 spaces, pick one ( I suggest 2 )</li>\n<li>The u...
{ "AcceptedAnswerId": "40161", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T01:21:03.650", "Id": "40072", "Score": "6", "Tags": [ "javascript", "optimization", "performance", "html" ], "Title": "Rich Text on multiple iFrames" }
40072
<p>Can someone look over this? This is the entire authentication file. It's referenced at the beginning of all my catalog editing files to make sure only the specified user is logged in. I want to make sure it's secure.</p> <pre><code>&lt;?php // pageauth.php // Asks for a username and a password and chec...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T02:17:55.287", "Id": "67318", "Score": "0", "body": "If you're using Basic authentication, you shouldn't need to deal with sessions; the browser will re-send whatever credentials it last used." }, { "ContentLicense": "CC BY-...
[ { "body": "<p>md5 usage may be okay on small projects, but it's generally considered weak and shouldn't be used. As of the MD5 wikipedia page:</p>\n\n<blockquote>\n <p>The security of the MD5 hash function is severely compromised.</p>\n</blockquote>\n\n<p>and <a href=\"http://us1.php.net/md5\" rel=\"nofollow n...
{ "AcceptedAnswerId": "40081", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T02:15:18.247", "Id": "40073", "Score": "5", "Tags": [ "php", "security", "authentication" ], "Title": "PHP Authentication Security" }
40073
<p>I am working on a project in which I need to have synchronous and asynchronous methods of my Java client. Some customer will call synchronously and some customer will call asynchronously, depending on their requirement.</p> <p>Here is my Java client which has <code>synchronous</code> and <code>asynchronous</code> m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T11:42:07.353", "Id": "67691", "Score": "0", "body": "Although you found already a thread-safe solution, there are other ways to achieve thread-safty. A couple of days ago an [interesting question was asked at stackoverflow](http://s...
[ { "body": "<p>If I haven't missed anything then <code>ClientKey</code> should be thread safe. Once you have build the <code>ClientKey</code> object, the <code>parameterMap</code> is only ever read and never modified. </p>\n\n<p>However it relies on the fact that no malicious or buggy client isn't trying to modi...
{ "AcceptedAnswerId": "40078", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T04:39:19.783", "Id": "40076", "Score": "3", "Tags": [ "java", "performance", "multithreading", "thread-safety" ], "Title": "Synchronous and asynchronous client methods" }
40076
<p>I am working on a project in which I am making a call to one of my servers using <code>RestTemplate</code> which is running a RESTful service and getting the response back from them. </p> <p>The response that I will be getting from my server can be either of these error responses (that's all I have for error respon...
[]
[ { "body": "<p>If you have indeed identified the json deserialization to be a performance problem (by profiling it) then you can </p>\n\n<ol>\n<li>Try using a different json serializer (GSon was reported at least in the past to be a fair bit slower than for example <a href=\"https://github.com/FasterXML/jackson\...
{ "AcceptedAnswerId": "40087", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T07:46:36.300", "Id": "40079", "Score": "3", "Tags": [ "java", "performance", "multithreading", "thread-safety", "rest" ], "Title": "Making a call to a server running a ...
40079
<p>I'm trying to get started with network and parallel programming in C#. I'm almost a complete novice in programming, so I'm looking for feedback on a small script I'm writing.</p> <p>The goal of the programming is to:</p> <ol> <li>Accept incoming connections and store them as users which are sent into <code>Room</c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T10:25:45.727", "Id": "67346", "Score": "0", "body": "“I just want the connections and asynchronous to work.” Does that mean it doesn't work now? If that's the case, your question is not appropriate here, Core Review is for reviewing...
[ { "body": "<p>A few things I noticed:</p>\n\n<ol>\n<li><p>Traditionally methods in C# follow <code>CamelCase</code> naming convention (as you can see everwhere in the .NET framework).</p></li>\n<li><p>You probably want to pass the <code>port</code> and <code>speed</code> as parameters to the server rather than ...
{ "AcceptedAnswerId": "40089", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T08:25:54.700", "Id": "40080", "Score": "5", "Tags": [ "c#", "tcp", "async-await" ], "Title": "Basic TCP server application in C# using async / await" }
40080
<p>Problem: Concat all sub-arrays of a given array. </p> <p>Example input: <code>[[0, 1], [2, 3], [4, 5]]</code></p> <p>Example output: <code>[0, 1, 2, 3, 4, 5]</code></p> <p><strong>Solution A: Use a loop</strong></p> <pre><code>var flattened=[]; for (var i=0; i&lt;input.length; ++i) { var current = input[i]; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T10:08:30.687", "Id": "67340", "Score": "5", "body": "Typical solution is `Array.prototype.concat.apply([],input)`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-11-20T04:21:17.187", "Id": "128663", ...
[ { "body": "<p><a href=\"http://jsperf.com/flatten-an-array-loop-vs-reduce\">Here</a> is the performance test for these two and couple more approaches (one suggested by @elclanrs in the comments).</p>\n\n<p>The performance differences will vary significantly across different browsers, and even different version ...
{ "AcceptedAnswerId": "40093", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T09:38:17.007", "Id": "40083", "Score": "14", "Tags": [ "javascript", "comparative-review" ], "Title": "Flatten an array - loop or reduce?" }
40083
<p>This is my first attempt a for git command I can use to push the latest commit and email the diff. Story behind how it came up: <a href="http://goo.gl/3NEHvn" rel="nofollow">http://goo.gl/3NEHvn</a></p> <p><strong>Revision 1</strong> (Scroll down for 2nd Revision)</p> <pre><code>import argparse import subprocess i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T11:42:53.203", "Id": "67353", "Score": "0", "body": "OOps I forgot to run pylint before posting, I'll do that next." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T11:50:49.827", "Id": "67355", ...
[ { "body": "<p>Here's my review on the Python code :</p>\n\n<p>As a general comment, your code does not follow <a href=\"http://www.python.org/dev/peps/pep-0008/\">this</a>. I'll try to hilight the different points as I see them but for the most obvious one, the namming convention is not respected. You can find ...
{ "AcceptedAnswerId": "40090", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T09:46:21.533", "Id": "40084", "Score": "8", "Tags": [ "python", "git" ], "Title": "Git command: push the latest commit and email the diff in colour" }
40084
<p>I am writing a method to synchronize the local Core Data entities with a remote web service (in this case, Parse.com).</p> <p>To update changed or created objects, I fetch all where the <code>updatedAt</code> date property is larger than the last local sync date. So far, so good.</p> <p>But I am struggling with th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T08:43:28.220", "Id": "67470", "Score": "0", "body": "For what it's worth, two nested `for`-loops are not the end of the world, are they?" } ]
[ { "body": "<p>You can use <code>NSPredicate</code>:</p>\n\n<pre><code>NSArray* productsToDelete = [allLocal filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@\"NOT (productId IN %@)\", allRemoteIds]];\nfor(Product* product in productsToDelete) {\n [product delete];\n}\n</code></pre>\n\n<p>This wi...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T14:05:12.477", "Id": "40095", "Score": "5", "Tags": [ "objective-c", "web-services", "sync" ], "Title": "Synchronization with remote web service" }
40095
<p>I have a (control engineering) controller. These controllers usually need several parameters to do their thing, and in my application it is desirable that these parameters can be changed while the controller is running - in a thread safe and well defined manner.</p> <p>I came up with this design (extremely simplifi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T21:39:14.190", "Id": "67429", "Score": "0", "body": "Why is this tagged 'Java'? It appears to be exclusively C# code. From what I understand, the threading mechanisms and classes in the two languages are rather different." }, { ...
[ { "body": "<p>Another option is to create ControllerInfo with mutable properties and a Clone method which would return a copy of the instance.</p>\n\n<p>Then on the ControllerInfo Info set, simply call the Clone method and set _info to the clone of the object passed in.</p>\n\n<pre><code>private ControllerInfo ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T14:26:19.787", "Id": "40096", "Score": "6", "Tags": [ "c#", "thread-safety", "immutability" ], "Title": "Allow changing the properties of a mutable controller in a thread safe way...
40096
<p>What's the best way to format a number?</p> <ul> <li>If decimal is less than <code>2</code> digits, add zero to make it <code>2</code> decimals</li> <li>If more than <code>4</code>, truncate to <code>4</code> decimals</li> <li><p>If <code>3</code> decimals, keep it to <code>3</code> decimals</p> <pre><code>14 =&gt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T17:53:01.553", "Id": "67380", "Score": "2", "body": "As I interpret it, 14.99999 → '14.9999'" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T01:39:41.203", "Id": "67443", "Score": "2", "bo...
[ { "body": "<p>since you don't want rounding, treat as string rather than number... </p>\n\n<pre><code>function strange(number){\n var n=0;\n if (number !== 0) {\n nParts = number.toString().split(/\\.|,/);\n if (nParts[1]){\n n=nParts[1].length;\n n = n &lt;=2 ? 2 : ...
{ "AcceptedAnswerId": "40139", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T14:46:09.753", "Id": "40097", "Score": "8", "Tags": [ "javascript", "formatting", "floating-point" ], "Title": "Number format in JavaScript" }
40097
<p>I keep running into the same pattern with code using promises in javascript.</p> <p>When writing a function which takes a promise and returns a promise, obviously I want to reject the promise I'm returning when the promise I received is rejected (and usually I want to pass the error down the chain verbatim). This ...
[]
[ { "body": "<p>You're making more work for yourself than necessary. </p>\n\n<p>Check this out:</p>\n\n<pre><code>var fs = require('fs');\nvar nodefn = require(\"when/node/function\");\n\nvar get_some_data = function(filename) {\n return nodefn.call(fs.readFile, filename);\n};\n\nvar parse_some_data = function(f...
{ "AcceptedAnswerId": "42965", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T14:55:30.383", "Id": "40100", "Score": "6", "Tags": [ "javascript", "error-handling", "promise" ], "Title": "Structuring functions receiving and returning promises?" }
40100
<p>In his <em><a href="http://en.wikipedia.org/wiki/Robert_Cecil_Martin#Bibliography" rel="noreferrer">Clean Code</a></em> book, <a href="http://en.wikipedia.org/wiki/Robert_Cecil_Martin" rel="noreferrer">Robert C. Martin</a> states that functions should do only one thing and one should not mix different levels of abst...
[]
[ { "body": "<p>The second one is much easier to read, it expresses the developers intent. At first sight I (as a maintainer or another developer in the same team, for example) just want a quick overview about the code and don't care about the details. (How the code creates a server socket, for example.) The seco...
{ "AcceptedAnswerId": "40103", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T16:33:42.677", "Id": "40101", "Score": "29", "Tags": [ "java", "multithreading", "exception-handling", "socket", "comparative-review" ], "Title": "Java method - levels ...
40101
<p>I have a repository class that impliments a repository Interface. In my Controllers I want a way to access the repository without creating constructors each time in the controller. So now all my Controllers have to do is inherit from Base. Any pitfalls to this, or how I can write it differently.</p> <pre><code>publ...
[]
[ { "body": "<p>This sounds exactly like a desire for Dependency Injection (using an <a href=\"https://stackoverflow.com/questions/871405/why-do-i-need-an-ioc-container-as-opposed-to-straightforward-di-code\">IoC container</a>). ASP.NET MVC is perfectly setup for this already with plenty of containers out there ...
{ "AcceptedAnswerId": "40112", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T17:02:14.777", "Id": "40102", "Score": "14", "Tags": [ "c#", "asp.net", "mvc", "controller" ], "Title": "Using a BaseController in MVC asp.net to reuse the repository" }
40102
<p>I've made an attempt at writing class wrappers around basic OpenGL objects to make managing them easier and more intuitive. Writing a generic one for program uniforms proved to require a little bit more effort than the other objects, due to there being different OpenGL functions for manipulating uniforms of differen...
[]
[ { "body": "<p>I decided to invert the class scheme: instead of having a <code>_UniformBase</code> class and having each specialization derive from it, I now have a single <code>_Uniform</code> class which owns a copy of a <code>_UniformHandler</code> class that provides the specialized uniform-setting functions...
{ "AcceptedAnswerId": "67500", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T19:21:45.473", "Id": "40117", "Score": "6", "Tags": [ "c++", "c++11", "template", "opengl", "type-safety" ], "Title": "Type safe program uniform manipulation in OpenGL"...
40117
<p>I'm looking for bugs, ways to make it more portable or standardized, improvements of any kind. Seems to do what it is supposed to on my Ubuntu 12.04 PC.</p> <pre><code>/* VLC-Watchdog v2 * * A fix for stopped VLC Media Player inhibiting the power management * daemon and preventing screen saver and/or monitor po...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T23:47:54.410", "Id": "67435", "Score": "0", "body": "I'm adding error logging and testing if the .pid file exists before trying to open it during a stop." } ]
[ { "body": "<p>Just a few simple things:</p>\n\n<ol>\n<li><p>This:</p>\n\n<blockquote>\n<pre><code>strcpy (name, \"org.mpris.MediaPlayer2.vlc-\");\nsprintf (buf, \"%d\", pid);\nstrcat (name, buf);\n</code></pre>\n</blockquote>\n\n<p>can be written as</p>\n\n<pre><code>sprintf(name, \"%s%d\", \"org.mpris.MediaPla...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T21:09:46.377", "Id": "40119", "Score": "8", "Tags": [ "c", "linux", "portability" ], "Title": "VLC media player watchdog daemon" }
40119
<p>I am currently working on a small website for my scuba diving club, and it needs a "simple" login system to allow members-only features etc.</p> <p>I've been using the php-login-minimal as the base for the PHP login: <a href="https://github.com/panique/php-login-minimal" rel="nofollow">https://github.com/panique/ph...
[]
[ { "body": "<p>Overall your code looks fine</p>\n\n<p>If you are having trouble with sessions, check the live server configuration, especially the cookie domain and path.</p>\n\n<p>I have put some inline comments in the code, the changes I have done will make it a bit easier to maintain (in my opinion) but are n...
{ "AcceptedAnswerId": "40121", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T21:15:47.780", "Id": "40120", "Score": "6", "Tags": [ "php", "html", "security", "authentication" ], "Title": "Review on a PHP login/authentication system" }
40120
<p>This algorithm is supposed to organize and visually duplicate images. I compare 2 images at a time; 1 is the first index image of the directory and another for comparing every other image in the directory. If there are duplicates of the first index image, all of the duplicates will be moved to a new folder that is n...
[]
[ { "body": "<p>The algorithm as described is <code>O(n^2)</code> worst case. Assuming that there are <code>n</code> images and no two images are equal then the first one gets compared against <code>n-1</code>, the second one against <code>n-2</code>, ... etc. so you have <code>1/2 * n * (n + 1)</code> comparison...
{ "AcceptedAnswerId": "40123", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-26T23:15:31.457", "Id": "40122", "Score": "8", "Tags": [ "c#", "algorithm", "performance", "sorting", "image" ], "Title": "Organizing and visually duplicating images" }
40122
<p>This function is intended to remove leading and trailing whitespace from a string. How can it be made more efficient? For example, can the two <code>for</code> loops be combined into one?</p> <pre><code>string trim(string str) { int i = 0; for (char c : str) { if (!isspace(c)) break...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T02:05:30.503", "Id": "67445", "Score": "1", "body": "For starters, you should pass `str` by `const&` since it's not being modified." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T02:57:17.487", "...
[ { "body": "<p>To make this more efficient, you have to consider what's inefficient about it. I see two main contenders:</p>\n\n<ol>\n<li>Data copies</li>\n<li>Data scans</li>\n</ol>\n\n<p>You copy data in up to three places. First when <code>str</code> is passed into the function it may be copied or it may be m...
{ "AcceptedAnswerId": "40302", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T01:57:57.697", "Id": "40124", "Score": "7", "Tags": [ "c++", "optimization", "strings", "c++11" ], "Title": "Trim white space from string" }
40124
<p>I'm working on an algorithm to determine if a <code>std::string</code> has all of the same character. Here is what I have:</p> <pre><code>bool string_has_all_of_the_same_chars(const std::string&amp; s) { return std::all_of(s.begin(), s.end(), [&amp;s](char ch) { return ch == s[0]; }); } </code></pre> <p>Are th...
[]
[ { "body": "<p>You could simply use <a href=\"http://en.cppreference.com/w/cpp/string/basic_string/find_first_not_of\" rel=\"noreferrer\"><code>find_first_not_of</code></a> </p>\n\n<pre><code>bool string_has_all_of_the_same_chars(const std::string&amp; s) {\n return s.find_first_not_of(s[0]) == std::string::n...
{ "AcceptedAnswerId": "40128", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T02:45:49.117", "Id": "40126", "Score": "1", "Tags": [ "c++", "algorithm", "strings" ], "Title": "Determine if a std::string has all of the same character" }
40126
<p>Working on an exercise from <a href="http://www.manning.com/bjarnason/" rel="nofollow">Functional Programming in Scala</a>, I implemented a <code>Traverse</code> instance for <code>Option</code>:</p> <pre><code>override def traverse[G[_],A,B](oa: Option[A])(f: A =&gt; G[B])(implicit G: Applicative[G]): G[Option...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T22:16:54.633", "Id": "67843", "Score": "0", "body": "Can't you just use `G.unit(oa map f)`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T22:20:42.297", "Id": "67845", "Score": "0", "bod...
[ { "body": "<ol>\n<li>Never use <code>get</code> method on option. In this case you could use <code>case Some(a)</code> instead.</li>\n<li>You don't need curly braces in <code>case</code> branches</li>\n</ol>\n\n<pre><code>oa match {\n case None =&gt; G.unit(None)\n case Some(a) =&gt;\n val x: G[B] = f(a)\n...
{ "AcceptedAnswerId": "40303", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T02:49:30.890", "Id": "40127", "Score": "3", "Tags": [ "scala" ], "Title": "Writing Traverse Instance for Option" }
40127
<p>Working on an example from <a href="http://www.manning.com/bjarnason/" rel="nofollow">Functional Programming in Scala</a>, I'm working on <code>Option#map2</code>:</p> <pre><code>override def map2[A, B, C](fa: Option[A],fb: Option[B])(f: (A, B) =&gt; C): Option[C] = { (fa, fb) match { case (None, _) =&gt; Non...
[]
[ { "body": "<p>Your code is correct - it should work nicely.</p>\n\n<p>The first thing that I would improve on is the <code>// runtime-safe get calls</code>. This is an anti-pattern in Scala and is generally discouraged. In this case you can use pattern matchings powerful extractors to get the value the <code>Op...
{ "AcceptedAnswerId": "40278", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T02:58:31.207", "Id": "40130", "Score": "2", "Tags": [ "scala" ], "Title": "Implementing Option#map2" }
40130
<p>Given the following piece of code, can it be done better:</p> <pre><code>public object DistanceFrom( IEnumerable&lt;Coordinate&gt; coordinates) { IEnumerable&lt;DbGeography&gt; addresses = coordinates.Select( c =&gt; DbGeography.FromText(String.Format("POINT ({0} {1})", c.Longitude, c.La...
[]
[ { "body": "<p>Firstly, I really don't like your indentation, particularly with the method header, so I've pasted into Visual Studio and will be working from the code as it appears below:</p>\n\n<pre><code> public object DistanceFrom(IEnumerable&lt;Coordinate&gt; coordinates)\n {\n IEnumerable&lt;Db...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T04:13:36.860", "Id": "40133", "Score": "2", "Tags": [ "c#", "linq", "entity-framework", "geospatial" ], "Title": "DbGeography calculation" }
40133
<p>I have the following questions for the below code:</p> <ol> <li>Is there a simpler implementation of an on-screen counter?</li> <li>I made <code>CountTimer</code> inner class since it's tightly coupled with the GUI part anyway. What would be the best way to uncouple them?</li> </ol> <p></p> <pre><code>package cou...
[]
[ { "body": "<p><strong>GUI</strong>:</p>\n\n<p>My preference is to have one <code>ActionListener</code> per button. This way you won't have to deal with checking the source before performing an action.</p>\n\n<hr>\n\n<p>Naming the method <code>GUI()</code> doesn't follow naming conventions. Methods should start ...
{ "AcceptedAnswerId": "40138", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T05:25:47.467", "Id": "40136", "Score": "6", "Tags": [ "java", "swing", "timer" ], "Title": "Java GUI code with Swing Timer" }
40136
<p>My program is a fraction calculator that is supposed to calculate the basic operations (+, -, *, /) and is supposed to exit when I enter % as my sentinel value. This is what I have so far; any feedback is highly appreciated. </p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdlib&gt; using namespace std; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T06:43:15.607", "Id": "67457", "Score": "2", "body": "Welcome! Please consider using proper, consistent indentation and avoiding excess whitespace. It's all over the place here and is hard to read." }, { "ContentLicense": "...
[ { "body": "<p>Had a few thoughts on your code. </p>\n\n<p>Your code doesn't accept a '%' to quit. Changing the menu to accept a '%' makes the rest of it inconsistent. so making all the input match the operation and changing the enum to reflect the character values instead of arbitrary ones helps with this.</p>...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T06:36:13.187", "Id": "40140", "Score": "5", "Tags": [ "c++", "beginner", "homework", "calculator", "rational-numbers" ], "Title": "Rational arithmetic calculator" }
40140
<p>While trying to learn more about arrays in C, I tried to write some code that did the following:</p> <ul> <li><p>Read a stream of numbers from the <code>stdin</code> and store them in an array</p></li> <li><p>Print the array in the order the numbers have been stored (i.e. print the original array)</p></li> <li><p>P...
[]
[ { "body": "<p>@sc_ray pretty good effort if you are new to C programming.</p>\n\n<p>A few points in your code which you can improve:</p>\n\n<ol>\n<li><p>Taking array values from command-line is not good. Its better you use scanf and proper data-type. Below are logs when I pass a very long int value as cmd-line ...
{ "AcceptedAnswerId": "40184", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T07:03:19.190", "Id": "40141", "Score": "3", "Tags": [ "c", "array" ], "Title": "Array manipulation exercise" }
40141
<p>Currently building my personal site using Jekyll, inuitcss and GitHub Pages. I'd like to hear your thoughts on the markup of my blog page and its post pages.</p> <p>What do you think about handling logo's like this? Also I'm not sure about the headings. The page-title probably should be part of the main section.</p...
[]
[ { "body": "<h3>Blog markup</h3>\n\n<p>The site title should be a <code>h1</code>.</p>\n\n<p>Use an <code>ul</code> for the navigation links. Or, if you don’t want that, use at least a <code>div</code> element for each link, or a textual separator between each link.</p>\n\n<p>The page title (+ the content under ...
{ "AcceptedAnswerId": "40262", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T07:37:31.657", "Id": "40142", "Score": "5", "Tags": [ "html", "html5" ], "Title": "Markup of a blog page and its posts" }
40142
<p>I just started trying out SVG the other day. Eventually I hope to be able to know how to do what SE does with their reputation graphs.</p> <p>For now, I've just been trying to set up an easier way to make lines. I think my below code is decent, but please let me know what I can improve on or what I'm doing poorly.<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-12-19T05:19:14.103", "Id": "212113", "Score": "1", "body": "Just to help you out to see how other people are creating _SVG_ renderers you might want to check out [TWO.js](https://jonobr1.github.io/two.js/). That library has a very nice wa...
[ { "body": "<p><em>Let me know what I can improve on or what I'm doing poorly.</em></p>\n\n<p>If you are going to do animations with those lines, you will want to keep track of them. I am assuming that is why you have an array of <code>LINES</code>. However, in <code>createLine</code> you create the SVG element ...
{ "AcceptedAnswerId": "40324", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T09:05:28.250", "Id": "40145", "Score": "12", "Tags": [ "javascript", "svg" ], "Title": "Making lines with SVG and JavaScript" }
40145
<p>I have this stored procedure that I'd like improved. I have changed the DB name and the procedure name. I am working on SQL Server 2000.</p> <pre><code> USE [DBName] ALTER PROCEDURE [dbo].[Table_GetSomething] @name nvarchar(50), @Cooltree nvarchar(10), @aID int, @bID int = 0 AS BEGIN -- SET...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T11:19:01.507", "Id": "67478", "Score": "7", "body": "The picture is missing and an explanation what this does." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T17:34:13.543", "Id": "67531", "Sc...
[ { "body": "<p>You have a lot of <code>if</code> statements in your SQL. This screams at me that you are doing something in your SQL that should be done in the application, and that this SQL should be separated into two distinct stored procedures. </p>\n\n<p>The benefits of doing this:</p>\n\n<ol>\n<li>Faster s...
{ "AcceptedAnswerId": "40280", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T09:58:32.323", "Id": "40146", "Score": "-5", "Tags": [ "sql", "sql-server" ], "Title": "Stored procedure" }
40146
<p>First attempt was done <a href="https://codereview.stackexchange.com/questions/36938/node-js-passport-wrapper">here</a>:</p> <p>My second attempt (now using jslint to make sure the spacing is correct and have incorporate the majority of the feedback from previous attempt).</p> <pre><code>/* * Export single functi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-29T01:30:51.357", "Id": "67866", "Score": "0", "body": "`addStandardStratergy` ;) In all seriousness, this code looks very nice." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-18T18:28:29.140", "Id": "...
[ { "body": "<p>I really like this code, I only have a few minor observations:</p>\n\n<ul>\n<li><code>'http://'</code> &lt;- https should be an option without modifying your wrapper ?</li>\n<li><code>(request.status === 200)</code> &lt;- You should provide support for when things go wrong ? Also I think <code>suc...
{ "AcceptedAnswerId": "47351", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T14:29:35.787", "Id": "40159", "Score": "11", "Tags": [ "javascript", "node.js", "authentication", "passport" ], "Title": "node.js Passport Wrapper 2" }
40159
<p>My <code>app</code> module bootstraps a Backbone.js application.<br> <strong>I need <code>app</code> to be available in every other view</strong> for easy access to router, triggering navigation, etc.</p> <p>I never ported an app to RequireJS before, and I got stuck on circular dependency problem, and <a href="http...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T14:38:31.830", "Id": "67730", "Score": "0", "body": "From an MVC perspective, your views should not have access to router or be able to trigger navigation. Don't get me wrong, I employ a similar scheme, but I think this is wrong." ...
[ { "body": "<p>There are few ways to solve your problem with Backbone.js + Require.js and executing functions or changing routes from view.</p>\n\n<h2>1. Using Backbone.Router</h2>\n\n<p>Here is approach I've used multiple times:</p>\n\n<pre class=\"lang-js prettyprint-override\"><code>'use strict';\n\n// Your v...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T14:48:50.490", "Id": "40160", "Score": "6", "Tags": [ "javascript", "backbone.js", "modules", "require.js" ], "Title": "Avoiding RequireJS circular dependencies" }
40160
<p>In Java they're not really known as <code>GOTO</code> statements and are rather referred to as <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html" rel="noreferrer">Branching Statements</a>, but I find that the former term is a bit more indicative of what they actually do.</p> <p>Regardles...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T15:22:12.330", "Id": "67503", "Score": "12", "body": "In either approach, it is worth considering [Extract-Till-You-Drop](https://sites.google.com/site/unclebobconsultingllc/one-thing-extract-till-you-drop) (with well thought of nam...
[ { "body": "<p>Your first excerpt is fine, and it is better than your second. Your second excerpt is worse because of the deeper nesting. (Also, if you were to choose nesting anyway, I'd invert the conditions to put the shorter code branch first to reduce mental workload when reading the code.)</p>\n\n<p>Consi...
{ "AcceptedAnswerId": "40170", "CommentCount": "27", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T15:03:59.253", "Id": "40162", "Score": "82", "Tags": [ "java", "parsing" ], "Title": "Nesting versus GOTO: which is better to avoid?" }
40162
<p>Provides 3 types of normal ajax - get, post, and post for form data.</p> <p>Also provides serialized ajax (get style) using a queue.</p> <p>Please review the correctness of this code.</p> <pre><code>/************************************************************************************************** AJAX */ // ......
[]
[ { "body": "<p>From a once-over:</p>\n\n<ul>\n<li><p>You keep creating the same function in <code>Pub.ajax</code>:<br></p>\n\n<pre><code> xhr.onload = function () {\n if (this.status === 200) {\n config_ajax.callback(xhr.responseText);\n }\n };\n</code></pre>\n\n<p>You could consid...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T15:33:58.333", "Id": "40167", "Score": "0", "Tags": [ "javascript" ], "Title": "A package for the DOM - Ajax" }
40167
<p>Please provide feedback on the correctness of this code. It should handle older versions of IE but how far back it goes I have not determined yet.</p> <pre><code>/************************************************************************************************** EVENTS */ // ... snip Priv.functionNull = f...
[]
[ { "body": "<p><strong>The good</strong></p>\n\n<p>Your code will handle any type of browser, is pretty easy to follow.</p>\n\n<p><strong>The bad</strong></p>\n\n<p><code>Pub.removeEvent</code> will not work. That's because you define <code>Priv.proto.removeEvent</code> twice, whereas you probably want to define...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T15:37:45.003", "Id": "40168", "Score": "1", "Tags": [ "javascript" ], "Title": "A package for the DOM - Events" }
40168
<p>I can't quite figure out the best way to approach this. I have two jQuery objects that both are used to set cookies. I then parse the JSON and set a cookie that is either the users height or the users weight.</p> <p>This works fine, but I feel like there is an extreme amount of redundant code here that could be cle...
[]
[ { "body": "<p>I'd put the cookies into an object so they can be named.</p>\n\n<pre><code>var userCookies = {\n height: {\n name: 'user-height',\n options: {\n path: '/',\n expires: 365\n }\n },\n weight: {\n name: 'user-weight',\n options: {\n ...
{ "AcceptedAnswerId": "40315", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T15:58:58.373", "Id": "40171", "Score": "7", "Tags": [ "javascript", "jquery", "beginner" ], "Title": "Pass in parameters instead of multiple functions" }
40171
<p>I've noticed some discrepancies in timings in our system, and I'm trying to narrow down what could be causing them.</p> <p>I'm reviewing out time abstraction, and as far as I can determine it's fine.</p> <p>Am I missing anything, and is it portable (besides being constrained to POSIX)?</p> <pre><code>typedef stru...
[]
[ { "body": "<p>I can see nothing wrong, but I think it is not optimal. My compiler warns me\nabout floating point conversions of those '1E9' constants. If I rewrite your\n<code>timeAdd</code> as follows, the code is easier to read and the generated code is\nsignificantly smaller:</p>\n\n<pre><code>#define BILL...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T16:59:58.583", "Id": "40176", "Score": "8", "Tags": [ "c", "datetime", "linux" ], "Title": "Correctness of calculations with struct timespec" }
40176
<p>I just want to make sure that my Rolling (Moving) Average class is understandable and reasonably <a href="https://docs.microsoft.com/en-us/archive/blogs/ericlippert/what-is-this-thing-you-call-thread-safe" rel="nofollow noreferrer">thread safe</a>.</p> <p>My main questions are:</p> <ol> <li><p>Is having totalCounts ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T22:31:10.977", "Id": "67599", "Score": "0", "body": "With `int` it does not matter, but for floating-point computations, the naive formula for a rolling average is prone to unnecessary round-off errors. And this has been known for 5...
[ { "body": "<p>To answer your questions:</p>\n\n<ol>\n<li>It's hard to say. If you expect a large number of values or moderate number of large values, you could potentially overflow an int. Otherwise, you may be fine using int instead of long.</li>\n<li>Yes, it's overkill, since dividing the total by the count...
{ "AcceptedAnswerId": "40182", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-01-27T17:02:42.643", "Id": "40177", "Score": "6", "Tags": [ "c#" ], "Title": "Rolling Average class sanity check" }
40177
<p>I have below code in one function:</p> <pre><code>public void func() { if (!string.IsNullOrEmpty(customerpay) &amp;&amp; !string.IsNullOrEmpty(warrantypay) &amp;&amp; !string.IsNullOrEmpty(maintanceplan)) { if (customerpay == "Include" &amp;&amp; warrantypay == "Include" &amp;&amp; maintanceplan == ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T17:46:01.797", "Id": "67537", "Score": "0", "body": "One thing you could do is have those `(stringVar) == \"Include\"` as boolean checks at the start of the if statement, like so: `if(/*none are null*/) { bool hasCustomerPay = custo...
[ { "body": "<p>You could do it like this:</p>\n\n<pre><code>public void func()\n{\n if (string.IsNullOrEmpty(customerpay) || string.IsNullOrEmpty(warrantypay) || string.IsNullOrEmpty(maintanceplan))\n return;\n\n if (customerpay != \"Include\" &amp;&amp; warrantypay != \"Include\" &amp;&amp; maintan...
{ "AcceptedAnswerId": "40185", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T17:20:21.167", "Id": "40178", "Score": "8", "Tags": [ "c#" ], "Title": "Simplifying conditional statements for transaction code" }
40178
<blockquote> <p>Define a macro <code>swap(t, x, y)</code> that interchanges two arguments of type <code>t</code>.(Block structure will help.)</p> </blockquote> <p>The ideea is that a variable defined in a block structure exists only inside the block structure. So, I can create a temporary variable without affecting ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T18:19:11.617", "Id": "67551", "Score": "5", "body": "I see that you have made a recent edit that invalidates some advice in the answers. It is often not recommended to make changes to your code once it has been reviewed (or even po...
[ { "body": "<p>If you are using GCC, we can use the <a href=\"http://gcc.gnu.org/onlinedocs/gcc/Typeof.html\" rel=\"nofollow noreferrer\"><code>typeof()</code></a><sup>(C99)</sup> keyword to get rid of one of the arguments. Also, <a href=\"https://stackoverflow.com/q/154136/1937270\">add a <code>do-while</code>...
{ "AcceptedAnswerId": "40181", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T17:27:30.230", "Id": "40180", "Score": "9", "Tags": [ "c", "macros" ], "Title": "Macro that interchanges 2 arguments" }
40180
<p>Today I started to tackle the 99 Haskell problems (<a href="http://www.haskell.org/haskellwiki/99_questions">http://www.haskell.org/haskellwiki/99_questions</a>). I had to struggle with problem 9 which requires to <em>Pack consecutive duplicates of list elements into sublists. If a list contains repeated elements th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T14:54:03.300", "Id": "67737", "Score": "0", "body": "For the record, that is the same as the `group` function of `Data.List`. You could also inspect its [source code](http://hackage.haskell.org/package/base-4.6.0.1/docs/src/Data-Lis...
[ { "body": "<p>Let's improve the function step by step, focusin on readability as well as on the algorithm itself.</p>\n\n<ol>\n<li><p>I believe the type of the function is not what it should be. We get a list of characters, and we should produce a list of lists:</p>\n\n<pre><code>pack1 :: [Char] -&gt; [[Char]]\...
{ "AcceptedAnswerId": "40211", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T18:03:09.000", "Id": "40188", "Score": "7", "Tags": [ "haskell" ], "Title": "99 Haskell problems, problem 9: Pack function" }
40188
<p><strong>PigLatin Kata</strong></p> <pre><code>PigLatin Kata Create a PigLatin class that is initialized with a string - detail: The string is a list of words seperated by spaces: 'hello world' - detail: The string is accessed by a method named phrase - detail: The string can be reset at any tim...
[]
[ { "body": "<p>The code clearly works, and is very concise. I think that to make it more readable, instead of using comments, you could have expressive method names:</p>\n\n<pre><code>def translate_word(word)\n replace_consonants_to_end_of_word(word)\n\n append_n_to_last_letter_y(word) or append_y_to_last_lett...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T18:27:45.713", "Id": "40189", "Score": "3", "Tags": [ "ruby", "rspec", "pig-latin" ], "Title": "Pig Latin Translator in Ruby and Rspec" }
40189
<p>I am learning about object oriented programming in Python using classes. I have attached an image of what I had in mind when structuring my classes. This is supposed script model cars. I want to know if the way that I set up my code it the ideal way of modeling cars.</p> <p>A few things:</p> <ul> <li><p>There are ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T13:25:28.030", "Id": "67707", "Score": "1", "body": "Your class hierarchy makes no sense. There are electric buses, trucks, and sports cars." } ]
[ { "body": "<p>When chaining constructors, it's customary to call the parent class constructor first, then perform the subclass-specific initialization. Here, it makes little difference since you're just setting a bunch of variables, but in more complex situations you could run into problems doing things in thi...
{ "AcceptedAnswerId": "40214", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T18:45:25.220", "Id": "40190", "Score": "9", "Tags": [ "python", "object-oriented", "classes", "python-2.x" ], "Title": "Model cars as classes" }
40190
<p>I've developed a simple CSS transition solution for a slide out menu with a single toggle, and would love some feedback on if anything could be simplified or improved.</p> <p><strong>Markup</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Slide out menu&lt;/title&gt;...
[]
[ { "body": "<p><strong>HTML:</strong></p>\n\n<ul>\n<li><p>In addition to your existing viewport meta tag, I suggest adding the width value:<br></p>\n\n<pre><code>&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n</code></pre>\n\n<p>Also moving the tag before you load your styleshe...
{ "AcceptedAnswerId": "40203", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T20:24:19.410", "Id": "40201", "Score": "6", "Tags": [ "html", "css" ], "Title": "Slide out CSS menu" }
40201
<p>I wrote a CppUnit test suite to unit-test the code that I posted <a href="https://codereview.stackexchange.com/questions/39887/lua-c-api-how-can-i-improve-this-runtime-expression-autocompletion">here</a> which is a single routine that proposes how a Lua expression could be auto-completed.</p> <p>What do you think? ...
[]
[ { "body": "<h2>Coverage</h2>\n\n<p>Your tests don't cover</p>\n\n<ul>\n<li><p>the case where there is no completion because the last separator is called on an entry that is not a table</p></li>\n<li><p>the case where <code>__index</code> is not a table</p></li>\n</ul>\n\n<p>This hints at a general problem: It s...
{ "AcceptedAnswerId": "61552", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T20:26:07.040", "Id": "40202", "Score": "7", "Tags": [ "c++", "c++11", "unit-testing" ], "Title": "CppUnit test suite for testing a routine" }
40202
<p>I feel like using this many partial views where a view renders a partial that renders a partial is just digging a hole of poor design, so I'm looking for any suggestions or guidance as to if this is best/worst practice. One of the reasons I don't like it is because it seems too easy to duplicate code across the dif...
[]
[ { "body": "<p>First of all, I don't see anything you have done here as bad practice or poor design, that being said, I would probably not opt to nest as deeply. In my thinking, breaking up the the view into sub views should be done for 2 possible reasons.</p>\n\n<ul>\n<li>Organization</li>\n<li>Reusibility</li...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T20:47:38.363", "Id": "40204", "Score": "8", "Tags": [ "c#", "html", "asp.net-mvc-4" ], "Title": "Stock list view" }
40204
<p>Here is an attempt to code a specific kind of Singleton - the one geared for our configuration needs. It needs to be initialized with a configuration location, do not allow copies or other instances, and provide feedback or fail in case of problems. Prefer graceful feedback from violated workflows. While not perform...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T16:07:03.913", "Id": "67761", "Score": "0", "body": "Doesn't relate to your questions, so I'll post it as a comment: `static std::unique_ptr<Config> cfg` should be a static member of `Config::init` to avoid issues with the initializ...
[ { "body": "<blockquote>\n <p>Does the instance() method need to be synchronized?</p>\n</blockquote>\n\n<p>Theoretically, yes: because unique_ptr isn't thread-safe: therefore you should not call get while another thread is calling reset.</p>\n\n<p>It may be safe in practice.</p>\n\n<p>Alternatively you don't ne...
{ "AcceptedAnswerId": "40218", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T20:58:38.820", "Id": "40205", "Score": "6", "Tags": [ "c++", "c++11", "singleton" ], "Title": "A parametrized Config singleton" }
40205
<p>This function converts a list to an array when list has quotes and embedded comma:</p> <pre><code>array function convertRow(required string lstRow) { var arResult = []; var arTemp = ListToArray(arguments.lstRow, ',', true); var quoteMode = false; var startQuote = false; for (var i in arTemp) ...
[]
[ { "body": "<p>I could get rid of your startQuote variable, I reduced the number of <code>i CONTAINS '\"'</code> comparasions by 1.</p>\n\n<pre><code>array function convertRow(required string lstRow) {\n var arResult = [];\n var arTemp = ListToArray(arguments.lstRow, ',', true);\n var quoteMode = false;...
{ "AcceptedAnswerId": "40216", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T21:58:31.247", "Id": "40209", "Score": "1", "Tags": [ "javascript", "array", "coldfusion" ], "Title": "Converting a list to an array when list has quotes and embedded comma" }
40209
<p>Here is the original C++ class I converted to Lisp at the very bottom of this post.</p> <pre><code>class TrainingData { public: TrainingData(const string filename); bool isEof(void) { return m_trainingDataFile.eof(); } void getTopology(vector&lt;unsigned&gt; &amp;topology); // Returns the number of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T02:15:17.393", "Id": "67640", "Score": "0", "body": "The link to the Neural Network code seems to be missing - can you please edit your question to have it please?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": ...
[ { "body": "<h2>Code review - mostly style</h2>\n\n<p>You did a litteral translation from C++ to CL that seems good. I have some stylistic issues with it:</p>\n\n<pre><code>(defclass training-data ()\n ((training-data-stream :reader training-data-stream\n :writer |set training data strea...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T22:21:36.190", "Id": "40212", "Score": "5", "Tags": [ "c++", "classes", "common-lisp" ], "Title": "Did I convert this C++ class to Common Lisp correctly?" }
40212
<p>I am kind of new to object orientation in PHP and I need some experts feedback.</p> <p>This class fetches the weather from <a href="http://api.met.no/weatherapi/locationforecast/1.8/?lat=59.32893000000001;lon=18.06491" rel="nofollow">this URL</a>.</p> <p>It grabs the weather, temperature and an icon from the curre...
[]
[ { "body": "<p>The bulk of your code looks fine, I have made what are (In my opinion) a few usability enhancements, but take it or leave it as you see fit.</p>\n\n<p>I don't think you can really make the xml processing any less ugly.</p>\n\n<p>Comments are inline</p>\n\n<pre><code>&lt;?php\n\n/**\n * Weather cla...
{ "AcceptedAnswerId": "40250", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T23:16:09.280", "Id": "40219", "Score": "3", "Tags": [ "php", "object-oriented", "xml" ], "Title": "PHP Weather class" }
40219
<p>I am creating an app in Unity3D and it is my first time coding in C#. I use the following code to parse a JSON file hosted on my server and use the information to render prefabs within my scene:</p> <pre><code> // Parses the json Object JSONParser parser = new JSONParser(); AssetData assetData = parser.ParseStr...
[]
[ { "body": "<p>I would split the asset loading into 3 different classes: <code>TextAsssetLoader</code>, <code>ImageAssetLoader</code>, and <code>VideoAssetLoader</code>. This will allow you to separate the loading of each type. Additionally, I would create an interface so you can eliminate the <code>if</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T00:09:04.480", "Id": "40221", "Score": "8", "Tags": [ "c#", "parsing", "json", "unity3d" ], "Title": "Loop through JSON and create prefab in Unity3D" }
40221
<p>A puzzle I was given:</p> <blockquote> <p><strong>Description:</strong></p> <p>Write a method that returns the "pivot" index of a list of integers. We define the pivot index as the index where the sum of the numbers on the left is equal to the sum of the numbers on the right. Given [1, 4, 6, 3, 2], the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T03:23:24.167", "Id": "67649", "Score": "1", "body": "Steven, your code is quite inefficient. For example, you calculate `last` each time through the loop, even though it doesn't change and you add up all the elements each time thro...
[ { "body": "<p>Ruby allows -1 as an index that means last, so you don't have to calculate it at all.</p>\n\n<p>Calculating the whole left_sum every time is repeating work since it is always the previous left_sum + arr[index-1] (except for when index = 0). Similarly the right_sum is always the previous right_sum ...
{ "AcceptedAnswerId": "40292", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T01:13:22.877", "Id": "40226", "Score": "7", "Tags": [ "ruby" ], "Title": "Make this Ruby array pivot more efficient?" }
40226
<p>I have two functions to count the number of set '1' bits in the first <code>offset</code> bits of either a 64 bit number, or a bitmap struct.</p> <p>After some profiling, particularly the latter is quite a bottleneck in our system.</p> <p>What can we do to make it faster?</p> <pre><code>#define POPCOUNT16(x) __bu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T03:05:32.143", "Id": "67646", "Score": "1", "body": "Either I'm confused, or you are. `count64()` takes an `int64 bitmap` — how can there be a `bitmap.hi`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01...
[ { "body": "<p>first issue: you hardcode <code>8</code> as the number of bits per <code>sizeof</code> unit: portability says it should be <code>CHAR_BIT</code> which may be something else on some architectures</p>\n\n<p>second issue: both members of int80 are signed, only <code>hi</code> should be while <code>lo...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T02:29:45.093", "Id": "40230", "Score": "4", "Tags": [ "optimization", "c", "performance", "bitwise" ], "Title": "Efficiently counting '1' bits in the first n bits" }
40230
<p>Is there any better way of printing it?</p> <pre><code>public class PercentPrinter { /** * @param args */ public static void main(String[] args) { for (int i = 0; i &lt; 100; i++) { if (i == 0) System.out.print("percent completed: " + i + " %"); try { Thread.sleep(500...
[]
[ { "body": "<p>this sounds like a good candidate for a <code>printf</code>:</p>\n\n<ul>\n<li>always print a fixed amount of backspaces.</li>\n<li>always print a fixed-size % value.</li>\n</ul>\n\n<p>Finally, when monitoring things this way you always have <a href=\"http://en.wikipedia.org/wiki/Off-by-one_error#F...
{ "AcceptedAnswerId": "40257", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-28T06:32:57.333", "Id": "40242", "Score": "5", "Tags": [ "java", "formatting", "console" ], "Title": "Is this the best way to print dynamic percent value?" }
40242