body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>is this class ok? any and all advice very welcome. Would it be better to pass the config file path array into the constructor or even through the static register method</p> <pre><code>namespace dh_mvc2\autoloaders; use dh_mvc2\classes\Config; /** * * @namespace dh_mvc2\autoloaders * @uses dh_mvc2\classes\Config i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T12:08:59.487", "Id": "37167", "Score": "0", "body": "On this line you simply use `/` as directory separator. `$className = str_replace ( \"\\\\\", \"/\", $className ) . '.php';`, but on this line `$fullFilePath = constant ( $key ) ....
[ { "body": "<p>Generally your class relies on multiple global states and is therefore tightly coupled with the environment.</p>\n\n<p>For instance:</p>\n\n<pre><code>private function __construct() {\n $this-&gt;pathsArray = array_change_key_case ( ( array ) Config::get_paths (), CASE_UPPER );\n self::$_ins...
{ "AcceptedAnswerId": "24099", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T11:17:50.640", "Id": "24092", "Score": "1", "Tags": [ "php", "object-oriented" ], "Title": "php autloader class reviews welcome" }
24092
<p>There are two aspects to formatting:</p> <h2>Report layout</h2> <p>How the output is presented, such as in columns or as a chart.</p> <h2>Formatting data items</h2> <p>How individual items are converted from internal representation to human-friendly output.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-03-19T11:17:59.597", "Id": "24094", "Score": "0", "Tags": null, "Title": null }
24094
For programs that are concerned with producing meaningful or clearer output. A typical example would be the transformation of a decimal into a particular currency format with the correct number of decimal places. (Note that code layout is always in scope for answers, so this tag is not used to indicate perceived iss...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-03-19T11:17:59.597", "Id": "24095", "Score": "0", "Tags": null, "Title": null }
24095
<p>I've been porting python Keyczar to work under 2to3 conversion (<a href="https://github.com/jbtule/keyczar-python2to3" rel="nofollow">Github</a>). I wanted to consolidate its streaming AES encrypt/decrypt backend interface with its string decrypt/encrypt. So I wrote a new implementation using <code>io.BufferReader</...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T12:55:28.317", "Id": "24101", "Score": "3", "Tags": [ "python", "security", "cryptography" ], "Title": "Streamed encrypt then MAC construction" }
24101
<blockquote> <p>Implement atoi to convert a string to an integer.</p> <p>Requirements for atoi: The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed...
[]
[ { "body": "<pre><code>if (((*str) != '\\0') &amp;&amp; (!isdigit(*str))) {\n return 0;\n}\n</code></pre>\n\n<p>You don't need this condition, because of the condition in the while loop afterwards. If that fails the first time <code>j</code> with value <code>0</code> is returned anyway.</p>\n\n<p>And a minima...
{ "AcceptedAnswerId": "24105", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T14:21:55.447", "Id": "24103", "Score": "2", "Tags": [ "c", "strings", "interview-questions" ], "Title": "string to integer (implement atoi)" }
24103
<p>I've taken this class and made it my own but I'm curious to know what other think of it? Are there things I'm missing? Anything you can recommend?</p> <pre><code>class Database { private $host = ''; private $user = ''; private $pass = ''; private $dbname = ''; private $dbh; private $error; ...
[]
[ { "body": "<pre><code> private $host = '';\n private $user = '';\n private $pass = '';\n private $dbname = '';\n\n // ....\n\n public function __construct() {\n $dsn = 'mysql:dbname=' . $this -&gt; dbname . ';host=' . $this -&gt; host . '';\n\n // ...\n }\n</code></pre>\n\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T14:56:44.260", "Id": "24104", "Score": "2", "Tags": [ "php", "classes", "pdo" ], "Title": "PDO database class review" }
24104
<p>the requirement for our search query is to look for all search words in the beginning of vehicle manufacturer, model and variant name. Case insensitive. The word being a string of characters separated by space.</p> <p>E.g. when search for "AU A3 TDI" you would find a vehicle with the following attributes: <code>Veh...
[]
[ { "body": "<p>I'm not entirely sure how your second example fails to match, because the string <code>\"Renault A3 2.0L TDI\"</code> contains all of \"AU\", \"A3\", and \"2.0\".</p>\n\n<p>That being said, here's an attempt at a cleaner rewrite:</p>\n\n<pre><code>Expression&lt;Func&lt;SearchVehicleVariant, bool&g...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T16:46:16.027", "Id": "24111", "Score": "6", "Tags": [ "c#", ".net", "linq" ], "Title": "Left hand search in string" }
24111
<p>Can anyone help me optimize my code? I really don't know what to do about all the var rectangles and <code>var</code> colors.</p> <pre><code>package PO; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.text.Text; import javafx.scene.text.Font; import javafx.scene.shape.Rectangle; import ja...
[]
[ { "body": "<p>You could reduce a some of your code by declaring your Rectangles and colors (kleur) as arrays. Then you could initialize (or reset) the kleur array elements within a loop.</p>\n\n<p>For example:\nInstead of </p>\n\n<pre><code>var rectangle1: Rectangle;\nvar rectangle2: Rectangle;\nvar rectangle3...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T16:48:44.410", "Id": "24112", "Score": "1", "Tags": [ "javascript", "optimization", "game" ], "Title": "Optimizing memory game" }
24112
<p>Please could you review and critic my code and logic? Is this is along the right lines of an MVC application class or not?</p> <pre><code>namespace dh_mvc2; use dh_mvc2\dispatchers\Base_Dispatcher; use dh_mvc2\routers\Base_Router; use dh_mvc2\autoloaders\Basic_Autoloader; use dh_mvc2\classes\Config...
[]
[ { "body": "<p>this looks pretty good to me.</p>\n\n<p>Some thoughts for entertainment;</p>\n\n<ul>\n<li><p>If you created the router in init(), then _config would not be required any more as a protected property, one less private property</p></li>\n<li><p>There seems to be no error handling when <code>$this-&gt...
{ "AcceptedAnswerId": "24119", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T17:39:44.920", "Id": "24114", "Score": "1", "Tags": [ "php", "object-oriented", "mvc", "url-routing" ], "Title": "MVC application class" }
24114
<p>For class, I was asked to write a (linear probing) hash table in Java. (I was also asked to write a linear-chaining hash table, which is why I named this one <code>HashtableB</code> as opposed to just <code>Hashtable</code>.) I'm think my code is correct, but please tell me if I've messed up.</p> <p>Primarily, thou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T22:43:24.120", "Id": "37228", "Score": "1", "body": "Your IDE will likely generate skeleton javadoc for you (and actually, that belongs on the interface definition, for those methods). I can't speak to the rest of your implementati...
[ { "body": "<p>I highly recommend <a href=\"http://rads.stackoverflow.com/amzn/click/0132350882\"><em>Clean Code: A Handbook of Agile Software Craftsmanship</em></a> by Robert C. Martin. It's an excellent source of great advice precisely aimed at your questions. The earlier you start, the fewer bad habits you'll...
{ "AcceptedAnswerId": "24132", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T17:55:49.787", "Id": "24116", "Score": "11", "Tags": [ "java", "homework", "hash-map" ], "Title": "Hash table implementation in Java" }
24116
<p>I have the following markup, and I'm wondering how best to locate the nearest previous <code>dpicker</code> input element and give it focus with jQuery when <code>a.dpicon</code> is clicked.</p> <pre><code>&lt;div class="eight mobile-two columns"&gt; &lt;input autocomplete="off" class="dpicker" type="text" name="...
[]
[ { "body": "<p>I would make the link between the 2 implicit.</p>\n\n<p><code>&lt;a href=\"#mdpdate\" id=\"startdatecalicon\" class=\"dpicon\"&gt;</code></p>\n\n<p>Then the code is </p>\n\n<pre><code>$(\".dpicon\").click(function(){\n $( this.href ).focus()\n}\n</code></pre>\n\n<p>It is a creative (ab)use of hre...
{ "AcceptedAnswerId": "24120", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T18:03:51.160", "Id": "24118", "Score": "1", "Tags": [ "javascript", "jquery", "html" ], "Title": "Locating child of a nearby ancestor with jQuery" }
24118
<p>I am very new to JavaScript and was wondering what kind of process or design pattern is most common among JavaScript developers.</p> <p>So far I have following code</p> <h2><code>index.html</code></h2> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"/&gt; ...
[]
[ { "body": "<p>First of all, your code's just fine as-is. Still, there are improvements that could be made.</p>\n\n<ol>\n<li><p>This isn't about the JavaScript, but the HTML: You're loading a lot of stuff twice for some reason. Both the google fonts and jQuery are loaded both as <code>//</code> and as <code>http...
{ "AcceptedAnswerId": "24124", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T18:43:19.183", "Id": "24121", "Score": "0", "Tags": [ "javascript", "datetime", "image", "canvas" ], "Title": "Updating clock with Canvas" }
24121
<p>A large .csv file I was given has a large table of flight data. A function I wrote to help parse it iterates over the column of Flight IDs, and then returns a dictionary containing the index and value of every unique Flight ID in order of first appearance.</p> <pre><code>Dictionary = { Index: FID, ... } </code></pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T09:20:04.877", "Id": "37238", "Score": "0", "body": "You are not always retrieving the first occurrence because \"If a value is equal to the value after it, it skips it.\"" } ]
[ { "body": "<p>One thing that slows you down is <code>if next in thegoodshit.values()</code> because it has to iterate through the values.</p>\n\n<p>A simple way to eliminate duplicate values is to first construct a dictionary where values are the key:</p>\n\n<pre><code>unique_vals = {val: i for i, val in enumer...
{ "AcceptedAnswerId": "24170", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T20:40:52.533", "Id": "24126", "Score": "3", "Tags": [ "python", "performance", "parsing", "csv", "iteration" ], "Title": "Retrieving the first occurrence of every uniqu...
24126
<p>Go, commonly referred to as "golang", is a fast, statically typed, compiled language created by Google. The language was initially developed as an alternative to C++ for server infrastructure and has native support for concurrency.</p> <h3>See also</h3> <ul> <li><a href="https://en.wikipedia.org/wiki/Go_%28program...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T21:00:56.223", "Id": "24128", "Score": "0", "Tags": null, "Title": null }
24128
Go, commonly referred to as "golang", is a fast, statically typed, compiled language created by Google. The language was initially developed as an alternative to C++ for server infrastructure and has native support for concurrency.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T21:00:56.223", "Id": "24129", "Score": "0", "Tags": null, "Title": null }
24129
<p>I'm trying to solve a graph traversal problem I found, and was wondering how I could improve my implementation. Currently it seems a little convoluted and long. </p> <p>The problem is as follows: I have a matrix of size (rows x cols). This matrix has some cells that are empty (designated by a 0) and some cells that...
[]
[ { "body": "<h3>1. Bug</h3>\n\n<p>I tried a different test case:</p>\n\n<pre><code>graph = [[1, 0, 0, 0, 1], [1, 1, 0, 1, 0], [0, 0, 0, 0, 0], [1, 1, 0, 1, 1], [1, 0, 0, 0, 0]]\nrows = 5\ncols = 5\nlength = 8\n</code></pre>\n\n<p>and then <code>findFinalPath</code> returned the following path:</p>\n\n<pre><code>...
{ "AcceptedAnswerId": "24197", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T02:00:11.330", "Id": "24136", "Score": "6", "Tags": [ "python", "graph" ], "Title": "My first graph traversal code" }
24136
<p>As a Java programmer, I'm new to the OOP-Approach of JavaScript and it's hard for me to find the best way to write code based on objects. I read a lot <a href="https://developer.mozilla.org/en-US/docs/JavaScript" rel="nofollow">MDN</a> and across the web to find a good way to code with JavaScript.</p> <p>Just to se...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T15:09:13.133", "Id": "37252", "Score": "0", "body": "I realize your program is in vanilla JS but if you check out the following video on handling events in jQuery, it just might provide some clarity on the JS subject. You should che...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li><p>Not sure if this occurred during the copy pasting of your code, but the indentation is bad, for example this:</p>\n\n<pre><code>//another kind of how to set up a class-method\nVideo.prototype.setControls = function() {\n\nvar playPauseBtn = new VideoControl(\"...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T07:13:55.517", "Id": "24142", "Score": "1", "Tags": [ "javascript" ], "Title": "Adding loop capability to video-element" }
24142
<p>I have a pipeline with loops of filters and one input filter. The rest are splitters, transform and output.</p> <p>I would like my code to go over the filters and push them into a queue (order is important). However, if I have a loop, I only want to count the end of the loop once.</p> <p>Here is my working code....
[]
[ { "body": "<p>As far as I can tell, this code seems pretty easy to follow, especially with the comments. Here are several things that stood out to me:</p>\n\n<ul>\n<li><p>Since you haven't provided your own <code>queue</code> implementation, I assume you're using <code>std::queue</code>. If so, remove <a href...
{ "AcceptedAnswerId": "40237", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T09:34:04.443", "Id": "24144", "Score": "6", "Tags": [ "c++", "queue", "breadth-first-search" ], "Title": "BFS for creating a queue without repetitions and with loops in the gra...
24144
<p>In graph theory, <a href="http://en.wikipedia.org/wiki/Breadth-first_search" rel="nofollow">breadth-first search</a> (BFS) is a graph search algorithm that begins at the root node and explores all the neighboring nodes. Then for each of those nearest nodes, it explores their unexplored neighbor nodes, and so on, unt...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T10:49:44.787", "Id": "24151", "Score": "0", "Tags": null, "Title": null }
24151
In graph theory, breadth-first search (BFS) is a graph search algorithm that begins at the root node and explores all the neighboring nodes. Then for each of those nearest nodes, it explores their unexplored neighbor nodes, and so on, until it finds the goal.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T10:49:44.787", "Id": "24152", "Score": "0", "Tags": null, "Title": null }
24152
<p>I need to map from one enum type to another. Here is the enum I am given:</p> <pre><code>enum CfgFruitType { CFGNoFruit, CFGApple, CFGApricot, CFGBanana, CFGMango, CFGKiwi, CFGFig, CFGGrape, CFGMelon, CFGLemon, CFGNectarine, CFGPineapple, CFGWatermelon, CFGCherry, CFGPear, CFGStrawberry }; </code></pre> ...
[]
[ { "body": "<p>If I were you I'd write a function to convert from one to the other which would perform a switch on your input.</p>\n\n<p>My motivation to do so would be to :</p>\n\n<ul>\n<li>have warnings/errors whenever a case is not handled. If you do so and you update the enum, you can't forget to update your...
{ "AcceptedAnswerId": "24199", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T11:17:39.280", "Id": "24154", "Score": "11", "Tags": [ "c++", "enum", "hash-map" ], "Title": "Mapping enum to enum" }
24154
<p>How can I simplify this .less code to require less repetition (i.e., so that I can have many buttons with normal, rollover, and pressed states without using 3 lines for each button):</p> <pre><code>.SBtnM(@urlprefix, @width, @height, @urlsuffix) { width: @width; height: @height; background-i...
[]
[ { "body": "<p>I don't see anything wrong with what you are doing but. it can be written shorter just as you asked.</p>\n\n<pre><code>.SBtnM(@selector, @urlprefix, @width, @height)\n{\n .@{selector}\n { \n .toolbarbutton &gt; &amp;\n {\n @url: %(\"%s_normal.png\", @urlprefix);\n ...
{ "AcceptedAnswerId": "35746", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T13:29:56.627", "Id": "24157", "Score": "5", "Tags": [ "css", "less-css" ], "Title": "How can I reduce this .less call to one line per image" }
24157
<p>Can I combine this two classes and have one fake db class?</p> <pre><code>public class FakeDb : Dictionary&lt;string, List&lt;string&gt;&gt; { public const string Table1 = "Table1"; public void AddToTable(string tableName, string line) { if(!ContainsKey(tableName)) Add(tableName, ne...
[]
[ { "body": "<p>Why not use generics:</p>\n\n<pre><code>public class FakeDb&lt;TList&gt; : Dictionary&lt;string, List&lt;TList&gt;&gt;\n{\n public const string Table1 = \"Table1\";\n\n public void AddToTable(string tableName, TList line)\n {\n if (!ContainsKey(tableName))\n {\n A...
{ "AcceptedAnswerId": "24162", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T13:49:04.810", "Id": "24158", "Score": "1", "Tags": [ "c#" ], "Title": "Eliminate duplication in similar fake data access classes" }
24158
<p>I wrote a Python program that performs an integration of data using Simpson's rule. The program takes the areas to be integrated from a foo.ref file, with the following syntax:</p> <blockquote> <pre><code># peak m/z charge window LAG_H4N4F1S1 4244.829467 1+ 0.06 LAG_H4N4F1S1 424...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T08:14:46.913", "Id": "37304", "Score": "1", "body": "Use NumPy and SciPy for numerical tasks. [scipy.integrate.simps](http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.simps.html)" } ]
[ { "body": "<pre><code>#! /usr/bin/env python\nimport glob\nimport os\nimport fileinput\nprint \"&lt;SimpInt.py&gt; a script to quickly calculate the area for a set\"\nprint \"of analytes. Written by Bas Jansen, Leiden University Medical\"\nprint \"Center, March 20th 2013.\"\nprint \"\"\n\n# Simpson's rule\ndef ...
{ "AcceptedAnswerId": "24163", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T15:06:06.377", "Id": "24160", "Score": "4", "Tags": [ "python", "performance", "mathematics", "csv", "floating-point" ], "Title": "Integration of data using Simpson's r...
24160
<p>How many tests could you write for the enum class below. I am looking for the following output given the following command:</p> <pre><code>java fileName HORIZON_BOX, HORIZON_BOX_WITH_CC, HORIZON_BOX_WITH_CC 1 HORIZON_BOX: 20.00 2 HORIZON_BOX_WITH_CC @ 30.00 : 60.00 GRAND TOTAL : 80.00 </code></pre> <p>What is the...
[]
[ { "body": "<p><code>Product.getPrice</code> is too trivial to warrant a test on its own, and testing the price of each product alone only tests your typing ability. If the test passes, it only means you typed the same price in the code and the test; it doesn't prove that the price is correct since you could hav...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T15:22:36.807", "Id": "24161", "Score": "2", "Tags": [ "java", "tdd" ], "Title": "TDD Approach and Simple Solution" }
24161
<p>I have a model class <code>Product</code> that gets populated from a service DTO object (using AutoMapper). The service is used to power many different applications and for each one the Product Model might need to behave a bit differently. After a bit of research I decided the <a href="http://www.dofactory.com/Pat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T17:48:32.497", "Id": "37262", "Score": "2", "body": "This doesn't look right; you're creating an abstract class which cannot be instantiated, and inheriting from a class that can. In addition, when I think of \"decoration,\" I thin...
[ { "body": "<p>I think you've misunderstood what decorator pattern is. As described in <a href=\"http://en.wikipedia.org/wiki/Decorator_pattern\" rel=\"nofollow\">Wikipedia</a></p>\n\n<p>\"In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T17:45:42.590", "Id": "24165", "Score": "2", "Tags": [ "c#", "design-patterns" ], "Title": "Is this correct usage of the \"Decorator\" Pattern?" }
24165
<p>I'm writing a pong game in Python and I created classes for the game objects. </p> <p>The top level class is <code>Object</code>, and <code>Ball</code> and <code>Paddle</code> inherit from it. And <code>ComputerPaddle</code> is a child class of <code>Paddle</code>. </p> <pre><code># classes.py # 3/19/2013 import ...
[]
[ { "body": "<p>Instead of using 4 different fields to keep track of your object's position and size, I suggest you just use a <a href=\"http://www.pygame.org/docs/ref/rect.html\"><code>Rect</code></a>:</p>\n\n<pre><code>def __init__(self, x, y, w, h, color):\n self.rect = Rect(x, y, w, h)\n self.vx...
{ "AcceptedAnswerId": "24189", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T18:08:20.880", "Id": "24167", "Score": "3", "Tags": [ "python", "object-oriented", "classes", "helper", "pygame" ], "Title": "Pong game in Python" }
24167
<p>I need a function to get the value of the name attribute of each element with class="class". I was wondering what is the best way to do this, performance-wise.</p> <p>Currently I'm using jQuery and doing it like this:</p> <pre><code>$("#Button").click(function() { var myElements = $(".class"); for (var i=0...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T03:52:12.053", "Id": "37332", "Score": "3", "body": "Please, always replace alert by console.log\nAlert is blocking code execution and forces you to click ok or press enter as many times as a result is found." } ]
[ { "body": "<p>To do this is in 'pure' JavaScript, you do something like this, if using ES6 syntax:</p>\n\n<pre><code>var elements = document.getElementsByClassName('class');\nelements.forEach(e =&gt; { alert(e.name) });\n</code></pre>\n\n<p>For any browsers not supporting ES6 (including all versions of IE):</p>...
{ "AcceptedAnswerId": "24190", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T21:32:12.717", "Id": "24172", "Score": "9", "Tags": [ "javascript", "jquery", "html", "dom" ], "Title": "Get the value of the name attribute of each element with class=\"cl...
24172
<p>I have began doing the problems found on Project Euler and have just solved problem 3. However, I feel as if my code is very long and too brute-force. I was hoping somebody could give it a look and give me some guidelines for this problem and for future programming in general. This would help me with cleaning it up...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T01:08:51.577", "Id": "37511", "Score": "0", "body": "If you are trying to find all primes in a given range, take a look at the sieve of Eratosthenes. It is the easiest and probably fastest way for integer/long. Rest is already answe...
[ { "body": "<p>If I may give you one <strong>tip</strong> right away: try to write out the variable names and don't use abbreviations. If <code>primeFactorCounter</code> seems too long to you, just say <code>counter</code>. Right now your code is short and you know what <code>pfCounter</code>means, but it is jus...
{ "AcceptedAnswerId": "24183", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-20T23:06:20.050", "Id": "24178", "Score": "2", "Tags": [ "java", "project-euler", "primes" ], "Title": "Project Euler Problem #3 - largest prime factor" }
24178
<h1>Background</h1> <p>The following code (part of a natural language processor) was written to eliminate duplicate code by using <code>isLeft</code> as a conditional throughout the method:</p> <pre><code>private void doInsideChartBinaryRules( boolean isLeft, int state, int start, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T00:14:09.880", "Id": "37508", "Score": "0", "body": "Even if it is already answered, I suggest to think about using objects and/or split the logic in several functions. Such a number of arguments is a good indicator to introduce an ...
[ { "body": "<p>The first thing checked was where and how <code>isLeft</code> is used by removing code repetition around it:</p>\n\n<pre><code> float rS = ( isLeft ) ?\n iScore[ split ][ end ][ rightChild ] :\n iScore[ split ][ end ][ state ];\n</code></pre>\n\n<p>became </p>\n\n<pre><code> float ...
{ "AcceptedAnswerId": "24185", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T01:48:18.407", "Id": "24181", "Score": "1", "Tags": [ "java", "optimization", "performance" ], "Title": "Optimization: Eliminate conditional expression within common code" }
24181
<p>Part 1 of 4 is complete.</p> <p>I would like to know if what I have done could be improved. Please don't worry about output - that is a work in progress.</p> <pre><code>#define _CRT_SECURE_NO_WARNINGS #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;ctype.h&gt; #include &l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T09:56:10.163", "Id": "37605", "Score": "0", "body": "In addition to what has already been said, you need to split your \"monster-main\" into several smaller functions." } ]
[ { "body": "<p>Nothing super huge, but here's a brain dump:</p>\n\n<ul>\n<li>typedef the accounts struct so you don't have to include <code>struct</code> each time</li>\n<li>you have a lot of debugging type code that shouldn't be in a final program (for example, dumping back out the passed arguments)\n<ul>\n<li>...
{ "AcceptedAnswerId": "24194", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T03:09:33.163", "Id": "24182", "Score": "2", "Tags": [ "c" ], "Title": "Managing a user account" }
24182
<p>I am just learning how to do some multiprocessing with Python, and I would like to create a non-blocking chat application that can add/retrieve messages to/from a database. This is my somewhat primitive attempt (note: It is simplified for the purposes of this post); however, I would like to know how close/far off of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T14:43:34.277", "Id": "37333", "Score": "0", "body": "That's quite odd that it works fine when I run it...I will look further into this. But, thank you for the feedback." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<ul>\n<li>Don't create a new process for every task. Put a loop in <code>add_messages</code>; <code>q.get</code> will wait for the next task in the queue.</li>\n<li><code>receive_new_message</code> is not doing anything useful in your example. Place <code>q.put(new_message)</code> right after <code>r...
{ "AcceptedAnswerId": "24213", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T06:56:02.460", "Id": "24187", "Score": "4", "Tags": [ "python" ], "Title": "Python multiprocessing messaging code" }
24187
<p>Pygame is free Python library released under the GPL License aimed at creating video games. It's build on top of <a href="/questions/tagged/sdl" class="post-tag" title="show questions tagged 'sdl'" rel="tag">sdl</a>, it's actively developed and hosted at <a href="https://bitbucket.org/pygame/pygame" rel="nofollow">B...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T08:26:24.240", "Id": "24191", "Score": "0", "Tags": null, "Title": null }
24191
Pygame is a portable Python package for video games, built on SDL.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T08:26:24.240", "Id": "24192", "Score": "0", "Tags": null, "Title": null }
24192
<p>I'm trying to write efficient code for calculating the chain-length of each number.</p> <p>For example, <code>13 -&gt; 40 -&gt; 20 -&gt; 10 -&gt; 5 -&gt; 16 -&gt; 8 -&gt; 4 -&gt; 2 -&gt; 1</code>. It took 13 iterations to get 13 down to 1, so <code>collatz(13)</code> = <code>10</code>.</p> <p>Here is my implementa...
[]
[ { "body": "<p>Using the Python call stack to remember your state is very convenient and often results in shorter code, but it has a disadvantage:</p>\n\n<pre><code>&gt;&gt;&gt; collatz(5**38)\nTraceback (most recent call last):\n File \"&lt;stdin&gt;\", line 1, in &lt;module&gt;\n File \"cr24195.py\", line 3,...
{ "AcceptedAnswerId": "24198", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T09:14:06.903", "Id": "24195", "Score": "5", "Tags": [ "python", "optimization", "algorithm", "recursion", "memoization" ], "Title": "Iterative Collatz with memoization"...
24195
<p>I've created a CSV parser that tries to build a string table out of a CSV file. The goal is to handle CSV files as well as Excel.</p> <h2>Input CSV file:</h2> <blockquote> <pre class="lang-none prettyprint-override"><code>First field of first row,"This field is multiline but that's OK because it's enclosed in d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T12:16:00.893", "Id": "37315", "Score": "0", "body": "Why did it add a `\"` after *quote*?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T13:54:48.627", "Id": "37324", "Score": "0", "body"...
[ { "body": "<ul>\n<li><p>I'm not sure it's best to return <code>0</code> from <code>nextCsvField()</code>. Since the function is to return a pointer, consider returning <code>NULL</code> (or <code>nullptr</code> if you have C++11). This function also shouldn't return a <code>const</code> pointer if the return ...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T10:07:52.273", "Id": "24196", "Score": "6", "Tags": [ "c++", "parsing", "csv", "excel" ], "Title": "Correctly import CSV data, even when possibly malformed" }
24196
<p>Given a linked list, remove the nth node from the end of list and return its head.</p> <p>For example,</p> <blockquote> <p>Given linked list: 1->2->3->4->5, and n = 2.</p> <p>After removing the second node from the end, the linked list becomes 1->2->3->5.</p> <pre><code>ListNode *removeNthFromEnd(ListNod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-17T03:16:24.553", "Id": "57564", "Score": "4", "body": "This question appears to be off-topic because it is not clear whether it's asking for code to be written; also the code being embedded in a block quote makes it looks like it's no...
[ { "body": "<p>Your function fails if <code>n</code> is 0 or greater than the list size.</p>\n\n<p>Also, I prefer to see one variable defined per-line:</p>\n\n<pre><code>ListNode *pre = head;\nListNode *cur = head;\n</code></pre>\n\n<p>And the opening brace belongs in column 0 (I guess you don't agree, but there...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T13:36:30.627", "Id": "24201", "Score": "1", "Tags": [ "c++", "interview-questions", "linked-list" ], "Title": "Remove Nth Node From End of List" }
24201
<p>In my VBA code, I am trying to generate a specific list of cell row positions.</p> <p>Basically, I first fill a collection with the entire list of row positions pertaining to a specific column:</p> <pre><code>Dim arrPos As New Collection .... For i = 3 To bottomRow arrPos.Add i Next i </code></pre> <p>Then I try ...
[]
[ { "body": "<p>Doesn't MATCH return NA when there's not match? If that's the way you have it set up and you want the rows where there are errors, then it seems like you could simplify it by just checking for errors and putting them into a 'no good' array.</p>\n\n<pre><code>Sub FilterMatch()\n\n Dim vaMatch As...
{ "AcceptedAnswerId": "24347", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T14:29:23.723", "Id": "24202", "Score": "5", "Tags": [ "vba", "excel" ], "Title": "Removing from a collection in Excel VBA" }
24202
<p>I'm working on my first large CodeIgniter project (and one of my first MVC projects), and I want to get some feedback on the techniques I've used so far in one of my models:</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Model_programs extends SOA_Model{ func...
[]
[ { "body": "<p>Is there any specific reason that you don't use Active Record?</p>\n\n<p>For example:</p>\n\n<pre><code>$sth = $this-&gt;dbh-&gt;prepare(\"SELECT programs.id, programs.name\n FROM programs\n INNER JOIN program_users\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T15:21:07.237", "Id": "24205", "Score": "0", "Tags": [ "php", "mvc", "codeigniter" ], "Title": "CodeIgniter model" }
24205
<h3>Some background</h3> <p>This functions does some business logic before submitting a "add to cart" form</p> <h2>HTML</h2> <pre><code>&lt;form class="atcLoginRequired" method="get" action="/somePage"&gt; &lt;input type="hidden" value="someVal" name="nextpage"&gt; &lt;input name="ISODSCTX66WA_qty" type="tex...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T18:02:17.367", "Id": "37490", "Score": "0", "body": "We prefix jQuery objects with `$`, for example, `$form` and `$input`." } ]
[ { "body": "<p><strong>Simple answer:</strong></p>\n\n<pre><code>var jThat = $(this).remove();\nreturn jThat.attr(\"name\") + \"=\" + jThat.val() + \"&amp;\"; \n</code></pre>\n\n<p>There's nothing wrong with calling <code>.remove()</code> right away; the element's still in memory so its attributes be still be ac...
{ "AcceptedAnswerId": "24214", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T15:31:57.460", "Id": "24206", "Score": "1", "Tags": [ "javascript", "jquery", "html", "validation" ], "Title": "Refactor function that returns a comma Operator to pass jsHi...
24206
<p>I'm new to jQuery and I've been messing about with this code, It works but I want to learn how to shorten the code by the eliminating unnecessary repeated code.</p> <p>Here is a link to <a href="http://jsfiddle.net/eSZFD/168/" rel="nofollow noreferrer">JSFiddle</a></p> <h1>HTML</h1> <pre><code>&lt;div id=&quot;div1&...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T17:06:24.803", "Id": "37339", "Score": "4", "body": "Hi and welcome to Code Review. Please post your code in the question as well. Also make sure to check this out: http://codereview.stackexchange.com/faq" }, { "ContentLicen...
[ { "body": "<p>Your newer code is much much better than the previous attempt. Some little fixes that I'd suggest are:</p>\n\n<ol>\n<li><p>Don't use the following</p>\n\n<pre><code>$('div[id^=div]').slideUp().delay(1000);\n</code></pre>\n\n<p>as it hides the <code>close</code> button inside the div. So, if I open...
{ "AcceptedAnswerId": "24229", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T15:46:38.437", "Id": "24207", "Score": "4", "Tags": [ "javascript", "jquery", "html", "animation" ], "Title": "Simple element slider animation tool" }
24207
<blockquote> <p>Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.</p> <p>The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.</p> </blockquote> <p>The following is my code, which has al...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T18:45:18.897", "Id": "37348", "Score": "2", "body": "Instead of a stack you could use recursion." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T18:53:30.663", "Id": "37376", "Score": "0", ...
[ { "body": "<p>You use of objects without prefix them with <code>std::</code> is a bad sign.<br>\nI bet you used <code>using namespace std;</code> in the code. Please stop this habit.<br>\n<a href=\"https://stackoverflow.com/q/1452721/14065\">https://stackoverflow.com/q/1452721/14065</a></p>\n\n<p>When passing o...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T16:18:23.887", "Id": "24208", "Score": "6", "Tags": [ "c++", "interview-questions", "stack" ], "Title": "Valid Parentheses" }
24208
<p>First, I want to say that this code works, but I want to make sure this is the right way of doing it. I am writing this for a SMS text API that loops through each phone number. I sometimes gets hung up on 1 number or just takes time. It roughly takes 6-8 sec per number. So I thought I would write something that woul...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T22:08:24.433", "Id": "37375", "Score": "0", "body": "Which .NET version are you using? Can you show the SMS API (ideal solution should use asynchronous calls to SMS API)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationD...
[ { "body": "<pre><code>static public BlockingCollection&lt;int&gt; Queue\nstatic public BlockingCollection&lt;int&gt; Finished\nstatic public BlockingCollection&lt;Thread&gt; Threads\nstatic public int QUCount\nstatic public int THCount\nstatic public int FNCount\n</code></pre>\n\n<p>There is no need to make any...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T19:34:58.997", "Id": "24211", "Score": "1", "Tags": [ "c#", "multithreading", ".net", "mobile" ], "Title": "Creating dynamic threads for a SMS text API" }
24211
<p>The code allows you to select an area from the left column and another area from the right column followed by clicking on the Choose button which sends the chosen areas to the server:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;style&gt; body { overflow: hidden; } article.left { over...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T19:59:30.610", "Id": "37361", "Score": "1", "body": "Why is your JavaScript, CSS and HTML all on the same file? Other than that, cache selector. I wouldn't use ember or angular for this sort of code since it is _very_ small compared...
[ { "body": "<p>This bit needs refactoring. If you are writing a one time script or throw away code ,and you are absolutely certain it won't be more than throw away code, you needn't worry about refactoring.</p>\n\n<p>But since this is a part of a large application everything needs a name indicating what it is or...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T19:55:56.323", "Id": "24212", "Score": "6", "Tags": [ "javascript", "jquery", "html" ], "Title": "Is this spaghetti javascript code? How can it be refactored with a javascript lib...
24212
<p>I discovered that the existing menu in a web app I'm working on has an issue in Chrome, where the "Logged in as" section would jump off the menu bar down below. After looking through the code, I'm trying to rewrite it a bit so that it works more consistently.</p> <pre class="lang-html prettyprint-override"><code>...
[]
[ { "body": "<p>You've done a pretty good job but there is still a lot of room for improvement. Some notes:</p>\n\n<ul>\n<li>It doesn't really make sense to use <code>&lt;ul&gt;</code> and <code>&lt;li&gt;</code> for the logo, menu and logged in text. Ideally they should each be in <code>&lt;div&gt;</code>s so th...
{ "AcceptedAnswerId": "24270", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T21:03:39.357", "Id": "24215", "Score": "1", "Tags": [ "html", "asp.net", "css" ], "Title": "Changing master page's menu" }
24215
<p>I had an assignment some weeks ago that consisted of making a simple McCulloch-Pitts neural network. I ended up coding it in a pretty OO style (or the OO style I've been taught), and I felt that my implementation might have been a bit excessive for being a one-off assignment: could this perhaps been implemented in a...
[]
[ { "body": "<p>Since you didn't post the code of <code>Neuron</code>, <code>InputNeuron</code> and <code>OutputNeuron</code> so I just give some comments on the style.</p>\n\n<h3>Instance variables</h3>\n\n<pre><code>private HashMap&lt;String,InputNeuron&gt; inputNeurons;\nprivate LinkedList&lt;Neuron&gt; intern...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T21:50:59.650", "Id": "24218", "Score": "5", "Tags": [ "java", "machine-learning", "neural-network" ], "Title": "Simple Neural Network in Java" }
24218
<p>I just failed in a JavaScript test and I would really appreciate some comments of how I can improve so I can keep learning.</p> <p>The test was about making a form interactive, where the code should do things like changing to the next tab while showing not visible content, validate email, etc.</p> <p>I have receiv...
[]
[ { "body": "<p><strong>[-] caching (no jquery selector is cached)----</strong><br>\n<strong>Your code</strong>:</p>\n\n<pre><code>$(\"#step\" + stepNumber + \"_tab\").addClass(\"on\");\n$(\"#step\" + stepNumber + \"_tab\").click(function() { ...\n</code></pre>\n\n<p><strong>Revised</strong>:</p>\n\n<pre><code>va...
{ "AcceptedAnswerId": "24240", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T23:33:49.963", "Id": "24223", "Score": "0", "Tags": [ "javascript", "performance", "jquery", "form" ], "Title": "Support for an interactive form with multiple tabs" }
24223
<p>I'm sure code indentation is a basic requirement for correct development. I have checked out may pages to learn more and results of my coding are below.</p> <p>I like to share that here to receive opinions and suggestions.</p> <pre><code>&lt;?php include_once "../../config.php"; // Start if (!isset($_SESSION)) se...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T02:05:32.843", "Id": "37385", "Score": "0", "body": "There is no One True Coding Style. Decide on something and, most importantly, stick to it. (So far, everything look sensible, but I prefer to align the `=` of related assignments)...
[ { "body": "<p>You don't need to indent your <code>$ser_</code> value assignments. Indentation should be left for within a class, method, loop, etc as you do for most of your other code. I notice that you separate your MySQL statement, which can be done, but on such a simple query, really isn't needed as the o...
{ "AcceptedAnswerId": "24228", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T01:39:11.820", "Id": "24227", "Score": "1", "Tags": [ "php", "optimization" ], "Title": "Better code indentation" }
24227
<p>I needed to get the minimum and maximum date values from a query using the Sequel ORM in Ruby from my database. Sequel has a <code>range</code> method that returns a Range value. I'm having it return values from a timestamp field, so they're coming back as a range of Time objects.</p> <p>In order to split it into t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T05:07:41.263", "Id": "37431", "Score": "1", "body": "`template_min_datestamp, template_max_datestamp = [t1..t2].map{ |r| [r.min, r.max] }[0]` this works, but I'm not sure if it is what you want." }, { "ContentLicense": "CC B...
[ { "body": "<p>If I understood your question correctly, you need a <code>let</code>-abstraction, for example <a href=\"https://stackoverflow.com/questions/12848967/\">Object#as</a> (or whatever name you like for it, it seems to have dozens). I'd write:</p>\n\n<pre><code># this goes in your core_ext module.\nclas...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T02:30:37.333", "Id": "24231", "Score": "1", "Tags": [ "ruby" ], "Title": "Splitting a range into min and max?" }
24231
<p><a href="http://pastebin.com/wMK0USKx" rel="nofollow">Here's a simple Python Flask app</a>. It uses the Wikidot API to transfer pages between two wikis. I'd like to hear your input on the best way to refactor this code. Here are a couple of questions I have in addition to any criticisms you may have:</p> <p><cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-04-22T01:50:38.707", "Id": "39234", "Score": "0", "body": "Under what kinds of circumstances will these errors happen?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-04-22T06:50:38.343", "Id": "39244", "...
[ { "body": "<p>The only one thing which looks dangerous<br>\nWith this:</p>\n\n<pre>\nexcept:\n</pre>\n\n<p>This means you will handle all the exceptions. That is wrong.<br>\nYou are supposed to handle only those exceptions which you expect.</p>\n\n<pre>\nexcept MyExpectedException, OtherExpectedException:\n</pr...
{ "AcceptedAnswerId": "25336", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T09:55:36.937", "Id": "24241", "Score": "2", "Tags": [ "python", "flask" ], "Title": "Simple Python Flash app using Wikidot API to transfer pages between two wikis" }
24241
<p>I am currently trying to teach myself some programming. I have started to work with Python by doing <a href="https://www.hackerrank.com/challenges/string-similarity" rel="nofollow">this challenge</a>.</p> <p>For each test case, I need to find the sum of the self-similarities of a string with each of its suffixes. ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T15:05:08.987", "Id": "49229", "Score": "2", "body": "Try studying z-algorithm. This question is a very very simple modification of the z-array you get as part of the z-algorithm. See this <http://codeforces.com/blog/entry/3107> for ...
[ { "body": "<p>It is slow because you use slow algorithm (\"too many loops\"). This problem might be a bit hard for beginner. If you want to solve it anyway, be sure to search for tutorials on string algorithms (try to look at <a href=\"http://en.wikipedia.org/wiki/Aho-Corasick\" rel=\"nofollow\">http://en.wikip...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T11:33:51.017", "Id": "24246", "Score": "6", "Tags": [ "python", "algorithm", "strings", "time-limit-exceeded" ], "Title": "Hackers Ranking String Similarity" }
24246
<p>As a free-time activity in order to learn some Lisp I had to implement depth first directed graph search. Due to large graph size (800K nodes, 5M arcs) recursion-based approach I could devise didn't work. </p> <p>Below is my stack-based implementation that I would like to improve in terms of readability if nothing ...
[]
[ { "body": "<p>If-else functionality is build-it into <code>loop</code> (no way). </p>\n\n<p>This fragment inside the loop can be rewritten:</p>\n\n<pre><code>do (if fresh-tails \n (progn\n (mapcar #'mark-seen fresh-tails)\n (setq stack (append fresh-tails stack)))\n (progn\n (pop stack...
{ "AcceptedAnswerId": "24333", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T11:39:41.110", "Id": "24247", "Score": "1", "Tags": [ "lisp", "common-lisp", "graph" ], "Title": "Improving readability of non-recursive depth first search function in Lisp" }
24247
<p>Is this a good approach for a BayeuxClient class?</p> <p>Reading cometd reference book, Chapter 6 Java Libraries, I created this BayeuxClient class.</p> <p>As a newbie to cometd, I would like to know if this class has any flaws:</p> <pre><code>import java.util.*; import java.net.URL; import org.cometd.client.Baye...
[]
[ { "body": "<ol>\n<li><p>I have no idea how to type the last character on my keyboard which makes modification harder:</p>\n\n<blockquote>\n<pre><code>public boolean GetIfHandIsShaken£()\n</code></pre>\n</blockquote>\n\n<p>It's better to use only ASCII letters.</p></li>\n<li><p>See <em>Effective Java, 2nd editio...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T12:52:53.870", "Id": "24248", "Score": "1", "Tags": [ "java", "design-patterns" ], "Title": "Is this a good approach for a BayeuxClient class?" }
24248
<p>I've recently re-written a Python script I use to run a couple of lightweight blogs. Looking over the horrible code I'd written before, I decided to rewrite it using object-oriented concepts. I wanted to submit it to get feedback, best practices, and other areas I should look at. This is my first script that uses an...
[]
[ { "body": "<p>Overall your design looks good to me. A couple of relatively minor things to note: </p>\n\n<p><strong>Use new-style classes</strong><br>\nIn Python 2.x you should make sure your classes inherit from <code>object</code>. Such classes are known as new-style classes. (In Python 3.x all classes are n...
{ "AcceptedAnswerId": "24261", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T13:23:49.300", "Id": "24250", "Score": "3", "Tags": [ "python", "object-oriented" ], "Title": "Small blogging script" }
24250
<p>I'm a PHP novice and so looking for some advice on a PHP function I have created to use within a WordPress installation.</p> <p>As you can see from the code below, it runs when one of the admin's press 'Publish' on a pending post.</p> <p>It takes a Zip file that has been uploaded by a user via Gravity Forms, then ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T14:14:46.733", "Id": "37400", "Score": "1", "body": "If you're going to delete files from the original zip file that are not mp3s, why bother to create a new one? You already have the one you want after the first loop." }, { ...
[ { "body": "<p>I'm not going to touch on how to improve the speed of the zip operation because it's always going to be a bottleneck no matter how much optimization you do. Instead you should focus on how to improve the experience for the end user so that they don't have to wait for the operation to complete. The...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-22T14:01:14.857", "Id": "24251", "Score": "4", "Tags": [ "php", "optimization", "beginner" ], "Title": "Unzip and move function" }
24251
<p>I wrote a simple Python snake game which is about 250 lines of code. Can someone give me some advice on how I can refactor/make it better?</p> <p><strong>game.py</strong></p> <pre><code># game.py - 3/22/2013 import pygame, sys, os from pygame.locals import * from classes import * def main(): pygame.init() ...
[]
[ { "body": "<h3>1. Introduction</h3>\n\n<p>This is not bad overall, considering that this is your first program written with PyGame. I've made many comments below, but don't take the length of this answer to heart: there are always many things to say about a piece of code of this length.</p>\n\n<h3>2. Game desig...
{ "AcceptedAnswerId": "24282", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T01:26:43.553", "Id": "24267", "Score": "26", "Tags": [ "python", "array", "pygame", "snake-game" ], "Title": "Snake game using PyGame" }
24267
<p>I'm making a GUI system in Python for game development with PyGame. Right now I have a button that changes colors when you hover and click on it. My question is, is this code well designed or can it be improved?</p> <p><strong>game.py</strong></p> <pre><code>import sys, pygame from pygame.locals import * from gui ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T22:30:07.090", "Id": "37456", "Score": "0", "body": "The comment \"TODO: update and draw\" suggests that this code might not be ready for review yet. It's best for you to fix all the problems you know about before submitting it for ...
[ { "body": "<ol>\n<li><p>There are no docstrings. What is the purpose of each of your classes and methods, and how am I supposed to call them?</p></li>\n<li><p>If you click outside the button, and then slide the pointer over the button, it becomes active. Normal GUI buttons require the initial click to be <em>on...
{ "AcceptedAnswerId": "24304", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T01:32:25.240", "Id": "24268", "Score": "4", "Tags": [ "python", "gui", "pygame" ], "Title": "GUI system in PyGame" }
24268
<pre><code>function dep_tree(graph,node,prev_deps){ return uniq(flatten(graph[node].map(function(child_node){ if (contains(prev_deps,child_node)) throw "Circular reference between "+child_node+" and "+node; return dep_tree(graph,child_node,prev_deps ? prev_deps.concat(node) : [node]) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T08:43:15.297", "Id": "37433", "Score": "1", "body": "`uniq`, `flatten` are imported from `underscore.js`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T08:51:52.310", "Id": "37436", "Score":...
[ { "body": "<p>Not a lot of code to review,</p>\n\n<ul>\n<li>To reduce confusion, I would use <code>_.uniq()</code> rather than point straight to <code>uniq()</code></li>\n<li>lowerCamelCase is preferred, <code>child_node</code> -> <code>childNode</code></li>\n<li><code>dep_tree</code> is unfortunate, I like <co...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T07:52:40.260", "Id": "24273", "Score": "2", "Tags": [ "javascript", "algorithm", "functional-programming", "graph" ], "Title": "Is this code for getting the dependency tree of...
24273
<p>I've written a circular buffer with multithreaded write and single read ability:</p> <pre><code>public class RingBuffer&lt;E&gt; extends AbstractList&lt;E&gt; implements RandomAccess { class Pointer { int p = 0; public int getPointer(){ return this.p; } public void...
[]
[ { "body": "<p>I highly recommend <a href=\"http://rads.stackoverflow.com/amzn/click/0321349601\" rel=\"nofollow\"><em>Java Concurrency in Practice</em></a> by Brian Goetz et al. This will give you a solid foundation for building multi-threaded Java applications.</p>\n\n<p>The biggest problem with <code>RingBuff...
{ "AcceptedAnswerId": "24314", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T09:06:52.367", "Id": "24275", "Score": "7", "Tags": [ "java", "multithreading", "circular-list" ], "Title": "Multi threaded circular buffer" }
24275
<p>I read about how markov-chains were handy at creating text-generators and wanted to give it a try in python. </p> <p>I'm not sure if this is the proper way to make a markov-chain. I've left comments in the code. Any feedback would be appreciated.</p> <pre><code>import random def Markov(text_file): with op...
[]
[ { "body": "<pre><code>import random\n\ndef Markov(text_file):\n</code></pre>\n\n<p>Python convention is to name function lowercase_with_underscores. I'd also probably have this function take a string as input rather then a filename. That way this function doesn't make assumptions about where the data is coming ...
{ "AcceptedAnswerId": "24284", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T11:57:42.617", "Id": "24276", "Score": "11", "Tags": [ "python", "algorithm", "markov-chain" ], "Title": "Implementation of a Markov Chain" }
24276
<p>This is a simple attempt by me to test whether two words are anagrams or not:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;ctype.h&gt; #define CH_LEN 15 #define N 26 int main(void) { char track_letters[N] = {0}; char first_word[CH_LEN]; char sec_word[CH_LEN]; printf("Enter first word: "); ...
[]
[ { "body": "<p>You limit yourself to anagrams of 15 letters.</p>\n\n<pre><code>#define CH_LEN 15\nchar first_word[CH_LEN];\nchar sec_word[CH_LEN];\n</code></pre>\n\n<p>But you don't actually use words after they are input.<br>\nYou can fix the limitation (and a potentially serious bug) by not using the concept o...
{ "AcceptedAnswerId": "24281", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T13:35:48.560", "Id": "24278", "Score": "1", "Tags": [ "c", "strings" ], "Title": "Comparing two anagrams in C" }
24278
<p>I am working on <a href="http://thehotdeal.net/clients/1/chris/re/phase3/" rel="nofollow">this website</a> currently.</p> <p>If you resize the window to less than 650px then the main menu is replaced by a button which when pressed triggers a left fly-out menu similar to the Facebook uses on the mobile website.</p> ...
[]
[ { "body": "<h2>Notes</h2>\n<p>I gave it a shot, there isn't really much that I felt could be improved upon though. I'm sure performance would be better if you were using CSS3 transitions (the implementation certainly would be nicer &lt;3 CSS3) but I assume you wanted better browser coverage.</p>\n<ul>\n<li><p>I...
{ "AcceptedAnswerId": "24285", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T13:57:35.030", "Id": "24279", "Score": "0", "Tags": [ "javascript", "performance", "jquery", "mobile" ], "Title": "Responsive left fly-out menu" }
24279
<p>I've started with developing BMP format reader in C#. This tool might read all data from binary BMP file and represents all data from it (from the header, the pixel data etc).</p> <p>I have started and have done only first 14 bytes reading (header) and getting the pixel data from 24 bit BMP file. Of course there wo...
[]
[ { "body": "<p>Instead of marking pieces of functionality within your BMPGetHeader() method with regions. I would suggest turning each region into a private method. The code will be much easier to read and refactor once this is done. </p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0",...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T18:15:45.717", "Id": "24286", "Score": "1", "Tags": [ "c#", "image" ], "Title": "BMP file reader" }
24286
<p>After creating a similar program in C++, I've decided to try to write it in x86 assembly language (the type of assembly I was taught in college).</p> <p>I'd like to receive feedback regarding syntax and clarity. The macros used here were provided by my college, so I don't think that's a concern.</p> <pre><code>%i...
[]
[ { "body": "<p>1) In a language like C or C++, you wouldn't do something like this:</p>\n\n<pre><code>foo (1,2);\nx = bar (2.5);\n</code></pre>\n\n<p>It makes it harder to read the code because the function name makes no sense without its parameters. The same is true for assembly. Basically, this...
{ "AcceptedAnswerId": "39654", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-23T19:23:59.387", "Id": "24288", "Score": "18", "Tags": [ "mathematics", "assembly" ], "Title": "GCD/LCM calculator in x86 NASM assembly" }
24288
<p>Here's some code... please, be brutal</p> <pre><code>function twisty (elem, container) { elem = $('.some-elem'); container = $('.container').hide(); var spots = elem.text().replace(' ', '').split(''); for(var i = 0; i &lt; 300; i++) { $('&lt;span/&gt;', { 'class': 'spot '+ i, text...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T03:04:46.083", "Id": "37463", "Score": "0", "body": "Lol, it's changed quite a bit." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T03:06:30.113", "Id": "37464", "Score": "0", "body": "yea...
[ { "body": "<h2>Notes</h2>\n\n<p>I had a go at converting it to native JavaScript, was fun :P Pretty nifty bit of code. Here are my notes:</p>\n\n<ul>\n<li>I pulled <code>Math.ceil(Math.random() * x))</code> out into a function <code>randomInt(x)</code>, I recommend against extending native JavaScript objects. T...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T01:56:09.453", "Id": "24292", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Here is a function I wrote that, with the help of jQuery, will randomize a bunch of propertie...
24292
<p>I have created a jQuery slider for my personal website and I wanted to get some feedback on how it looks and if there are things I can do to make it better.</p> <p>You can see the live demo here: <a href="http://www.nickmeagher.com" rel="nofollow">http://www.nickmeagher.com</a></p> <p>And here is the code:</p> <p...
[]
[ { "body": "<p>Here are some general things you should be doing differently. These suggestions don't change the functionality of your slider, and are suggestions you can apply to your future projects.</p>\n\n<p>First and most important</p>\n\n<pre><code>var wrapper = $('.portfolio-inner-wrapper');\n//As a rule o...
{ "AcceptedAnswerId": "24321", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T01:56:46.837", "Id": "24293", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "A review of my jQuery Slider" }
24293
<p>I believe with everyone's help on Stack Overflow, I got my code safe guarded from SQL injection. I'm trying to confirm that is correct, just in case I misinterpreted the help and advice I received.</p> <pre><code>&lt;?php $username = "xxxx"; $password = "xxxx"; ?&gt; &lt;font size="+3" face="Verdana"&gt;xxxx&lt;/...
[]
[ { "body": "<p>You can use PHP to output the page to your own for <code>action=\"xxxx.php\"</code> in the form tag.</p>\n\n<pre><code>action=\"&lt;?= htmlentities($_SERVER['PHP_SELF']); ?&gt;\"\n</code></pre>\n\n<p>It looks like a lot to type, but it'll help if you might decide to change file name later. Other t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T03:39:07.473", "Id": "24296", "Score": "3", "Tags": [ "php", "mysql", "pdo", "sql-injection" ], "Title": "Confirming safety of SQL injection" }
24296
<p>I need to remove the fractional part of a <code>BigDecimal</code> value when its scale has a value of zero. For example,</p> <pre><code>BigDecimal value = new BigDecimal("12.00").setScale(2, RoundingMode.HALF_UP); </code></pre> <p>It would assign <code>12.00</code>. I want it to assign only <code>12</code> to <cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T17:23:38.370", "Id": "37552", "Score": "0", "body": "Besides the content, a +1 for providing the tests. Makes it much easier to get an understanding of the desired functionality" } ]
[ { "body": "<blockquote>\n <p>Is there a better way to do this?</p>\n</blockquote>\n\n<p>Yes, <code>stripTrailingZeros()</code>.</p>\n\n<p>To check your tests:</p>\n\n<pre><code>public static void main(final String[] args) {\n check(truncate(\"12.000000\"), \"12\");\n check(truncate(\"12.0001\"), \"12\");...
{ "AcceptedAnswerId": "24325", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T07:02:46.900", "Id": "24299", "Score": "3", "Tags": [ "java" ], "Title": "Is this the way of truncating the fractional part of a BigDecimal when its scale is zero in Java?" }
24299
<p>Can you please try my algorithm and give comments or feedback about it?</p> <pre><code>package md52; import java.io.*; //input outputs import static java.lang.Math.*; //for math purposes /** * * JesseePogi */ public class Md52 { public static String input; public static void main(String[] args) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T23:42:51.370", "Id": "37507", "Score": "6", "body": "What is the purpose of this? Should this be an implementation of md5? Or is it something else?" } ]
[ { "body": "<p>One thing is that you should always specify an encoding when calling <code>String.getBytes</code>, since otherwise the result depends too much on the execution environment. I didn't look through the rest of the code, though.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3....
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T07:32:58.203", "Id": "24300", "Score": "4", "Tags": [ "java", "algorithm", "cryptography" ], "Title": "New MD5 algorithm" }
24300
<p>This is my first program written in C++. I chose to make this public in order to receive suggestions on further improvements and to know if I'm using any "forbidden" code.</p> <p>I'm asking because I initially put a lot of <code>goto</code>s in the program, but later found out that using <code>goto</code> was "evi...
[]
[ { "body": "<p>Armond, the main thing you should do is to learn about functions. Putting everything in <code>main</code> is not practicable beyond very small programs. And nested loops are generally a bad idea too. So for example you might extract the content of the first loop into a function and extract the...
{ "AcceptedAnswerId": "24318", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T09:48:31.060", "Id": "24301", "Score": "3", "Tags": [ "c++", "beginner" ], "Title": "\"Favorite food\" program" }
24301
<p>I am making a Python program with what I learned so far where the user enters two IPs that represents the start and end of the range of IPs to be scanned, then saves the wanted IP in a text file.</p> <pre><code> #ip range and scanning import socket import sys ok=[] def ipscan(start2,port): s=socket.socket(soc...
[]
[ { "body": "<p>Your naming convention doesnt aid legability. e.g, rename <code>p</code> to <code>port</code>.</p>\n\n<p>Don't do carte blanche exception handling. Be more specific, e.g.:</p>\n\n<pre><code>try:\n ...\nexcept (ValueError, KeyError)\n ...\n</code></pre>\n\n<p>You are also a miser with your sp...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T10:47:24.030", "Id": "24302", "Score": "2", "Tags": [ "python", "socket" ], "Title": "Port-scanning with two IPs" }
24302
<p>Is it possible to reduce this long nested for loops and if conditions to increase its readability and to optimize it for future reference. </p> <p>While writing code for my scheduling app, I ended up with a method as shown below. Really, I have a data structure like <a href="http://pastie.org/7097616" rel="nofollow...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T11:45:00.153", "Id": "37472", "Score": "0", "body": "o.0 do you really need that many `for` loops?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T12:08:26.843", "Id": "37473", "Score": "0", ...
[ { "body": "<p>This does not reduce nesting per se, but it reduces clutter for all loop variables that are not really used:</p>\n\n<pre><code>public List&lt;LCycle&gt; ToolArrangment(List&lt;LCycle&gt; TimeLineInit)\n{\n for (int i = 0; i &lt; TimeLineInit.Count; i++) //Each LIfeCycles In TimeLine\n {\n ...
{ "AcceptedAnswerId": "24359", "CommentCount": "16", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T10:55:24.270", "Id": "24303", "Score": "3", "Tags": [ "c#", "design-patterns" ], "Title": "Reduce nested for loops and if statements using Iterator Blocks?" }
24303
<p>I've been teaching myself a bit of web design and development over the past month or so, coming from an CG/VFX background with no prior experience so it's been a bit alien to me to say the least.</p> <p>I found the excellent Javascript is Sexy guide and have been going through it, but today was project time. I must...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T14:57:01.413", "Id": "37482", "Score": "0", "body": "There is something one should understand when programming in client-side javascript: the DOM is slow. Awfully slow. Very very slow. You have to use the DOM the least possible time...
[ { "body": "<p>Overall, it's ok.</p>\n\n<p>Several points though:</p>\n\n<ul>\n<li><strong>The DOM is slow.</strong> Really. Calling it ten times when it's possible to do it only once is awful.</li>\n<li>To follow this, cache your selectors. <code>$</code> is a function returning an object. And you're calling it...
{ "AcceptedAnswerId": "24352", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T14:36:03.427", "Id": "24308", "Score": "4", "Tags": [ "javascript", "beginner", "jquery", "quiz" ], "Title": "Beginner's quiz with jQuery" }
24308
<p>This page (<a href="http://bl.ocks.org/byrongibson/5232838" rel="nofollow">full source &amp; demo</a>) displays a 2-channel horizontal <a href="http://bl.ocks.org/mbostock/4060954" rel="nofollow">d3.js Streamgraph</a> that takes realtime mouse coordinates as data inputs for the graph.</p> <p>However, it tends to gr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T20:43:46.333", "Id": "37501", "Score": "1", "body": "You use `$(window)` and `$(document)` quite a bit, so you might want to wrap with an IIFE and pass `document` and `window` into to it." }, { "ContentLicense": "CC BY-SA 3....
[ { "body": "<p>I am happy your problem is solved. All in all, your code looks solid, my review is mostly nitpicking:</p>\n\n<ul>\n<li><p>I am all for spartan coding, but you have far too many 1 and 2 character variables, you ought to use more meaningful variables.</p></li>\n<li><p>Try to have 1 <code>var</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T17:43:15.287", "Id": "24313", "Score": "4", "Tags": [ "javascript", "jquery", "memory-management", "d3.js" ], "Title": "d3.js realtime streamgraph memory usage" }
24313
<p>How well does this code limit security problems when uploading images to the server?</p> <pre><code>&lt;?php $filename = $_FILE['inputfile']['name']; $upload_path = 'images/'; //extract extension $ext = strtolower(substr($filename, strrpos($filename, '.') + 1)); // return mime type ala mimetype extension $finfo =...
[]
[ { "body": "<p>The whitelist of file extensions is a pretty good way to keep it secure. There are a couple other things you can do to safeguard from someone uploading different file types though.</p>\n\n<ol>\n<li><p>Add an .htaccess file that disables PHP files in the upload directory. This should protect from a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T19:01:29.540", "Id": "24317", "Score": "1", "Tags": [ "php", "security", "php5", "file-system" ], "Title": "Securing an Image Upload Script" }
24317
<p>My postfix program essentially allows the user two input options to calculate a postfix equation:</p> <ul> <li>Confirmations after each input (after an input, the user is ask for another number, operator, or final result)</li> <li>No confirmation after each input (user is only asked for a number of inputs (values a...
[]
[ { "body": "<p>Sure if you have too:</p>\n\n<pre><code>using std::cout;\nusing std::cin;\n</code></pre>\n\n<p>But are you really saving that much.</p>\n\n<p>Even forward declaration of functions, its nice to have the name of the parameters. It helps in understanding the context in which the function will be call...
{ "AcceptedAnswerId": "24326", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-24T22:41:38.577", "Id": "24324", "Score": "3", "Tags": [ "c++", "stack", "math-expression-eval" ], "Title": "Calculating postfix notation using two forms of input" }
24324
<p>Im trying to get better at writing jQuery plugins. Was hoping to get some feedback on my notes, but also just about the general architechture and implenmentation of this pattern (dont even know this one is called :P)</p> <p>jsFiddle: <a href="http://jsfiddle.net/gajwp/4/" rel="nofollow">http://jsfiddle.net/gajwp/4/...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T06:53:49.177", "Id": "37591", "Score": "0", "body": "I actually had the semicolon in ealier, but removed it because jslint diddnt like it. But your suggestion made me look it up at read about it, so now I understand WHY its a good i...
[ { "body": "<p>It was fun going over your code. I haven't played with 1.4 for a while. Well here are some suggestions:</p>\n\n<ul>\n<li>Place a semicolon before your IIFE as a precaution against statements without a separator. Putting a semicolon before the function prevents the function from becoming an argumen...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T12:27:00.713", "Id": "24334", "Score": "2", "Tags": [ "javascript", "jquery", "optimization", "plugin" ], "Title": "Optimizing my jQuery form popup plugin" }
24334
<p>According to instructions and sample code from <a href="http://msdn.microsoft.com/en-us/magazine/jj863137.aspx" rel="nofollow noreferrer">MSDN Magazine</a> and comments from post here <a href="https://stackoverflow.com/questions/15530143/deteminant-of-nn-matrix">determinant of n x n</a>...</p> <p>I changed code to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-09-26T17:30:24.850", "Id": "267212", "Score": "0", "body": "This code not can detriment matrix 4*4 ={0012,0051,6790,0795}" } ]
[ { "body": "<p>Optimizing for performance and readability you may want to avoid the 3 executions of the same loop:</p>\n\n<pre><code>for (int k = 0; k &lt; result.GetLength(1); k++){\n var swapTemp = result[pRow, k];\n result[pRow, k] = result[j, k]\n result[j, k] = swapTemp;\n}\n</code></pre>\n\n<p>You...
{ "AcceptedAnswerId": "24354", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T12:50:23.997", "Id": "24336", "Score": "4", "Tags": [ "c#", "matrix" ], "Title": "Calculating n x n determinant" }
24336
<p>I am trying to write an efficient loop for rendering a jQuery Mobile listview. Is this the most efficient loop? I append elements 100 at a time to try and allow the user to see progress without blocking the UI. This currently still needs work.</p> <p>I also use a blend of html strings and jQuery DOM objects. I'...
[]
[ { "body": "<ul>\n<li><p>If you have a reasonably or entirely fixed template, use something like <a href=\"http://handlebarsjs.com/\" rel=\"nofollow noreferrer\">HandlebarsJS</a> to make a template that you populate. </p></li>\n<li><p>Now about performance, I would suggest you make a <a href=\"http://jsperf.com/...
{ "AcceptedAnswerId": "24346", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T14:35:19.183", "Id": "24338", "Score": "0", "Tags": [ "javascript", "jquery", "dom", "jquery-mobile" ], "Title": "Render Large jQuery Mobile Listview" }
24338
<p>I am new to Haskell and, coming from a OO/procedural programming background, I want to make sure my code follows the <em>functional</em> way of doing things. I built this short module to test if a given string is a palindrome (same backwards and forwards, case-sensitive) and I am simply wondering if this is the most...
[]
[ { "body": "<p>I would just write</p>\n\n<pre><code>isPalindrome w = w == reverse w\n</code></pre>\n\n<p>Short, and very easy to understand! And in this case it's also a lot more efficient, but that's another story...</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
{ "AcceptedAnswerId": "24345", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T14:46:25.860", "Id": "24340", "Score": "7", "Tags": [ "haskell", "functional-programming" ], "Title": "Palindrome test in Haskell" }
24340
<p>I am trying to design a class that will log errors to a text file, the application is using threads heavily so it may be that 2 errors that need to be written at the same time. I know there are 3rd party solutions available but for this particular case I would like to roll my own. What I have at the moment seems to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T15:03:03.587", "Id": "37539", "Score": "2", "body": "What are the reasons for rolling out your own logger? What functionality you find missing in existing solutions?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<p>Instead of creating a task to check the queue every second it's probably better to just to create it once and wait for the data (errors) to arrive. <code>BlockingCollection</code> will help here to provide automated blocking until the new data is available. I've simplified file operations here (ea...
{ "AcceptedAnswerId": "24358", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T14:56:34.393", "Id": "24342", "Score": "1", "Tags": [ "c#", "multithreading", "exception-handling" ], "Title": "Multi Threaded Error Logger" }
24342
<p>I wrote a custom server control. The data in it can be manipulated on the client and the changes will be written into the hidden field. The data represents a property of the control and should be retrieved on a postback. I achieved this by using the value changed event to set the property and all its dependencies. ...
[]
[ { "body": "<p>You can just expose hiddenField.Value in the property.</p>\n\n<pre><code>public bool Property\n{\n get\n {\n EnsureChildControls();\n return Convert.ToBoolean(hiddenField.Value);\n }\n set\n {\n EnsureChildControls();\n hiddenField.Value = value.ToString(...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T15:16:25.087", "Id": "24344", "Score": "1", "Tags": [ "c#", "asp.net" ], "Title": "Asp.Net Custom Server Control: PostBack handling" }
24344
<p>I wrote a python module that needs to load a file parser to work. Initially it was just one text parsing module but I need to add more parsers for different cases.</p> <pre><code>parser_class1.py parser_class2.py parser_class3.py </code></pre> <p>Only one is required for every running instance. I'm thinking loa...
[]
[ { "body": "<h1>Regarding the safety aspect of your question.</h1>\n<p>The reason why <code>exec()</code> can be dangerous is that is can allow a nefarious agent to execute code that you never intended.</p>\n<p>Let's assume for example that somewhere in your program, you have sensitive data elements such as:</p>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T16:02:11.530", "Id": "24349", "Score": "7", "Tags": [ "python", "dynamic-loading" ], "Title": "Load modules conditionally Python" }
24349
<p>I've been trying to create a tree module in JavaScript for implementing a "family tree" style structure. I'm not very experienced in newer JavaScript design styles and want to make sure I am going along the right path with the code I have written so far. Can someone let me know if I am on the right track with how th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T02:01:58.450", "Id": "37579", "Score": "0", "body": "I suggest you finish up the code first before we review it. That way, further optimizations can be done with your code. As far as I can see, this code should work as intended." ...
[ { "body": "<p>Looks okay to me,</p>\n\n<ul>\n<li><p>I would not expose function names mentioning <code>node</code>, but rather <code>familyMember</code> or <code>member</code>.</p></li>\n<li><p>You expose only <code>name</code> through addNode, but you have <code>name, mother, father, children</code> in the con...
{ "AcceptedAnswerId": "24360", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-25T20:21:35.903", "Id": "24356", "Score": "2", "Tags": [ "javascript" ], "Title": "Javascript Module Design" }
24356
<p>I was given a homework assignment in Java to create classes that find Prime number and etc (you will see in code better).</p> <pre><code>class Primes { public static boolean IsPrime(long num) { if (num%2==0){ return false; } for (int i=3; i*i&lt;=num;i+=2) { if ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T02:16:43.403", "Id": "37580", "Score": "2", "body": "Hello and Welcome to Programmers. This question is off-topic here but on topic for Stack Overflow (if it's broken) and Code Review (if it's not and you just want to make it better...
[ { "body": "<p>Your <code>IsPrime</code> method looks already pretty good to me, just one little thing there in the line: </p>\n\n<pre><code>if (num % 2 == 0) {\n return false;\n}\n</code></pre>\n\n<p>It would return <code>false</code>for <code>num=2</code>, but <code>2</code>is also a prime number. So just ...
{ "AcceptedAnswerId": "24394", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T02:14:36.320", "Id": "24361", "Score": "1", "Tags": [ "java", "performance", "homework", "primes" ], "Title": "Primes Tester for speed performance" }
24361
<p>I am working on a site that themes itself based on images / logos. I have made a utility class that gets the colors from an image, shown below. I am fairly new to OOP with PHP, and I'm looking for feedback on what I could improve with the following. It is still in beta, so image-handling is a little sketchy and coul...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-19T18:03:36.567", "Id": "62709", "Score": "2", "body": "See http://99designs.com/tech-blog/blog/2012/05/11/color-analysis/ and https://github.com/99designs/colorific" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<h2>General Feedback</h2>\n<p>The class looks okay. I like how the method names follow <a href=\"https://www.php-fig.org/psr/psr-12/#44-methods-and-functions\" rel=\"nofollow noreferrer\">PSR-12 recommendation</a> of method names in camelCase, however it is also recommended that an underscore not be ...
{ "AcceptedAnswerId": "257275", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-03-26T02:59:25.350", "Id": "24363", "Score": "5", "Tags": [ "php", "object-oriented", "css", "file", "image" ], "Title": "Getting color information from an image" }
24363
<p>This is my first program in C. I'd rather not form any bad habits now. Is there anything that looks like bad practice, or something just looks wrong?</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; int main(void) { srand(time(NULL)); int r = rand() % 10 + 1; in...
[]
[ { "body": "<p>Here are some of the improvements i can suggest:</p>\n\n<ul>\n<li>move your <code>counter</code> variable , from the inside the <code>if</code> statements , as increasing the count is independent of the <code>if</code> condition.</li>\n<li><p>Use <code>srand(time(NULL));</code> , below the declara...
{ "AcceptedAnswerId": "24369", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T07:28:58.080", "Id": "24366", "Score": "6", "Tags": [ "beginner", "c", "game", "number-guessing-game" ], "Title": "\"Guess the Number\" game in C" }
24366
<p>I was working through another question <a href="https://stackoverflow.com/questions/15632476/">here</a> and have hacked up an answer:</p> <pre><code>def get_rows(): """ Get height of triangle from user""" while True: rows = input('Enter the number of rows: ') if 3 &lt;= rows &lt;= 33: ...
[]
[ { "body": "<p>Decorators are a tool that you use when you have many functions that share a behaviour, for example a particular calling convention or treatment of results. See the <a href=\"http://wiki.python.org/moin/PythonDecoratorLibrary\" rel=\"nofollow noreferrer\">Python Decorator Library</a> on the Python...
{ "AcceptedAnswerId": "24373", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T11:13:37.633", "Id": "24372", "Score": "3", "Tags": [ "python" ], "Title": "Drawing inverted triangles" }
24372
<p>I write abstract repository </p> <pre><code>using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using System.Linq.Expressions; namespace Framework.DataLayer { public class Context&lt;T&gt; : IContext&lt;T&gt; where T : class { private read...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-27T07:12:31.733", "Id": "37673", "Score": "0", "body": "Why are you returning anything from `Add` and `Update`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-16T12:05:18.580", "Id": "62067", "Scor...
[ { "body": "<p>For one, it is not an <em>abstract</em> repository, but a <em>generic</em> repository. Never mind. As mentioned in a comment, generic repositories are hardly ever helpful and I would never use them. But apart from that, there's a couple of things I can say about this code:</p>\n\n<ul>\n<li><p><cod...
{ "AcceptedAnswerId": "37678", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T11:56:58.173", "Id": "24374", "Score": "1", "Tags": [ "c#", "entity-framework" ], "Title": "Abstract repository for entity framwork" }
24374
<p>I have to run an external program from Python. The external program makes many temporary files (which conflict with other instance of same program).</p> <p>My strategy is:</p> <ol> <li>get current directory (native) path</li> <li>change to temp directory</li> <li>run external command</li> <li>copy output to nativ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-27T03:53:31.650", "Id": "89543", "Score": "0", "body": "This code doesn't appear to do anything useful, so I've classified it as hypothetical / example code, which would be off-topic for Code Review." } ]
[ { "body": "<p>Give a try to shutil and subprocess.</p>\n\n<p>To copy all the files:\n<a href=\"http://docs.python.org/2/library/shutil.html#shutil.copyfile\" rel=\"nofollow\">http://docs.python.org/2/library/shutil.html#shutil.copyfile</a></p>\n\n<pre><code>import shutil\nshutil.copy(src_file, destination_file)...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T11:59:20.783", "Id": "24375", "Score": "3", "Tags": [ "python", "bash", "file-system", "child-process" ], "Title": "Run external command from Python" }
24375
<p>How can I refactor this code to be more clean?</p> <pre><code> $scope.unreserve = function () { var params = { 'wishlist_product_id' : product.wishlist_product_id }; WishlistService.unreserve(params, function (data) { if (data.success) { $rootScope.$broadcast('NotificationControlle...
[]
[ { "body": "<p>There are 2 main changes I would make:</p>\n\n<ol>\n<li><p>ProductService.addManualProduct seems to require a callback. A way that is more consistent with Angular, and with a number of benefits, would be to return a promise, so you can use it like:</p>\n\n<pre><code>ProductService.addManualProduct...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T12:29:49.020", "Id": "24378", "Score": "1", "Tags": [ "javascript", "angular.js" ], "Title": "Broadcast event in angularJS" }
24378
<p>Could you have a quick look over my code to see if it's safe from SQL injection etc.. and suggest any amendments?</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;title&gt;Retrieve Your Login Code&lt;/title&gt; &lt;/head&gt; &lt;body bgcolor=#ffffff&gt; &lt;?php echo "&lt;h2&gt;Search Results:&lt;/h2&gt;&lt;p&gt;"; /...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-28T01:17:09.373", "Id": "37732", "Score": "1", "body": "mysql_connect (and related) are depreciated in PHP v5.5 http://php.net/manual/en/function.mysql-connect.php You should switch to use mysqli or more preferably a PDO system. This a...
[ { "body": "<pre><code>// We perform a bit of filtering\n$find = strtoupper($find);\n$find = strip_tags($find);\n$find = trim ($find);\n$find = mysql_real_escape_string($find);\n</code></pre>\n\n<p>one more step and you are safer. I recommend using <code>PDO</code> or <code>mysqli</code> to prevent sql injection...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T12:32:45.003", "Id": "24379", "Score": "-1", "Tags": [ "php", "html", "mysql", "sql-injection" ], "Title": "Search for a transaction" }
24379
<p>I always wanted to ask this but couldn't for some reason. </p> <p>I had written this chunk of code about 3 months ago when one of my teacher explained what selection sort was using flow chart. I had a basic understanding of what arrays were. So I sat down and wrote this:</p> <pre><code>#include &lt;stdio.h&gt; #d...
[]
[ { "body": "<ul>\n<li><p>You don't need two arrays, it works with one too, simply swap the\nvalues. This needs less memory.</p></li>\n<li><p>According to this:</p>\n\n<pre><code>int i, high = 0, k, j = 9, store;\n</code></pre>\n\n<p><code>j</code> is always one less than the size of the array. Don't use magic nu...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T13:40:41.717", "Id": "24383", "Score": "1", "Tags": [ "c" ], "Title": "Selection sort review. Does it look good?" }
24383
<p>I have to set up a new JavaScript library for a big project, which isn't Object Oriented yet. So I built a small file to test some needs. The result is the following:</p> <pre><code>var Module = { Config: (function() { //- private members var _systemName = 'mySystem', _version ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T16:24:38.537", "Id": "37649", "Score": "5", "body": "Consider putting the opening `{` in the same line as the statement, e.g. `var foo = {`. When using `return` you are actually *required* to do this so it's a good idea to do it in ...
[ { "body": "<p>To start off, your module should be the bare minimum, but extendable (like jQuery). That way, you won't have problems with scalability and maintenance. Here's a simple module template, where everything gets declared in the <code>Module</code> namespace:</p>\n\n<pre><code>//this is a simple module ...
{ "AcceptedAnswerId": "24406", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T16:20:54.133", "Id": "24393", "Score": "1", "Tags": [ "javascript", "jquery", "object-oriented" ], "Title": "js oop best practise" }
24393
<p>My first algorithm for finding the factors of a number was pretty slow and horrible (it started at \$O(n^2)\$, where <em>n</em> was not even the inputted number), but I eventually came up with this new code. I just want the first factors of a number (not the duplicates), so I used <code>sqrt(n)</code> instead of <c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T05:35:15.447", "Id": "90133", "Score": "0", "body": "What was `n` then?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-30T05:37:41.053", "Id": "90134", "Score": "0", "body": "@Nobody: I'll h...
[ { "body": "<p>I have a couple of suggestions that you may wish to consider:</p>\n\n<ul>\n<li><p>Don't return a string with the complete statement, return a <code>std::vector</code>/<code>std::map</code> instead with the values, and later assemble the string. It will keep the values in a more usable form and sep...
{ "AcceptedAnswerId": "24415", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T22:14:16.857", "Id": "24399", "Score": "4", "Tags": [ "c++", "optimization", "strings", "primes" ], "Title": "Simplifying and optimizing factors and prime factorization gen...
24399
<p>I'm learning F#, and even though I'm able to do whatever I want, parts of my code looks really bad. I would love to get some suggestions on how to improve a couple of functions involving some conditional logic.</p> <pre><code>let stripLast (punct : char) (word : string) = if word.Length &gt; 0 &amp;&amp; word.L...
[]
[ { "body": "<p><code>stripLast</code> looks good to me. You could try to use pattern matching for the empty string case, but I think it would actually make your code worse.</p>\n\n<p>Regarding <code>countWord</code>, instead of <code>\"\" |&gt; ignore</code>, you should write just <code>()</code> (this works, be...
{ "AcceptedAnswerId": "24434", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T22:31:14.147", "Id": "24401", "Score": "4", "Tags": [ "f#" ], "Title": "Idiomatic conditionals in F#" }
24401
<p>This is for regenerating some things in a game a made. The code is very big and I think it can be compressed but I don't know how to do it.</p> <pre class="lang-vb prettyprint-override"><code>Private Sub regen() 'regen coins z = coin1 z.Location = zloc z.Hide() zloc = New Point(RandomNumber...
[]
[ { "body": "<p>Have you heard of functions? The easiest way to shorten this is to take the repeated code, put it in a function, then call the function with all your coins.</p>\n\n<p>You should make the if statement a loop. As it currently is coded, what happens if the 2nd try > 595?</p>\n\n<pre><code>Private S...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-27T00:28:57.823", "Id": "24403", "Score": "1", "Tags": [ ".net", "vb.net" ], "Title": "Regenerations in a game" }
24403
<p>While upgrading our code base to take advantage of new features in .Net 4.5, I'm trying to refactor our take of the classic Producer/Consumer algorithm, but I'm concerned my refactoring is going to increase the CPU usage.</p> <p>Each instance of my <code>WorkItemConsumer</code> class is basically a <code>System.Thr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-27T19:57:13.850", "Id": "37720", "Score": "1", "body": "I think the only way to tell if it increases CPU usage is to put a profiler on it, and run it each way." } ]
[ { "body": "<p>Well, after more resarch and testing, it appears that the <code>GetConsumingEnumerable()</code> method of the <code>BlockingCollection&lt;T&gt;</code> is actually blocking when there are no items to consume. And it handles the case where the collection is completed as well.</p>\n\n<p>The final tou...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-27T08:52:59.797", "Id": "24410", "Score": "1", "Tags": [ "c#", ".net", "multithreading", "collections" ], "Title": "Does refactoring a while loop increase CPU usage?" }
24410
<p>I would like to hear the opinion of more experienced AngularJS developers on whether the following directive is best practice...</p> <p>I was trying to make to make a directive that will include HTML that:</p> <ul> <li>Can include compiled elements (other directives, like ng-src in the example below) </li> <li>Int...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-19T14:39:45.163", "Id": "45064", "Score": "1", "body": "Am i wrong or the third compile argument comes null? compile(tElement, tAttrs, transclude)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-08T16:27:51...
[ { "body": "<p>I am a bit confused, your directive basically would do what Angular already does?</p>\n\n<p>When I comment out the entire <code>testapp.directive('tag', function() {</code> block, I see no change in the functionality of this code in fiddle.. I think you need a more extensive example for us to prov...
{ "AcceptedAnswerId": "44573", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-27T08:58:46.243", "Id": "24411", "Score": "4", "Tags": [ "javascript", "angular.js" ], "Title": "AngularJS directive that manually transcludes content and has isolated scope" }
24411
<p>I'm trying to get to grips with the DateTime class in PHP. Previously I've used date() and mktime() when playing with dates.</p> <p>Here's the head of a calendar table, and I'm pretty sure I'm doing this in a stupid way! That fact that I'm setting the format each time, and modifying the original date with each Inte...
[]
[ { "body": "<p>I like it.\nYou could use loops and use a variable for 'DateInterval(P1D)'.</p>\n\n<pre><code>&lt;table class=\"twelve\"&gt;\n&lt;thead&gt;\n&lt;tr&gt;\n&lt;?php $date = new DateTime('2013-04-01'); \n $day = new DateInterval('P1D');\n?&gt;\n&lt;th style=\"width:16%\"&gt;&lt;?php echo $date-&g...
{ "AcceptedAnswerId": "24502", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-27T10:58:13.937", "Id": "24413", "Score": "1", "Tags": [ "php", "datetime" ], "Title": "PHP DateTime increments, a neater / more efficient way?" }
24413