body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I'm developing a web application that leverages multiple programming languages. The data flow resembles:</p>
<ul>
<li>Browser » <strong>PHP</strong> » <strong>PL/SQL</strong> » XML » <strong>XSLT</strong> » XHTML + <strong>JavaScript</strong> » Browser</li>
</ul>
<p>Using different languages makes it tempting to h... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-26T21:14:03.773",
"Id": "31896",
"Score": "0",
"body": "What's wrong with putting everything in this table? Each language doesn't have to use all of it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-26T21... | [
{
"body": "<p>I'm not familiar with PL/SQL so I'm unsure what exactly is being done with it. However, the commonly accepted solution for sharing between PHP and JavaScript is to use a JSON file. JSON is native to JS, its even in the name. PHP also supports JSON via its <code>json_encode()</code> and <code>json_... | {
"AcceptedAnswerId": "19968",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-26T21:03:01.607",
"Id": "19953",
"Score": "12",
"Tags": [
"javascript",
"php",
"postgresql",
"xslt"
],
"Title": "Cross-language constants"
} | 19953 |
<p>This is what i had before (using the MySQL api)</p>
<pre><code>$info_get = mysqli_query("SELECT * FROM `users` WHERE `uid`='".$_SESSION['uid']."'") or die(mysqli_error());
$info = mysql_fetch_assoc($info_get);
</code></pre>
<p>This is after I converted it to MySQLi</p>
<pre><code>$var = $_SESSION['uid']; //var... | [] | [
{
"body": "<p>No need to \"bump\" someone will eventually get around to it. It doesn't even work that way. Your question will always be towards the top of the PHP section, assuming it hasn't been too long (days). The only thing \"bumping\" does is boost it to the top of the ALL Languages section which isn't lik... | {
"AcceptedAnswerId": "19970",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T03:15:04.003",
"Id": "19957",
"Score": "-1",
"Tags": [
"php",
"mysqli"
],
"Title": "(Procedural)(Snippet) MySQL to MySQLi. Any advice?"
} | 19957 |
<p>Essentially I'm wondering if this implementation of an interface is correct. I mostly don't like having to repeat the exact same getters and setters. Is there a better way or is this alright?</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.F... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T18:13:29.837",
"Id": "71153",
"Score": "0",
"body": "Check for the snippet creation walkthrough on MSDN. It can help if you want to implement some properties and getter + setter over dozen of class without having to rewrite everyth... | [
{
"body": "<p>Please read <a href=\"http://msdn.microsoft.com/en-us/library/vstudio/ms229040%28v=vs.100%29.aspx\">.NET Naming conventions</a>, in particular interfaces should be prefixed with <code>I</code> (<code>Block</code> => <code>IBlock</code>).</p>\n\n<ul>\n<li>Your interface doesn't include SetPosition ... | {
"AcceptedAnswerId": "19960",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T03:53:45.383",
"Id": "19958",
"Score": "1",
"Tags": [
"c#",
"xna"
],
"Title": "C#/XNA interface usage, repeating functions"
} | 19958 |
<p>So, I have coded a PHP script that will make it able for the users to edit their Post, or comments on a site that runs SociaEngine 4.</p>
<p>So, Is there anything that could get inproved/fixed on this?</p>
<pre><code><?php
session_start();
$Mysql_Hostname = "192.168.1.110";
$Mysql_Username = "*user"... | [] | [
{
"body": "<p>You might consider incorporating a config file for your SQL connection. This will allow you to reuse it should that become necessary and update it more easily. Additionally, the <code>$Mysql_*</code> namespace seems unnecessary.</p>\n\n<p>Typically variables are not capitalized. This may just be a... | {
"AcceptedAnswerId": "19973",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T05:45:18.103",
"Id": "19959",
"Score": "0",
"Tags": [
"php"
],
"Title": "SocialEngine 4: Edit Post / Comment feature [Anything that can be improved? ]"
} | 19959 |
<p>I have following queries</p>
<p>First one using inner join</p>
<blockquote>
<pre><code>SELECT item_ID,item_Code,item_Name
FROM [Pharmacy].[tblitemHdr] I INNER JOIN EMR.tblFavourites F ON I.item_ID=F.itemID
WHERE F.doctorID = @doctorId AND F.favType = 'I'
</code></pre>
</blockquote>
<p>second one using sub quer... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T01:36:32.513",
"Id": "31945",
"Score": "0",
"body": "Have you checked the [execution plans](http://sqlserverpedia.com/wiki/Examining_Query_Execution_Plans) for the two queries?"
}
] | [
{
"body": "<p>The SQL Server query analyzer is smart enough to understand that these queries are identical (given that <code>item_ID</code> is unique in <code>EMR.tblFavourites</code> for a certain doctorID/favType pair). </p>\n\n<p>They should yield exactly the same execution plan, and thus they are equal in t... | {
"AcceptedAnswerId": "19964",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T09:39:35.967",
"Id": "19962",
"Score": "3",
"Tags": [
"optimization",
"sql",
"sql-server"
],
"Title": "Subquery v/s inner join in sql server"
} | 19962 |
<p>Given the following code, I have written a <code>for</code> loop that returns a key and value (0 or 1) of file names passed. 1 means present, and 0 means not present.</p>
<p>Is there a way to construct a flat map without having to use <code>into</code>?</p>
<pre><code>(defn kind-stat
[filename expected-type]
(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T17:28:52.980",
"Id": "31928",
"Score": "0",
"body": "I agree, this belongs on codereview. Though I would get rid of your let and if, and make them one whole, and have expected type be the function that accepts f so instead of f, d, ... | [
{
"body": "<p>You could use <a href=\"http://clojuredocs.org/clojure_core/1.2.0/clojure.core/zipmap\" rel=\"nofollow\"><code>zipmap</code></a>:</p>\n\n<pre><code>(defn all-files-present?\n [file-seq]\n (let [f #(bit-flip (look-for % \"f\") 0)]\n (zipmap (map keyword file-seq) (map f file-seq))))\n</code><... | {
"AcceptedAnswerId": "22715",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T16:55:04.193",
"Id": "19974",
"Score": "3",
"Tags": [
"file-system",
"clojure"
],
"Title": "Check for the presence of multiple files"
} | 19974 |
<p>I've started to learn an OOP and I've built a class called accountactions, and I would like to know if I did a good job writing it.</p>
<p>The class is in the file: accountactions.class.php.</p>
<pre><code><?php
class accountactions(){
public function register($login, $password, $email){
//Zapisu... | [] | [
{
"body": "<p>I think you have three options:</p>\n\n<ol>\n<li>Create a setter: <code>public function setDatabase($database) { ... }</code> and everytime the <code>accountactions</code> class is instantiated call it to provide the database functionality.</li>\n<li>Make a constructor that will require your datab... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T18:34:45.813",
"Id": "19976",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"sql"
],
"Title": "A method to insert a database entry for a newly registered account"
} | 19976 |
<p>I wrote this perl script that analizes a text and plot out a bar graph of the word occurrences during the text.</p>
<p>Since come mainly from Javascript and PHP, i would like to know how bad is this code and if there is room for improvement and how, any tip will be appreciated! </p>
<p>Thanks!</p>
<pre><code>#!us... | [] | [
{
"body": "<ul>\n<li><p>Use lexical filehandles instead of typeglobs (read <a href=\"https://stackoverflow.com/questions/1479741/why-is-three-argument-open-calls-with-autovivified-filehandles-a-perl-best-pract\">here</a> for more about why; the biggest problem with typeglobs is that they are global in scope).</... | {
"AcceptedAnswerId": "19985",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T19:20:07.507",
"Id": "19977",
"Score": "2",
"Tags": [
"perl"
],
"Title": "Perl project review - Word counter"
} | 19977 |
<p>For a project I need to give a load of diverseinformation in JSON format. All the information will be used on the same page so a single call would result in the least overhead. The information all concerns the same database object and is all nescessary on the page. It basically is a collection of counts of the amoun... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T01:33:13.013",
"Id": "31982",
"Score": "1",
"body": "what specific parts are you (or your co-worker) concerned about? The response data structure? The number of queries being issued? other?"
},
{
"ContentLicense": "CC BY-SA ... | [
{
"body": "<p>I think that what you have is probably fine. Personally, I'd move the construction of the result array to a view but this is not that big of a deal. That might help with the \"clunkiness\".</p>\n\n<p>With regards to your concern about the size of the json response: You say that all of the informat... | {
"AcceptedAnswerId": "20038",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T22:06:51.010",
"Id": "19981",
"Score": "2",
"Tags": [
"php",
"ajax",
"json",
"doctrine"
],
"Title": "Passing a large amount of diverse information in JSON using Symfony 2.1... | 19981 |
<p>I am trying to implement Boyer Moore Algorithm for text searching and have come up with this implementation:</p>
<pre><code>public class BoyerMooreStringSearching
{
readonly Dictionary<char, LastIndexTable> _lastIndexTable = new Dictionary<char, LastIndexTable>();
public string PatternToSearch;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T22:02:31.597",
"Id": "31969",
"Score": "1",
"body": "The standard way to deal with indices is `v < element.Length`, which is mostly to help prevent off-by-one (fencepost) errors. Dijkstra has [some notes on this](http://www.cs.utex... | [
{
"body": "<p>I have checked your code and there are some things which I would change:</p>\n\n<ul>\n<li>Create an interface, say, <code>IStringSearcher</code> with one method <code>List<int> GetStartingIndexsOfPatternInText(string textToSearchIn, string patternToSearch)</code>. That will help you to chang... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T07:03:00.807",
"Id": "19988",
"Score": "2",
"Tags": [
"c#",
"algorithm"
],
"Title": "Boyer Moore Implementation"
} | 19988 |
<blockquote>
<p>Given an input string, write a function that returns the Run Length
Encoded string for the input string.</p>
<p>For example, if the input string is “wwwwaaadexxxxxx”, then the
function should return “w4a3d1e1x6″.</p>
</blockquote>
<p>The following is my implementation:</p>
<pre><code>string... | [] | [
{
"body": "<p>I'm not a C++ guru, but for what they are worth, I have some comments:</p>\n\n<ul>\n<li>it would be better to evaluate s.end() just once (outside the loop). Correction: this won't help.</li>\n<li>the function fails if <code>s</code> starts with a space</li>\n<li><p>you have duplicate code turning... | {
"AcceptedAnswerId": "20004",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T09:52:11.120",
"Id": "19990",
"Score": "3",
"Tags": [
"c++",
"strings",
"interview-questions",
"compression"
],
"Title": "Run Length Encoding"
} | 19990 |
<p>I have this method that will give a random prime for a given range (min inclusive an max not inclusive) all comments are welcome:</p>
<pre><code>public static int randomPrime(int min, int max) {
if (min < 0)
throw new IllegalArgumentException("min must be positive.");
if (min >= max)
t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T14:51:36.520",
"Id": "31951",
"Score": "0",
"body": "Would you like to share your `isPrime` method as well?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T22:21:12.157",
"Id": "31972",
"Score... | [
{
"body": "<pre><code>int out = rand.nextInt(max - min) + min;\nwhile (!isPrime(out)) {\n out = rand.nextInt(max - min) + min;\n}\nreturn out;\n</code></pre>\n\n<p>This duplicate code can be replaced with a do/while loop. The rule of thumb is, if you always need to perform an action at least once, do while!<... | {
"AcceptedAnswerId": "19996",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T12:36:11.123",
"Id": "19993",
"Score": "3",
"Tags": [
"java",
"primes"
],
"Title": "Random Prime generator"
} | 19993 |
<p>I have written some code which will fetch contents from a resource which is actually stored in a tree format. Since it is in a tree format, there will be a parent-child relation and hence recursion.</p>
<p>I am facing lot of performance issue as tree is growing in size this particular piece of code takes up-to 25 s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T14:54:26.287",
"Id": "31952",
"Score": "0",
"body": ":I think, this must belong to the StackOverflow"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T15:58:08.790",
"Id": "31955",
"Score": "0",... | [
{
"body": "<pre><code>Iterator it = navModel.getChildren( objectNode );\nwhile( it.hasNext() ){\n NavNode node = (NavNode) it.next();\n</code></pre>\n\n<p><code>java.util.Iterator</code> has an extending class, which if you use, you don't have to manally cast back after calling <code>.next()</code>, as f... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T12:50:15.027",
"Id": "19994",
"Score": "3",
"Tags": [
"java",
"optimization",
"recursion"
],
"Title": "Recursion and iteration how can i optimize this code"
} | 19994 |
<p>I'm working on a 3 columns photo website (responsive), and I'm parsing the <code>img src</code> from XML. I need to prepend HTML code every 3 elements so my photo wall respects my responsive class.</p>
<p>I just found a cheap solution, repeating the XML loop (<code>for</code>). Do you have an advice to give me, to ... | [] | [
{
"body": "<p>Perhaps using a template system can help you, check <a href=\"http://handlebarsjs.com/\" rel=\"nofollow\">http://handlebarsjs.com/</a> you can integrate with jquery and reuse partial html code as a templates</p>\n\n<pre><code><script id=\"entry-template\" type=\"text/x-handlebars-template\">... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T18:00:34.163",
"Id": "20001",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Parsing XML and prepend HTML every 3 elements"
} | 20001 |
<p>This is my first time building anything remotely like a robust database. I'm midway through designing it and I would be grateful if you have suggestions or have found any logical errors.</p>
<p><strong>Goal:</strong> allow authenticated users to enter data for multiple hospitals.</p>
<p>My database has three table... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T05:18:10.087",
"Id": "51966",
"Score": "0",
"body": "I'm looking for exactly the same kind of best practice. If you have become confident in how to do it, could you share in a self-answer?"
}
] | [
{
"body": "<h2>Models - General</h2>\n\n<p>The comments on the model definitions don't add much value. I could figure out the relationships from the db schema; tell me instead something about what the classes are meant to represent, any invariants they have, anything not made explicit in the code.</p>\n\n<h2>Mo... | {
"AcceptedAnswerId": "42018",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-28T22:01:01.650",
"Id": "20008",
"Score": "15",
"Tags": [
"python",
"unit-testing",
"flask"
],
"Title": "Flask-SQLAlchemy models and unit-testing"
} | 20008 |
<p>I've finally finished my universal query preparation function. Any suggestions on making it better? I feel it could use some tweaking, but am not sure how I would go about it.</p>
<p><strong>Variable examples/explanation</strong></p>
<ul>
<li><code>$db</code> - The database connection</li>
<li><code>$query</code> ... | [] | [
{
"body": "<ul>\n<li><p>This is going to sound a bit harsh, but I don't see a purpose to this function. It offers a tiny bit of a shortcut, but it cripples a lot of functionality to do so.</p>\n\n<ul>\n<li>I'm not very familiar with MySQLi (PDO seems to have a lot more advantages than MySQLi and only a few, in... | {
"AcceptedAnswerId": "20012",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T00:47:12.593",
"Id": "20009",
"Score": "1",
"Tags": [
"php",
"mysql",
"mysqli"
],
"Title": "Universal query preparation function"
} | 20009 |
<p>I created some code for Minesweeper but I need help going over it. I would like if someone could go over it and point out anything (repeating code, code being called multiple times when not needed, etc).</p>
<p>This it the main class that also does a lot of other things:</p>
<pre><code>public class BoardBuild exte... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T17:41:54.057",
"Id": "32106",
"Score": "0",
"body": "move `10` as field dimension to a constant. This way you can easily change it in the future."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T10:48:... | [
{
"body": "<p>In Java, primitive numeric types all default to their equivalent of <code>0</code>, therefore this block can be removed entirely from GenerateMines:</p>\n\n<pre><code>for (int x = 0; x < 10; x++) {\n for (int y = 0; y < 10; y++) {\n board[x][y] = 0;\n }\n}\n</code></pre>\n\n<p>A... | {
"AcceptedAnswerId": "20023",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T09:27:10.483",
"Id": "20017",
"Score": "4",
"Tags": [
"java",
"game",
"minesweeper"
],
"Title": "Minesweeper Code"
} | 20017 |
<p>The problem can be viewed <a href="http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36" rel="nofollow">here</a>, since it's styled. I don't think I should just copy and paste.</p>
<p>I implemented recessive function and dynamic programming to solve it. It ca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-30T18:11:21.640",
"Id": "32027",
"Score": "3",
"body": "Why are you using the C standard library and C programming idioms in what is apparently supposed to be a C++ program?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>The only places I have found that improve <code>cycleLength</code> (by 5-10%) are </p>\n\n<ul>\n<li>reversing the (somewhat illogical) <code>if (!(arg & 1))</code> conditions (not really sure if this had an effect though, as there seems no reason for it to)</li>\n<li><p>and removing the test f... | {
"AcceptedAnswerId": "20037",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T12:42:29.970",
"Id": "20020",
"Score": "10",
"Tags": [
"c++",
"time-limit-exceeded",
"collatz-sequence"
],
"Title": "3n + 1 problem optimization"
} | 20020 |
<p>Here is my breadth-first search (<code>bfs</code>) and depth-first search (<code>dfs</code>) code for graph traversal. Please give me some constructive reviews on it.</p>
<pre><code>#include<stdio.h>
#include<stdlib.h>
#define null 0
typedef struct node//node of a linked list
{
struct vertex* inf... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-30T20:25:33.630",
"Id": "32029",
"Score": "0",
"body": "I can understand how your graph hangs together. You will need to add comments the describe how `node/edge/vertex/graph` hang together to build a graph."
},
{
"ContentLicen... | [
{
"body": "<p>Some comments, in no particular order:</p>\n\n<p>You are inconsistent in spacing and in positioning of '*', which makes the code look\nrather scrappy.</p>\n\n<p>It is generally less confusing not to hide pointers behind type definitions.\nAdmittedly you use 'ptr' in the type names, so this lessens... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T12:54:24.663",
"Id": "20022",
"Score": "2",
"Tags": [
"c",
"algorithm",
"breadth-first-search",
"depth-first-search"
],
"Title": "Breadth- and Depth-first search code"
} | 20022 |
<p>As a Java native, I am always a little worried when doing Objective-C because of memory leaks and pointers flying at my head...</p>
<p>All comments are welcome on the <code>Category</code> below. The <code>Category</code> functions are correct.</p>
<p><a href="https://github.com/Chucky2be/iRot47" rel="nofollow">G... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T22:51:03.823",
"Id": "32115",
"Score": "1",
"body": "I would say it looks ok — as long as you dont use it to gain safety in real world projects. ROT is hardly obfuscating and not secure at all."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>This bit looks just a bit suspect:</p>\n\n<pre><code>int stringLength = [self length];\nchar newString[stringLength+1];\n</code></pre>\n\n<p>You're using the NSString \"length\" property to size the C char array allocation. This assumes that the string's \"length\" value (which reflects number of ... | {
"AcceptedAnswerId": "20311",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T15:58:21.707",
"Id": "20025",
"Score": "5",
"Tags": [
"strings",
"objective-c",
"ios",
"caesar-cipher",
"category"
],
"Title": "Rot47 an NSString Category"
} | 20025 |
<p>I have multiple forms, each of which would like to send message through the network, using my <code>NetworkCommunicator</code> class's <code>SendMessage</code> method.</p>
<p>The solution I described here works, however it is ugly, and bludgeons some of the main concepts of OOP paradigm. What I'm looking for (and I... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-30T20:30:01.303",
"Id": "32030",
"Score": "0",
"body": "Feel more complex than it should have been. Is it a two-way communication, or do forms send their message in one direction only? Also, I believe that the `MainForm` should tempora... | [
{
"body": "<p>My suggestions:</p>\n\n<p>If the NetworkCommunicator exists only once per application, you should create a singelton. Code sample:</p>\n\n<pre><code> /// <summary>\n /// Provides a base class for singeltons.\n /// </summary>\n /// <typeparam name=\"T\">The class that ... | {
"AcceptedAnswerId": "20056",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T17:24:30.940",
"Id": "20027",
"Score": "1",
"Tags": [
"c#",
".net",
"delegates"
],
"Title": "Using delegates to communicate between forms and networkcommunicator class"
} | 20027 |
<h1>Problem</h1>
<p>Disclaimer: This is my first clojure function & I'm still busy finishing the last chapters of "Programming Clojure". Thanks! :)</p>
<p>I am writing a function to randomly flood-fill parts of a game's map (i.e. this is not a traditional flood-fill that can recursively fill all available space).... | [] | [
{
"body": "<p>I am a journeyman myself in clojure, and I don't have answers for all of your questions, but I have some input.</p>\n\n<p>I am not sure I fully understand your algorithm, but it seems you really have two loops rolled in to one. You have an inner loop looking for what could be the next tile to pain... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T17:39:20.873",
"Id": "20028",
"Score": "3",
"Tags": [
"optimization",
"functional-programming",
"clojure"
],
"Title": "Idiomatic Clojure? Performant & functional enough?"
} | 20028 |
<p>I'm currently using SciPy's mode function to find the most occurring item in different iterable objects. I like the mode function because it works on every object type I've thrown at it (strings, <code>float</code>s, <code>int</code>s).</p>
<p>While this function seems reliable, it is very slow on bigger lists:</p>... | [] | [
{
"body": "<p>Originally I thought you must have been doing something wrong, but no: the <code>scipy.stats</code> implementation of <code>mode</code> scales with the number of unique elements, and so will behave very badly for your test case.</p>\n\n<p>As long as your objects are hashable (which includes your t... | {
"AcceptedAnswerId": "20033",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T19:33:13.343",
"Id": "20030",
"Score": "3",
"Tags": [
"python",
"python-2.x"
],
"Title": "Finding the mode of an array/iterable"
} | 20030 |
<p>I am writing a function for a rotating navigation with JS and jQuery. I am using a plugin called jQuery transit for animating rotation. The code works, but it is very long for such a simple function. Is there any way this can be improved?</p>
<pre><code>var rotation = 0;
$('nav ul li a').bind('click', function() {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T20:39:16.333",
"Id": "31998",
"Score": "0",
"body": "Just realized that the `$('nav ul li a')` should be put in a variable. Any other suggestions?"
}
] | [
{
"body": "<p>Instead of that complex <code>switch</code> statement, I'd just use an option object:</p>\n\n<pre><code>var allLinks = $('nav ul li a');\nvar rotation = 0;\n\n$('nav').on('click', 'ul li a', function() {\n 'use strict';\n var $this = $(this);\n var item = $this.parent();\n var navAll =... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T19:35:00.387",
"Id": "20031",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "Animating rotations using jQuery"
} | 20031 |
<p>Background:</p>
<p>A synchronous grammar is a like two context-free grammars connected in parallel. It is used for translation. For example, here is a small synchronous grammar that can be used for translating between natural language text and semantic representation:</p>
<blockquote>
<pre class="lang-none prett... | [] | [
{
"body": "<ol>\n<li><p>NullPointerException</p>\n\n<p>It should be IllegalArgumentException.\nConsider just returning empty collection of expansion.\nIt greatly improves composeability of your code.</p>\n\n<p>Think about making invalid states unrepresentable.\n(though I cannot think a trivial way of doing this... | {
"AcceptedAnswerId": "20054",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-30T10:12:35.347",
"Id": "20041",
"Score": "2",
"Tags": [
"java",
"grammar"
],
"Title": "Expanding a synchronous grammar"
} | 20041 |
<p>In chapter 45 of <em>Learn Python the Hard Way</em>, the author basically says: "Ok, go figure out how to make a text based game"</p>
<p>Before I get too far in this I just want to be sure I'm not doing anything stupid. The code as it is is fairly functional just not too many rooms.</p>
<p>I am running this under ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-30T09:38:46.133",
"Id": "32011",
"Score": "0",
"body": "Comments are always nice. `color=(4 if b[i]>15 else (3 if b[i]>9 else (2 if b[i]>4 else 1)))` isn't nice, nor are `try` and `if` statements that are nested to a depth of five. Try... | [
{
"body": "<p>I don't think having <a href=\"http://docs.python.org/2/reference/simple_stmts.html#the-global-statement\" rel=\"nofollow\"><code>global</code></a> at the module level makes sense.</p>\n\n<p>You should have it in a function/method if you need, but I would advise against having global variables at ... | {
"AcceptedAnswerId": "20044",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-30T09:34:30.697",
"Id": "20042",
"Score": "4",
"Tags": [
"python",
"adventure-game"
],
"Title": "\"You are in a dark room; learn how to make a text based game\""
} | 20042 |
<p>Would you have any suggestions improvements for the below functions classes ?</p>
<p>Ok here how do i make a registered member login</p>
<pre><code> HttpCookie LoginInfo = new HttpCookie("LoginInfo");
LoginInfo.Values["UserName"] = srUserName;
LoginInfo.Values["Password"] = srPassword;
LoginInfo.Val... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T02:11:35.630",
"Id": "32040",
"Score": "1",
"body": "Lose the \"Hungarian Notation\" variable names: http://msdn.microsoft.com/en-us/library/vstudio/ms229045.aspx"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | [
{
"body": "<p>In addition to losing the hungarian notation there are a few things worth mentioning:</p>\n\n<ol>\n<li>Don't use try-catch construction with empty 'catch' clause. It is almost always a bad idea to hide an exception if it was thrown. </li>\n<li>It would be better to check explicitly if the key is i... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-30T23:57:48.857",
"Id": "20048",
"Score": "0",
"Tags": [
"c#",
"asp.net",
"logging",
"session"
],
"Title": "ASP.net proper login - logout classes - control login status"
} | 20048 |
<p>I have a dataframe with several columns. One of them is an user ID column, in this column, I have several ids that can be repeated several times.</p>
<p>What I want to do is remove the first ID, for instance:</p>
<pre><code>1,2,3,4,3,4,2,1,3,4,6,7,7
</code></pre>
<p>I would like to have an output like this:</p>
... | [] | [
{
"body": "<p>Well after reading some stuffs, I've come to the conclusion that I could eliminate several lines and do this instead:</p>\n\n<pre><code>rbind(results1, results[dup,]) -> results1\n</code></pre>\n\n<p>It is much quicker and seems more efficient.</p>\n\n<p>However any suggestions or recommendatio... | {
"AcceptedAnswerId": "20378",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T09:46:59.753",
"Id": "20053",
"Score": "1",
"Tags": [
"r"
],
"Title": "Removing first duplicate dataframe"
} | 20053 |
<p>This is a polymorphic wrapper capable of holding any type. (It is loosely based on <code>boost::any</code>)</p>
<p>In particular, this is useful when you want to store a heterogeneous collection, such as <code>vector<Any></code>.</p>
<h2>Synopsis</h2>
<pre><code>string s = ...;
int i = ...;
Any a1 = s;
An... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-21T08:36:22.207",
"Id": "47648",
"Score": "1",
"body": "This seems not compiling on Visual Studio 2010... anybody tried on VS 2010?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-21T13:07:35.453",
"Id"... | [
{
"body": "<pre><code>template<class T>\nusing StorageType = typename decay<typename remove_reference<T>::type>::type;\n</code></pre>\n\n<p>This appears unnecessarily complex: 'decay' already removes a reference. Consider using:</p>\n\n<pre><code>template <class T>\nusing StorageType = t... | {
"AcceptedAnswerId": "20059",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T11:42:08.127",
"Id": "20058",
"Score": "27",
"Tags": [
"c++",
"c++11",
"variant-type"
],
"Title": "C++11 Any class"
} | 20058 |
<blockquote>
<p>Write an efficient function to find the first non-repeated character
in a string. For example, the first non-repeated character in "total"
is 'o' and the first non-repeated character in "teeter" is 'r'.</p>
</blockquote>
<p>Please see my solution and give me some feedback and suggestions for impr... | [] | [
{
"body": "<p>Alex, it looks quite efficient. There are some issues that I see:</p>\n\n<ul>\n<li><p><code>gets</code> should never be used. Use <code>fgets</code> (but note that you will have to strip the trailing <code>\\n</code>)</p></li>\n<li><p>define <code>main</code> at the end to avoid the need for a pro... | {
"AcceptedAnswerId": "20063",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T12:06:51.250",
"Id": "20060",
"Score": "1",
"Tags": [
"optimization",
"c",
"strings",
"array"
],
"Title": "First non-repeated character in a string in c"
} | 20060 |
<p>I quite often need to implement collection-like classes and - to make using them more comfortable - would like to take advantage of a constructor with variable arguments.</p>
<p>The following implementation does not work, though.</p>
<pre><code>class FruitsStore
{
private List<String> availableFruits;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T14:35:25.877",
"Id": "32063",
"Score": "0",
"body": "http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#asList%28T...%29\nreturns a **fixed-size** list. No `add` no `remove`."
},
{
"ContentLicense": "CC BY-SA 3.0... | [
{
"body": "<p>You have found the <em>natural</em> solution to this situation. <code>Arrays.asList</code> will give you a <code>List</code> with specific features - <code>new xxList(Arrays.asList(...))</code> will give you a list with attributes you require.</p>\n",
"comments": [
{
"ContentLice... | {
"AcceptedAnswerId": "20073",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T12:49:26.067",
"Id": "20062",
"Score": "1",
"Tags": [
"java"
],
"Title": "Collection-like classes in Java - taking advantage of varargs"
} | 20062 |
<p>I've been trying to get a relatively optimized version of base64 encoding that works against files. However, I've made several attempts and haven't gotten anything much faster than what I have here. On the posted implementation, I started from what was posted on <a href="http://www.swissdelphicenter.ch/torry/showc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T00:16:17.237",
"Id": "32088",
"Score": "0",
"body": "I have a different version of this now with much smaller numbers of instructions. I figured out the main issue is with the output buffer assigns (my guess about 20% of the total ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T14:41:43.327",
"Id": "20064",
"Score": "2",
"Tags": [
"delphi",
"base64"
],
"Title": "Performance Tuning Base64 encoding"
} | 20064 |
<p>I am trying to wrap my arms around all the digital files we have, so I thought I would organize all of our pictures and videos into folders named after dates. I'm learning F#, and this felt like a good chance for me to exercise that muscle.</p>
<p>Please review the code. I'm open to any criticisms, but I also hav... | [] | [
{
"body": "<p>A few things:</p>\n\n<p>There's already a recursive overload of <code>EnumerateFiles</code> so you don't need <code>getAllFiles</code>. Your top level function would be:</p>\n\n<pre><code>let moveFrom source =\n Directory.EnumerateFiles(source, \"*\", SearchOption.AllDirectories)\n |> Seq.f... | {
"AcceptedAnswerId": "20083",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T19:59:43.707",
"Id": "20068",
"Score": "0",
"Tags": [
"asynchronous",
"f#"
],
"Title": "Perfomance and Other Improvements"
} | 20068 |
<p>This question is related to <a href="http://expressjs.com" rel="nofollow">Express</a> under <a href="http://nodejs.org" rel="nofollow">Node.js</a>.</p>
<h1>Background</h1>
<p>With Express, you stack up several "middleware" modules to handle a specific HTTP request.</p>
<pre><code>app.use(express.logger());
app.us... | [] | [
{
"body": "<p>I did the following for something similar. This uses the closure to create a chain-of-command pattern.</p>\n\n<pre><code>function (req, res, next) {\n var realEnd = res.end;\n res.end = function () {\n var realEndArgs = arguments;\n req.log.info (\"HTTP RESPONSE CODE \" + res.statusCode);... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T20:06:51.283",
"Id": "20069",
"Score": "4",
"Tags": [
"javascript",
"node.js"
],
"Title": "Monkey patching extra events in Node.js HTTP/Express"
} | 20069 |
<p>I started off with a simple dispatch class, but it's grown and I'm sure it could be simplified in the very least. In fact, I'm doing way too much in the <code>__construct()</code> method</p>
<p>It it being called as such:</p>
<pre><code>$router = new router($_SERVER['REQUEST_URI'], $database);
$router->dispatc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-20T14:01:40.067",
"Id": "40832",
"Score": "0",
"body": "Your AJAX requests should be treated the same as normal requests, as in they go to the relevant controller / action. In the relevant **controller method** is where you make sure t... | [
{
"body": "<p>Your property doccomments are wrong. As they are you will only get that one long list of <code>@var</code>s for <code>$url</code> and the rest will remain empty. This defeats the purpose of the doccomments. The proper way is to put each doccomment above its respective property, like so:</p>\n\n<pr... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-31T23:44:43.753",
"Id": "20071",
"Score": "0",
"Tags": [
"php",
"mvc"
],
"Title": "Simplifying my dispatch and routing class"
} | 20071 |
<p>Following code helps me to automatically map the query result with Entity properties. For example, result of the following query “ReportTypeCode“ is mapped with Report object’s ReportTypeCode property.</p>
<pre><code>SELECT R.report_type_code AS ReportTypeCode FROM Report_Type R
</code></pre>
<p><strong>QUESTIONS<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-01T23:20:09.567",
"Id": "32087",
"Score": "3",
"body": "One idea is have you considered using existing ORM's such as EF or LinqSQL?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-21T11:58:24.893",
"Id"... | [
{
"body": "<h3>Observations</h3>\n\n<ul>\n<li><p><strong>You are reinventing the wheel</strong>. Yes, an Object/Relational Mapper such as Entity Framework adds an overhead, but if your queries are <code>select abc from xyz</code> I don't see it being an issue.</p></li>\n<li><p>Using reflection has an overhead a... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-01T11:21:02.137",
"Id": "20075",
"Score": "3",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Mapping Query Result with Entity Properties"
} | 20075 |
<p>I'm asking for suggestions on a random accessed vector with allocated elements sorted by its key obtained from its member function.</p>
<p>I use it with Qt tree view where the access, add and deletion of tree items is implemented via its index or row number. And I want all the tree items are automatically sorted un... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T04:31:56.350",
"Id": "32091",
"Score": "1",
"body": "This looks a lot like an _associative ordered container_, but fails to expose the interface we expect from _associative ordered containers_ in **C++**."
},
{
"ContentLicen... | [
{
"body": "<p>There's probably much that can be done here, but I'll point out some things I've noticed:</p>\n\n<ul>\n<li><p>As @David Harkness has mentioned in the comments, the method-naming looks like C# naming (uppercase, or PascalCase). While this isn't necessarily a bad thing as C++ is more flexible with ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-01T00:20:09.993",
"Id": "20079",
"Score": "7",
"Tags": [
"c++",
"c++11",
"vectors",
"smart-pointers"
],
"Title": "A pointer vector sorted by its member function"
} | 20079 |
<p>I am working on a little browsergame project written in PHP and using PostgreSQL as DBMS. Now I'm not really lucky with the process started after a userlogin was successful.</p>
<p>Some info:</p>
<ul>
<li>There are 3 different kinds of properties a game character can have:
<ul>
<li>Attributes</li>
<li>Skills</li>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T07:29:24.320",
"Id": "32243",
"Score": "0",
"body": "I'm too lazy to write out a full answer, and this was hinted at by the answers below, but a little note: storing the data in a session has a major problem that wasn't made explici... | [
{
"body": "<p>Here's how I would write this:</p>\n\n<pre><code>[...]\n$this->getIngameInfo();\n\n//one account can have up to 4 characters\n//each of the characters can have different values \nforeach($_SESSION['user']['character'] as $key => $data){\n $_SESSION['user']['character'][$key]['att... | {
"AcceptedAnswerId": "20127",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-01T22:12:40.607",
"Id": "20082",
"Score": "2",
"Tags": [
"php",
"performance",
"session",
"postgresql"
],
"Title": "Browser game project"
} | 20082 |
<p>I have this code that converts audio to different file formats:</p>
<pre><code>import java.io.File;
import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.In... | [] | [
{
"body": "<h2>Overall</h2>\n\n<p>Design first.</p>\n\n<h2>Name and semantic of your class</h2>\n\n<blockquote>\n <p>I have this code that converts audio to different file formats.</p>\n</blockquote>\n\n<p>Not exactly, your code is a client to an <code>Encoder</code>, that converts audio to different file form... | {
"AcceptedAnswerId": "20090",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T08:57:43.233",
"Id": "20084",
"Score": "5",
"Tags": [
"java",
"performance",
"converting",
"interface",
"audio"
],
"Title": "Converting audio to different file formats"... | 20084 |
<p>Here is the code: <a href="https://github.com/EarlGray/haskell-snippets/blob/master/ext2hs/Ext2.hs" rel="nofollow">https://github.com/EarlGray/haskell-snippets/blob/master/ext2hs/Ext2.hs</a></p>
<p>My problem is that it is quite painful to make large Haskell "records" and deserialize a binary layout with <code>Data... | [] | [
{
"body": "<p>A way to avoid those temporary values and (!!) operators, at the cost perhaps of some obscurity, would be something like the following:</p>\n\n<pre><code>import Control.Applicative ((<$>),(<*>),pure)\n\nbinGetSuperblock' = do \n partiallyAppliedConstructor <- Superblock \n ... | {
"AcceptedAnswerId": "20135",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T10:53:15.443",
"Id": "20086",
"Score": "2",
"Tags": [
"haskell"
],
"Title": "Reducing boilerplate of binary layout handling in Haskell"
} | 20086 |
<p>I have a list of pointers to objects where some of the objects contain a pointer to another object. When I remove an object in the list which has a linked object I need to remove them BOTH. I also want to position the next iterator at a convenient position which will usually be just after the object in the list wh... | [] | [
{
"body": "<p>OK. This is <strong>NOT</strong> C++ code. This is C that happens to use a few C++ features like std::list. I would call this \"C with classes\".</p>\n\n<p>What you have failed to do is define the ownership of the pointers. Without ownership calling delete is a pain (because you don't know if call... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T11:51:07.380",
"Id": "20087",
"Score": "2",
"Tags": [
"c++"
],
"Title": "Function to erase original element but also linked"
} | 20087 |
<p>The new <a href="http://html5bones.com/" rel="nofollow">HTML5 Bones</a> template uses the following example for the main content (I removed some parts (like ARIA, comments, <code>aside</code>, …) not relevant for this question):</p>
<pre><code><!-- The <section> element can be used to enclose content that ... | [] | [
{
"body": "<p>I think the <code>section</code> element should be an <code>article</code> element, and the two <code>article</code> elements should be <code>section</code> elements:</p>\n\n<pre><code><article>\n\n <h2>Getting Started</h2>\n\n <section id=\"introduction\">\n <h3>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T15:34:29.523",
"Id": "20091",
"Score": "1",
"Tags": [
"html5"
],
"Title": "Sectioning element choice for main content in HTML5 Bones"
} | 20091 |
<p>The same view (a layout) used for all pages in Kohana3.3 project. That's why it could be placed in before() method instead of every action. Right?</p>
<p>Is there any better way to optimize the code below so you shouldn't use so many <code>$this-></code>? Are there any other improvements of this code so it looks... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T19:15:41.007",
"Id": "32103",
"Score": "1",
"body": "I don't get the question, your code is good. And $this refers to the object that it's in so why would you use less of it? Code is good."
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>Your code is violating the \"Don't Repeat Yourself\" (DRY) Principle, which is why it seems like you have \"too many\" <code>$this->*</code> lines. As the name implies, your code should not repeat. Usually, in an instance such as this, I would say to use the constructor and inject those values ... | {
"AcceptedAnswerId": "20101",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-29T08:54:54.427",
"Id": "20095",
"Score": "0",
"Tags": [
"php"
],
"Title": "Kohana newbie: setting a layout view and variables for layout in before()"
} | 20095 |
<p>This is a little yet unfinished RPG I made with C#. It runs well but I'm wondering if there are things I could improve to make it more clear or optimal. I'm basically asking for some feedback and suggestions.</p>
<p>The program is obviously not finished but I'm asking now before I move on so I know if I got some s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T22:01:54.567",
"Id": "32111",
"Score": "0",
"body": "What do you mean by \"optimal\"? There doesn't seem to be any performance-sesitive code in your game, so trying to make it faster doesn't make much sense."
},
{
"ContentLi... | [
{
"body": "<p>Your code is \"incorrect\" in quite a few ways, from naming conventions, to separation of concerns (UI vs. object creation) to bedrock principles (such as principle of least privilege - <code>public</code> member variables being a big no-no). All that being said, I've taken a quick stab at address... | {
"AcceptedAnswerId": "20108",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T21:13:36.207",
"Id": "20102",
"Score": "3",
"Tags": [
"c#",
"beginner",
"console",
"role-playing-game"
],
"Title": "RPG character creation implementation"
} | 20102 |
<p>I had this programming exercise of mine where I had to find the shortest path to an exit in an NxM -grid maze in under a second (both N and M would be anywhere between 3 and 1000). The program would be tested with 10 different inputs (mazes), all of which includes a very different amount of exits.</p>
<p>The input ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T00:54:38.110",
"Id": "32121",
"Score": "0",
"body": "This: `int *f_coords = new int[2];` just screams \"I have no idea how to use C++\". This is not Java don't use the language as if it was. Unless there is a good reason to use new ... | [
{
"body": "<p>Reviewing all of this is a fairly big task, so let me start with a few ideas and come back later if I have the time.</p>\n\n<h2>Algorithmic considerations</h2>\n\n<p>As Sylvain pointed out in his answer to <a href=\"https://stackoverflow.com/questions/14129584/a-shortest-path-algorithm-optimizatio... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T21:48:57.413",
"Id": "20104",
"Score": "2",
"Tags": [
"c++",
"performance",
"memory-management",
"taxicab-geometry"
],
"Title": "A* shortest path algorithm optimization"
} | 20104 |
<p>This program displays either the time, current temperature, 12hr graph of temps, 24 hr graph of temp or a week's graph of temps. Selection is based on user input of one of the GPIO pins.</p>
<p>Please review my code, especially the use of the global variables, indentation and comments.</p>
<pre><code>from subproc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T12:38:25.133",
"Id": "32251",
"Score": "0",
"body": "I see that you have accepted my answer. Don't you want to put a new version of your code here so that one can have a deeper look ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Too much to put as a comment, so this is going to be an answer :</p>\n\n<p>As a general comment, you use many variables which are used only once, so they might not really be useful.</p>\n\n<p><code>ckyorn</code> can be rewritten in a more concise way. Also, its name is weird and one of the paramet... | {
"AcceptedAnswerId": "20116",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-02T23:33:37.267",
"Id": "20109",
"Score": "12",
"Tags": [
"python",
"beginner",
"matplotlib",
"raspberry-pi"
],
"Title": "Time and temperature displaying program for Raspberry... | 20109 |
<p>I am using <code>DataGrid</code> to show storagehouse occupancy (Occupied-Show Image With a box, Not Occupied-Show Empty Image).<br>
In DataGrid I am using <code>DataGridTemplateColumn</code> to override the Images.<br>
My Main Form XAML Code: </p>
<pre><code><xctk:BusyIndicator Name="ctrlBusy" IsBusy="False" B... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T01:08:56.223",
"Id": "45130",
"Score": "1",
"body": "This will never work fine. We are facing a similar issue with a grid (~20 row and ~90 column) and everything is slow as hell becouse Silverlight/desktop WPF application can not ha... | [
{
"body": "<blockquote>\n <p>The stopwatch i kept for checking time taken to load DataGrid. It is\n showing value less than 250ms. But in reality it is taking too much\n take show and for 4-6 second the UI gets hanged. Why is hanging? How\n to overcome it?</p>\n</blockquote>\n\n<p>That's beacuse the datagri... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-01-03T05:29:37.730",
"Id": "20111",
"Score": "2",
"Tags": [
"c#",
"wpf",
".net-datatable"
],
"Title": "Performance of WPF datagrid when using DataGridTemplateColumn"
} | 20111 |
<p>I have a wrapper which interacts with a third party component. In Each function i am performing the operation if it the component is initialized. </p>
<p>I have other function to check the errorCode and component initialization check. </p>
<p>Is this right way to do this? I am not happy with the readability of thi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T07:17:12.590",
"Id": "32132",
"Score": "0",
"body": "Does the third party have some sort of mapping of error codes to strings? Most of the third party libraries I have used have had something like that. Either a function I could cal... | [
{
"body": "<p>Okay, well here is what I would probably do in this situation. If the error codes you are getting are consistent this will make this type of solution even better (consistent as in \"FileNotFound\" error code is always -42 or something like that).</p>\n\n<p>I would add a private method that throws ... | {
"AcceptedAnswerId": "20117",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T07:02:17.407",
"Id": "20113",
"Score": "1",
"Tags": [
"c#",
"error-handling"
],
"Title": "Best way to handle repetitive error code or return value"
} | 20113 |
<p>This is my command interface:</p>
<pre><code>public interface IConverter {
void convert();
}
</code></pre>
<p>This is my Receiver class:</p>
<pre><code>public class Ogg extends Audio{
private File src;
private File trgt;
public static final String CODEC = "libvorbis";
public static final Str... | [] | [
{
"body": "<p>I do not see the reason of for class <code>OggConverter</code> as it is now. </p>\n\n<p>Instead of that you could just add the interface <code>IConverter</code> to class <code>Ogg</code>. And remove all others classes as then only forward the call. </p>\n\n<p><code>IConverter converter = OggConver... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T07:05:13.160",
"Id": "20114",
"Score": "2",
"Tags": [
"java",
"object-oriented",
"design-patterns",
"interface",
"audio"
],
"Title": "Ogg audio format conversion classes"
... | 20114 |
<p>I am working on a sparse matrix application in C and I choose compressed sparse row (CSC) and compressed sparse column (CSC) as my data structure for it. But the difficult part is I cannot improve my matrix multiplication function.</p>
<pre><code>/**
* The element and matrix are the naive format I have for sparse ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T19:16:11.840",
"Id": "32164",
"Score": "0",
"body": "Well you could make sure the indentation is consistent so people can read it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T21:58:55.700",
"I... | [
{
"body": "<p>Here is my understanding of what you are doing:</p>\n\n<ul>\n<li>you have some matrices stored in files using your own 'naive' format.</li>\n<li>you read these into your <code>matrix</code> structures</li>\n<li>two of these matrices are then passed to <code>multiply()</code></li>\n<li>you convert ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T14:22:58.130",
"Id": "20124",
"Score": "2",
"Tags": [
"optimization",
"performance",
"c",
"matrix"
],
"Title": "Sparse matrix multiplication"
} | 20124 |
<p>I have some pretty basic Regex that scans the output of a <strong>HTML</strong> file (the whole document source) and attempts to extract all of the absolute links that look like images. Whether they <em>are</em> actually images or not isn't too important, as those checks would be made later.</p>
<p>I am just trying... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T14:37:22.860",
"Id": "35189",
"Score": "1",
"body": "Someone has to link it, do not parse html with regex: http://stackoverflow.com/a/1732454/7602"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T15:0... | [
{
"body": "<p>Have you tested your regex with lines such as :\n<a href=\"http://example.com/\" rel=\"nofollow\">http://example.com/</a> file.png</p>\n\n<p>(note the space before file).</p>\n\n<p>It matches such lines. Is it what you intend ?</p>\n\n<p>As your question is about efficiency, you should consider ha... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T15:37:21.613",
"Id": "20126",
"Score": "4",
"Tags": [
"regex",
"coldfusion"
],
"Title": "Regex to get all image links"
} | 20126 |
<pre><code>public class NANDFunction : FunctionInfo
{
public override string Name { get { return "NAND"; } }
public override int MinArgs { get { return 2; } }
public override int MaxArgs { get { return 2; } }
public override object Evaluate(object[] args)
{
bool arg0 = CalcConvert.ToBool(ar... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T19:20:25.187",
"Id": "32165",
"Score": "0",
"body": "Is FunctionInfo a class you've created? If so, what does it look like?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T19:22:05.383",
"Id": "3... | [
{
"body": "<p>You may want to add some additional validation around how many arguments you're expecting (since you know via <code>MinArgs</code> and <code>MaxArgs</code>). You can also eliminate having to create an object array explicitly in the caller by using the <code>params</code> keyword (make sure you do ... | {
"AcceptedAnswerId": "20131",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T19:14:13.847",
"Id": "20129",
"Score": "0",
"Tags": [
"c#"
],
"Title": "Possible issues and best practices for this piece of code"
} | 20129 |
<p>I'm developing a desktop app that will scan a user's system for mp3 files and send their whole collection to a website. I'm assuming the best file format for sending this data to a server would be XML -- although correct me if I'm wrong.</p>
<p>Can someone kindly comment on whether the formatting of the sample XML ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T22:25:23.630",
"Id": "32177",
"Score": "2",
"body": "Are you trusting metadata from the file? What about performing some sort of hashing on the file, to get ids? What is your usecase, if somebody tries to feed you false informatio... | [
{
"body": "<p>It looks fine. I'd add a space before the xml closing tag:</p>\n\n<p><code><?xml version=\"1.0\" encoding=\"utf-8\" ?></code></p>\n\n<p>But surely you want more than artist and track title? Album? Maybe not much else could be figured out by the scanning. But if you can get into the ID3 tag o... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T19:19:35.797",
"Id": "20130",
"Score": "2",
"Tags": [
"xml"
],
"Title": "XML format for mp3 files"
} | 20130 |
<p>I need help refactoring this code to dynamically generate a sort string that I can send to my data layer so that my database does the sorting instead of it happening in memory. I am using MVC4 with EF5 as my data layer.</p>
<pre><code>public ActionResult InstanceSearch(int? page, string sortOrder, string computerNa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T03:13:54.963",
"Id": "32186",
"Score": "0",
"body": "Does this work correctly? If not, then you need to get it working before posting here."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T16:53:54.463... | [
{
"body": "<p>The data layer that appears to be causing your problem is the root cause.</p>\n\n<p>You're abstracting over an abstraction, and in the process having to marshall sort orders around as a result. Prefer injecting your context in a request scope and remove the abstraction.</p>\n\n<p>You can always cr... | {
"AcceptedAnswerId": "20426",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T21:33:00.447",
"Id": "20132",
"Score": "1",
"Tags": [
"c#",
"asp.net",
"asp.net-mvc-4"
],
"Title": "How to dynamically Generate Sort strings for Data Layer from Controller"
} | 20132 |
<p>I would like to know, if my design of this class is good OOP.
Should I implement for every hash algorithm a separate class?
I'm asking this, because the <code>HashService</code> can be used with a <code>KeyedHashAlgorithm</code> which wouldn't work correctly?!</p>
<pre><code>public class HashService : IDisposable
{... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T00:57:39.973",
"Id": "32184",
"Score": "0",
"body": "If you want to control the Algorithms supported then you could make the constructor private. Then you would control what algorithms you support. Not very OCP though???"
}
] | [
{
"body": "<p>Personally I think that all properties (Getters/Setters) should be at the top of the class, before the constructor. I believe that also matches Microsoft's style guide.</p>\n\n<p>I personally use <code>this.Property</code>, I think its much easier to read and tells you its a class member not a loc... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T22:58:01.857",
"Id": "20134",
"Score": "3",
"Tags": [
"c#",
"object-oriented",
"cryptography"
],
"Title": "Nice design of my hash service class"
} | 20134 |
<pre><code>Uint8Array.prototype.indexOfMulti = function(searchElements, fromIndex) {
fromIndex = fromIndex || 0;
var index = Array.prototype.indexOf.call(this, searchElements[0], fromIndex);
if(searchElements.length === 1 || index === -1) {
// Not found or no other elements to check
return ... | [] | [
{
"body": "<p>First things first. This code is fairly difficult to read. <code>indexOfMulti</code> could mean</p>\n\n<ul>\n<li>You're searching for any one of multiple values.</li>\n<li>You're searching for all occurrences of a value (less likely -- might be <code>indicesOf</code> or <code>findAll</code>).</li>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-03T23:21:36.603",
"Id": "20136",
"Score": "1",
"Tags": [
"javascript",
"optimization",
"node.js"
],
"Title": "Uint8Array indexOf method that allows to search for byte sequences"
} | 20136 |
<p>I have following in Windows Forms .NET 3.5</p>
<p>It works fine for csv with records less than 10,000 but is slower for records above 30,000.
Input csv file can can any records between 1 - 1,00,000 records </p>
<p>Code currently used :</p>
<pre><code>/// <summary>
/// This will import file to the c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T12:48:51.700",
"Id": "32199",
"Score": "0",
"body": "Do you have a multi core machine? Then you can parse in parallel. Does the CSV files contain redundant data? In this case it does make sense to intern strings to reduce memory loa... | [
{
"body": "<p>There isn't much to optimize in regards to speed, but following is much more readable. If it is too slow, it probably isn't the method <em>reading</em> the file, but your WinForm that needs to display >30k records.</p>\n\n<pre><code> accountsDataGridView.Rows.Clear();\n using (FileStream fil... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T12:34:29.223",
"Id": "20145",
"Score": "6",
"Tags": [
"c#",
".net",
"winforms",
"csv"
],
"Title": "Faster way of reading csv to grid"
} | 20145 |
<p>The following logic:</p>
<p>Iterate over the URLs array and If the HTTP request with the given URL does not timeout, continue. If the URL times out, remove it from the array and continue with the next one until the array is exhausted.</p>
<p>Has been implemented in the following way:</p>
<pre><code>@urls.delete_i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T15:23:43.613",
"Id": "32206",
"Score": "0",
"body": "Specifically, hate the break in there - maybe someone can propose a cleaner solution."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T15:33:12.537... | [
{
"body": "<p>I'd take a functional approach (no in-place updates):</p>\n\n<pre><code>url, doc = @urls.map_detect do |url|\n begin\n [url, perform_request(some_params)]\n rescue TimeoutError\n Rails.logger.warn(\"URL #{url} timed out\")\n false\n end\nend\n</code></pre>\n\n<p>This snippet uses the c... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T15:23:14.970",
"Id": "20151",
"Score": "3",
"Tags": [
"ruby"
],
"Title": "iterate over an array and delete elements conditionally"
} | 20151 |
<p>I have this problem where I have to find the shortest path in an NxM grid from point A (always top left) to point B (always bottom right) by only moving right or down. Sounds easy, eh? Well here's the catch: I can only move the number shown on the tile I'm sitting on at the moment. Let me illustrate:</p>
<pre><code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T16:34:52.920",
"Id": "32211",
"Score": "0",
"body": "always right or down, always the total amount the case value is at? so it should be *very* fast : on each step, try both directions: try_right (goes N right, and also store \"R\" ... | [
{
"body": "<p>I think BFS is your algorithm, but I do have some cleanups for you. The reason A* won't work is because your estimation of how much farther you have to go (you could do a simple grid distance from where you are to the end point, also considering the jump value where you are sitting) could be wrong... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T15:27:15.477",
"Id": "20152",
"Score": "4",
"Tags": [
"c++",
"optimization",
"algorithm",
"pathfinding",
"breadth-first-search"
],
"Title": "Shortest path in a grid betwee... | 20152 |
<p>This is the backend to my jquery.php plugin which handles requests to make function calls and execute PHP code that is sent in various forms. After requests are processed they're sent back to the client side as a JSON object with a type flag set so JavaScript can convert the returned data to the correct type for the... | [] | [
{
"body": "<p>I can't really help you with your specific questions, but I do have some suggestions.</p>\n\n<p>The first, and most crucial, bit of advice, especially if you are worried about security, is not to turn off your error reporting. Instead you should turn it on all the way. While developing it is essen... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T17:19:15.473",
"Id": "20155",
"Score": "1",
"Tags": [
"php",
"jquery"
],
"Title": "jquery.php plugin security optimization (backend)"
} | 20155 |
<p>I'd like to practice oojs so I've written code:</p>
<pre><code>function Randoms(c, l, h) {
var count = c,
min = l,
max = h,
nums = Array(),
self = this;
//returns random number from given max and min
var getRand = function () {
return Math.floor(Math.random() * (... | [] | [
{
"body": "<ol>\n<li>Your <code>check</code> method is inefficient for large datasets. I'd recommend using a hash instead. This will eliminate the need of iterating over the array every time you want to check if a number is there. </li>\n<li>It is possible for your code to enter an infinite loop if <code>count<... | {
"AcceptedAnswerId": "20159",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T18:01:30.670",
"Id": "20157",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Random array of numbers without repeating - oojs practice"
} | 20157 |
<p>My A* Algorithm in C++ is pretty slow. I'm not sure if it is because of a bad implementation or just because I have way too many <code>Node</code>s (I have a field of 256x256 <code>Node</code>s). It takes the algorithm about 5 seconds to complete.</p>
<p>I'm using a vector for the open and closed List. For the <cod... | [] | [
{
"body": "<p>As a guideline: your inner loop should contain no operation more expensive than O(log(N)). This means no iterating over the entire closed/open list, and no making heaps over and over again! Here's how:</p>\n\n<ol>\n<li>Use a <code>std::set</code> sorted by weight instead of a heap. <code>begin()</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T19:09:00.640",
"Id": "20161",
"Score": "2",
"Tags": [
"c++",
"performance",
"algorithm",
"pathfinding"
],
"Title": "A* C++ implementation is too slow"
} | 20161 |
<p>Generally, I structure small threadsafe immutable objects like this:</p>
<pre><code>public class SmallObject {
private final String state;
public SmallObject(final String state) {
this.state = state;
}
// ...
}
</code></pre>
<p>And then wire these up in Spring like this:</p>
<pre><code>&l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T11:36:30.703",
"Id": "32414",
"Score": "2",
"body": "I do not understand the purpose, an opinion about this solution depends heavily on the circumstances. This approach will generate a lot of problems if it comes to threadsafety. An... | [
{
"body": "<p>This class should instead use an AtomicReference to ensure the state is kept valid. Alternatively, you should incorporate thread-safe handling of the String.</p>\n\n<p>Consider:</p>\n\n<pre><code>private final AtomicReference<String> stateref = new AtomicReference<String>();\n\npublic ... | {
"AcceptedAnswerId": "36946",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-04T19:23:04.683",
"Id": "20163",
"Score": "6",
"Tags": [
"java",
"object-oriented",
"immutability",
"spring"
],
"Title": "Circular dependencies between immutable objects; the ... | 20163 |
<p>These classes are part of a program I am working on to convert Arabic numerals to Roman numerals and vice-versa. Do these classes look correct for representing objects in Java?</p>
<pre><code>public class ArabicNumeral {
private final int value;
public ArabicNumeral(final int value) {
if (value < 0) {
... | [] | [
{
"body": "<ul>\n<li><code>RomanNumerals.D.getMultipleOfTen()</code> is <code>java.lang.ArrayIndexOutOfBoundsException</code></li>\n<li>RomanNumerals.D.getMultipleOfFive() is M</li>\n</ul>\n\n<p>What does <code>getMultipleOfFive</code> mean? And why should it return 1000\n when called on 500?</p>\n\n<ul>\n<li... | {
"AcceptedAnswerId": "20193",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T00:52:39.433",
"Id": "20166",
"Score": "6",
"Tags": [
"java",
"beginner",
"object-oriented",
"converting",
"roman-numerals"
],
"Title": "Converting Arabic numerals to R... | 20166 |
<p>I have many thousands of image files spread around various places and would like to copy them into one directory. However, may of the files are duplicates with the same names (often thumbnails or reduced resolution etc). I want to delete all files that have the same name except for the largest. </p>
<p>The followi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T22:55:44.187",
"Id": "62167",
"Score": "0",
"body": "prefer to use a range based for loop since you are using c++11:\n\nfor(const auto & file : files)\n{\n std::cout << file.first << \" \" << file.second;\n}"
}
] | [
{
"body": "<p>Looks good overall (though I'm by no means a C++ expert).</p>\n\n<p>In coming brain-dump though:</p>\n\n<hr>\n\n<p><code>void</code> argument lists are rare in C++. Yes, in C, <code>int c()</code> and <code>int c(void)</code> are different, but in C++, that's not the case. In C++, <code>int c()</c... | {
"AcceptedAnswerId": "20169",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T01:02:38.980",
"Id": "20167",
"Score": "5",
"Tags": [
"c++",
"beginner",
"file"
],
"Title": "Reading a list of file paths and adding them to a map"
} | 20167 |
<p>I have created WordPress theme options using an array, and it is working. There are 5 type of input: <code>text</code>, <code>textarea</code>, <code>checkbox</code>, <code>select</code> and <code>upload</code>.</p>
<p>Please read over my code and offer some possible improvements and/or tweaks. </p>
<pre><code><... | [] | [
{
"body": "<p>Mostly, it just appears that your code is violating the \"Don't Repeat Yourself\" (DRY) Principle. As the name implies, your code should not repeat itself. There are a few reasons for this, efficiency and reusablity chief among them. Your first violation of DRY is sort of a combination of the two.... | {
"AcceptedAnswerId": "20239",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T03:55:37.647",
"Id": "20171",
"Score": "2",
"Tags": [
"php",
"wordpress"
],
"Title": "Simple theme options held in array"
} | 20171 |
<p>My code looks like "spaghetti code". I have yet to use OOP in PHP but I am really interested in how a good programmer would handle this many <code>if</code> statements. It looks like a mess.</p>
<pre><code><?php
session_start();
include './functions.php';
if(empty($_FILES['browseMovie']) || empty($_... | [] | [
{
"body": "<p>Your first if can be simplifed with <code>any</code> function.</p>\n\n<pre><code>function any ($list, $pred) \n{\n foreach ($list as $value) \n {\n if (call_user_func ($pred, $value) == TRUE)\n return TRUE;\n }\n return FALSE;\n}\n</code></pre>\n\n<p>So it will... | {
"AcceptedAnswerId": "20178",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T04:11:16.317",
"Id": "20172",
"Score": "2",
"Tags": [
"php",
"optimization"
],
"Title": "Movie database browser"
} | 20172 |
<p>I'm developing a model for web applications. The database that I use is Redis.</p>
<p>I created special <code>DbField</code> objects like <code>HashDbField</code>, <code>SortedSetDbField</code>, <code>ScalarDbField</code> and so on, for each data type in Redis. This objects provides a convenient way to work with re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-15T03:23:47.503",
"Id": "32886",
"Score": "0",
"body": "While we're on the topic of being as pythonic as possible, [PEP-8](http://www.python.org/dev/peps/pep-0008/) recommends lowercase function names with underscores. So `SortedSetDbF... | [
{
"body": "<p>Woah, that's a lot of code.</p>\n\n<p>In Python 3, you can do replace <code>super(DbObjectType, cls)</code> by <code>super()</code>.</p>\n\n<p>Instead of</p>\n\n<pre><code>if not cls._Reg_raw.contains(dbObjectId): return None\n\nreturn cls(dbObjectId)\n</code></pre>\n\n<p>You could do that</p>\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T09:17:17.347",
"Id": "20175",
"Score": "3",
"Tags": [
"python",
"object-oriented",
"database",
"redis"
],
"Title": "Model for web applications"
} | 20175 |
<pre><code>private function getFeatureByParam ($classname, $module, $action) {
$needFeature = array();
foreach ($this->featureConf as $featureIndex => $feature) {
if ($feature['classname'] == $classname &&
$feature['module'] == $module &&
$feature['action'... | [] | [
{
"body": "<p>Personally, option 2.</p>\n\n<p>In option 1, by breaking out of the loop, you have to look down until after the end to see what happens, just to see a return.\nIn option 2, it's obvious what you want and when you get it. Although, I think the condition is a little complex.</p>\n\n<p>There are, of ... | {
"AcceptedAnswerId": "20188",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T10:03:16.407",
"Id": "20177",
"Score": "1",
"Tags": [
"php"
],
"Title": "A puzzle about how to write more clean and understandability code"
} | 20177 |
<p>I am trying to use Entity Framework as simple as posible. Use UnitOfWork and Repository patterns seems to be overkill because whole web application will be pretty straightforward. I came with this idea:</p>
<pre><code>public class Entity
{
...
}
public class MyContext : DbContext
{
//Set database connectio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T12:11:17.933",
"Id": "32342",
"Score": "0",
"body": "IMO you should'nt depend on DbContext. DbContext is plumbing to supply your own MyContext with underlying functionality. It's not an interface to use throughout your code."
}
] | [
{
"body": "<p>You're doing it right - <em>per-request</em> lifestyle is exactly what you need, and you got it; this ensures your favorite IoC container disposes your context at the end of each request, and serves a new instance at each new one.</p>\n\n<p>One thing bothers me though, and it's not about your code... | {
"AcceptedAnswerId": "35653",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T14:13:52.990",
"Id": "20179",
"Score": "20",
"Tags": [
"c#",
"asp.net-mvc-3",
"entity-framework"
],
"Title": "Correct usage of EF's DBContext in ASP.NET MVC application with Ca... | 20179 |
<p>I created a program to find the largest prime factor for a given number. The program works but unfortunately takes very long time to compute a huge number like 600851475143. </p>
<p>How can I optimise this program to run faster?</p>
<p>I don't know what does this multicore thing is, but I think it is a possible wa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-06T15:36:59.293",
"Id": "32309",
"Score": "0",
"body": "You have optimised your loop by jumping by 2. There is another small improvement that you increment alternatively by 2 and 4. This is the equivalent of removing multiples of 2 and... | [
{
"body": "<p>First, a couple of suggestions:</p>\n\n<ul>\n<li>If you're using <code><iostream></code>, you might as well use <code>#include <cmath></code> instead of <code>#include <math.h></code>, for consistency if nothing else.</li>\n<li>avoid <code>using namespace std;</code>, it's not wo... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T14:19:23.683",
"Id": "20180",
"Score": "6",
"Tags": [
"c++",
"primes"
],
"Title": "Largest prime factor for a given number"
} | 20180 |
<p>If I create a brush like so</p>
<pre><code>HBRUSH hBrush = CreateSolidBrush(RGB(33, 33, 33));
</code></pre>
<p>and then later on, I want to change the color of the brush, how would I do this?<br>
I googled a bit and found out that creating a bunch of different brushes is not the way to go.</p>
<p>I was thinking t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T18:34:09.407",
"Id": "32269",
"Score": "0",
"body": "Who says creating a bunch of different brushes is not the way to go? You should avoid creating more brushes than needed, but you cannot change their colors once created so you wil... | [
{
"body": "<p>Assume any Win32 call that returns a handle allocates a struct with <code>malloc</code>. And assume <code>DeleteObject</code> (<code>DestroyWindow</code> etc) frees allocated memory. you should call <code>DeleteObject</code> every time you creare a GDI object.</p>\n\n<p>Calling <code>CreateSolidBr... | {
"AcceptedAnswerId": "20190",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T14:47:30.677",
"Id": "20181",
"Score": "0",
"Tags": [
"c++",
"optimization",
"performance",
"windows",
"garbage-collection"
],
"Title": "Correct way of using HBRUSHes..... | 20181 |
<p>I have the following function that looks up a mathematical operation that can be applied to a Numeric sequence based on a String</p>
<pre><code>def getAction[T : Fractional]( op : String ) : Seq[T] => String =
op match {
case "add" => seq => seq.sum.toString
case "product" => seq => seq.pro... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T16:26:46.100",
"Id": "32260",
"Score": "0",
"body": "your code won't even compile as given..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T16:54:23.717",
"Id": "32261",
"Score": "0",
"b... | [
{
"body": "<p>How about not having to specify the type at all?</p>\n\n<pre><code>implicit class SeqWithAction[T:Fractional](seq:Seq[T]) {\n def getAction( op : String ) : String =\n op match {\n case \"add\" => seq.sum.toString\n case \"product\" => seq.product.toString\n case \"mean\" ... | {
"AcceptedAnswerId": "20187",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T15:50:05.377",
"Id": "20183",
"Score": "4",
"Tags": [
"scala"
],
"Title": "Terser syntax for first-class functions needing a context bound"
} | 20183 |
<p>I was thinking in a way of implementing a graph in such that would let find a minimum spanning tree.</p>
<p><strong>Graph.h</strong></p>
<pre><code>#ifndef GRAPH_H
#define GRAPH_H
#include <list>
#include <vector>
#include <utility>
#include <iostream>
#include <map>
#include <que... | [] | [
{
"body": "<ul>\n<li>You can use <code>EdgeIt</code> and <code>VertexIt</code> instead of <code>Edge*</code> and <code>Vertex*</code></li>\n<li>Your algorithm might be turned into class that incrementally update MST while new links added and dropping off rest of edges that isn't improving MST.</li>\n<li>Conside... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T15:54:30.267",
"Id": "20184",
"Score": "2",
"Tags": [
"c++",
"graph"
],
"Title": "Undirected, connected and weighted graph implementation"
} | 20184 |
<p>I would like a review of how I am comparing two <code>java.util.String</code> in a private method in a <code>java.util.Comparator</code>. Either of the <code>String</code>s could be null or blank, and would be "less than" the other <code>String</code> if that other <code>String</code> were not null/blank.</p>
<p>M... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2018-04-24T17:32:58.357",
"Id": "370493",
"Score": "0",
"body": "Is `Comparator.nullsFirst(String::compareTo).compare(date0, date1)` not sufficient?"
}
] | [
{
"body": "<p>You could write the code like this, it is doing the same, but I think it is more readable, you almost don't need any comment, to assume the return value.</p>\n\n<pre><code>private Integer compareDateStrings(BeanToDoTask arg0, BeanToDoTask arg1, String strProperty) {\n String strDate0 = BeanUtil... | {
"AcceptedAnswerId": "20195",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T18:24:13.973",
"Id": "20191",
"Score": "5",
"Tags": [
"java"
],
"Title": "Comparing two Strings which could be null or blank in a Comparator"
} | 20191 |
<p>I tried to implement an answer for the algorithm question given below. I implemented two different solutions. I couldn't decide which one is better. ( Maybe none )</p>
<p>Note: Node class and ZigZag interface are given along with the question.</p>
<p><strong>Problem Definition</strong> A binary tree is given. Retu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T10:03:43.073",
"Id": "32340",
"Score": "1",
"body": "Time and Space complexity is never stated as O(3n) or O(2n).\n\nO(a*n + b) = O(n)."
}
] | [
{
"body": "<ol>\n<li>First of all you are not really using Queue and Stack in any specific way.</li>\n<li><p>The following :</p>\n\n<pre><code>currentNode = levelStack.firstElement();\nlevelStack.remove(currentNode);\n</code></pre>\n\n<p>can be more concisely expressed as:</p>\n\n<pre><code>currentNode = levelS... | {
"AcceptedAnswerId": "20227",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T19:43:44.580",
"Id": "20192",
"Score": "3",
"Tags": [
"java",
"binary-search"
],
"Title": "Returning Binary Search Tree Nodes in Zig Zag manner"
} | 20192 |
<p>I am a newbie to C++ programming and am currently reading this book called <em>Jumping to C++</em> by Alex Allain. I have finished the pointers chapter and I am doing the exercises at the end of the chapter.</p>
<p>The following paragraphs are the exercises and included are my own solutions:</p>
<blockquote>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T22:10:44.463",
"Id": "32276",
"Score": "1",
"body": "You are not implementing pointers, you are merely using them..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T22:16:40.333",
"Id": "32278",
... | [
{
"body": "<p>I'm not sure whether this should be reviewed yet or not. I can't decide what critiques are things that you haven't learned yet but will, and things that you haven't learned yet and might not. (Also, there's a handful of errors that should have been found with basic testing.)</p>\n\n<p>Anyway her... | {
"AcceptedAnswerId": "20197",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T22:09:08.317",
"Id": "20196",
"Score": "3",
"Tags": [
"c++",
"beginner",
"pointers",
"reference"
],
"Title": "Am I using C++ pointers and references correctly?"
} | 20196 |
<p>I would like to get an advice regarding how to test the same code with different input data.</p>
<p>I would like to test that method <code>operationSucceeded</code> will be invoked for all successful status codes. Here is how I can test (with <a href="https://github.com/allending/Kiwi" rel="nofollow">Kiwi</a>) sing... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T14:35:13.907",
"Id": "32346",
"Score": "0",
"body": "This site is dedicated for code review: you can present working code and ask for possible improvements. However if the code is faulty it isn't in the scope of this site and you sh... | [
{
"body": "<p>I've got one possible solution from Max Lunin:</p>\n\n<pre><code>NSArray *successCodes = @[@200, @201, @202, @203, @204, @205, @206];\nfor (NSNumber *statusCode in successCodes) {\n it([NSString stringWithFormat:@\"should call operationSucceeded for status code %@\", statusCode], ^{\n MK... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-05T22:42:10.340",
"Id": "20198",
"Score": "2",
"Tags": [
"objective-c",
"unit-testing",
"ios"
],
"Title": "Testing the same code with different input data"
} | 20198 |
<p>At the end of the immediately-invoked function expression, there is an if statement that checks the screen width and loads in some resources. I'm curious if it is best practice to include this logic inside my IIFE, or outside. Both seem to function the same as far as I can tell, though I'm curious if there is prefer... | [] | [
{
"body": "<p>In this case, it makes no difference at all. This IIFE really has no reason for even being there because all it contains is a single function. Your code does use any of the usual benefits of an IIFE (like a local and protected scope) or capturing the arguments in a closure. </p>\n\n<p>So the ad... | {
"AcceptedAnswerId": "20453",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-06T01:42:57.263",
"Id": "20202",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "New to immediately-invoked function expression with JavaScript, curious about placement"
} | 20202 |
<p>At first I tried using a timedelta but it doesn't accept months as an argument, so my next working example is this:</p>
<pre><code>from datetime import datetime
current_date = datetime.now()
months = []
for month_adjust in range(2, -3, -1): # Order by new to old.
# If our months are out of bounds we need to ch... | [] | [
{
"body": "<p>Based on <a href=\"https://stackoverflow.com/questions/546321/how-do-i-calculate-the-date-six-months-from-the-current-date-using-the-datetime\">this answer</a>, I would do something like :</p>\n\n<pre><code>from datetime import date\nfrom dateutil.relativedelta import relativedelta\ntoday = date.t... | {
"AcceptedAnswerId": "20217",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-06T22:31:19.160",
"Id": "20216",
"Score": "1",
"Tags": [
"python"
],
"Title": "Is there a cleaner way of building a list of the previous, next months than this?"
} | 20216 |
<p>I am fetching rows from the DB and returning the result in JSON. The output needs to be an array of associative arrays.</p>
<pre><code>$i = 0;
foreach($resultSet as $r)
{
$output[$i]['key1'] = $r['col1'];
$output[$i]['key2'] = $r['col2'];
...
$output[$i]['keyN'] = $r['colN'];
$i++;
}
</code></pre>
<p>Is ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T05:33:22.000",
"Id": "32332",
"Score": "0",
"body": "Which DB API are you using? If PDO, your best bet will be to alias the columns to whatever you want their names to be (`SELECT a as b` or `SELECT a b`) and then use `fetchAll()`.... | [
{
"body": "<p>Instead of declaring <code>$i=0;</code> before the loop, you can also write :</p>\n\n<pre><code>foreach($resultSet as $i => $r)\n{\n $output[$i]['key1'] = $r['col1'];\n $output[$i]['key2'] = $r['col2'];\n ...\n $output[$i]['keyN'] = $r['colN'];\n}\n</code></pre>\n\n<p>Also, if you could ren... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T05:26:45.603",
"Id": "20220",
"Score": "1",
"Tags": [
"php",
"performance"
],
"Title": "Creating an array of associative arrays in PHP"
} | 20220 |
<p>This is my solution to <a href="https://www.spoj.com/problems/INTEST/" rel="nofollow">SPOJ Problem 442</a>. How can I make this code run faster? What are some techniques that can be used to make this faster? I am getting a Time Limit Exceed Error here.</p>
<pre><code>import java.util.Scanner;
class main{
publi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T12:26:03.647",
"Id": "32343",
"Score": "1",
"body": "`You are expected to be able to process at least 2.5MB of input data per second at runtime.` Are you expecting your user to be able to type that much data that fast into the conso... | [
{
"body": "<p>According to <a href=\"https://stackoverflow.com/questions/4960736/which-is-the-most-efficient-way-of-taking-input-in-java\">this question</a> on SO, the issue is with Scanner's nextInt method. Use a BufferedReader, then manually convert the string into an int.</p>\n",
"comments": [],
"met... | {
"AcceptedAnswerId": "20242",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T12:16:17.033",
"Id": "20222",
"Score": "2",
"Tags": [
"java",
"performance",
"programming-challenge"
],
"Title": "Enormous Input Test - reducing program runtime"
} | 20222 |
<pre><code>def users_list
html = ''
self.users.each do |user|
html << user.link_avatar_tag
end
html.html_safe
end
</code></pre>
<p>I feel that it is possible to write shorter.</p>
<p>Is it possible get rid of the temporary variable(html)?</p>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T15:08:55.900",
"Id": "32352",
"Score": "0",
"body": "What class is user? `html_safe` is no standard method for String - What gems are you using? Or in short: Can you provide a MWE? And to answer: It looks ok for me."
},
{
"C... | [
{
"body": "<p>You should use <code>map</code> (don't use <code>each</code> to accumulate. Check <a href=\"https://code.google.com/p/tokland/wiki/RubyFunctionalProgramming\" rel=\"nofollow\">this page about functional programming</a>):</p>\n\n<pre><code>def users_list \n users.map(&:link_avatar_get).join.h... | {
"AcceptedAnswerId": "20237",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T13:43:49.017",
"Id": "20224",
"Score": "3",
"Tags": [
"ruby",
"html",
"ruby-on-rails"
],
"Title": "Refactor ruby each-code"
} | 20224 |
<p>A few days ago I've faced an annoying problem.
Let's imagine we have 3 classes: Base, System, Handler.</p>
<p>The classes Systen and Handler both inherit from the class Base.
I want to access those classes this way: System::DoStuff();
I also need the Handler be available in the System, but do not want to instantia... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T21:27:56.383",
"Id": "32390",
"Score": "2",
"body": "Static classes tend to quickly move you in the exact opposite direction as OOP. I have a feeling that there's a much better way to accomplish what you're doing, but after reading... | [
{
"body": "<p>I don't know if I'm just not understanding your situation properly or what, but I don't think converting three classes to static for one static method is really the right thing to do here. Why would you need to call <code>System::DoStuff()</code> statically? Why not just <code>$system->DoStuff(... | {
"AcceptedAnswerId": "20247",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T13:58:01.607",
"Id": "20225",
"Score": "1",
"Tags": [
"php",
"singleton",
"static"
],
"Title": "PHP my way of threating static classes"
} | 20225 |
<p>I made the popular Guess-The-Number game and included an AI version that picks random numbers. The AI version has slightly different <code>Console</code> output that differ slightly, for example:</p>
<pre><code>I generated a number between 1 and 100. Can you guess it?
You generated a number between 1 and 100. Let m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T15:57:59.707",
"Id": "32364",
"Score": "2",
"body": "Could you post the relevant code directly here?"
}
] | [
{
"body": "<p>I can't say that it's going to be more efficient, or better designed, but one option is to take advantage of polymorphism by creating a set of classes for this.</p>\n\n<pre><code>public abstract class GuessBase\n{\n protected abstract string GuessMessage { get; }\n protected abstract string Wr... | {
"AcceptedAnswerId": "20240",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T15:11:46.187",
"Id": "20229",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Combine similar methods with different text?"
} | 20229 |
<p>I have some sample code where I used <code>string.Format</code> but after reading about benchmark performances by other people I believe that it may be better to do multiple <code>appends</code> by a <code>StringBuilder</code></p>
<p>Here is the scenario:</p>
<p>In my <code>gridView</code>, I have a function calle... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T15:55:55.430",
"Id": "32363",
"Score": "0",
"body": "It doesn't directly matter how many times the function will be called. (And it's not even clear what exactly do you mean by that: Is that 10,000 times per year? Or per second? Or ... | [
{
"body": "<p>A <code>StringBuilder</code> is useful when you're constructing a <code>string</code> where a loop will be directly effecting it, i.e. if you were appending several strings together within a loop, I'd recommend using a <code>StringBuilder</code>. Here's an example of where you might use a <code>St... | {
"AcceptedAnswerId": "20235",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T15:15:18.153",
"Id": "20230",
"Score": "3",
"Tags": [
"c#",
"strings"
],
"Title": "Inefficient usage of string.format?"
} | 20230 |
<p>I have this working code. I think this must be easier with a while loop.</p>
<pre><code>if not c.e1.nil?
extrapreis = number_to_currency Extra.find(c.e1).aufschlag, :unit=>"EUR "
array.push Extra.find(c.e1).name + " (" + extrapreis.to_s + ")"
extpreis = extpreis + Extra.find(c.e1).aufschlag
end
if not c.e2... | [] | [
{
"body": "<p>I'd start with this untested code:</p>\n\n<pre><code>[c.e1, c.e2, c.e3, c.e4, c.e5].each do |e|\n if e\n extrapreis = number_to_currency(Extra.find(e).aufschlag, unit: 'EUR ')\n array << Extra.find(e).name + ' (' + extrapreis.to_s + ')'\n extpreis += Extra.find(e).aufschlag\n end\... | {
"AcceptedAnswerId": "20234",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-06T20:58:40.077",
"Id": "20232",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Dynamic variables in loop"
} | 20232 |
<p>This is intended to be a simpler replacement of <code>std::vector</code>, written for entertainment.
It should be as fast or faster than <code>std::vector</code>, but does not need to have as many features.</p>
<p>It should also be simple to use.</p>
<p>I am looking for a review on the following:</p>
<ul>
<li>Bug... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T20:18:29.917",
"Id": "32382",
"Score": "1",
"body": "For being _C++_ it looks a lot like _C#_... it even has some conceptual errors from thinking in _reference semantics_ instead of _value semantics_"
},
{
"ContentLicense": ... | [
{
"body": "<p>The first and most obvious disadvantage of your <code>Vector</code> is that it does not satisfy the standard requirements for a <em>Sequence</em>. That means that your <code>Vector</code> cannot be used with any of the <em>standard algorithms</em> nor with 3rd party algorithms designed to work wit... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T19:56:03.837",
"Id": "20243",
"Score": "4",
"Tags": [
"c++",
"vectors"
],
"Title": "Vector implementation - simple replacement"
} | 20243 |
<p>This is my implementation of Conway's Game of Life in JavaScript. While I know that it runs slowly, I do not ask for performance improvements, but for a review on the code quality in general from professional JavaScript programmers.</p>
<p>Working HTML/CSS/JS files can be found <a href="http://www.mediafire.com/?8... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T21:31:01.040",
"Id": "32392",
"Score": "0",
"body": "For a start, I'd get rid of the magic number."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T13:11:42.397",
"Id": "32422",
"Score": "0",
... | [
{
"body": "<p>There is a ton here, these are my 2 cents:</p>\n\n<ul>\n<li>Read about Model View Controller, and implement it</li>\n<li>More specifically, knowing the state of a cell by checking the class name is bad form</li>\n<li>Read about the cool Array functions that exist ( filter, forEach etc. ), they cou... | {
"AcceptedAnswerId": "31599",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T21:00:12.897",
"Id": "20250",
"Score": "3",
"Tags": [
"javascript",
"game-of-life"
],
"Title": "Main implementation of Game of Life"
} | 20250 |
<p>I am currently learning C++ (note: I am using C++11) and have begun working on a small project to practice what I've been learning. This project is a deck of cards that I hope to use later to create simple card games. I have created three classes: <code>Card</code> represents a single playing card, <code>CardStack</... | [] | [
{
"body": "<h3>Answers</h3>\n<blockquote>\n<p>Is there a better container choice than std::vector to hold Cards? If so, why?</p>\n</blockquote>\n<p>Depends.</p>\n<blockquote>\n<p>Should I be storing a pointer to Card rather than copies of Card in CardStack::cards?</p>\n</blockquote>\n<p>No. You should be storin... | {
"AcceptedAnswerId": "20265",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T23:09:36.130",
"Id": "20254",
"Score": "7",
"Tags": [
"c++",
"classes",
"c++11",
"playing-cards"
],
"Title": "Playing cards in C++"
} | 20254 |
<p>I use the following functions to encrypt my <code>$_GET</code> variables (whenever I can't easily get away with using <code>$_POST</code> or some other way of passing information between pages). </p>
<pre><code>function decryptStringArray ($stringArray, $key = "Your secret salt thingie")
{
$s = unserialize(rtri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T02:25:21.847",
"Id": "32404",
"Score": "3",
"body": "$_POST over HTTPS is the correct approach security and functionality wise. Encrypting GET variables is just reinventing the wheel, and what happens if you forget to encrypt a par... | [
{
"body": "<p>Agree 100% with Corbin. GET isn't something that is inherently secure, and trying to make it so is nigh impossible. That's what POST is for. Only use GET for non-sensitive information. That being said, there are some generally concerning bits to your code that could cause some people to downvote i... | {
"AcceptedAnswerId": "20279",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-07T23:42:53.893",
"Id": "20257",
"Score": "5",
"Tags": [
"php",
"strings",
"cryptography",
"url"
],
"Title": "Hiding $_GET variables using encryption"
} | 20257 |
<p>I wrote a simple script that converts a decimal to a mixed number, proper, or improper fraction depending on the inputed decimal.</p>
<p>It works but I think it could be improved as it hangs when large decimals are used. Please review and let me know how I could improve and simplify it. Thanks.</p>
<p>My script on... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-10T16:38:56.677",
"Id": "32647",
"Score": "0",
"body": "Why not use an existing fraction library instead? Here's one https://github.com/LarryBattle/Ratio.js"
}
] | [
{
"body": "<ol>\n<li><p><code>highestCommonFactor</code> should take 2 integers as parameter instead of relying on the variable <code>numerator</code> and `denominator'. Also, you could find it using <a href=\"http://en.wikipedia.org/wiki/Greatest_common_divisor#Using_Euclid.27s_algorithm\" rel=\"nofollow\">Euc... | {
"AcceptedAnswerId": "20261",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T00:36:45.253",
"Id": "20258",
"Score": "5",
"Tags": [
"javascript"
],
"Title": "Converting Decimals to Fractions with JavaScript - Simplify & Improve"
} | 20258 |
<p>I've put in quite a bit of hours on this BlackJack project for Codecademy to get it to the point where I'm satisfied with it. Before I move on to create the UI for it I would really appreciate feedback on things to improve, such as my use of classes and objects, best practices, etc. I'm including a link to my jsFidd... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T01:00:22.803",
"Id": "32399",
"Score": "1",
"body": "As stated in the FAQ, please include the code you would like reviewed in the question. http://codereview.stackexchange.com/faq#make-sure-you-include-your-code-in-your-question"
... | [
{
"body": "<blockquote>\n <p>Can you give me an example by refactoring one of the if statements? </p>\n</blockquote>\n\n<p>Your <code>Card</code> object can be changed as follows:</p>\n\n<p>Following your general style,</p>\n\n<pre><code>function Suit(name, sym) {\n this.getName = function () {\n ret... | {
"AcceptedAnswerId": "20267",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T00:38:44.963",
"Id": "20259",
"Score": "5",
"Tags": [
"javascript",
"game",
"playing-cards"
],
"Title": "Codecademy BlackJack project"
} | 20259 |
<p>I've developed mini utility, the source code can get reviewed here:</p>
<p><a href="http://rle.codeplex.com/SourceControl/BrowseLatest" rel="nofollow">http://rle.codeplex.com/SourceControl/BrowseLatest</a></p>
<p>It's developed in C#, in the general page there is a description.
I'm listening to well criticism to m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T01:32:53.617",
"Id": "32401",
"Score": "0",
"body": "If you want us to review your code, you need to post it here directly, not just link to it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T02:07:2... | [
{
"body": "<p><strong>MPEG?</strong></p>\n\n<p>I'm a little unclear where RLE comes into the MPEG codec, but if it does I would assume its based on binary encoding, not text based? In the same way as RLE formats for BMP's?</p>\n\n<p><strong>Streaming</strong></p>\n\n<p>Anything that processes information like t... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T00:54:07.400",
"Id": "20260",
"Score": "2",
"Tags": [
"c#",
".net"
],
"Title": "RLE encoding/decoding tool, review source"
} | 20260 |
<p>I am trying to wrap my head around how to properly use OOP in PHP when dealing with form submissions.</p>
<p>The example below is a form for editing course information. I have a class called Course which has methods for loading the class with information from the database and saving information into the database.</... | [] | [
{
"body": "<p>The <code>*_once()</code> versions of <code>require()</code> and <code>include()</code> are relatively slower and should be avoided. When just including a few files it wont be noticeable, but the more you add, the more it will stack up. There are some exceptions, but headers and footers shouldn't ... | {
"AcceptedAnswerId": "20292",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T02:34:12.143",
"Id": "20262",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"pdo",
"form"
],
"Title": "How to properly use OOP in PHP with forms"
} | 20262 |
<p>I am a JavaScript beginner. Here's a fictional example which isolates the functionality mentioned in the subject line. I hope to employ this functionality as part of a larger web application in the real world soon.</p>
<p><a href="http://illumin-8.com/lunchtime/addingelements.html" rel="nofollow">Live example here<... | [] | [
{
"body": "<p>You should probably have a look at <a href=\"https://stackoverflow.com/questions/5805059/select-placeholder#answer-8442831\">https://stackoverflow.com/questions/5805059/select-placeholder#answer-8442831</a> and make the first line non-selectable by HTML only.</p>\n\n<p>It's done by making the firs... | {
"AcceptedAnswerId": "20271",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T02:57:57.393",
"Id": "20263",
"Score": "3",
"Tags": [
"javascript",
"beginner",
"html",
"html5",
"form"
],
"Title": "Using JavaScript to add and delete rows from an HTM... | 20263 |
<p>I'm trying to write a simple <a href="https://en.wikipedia.org/wiki/Triplestore" rel="nofollow">triplestore</a> in Common Lisp that will store <a href="https://en.wikipedia.org/wiki/Resource_Description_Framework" rel="nofollow">triples</a> in the form subject-predicate-object. The code is inspired by the book <a hr... | [] | [
{
"body": "<p>First of all, I suggest that you use a structure instead of a hash table when you know that the table will only have 3 elements; this improves both readability and performance:</p>\n\n<pre><code>(defstruct triplestore-graph \n (spo (make-hash-table))\n (pos (make-hash-table))\n (osp (make-hash-... | {
"AcceptedAnswerId": "20305",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T06:25:26.590",
"Id": "20266",
"Score": "2",
"Tags": [
"common-lisp",
"macros",
"hash-map"
],
"Title": "Simplify complex hash-table manipulations in Common Lisp"
} | 20266 |
<p>I have this question in my exam and I want to know if my answer is correct.</p>
<p>Consider the following program written in C language to implement a reader:</p>
<pre><code>// to simplify the exercise, are not checked the return values of calls to the operating system
int main(int argc, char* argv[]) {
s... | [] | [
{
"body": "<pre><code>int fd, readcount;\n// ...\nreadcount=mmap(0,sizeof(int),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);\n</code></pre>\n\n<p>If this is the code you're using, it probably gave you a warning which you ignored. <code>mmap</code> returns <code>void *</code>. You should change the declaration of <co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T15:06:33.837",
"Id": "20272",
"Score": "2",
"Tags": [
"c"
],
"Title": "Processes and semaphores in C"
} | 20272 |
<p>I have this working code for C++ state machine using STL (not using boost state chart).</p>
<p>The purpose of posting is two-fold:</p>
<ol>
<li><p>To share a simple and working code C++ state machine using the STL for the sparse 'state' and 'event' function matrix.</p></li>
<li><p>To seek enhancements of implement... | [] | [
{
"body": "<h2>Two beginners mistakes:</h2>\n\n<h3>Leading underscore in identifers</h3>\n\n<pre><code>#ifndef _BasicFsmT_h\n#define _BasicFsmT_h\n</code></pre>\n\n<p>Using a leading underscore is a bad idea. The exact rules are complex and people usually get them wrong. So just don't use them and you will be s... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T15:21:18.887",
"Id": "20273",
"Score": "8",
"Tags": [
"c++",
"stl",
"state-machine"
],
"Title": "Designing a state machine in C++ using the STL"
} | 20273 |
<p>I wrote code that queries a data structure that contains various triples - 3-item tuples in the form subject-predicate-object. I wrote this code based on an exercise from <em><a href="http://shop.oreilly.com/product/9780596153823.do" rel="nofollow noreferrer">Programming the Semantic Web</a></em> textbook.</p>
<pre... | [] | [
{
"body": "<ol>\n<li>Your code would be helped by splitting parts of it out into functions.</li>\n<li>Your <code>continue</code> statement does nothing</li>\n<li>Rather then having a special case for the first time through, initialize <code>bindings</code> to <code>[{}]</code> for the same effect. </li>\n</ol>\... | {
"AcceptedAnswerId": "20295",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-08T16:48:24.977",
"Id": "20278",
"Score": "3",
"Tags": [
"python",
"functional-programming"
],
"Title": "Querying a data structure that contains various triples"
} | 20278 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.