body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Vimscript is based on the <em>ex</em> language of the original vi editor. However, Vimscript extends ex in many ways, including: support for control flow; function definitions; and advanced datatypes including lists and associative arrays (dictionaries).</p> <p>Vimscript files use the <code>.vim</code> file extensi...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T03:25:46.700", "Id": "38663", "Score": "0", "Tags": null, "Title": null }
38663
Vimscript is the scripting language built into the text editor Vim. It can also be referred to as "Vim Language" or "VimL".
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T03:25:46.700", "Id": "38664", "Score": "0", "Tags": null, "Title": null }
38664
<p>TeX is a typesetting system, where the output is defined by command-sequences. It was invented by Donald Knuth.</p> <p>There is <a href="http://tex.stackexchange.com">a Stack Exchange site dedicated to TeX</a>, which is a good place to ask any TeX-related questions.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T03:26:16.983", "Id": "38665", "Score": "0", "Tags": null, "Title": null }
38665
TeX is a typesetting system, where the output is defined by command-sequences. Note that http://tex.stackexchange.com is specifically dedicated to TeX questions.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T03:26:16.983", "Id": "38666", "Score": "0", "Tags": null, "Title": null }
38666
<p>I wrote a program that finds empty folders and subfolders in a directory. It's the first program I've ever written in Java, and I'd like some critique. I feel like I'm not utilizing classes in a very coherent manner. Also, I think I'm naming variables poorly, because as I write my program I find myself constantly ha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T08:35:51.913", "Id": "64536", "Score": "1", "body": "You're currently in danger of infinite recursion if the folder structure is cyclical (eg, a shortcut for Desktop is placed on the Desktop...). I doubt Windows or other OSs have a...
[ { "body": "<p>There are a few small items, and a couple of larger ones that concern me in your code...</p>\n\n<ul>\n<li>You have an empty <code>main</code> method under your hood.... it serves no purpose, so remove it ;-)</li>\n<li><p>you are not using the generic typing for your List. In this case, your code s...
{ "AcceptedAnswerId": "38670", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T03:27:25.920", "Id": "38667", "Score": "5", "Tags": [ "java", "recursion", "file-system", "swing" ], "Title": "Finding empty folders" }
38667
<p>My question is regarding a rather inelegant solution to a problem that I came up with a while ago.</p> <p>I was making a Winform Application to access active directory among other things and needed to thread my application to stop my UI from freezing. </p> <p>Although I have little knowledge of actual threading (I...
[]
[ { "body": "<p>You shouldn't <a href=\"http://blogs.msdn.com/b/pfxteam/archive/2010/06/13/10024153.aspx\" rel=\"nofollow noreferrer\">usually</a> use <code>Task</code> constructor directly, use <code>Task.Factory.StartNew</code> (or <code>Run</code>).</p>\n\n<p>I also don't understand why you want to have a sepa...
{ "AcceptedAnswerId": "38682", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T09:24:34.483", "Id": "38673", "Score": "6", "Tags": [ "c#", "multithreading", "task-parallel-library" ], "Title": "Using Task<T> and actions for simple threading?" }
38673
<p>I am using the following function to check if a MySQL connection is in an invalid state or if it has reached a predefined maximum operation count:</p> <pre><code> /// &lt;summary&gt; /// Holds the amount of operations for the currently mysql-connection open /// &lt;/summary&gt; private int connectionUsageCount =...
[]
[ { "body": "<ol>\n<li><p>As per <a href=\"https://stackoverflow.com/questions/5567097/using-mysqlconnection-in-c-sharp-does-not-close-properly\">this SO question</a> you need to be aware that calling <code>Close</code> will not necessarily actually close the connection but only put it back into the connection po...
{ "AcceptedAnswerId": "38676", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T09:39:49.917", "Id": "38675", "Score": "2", "Tags": [ "c#", "mysql" ], "Title": "Checking a MySQL connection and refreshing it" }
38675
<p>I have some Scala code that uses Internet to authorize a user. Therefore, it can throw Exceptions like <code>IOException</code> in the method.</p> <p>The original code was written in Java. So, yes, it uses variables, not <code>val</code>. Also it "returns early" many times if some condition is not satisfied.</p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T12:35:10.780", "Id": "64557", "Score": "0", "body": "I'm taking a look at Scala right now, so I'm also very interested in an answer. Thanks for asking!" } ]
[ { "body": "<p>After reading the code, I assume these are the signatures of the building blocks of your code</p>\n\n<pre><code>class IdInfo\nclass PasswordInfo\nclass ConnectionInfo\n\ndef calcIdInfo:IdInfo=???\ndef calcPwdInfo(idInfo:IdInfo):PasswordInfo=???\ndef calcConnInfo(idInfo:IdInfo,pwdInfo:PasswordInfo)...
{ "AcceptedAnswerId": "38698", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T12:25:53.763", "Id": "38689", "Score": "20", "Tags": [ "functional-programming", "scala" ], "Title": "Code with many \"early returns (exits)\" into the functional style" }
38689
<p>By outer-package, I mean outside of this package - this can be the DOM or other packages. This package has a basic event system and a basic registry. It also has a debugger which allows you to fiddle with the DOM by removing and adding entire sets of tags. Later it might have things which allow it to Debug / Con...
[]
[ { "body": "<p>The below code would be cleaner with object literal notation :</p>\n\n<pre><code> // a basic registry pattern with get/set and getMany/setMany\n $P.Reg = (function () {\n var publik = {},\n register = {};\n publik.get = function (key) {\n return register[k...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T13:28:11.597", "Id": "38692", "Score": "2", "Tags": [ "javascript", "library" ], "Title": "A package for outer-package communications" }
38692
<p>Compare to <a href="http://underscorejs.org/" rel="nofollow">underscorejs</a> if it pleases you. Once again, I hope this is well commented. Please let me know what comments/improvements I can add.</p> <p>Please review all aspects of this code.</p> <pre><code>/*****************************************************...
[]
[ { "body": "<p>The code itself looks somewhat clean, but I'd say it lacks the <a href=\"http://underscorejs.org/docs/underscore.html\" rel=\"nofollow\">elegancy of Underscore</a>.</p>\n\n<p>Your (P)ublic / P(r)ivate convention is very weird; I can't train my eyes to tell <code>$R</code> from <code>$P</code> quic...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T13:41:22.740", "Id": "38695", "Score": "0", "Tags": [ "javascript", "underscore.js" ], "Title": "Utility package comparable to underscores.js" }
38695
<p>Can this be improved?</p> <pre><code>foreach (Gift gift in usedGifts) { foreach (GiftTransaction GiftTransaction in gift.GiftTransactions) { if (!string.IsNullOrEmpty(giftTransaction.GiftId) &amp;&amp; !orderList.Where(b =&gt; b.GiftId == giftTransaction.GiftId).Any()) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T15:09:26.163", "Id": "64587", "Score": "2", "body": "please provide more information on what you want improved. and probably more surrounding code for context." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>I'm not sure if it will make your query faster but here is my take on it:</p>\n\n<p>If I read the code correctly you want to create orders for all gift transactions related to gift ids which are not covered by an order yet.</p>\n\n<pre><code>usedGifts.SelectMany(g =&gt; g.GiftTransactions)\n ...
{ "AcceptedAnswerId": "38715", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T15:04:42.860", "Id": "38700", "Score": "3", "Tags": [ "c#" ], "Title": "Creating orders for gift transactions" }
38700
<p>I recently had the need of "reflecting" multiple <code>enum class</code> constructs in order to get their elements' names as <code>std::string</code> objects or their element count. I came up with a C++11 variadic macro solution:</p> <pre><code>namespace ssvu { namespace Internal { inline std::vecto...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T18:07:48.483", "Id": "64608", "Score": "0", "body": "[**Abusing the preprocessor is a lot of fun**](http://pastebin.com/0qjynriq)" } ]
[ { "body": "<p>Just a few things to point out:</p>\n\n<ul>\n<li><p>There's no need to use <code>inline</code> yourself. For modern compilers, it merely serves as a suggestion, but they can otherwise determine if and when it's really needed. Read <a href=\"https://stackoverflow.com/questions/145838/benefits-of-...
{ "AcceptedAnswerId": "46229", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T16:15:23.993", "Id": "38703", "Score": "8", "Tags": [ "c++", "c++11", "reflection", "enum", "macros" ], "Title": "Variadic macro enum class \"reflection\" in C++11" }
38703
<p>I have been trying to solve <a href="http://projecteuler.net/problem=35">Project Euler problem number 35</a>. The problem is to find:</p> <blockquote> <p>How many circular primes are there below one million?</p> </blockquote> <p>A circular prime is a prime where all the rotations of its digits are primes too. E....
[]
[ { "body": "<p><strong>Updated</strong> since reading the <a href=\"http://en.wikipedia.org/wiki/Circular_prime\" rel=\"nofollow noreferrer\">wikipedia definition of circular prime</a> </p>\n\n<p>There are a few things I would recommend you change in your <code>findCircularPrimes</code> algorithm. First, you sho...
{ "AcceptedAnswerId": "38725", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-06T21:13:45.030", "Id": "38718", "Score": "8", "Tags": [ "javascript", "algorithm", "project-euler", "primes" ], "Title": "Checking for circular primes - Project Euler Problem...
38718
<p>For a few reasons I had to use EJS on a specific page in my Express project. This was previously like 13 lines of code with MustacheJS and a small JSON file. But now that it is hard-coded, it is a monstrous 289 lines of code (not counting lines in the includes). What can I do here? </p> <pre><code>&lt;!doctype htm...
[]
[ { "body": "<p>Sorry to tell you, but unfortunately it is near impossible to dry html in itself if you want to keep the elements in the same way.</p>\n<p>As far as I can see, you already use only the minimum amount of elements.</p>\n<h1>Move on, your code is fine</h1>\n", "comments": [], "meta_data": { ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T03:04:13.083", "Id": "38730", "Score": "4", "Tags": [ "html", "node.js", "express.js" ], "Title": "Using EJS for a web page" }
38730
<p>I've written this <code>ActionResult</code> to model an Order that goes through. I couldn't think of another way to write this without using context <code>Db&lt;Sets&gt;</code>. It runs kinda slow, taking around 4 seconds to complete. Is there way to optimize the code or is this kinda has to happen since I'm doing s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T14:44:19.713", "Id": "64708", "Score": "0", "body": "I think you could go with wrapping the context in a \"Unit Of Work\" and the UnitOfWork in a \"Repository\" patterns.\n\nhttp://www.asp.net/mvc/tutorials/getting-started-with-ef-5...
[ { "body": "<p>I'm not sure i understand exactly why you have multiple contexts. If you keep to one context you can do one SaveChanges(). That should save you some time in storing data. </p>\n\n<p>Do all your SaveChanges() take equal amount of time? </p>\n\n<p>You could add a timer inside the contexts to print o...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T06:26:20.063", "Id": "38732", "Score": "1", "Tags": [ "c#", "entity-framework", "asp.net-mvc-4", "controller" ], "Title": "Inserting using multiple contexts into LocalDB" }
38732
<p>I've just completed <a href="http://see.stanford.edu/materials/icspmcs106a/07-assignment-1-karel.pdf" rel="nofollow">the 3rd task of the 1st assignment offered by Stanford's programming methodologies</a> (see the <a href="http://see.stanford.edu/see/materials/icspmcs106a/assignments.aspx" rel="nofollow">full resourc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T11:49:22.097", "Id": "64695", "Score": "1", "body": "Your JavaDoc style is extremely odd, was that a requirement/template from them? Oh, it's not JavaDoc at all...[you'd better read up on that one](http://www.oracle.com/technetwork/...
[ { "body": "<p>Overall, your code looks pretty good! I'd say if you want a more thorough code review of your abilities, you should write up some code that doesn't simply call these external methods. It's hard to get a good feel of whether you know good programming/Java habits when all of your methods only call...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T10:56:20.427", "Id": "38741", "Score": "6", "Tags": [ "java", "homework", "state-machine" ], "Title": "Design feedback for automaton to draw a checkerboard pattern" }
38741
<p>I am modifying Volley for Android a bit and Findbugs complains about the data flow and I am a bit lost. First the code:</p> <pre><code>String userAgent; try { String packageName = getPackageName(); PackageInfo info = getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + inf...
[]
[ { "body": "<p>It would be bad practice to silently <em>swallow</em> an exception. However, I think the following code would be acceptable:</p>\n\n<pre><code>String userAgent = \"volley/0\"; // Default value\ntry {\n String packageName = getPackageName();\n PackageInfo info = getPackageManager().getPacka...
{ "AcceptedAnswerId": "38743", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T11:11:57.983", "Id": "38742", "Score": "5", "Tags": [ "java", "android" ], "Title": "Data flow anomaly: how to do it correct?" }
38742
<p>What could be a better implementation, following the Scala way of doing it?</p> <pre><code>class Node(itemValue: Object, nextItem:Node){ val value = itemValue val next = nextItem } class MyList() { var start: Node =null def add(value:Object){ val cache = start this.start = new Node(value,cache) ...
[]
[ { "body": "<p>A list is just a wrapper for an element that also contains a pointer to another list, thus its definition is straightforward:</p>\n\n<pre><code>scala&gt; abstract class MyList[+A]\ndefined class MyList\n\nscala&gt; case class MyCons[A](head: A, tail: MyList[A]) extends MyList[A]\ndefined class MyC...
{ "AcceptedAnswerId": "38754", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T12:30:39.000", "Id": "38744", "Score": "5", "Tags": [ "scala" ], "Title": "Singly linked list implementation in Scala" }
38744
<p>I want to import in python some ascii file ( from tecplot, software for cfd post processing). Rules for those files are (at least, for those that I need to import): -The file is divided in several section -Each section has two lines as header like:</p> <pre><code>VARIABLES = "x" "y" "z" "ro" "rovx" "rovy" "rovz" "...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T12:53:57.883", "Id": "64699", "Score": "0", "body": "Not enough for an answer but you could/should use list comprehension in vectorr and the with keyword when you open your file (you forfot to close it)" } ]
[ { "body": "<p>There are two algorithmic aspects to your code which concern me. The most significant problem is that you read the entire file in to memory before you start processing the data:</p>\n\n<pre><code>filelist = a.readlines()\n</code></pre>\n\n<p>This is an inefficient way to do things with large input...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T12:44:42.477", "Id": "38745", "Score": "2", "Tags": [ "python" ], "Title": "Importing of big files:right approach?" }
38745
<p>I made Conway's Game of Life in JavaScript and was hoping someone could give me some pointers regarding my logic of checking adjacent cells. I know there must be a better way, but at the same time, it works.</p> <p><strong>JS:</strong> </p> <pre><code>var board = [["","","","","","","","","","","","","","",...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T15:58:58.143", "Id": "64737", "Score": "2", "body": "About a year ago I created a Game of Life in Javascript, as an excercise. I used html5 canvas to render, but you can see how I solved some things. http://jsfiddle.net/mgvd/a2tVe/"...
[ { "body": "<p>There is a major bug/issue, and also stringing together three very different recommendations here.</p>\n\n<h2>Bug/issue</h2>\n\n<p>in the Game-Of-Life you are supposed to scan the entire board, and only then apply the changes. You are applying changes part-way through the process (as you check eac...
{ "AcceptedAnswerId": "38749", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T13:01:22.673", "Id": "38746", "Score": "45", "Tags": [ "javascript", "html", "game-of-life" ], "Title": "Conway's Game of Life in JavaScript" }
38746
<p>I have created a small 'game' which basically asks the user for the row number and column number and then picks a random number and if that number is above 11, out of 15, the user wins. When the user wins that position in the array is replaced with a X or O to indicate a win or loss.</p> <p>The program works fine. ...
[]
[ { "body": "<p>Think about what happens when you want to change your dimensions from 10x10 to 12x14.\nHow many locations in your code would require updating?</p>\n\n<p>You can look into using constants for the dimensions and the <code>.length</code> property of your arrays to bound your <code>for</code> loops.</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T14:29:54.933", "Id": "38752", "Score": "6", "Tags": [ "c++", "beginner", "game", "random", "number-guessing-game" ], "Title": "Random number game" }
38752
<p>I have a year or so of experience in developing in Java. I submitted <a href="https://github.com/kristjanr/energycalc" rel="nofollow">the solution</a> for <a href="http://blog.codeborne.com/2012/04/every-developer-wants-to-estimate-his.html" rel="nofollow">this task</a>, but never got the feedback that was promised....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T09:13:45.547", "Id": "65196", "Score": "2", "body": "Personally, I distinguish between comments and JavaDoc, the last is documentation which is non-negotiable. Can there be too many comments? Yes, absolutely. Can there be too many J...
[ { "body": "<p>the first thing that I noticed is that your functions do not describe an action, they are missing a verb. So when a reader comes to the function \"MonthConsumption()\" he has to read your comment to find out if the function calculates a mont consumption or .. or .. or consumes a month :-)</p>\n\n<...
{ "AcceptedAnswerId": "38769", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T15:52:45.250", "Id": "38762", "Score": "6", "Tags": [ "java", "unit-testing", "api", "jodatime" ], "Title": "Computing the electricity consumption of a client" }
38762
<p>I based this implementation upon the implementation given in <a href="https://stackoverflow.com/a/16215688/1219414">this answer</a> and the book linked in it, but modified it to, instead of a constraint list and a substitution stack, generate a substitution tree in a single tree traversal operation. </p> <p>Each no...
[]
[ { "body": "<p>I can't say much about the correctness but I have some comments about the design:</p>\n\n<ol>\n<li><p>Whenever you write code like this:</p>\n\n<pre><code>if (foo is SomeType)\n{\n // do something\n}\nelse if (foo is SomeOtherType)\n{\n // do something else\n}\n...\n</code></pre>\n\n<p>then th...
{ "AcceptedAnswerId": "38817", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T15:58:57.583", "Id": "38763", "Score": "5", "Tags": [ "c#" ], "Title": "Is this implementation of the Hindley-Milner algorithm correct?" }
38763
<p>I'm in a location with poor Internet access. In order to ensure that a call to an external service succeeds, I am wrapping the call in a pseudo-<code>do-while</code> in Python. Additionally, I am limiting the call to running a maximum of three times:</p> <pre><code>def post_safe(url, params): done = 0 max_...
[]
[ { "body": "<p>The <code>else</code> branch in your <code>try</code> is hackish (skipping over the <code>max_tries</code>) so I added <code>success</code> variable.<br>\n(Although you asked not to avoid it in the question, I think it's the better way, and I'll explain why.)</p>\n\n<p>It also nicely allowed me to...
{ "AcceptedAnswerId": "38768", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T16:26:06.097", "Id": "38766", "Score": "6", "Tags": [ "python", "error-handling" ], "Title": "Do-While loop in Python, with limit on the amount of 'do's" }
38766
<p>I am trying to write clean code in Java for reading text of any size and printing the word count in ascending order without using Java collection framework.</p> <p>For example, given the following input text "What is the your name of the name?", it should print:</p> <pre><code>your 1 of 1 is 1 What 1 name 2 the 2 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T16:41:47.030", "Id": "64729", "Score": "0", "body": "Could you include the `TextAnalyzerUtil.sort` method in your code? That way we could compile the code ourselves and therefore make a better review." }, { "ContentLicense":...
[ { "body": "<p>There are a couple of things you should think about or fix:</p>\n\n<ul>\n<li><p>Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.</p></li>\n<li><p>No need to call <code>super()</code> inside your constructor, the default empty super constructor i...
{ "AcceptedAnswerId": "38771", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T16:30:24.427", "Id": "38767", "Score": "10", "Tags": [ "java", "strings", "array" ], "Title": "Word count program in Java" }
38767
<p>I have a function which sends an email via outlook when given text, a subject, and recipients shown below:</p> <pre><code>def __Emailer(text, subject, recipient, auto=True): import win32com.client as win32 outlook = win32.Dispatch('outlook.application') mail = outlook.CreateItem(0) if type(recip...
[]
[ { "body": "<p>In Python, it is part of the mentality to check for behavior rather than for exact type. </p>\n\n<p>Your method doesn't even need <code>recipients</code> to be a list—it can be any iterable (e.g. a set) so it can be used in the <code>for</code> loop. Strings, however, are also iterable, so you ne...
{ "AcceptedAnswerId": "38780", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T17:52:18.913", "Id": "38776", "Score": "4", "Tags": [ "python", "python-2.x", "outlook" ], "Title": "Sending an email via Outlook" }
38776
<p>This morning, I wrote a quick-and-dirty table-revision generation script: (<a href="https://gist.github.com/chrisforrence/8303815" rel="nofollow">gist</a>). It is intended to be run in the command line. Here's the entirety of it (149 lines):</p> <p> <pre><code>/** * Creates a revision table for an already-existin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T19:23:42.670", "Id": "64775", "Score": "0", "body": "The only real comment I have to add is, If you know you could do better then why not? For question 1 I would say its never acceptable to half do the job. 2) NEVER ignore a securit...
[ { "body": "<blockquote>\n <ol>\n <li>I know that I'm not handling my PDO object very well. For truly one-off scripts, is this acceptable, or should I create an internal PDO wrapper?</li>\n </ol>\n</blockquote>\n\n<p>It is generally discouraged to wrap PDO. Please see this <a href=\"https://codereview.stackex...
{ "AcceptedAnswerId": "38794", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T18:34:49.077", "Id": "38779", "Score": "0", "Tags": [ "php", "optimization", "pdo" ], "Title": "Generating revision-table to accompany existing table" }
38779
<p>I'm at loggerheads between performing operations one-by-one within a method, performing all of them at once (in one block) within the method, or breaking them up into four different methods.</p> <p>In terms of best-practice, which of the following three options seems most advantageous, and why would it be preferred...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T10:42:16.983", "Id": "64852", "Score": "2", "body": "Why do you call `.add()` so many times? Why not go `List<string> specialWordEndings = new List<String>(){\"a\",\"b\",\"c\"};`?" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>I'd take the last option and then extract common functionality between</p>\n\n<ul>\n<li><code>SpacelessWordBreakUnusualCombo</code></li>\n<li><code>SpacelessWordBreakNormalBeginUnusualEnd</code></li>\n<li><code>SpacelessWordBreakUnusualBeginNormalEnd</code></li>\n</ul>\n\n<p>and other methods into...
{ "AcceptedAnswerId": "38782", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T18:53:05.167", "Id": "38781", "Score": "5", "Tags": [ "c#", "strings", "comparative-review" ], "Title": "Splitting words in a selected file" }
38781
<pre><code>bool loadFileContents(const std::string&amp; fileName, std::string &amp;out) { bool res = false; FILE* file = fopen(fileName.c_str(), "r"); char buf[128] = { 0 }; if (file) { while (fread(buf, 1, sizeof(buf), file)) out += std::string(buf); res = true; } fc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T20:27:03.637", "Id": "64783", "Score": "0", "body": "[Here's the same SO question, which also has an answer](http://stackoverflow.com/questions/20980801/what-would-be-a-correct-c-style-for-function-loading-file-contents)." }, { ...
[ { "body": "<p>Here are some of the C-style features of your code:</p>\n\n<ul>\n<li><code>FILE</code> </li>\n<li><code>fopen</code> </li>\n<li><code>char buf [128]</code> </li>\n<li><code>fclose</code> </li>\n</ul>\n\n<p>I personally liked the answer that was given in @Jamal's link.</p>\n\n<pre><code>std::i...
{ "AcceptedAnswerId": "38796", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T19:45:50.930", "Id": "38784", "Score": "3", "Tags": [ "c++", "stream" ], "Title": "What would be a correct C++ style for function loading file contents?" }
38784
<p>These arrays are the result of Store Procedure. They are to build a Google Chart, therefore I need transform the array to a specific format. I also want to remove the <code>$col</code> and <code>$row</code> elements that have a Null value. These arrays are dynamic to their length variable, but a <code>$row</code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T00:58:45.467", "Id": "64812", "Score": "0", "body": "Every heard of `RecursiveFilterIterator` (part of the SPL)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T01:42:39.730", "Id": "64818", "...
[ { "body": "<p>Why not do something like this?</p>\n\n<pre><code>$output = array();\n\nif((bool)$cols &amp;&amp; (bool)$rows) {\n foreach($rows as $row_index =&gt; $row) {\n foreach($cols as $column_index =&gt; $column_name) {\n $column_has_atleast_one_value = false;\n if(isset($r...
{ "AcceptedAnswerId": "38936", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T20:04:08.167", "Id": "38787", "Score": "0", "Tags": [ "php", "array" ], "Title": "how many alternative ways are there, and how much better are they to transform this array?" }
38787
<p>I recently read the book <em>Clean Code</em> and I also did some research on the SOLID principles. I'm looking for general feedback on if I was able to transpose the examples (written in Java) to Python while still maintaining a "Pythonic" program.</p> <p>I wrote a simple TicTacToe game in Python using Tkinter as t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T07:36:55.223", "Id": "64833", "Score": "1", "body": "Please check the indentation; it is off at least in `TicTacToeBoard.draw`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T13:12:22.077", "Id":...
[ { "body": "<p>Looks to me that you want to have a box with various buttons that allows you to select, say, easy, medium, or hard. Return that and then say </p>\n\n<pre><code>if AIChoose == \"Easy\":\n getEasyAIMove()\nelif AIChoose == \"Medium\":\n GetMedAIMove()\nelif AIChoose == \"Hard\":\n GetHardAI...
{ "AcceptedAnswerId": "39706", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T20:46:23.113", "Id": "38789", "Score": "8", "Tags": [ "python", "game", "tkinter", "tic-tac-toe" ], "Title": "Clean code and SOLID principles for a simple Python TicTacToe ...
38789
<p>I wrote <a href="https://github.com/RobertZenz/daemonize-win" rel="nofollow">a simple tool to allow to daemonize any process under Microsoft Windows</a>.</p> <p>The goal is to push <em>any</em> process into the background with no questions asked. That includes GUI applications, which means that the main window will...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T23:39:11.563", "Id": "64804", "Score": "0", "body": "The Windows analogue of a daemon is a [service](http://stackoverflow.com/q/7073557/1157100)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T08:14:...
[ { "body": "<p>It looks good: very good, assuming it works (i.e. has the run-time behaviour that you want: I don't know the effect of calling <code>CreateProcess</code> in that way).</p>\n\n<p>You don't <code>free(arguments)</code> but that doesn't matter because memory will be reclaimed by the O/S when the proc...
{ "AcceptedAnswerId": "39086", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T21:31:17.573", "Id": "38793", "Score": "3", "Tags": [ "c", "windows" ], "Title": "Daemonize a process under Microsoft Windows" }
38793
<p>Elsewhere, there was a question about finding an elegant solution to a particular problem, and the following solution was presented.</p> <p>I'm curious whether this solution is elegant <strong>from the perspective of easy to understand</strong> for a Ruby programmer (which I am no longer).</p> <pre><code>merged_fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-07-09T10:16:24.880", "Id": "175987", "Score": "0", "body": "The code does something, it's not _hypothetical_" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-07-09T10:22:08.110", "Id": "175990", "Score": "...
[ { "body": "<p>I had no trouble figuring it out what it does, but I'm not sure I'd call it \"easy to understand\". </p>\n\n<p>All the declarations are implicit and thus if you're familiar with all the in's and outs of Array and the map method, it's pretty straight forward what the code is attempting to do. Some ...
{ "AcceptedAnswerId": "38798", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T21:49:03.193", "Id": "38795", "Score": "2", "Tags": [ "ruby" ], "Title": "How clear is this Ruby code?" }
38795
<p>A few months ago I wrote this module but, coming back to it, I find it a bit hard to read and reason about. I want to ask community's opinion on whether this needs to be refactored, and how I could approach this.</p> <pre><code>(function (q) { 'use strict'; var DELAY_BEFORE_RENDERING_NEXT_PAGE_VIEW = 3 * 1000...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T23:16:01.420", "Id": "64800", "Score": "0", "body": "I must say, this sure looks like a complicated way to express what it is you're trying to do. If it were me, I'd back up to first principles and find a much easier way to express...
[ { "body": "<p>Is this code hard to comprehend? Yes.</p>\n\n<p>That is because there are a lot of unknown functions: <code>view.render</code>, <code>page.fetchUnlessReady</code>, <code>token.catchItself</code> ,<code>token.throwIfCanceled</code> or <code>window.st.Helper.CancellationToken.getNone()</code> etc. e...
{ "AcceptedAnswerId": "38806", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-07T22:52:21.867", "Id": "38800", "Score": "4", "Tags": [ "javascript", "mvc", "asynchronous", "promise" ], "Title": "Refactoring asynchronous JS pre-rendering code" }
38800
<p>I have the following factory class, wonder if this code can be implemented in better way. I saw few discussions about spring factory bean, but don't find good examples.</p> <pre><code>@service public CustomerSearchFactory{ @Autowired private CustomerSearchByID searchById; @Autowired private CustomerSearchBy...
[]
[ { "body": "<p>I would advise not to use a different <code>CustomerSearch</code> per search criteria.<br/>\nAs your functionality will evolve you could need a <code>CustomerSearch</code> that is using the country the <code>Customer</code> is from.<br/>\nBut what if you want to search on the <code>Country</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T00:13:48.600", "Id": "38802", "Score": "3", "Tags": [ "java", "spring" ], "Title": "factory pattern in spring" }
38802
<p>I'm making a Windows service that watches a directory for new files to process them.</p> <p>I hit a race condition between the file copying going on and me trying to process it. Going by a SO answer I wrote the following wait-and-retry method to make sure I can work with the file:</p> <pre><code>public static void...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T06:08:02.433", "Id": "64825", "Score": "0", "body": "It seems to me that you're only closing a newly created connection to the file not an existing one. You might have to pass the stream instead so that it can be closed." }, { ...
[ { "body": "<p>Your <code>catch</code> statement is catching <strong>any</strong> error <em>(<strong>EVERY ERROR</strong>)</em>, which is not a good thing. I assume there are several errors that you are anticipating, but you shouldn't catch them all. You will run into bugs and won't know what is going on becau...
{ "AcceptedAnswerId": "38829", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T04:08:44.373", "Id": "38807", "Score": "8", "Tags": [ "c#", "task-parallel-library" ], "Title": "Implementing a cancellable \"infinite\" loop" }
38807
<p>Markdown was developed by John Gruber, and described on his <a href="http://daringfireball.net/projects/markdown/" rel="nofollow noreferrer">website</a>. However, the grammar was not rigorously specified, leading to a number of variant implementations. In September 2014, a <a href="http://standardmarkdown.com" rel...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T04:09:50.533", "Id": "38808", "Score": "0", "Tags": null, "Title": null }
38808
Markdown is a markup language which can allow for plain-text documents to be transformed into HTML and other formats.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T04:09:50.533", "Id": "38809", "Score": "0", "Tags": null, "Title": null }
38809
<p><a href="https://stackoverflow.com/questions/20969923/weird-behaviour-of-a-seconds-elapsed-function/20970030?noredirect=1#comment31504047_20970030">Background of the problem</a></p> <p>My Class level variables: </p> <pre><code> static int secondsInterval = 100000000; static long secondsSpecial=0; static...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T10:43:55.537", "Id": "64853", "Score": "1", "body": "What's your goal? To parse `d` as a date and add `seconds` to it, except that `seconds` is rounded up to the next 1157 days? May I ask why?" }, { "ContentLicense": "CC BY-...
[ { "body": "<pre><code> static long secondsSpecial=0;\n</code></pre>\n\n<p>Static variables that get modified? Rethink your approach.</p>\n\n<p>If you have static variables, there's a good chance that either your design is wrong, or it should be an instance class. Always limit the scope of variables, methods and...
{ "AcceptedAnswerId": "38819", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T04:30:41.017", "Id": "38810", "Score": "2", "Tags": [ "java", "datetime", "integer" ], "Title": "Check robustness of function to add an interval to a date" }
38810
<p>As I understand it, blowfish (actually eksblowfish, as it's used one way) is generally seen a secure hashing algorithm, even for enterprise use (correct me if I'm wrong). Because of this, I created functions to create and check secure password hashes using this algorithm, and using the (also deemed cryptographically...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T07:11:41.647", "Id": "64830", "Score": "3", "body": "Why bother reinventing the wheel? Time and energy best spent upgrading your PHP version to 5.5, which introduced the `password_hash` function, to be called like so: `password_hash...
[ { "body": "<p>I would have to agree with @EliasVanOotegem. Consider using <code>password_hash()</code> and <code>password_verify()</code>. All you've done is recreate something, which <a href=\"https://security.stackexchange.com/questions/25585/is-my-developers-home-brew-password-security-right-or-wrong-and-why...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T06:08:39.363", "Id": "38812", "Score": "1", "Tags": [ "php", "security" ], "Title": "PHP secure hash generator" }
38812
<p>I tend to write quite explicit tests for my rails controllers exposing APIs with two seperate concerns:</p> <ul> <li>meeting the defined API-Response with headers headers and the response itself</li> <li>ensuring the right calls to underlaying methods/objects are made</li> </ul> <p>However when the calls are not s...
[]
[ { "body": "<p>shared examples share the <a href=\"https://stackoverflow.com/a/5557454\"><code>let</code> scope</a>, so you could further dry up your code (assuming you use <code>do_action</code> for every action) to this:</p>\n\n<pre><code>shared_examples :empty_success_response do\n\n before do\n do_action...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T07:07:47.757", "Id": "38813", "Score": "2", "Tags": [ "ruby", "ruby-on-rails", "rspec" ], "Title": "How can this rails controller test be cleaner refactored?" }
38813
<p>I have two threads - one thread queues items another thread dequeues. <code>dequeue</code> is fast enough and so we can assume that queue is never contains more than 65536 items.</p> <p>C++ doesn't contain "ring-buffer." Boost has one, but it doesn't allow "reuse" of elements. So I wrote my own ring-buffer, which ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T21:39:50.517", "Id": "64960", "Score": "0", "body": "because of currWriteNum/curReadNum overflow you have a dependency on the ring size being a power of 2. You should write length in those terms or add a comment about the dependency...
[ { "body": "<ul>\n<li><p>there is absolutely no thread safety constructs, this means that you'll see a lot of <em>interesting</em> race conditions and memory inconsistencies </p></li>\n<li><p>just assuming dequeues happen fast enough does not mean they will in production</p></li>\n<li><p>you return <code>T</code...
{ "AcceptedAnswerId": "39436", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T08:15:24.953", "Id": "38815", "Score": "13", "Tags": [ "c++", "multithreading", "circular-list" ], "Title": "One reader / one writer no-memory-allocation lock-free ring-buffer"...
38815
<p>Is it possible to create dynamic TR and TD elements in an HTML table? Something similar but better than this:</p> <pre><code>jQuery(document).ready(function() { $('button[name="new-title"]').on('click', function(){ var table = $('table[name="errortitle"]'); var tr = $('&lt;tr /&gt;'); var td = $('&lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T17:34:47.357", "Id": "65128", "Score": "0", "body": "An alternative way should be AngularJS. You can define a default HTML and ride a repeater into this code. For more information: [AngularJS:ngRepeat](http://docs.angularjs.org/api/...
[ { "body": "<p>You could create a function that will add a row to the table based on the number of elements of data you pass to it (which will become columns):</p>\n\n<pre><code>function newRow($table,cols){\n $row = $('&lt;tr/&gt;');\n for(i=0; i&lt;cols.length; i++){\n $col = $('&lt;td/&gt;').appe...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T08:28:50.897", "Id": "38816", "Score": "7", "Tags": [ "javascript", "jquery", "html" ], "Title": "jQuery dynamic elements like TR and TD, add to HTML table" }
38816
<p>I am getting data from JSON and then create rows of it:</p> <pre><code> $.each(data.GetwebMethodResult, function (index, item) { $("#TableABC").append(FunABC(item.aID, item.b, item.c, item.d, item.e, item.f)); }); function FunABC(a, b, c, d, e, f) { var row = "&lt;tr class='Row' ...
[]
[ { "body": "<p>Not really. It hard to optimize something with little logic. You could do this instead:</p>\n\n<pre><code>var row =\n \"&lt;tr class='Row' onclick=\\\"AnotherUnrelatedFunction('\" + a + \"' , '\" + b + \"', '\" + c + \"', '\" + d + \"', '\" + e + \"', '\" + f + \"')\\&gt; \\\n &lt;div cla...
{ "AcceptedAnswerId": "38828", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T12:47:53.897", "Id": "38822", "Score": "3", "Tags": [ "javascript", "json" ], "Title": "Creating rows from JSON data" }
38822
<p>I have a class foo that needs to get input from different sources, namely input streams, arrays and iterators. The code that actually does the work in the end takes iterators as input, and all the other methods end up calling it behind the scenes:</p> <pre><code>void from_stream(std::istream&amp; in); // Read from ...
[]
[ { "body": "<p>Why not just <code>insert()</code> and <code>iterator</code> like most containers in the STL.</p>\n\n<pre><code> std::vector&lt;int&gt; data;\n std::ifstream file(\"Plop\");\n\n data.insert(data.end(), std::istream_iterator&lt;int&gt;(file),\n std::istream_iterator&l...
{ "AcceptedAnswerId": "38857", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T13:07:25.510", "Id": "38824", "Score": "3", "Tags": [ "c++" ], "Title": "Design for C++ class methods taking input from different sources" }
38824
<p>I'm wondering about the following code:</p> <pre><code>def ValidateGoto(placeToGo): conditions = {} conditions["not placeToGo"] = "Enter a positive integer in the text box" conditions[ "int(placeToGo) &lt;= 0"] = "I need a positive integer in the text box please" conditions[ ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T16:37:15.930", "Id": "64894", "Score": "1", "body": "This code does not work: the indentation is wrong and there is a missing double quote. Can you fix, please?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>You have the right basic idea - pass a list of conditions - but the implementation is wrong.</p>\n\n<p>Yes, you should avoid <code>eval</code>; it is a dangerous source of potential error (and performs poorly as a non-bonus). You might put <em>anything</em> in there. You might not even notice a ...
{ "AcceptedAnswerId": "38869", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T13:09:50.790", "Id": "38825", "Score": "4", "Tags": [ "python", "python-2.x" ], "Title": "if statements or eval?" }
38825
<p>I created a JS widget library for distribution purpose on external websites and would like your thoughts on it.</p> <p><strong>What widget does:</strong> It adds an always visible text on the screen. When user clicks on text, an external page gets loaded in iFrame in a lightbox. Internally, widgets loads jQuery lib...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T18:51:12.937", "Id": "64916", "Score": "0", "body": "some of your questions imply that you have not tested the code and that you don't know if the code works or not." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<h1>Focus on your widget</h1>\n\n<p><strong>Do not</strong> load its dependencies. Instead, have the user of the widget to load them for you. </p>\n\n<p>Real world scenario: </p>\n\n<ul>\n<li>Bootstrap requires jQuery for it to work. Do you see Bootstrap load jQuery for itself? <strong>No, you don't....
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T14:21:02.100", "Id": "38830", "Score": "2", "Tags": [ "javascript", "jquery", "jquery-ui" ], "Title": "Is this JS Widget written correctly and production-ready?" }
38830
<p>I have a process, let's call it Proc1. It is installed in two different directories and one instance of each is running:</p> <ul> <li>C:\DirA\Proc1.exe </li> <li>C:\DirB\Proc1.exe</li> </ul> <p>When iterating through all currently running processes, I need to be able to differentiate one from the other. I do this...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T02:13:51.463", "Id": "64979", "Score": "1", "body": "Since you say you want the full path to the process, I would pay more attention to this note: *Note that you can use the [QueryFullProcessImageName](http://msdn.microsoft.com/en-u...
[ { "body": "<p>I think you don't need to check for errors twice, and that will make your code cleaner.</p>\n\n<pre><code>bool MyClass::IsCorrectPath (const DWORD dwPid, const std::string &amp;strPath) const\n{\n DWORD dwError = 0 ;\n NormalHandle hModSnap ; // RAII wrapper for HANDLE\n ::SetLastError (0...
{ "AcceptedAnswerId": "38845", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T16:51:02.950", "Id": "38839", "Score": "3", "Tags": [ "c++", "windows", "winapi" ], "Title": "Using ::CreateToolhelp32Snapshot" }
38839
<p><strong>Background</strong></p> <p>This is my first experience with functional programming and totally self-study. I just have 2-3 days' worth experience in Haskell. Now let's continue with actual code.</p> <hr> <p>For <a href="http://www.haskell.org/haskellwiki/99_questions/1_to_10" rel="nofollow">Problem 2</a> ...
[]
[ { "body": "<p>You have the right idea, I just want to make a few remarks:</p>\n\n<ol>\n<li>You could have used <code>_</code> in the first and the last clause of your function in place of the ignored arguments. It might help readability to know right away that an argument is being ignored.</li>\n<li>You're expl...
{ "AcceptedAnswerId": "38864", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T17:17:20.850", "Id": "38840", "Score": "4", "Tags": [ "beginner", "haskell" ], "Title": "99 Haskell Problems - Problem 2" }
38840
<p>I'm looking for advice how to improve the code. It's a mess, but I don't know how to improve it. There are some mathematical errors, projectile movements are behaving strangely, code is messy in general, unit positions are off, etc.</p> <pre><code>var canvas = document.createElement("canvas"); canvas.id = "canvas...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T17:34:53.980", "Id": "64901", "Score": "1", "body": "Do you have prior experience with *object oriented programming*? Is this your first larger programming project? Knowing this could help to write a more useful code review." }, ...
[ { "body": "<p><strong>Object Literal Notation</strong></p>\n\n<p>There are number of objects that would be easier to create</p>\n\n<pre><code>camera = new Object();\ncamera.x = -50;\ncamera.y = -50;\ncamera.zoom = 1;\nmouse = new Object();\nmouse.x=0;\nmouse.y=0;\nselect = new Object();\nselect.x1=0;\nselect.y1...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T17:26:12.363", "Id": "38842", "Score": "6", "Tags": [ "javascript", "game" ], "Title": "RTS game improvement" }
38842
<p>Since I am new to MVC and the Entity Framework, I have been struggling to grasp the concept of creating useful Data and Service layers. I have come across a scenario where I believe my code has become very redundant: </p> <p><strong>Data Access Layer:</strong></p> <pre><code>public static class DeploymentOrderDa...
[]
[ { "body": "<p>This is going to be just a partial review, I don't have much time but I can't help it, I have to say something.</p>\n\n<ul>\n<li><p><code>usr_OrderFulfillment</code> might be how the table is called in your database, and <code>SOPNUMBE</code> might be how a column is called in that table. <strong>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T17:36:26.617", "Id": "38843", "Score": "6", "Tags": [ "c#", "asp.net-mvc-4", "asp.net-mvc" ], "Title": "Building a better Data Access Layer Class" }
38843
<p>I am doing a little in-between semester reading in my C++ book, and I came up with the wonderful idea to try to make Yahtzee in C++. So far the code generates 5 random numbers and then calls the function that I made to display a rendering of the die. I cannot figure out how to allow the users to hold the dice that t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T18:32:07.810", "Id": "64912", "Score": "0", "body": "Your best bet is to copy the code into visual studio and try it out." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T19:35:15.800", "Id": "6492...
[ { "body": "<p>You might consider not generating the dice displays every time, but rather storing them as strings, for example:</p>\n\n<p>To display a dice value of 1 you could use the string:</p>\n\n<pre><code>std::string displayValue1 = \"\\n***\\n*x*\\n***\\n\\n\";\n</code></pre>\n\n<p>Then you could store yo...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T18:31:24.527", "Id": "38847", "Score": "4", "Tags": [ "c++", "game", "dice" ], "Title": "Yahtzee game in C++" }
38847
<p>This thing kills me: </p> <pre><code> def report_subtitle case params[:kind] when 'position' then h("for Position: #{@current_company.positions.find_by_id(params[:id])}") when 'grade' then h("for Grade: #{params[:id]}") when 'location' then h("for Location: #{Lo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T22:40:30.913", "Id": "64966", "Score": "2", "body": "What does your view template look like? If the report subtitle has this many cases, I'd expect that this is just the tip of the iceberg." } ]
[ { "body": "<p>There are a few issues with this method:</p>\n\n<ul>\n<li>The parameter <code>kind</code> is not descriptive enough. Is this a kind of report? Is it <code>report_type</code>?</li>\n<li>You seem to be looking up a <code>Location</code>, <code>Position</code> and <code>Department</code> using the sa...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T22:11:18.063", "Id": "38858", "Score": "2", "Tags": [ "ruby-on-rails", "helper" ], "Title": "Horrible case statement for displaying a title" }
38858
<p>I'v written this code snippet that's part of a code competition. </p> <p>I want to do the trick without the for-loop, or simply find a way to optimize this code for speed. </p> <pre><code>for ( i=1; i&lt;=N; i++ ) </code></pre> <p>How is it possible, if it is? What do I need to modify to speed up this code con...
[]
[ { "body": "<p>A compiler might unroll the loop for you. Try inspecting the assembly output when it is compiled at different optimization levels.</p>\n\n<p>As for the body of the loop, I'd keep the string manipulation to a minimum.</p>\n\n<pre><code>int AB = A * B;\nfor ( int i=1; i&lt;=N; i++ )\n{\n if (...
{ "AcceptedAnswerId": "38867", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T22:40:30.897", "Id": "38859", "Score": "0", "Tags": [ "optimization", "performance", "objective-c", "fizzbuzz" ], "Title": "How can I remove this for-loop in this competiti...
38859
<p>From <a href="https://codereview.stackexchange.com/questions/38371/avoiding-duplicate-boilerplate-code-in-wcf-service?noredirect=1#comment63990_38371">a previous question</a>, I got the idea of moving boilerplate code structures into a helper function and passing in a lambda function to it.</p> <p>I then applied th...
[]
[ { "body": "<p>I'd say the best course of action is to make your <code>ProcessDatabaseCall</code> generic:</p>\n\n<pre><code>private T ProcessDatabaseCall&lt;T&gt;(string procedureName, Func&lt;SqlCommand, T&gt; processor)\n{\n using (SqlConnection Mackin1Conn = new SqlConnection(connectionString))\n {\n ...
{ "AcceptedAnswerId": "38883", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T22:54:50.157", "Id": "38860", "Score": "2", "Tags": [ "c#", "lambda" ], "Title": "Unwanted return values in lambda functions?" }
38860
<p>Which style of printing strings from the SI registry in NASM is more correct?</p> <p>I'm learning assembly and x86 architecture, but I'm rather new in it, so I've prepared two styles (in NASM) of printing a string, which is held in the <code>SI</code> register.</p> <p>For a clear text, the samples are at the botto...
[]
[ { "body": "<p>The two samples don't quite do the same thing. The first sample starts by setting the location of the stack and data segments to some 'magic' location in memory:</p>\n\n<pre><code>mov ax, 07C0h\nadd ax, 288\nmov ss, ax\nmov sp, 4096\nmov ax, 07C0h\nmov ds, ax\n</code></pre>\n\n<p>The second sample...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-08T23:23:40.740", "Id": "38861", "Score": "9", "Tags": [ "strings", "beginner", "assembly" ], "Title": "Iterating string characters and passing them to a BIOS API" }
38861
<p>I wrote this function to find the index of the first substring. I was wondering if you can help me find some flaws or possibly help increase performance?</p> <p>Example:</p> <blockquote> <p>str = "happy" substr = "app"</p> <p>index = 1</p> </blockquote> <p>My code:</p> <pre><code>public static int subStri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T02:14:02.980", "Id": "64980", "Score": "0", "body": "You can simplify that a great deal by not reassigning index at each step" } ]
[ { "body": "<p>Just checking that you intend to be <a href=\"/questions/tagged/reinventing-the-wheel\" class=\"post-tag\" title=\"show questions tagged &#39;reinventing-the-wheel&#39;\" rel=\"tag\">reinventing-the-wheel</a>, you can do:</p>\n\n<pre><code>System.out.println(\"happy\".indexOf(\"app\"));\n</code></...
{ "AcceptedAnswerId": "38872", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T01:58:48.963", "Id": "38870", "Score": "6", "Tags": [ "java", "performance", "strings", "reinventing-the-wheel" ], "Title": "Finding index of first substring" }
38870
<p>I'm looking for a review paying special attention as to whether the code can be optimized in the form of number of variables used, especially for the <code>delete()</code> method.</p> <pre><code>public class circularLL { Node start; Node last; circularLL() { start=null; last=null; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-12-31T15:37:17.383", "Id": "137009", "Score": "0", "body": "You would get more reviews if you provide more information about this piece of code." } ]
[ { "body": "<p>I'm not a big algorithms/data structures guy, but the only thing that caught my attention was the <code>delete</code> function. Is there a reason that <code>delete</code> uses data to identify the node, as opposed to just taking in the <code>Node</code> object you want to delete? It seems like tha...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T05:05:36.207", "Id": "38876", "Score": "5", "Tags": [ "java", "optimization", "linked-list", "circular-list" ], "Title": "Circular linked list of integers" }
38876
<p>I have a text file that contains <code>name</code>, <code>age</code>, <code>salary</code>, <code>hoursWorked</code>, <code>randomText</code> and are filled with different delimiters.</p> <p>Text file:</p> <pre><code>susan:25-2600,28[asd] mary:21-2200,38[asd] john:23-3400,46[asd] </code></pre> <p>Instead of breaki...
[]
[ { "body": "<p>I would create a class and define an input operator:</p>\n\n<pre><code>struct Person\n{\n std::string name;\n std::string age;\n std::string salary;\n std::string hoursWorked;\n std::string randomText;\n\n friend std::istream&amp; operator&gt;&gt;(std::istream&amp; str, Person&am...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T05:58:40.180", "Id": "38879", "Score": "12", "Tags": [ "c++", "parsing" ], "Title": "Parsing text file in C++" }
38879
<p>To catch errors, I have written if-else blocks in every function which looks bad. Please suggest a better way to handle errors in async node.</p> <pre><code> async.waterfall([ function(callback){ fnOne.GetOne(req, res,function(err,result) { if(err){ ...
[]
[ { "body": "<p>Check out <a href=\"http://www.html5rocks.com/en/tutorials/es6/promises/\" rel=\"nofollow\">promises</a>. They are not (yet) available natively in Node.js, but you can use <a href=\"https://github.com/kriskowal/q\" rel=\"nofollow\">Q library</a>.</p>\n\n<p>Promises allow you to make your control f...
{ "AcceptedAnswerId": "38905", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T08:52:53.343", "Id": "38884", "Score": "1", "Tags": [ "javascript", "node.js", "asynchronous" ], "Title": "Best way to handle the error in async node" }
38884
<p>I am thinking about passing a private variable of one class into another class, for some belonging case like 'company --> department --> employee'. As an employee can tell some information of his company, there's some private variables I'd like to pass.</p> <p>I think this relationship is not as same as common clas...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T16:01:44.173", "Id": "65085", "Score": "0", "body": "This works well, you might get fed up with `this.` after a while, at that point you can look into IIFEs." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-...
[ { "body": "<p>Ideally, how you choose to represent the members inside <code>TeamClass</code> shouldn't matter to the outside world. Your solution is fine, but I think I'd get tired of accessing the members like this:</p>\n\n<pre><code>class01.members[0].report();\n</code></pre>\n\n<p>It's a bit cumbersome. Plus...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T08:59:17.410", "Id": "38885", "Score": "1", "Tags": [ "javascript", "classes" ], "Title": "Passing private variable in JavaScript nested class?" }
38885
<p>I currently have a basic application that has a database backing it. I originally connected to the database with Entity Framework, but my tutor has requested from me to recreate the functionality with ADO.NET SQL. This has gone well so far using the <code>SqlDataReader</code>, however I have come across a problem.</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T09:12:31.150", "Id": "65010", "Score": "1", "body": "Could animals have properties, that extend base class?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T09:13:38.420", "Id": "65011", "Score...
[ { "body": "<p>Here is your code refactored - since all animals have id, name and age, you can remove duplication (reading and setting these properties for each type of animal):</p>\n\n<pre><code>if (reader.HasRows)\n{\n while (reader.Read())\n {\n string animalType = reader.GetString(3);\n\n ...
{ "AcceptedAnswerId": "38887", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T09:07:25.423", "Id": "38886", "Score": "5", "Tags": [ "c#", "homework", "ado.net" ], "Title": "Build object from database without a discriminator column?" }
38886
<p>I am pretty new to Python and just wanted to make sure I am going in the right direction with my coding style.</p> <p>After reading <a href="http://dirtsimple.org/2004/12/python-is-not-java.html" rel="nofollow">this</a>, I'm not so sure.</p> <p>The following is a convenience class that has operations used a lot in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T13:40:20.763", "Id": "65057", "Score": "0", "body": "Ugh, if..elif..elif That's a bad smell. Use a dictionary to map the request verb to the appropriate function. Raise an exception if there is no key in the dictionary to match t...
[ { "body": "<ol>\n<li><p>Unlike in Java, not everything in Python needs to be a class. In Python we tend to reserve classes for representing <em>things</em> with individual state and common behaviour. If you just want to group some functions together, you can put them in a <em>module</em>.</p></li>\n<li><p>You h...
{ "AcceptedAnswerId": "38900", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T09:45:49.990", "Id": "38890", "Score": "4", "Tags": [ "python", "design-patterns", "python-2.x" ], "Title": "Python coding style from Java background" }
38890
<p>I am not new to html however would like to know about best practices. I need to develop a layout like this:</p> <p><img src="https://i.stack.imgur.com/5P2JW.png" alt="enter image description here"></p> <p>This is what I have proposed:</p> <pre><code>&lt;div id="body"&gt; &lt;div id="body-main"&gt; &lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T10:13:46.233", "Id": "65015", "Score": "0", "body": "Seems pretty solid to me. Depending on what you are trying to achieve you could possible remove a few `<div>s` here and there such as `div#body-main-upper-image`and target the ima...
[ { "body": "<p>You might consider adding classes. You have many broadly similar elements on that page; adding classes to them would give you more flexibility in your CSS. As things stand, you can only apply style to elements based on their id, their parent elements or their type (and hey, they're all DIVs).</p...
{ "AcceptedAnswerId": "38910", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T09:56:19.323", "Id": "38891", "Score": "4", "Tags": [ "html", "layout" ], "Title": "Improve HTML structure?" }
38891
<p>Refactor this code so that I don't have to insert the parameters any time I need to use one of the functions.</p> <p>I have a class, say <code>julian</code>, for calculating Julian dates of today, a date I insert and the difference between these two Julian dates. </p> <pre><code> int julian::calc_julianToda...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T10:36:04.063", "Id": "65020", "Score": "0", "body": "I'm seriously at a loss as to what exactly you are trying to achieve. Can you post some code showing how you would like to be able to use it?" }, { "ContentLicense": "CC B...
[ { "body": "<p>Welcome to Code Review,</p>\n\n<p>I do not know how to solve your problem, however, your code could use polishing.</p>\n\n<ul>\n<li>Magical constants; your code is littered with them, use constants instead</li>\n<li>Undocumented magical constants, I can guess what <code>365</code> or <code>12</cod...
{ "AcceptedAnswerId": "38928", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T10:06:37.897", "Id": "38893", "Score": "3", "Tags": [ "c++", "classes", "datetime" ], "Title": "Calculating Julian dates" }
38893
<p>I have written a wrapper for Soap based 3rd party web service.</p> <p><a href="https://gist.github.com/veganista/bd940750d9e240e63b89" rel="nofollow">https://gist.github.com/veganista/bd940750d9e240e63b89</a></p> <p>I'm pretty happy with it so far (I think, anyway). It's only a small sub-set of what the full API ...
[]
[ { "body": "<p>Here are some tips for your class:</p>\n\n<p>For the lines like the following, I suggest applying different formatting (to make it more readable). Please see below:</p>\n\n<pre><code>$arguments = array_merge(array('UserName' =&gt; $this-&gt;username, 'Password' =&gt; $this-&gt;password), $argument...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T11:29:08.493", "Id": "38896", "Score": "1", "Tags": [ "php", "object-oriented", "classes", "php5", "web-services" ], "Title": "Review of my PHP Wrapper around Third Party ...
38896
<p>Continuation of this question: <a href="https://codereview.stackexchange.com/questions/36561/unit-of-work-with-generic-repository-pattern-mvvm-vol-2">https://codereview.stackexchange.com/questions/36561/unit-of-work-with-generic-repository-pattern-mvvm-vol-2</a></p> <p>I have made some modifications:</p> <ul> <li>...
[]
[ { "body": "<p>Few tiny items:</p>\n\n<ol>\n<li><p><strike>Can you use an <code>IDbConnection</code> interface (or worst case, <code>DbConnection</code> class) instead of <code>SQLiteConnection</code> for your constructor parameter/class member? This would allow for more generic operation, easier unit testing an...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T12:24:44.217", "Id": "38901", "Score": "2", "Tags": [ "c#", "sqlite", "mvvm" ], "Title": "Unit of Work with Generic Repository Pattern MVVM, vol. 3" }
38901
<p>Here's a problem that I tried solving: </p> <blockquote> <p>Lakshagraha was a house built of lacquer, made by the Kauravas to kill the Pandavas. The Kauravas wanted to burn the house down when the Pandavas were asleep at night. But poor Kauravas – once again they underestimated their cousins. Having been wa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T16:22:22.260", "Id": "65089", "Score": "0", "body": "Before it can be optimized for speed, it really needs to be refactored. That should make optimization much easier." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>Before I get started, I'm writing C++11. If you're using GCC, you'll need to compile with <code>-std=c++11</code> (consult your compiler documentation otherwise; if you have to use C++98/03, you'll need to modify some of the code). The code I'm giving you is also untested -- you may need to debug ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T13:03:45.557", "Id": "38904", "Score": "4", "Tags": [ "c++", "algorithm", "pathfinding", "breadth-first-search", "time-limit-exceeded" ], "Title": "Time Limit Exceeded in ...
38904
<p>I want to create a class <code>ClientSocket</code> with PHP, which is an adapter of the <code>fsockopen</code>, <code>fread</code>, and <code>fwrite</code>.</p> <pre><code>Class ClientSocket extends SenderAdapterAbstract { private $s = null; public function __construct($host, $port) { $this-&gt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-14T13:44:55.003", "Id": "198442", "Score": "0", "body": "As explained here: http://stackoverflow.com/questions/21021916/how-to-really-unit-test-an-adapter I don't have to UNIT TEST these kind of adapter pattern... Maybe \"integration t...
[ { "body": "<p><code>a unit test is not really one if it talks to the network...</code></p>\n\n<p>I am not so sure what you meant by that. It seems like you are trying to follow exactly what someone may have said in a book or a talk. Unit testing is all about testing a 'Model'. And the assumptions are that the M...
{ "AcceptedAnswerId": "45267", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T14:15:31.593", "Id": "38906", "Score": "3", "Tags": [ "php", "unit-testing" ], "Title": "Unit-testing an adapter" }
38906
<p>A job application of mine has been declined because the test project I submitted was not coded in a clean and straightforward way.</p> <p>Fine, but that's all the feedback I got. Since I like to continuously improve my coding skills, are there people here who want to check out this project at Github? It's not compl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T14:49:43.737", "Id": "65070", "Score": "0", "body": "I know that these requests should run simultaneously but you should have us review portions of your code rather than the whole thing, please post a portion of one of the requests ...
[ { "body": "<p>I have to agree with the evaluation.</p>\n\n<p><code>10thLetterRequest</code> and <code>Every10thLetterRequest</code> are pretty much exactly the same, except that <code>10thLetterRequest</code> only requires the first letter.</p>\n\n<p>Yet, you decided to use different regexes and have no re-use ...
{ "AcceptedAnswerId": "38939", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T14:25:26.817", "Id": "38907", "Score": "6", "Tags": [ "mvc", "objective-c", "interview-questions", "ios", "web-scraping" ], "Title": "HTTP site scraper" }
38907
<p>I have designed the following input validation implementation with one goal: DRY. I'd like to know whether it is intuitive and what are the possible shortcomings.</p> <pre><code>$vlad = new \ay\vlad\Vlad(); $test = $vlad-&gt;test([ // Test script [ // Group of selectors and validators. Each selector is assesse...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T15:41:07.797", "Id": "65081", "Score": "0", "body": "This question is not a good candidate for Code Review I feel. You are asking us to review a piece of code that only servers to demonstrate the use of library you wrote.. It would ...
[ { "body": "<p>Well, since you didn't post your lib code, I'm assuming you're looking for an API-review. I hope you're not going to take this the wrong way, but I wouldn't like to use your validator class at all.<Br/>\nIf I were you, I'd provide the users with an API that uses constants for the supported validat...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T15:14:36.490", "Id": "38911", "Score": "1", "Tags": [ "php", "form" ], "Title": "What are the drawbacks of DRY input validation configuration?" }
38911
<p>I have this script that moves a box around the screen and the loops the second part of the movement. I have altered the code to drop another three boxes (4 in total) into the animation so the boxes follow each other around the screen.</p> <p>I want it to work exactly like it does, but I'm sure there's a much better...
[]
[ { "body": "<p>You are repeating yourself a ton here, you should read up on DRY.</p>\n\n<p>You could store the animations in an array and then execute those animations : </p>\n\n<pre><code>var PROPERTIES = 0 , OPTIONS = 1;\nvar animations = \n[ \n [ {top: '425px'} , { duration: 1800, easing : 'linear', ...
{ "AcceptedAnswerId": "38918", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T15:59:33.643", "Id": "38915", "Score": "4", "Tags": [ "javascript", "performance", "jquery", "jquery-ui", "easing" ], "Title": "Delay and queue animation in a function ...
38915
<p>This is code for <a href="http://en.wikipedia.org/wiki/Fizz_buzz" rel="nofollow">FizzBuzz</a>. I have also hosted in on my <a href="https://github.com/sarawut-p/FizzBuzz" rel="nofollow">GitHub</a>.</p> <p><strong>FizzChecker Tests</strong></p> <pre><code>[TestClass] public class FizzChecker_Tests { IFizzChecke...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-30T00:16:56.870", "Id": "104941", "Score": "1", "body": "Related: https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition" } ]
[ { "body": "<p>I think you're overdoing it. SRP does not mean that every class should have only one method and every method should be a one-liner.</p>\n\n<p>Instead, you should structure your code into parts that are likely to change together (though that's not the only criterion). But here, it's not really poss...
{ "AcceptedAnswerId": "38924", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T16:57:34.240", "Id": "38920", "Score": "6", "Tags": [ "c#", "unit-testing", "fizzbuzz" ], "Title": "Does this FizzBuzz code correctly follow SRP and unit-testing?" }
38920
<p>Suppose I have a text file which contains 10,000 random values between 0 and 1, and I want to count the number of values within a specific interval. An example may explain it more clearly.</p> <p>Suppose my Datefile.txt contains data like:</p> <pre><code>0.0102244 0.028072 0.0144578 0.064578 0.08148 0.012749 0.12...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T17:47:40.073", "Id": "65100", "Score": "0", "body": "What are your single-letter variables for? It looks like they should be in an array. You also shouldn't use a single letter for any variable, unless it's a loop counter." }, ...
[ { "body": "<p>In general, do not to use single letters as variable names, unless they're simple loop counters. This reveals nothing about them and will just make your code harder to understand.</p>\n\n<p>In your example, it looks like you're holding the number of values at different ranges. Not only do your v...
{ "AcceptedAnswerId": "38930", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T17:34:22.047", "Id": "38922", "Score": "4", "Tags": [ "c++", "optimization", "statistics" ], "Title": "More efficient way of counting the number of values within an interval?" ...
38922
<p>My company has asked me to write a few Java based programs to deal with sending HTTP requests and parsing the response. After playing around with the Apache HTTP Commons library and making plenty of shortsighted programs using it, I've decided to make a little library for us to use and avoid major code duplication. ...
[]
[ { "body": "<p>I think that your exception handling is problematic.</p>\n\n<pre><code>try {\n ...\n} catch (IOException e) {\n e.printStackTrace();\n return null;\n}\n</code></pre>\n\n<p>Besides logging, all that accomplishes is degrade an \"informative\" kind of exception into a <code>null</code>, whic...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T18:00:46.663", "Id": "38926", "Score": "5", "Tags": [ "java", "library", "http" ], "Title": "Java HTTP Apache - Making my own library" }
38926
<p>There must surely be a nicer way of writing this.</p> <p>The wrinkle of complexity is that <code>prev_seq</code> or <code>next_seq</code> might be an empty string if the user moves the question to the first or last position, but it could also validly be '0.0' so I can't just rely on 'falsiness'.</p> <p>I hope it's...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T20:52:10.880", "Id": "65134", "Score": "0", "body": "Have you tried `if prev_seq == \"\":`? That gives a different result for \"\" and 0." } ]
[ { "body": "<pre><code>def get_new_position(prev_seq, next_seq):\n\n if next_seq == \"\":\n new_position = float(prev_seq) + 1\n elif prev_seq == \"\":\n new_position = float(next_seq) - 1\n else:\n new_position = (float(prev_seq) + float(next_seq)) / 2\n\n return new_position\n<...
{ "AcceptedAnswerId": "38940", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T18:00:55.773", "Id": "38927", "Score": "3", "Tags": [ "python", "python-2.x" ], "Title": "Function to find midpoint of two floats where one of the floats might be an empty string" ...
38927
<p>I have written a function for switching advert image based on <code>$template</code>. Function is working completely fine without any problem and getting everything dynamically with no issue.</p> <p>Concerning performance, I want some feedback and suggestion from you experts to optimize code in better way.</p> <p>...
[]
[ { "body": "<p>Ah! what a stupid mistake I have done.. :P Didn't realized that I don't have to use Switch Case either. Here is the final optimized code</p>\n\n<pre><code>function page_advert()\n{\n\n $template = get_request() == '' ? 'home' : get_request_part(0);\n $advert = option('ops_'.$template.'_adver...
{ "AcceptedAnswerId": "38934", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T19:43:30.640", "Id": "38933", "Score": "1", "Tags": [ "php", "optimization" ], "Title": "Optimize switch case for dynamic content" }
38933
<p>This is a <code>.wav</code> to <code>.flac</code> <a href="https://en.wikipedia.org/wiki/Encoder" rel="nofollow">encoder</a> that I wrote a little while ago. The only method that is really called is <code>encode()</code>, which takes in a <code>.wav</code> file, converts it to <a href="https://xiph.org/flac/" rel="...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-12-22T00:50:15.400", "Id": "283368", "Score": "0", "body": "This code is not written by yourself, you just plagiarism code from xlph.org." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-12-22T01:05:19.640", "...
[ { "body": "<p>These two statement could be implemented by the same subroutine:</p>\n\n<pre><code>sampleRate = ((((((unsigned)buffer[27] &lt;&lt; 8) | buffer[26]) &lt;&lt; 8) | buffer[25]) &lt;&lt; 8) | buffer[24];\ntotalSamples = (((((((unsigned)buffer[43] &lt;&lt; 8) | buffer[42]) &lt;&lt; 8) | buffer[41]) &lt...
{ "AcceptedAnswerId": "39031", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T21:55:47.897", "Id": "38944", "Score": "5", "Tags": [ "performance", "c", "memory-optimization" ], "Title": "WAVE to FLAC encoder in C" }
38944
<p>I have been using HTML and CSS for a long time, and just starting to learn jQuery. I created a calculator by myself from research and trial and error. I would like someone to let me know what I'm doing wrong (pertaining to the jQuery) as far as code efficiency, structure, and comments.</p> <p>Here is the HTML:</p...
[]
[ { "body": "<p>You shouldn't specify ALL of your code in the jQuery ready callback. Try and move all your callbacks, etc out. OR if your code is at the end of the page, you can just execute it straight away.</p>\n\n<p>In your <code>equals</code> on click handle, <code>firstInput</code> and <code>secondInput</cod...
{ "AcceptedAnswerId": "38971", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T23:17:32.273", "Id": "38947", "Score": "2", "Tags": [ "javascript", "performance", "beginner", "jquery", "calculator" ], "Title": "Basic calculator in jQuery" }
38947
<p>This is a subclass of <code>Backbone.Collection</code> with a method <code>fetchNextPage</code> that returns a Q promise.</p> <p>To find out the next page's URL, it looks in <code>meta.next</code> from server response.<br> The server will return <code>null</code> for the last page.</p> <p>It also has a <code>getSt...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-09T23:36:14.570", "Id": "38950", "Score": "1", "Tags": [ "javascript", "asynchronous", "backbone.js", "pagination", "promise" ], "Title": "Paginated Backbone.Collection subcl...
38950
<p>This 43 line program is designed to listen for Syslog messages on port 514 and record the messages to an MS SQL Server database table.</p> <p>I would appreciate feedback from experienced node.js developers.</p> <p>I am just starting to learn node.js. I'm average at JavaScript, still getting my head around closure...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-19T08:25:40.947", "Id": "115697", "Score": "1", "body": "You probably want to use prepared statements to deal with escaping properly: https://github.com/Azure/node-sqlserver/blob/master/test/query.js#L74" } ]
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li><p>Comments should be worth the space they take up, my favourite offender is this one:</p>\n\n<pre><code>// open the database connection\nsql.open(conn_str, function (err, conn) {\n</code></pre></li>\n<li>I want to point to <a href=\"https://github.com/Azure/node...
{ "AcceptedAnswerId": "71538", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T00:21:35.967", "Id": "38951", "Score": "4", "Tags": [ "javascript", "sql-server", "node.js", "server" ], "Title": "node.js Syslog server recording to MS-SQL database" }
38951
<p>I have an ASP.NET application which uses a <a href="http://msdn.microsoft.com/en-us/library/bb628652.aspx" rel="nofollow">Service Reference</a> to a (third-party, offsite) payment processor.</p> <p>The service reference class is generated automatically. Its implementation is a subclass of <a href="http://msdn.micro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T02:26:03.853", "Id": "65158", "Score": "1", "body": "@retailcoder I don't have enough reputation to answer [your question in Chat](http://chat.stackexchange.com/transcript/message/13102181?noredirect=1#13102181); I want them to be s...
[ { "body": "<p>The code in the OP seems thread-safe to me, but may not be the best solution.</p>\n<p>If the channel has many concurrent users, and if using the channel takes for example 100 msec, then 100 concurrent users would queue for up to 10 seconds before being able to use the (single) channel one after th...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T00:26:47.843", "Id": "38953", "Score": "4", "Tags": [ "c#", ".net", "multithreading", "asp.net", "wcf" ], "Title": "Thread-safe wrapper around WCF ServiceModel.ClientBase ...
38953
<p>The following class's method <code>public IAsyncResult BeginInvoke(Delegate method, object[] args)</code> is called by a third party dll. This dll may or may not be multi-threaded.</p> <p>The dll also calls <code>public bool InvokeRequired { get; }</code> to check if it should call the <code>BeginInvoke</code> meth...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T01:17:47.000", "Id": "65152", "Score": "0", "body": "I'm not too sure about the lock-objects array. Nice question, welcome to CR!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T01:26:59.147", "Id...
[ { "body": "<p>I'm not entirely sure what exactly you intend to be thread-safe. Right now just the access to the <code>Callback</code> and <code>Options</code> properties is locked and those locks are useless because <a href=\"https://stackoverflow.com/questions/5209623/is-a-reference-assignment-threadsafe\">ref...
{ "AcceptedAnswerId": "38972", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T01:14:13.123", "Id": "38956", "Score": "4", "Tags": [ "c#", "multithreading", "thread-safety" ], "Title": "Thread safe class" }
38956
<p>I have a business object base class which is inherited by my business objects:</p> <pre><code>public class ErrorBase { public bool HasError { get; set; } public List&lt;Error&gt; ErrorList { get; set; } public ErrorBase() { HasError = false; ErrorList = new List&lt;Error&gt;(); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T09:25:33.657", "Id": "65199", "Score": "0", "body": "Answer really depends on how you are going to use that class. Are you going to add errors to each of this class instances? Some of them will not have errors? Or only several will ...
[ { "body": "<p>First: I doubt that creating a new <code>List&lt;&gt;</code> object creates enough overhead which has measurable impact on your system so unless you can prove that it's a problem don't worry about it.</p>\n\n<p>That being said: The classic solution to that problem is lazy instantiation. As you hav...
{ "AcceptedAnswerId": "38969", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T02:46:28.247", "Id": "38961", "Score": "4", "Tags": [ "c#" ], "Title": "When to initialize infrequently used base class objects" }
38961
<p>Below is my Interface:</p> <pre><code>public interface IDBClient { public String read(ClientInput input); } </code></pre> <p>This is my implementation of the interface:</p> <pre><code>public class DatabaseClient implements IDBClient { @Override public String read(ClientInput input) { } } </code>...
[]
[ { "body": "<p>I have no major concern with setting the values of <code>ClientInput</code> via the constructor. What is your concern with this anyway? My minor concerns are:</p>\n\n<ol>\n<li>There are already three arguments of the Long type, it may not clear to other developers which position is for which field...
{ "AcceptedAnswerId": "38964", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T02:49:51.703", "Id": "38962", "Score": "3", "Tags": [ "java" ], "Title": "Passing input parameters correctly to a method" }
38962
<p>I am struggling with commenting and variable naming. My teacher says my comments need to be more explanatory and explicit. He says my variable names are also sometimes confusing. I was just wondering whether you could go through my code and see whether you are able to understand the comments and add in comments/edit...
[]
[ { "body": "<p>To steal an old quote: \"There are 2 hard things in computer science. Naming, cache invalidation, and off-by-one errors\". </p>\n\n<p>That being said, there is room for improvement here. Firstly, I'm assuming the class name, <code>PPM</code>, is short for <em>Portable Pixmap Format</em>. However, ...
{ "AcceptedAnswerId": "38966", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T02:50:28.293", "Id": "38963", "Score": "10", "Tags": [ "python", "image", "io" ], "Title": "Writing .ppm images to a file" }
38963
IEnumerable is a .NET interface for iterating (or enumerating) a collection of items.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T03:50:30.547", "Id": "38968", "Score": "0", "Tags": null, "Title": null }
38968
<p>OK, maybe crazy overkill and a little silly, but why not? Here's a Python FizzBuzz Acceptance Test:</p> <pre><code>import unittest from fizzbuzzmodule import fizzbuzz class FizzBuzzAcceptanceTestCase(unittest.TestCase): ''' Test that fizzbuzz(int) returns int unless multiple of 3 (then returns 'fizz')...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T06:04:24.563", "Id": "65179", "Score": "0", "body": "you should remove the code golf part, or post it on the [Code Golf Stack Site](http://codegolf.stackexchange.com/)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>For something so simple, it might be less overkill to use the <a href=\"http://docs.python.org/2/library/doctest\" rel=\"nofollow\"><code>doctest</code></a> module. Write the expected calls and outputs in the docstring, then run <code>python -m doctest -v fizzbuzzmodule.py</code>. There's no nee...
{ "AcceptedAnswerId": "38984", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T05:49:09.280", "Id": "38973", "Score": "4", "Tags": [ "python", "unit-testing", "fizzbuzz" ], "Title": "Python Fizz Buzz, Acceptance Unit test" }
38973
<p>This was a project I worked on for fun that basically uses a genetic algorithm to produce simple Brainfuck programs that output whatever the user specifies.</p> <p>I was just was hoping for criticism of the code, mainly if I'm doing anything blatantly wrong. I'm not too familiar with the STL, so there may have been...
[]
[ { "body": "<p>There's quite a bit of code here, so I'm not going to get through all of it, but I'll do as much as possible. Also, since I don't have access to your <code>interpreter.h</code>, I can't guarantee everything I've written will compile; there may be syntax errors and a few bugs lurking around, so con...
{ "AcceptedAnswerId": "38995", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T05:56:30.417", "Id": "38974", "Score": "7", "Tags": [ "c++", "generics", "brainfuck" ], "Title": "Genetic C++ programming with Brainfuck" }
38974
<p>Say you have a dictionary <code>some_dict</code> and want to make sure there's no key <code>some_key</code> in it. What's the best way to do this stylistically speaking and why?</p> <p><strong>Option 1</strong></p> <pre><code>some_dict.pop(some_key, None) </code></pre> <p><strong>Option 2</strong></p> <pre><code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T13:23:43.393", "Id": "65223", "Score": "0", "body": "If you happen to need a separate copy there's always `copied_dict = { k : v for (k,v) in some_dict.iteritems() if k != some_key }`. (or `items()` instead of `iteritems()` in pytho...
[ { "body": "<p>Option 1 looks perfect to me. It does the job in one line and is easy to read. </p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T13:48:10.420", "Id": "65227", "Score": "0", "body": "That's what my first instinct...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T06:32:24.837", "Id": "38976", "Score": "1", "Tags": [ "python" ], "Title": "In Python, stylistically better way to remove a potentially nonexistent key from a dictionary?" }
38976
<p>This is my first shot at implementing a fully static version of the <code>Observer</code> pattern in C++11. It is static in that all notifications are dispatched via CRTP, and therefore there is no virtual overhead. It also has the benefit of catching unimplemented notifications at compile time, by checking availa...
[]
[ { "body": "<p>Personally (so you can take or leave this advice as this is just a personal pref) I find your style over compact and thus harder than necessary to read:</p>\n\n<pre><code>template &lt;typename Base&gt; class Observer {\n\n// I split this across two lines:\ntemplate &lt;typename Base&gt;\nclass Obs...
{ "AcceptedAnswerId": "39095", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T07:14:39.227", "Id": "38980", "Score": "4", "Tags": [ "c++", "c++11" ], "Title": "Static Observer Pattern in C++11" }
38980
<p>Assume the following requirements:</p> <p><img src="https://i.stack.imgur.com/DzZNJ.png" alt="enter image description here"></p> <p>Is it a good idea to use the Composite design-pattern for this, taking into account that there will be:</p> <ul> <li>Only 1 <code>TestPlan</code></li> <li>a <code>TestPlan</code> can...
[]
[ { "body": "<p>I don't think this is an example of composite pattern. Composite is defined as</p>\n\n<blockquote>\n <p>The Composite Pattern allows you to compose objects into tree\n structures to represent part-whole hierarchies. Composite lets clients\n treat individual objects and compositions of objects u...
{ "AcceptedAnswerId": "38983", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T08:05:41.240", "Id": "38981", "Score": "4", "Tags": [ "c#", "object-oriented", "design-patterns" ], "Title": "Use of the composite pattern" }
38981
A lambda is an expression that acts as an anonymous function. Use this tag if you would like to discuss the appropriateness of a lambda or anonymous function in your code.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T09:37:47.623", "Id": "38987", "Score": "0", "Tags": null, "Title": null }
38987
<p><strong>Introduction</strong></p> <p>I have a hierarchically nested tree class (like <code>SampleFolder</code>, s.b.) that I want to serialize. </p> <p>The problem arises with the collection of sub items like this one:</p> <pre><code>List&lt;SampleFolder&gt; subFolders; </code></pre> <p><strong>I do not want to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T12:24:45.597", "Id": "65211", "Score": "1", "body": "Is this *working code*? Primitive types like `double` cannot be used as type parameters. Also double is not suitable for equals check and thus for being used neither as IDs nor as...
[ { "body": "<p>Do not use floating point numbers as IDs! Floating point is a horrible minefield of gotchas out there to sabotage your program in subtle ways: Losing precision, imprecise equality, NaNs, …. Using a <code>double</code> only defers, but not solves these issues.</p>\n\n<p>For IDs, always use an integ...
{ "AcceptedAnswerId": "38989", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T09:46:26.977", "Id": "38988", "Score": "3", "Tags": [ "java", "generics", "collections", "serialization" ], "Title": "Forcing type-safe IDs for use with Collections and Map...
38988
<p>In a sorted array, I am trying to find pairs that sum up to a certain value. I was wondering if anyone could help me improve my code in performance or memory. I believe my code is O(n). If there are other method for finding pairs the sum up to a certain value that is much more efficient, I am open to these methods!<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T13:22:40.213", "Id": "65221", "Score": "0", "body": "The `i++;` produces the wrong result. I'd recommend you remove it from your question, since the code under review out to run and produce correct results. Why is it there?" } ]
[ { "body": "<h1>Code improvements</h1>\n\n<p>Before addressing efficiency, let's see if there are any improvements that could be made to the code.</p>\n\n<p>I suspect some of the names could be improved.</p>\n\n<ul>\n<li><code>pointer1</code> -> <code>value1</code></li>\n<li><code>pointer2</code> -> <code>value2...
{ "AcceptedAnswerId": "38998", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T12:50:21.257", "Id": "38994", "Score": "15", "Tags": [ "java", "performance" ], "Title": "Finding pair of sum in sorted array" }
38994
<p>I'm working on a simple program and am trying to make it faster.</p> <pre><code>import time import numpy as np import matplotlib.pyplot as plt import pp first_file = open("ac_data.dat", 'r') #real dataset includes about 20000 terms res_file = open("res.dat", 'w') times_file = open("times.dat", 'a') #times = [0.00...
[]
[ { "body": "<p>I don't do much python so I might be wrong but to my understanding, this:</p>\n\n<pre><code>job = job_server.submit(rxx_func, (arg_n,), (), ())\n</code></pre>\n\n<p>just submits a single job but it doesn't automatically parallelize it. If you want to process the input in parallel you need to submi...
{ "AcceptedAnswerId": "39044", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T13:59:33.307", "Id": "38999", "Score": "2", "Tags": [ "python", "optimization", "beginner" ], "Title": "Reading datasets from files to lists" }
38999
<p>I have implemented the shuffling algorithm of Fisher-Yates in C++, but I've stumbled across the modulo bias. Is this random number generation by <code>rand()</code> correct for Fisher-Yates?</p> <pre><code>srand(time(NULL)); vector&lt;int&gt; elements; // push numbers from 1 to 9 into the vector for (int i = 1; i ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-12T18:37:39.430", "Id": "65421", "Score": "4", "body": "rand() is well know for its bad distribution. But you are using it correctly. Note: `rand() % currentIndexCounter` does not give you a perfect distribution unless `currentIndexCou...
[ { "body": "<p>@Loki Astari is correct in his comment:</p>\n\n<blockquote>\n <p><code>rand()</code> is well know for its bad distribution. But you are using it correctly. Note: <code>rand() % currentIndexCounter</code> does not give you a perfect distribution unless <code>currentIndexCounter</code> is an exact ...
{ "AcceptedAnswerId": "39669", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T14:14:43.483", "Id": "39001", "Score": "13", "Tags": [ "c++", "algorithm", "c++11", "shuffle" ], "Title": "Fisher-Yates modern shuffle algorithm" }
39001
<p>I want to share something with this community. I did a class connection between Python and MySQL. I hope you can help me with this project and help me do a better class.</p> <p>Here is the class connection code:</p> <pre><code>import mysql __author__ = 'Alejandro' import mysql.connector from mysql.connector im...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-02-09T11:00:04.977", "Id": "222326", "Score": "0", "body": "Can you explain me which args must passed for Select method here ? cheers" } ]
[ { "body": "<p>Everything looks quite neat. Here are a few comments.</p>\n\n<pre><code> query = \"SELECT \"\n l = len(keys) - 1\n for i, key in enumerate(keys):\n query += \"`\"+key+\"`\"\n if i &lt; l:\n query += \",\"\n query += \" FROM %s\" % table\n</code></pre>\n\n<p>can...
{ "AcceptedAnswerId": "39013", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T15:42:57.837", "Id": "39009", "Score": "8", "Tags": [ "python", "mysql" ], "Title": "Python Connection with MySQL" }
39009
<pre><code>&lt;?php /** *session.php *danutz0501 *@copyright 2013 **/ //defined('BASE_PATH')||(header("HTTP/1.1 403 Forbidden")&amp;die('403 - Acces direct interzis.')); class session{ private $db, $table_name = 'session_data', $session_name = 'PDOSESSID', $session_litetime = 1440; private static $instance = n...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-13T00:10:23.583", "Id": "65454", "Score": "0", "body": "How about including some calling code?" } ]
[ { "body": "<p>For one thing, to increase readability and cleanliness, try organizing your code a little better. You can read more on that <a href=\"http://framework.zend.com/manual/1.12/en/doc-standard.html\" rel=\"nofollow\">here</a>.</p>\n\n<p>In <code>init()</code>, you can use <code>if(is_null(self::$instan...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T15:44:45.840", "Id": "39010", "Score": "4", "Tags": [ "php", "classes", "session" ], "Title": "Custom session class" }
39010
<p>So I have built a clock widget. It basically has 2 hands and displays a time, either the current time or a selected time. There is another option which tells the clock if it should move around as the time does. </p> <p>Is this a good way to do this? It seems to work well in my app but I was wondering if there migh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T18:13:58.310", "Id": "65273", "Score": "1", "body": "Is this an Android **widget** or an **application**? It seems like an application to me. You're confusing me when you're saying that it's a widget." }, { "ContentLicense":...
[ { "body": "<p>Just a few Java-related notes:</p>\n\n<ol>\n<li><p>About <code>getDegrees</code>:</p>\n\n<blockquote>\n <p>Flag arguments are ugly. Passing a boolean into a function is a truly terrible practice. It\n immediately complicates the signature of the method, loudly proclaiming that this function\n d...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-10T15:57:49.370", "Id": "39011", "Score": "7", "Tags": [ "java", "android", "datetime" ], "Title": "Clock View in Android" }
39011