body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I've decided a while ago to make my own voxel engine. To start, I coded my own basic 3D engine in Java using minimal OpenGL bindings for things such as SRGB ect. I set up my own VBA and VBOS and had it working with .obj files. I already have transformations and Quaternions set up.</p> <p>I've recently started to im...
[]
[ { "body": "<ol>\n<li><p><code>createBlocks</code> actually fills the blocks array, creation happens before that, so this name is a little bit misleading. I'd move the array creation inside the method and use it as a return value:</p>\n\n<pre><code>private Block[][][] blocks;\n\npublic Chunk(int chunkXNumber, in...
{ "AcceptedAnswerId": "42515", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T00:41:15.057", "Id": "33812", "Score": "6", "Tags": [ "java", "opengl" ], "Title": "Making a voxel engine" }
33812
<p>I wrote a PHP function that generates JSON data to populate a line graph. Through jQuery, my code uses a GET request to the PHP script to fetch the JSON data. An example of the JSON data is as follows:</p> <pre><code>{"labels":[{"x":"2013-10-30","a":"1","b":"8"},{"x":"2013-10-31","a":"2","b":"14"},{"x":"2013-11-01"...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T04:54:51.630", "Id": "54193", "Score": "0", "body": "you are executing three different sql. Here you should execute a query only once and fetch all records. It will improve your code execution time. When you have all records, you co...
[ { "body": "<p>The first problem is what @Kinjal identified in your comment. You should only run your query once (in this particular case. You can do this because your querys basically return the same result). </p>\n\n<p>So you run your query and load it into a table, and then you can iterate and work with that ...
{ "AcceptedAnswerId": "33825", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T01:48:01.473", "Id": "33813", "Score": "1", "Tags": [ "php", "beginner", "json" ], "Title": "Feedback on a small PHP function that generates JSON data" }
33813
<p>If the prefix/suffix does not match the beginning or the end of a string, then, depending on how I call these functions, they should either raise an exception or return the original text unmodified.</p> <p>I am using these inside of a simple script for now, so there was no need to make these member functions of som...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T21:36:17.970", "Id": "54363", "Score": "0", "body": "It seems to me that you could just delete code from first `if` to first `raise`. The rest is ok." } ]
[ { "body": "<p>Firstly I would say turn your print statements into a test. That way you can change the implementation with confidence that you have not broken anything.</p>\n\n<p>Here is what those debug prints are as a test:</p>\n\n<pre><code>class TestRemove(unittest.TestCase):\n\n def test_remove_prefix(se...
{ "AcceptedAnswerId": "33845", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T03:16:55.493", "Id": "33817", "Score": "0", "Tags": [ "python", "strings", "helper" ], "Title": "remove_prefix and remove_suffix functions" }
33817
<p>I've just completed the Calculator Kata in the Kata Gem and I was hoping for some feedback. Here's the Kata:</p> <pre><code>Calculator Kata Create a calculator that is initialized with a string expression - detail: The expression is of the form digits separated by commas: "1,2" - detail: The expression is acce...
[]
[ { "body": "<p>Looks good! Most importantly, you're using <code>inject</code> properly. The specs seem nice too (although running all the <code>\"methods\"</code> expectations every time is maybe a little redundant).</p>\n\n<p>But I don't see support for this requirement:</p>\n\n<blockquote>\n <p>The expression...
{ "AcceptedAnswerId": "33842", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T03:54:26.987", "Id": "33818", "Score": "1", "Tags": [ "ruby", "calculator" ], "Title": "Ruby Kata Gem: Calculator" }
33818
<p>I wrote a program for a college assignment, and I'd like to receive some pointers on making my code a little more efficient.</p> <blockquote> <p>The program should ask the end user to enter an integer. Use the <code>isPalidrome</code> method to invoke the reverse method, and report whether the integer is a p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-02-26T15:10:27.577", "Id": "148692", "Score": "0", "body": "Am I going to be the one who says that all single digit numbers are palindromes? A special case I'll grant but if ABA is a palindrome what is wrong with B as a palindrome? I thin...
[ { "body": "<pre><code>if (isPalindrome(integer) &amp;&amp; (integer &gt; 0 &amp;&amp; integer &gt; 9))\n {\n System.out.println(integer + \" is a palindrome\");\n return;\n }\n</code></pre>\n\n<p>This piece should be moved to a se...
{ "AcceptedAnswerId": "33846", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T07:23:53.890", "Id": "33822", "Score": "6", "Tags": [ "java", "beginner", "homework", "palindrome" ], "Title": "Palindrome program with reverse method" }
33822
<p>I'll start by saying I've just started with programming, and Ruby is my first language. I've made a little soccer shoot-out game. I'm having problems with the end of the code looping back to where I want it.</p> <p>If there's a tie, I want it to keep the same score and players, but add another round of shooting. Sh...
[]
[ { "body": "<p>Not a bad start. However here's a few things that immediately pops out when I look at the code.</p>\n\n<ol>\n<li><strong>Avoid duplication:</strong> The code for both players to kick is exactly the same. You should try to move that into a function instead of writing it out twice.</li>\n<li><strong...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T08:05:44.900", "Id": "33828", "Score": "4", "Tags": [ "ruby", "beginner", "game" ], "Title": "Cleaning up code and making better loops for soccer shoot-out game" }
33828
<p>I working with a lot of Strings which I get from a web-form:</p> <pre><code>final String user = request.getParameter("user"); final String pw = request.getParameter("password"); final String name = request.getParameter("name"); final String shortname = request.getParameter("shortname"); final String appl_name = req...
[]
[ { "body": "<p>You can build a method which pulls a String from request and check if it is empty:</p>\n\n<pre><code>private static String getString(Request request, String parameter){\n\n String result = request.getParameter(parameter);\n if(result==null||result.isEmpty()){\n System.exit(0);\n }\...
{ "AcceptedAnswerId": "33843", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T10:24:41.243", "Id": "33837", "Score": "2", "Tags": [ "java", "strings" ], "Title": "Improve if-statement for multiple strings" }
33837
<p>I am currently learning JavaScript and wanted to fellow coders to review a function that I had written. I am looking for feedback particularly on:</p> <ul> <li>Whether I have followed best practice and JavaScript conventions</li> <li>Any suggestion on doing it better.</li> </ul> <p>Things I know I need to implemen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T17:33:41.133", "Id": "54479", "Score": "0", "body": "JavaScript is weakly typed. The convention is to do [duck typing](http://en.wikipedia.org/wiki/Duck_typing): do what you want to do without checking `typeof`. If it works, great! ...
[ { "body": "<p>The only criticism I can think to make of this is that you could/should maybe return a success parameter to identify if an error occurred or not.</p>\n\n<p>maybe:</p>\n\n<pre><code>var result = {\n success=true,\n message=\"The following scores were above the threshold: \" + output.join(\", \")\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T11:27:10.380", "Id": "33844", "Score": "2", "Tags": [ "javascript" ], "Title": "Refactoring a function to return all scores above a certain threshold" }
33844
<p>The environment I'm working in requires that all allocation is done through a special set of <code>malloc</code>/<code>calloc</code> functions and that a user ID is provided when allocating. The environment has no implementation of exceptions, so errors are signaled by returning <code>NULL</code>.</p> <p>For this r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T19:12:23.797", "Id": "54333", "Score": "1", "body": "Why not use new/delete?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T09:00:23.587", "Id": "54405", "Score": "0", "body": "Can you pr...
[ { "body": "<p>After some research, I'm convinced Christopher Creutzig is right. If you want all your allocations to go through customized functions, you're much better off <a href=\"https://stackoverflow.com/questions/8186018/how-to-properly-replace-global-new-delete-operators\">replacing the global operator ne...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T13:44:06.000", "Id": "33858", "Score": "4", "Tags": [ "c++", "c++11", "memory-management" ], "Title": "Implementing `create` and `destroy` functions to replace `new` and `delete` ...
33858
<p>I want to parse some reports from multiple devices, reports looks like this:</p> <blockquote> <pre><code>VR Destination Mac Age Static VLAN VID Port VR-Default 192.168.11.13 90:e2:ba:3c:95:c0 2 NO intra1 350 49 VR-Default 192.168.1.1 00:0e:...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T14:57:27.777", "Id": "54274", "Score": "0", "body": "This question does not deserve to be closed — the second program works." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T16:28:46.347", "Id": "5...
[ { "body": "<p>If a problem has been encountered before by someone else, chances are that there is a CPAN module for that <a href=\"http://search.cpan.org/dist/DataExtract-FixedWidth/\" rel=\"nofollow\">(<code>DataExtract::FixedWidth</code>)</a>.</p>\n\n<p>If you don't want to use a CPAN module, then my next cho...
{ "AcceptedAnswerId": "33894", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T14:03:43.307", "Id": "33859", "Score": "3", "Tags": [ "parsing", "perl" ], "Title": "Parsing text from reports" }
33859
<p>I'm just getting started with Python -- completing a simple exercise from a practice website. My code works -- just looking for feedback on better ways to achieve the goal.</p> <p>Goal:</p> <blockquote> <p>Find the original (unscrambled) words, which were randomly taken from a wordlist. Send a comma separated...
[]
[ { "body": "<p>I'm not a Python programmer but I would take this approach, as if I understand the problem correctly, it seems like an easy solution. Along side that I believe it makes us of the language features also.</p>\n\n<pre><code>#!/usr/bin/env python3\n\n# open word files\nwordlist = open(\"wordlist.txt\"...
{ "AcceptedAnswerId": "33862", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T14:29:15.703", "Id": "33861", "Score": "3", "Tags": [ "python", "beginner", "python-3.x" ], "Title": "Find scrambled words within word list" }
33861
<p>Just thought I'd share this and see what kind of improvements could be made that I'm not aware of and taking advantage of.</p> <p>The situation is this: I have a list of items on a page that have a button that opens a menu. I need a click away event as well as close others when a new menu is opened. Also some of th...
[]
[ { "body": "<p>I believe there is no better way. Regardless, we can shorten the code a little. Also note that <a href=\"http://api.jquery.com/delegate/\" rel=\"nofollow\">.delegate()</a> has been superceded by <a href=\"http://api.jquery.com/on/\" rel=\"nofollow\">.on()</a> since jQuery 1.7, so I replaced your d...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T14:43:41.610", "Id": "33863", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "jQuery delegate events on dynamic elements with a click away handler" }
33863
<p>This <a href="http://codility.com/demo/take-sample-test/triangle" rel="nofollow">Codility challenge</a> is to take an array of integers representing lengths of line segments, and determine whether or not it is possible to choose three distinct segments to form a triangle. (The sum of the lengths of any two sides mu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T17:26:39.760", "Id": "54313", "Score": "2", "body": "please include the basics of the problem from the link. i clicked the link, and it wanted me to do the test, this could be considered spam by some, trying to lure people to a site...
[ { "body": "<p>Funny things that we(human) know that 2,147,483,647 + 1 = 2,147,483,648 but computer thinks <a href=\"http://ideone.com/QX7N6z\" rel=\"nofollow noreferrer\">otherwise</a>. <em>Ahhh! see</em>, so now what to do?</p>\n\n<p>You know <code>4 + 5 &gt; 7</code> is same as <code>5 &gt; (7 - 3)</code>. Ye...
{ "AcceptedAnswerId": "33881", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T17:19:20.980", "Id": "33868", "Score": "3", "Tags": [ "java", "interview-questions", "programming-challenge" ], "Title": "Determining possible triangle from lengths of line se...
33868
<p>Code golfing is the challenge of accomplishing a given task with the shortest source code. The name comes from the sport of golf, where players try to hit the ball into the hole using the fewest number of strokes. When code golfing, all usual considerations, such as clarity and performance, are considered secondar...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T17:27:32.443", "Id": "33869", "Score": "0", "Tags": null, "Title": null }
33869
Code golfing is the challenge of accomplishing a given task with the shortest source code. NOTE: Code golfing is **off-topic** for this site.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T17:27:32.443", "Id": "33870", "Score": "0", "Tags": null, "Title": null }
33870
<p>The tests consist of relatively simple programming tasks (Fibonacci sequence, equilibrium index, etc.) and aim to evaluate the applicant's ability to write working, error-free code that is also good performance-wise. Solutions must be produced within a set time limit. It's possible to create and run test cases while...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T17:41:19.937", "Id": "33871", "Score": "0", "Tags": null, "Title": null }
33871
Codility offers browser-based tests to verify programming skills of job applicants. The platform supports 14 programming languages, including Java, C#, Ruby, Python, Objective-C, JavaScript and more.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T17:41:19.937", "Id": "33872", "Score": "0", "Tags": null, "Title": null }
33872
<p>I'm making a server in C that needs to parse JSON that follows oBIX protocol and I'm using the <a href="https://jansson.readthedocs.org/en/2.5/" rel="nofollow">Jansson library</a> for this. I've been programming in high level languages such as Java and C# for my entire career and the last time I touched C was way ba...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T19:23:41.347", "Id": "54487", "Score": "0", "body": "It is better to use const and enums than #define, because #define's are I scoped and unchecked." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T19:...
[ { "body": "<p>A few notes:</p>\n\n<ul>\n<li><p>My first concern with your program is the use of the Jansson library. <a href=\"http://chadaustin.me/2013/01/json-parser-benchmarking/\" rel=\"nofollow noreferrer\">Looking at some benchmarks</a> shows me that it is less than stellar. (The Y-axis is parses-per-sec...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T17:50:42.927", "Id": "33873", "Score": "7", "Tags": [ "c", "json" ], "Title": "Parsing function for a server, using the Jansson library" }
33873
<p>I'm looking for some feedback on Python best practices, general code quality, and bonus points if you have knowledge of CANOpen that you can leverage to find anything I missed functionality-wise, but isn't necessary! I'm hoping that this isn't too technical.</p> <p><strong>PDOMapping.py:</strong></p> <pre><code>im...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T21:20:55.987", "Id": "54358", "Score": "0", "body": "Could you give a pointer to the context? What is a PDO, etc?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T21:37:46.420", "Id": "54364", ...
[ { "body": "<p>Well, here are a few points that I noticed:</p>\n\n<ul>\n<li>The docstrings are all a long single line, which is hard to read on StackExchange, and in most editors as well. I would suggest to wrap the docstrings to a reasonable line length.</li>\n<li>Spelling error -- \"recieve\" (in <code>recieve...
{ "AcceptedAnswerId": "33888", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T19:25:57.167", "Id": "33878", "Score": "2", "Tags": [ "python", "object-oriented" ], "Title": "PDOMapping: a CAN Open Process Data Object Management Class" }
33878
<p>I'm porting some AVR code from <a href="http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html"><code>PROGMEM</code>/<code>PGM_P</code></a> to <a href="http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Named-Address-Spaces.html"><code>__flash</code></a>, and I want to reduce the amount of conditional compila...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T21:08:28.727", "Id": "54353", "Score": "0", "body": "The known alternative to #conditionals is to make a variable and use normal control flow statements. So, I don't understand what you are asking here? The advantage of #conditional...
[ { "body": "<p>A few notes:</p>\n\n<ul>\n<li><p>Your included libraries and definitions at the beginning of your code is not very organized.</p>\n\n<blockquote>\n<pre><code>#include &lt;avr/io.h&gt;\n//#undef __FLASH\n#ifndef __FLASH\n#include &lt;avr/pgmspace.h&gt;\n#define FLASH(x) const x PROGMEM\n#define FLA...
{ "AcceptedAnswerId": "40852", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T20:37:23.400", "Id": "33883", "Score": "8", "Tags": [ "c", "assembly", "type-safety", "embedded" ], "Title": "Embedded conditional code compaction" }
33883
<p>That's an easy one. I just want to calculate the Hamming distance between two strings.</p> <pre><code>function hamming(str1,str2) local distance = 0 -- cannot calculate Hamming distance if strings have different sizes if #str1 ~= #str2 then return false end for i = 1, #str1 do if str1:sub(i,i) ~= str2...
[]
[ { "body": "<p>There is nothing inefficient about your loop. You are simply counting from <code>1</code> to <code>#str1</code>. Both bounds are known in advance. This is as good as it gets with loops in Lua.</p>\n\n<p>The only improvement I could think of was using <code>string.byte</code> instead of <code>st...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T02:42:56.790", "Id": "33896", "Score": "2", "Tags": [ "strings", "lua" ], "Title": "Calculating the Hamming distance" }
33896
<p>I am, primarily for learning purposes, working on creating an editor component in C++ with Qt. As a first step, to begin getting familiar with editing a document via <code>QTextCursor</code>, I wrote this function on my subclass of <code>QPlainTextEdit</code> to indent multiple selected lines:</p> <pre><code>void M...
[]
[ { "body": "<ul>\n<li><p>Some of these comments can be removed:</p>\n\n<p>Too obvious:</p>\n\n<pre><code>// Do nothing if we don't have a selection.\n</code></pre>\n\n<p>Noisy:</p>\n\n<pre><code>// Done!\n</code></pre></li>\n<li><p>These initialized variables:</p>\n\n<pre><code>int spos = curs.anchor(), epos = c...
{ "AcceptedAnswerId": "49893", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T04:49:58.417", "Id": "33899", "Score": "7", "Tags": [ "c++", "qt" ], "Title": "QPlainTextEdit subclass function to indent lines in selection" }
33899
<p>I have the following constructor</p> <pre><code> /** * @param codePath path to player's code. If ends in '/' it assumes the code is in .class'es in * a directory; otherwise assumes a jar * @throws PlayerException if there is a problem loading the code */ public Player(File codePath) throws PlayerExce...
[]
[ { "body": "<p>I think you are putting way too much logic in your constructor. The other problem is that you do not want to create dummy files, if so, are there are real files you can make a copy of and test on? If there are no real files either you might actually have to create some real/dummy files.</p>\n\n<p>...
{ "AcceptedAnswerId": "33958", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T06:20:21.817", "Id": "33900", "Score": "2", "Tags": [ "java", "unit-testing", "constructor" ], "Title": "Improve testability of constructor" }
33900
<p>I've creating a small library of JavaScript functions that I will be using. Some are for UI functions others are to return something.</p> <p>I am wondering if this method is ok and not a bad move before going any further with this library. Also, please do not mention jQuery as this is all JavaScript!</p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-08-10T13:02:58.340", "Id": "183549", "Score": "0", "body": "There is no need to make is enumerable...just use `defineProperty` to add functionality." } ]
[ { "body": "<p>I don't have any insight on extending host objects, because I've never done it, and quite frankly this scares me a little bit.</p>\n\n<p>That said, I can shed a bit of light on that \"enumerable\" problem.</p>\n\n<p>Objects in javascript are traversable, much like arrays. This means that when you ...
{ "AcceptedAnswerId": "33906", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T06:35:25.703", "Id": "33901", "Score": "0", "Tags": [ "javascript" ], "Title": "Extending DOM elements with prototype for easier function execution" }
33901
<p>I thought to do away with getters and setters behind the real world objects such as <i>Person</i>, <i>Company</i> or <i>Address</i>, i.e. <code>getName</code> and <code>setName</code>.</p> <p>Each of these have <code>public enum Attrib</code> of <a href="https://docs.oracle.com/javase/tutorial/java/concepts/object....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T14:28:18.290", "Id": "54444", "Score": "10", "body": "`public int phone;` is, IMO, a Very Bad Thing. If you're not doing math with it, use a string, Full Stop." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<p>You are right, this is not recommended practice. In your case, you need to know how the internals of the Person class works in order to use it effectively. As much as getters and setters appear to be clutter, they actually create a protocol, standard, and convenient system that you can take for gr...
{ "AcceptedAnswerId": "33922", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T10:53:31.107", "Id": "33914", "Score": "8", "Tags": [ "java", "beginner" ], "Title": "Getters and setters in a Person class" }
33914
<p>GPGPU is the use of graphics processing units for general-purpose computing, usually to exploit the GPU's ability to perform parallel computations on multiple data inputs.</p> <p>Related tag: <a href="/questions/tagged/simd" class="post-tag" title="show questions tagged &#39;simd&#39;" rel="tag">simd</a>.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T11:01:42.517", "Id": "33915", "Score": "0", "Tags": null, "Title": null }
33915
General-purpose computing on graphics processing units
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T11:01:42.517", "Id": "33916", "Score": "0", "Tags": null, "Title": null }
33916
<p>I'm creating a Python API client, after thinking and checking some open source Python clients I created this class, and I'm looking for any feedback (design, best practices...), this is an example URL of the API:</p> <blockquote> <pre><code>https://www.api.com/collection/resource.json?userid=id&amp;key=apikey&amp;c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T22:23:12.400", "Id": "56892", "Score": "0", "body": "Look at this package: https://github.com/olegpidsadnyi/restart" } ]
[ { "body": "<ol>\n<li><p>Python has a mechanism for handling exceptional situations, but you go to great lengths to suppress it: you catch all the exceptions that might result from your <code>request</code> method and replace them with a string in the <code>.error</code> property of the <code>APIClient</code> ob...
{ "AcceptedAnswerId": "34071", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T11:32:40.693", "Id": "33919", "Score": "5", "Tags": [ "python", "http" ], "Title": "Python API client" }
33919
<p>I have written this Pseudo-Code for the following program, I'm wondering if this might be descriptive enough for anyone to follow up and perform more or less the same program. The program reads and analyzes a set of data in a text file, then displays the information in a filtered way. Any improvements/ revision woul...
[]
[ { "body": "<p>When it comes to pseudo-code there are different standards depending on your organization, target group, etc, but here is my input:</p>\n\n<p>The comments in your pseudo-code are redundant.</p>\n\n<p>17 and 18 should be merged.</p>\n\n<p>Variable declaration (such as <em>3. Declare String content<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T12:09:37.960", "Id": "33923", "Score": "0", "Tags": [ "c#" ], "Title": "C# Pseudo-Code improvement/peer revision" }
33923
<p>I am fairly new to programming and I am having difficulty modulating the following code.</p> <p>The program reads a file, selects certain requirements, and displays them. I have tried to use passing arrays as arguments or functions as indicated in my textbook. I have been using examples such as <code>int getAges(...
[]
[ { "body": "<p>Here's how I would do it. </p>\n\n<p>Update: I included a description of my code this time based on comments. </p>\n\n<p>First, reading a file into a variable so that each line of the file is its own element in an array is super easy with File.ReadAllLines(...). But I don't feel like using a varia...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T13:14:26.720", "Id": "33928", "Score": "2", "Tags": [ "c#", "array", "beginner", "modules" ], "Title": "Finding correct format? Arrays and Modulation" }
33928
<p>Am I making good use of a 2-D array? Is this code inefficient? I am supposed to receive input from 6 departments for 4 quarterly periods in Java.</p> <p>My assignment asks:</p> <blockquote> <p><strong>Quarterly Sales Statistics</strong></p> <p>Write a program that lets the user enter four quarterly sales f...
[]
[ { "body": "<p>I'm not really sure why you have 4 functions that are doing the exact same thing!?</p>\n\n<p>The only difference seems to be the prompt text</p>\n\n<p>I'm also not a big fan of the second for statement</p>\n\n<p>// This for statement will sum each department's input</p>\n\n<pre><code>for (int i = ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T13:37:12.513", "Id": "33930", "Score": "5", "Tags": [ "java", "optimization", "array", "homework", "statistics" ], "Title": "How is my quarterly sales statistics program?"...
33930
<p>I'm writing a laser connection game. This is my first game on Windows Phone, and I've never used C# and XNA before.</p> <p>The part of my code that could be improved is <code>Update()</code> (where I make my sprites move).</p> <pre><code>public void Update(GameTime gameTime) { TouchPanelCapabilities touchCap =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T15:26:16.703", "Id": "54454", "Score": "0", "body": "touches.Count will give you the number of items, but the last item would be touches.Count - 1, hence the crashing" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<ol>\n<li><p>You can reduce some of the indent by checking for the negative condition and bailing out early. E.g.:</p>\n\n<pre><code>TouchPanelCapabilities touchCap = TouchPanel.GetCapabilities();\nif (!touchCap.IsConnected) { return; }\n\nTouchCollection touches = TouchPanel.GetState();\nif (touches...
{ "AcceptedAnswerId": "36496", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T15:08:40.003", "Id": "33938", "Score": "3", "Tags": [ "c#", "xna" ], "Title": "Position update loop and checking collision" }
33938
<p>I have the following SQL query that computes for every date the week it falls in (a week begins on Sunday and ends on Saturday):</p> <pre><code>SELECT EntryDate ,CAST(DATEADD(DAY, 1-DATEPART(WEEKDAY, EntryDate), EntryDate) AS DATE) AS 'SundayDate' ,CAST(DATEADD(DAY ,7-DATEPART(WEEKDAY, EntryDate), Entry...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T16:02:38.113", "Id": "54464", "Score": "0", "body": "I am not sure that you can make this \"cleaner\" or more readable. it looks pretty straight forward." } ]
[ { "body": "<p>You can lose the <code>CAST</code> that surrounds the <code>DATEADD</code> function.</p>\n\n<p>The <code>DATEADD</code> function should spit out a <code>DATETIME</code> datatype.</p>\n\n<p>It should look like this:</p>\n\n<pre><code>SELECT EntryDate\n ,DATEADD(DAY, 1-DATEPART(WEEKDAY, EntryDate),...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T15:40:16.350", "Id": "33939", "Score": "3", "Tags": [ "sql", "datetime", "sql-server", "t-sql" ], "Title": "Computing the week for a certain date" }
33939
<p>Can anyone optimize this code? I am new to jQuery.</p> <p>I want add class on next and previous button click. I wrote this code that works for me, but could anyone optimize it using jQuery predefined methods? That would be helpful. </p> <pre><code>$(document).ready(function () { var length = $('#slides li')...
[]
[ { "body": "<p>There's not much in the way of predefined jQuery methods to add. Here's what I came up with though...</p>\n\n<pre><code>$(document).ready(function () {\n var $slides = $('#slides li'); //Save repeated selector result. \n var length = $slides.length - 1; //size is deprecated\n var curren =...
{ "AcceptedAnswerId": "33946", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T16:31:50.463", "Id": "33943", "Score": "2", "Tags": [ "javascript", "jquery", "optimization", "html5" ], "Title": "Menu traversing on next and prev button click up and down...
33943
<p>I believe this is considered value noise or possibly gradient noise in that I simply interpolate between random values (always returning the same values per coordinate).</p> <p>I am using this currently to generate a basic heightmap in a 3D game that expands outward as the player moves (being nearly infinite, only ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T17:16:52.193", "Id": "57309", "Score": "0", "body": "In what way is this a bottleneck? If I take your sample and run it over a sample set of 1024 values (as I think you are doing) then it takes milliseconds for it to complete, so I ...
[ { "body": "<p>I'm not sure if Cos and Sin are efficient here, they might be a ferformance killer. Consider making a table of sin/cos values for come range of angles.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-29T09:36:40.740", "Id": "5955...
{ "AcceptedAnswerId": "36513", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T17:07:11.537", "Id": "33944", "Score": "5", "Tags": [ "c#", "algorithm", "performance", "game" ], "Title": "Looking for performance suggestions in Noise algorithm" }
33944
<p>I have a <code>Playlist</code> object which contains many <code>PlaylistItem</code> children. If I have 10,000 children then the UI gets blocked from rendering until all 10,000 children have been processed.</p> <p>To avoid this, I've created a recursive function wrapped in a <code>setTimeout</code>. This allows a c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-10-13T10:57:10.403", "Id": "196887", "Score": "0", "body": "I'm not entirely convinced that `setTimeout` to control the amount you render is the right way to go here. Your problem is that you're trying to render 10,000 elements at once.. ...
[ { "body": "<p>You code looks good, I only can give a few suggestions:</p>\n\n<ul>\n<li>I find it more convenient to use <code>...bind(this)</code> instead of <code>var self = this;</code> - in this case the extra variable is not necessary the code looks better.</li>\n<li>Maybe it is better to use an index withi...
{ "AcceptedAnswerId": "34017", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T17:37:14.897", "Id": "33947", "Score": "2", "Tags": [ "javascript", "jquery", "backbone.js", "lodash.js" ], "Title": "Rendering a large collection using BackboneJS and LoDa...
33947
<p>I am trying to standardize the way I write code. Which is the best way to place the values into a string, method 1 or 2?</p> <pre><code>string myCat = "persian"; // Method 1 Console.WriteLine("I have a wild {0} cat that likes to visit", myCat); // Method 2 Console.WriteLine("I have a wild " + myCat + " cat that l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T21:16:47.167", "Id": "54496", "Score": "3", "body": "Not too sure about on-topicness of this question. This isn't a code review, it's asking about the *best way to concatenate strings*, which I believe would be a better fit on Progr...
[ { "body": "<p>I much prefer method 1. Try adding 3-4 values and you'll quickly see it takes less code. Plus, you can reuse a value elsewhere in the string. Dunno which is more performant though. If you want performance, use StringBuilder. </p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3....
{ "AcceptedAnswerId": "34027", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T20:02:56.957", "Id": "33952", "Score": "8", "Tags": [ "c#", "strings" ], "Title": "Cleanest way to place values into strings" }
33952
<p>I'm a beginner at JavaScript and I'm working on building a mini-framework just to become familiar with what good code looks like. In my application I often have the need for the user to enter in a list of things they want to send to the server for querying purposes. So currently I have <a href="http://jsfiddle.net...
[]
[ { "body": "<p>The starting point in plugin creation is most likely the official documentation here: <a href=\"http://learn.jquery.com/plugins/basic-plugin-creation/\" rel=\"nofollow\">http://learn.jquery.com/plugins/basic-plugin-creation/</a></p>\n\n<p>You can start from the very simple plugin that actually con...
{ "AcceptedAnswerId": "34031", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T22:07:13.400", "Id": "33955", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Building jQuery like controls" }
33955
<p>In a complex library I've been working on, I got pretty tired of all of the individual type functions and operators to determine whether I was working with an object or piece of data of a given type. This was especially true when I was checking for inherited prototypes between classes. In an effort to alleviate, I m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T23:53:41.020", "Id": "54507", "Score": "3", "body": "Could you give an example of how this code would be used in practice? Usually, JavaScript programmers don't encounter the `is(v, t)` problem because [duck-typing](http://en.wikipe...
[ { "body": "<h1>Code Review</h1>\n\n<h2>Coding Style</h2>\n\n<p>You coding style is quite uncommon. However, it is fine if it is consistent across\nyour projects.</p>\n\n<p>My personal preference is to use constant ahead of comparison so it looks a\nlittle bit less confusing:</p>\n\n<pre><code>if ('function' ===...
{ "AcceptedAnswerId": "33972", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T22:24:11.977", "Id": "33956", "Score": "5", "Tags": [ "javascript", "classes" ], "Title": "Generalized is() type-checking function for JavaScript" }
33956
<pre><code>fadeTo = function(obj, time, to, cChange ){ if ( typeof( time ) == "undefined" ) time = 1000; if ( typeof( to ) == "undefined" ) to = 1; if ( time &lt;= 0 ) return true; objSt = obj.style; objOpac = parseFloat(objSt.opacity) + 0; if ( typeof( cChange ) == "u...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T00:36:25.323", "Id": "54511", "Score": "1", "body": "`typeof` is an operator and not a function, also prefer `===` to `==` for consistency. Why the `+ 0` on `objOpac` ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>Well written animation functions typically use a tweening algorithm that checks the system clock to see how much time is actually remaining in the originally specified time allotment and then adjusts the animation increment to put things back on time, even if the timer events weren't coming in exa...
{ "AcceptedAnswerId": "33963", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T00:29:56.987", "Id": "33962", "Score": "1", "Tags": [ "javascript" ], "Title": "Should I write my fadeTo function differently?" }
33962
<p>I have a file directory which contains folders for every month, and within those folders are several text files. In this context I would like to copy all of the text files from my <code>January</code> folder into a separate <em>target</em> folder. Then copy all of the text files within the <code>February</code> fold...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T01:26:55.713", "Id": "54527", "Score": "0", "body": "There is an extra `end` at the end. It it a function definition?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T01:29:46.793", "Id": "54529", ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T01:20:10.910", "Id": "33966", "Score": "6", "Tags": [ "lua", "directory" ], "Title": "Copying folder contents from several folders" }
33966
<p><a href="http://en.wikiedia.org/wiki/Computational_complexity_theory" rel="nofollow">Computational complexity</a> is the analysis of how the time and space requirements of an algorithm vary according to the size of the input.</p> <p>A common metric of complexity is <a href="http://en.wikipedia.org/wiki/Big_O_notati...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T04:21:32.130", "Id": "33970", "Score": "0", "Tags": null, "Title": null }
33970
Complexity is the analysis of how the time and space requirements of an algorithm vary according to the size of the input. Use this tag for reviews where the "Big O" is a concern.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T04:21:32.130", "Id": "33971", "Score": "0", "Tags": null, "Title": null }
33971
<p>My application's structure looks like this:</p> <p>Solution: MySolution</p> <p>Projects in MySolution: Host, Business, Server.</p> <p>References between the projects looks like this:</p> <pre><code>Host &lt;-- Business --&gt; Server </code></pre> <p>(Business references Host and Server but Host does not referen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T08:41:54.143", "Id": "54549", "Score": "1", "body": "What about having a Data layer that is your db layer and using a config file for the connection string?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-1...
[ { "body": "<p><strong>Var</strong></p>\n\n<p>Use the <code>var</code> keyword when defining local variables where the right hand side of the definition makes the type obvious. This looks cleaner and saves time when it comes to changing types during refactoring.</p>\n\n<p>e.g.</p>\n\n<pre><code>bool success = fa...
{ "AcceptedAnswerId": "78871", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T07:42:03.030", "Id": "33974", "Score": "3", "Tags": [ "c#", "interface" ], "Title": "Interfaces and Classes between Projects" }
33974
<p>I am trying to read a large file ~200 MB (~300 million lines of text). I am using a relatively standard way of reading like: </p> <pre><code>for (int i = 1; i &lt;= numProcs; i++) { System.out.println("Parsing " + traceFilePrefix + i + ".prg"); System.out.println("##########################"); try { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T18:07:21.060", "Id": "54629", "Score": "0", "body": "Comment the `traces.add` and see if you title is correct. I feel that reading is not a problem at all. It should be a memory, an issue of storing the millions of small objects. Ac...
[ { "body": "<p>First thing you should change in the code is avoid reading binary file using <a href=\"http://docs.oracle.com/javase/7/docs/api/java/io/FileReader.html\" rel=\"nofollow\">FileReader</a>. It is meant for reading streams of character. You can use <a href=\"http://docs.oracle.com/javase/7/docs/api/ja...
{ "AcceptedAnswerId": "33990", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T10:21:19.963", "Id": "33976", "Score": "10", "Tags": [ "java", "performance", "io" ], "Title": "Reading Large Files in Java getting really slow" }
33976
Cocoa is Apple's application-development framework for macOS, consisting of Foundation, Application Kit, and Core Data.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-11-07T11:43:10.683", "Id": "33980", "Score": "0", "Tags": null, "Title": null }
33980
Canvas is a drawing element introduced to web development with HTML5.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T11:45:01.520", "Id": "33982", "Score": "0", "Tags": null, "Title": null }
33982
<p><a href="https://www.mongodb.org/" rel="nofollow">MongoDB</a> is based on NoSQL databases, which means:</p> <blockquote> <p>When compared to relational databases, NoSQL databases are more scalable and provide superior performance, and their data model addresses several issues that the relational model is not ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T11:47:16.860", "Id": "33983", "Score": "0", "Tags": null, "Title": null }
33983
MongoDB is a scalable, high-performance, open source, document-oriented database. It supports a large number of languages and application development platforms.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T11:47:16.860", "Id": "33984", "Score": "0", "Tags": null, "Title": null }
33984
OCaml is a strict statically-typed functional programming language, focusing on expressivity, correctness and efficiency.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T11:52:25.353", "Id": "33986", "Score": "0", "Tags": null, "Title": null }
33986
<p>Shuffling is the process by which the order of the elements in a collection is randomized. One effective algorithm for doing so is as follows:</p> <p>For a zero-based collection of <code>n</code> elements:</p> <ol> <li>i = n</li> <li>j = random integer between 0 and i (inclusive)</li> <li>Swap the values of the el...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T11:57:48.033", "Id": "33987", "Score": "0", "Tags": null, "Title": null }
33987
Shuffling is the act of randomizing the order of the elements in a collection.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T11:57:48.033", "Id": "33988", "Score": "0", "Tags": null, "Title": null }
33988
Parsec is a parser library for the Haskell programming language.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T12:19:46.977", "Id": "33993", "Score": "0", "Tags": null, "Title": null }
33993
<p>I'm working on a simple little one page website for giving a presentation and I have some working code now, but I'm thinking there has to be a more elegant way of doing this. I would describe myself, at best, as a "dabbler" in JavaScript at this point; I'm much more comfortable with statically-typed languages and am...
[]
[ { "body": "<p>You do not need to add the id to the created <code>li</code> if you store it to a variable. </p>\n\n<p>The code below shows the basic concept. Does it make you more comfortable?</p>\n\n<pre><code>$.each(current.contents, function(_, mp){\n var $li = $('&lt;li&gt;' + mp.main + '&lt;/li&gt;'); ...
{ "AcceptedAnswerId": "34011", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T14:55:00.540", "Id": "34002", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Creating lists and sublists dynamically" }
34002
<p>This example is simplified down to the bare minimum. No <code>DatabaseAdapter</code> <code>IdentityMap</code> or anything. No <code>fetch()</code> method. Just what is needed to demonstrate this.</p> <p>If all your data mappers have a method:</p> <pre><code>/** * @return EntityType */ public function assign(Enti...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T01:23:46.523", "Id": "54668", "Score": "0", "body": "Which library do you use? There are at least several PHP libraries that claim DataMapper implementation and all of them are different in details." }, { "ContentLicense": "...
[ { "body": "<p>I can't speak to cloning specifically, as I've never used it before, but here are a few basic things to think about.</p>\n\n<p><strong>Is the User class used in any other methods of your UserMapper?</strong></p>\n\n<p>If it is then injecting it in the constructor, or through a setter is ideal as i...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T15:28:27.657", "Id": "34004", "Score": "2", "Tags": [ "php", "object-oriented" ], "Title": "Data mapper reuse related domain object for setting data and return a clone of the domain o...
34004
<p>I'm just wanting feedback on the efficiency, design and layout of this code if possible please. I suspect it's weird having a constructor with nothing in. I'd be grateful if it could be explained how to modify the code to fit in with conventions, especially in this respect, but also in others.</p> <pre><code>packa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T21:28:31.287", "Id": "54652", "Score": "0", "body": "In other words, find the smallest positive integer expressible as a sum of two cubes in two different ways. http://mathworld.wolfram.com/Hardy-RamanujanNumber.html" } ]
[ { "body": "<p>There are a few things I would like to comment on:</p>\n\n<ol>\n<li>Whether you have an empty constructor or not is irrelevant. In your case, there already was a public 'default' (empty) constructor, and you have just made it explicit. This is neither a good thing nor a bad thing. Many classes hav...
{ "AcceptedAnswerId": "34013", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T17:18:27.737", "Id": "34009", "Score": "4", "Tags": [ "java", "mathematics" ], "Title": "How is my program for computing the Hardy-Ramanujan number?" }
34009
<p>I am asking about the right way to make a component that holds some state. This includes a Jbutton that saves a color in it, or a list item that saves a certain object. So when those GUI components fire an event, I can use the saved states to do something with it.</p> <p>My way is like this:</p> <ol> <li><p>Make ...
[]
[ { "body": "<p>Instead of comparing the class with <code>if( source.getClass() == ColorButton.class)</code> you can use <code>if (source instanceof ColorButton)</code>. This is preferable in case you would make a subclass of <code>ColorButton</code>. If it's an instance of a subclass of <code>ColorButton</code> ...
{ "AcceptedAnswerId": "34021", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T19:22:29.033", "Id": "34015", "Score": "3", "Tags": [ "java", "swing" ], "Title": "Create GUI components with states" }
34015
<p>The variable <code>result</code> is an integer representing the exit code of a command line process that was run via Groovy code. An exit code of 0 means the process was successful and an exit code from 1-255 means a failure. Then this line is executed:</p> <pre><code>println result ? "The command failed." : "The c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T20:40:46.343", "Id": "54645", "Score": "6", "body": "Nothing about this seems like magic. It is _very_ straightforward especially in light of the [Elvis Operator](http://docs.codehaus.org/display/GROOVY/Operators#Operators-ElvisOper...
[ { "body": "<p>I don't do JS or Groovy stuff, so I'm a bit biased (and possibly completely wrong).</p>\n\n<p>What I would normally expect in such an expression is </p>\n\n<pre><code>{bool expression} ? {true part} : {false part}\n</code></pre>\n\n<p>... and your <em>groovy</em> code has that reversed, which <em>...
{ "AcceptedAnswerId": "34028", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T19:30:22.367", "Id": "34016", "Score": "3", "Tags": [ "error-handling", "groovy", "child-process" ], "Title": "Reporting success or failure of a child process" }
34016
<p>I created a class a while ago that I named a "Recursion Array". It is a way to create dynamically memoized sequences such as the Fibonacci sequence or the factorial numbers sequences. The concept is to create mathematic sequences defined by recursion by only providing the first values and the recursive formula; all ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-09T09:12:29.847", "Id": "75873", "Score": "0", "body": "I am not very experienced with C++, but wouldn't it be better to pass in the `value_type` as an argument to the template: `RecursionArray<MemoizedFibonnacci, unsigned int>`? It se...
[ { "body": "<p>There's a (slight) typo in what you've posted - the forward declaration of <code>types_t</code>:</p>\n\n<pre><code> template&lt;typename T&gt;\n types_t;\n// ^^^^^^^^\n// Should be struct types_t;\n</code></pre>\n\n<p>Similarly, you've forward defined <code>class MemoizedFibonacci</code> and t...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T23:34:10.063", "Id": "34022", "Score": "8", "Tags": [ "c++", "c++11", "recursion", "cache", "fibonacci-sequence" ], "Title": "Optimize RecursionArray interface" }
34022
<p>I have an array of a struct containing 5 byte values. I need to sort this array by each value in a different order depending on the situation. These arrays are sometimes quite small (10-30 elements), sometimes quite large (1024-16384). </p> <p>Below is the code I'm using. The reason this has become a bottleneck fo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T00:36:00.953", "Id": "54662", "Score": "0", "body": "Why exactly do you need to sort it so often? Is it always a different array or do you sort the same array over and over to get different views? Also, why does it have to be an arr...
[ { "body": "<p>If your analysis is correct and the slowdown is really cased by the copying, then you could avoid that by using <a href=\"http://msdn.microsoft.com/en-us/library/System.Array.Sort\"><code>Array.Sort()</code></a>, which directly sorts the array you have.</p>\n\n<p>Though <code>Array.Sort()</code> i...
{ "AcceptedAnswerId": "34025", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T00:03:01.243", "Id": "34023", "Score": "4", "Tags": [ "c#", "performance", "array", "sorting", "game" ], "Title": "Improving performance when sorting array of structs b...
34023
<blockquote> <p><strong>Question: Simple Calculator</strong></p> <p>Input loaded from file. Instructions can be any binary operators. Ignore math precedence. Last input is apply and a number e.g. "apply 5". Calc is then initialized with that number and previous instructions are applied to it.</p> <p>A...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-21T10:39:44.867", "Id": "515112", "Score": "0", "body": "Is there a source code in C# for this problem?" } ]
[ { "body": "<p>my 2 cents:</p>\n\n<ul>\n<li>I am not sure why you split the constructor over 2 methods. Looks awkward.</li>\n<li>You store <code>inputPath</code> in <code>FileCalculationConsumer</code>, you even have a getter, but you never do anything with after you create the Scanner</li>\n<li>Why would you in...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T01:06:41.613", "Id": "34026", "Score": "7", "Tags": [ "java", "unit-testing", "interview-questions", "calculator" ], "Title": "Simple calculator for an interview" }
34026
<p>I have implemented a very basic sandwich (sub) shop which a user can add extra toppings at an additional cost. The cost is calculated and the contents of the sandwich is outputted.</p> <p>I am learning design patterns and the book I am learning from (<em>Head First Design Patterns</em>) is in Java, which I am not t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T05:49:02.117", "Id": "54695", "Score": "3", "body": "You should probably use int for monetary units. You don't want to have rounding errors. Use int and make the price in cent (you can put the decimal point in when printing)." } ]
[ { "body": "<p>No:</p>\n\n<p>An object \"Sub\" and a decorator \"Topping\" implement the same interface. \nIn addition a decorator takes an item (of the same interface) that it is decorating.<br>\nThis is not quite what you have done.</p>\n\n<p>What if I want extra cheese and meat?</p>\n\n<p>You need something m...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T04:12:04.123", "Id": "34035", "Score": "0", "Tags": [ "c++", "design-patterns", "c++11" ], "Title": "Sandwich shop interface using the Decorator pattern" }
34035
<p>I need to check whether a generic type parameter is in a set of valid types and have created extension methods to do a run time check:</p> <pre><code>public static bool Is(this Type type, params Type[] types) { return types.Any(t =&gt; t == type); } public static bool Is&lt;T1&gt;(this Type type) { return type...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T21:39:08.193", "Id": "54685", "Score": "1", "body": "Part of me wonders if this would be more suited for [codereview.se]..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T21:41:05.260", "Id": "54...
[ { "body": "<p>Would something like this be helpful?</p>\n\n<pre><code>List&lt;Type&gt; acceptedTypes = new List&lt;Type&gt;(){typeof(string), typeof(int), typeof(long)};\nvar stringTypeToCheck = \"this is a string type\";\nvar intTypeToCheck = 123;\nvar guidToCheck = Guid.NewGuid();\n\nif(!acceptedTypes.Contain...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T21:35:49.423", "Id": "34041", "Score": "10", "Tags": [ "c#" ], "Title": "Check if a type is of any from a list of types?" }
34041
<p>I have heard that some patterns in R code are really anti-patterns and thus I am trying to imitate superior examples of R code.</p> <p>I am confused about control flow.</p> <p>I have been reviewing some R code from openintro.org; the original exercise is explained at:</p> <p><a href="http://www.openintro.org/down...
[]
[ { "body": "<p>In my opinion, this function is a nice example of R code. Your interpretation of the code is correct. One unnecessary command is <code>y == 0</code> since the information is redundant given that <code>x == \"H\"</code> is already known. In this case, <code>y == 0</code> is identical to <code>c(TRU...
{ "AcceptedAnswerId": "34069", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T05:46:08.230", "Id": "34048", "Score": "1", "Tags": [ "r" ], "Title": "Should I be trying to imitate the control flow in this example R code?" }
34048
<p>I've just written a palindrome generator and would like to know what you think about it.</p> <p>Especially:</p> <ul> <li>code style </li> <li>Is it possible to get the same result without making a special case for 1-digit palindromes?</li> <li>efficiency</li> </ul> <p></p> <pre><code>#!/usr/bin/env python def g...
[]
[ { "body": "<ol>\n<li><p>I'd implement this function like this:</p>\n\n<pre><code>from itertools import count\n\ndef palindromes():\n \"\"\"Generate numbers that are palindromes in base 10.\"\"\"\n yield 0\n for digits in count(1):\n first = 10 ** ((digits - 1) // 2)\n for s in map(str, ra...
{ "AcceptedAnswerId": "34059", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T10:16:21.937", "Id": "34052", "Score": "3", "Tags": [ "python", "optimization", "palindrome" ], "Title": "Python Palindrome Generator" }
34052
<p>I'm quite new to C, and I'm looking for feedback on this (doubly) linked list code.</p> <p>Once I get to the add and remove methods, I feel like the code goes downhill. I'm looking for any potential errors I haven't spotted, and improvements that could be made for efficiency/tidiness.</p> <pre><code>struct node { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T13:10:10.480", "Id": "54710", "Score": "0", "body": "In the listset_add you do not change the tail in the `else` block: `this->tail = new_node`" } ]
[ { "body": "<p>The code of the list looks correct but the coding style is not neat yet. There are some suggestions:</p>\n\n<ul>\n<li>There are different recommendations on how to format the type of the pointers, but probably all agree that the character <code>*</code> is the part of the type. So it is better to ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T11:36:35.080", "Id": "34053", "Score": "2", "Tags": [ "c", "beginner", "linked-list" ], "Title": "Doubly linked list implementation in C" }
34053
<p>The program assignment:</p> <blockquote> <p>A drunkard in a grid of streets randomly picks one of four directions and stumbles to the next intersection, then again randomly picks one of four directions, and so on. You might think that on average the drunkard doesn't move very far because the choices cancel ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T01:54:49.487", "Id": "54707", "Score": "3", "body": "Simplify your random call to `generator.nextInt(MAX_DIRECTION)` where MAX_DIRECTION is an int constant and == 4." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<p>Why don't you indent inner statements?</p>\n\n<p>The constants 0, 1, 2, 3 could be declared as constants like</p>\n\n<pre><code>private static final short NORTH = 0;\nprivate static final short EAST = 1;\netc...\n</code></pre>\n\n<p>Also, the \"Impossible!\" is an unreachable statement so it would...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T01:52:45.830", "Id": "34054", "Score": "7", "Tags": [ "java", "beginner", "random" ], "Title": "Random walk on a 2D grid" }
34054
<p>I've recently try to brush up my javascript skills, so I have a friend who gives me puzzles from time to time to solve. Yesterday I got this :</p> <pre><code>function testFun() { f = {}; for( var i=0 ; i&lt;3 : i++ ) { f[i] = function() { alert("sum='+i+f.length); } } return f; } Expected Results: testFu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T17:25:02.227", "Id": "54730", "Score": "0", "body": "@downvoter care to explain why" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T17:49:41.630", "Id": "54732", "Score": "1", "body": "I d...
[ { "body": "<p>The style of you code is good. Here is not much of it but it looks like you understand the concept of closures well.</p>\n\n<p>The logic of the original task is changed so even if you code returns the right values, they are calculated differently. The original task calculates it as <code>i + f.len...
{ "AcceptedAnswerId": "34063", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T17:21:01.060", "Id": "34060", "Score": "2", "Tags": [ "javascript" ], "Title": "Solving the puzzle in javascript" }
34060
<p>I'm hoping someone could look through this code for my <code>Chunk</code>, <code>Mesh</code> and <code>ChunkManager</code> classes and tell me what I need to do to improve.</p> <p>For some reason, when I wrote it in NetBeans and transferred it to Eclipse it deleted all my comments.</p> <p>I especially don't unders...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T20:27:26.293", "Id": "54752", "Score": "1", "body": "Your question is not exactly clear. First of all: **Is your code working properly?** If it is not, you should ask it on StackOverflow - but if you do, you will need to improve you...
[ { "body": "<p>Ok so I actually asked this question a while ago and since I've since figured it out I figured I would go ahead and answer it.</p>\n\n<p>Firstly my issue was not caused by some singular defect in my code or poorly written line but moreso by a culmination of poorly written code as a whole and the s...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T17:38:57.203", "Id": "34061", "Score": "3", "Tags": [ "java", "optimization", "opengl" ], "Title": "Vertex Buffer Object (VBO) multi-class implementation" }
34061
<p>I'm using <a href="https://github.com/kriskowal/q" rel="nofollow">Q</a> to flatten out some callbacks in my unit tests and return a promise to <a href="http://visionmedia.github.io/mocha/" rel="nofollow">mocha</a> (which knows to wait until the promise is resolved before running the next test).</p> <p>Originally I ...
[]
[ { "body": "<blockquote>\n<pre><code>.then(q.nmcall(user, 'nextCount'))\n</code></pre>\n</blockquote>\n\n<p>is wrong. The nextCount call does return a promise (and starts its execution right away), while <code>then</code> does expect a [callback] function. You'd rewrite it to</p>\n\n<pre><code>.then(function(res...
{ "AcceptedAnswerId": "39222", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T17:59:19.187", "Id": "34062", "Score": "3", "Tags": [ "javascript", "node.js", "asynchronous", "mocha" ], "Title": "Am I using Q the right way or is there a better way to d...
34062
<p>Spacing, punctuation, and other such characters are generally ignored when determining whether or not a phrase is a palindrome.</p> <p>Example:</p> <blockquote> <p>A Man, A Plan, A Canal: Panama!</p> <p>amanaplanacanalpanama</p> </blockquote> <p>There are <a href="http://www.palindromelist.net/" rel="nofol...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T18:43:20.323", "Id": "34064", "Score": "0", "Tags": null, "Title": null }
34064
Any sequence of units (typically letters or numbers) that are read the same way forward or backward.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T18:43:20.323", "Id": "34065", "Score": "0", "Tags": null, "Title": null }
34065
<p>I made this nice bit of code that I can insert into any of my projects requiring user input. It seems quite long for what it does and I would love some insight as to how I can do this more efficiently i.e. fewer lines of code.</p> <p>I love to make my code elegant, but I don't see how to do this any better.</p> <p...
[]
[ { "body": "<ul>\n<li><p>There is absolutely no need to put parentheses around the first statement (small improvement, but it improves readability). \"parameter\" is also misspelled (improving readability but in a different way).</p>\n\n<pre><code>String x = JOptionPane.showInputDialog(\". Each parameter should ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T18:59:50.513", "Id": "34066", "Score": "3", "Tags": [ "java" ], "Title": "Improving some plugin user-input code" }
34066
<p>I borrowed the code from this <a href="https://stackoverflow.com/questions/19405571/failed-to-understand-the-use-of-delegates-in-real-world-scenarios">question</a>. I'm trying to implement the delegate in that code. Below is my outcome so far.</p> <p>What else can be done to improve this code? Any suggestions? I w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T22:01:34.140", "Id": "56884", "Score": "0", "body": "Thanks all for their time and efforts. @radarbob most of the pieces are clear now. Please advice for the EDIT in my questions." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<h2>Be more Object Oriented</h2>\n\n<p>Most of the code in <code>Main()</code> should be in the <code>Flight</code> or <code>FlightTower</code> classes. Seems to me that if it's in an appropriate class then its re-usable.</p>\n\n<h3>What does a Tower <em>DO</em>?</h3>\n\n<ul>\n<li>Clear flights to la...
{ "AcceptedAnswerId": "34090", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T20:44:53.573", "Id": "34073", "Score": "2", "Tags": [ "c#", "delegates" ], "Title": "Implementation of delegates for flight operations" }
34073
<p>I have a script that separates the date from a datepicker into day, month, and year. It works fine when there is one form on the page but not when there is a second one (presumably due to the id being the same). How can I add a value to my id and name so that they are unique values if the script runs twice on the sa...
[]
[ { "body": "<p>Use a closure, so everything will be only inside it's scope. Additionally you can use $ now!</p>\n\n<pre><code>(function ($) {\n var now = new Date();\n var date = $('.form-date');\n var day = (\"0\" + now.getDate()).slice(-2);\n var month = (\"0\" + (now.getMonth() + 1)).slice(-2);\n ...
{ "AcceptedAnswerId": "34076", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T21:01:03.207", "Id": "34075", "Score": "1", "Tags": [ "javascript", "php", "jquery" ], "Title": "Refactor to provide for multiple instances on a single page" }
34075
<p>I have much more experience with PAWN scripting language, but I'm digging into K&amp;R book (I think it is it), and trying some stuff on my own.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #define ITEMS_COUNT 16 unsigned int randr(unsigned int min, unsigned int max)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T12:54:36.840", "Id": "57010", "Score": "0", "body": "K&R is about _the C language_, `inline` is C++'s alternative/answer/attempt at solving macro issues" } ]
[ { "body": "<p>My little bit of input:</p>\n\n<ol>\n<li><p><code>inline</code> is a C++ keyword, and it's only a hint to the compiler. The only reason to explicitly use <code>inline</code> is when you define function's body inside a header file, which is included in more than one source file.</p></li>\n<li><p><a...
{ "AcceptedAnswerId": "34080", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T21:54:42.150", "Id": "34077", "Score": "0", "Tags": [ "c++", "c" ], "Title": "C code displaying random datasets" }
34077
<p>It is nice to be able to set your data in a domain object like so:</p> <pre><code>$order-&gt;setId($id); $order-&gt;setCustomer($customer); $order-&gt;setItems($items); </code></pre> <p>And then be able to do</p> <pre><code>if( !$order-&gt;validate() ) { // Invalid data } </code></pre> <p>Which will validate...
[]
[ { "body": "<p>my two cents :</p>\n\n<ul>\n<li>I think tying validation activation to setters is not really good. What if you never set any value on your object ? It will be considered valid ! And what happens if you set the property more than once ?</li>\n<li>Some implementations use external validator objects,...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-08T22:07:33.090", "Id": "34078", "Score": "3", "Tags": [ "php", "object-oriented" ], "Title": "Closures with validation rules for domain object properties" }
34078
<p>I have a <code>while</code> loop below, but I'm not quite sure if it's the most 'pythonic' thing. I've omitted most of the code, and have the skeletal structure below (but have all the code necessary to understand my <code>game_status()</code> function). And the main thing in question is whether/how to use a functio...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T01:11:42.600", "Id": "54789", "Score": "0", "body": "Okay. :O I know that on CodeReview, I was previously criticized for calling a function repeadetly in this manner, so I was curious if there was a simpler way, or more pythonic way...
[ { "body": "<p>When you make \"the same\" function call repeatedly, you can create a question in the reader's mind whether or not it will return the same value every time (especially where the arguments are mutable objects, but even if not).</p>\n\n<p>This is probably to be avoided where it's easy to do so. In y...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T01:08:39.387", "Id": "34084", "Score": "3", "Tags": [ "python", "python-2.x" ], "Title": "Pythonic loop logic for Tic-Tac-Toe game board" }
34084
<p>I am working on a code where I represent a <code>MonadPlus</code> using a <code>Tree</code> data structure and then explore it, summing over all of the leaves (whose type must be an instance of <code>Monoid</code>); I need to use a <code>Tree</code> representation to do this (rather than using the <code>List</code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-01T14:34:25.843", "Id": "68475", "Score": "0", "body": "Could you please describe in more detail what task you'd like to solve? This would help to understand the program and offer alternative solutions." }, { "ContentLicense": ...
[ { "body": "<p>A bit late, but perhaps it'll still help someone.</p>\n\n<p>From the benchmark it's not clear if the time difference is caused by producing a tree or consuming it. I'm not very familiar with <em>operational</em> to make a guess.</p>\n\n<p>It seems that what you're looking for is a <a href=\"http:/...
{ "AcceptedAnswerId": "135713", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T05:32:54.453", "Id": "34089", "Score": "4", "Tags": [ "haskell", "tree", "monads" ], "Title": "Performance of List representation of MonadPlus versus Tree representation" }
34089
<p>Please check my code, did i get some things wrong<br> I'm a newbie in jquery and ajax, please check and show me how to fix this </p> <p>In jsp page :</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;AJAX calls using Jquery in Servl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T16:57:42.200", "Id": "54813", "Score": "0", "body": "do you need to fix it? does it work?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T03:10:00.953", "Id": "56827", "Score": "0", "body...
[ { "body": "<p>I can't talk for the java part, but here's my two cents on your js.</p>\n\n<h3>favor placing scripts at the bottom of your page.</h3>\n\n<p>...just before the <code>&lt;/body&gt;</code>tag. Many reasons to do so can be found <a href=\"http://codecraftingblueprints.com/put-scripts-at-the-bottom/\" ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T05:59:43.683", "Id": "34091", "Score": "-1", "Tags": [ "javascript", "jquery", "ajax", "servlets" ], "Title": "Please check my example about jquery autocomple with servlet" }
34091
<p>Just looking for some feedback on my solution for <a href="http://tour.golang.org/#24" rel="nofollow">Tour of Go Exercise 24 - Loops and Functions</a>. Is there anything that looks like a wrong way to do things in go? anything I could have done better?</p> <pre><code>package main import ( "fmt" "math" ) f...
[]
[ { "body": "<p>One tiny thing: If you drop one set of parentheses:</p>\n\n<pre><code>return z - ((z * z - x) / (2 * z))\n</code></pre>\n\n<p>and then run <code>go fmt</code>, it will change it to</p>\n\n<pre><code>return z - ((z*z - x) / (2 * z))\n</code></pre>\n\n<p>The expressions around the <code>*</code> are...
{ "AcceptedAnswerId": "35542", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T14:06:05.580", "Id": "34095", "Score": "4", "Tags": [ "go", "mathematics" ], "Title": "Approximating square root (loops and functions exercise)" }
34095
<p>Not sure how subjective this question is however I am looking for a peer review and general feedback on the intuitiveness and scaffolding potential of a framework concept. I have a gist on GitHub here: <a href="https://gist.github.com/bsawyer/fbfe8b597cff32e0c73b" rel="nofollow">node.js MVVM framework concept</a></p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T17:02:47.883", "Id": "55812", "Score": "1", "body": "you need to include the code that you want Reviewed. Follow These [Rules](http://codereview.stackexchange.com/help/how-to-ask) as well as not linking to the code that you want rev...
[ { "body": "<p>It's better than rendering HTML in some other language manually, but it's at a disadvantage to HTML super-set template languages. </p>\n\n<p>Mirroring the structure of HTML in JS makes the design more verbose because you need to map object fields to HTML tokens like <code>attr:</code> and not tan...
{ "AcceptedAnswerId": "35113", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T16:25:29.933", "Id": "34098", "Score": "3", "Tags": [ "javascript", "node.js", "mvvm" ], "Title": "node.js MVVM framework concept" }
34098
<p>I'm creating a program that reads data from two .dat files: one for food-bank location and the other for residence. Right now, the program can calculate the distance between food-bank and residence and insert it into a distances vector.</p> <p>My concerns are:</p> <ol> <li>Is my logic right?</li> <li>Can I determ...
[]
[ { "body": "<p>Stop doing this:</p>\n\n<pre><code>using namespace std;\n</code></pre>\n\n<p>Yes every text book does this. But once you start writing programs more than 10 lines long it causes issues. Prefix items in the standard namespace with <code>std::</code> (it was designed to be short). See detailed expla...
{ "AcceptedAnswerId": "34102", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T16:26:04.467", "Id": "34099", "Score": "2", "Tags": [ "c++", "c++11" ], "Title": "Reading two .dat files for calculating location distance" }
34099
<p>I am using Django multi-table inheritance: <code>Video</code> and <code>Image</code> are models derived from <code>Media</code>. There are two views: <code>video_list</code> and <code>image_list</code>, which are just proxies to <code>media_list</code>. <code>media_list</code> returns images or videos (based on inpu...
[]
[ { "body": "<p>You could avoid the \"is Image or Video\" checks in <code>media_list</code>, by passing in some extra arguments, for example in <code>image_list</code>:</p>\n\n<pre><code>def image_list(request, rel_model_tag, rel_object_id, mode):\n get_star_media = lambda rel_object: rel_object.star_image\n ...
{ "AcceptedAnswerId": "48149", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T19:45:38.543", "Id": "35103", "Score": "3", "Tags": [ "python", "object-oriented", "mvc", "django" ], "Title": "Is one view that handles two sibling models a good idea?" }
35103
<p>Is this image uploading script safe? I have spent my day researching this and it would be very much appreciated if you could point out any errors or ways to make it safer.</p> <pre><code>&lt;?php $max_file_size = 1048576; // expressed in bytes // 10240 = 10 KB //...
[]
[ { "body": "<p>It is pretty solid for saving images on a single web server. Some optional/extra things you could do are:</p>\n\n<ul>\n<li>Host the images on a CDN. That way if there was any PHP or JS injected in, it would not be able to access any cookies or directories on the web server you use to serve content...
{ "AcceptedAnswerId": "35109", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T22:00:58.653", "Id": "35104", "Score": "3", "Tags": [ "php", "security" ], "Title": "Is this file image upload safe?" }
35104
<p>Just wanted to post my registration controller and see what anybody thought about it.</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * Register * */ class Register extends CI_Controller { /** * Register::__construct() * * @return */ ...
[]
[ { "body": "<p>Direct access to a class file will just result in a blank page as there is no output being produced by it. However, there are better ways of doing what you are trying to do. For instance, you could use an .htaccess file. The following .htaccess file, if placed in the base directory of your site, w...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-09T22:06:50.117", "Id": "35106", "Score": "1", "Tags": [ "php", "codeigniter" ], "Title": "Codeigniter Registration Controller" }
35106
<pre><code>def minval(xs): minum = xs[0] for i in range(len(xs)): if xs[i] &lt; minum: #difference in code: xs[i] minum = xs[i] return minum </code></pre> <p>or</p> <pre><code>def minval(xs): minum = xs[0] for i in range(len(xs)): if i &lt; minum: #difference in code: i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T12:38:18.427", "Id": "56855", "Score": "4", "body": "What's wrong with Python's built-in function [`min`](http://docs.python.org/3/library/functions.html#min)?" } ]
[ { "body": "<p>They aren't the same: The second gives <code>-1</code> for <code>[-1,-2,-3]</code> and is simply spuriously correct, while the first gives the correct answer.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T08:50:15.563", "Id": "35117", "Score": "-1", "Tags": [ "python" ], "Title": "Which loop code is better practice?" }
35117
<p>I am learning <a href="https://class.coursera.org/algs4partI-003/class/index" rel="nofollow">Algorithms, Part I on coursera.org</a>. I just watched the first lecture then tried to write some code in C#. The class basically stores list of connected numbers. You can add numbers that connected together by calling <code...
[]
[ { "body": "<p>Your naming of <code>isLeftExist</code> is not correct. The variable holds a list containing th number <code>left</code>. So its name should be <code>listContainingLeft</code>. The same applies to the <code>isRightExist</code> list.</p>\n\n<p>Regarding the if-else construct: One clause is redundan...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T09:48:17.527", "Id": "35120", "Score": "3", "Tags": [ "c#", "algorithm", "unit-testing" ], "Title": "Complexity in multiple if-else algorithms" }
35120
<p>Please review the code.</p> <pre><code>document.addEventListener("keydown", function(e) { // shortcuts if (e.ctrlKey) { // Ctrl+ if (/^(82|79|83|66|191)$/.test(e.keyCode)) { e.preventDefault(); } switch (e.keyCode) { case 82: // R newDoc(); break; case 79: // O ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T11:14:31.820", "Id": "56850", "Score": "0", "body": "What's the background/usage of your app? On what basis you want to review your code? readability/clean-code/optimization? Please mention them." }, { "ContentLicense": "CC ...
[ { "body": "<p>In JS, when you have a switch, it's usually better to go with a dispatch table.</p>\n\n<pre><code>var mapping = {\n 82: newDoc,\n 79: openDoc,\n 83: saveDoc,\n 66: function() {\n showHideStatusBar(statusBarOn ? false : true);\n },\n 191: function() {\n alert(\"Welco...
{ "AcceptedAnswerId": "35122", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T10:12:16.723", "Id": "35121", "Score": "1", "Tags": [ "javascript" ], "Title": "Handling keyboard shortcuts for webapp" }
35121
<p>I am after a peer review of a C# implementation of the Barnes-Hut algorithm which I have translated from F#. The F# version is the base for comparison, therefore the C# version is suppose to reflect the F# in structure and behaviour. I have tried to translate the F# implementation as accurately as possible, howeve...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T17:54:53.843", "Id": "56867", "Score": "1", "body": "Please include the code you want to get reviewed in your question (you can keep external links). This prevents your question and the answers to become useless when the link goes a...
[ { "body": "<p>I think there is a lot in the code which can be improved especially from design point of view. A few points which caught my eye follow but it can probably improved further. I would start with what I've written below and then possibly go through another round of refactoring.</p>\n\n<p><strong>Namin...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T16:41:56.917", "Id": "35125", "Score": "2", "Tags": [ "c#", "performance", ".net", "f#", "task-parallel-library" ], "Title": "Barnes-Hut implementation of the N-Body probl...
35125
<p>This script uses robocopy purge with list command to out what would be purged it then parses that log file and checks each file and only deletes files older than 7 days. Is there way it could be simplified to maybe use less log files in the process?</p> <pre><code>$Log = "D:\IT\Backups\Logs\list.txt" $extrafile = "...
[]
[ { "body": "<p>To reduce the amount of log files I would keep things in memory:</p>\n\n<pre><code>$Log = \"C:\\scripts\\list.txt\"\n$purged = \"C:\\scripts\\purged.txt\"\n$now = Get-Date\n$days = \"7\"\n$Lastwrite = $now.AddDays(-$days)\n$datetime = get-date -f MM-dd-yy-hhmmtt\n\n#Robocopy will automatically ove...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T19:11:10.163", "Id": "35126", "Score": "5", "Tags": [ "powershell" ], "Title": "Robopurging expired files" }
35126
<p>Need to write a function that takes an open file as the only parameter and returns a dictionary that maps a string to a list of strings and integers. </p> <p>each line in the text will have a username, first name, last name, age, gender and an e-mail address. The function will insert each person's information into...
[]
[ { "body": "<p>There are more efficient ways to implement this:</p>\n\n<p>1) If you only need a dictionary to keep your data together without semantics, you could split as follows:</p>\n\n<pre><code>&gt;&gt; line = \"ajones Alice Jones 44 F alice@alicejones.net\"\n&gt;&gt; identifier, *userdata=line.split()\n</c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T19:31:58.613", "Id": "35128", "Score": "2", "Tags": [ "python", "hash-map", "file" ], "Title": "opening a text file and building a dictionary" }
35128
<p>I have a single file of a java Bingo program that I want to split into three separate classes (BingoMain, BingoGUI, BingoCard). Extending a program across several files is something I have never really done, so a little help is appreciated. I also want to add the ability to extend the current program to include func...
[]
[ { "body": "<p>Your choice of classes to split the code in to is a little off, in my opinion. I would create three classes and an interface...</p>\n\n<p>The interface would look like this:</p>\n\n<pre><code>package bingo;\n\npublic interface BingoCardListener {\n public void setup(String name, int columns, in...
{ "AcceptedAnswerId": "36123", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T20:59:04.643", "Id": "35131", "Score": "5", "Tags": [ "java", "object-oriented", "game" ], "Title": "How to split this Bingo game into 3 separate classes?" }
35131
<p>If you write a VS extension, you can get access to VS services with the IServiceProvider interface:</p> <pre><code>var vsUIShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsVsUIShell)); vsUIShell.SetWaitCursor(); // for example </code></pre> <p>To reduce duplication every time I need this, I created a class...
[]
[ { "body": "<p>Well, one option is to use reflection to instantiate all the static fields:</p>\n\n<pre><code> static VisualStudioServices()\n {\n var fields = typeof(VisualStudioServices).GetFields(bindingAttr: BindingFlags.Static | BindingFlags.NonPublic);\n foreach (var field in fields)\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T21:10:22.417", "Id": "35132", "Score": "2", "Tags": [ "c#", "visual-studio" ], "Title": "Reduce duplication while accessing Visual Studio services" }
35132
<p>I've made this script the other day, and I need some input from you telling me how could I improve the code / style. There aren't problems with the code (it does the job) but I want it more organized and "simple" so that in 1 week I still remember what the hell was I thinking!</p> <p>The problem was: I needed a pro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-11-07T15:25:18.127", "Id": "126302", "Score": "0", "body": "Do you have an updated version of this script?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-11-08T20:24:02.467", "Id": "126475", "Score": "0"...
[ { "body": "<p>I'm just going to mention a few quick observations rather than do a thorough review.</p>\n\n<p>You're concatenating backslashes everywhere. Use <strong><code>os.path.join()</code></strong> like you're supposed to. (The one place where you call <code>os.path.join()</code>, you're manually adding ...
{ "AcceptedAnswerId": "35783", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T22:14:35.643", "Id": "35137", "Score": "3", "Tags": [ "python", "optimization", "file-system" ], "Title": "Improve my script to organize a video collection" }
35137
<p>In this function, the copy (<code>Write XML</code>) is inside, but I want it to be separated from the function. How can I improve this function?</p> <pre><code>Sub ExporttoFolder(ByVal POSPath As String, ByVal dt As DataSet, ByVal FolderCopyto As String,ByVal SelectedItem As DataTable) If MsgBox("Do you want to E...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T04:33:55.130", "Id": "56906", "Score": "0", "body": "Why is `ProcessCopy` recursive? Can you give an example of what the folder structure looks like?" } ]
[ { "body": "<blockquote>\n <p>In this function, the copy (Write XML) is inside, but I want it to be separated from the function.</p>\n</blockquote>\n\n<p><H2>Shallow Observations</H2></p>\n\n<p>In no particular order:</p>\n\n<ul>\n<li><strong>You need to <em>indent</em> your code</strong>, it makes it much easi...
{ "AcceptedAnswerId": "35153", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-10T22:37:49.050", "Id": "35139", "Score": "3", "Tags": [ "vb.net" ], "Title": "Improving my invoice generator" }
35139
<p>Is this reliable?</p> <p>While there are many backup programs out there, it is still hard to find free software that allows unattended differential backup on Windows. Completely rolling something from scratch is usually not the way to go and after some searching I found that 7-Zip can be utilized to achieve full an...
[]
[ { "body": "<p><strong>Code Quality</strong></p>\n\n<p><em>1. PEP8/PyLint</em>:</p>\n\n<p>Fix <a href=\"http://pep8online.com/s/YnHEYUA5\" rel=\"nofollow\">http://pep8online.com/s/YnHEYUA5</a>\nI also suggest you to read these documents:</p>\n\n<ul>\n<li><a href=\"http://www.python.org/dev/peps/pep-0008/bvm=bv....
{ "AcceptedAnswerId": "35171", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T03:31:04.213", "Id": "35147", "Score": "5", "Tags": [ "python", "file-system" ], "Title": "Small backup script in Python based on 7-Zip" }
35147
<p>I'm trying to build a framework similar to Scrapy ItemPipelines or <a href="http://asperous.github.io/pipeless/" rel="nofollow">Pipeless</a>. The motivation is to be able to build generic data pipelines via defining a modular collection of "pipe" classes that handle distinct steps within the pipeline. I've taken s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T16:02:57.883", "Id": "57152", "Score": "1", "body": "Your `Pipeline.run()` *requires* an iterable, but you then proceed to hand that iterable to multiple pipeline runners; this won't work because an iterable can only be iterated ove...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T06:11:13.190", "Id": "35155", "Score": "2", "Tags": [ "python", "design-patterns" ], "Title": "Data pipeline processing framework" }
35155
Visual Studio is an integrated development environment (IDE) from Microsoft. THIS TAG SHOULD ONLY BE USED FOR CODE INVOLVING THE IDE ITSELF, NOT FOR CODE SIMPLY WRITTEN WITH IT.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T06:56:40.643", "Id": "35157", "Score": "0", "Tags": null, "Title": null }
35157
Data mining is the process of analyzing large amounts of data in order to find patterns and commonalities.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T06:58:48.953", "Id": "35159", "Score": "0", "Tags": null, "Title": null }
35159