body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I have an extension method that does this:</p>
<pre><code>public static IEnumerable<T> ToIEnumerable<T>(this T source) where T : new()
{
return new[] { source };
}
</code></pre>
<p>I need to be able to convert any object to an <code>IEnumerable</code>.</p>
<p>For example when I use the .NET <code>... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-20T09:19:26.303",
"Id": "1591",
"Score": "0",
"body": "Doesn't the first method return an array of T while the second one returns an IEnumerable of T?"
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-23T10:3... | [
{
"body": "<p>I don't see why not.</p>\n\n<p>If you wanted to be 'monadically pure', you could call it <code>Return</code> (because in monads, the function which performs <code>'a -> M 'a</code> is called <code>return</code>).</p>\n\n<p>(See <a href=\"https://stackoverflow.com/questions/1577822/passing-a-sin... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-18T12:17:19.520",
"Id": "836",
"Score": "4",
"Tags": [
"c#",
"linq",
"ienumerable"
],
"Title": "Is ToIEnumerable<T> good practice?"
} | 836 |
<p>I think there are some confusing and weird indentation problems in this WordPress file (single.php). Any suggestions on improving indentation and readability?</p>
<pre><code><?php
/**
* The Template for displaying all single posts.
*
* @package WordPress
* @subpackage Starkers
* @since Starkers 3.0
*/
get... | [] | [
{
"body": "<pre><code><?php // Start The Loop\n if ( have_posts() ) while ( have_posts() ) : the_post();\n?> <div class=\"block-2 padding-top no-overlay\">\n <?php the_content(); ?>\n </div><!-- .entry-content -->\n<?php endwhile; // end of the loop. ?> \n</code>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-18T12:51:36.253",
"Id": "837",
"Score": "5",
"Tags": [
"php",
"wordpress"
],
"Title": "Displaying all single posts"
} | 837 |
<p>I'm new to Java and find it hard to grasp the concept of objects. I wrote a simple guessing game to practice the concept of OO programming but I am not sure if I am doing it correctly. </p>
<p>The objective of the game is to guess a number from 0-9 with 3 players and the first player who guesses it correctly will w... | [] | [
{
"body": "<p>The layout felt very C++ and very connected to \"functions\" instead of objects. Though you seem to got a nice idea of how it's work and do a lot better at objects than most people do.</p>\n\n<p>I would do it like this (dirty version, should be improved, but it was a quick redesign):</p>\n\n<pre><... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-19T10:18:26.970",
"Id": "850",
"Score": "15",
"Tags": [
"java",
"object-oriented",
"game",
"swing"
],
"Title": "Guessing game - am I using the concept of objects in Java properly... | 850 |
<p>So... I have a program in which I want to flip heads three times in the row.</p>
<p>What I'm asking for is for proposals of other solutions for this program, in pro way, as You do in natural sense.</p>
<p>That's my code as Java novice.</p>
<pre><code>/*
* File: ConsecutiveHeads.java
* ----------------
* This p... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-19T17:01:11.933",
"Id": "1587",
"Score": "0",
"body": "Unless you need cryptographic stength randomness, this approach is good."
}
] | [
{
"body": "<p>Some things you could consider</p>\n\n<ul>\n<li>make the starting class a simple program which calls other methods and/or classes to do most of the work.</li>\n<li>if you want something more general, you could use an abstract output stream so it can be captured or even use a Listener interface.</l... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-19T16:57:29.663",
"Id": "855",
"Score": "4",
"Tags": [
"java",
"homework"
],
"Title": "\"Consecutive Heads\" program"
} | 855 |
<p>I've got this javascript function which was written a bit ad-hoc and I'm not really sure how to go about refactoring and improving it.</p>
<p>It's basically an implementation of <a href="http://wiki.commonjs.org/wiki/Unit_Testing/1.1">draft Unit-Testing/1.1</a> specification.</p>
<pre><code>// Runs the object as a... | [] | [
{
"body": "<p>I would start out by cleaning the code along these lines:</p>\n\n<ol>\n<li>Refactor variable names and functions so as to limit the use comments (<em>code doesn't' lie, comments sometimes do</em>)</li>\n<li>Use better descriptive names (fx <strong>key/val</strong> relates to test's in your code bu... | {
"AcceptedAnswerId": "1825",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-19T17:19:48.293",
"Id": "856",
"Score": "20",
"Tags": [
"javascript",
"unit-testing"
],
"Title": "Unit-testing function"
} | 856 |
<p>I feel like I can make my switch statements more elegant with a function pointer, i.e. I'd like to set the <code>digestLength</code> and a pointer to a function in the same switch statement instead of setting the length, declaring the result array, then calling the function.</p>
<pre><code>- (NSString *)hashWithDig... | [] | [
{
"body": "<p>I can't write the code in Objective-C, but in C, you could create yourself a structure type to get the information in one move. I don't know whether the NSStringDigestTypeXXX values are conveniently numbered compactly from 0 or 1, so I'm taking the pessimistic view that they are not. You can sim... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-19T18:05:21.783",
"Id": "858",
"Score": "6",
"Tags": [
"c",
"objective-c"
],
"Title": "Function pointers and switch statements"
} | 858 |
<p>I was bored over the last couple of days and wrote up a string interpolation library for JavaScript.</p>
<p>I'm very pleased with its functionality, it passes it <a href="https://github.com/BonsaiDen/Fomatto/blob/master/test/test.js" rel="nofollow">79 tests</a> cross browser and the comments and <a href="https://gi... | [] | [
{
"body": "<p>I have not looked at your regexes in detail. Could you please explain them? The rest of the code could use better documentation as well.</p>\n\n<p>I did find two serious code correctness issues:</p>\n\n<ol>\n<li><p>Your <code>:join()</code> formatter will not work with the empty string as the deli... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-19T19:06:14.757",
"Id": "860",
"Score": "11",
"Tags": [
"javascript",
"strings",
"formatting",
"library"
],
"Title": "String interpolation library"
} | 860 |
<p>Writing a new site, has anyone got any comments on the HTML here? Is it all semantically correct? Thanks! This will basically be the template, so I want to make sure it's pretty perfect.</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<title>Welcome to Scirra.com</title>
<me... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-20T22:51:25.903",
"Id": "1613",
"Score": "0",
"body": "Why such a short DOCTYPE?"
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-20T23:03:22.870",
"Id": "1615",
"Score": "6",
"body": "@Peter I w... | [
{
"body": "<p>Looks like a lot of extra <code><div></code>s, as far as I can see. Why do you have <code>.footer</code> and <code>.footerContent</code>? Generally a <code><div></code> without any siblings can be killed.</p>\n\n<p>And that header looks really out of control. Any reason for wrapping th... | {
"AcceptedAnswerId": "884",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-20T20:59:18.157",
"Id": "866",
"Score": "12",
"Tags": [
"html",
"html5",
"template"
],
"Title": "HTML Review of template for site - Is this ok for HTML5?"
} | 866 |
<p>We're calculating entropy of a string a few places in Stack Overflow as a signifier of low quality.</p>
<p>I whipped up this simple method which counts unique characters in a string, but it is quite literally the first thing that popped into my head. It's the "dumbest thing that works".</p>
<pre><code>/// <summ... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-20T21:25:37.800",
"Id": "1603",
"Score": "0",
"body": "Why a `Dictionary` as opposed to a `List`?"
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-20T21:26:05.693",
"Id": "1604",
"Score": "0",
"b... | [
{
"body": "<pre><code>public static int Entropy(this string s)\n{\n HashSet<char> chars = new HashSet<char>(s);\n return chars.Count;\n}\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-21T17:56:22.177",
"Id": "1642... | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-20T21:21:40.627",
"Id": "868",
"Score": "241",
"Tags": [
"c#",
"strings"
],
"Title": "Calculating entropy of a string"
} | 868 |
<p>I often run into the problem of producing a javascript array on an ASP.net page from an IEnumerable and I was wondering if there was an easier or clearer way to do it than</p>
<pre><code><% bool firstItem = true;
foreach(var item in items){
if(firstItem)
{
firstItem = false;
}
... | [] | [
{
"body": "<p>With a bit of help from System.Linq this becomes quite easy.</p>\n\n<pre><code>var array = [ <%= \n string.Join(\",\", items.Select(v => \"'\" + v.ToString() + \"'\").ToArray()) \n%> ];\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 2.5",
"Cre... | {
"AcceptedAnswerId": "887",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-20T22:34:53.247",
"Id": "881",
"Score": "9",
"Tags": [
"c#",
"javascript",
"asp.net"
],
"Title": "Is there a better way to output a javascript array from ASP.net?"
} | 881 |
<p>Here's my code:</p>
<pre><code>public static void CopyStream(Stream input, Stream output)
{
var size = 8192;
var inBuffer = new byte[size];
var outBuffer = new byte[size];
IAsyncResult writeAsync = null;
int count;
while (true)
{
var readAsync = input.BeginRead(inBuffer, 0, si... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-21T01:34:25.333",
"Id": "1621",
"Score": "0",
"body": "This is a cross-post of http://stackoverflow.com/questions/5061345/, but I'm not sure how to handle the closing of the other site's question."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>It's not entirely clear what your goals are with this bit of code. Three possibilities that come to mind:</p>\n\n<ul>\n<li>CopyStream should be asynchronous. As written, it does not meet this goal since it blocks on the results of EndRead and EndWrite. If this is your goal, you need to use call... | {
"AcceptedAnswerId": "893",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-21T01:33:23.120",
"Id": "888",
"Score": "10",
"Tags": [
"c#",
"asynchronous"
],
"Title": "Am I overlooking anything with this asynchronous read/write loop?"
} | 888 |
<p>I want to create a validation wherein blank entries will not be accepted. So if I call this code:</p>
<pre><code>entry[i].setName(JOptionPane.showInputDialog("Enter Name: "));
if the entry is blank, it will not be accepted and an error will prompt:
</code></pre>
<p>it cannot accept blank entries. Of course it coul... | [] | [
{
"body": "<p>Extract the input code into a method:</p>\n\n<pre><code>String getNonBlankInput(String prompt) {\n String input = JOptionPane.showInputDialog(prompt);\n\n while (input.equals(\"\")) {\n JOptionPane.showMessageDialog(null, \"Cannot accept blank entries!\");\n input = JOptionPane.showI... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-21T02:07:04.827",
"Id": "889",
"Score": "6",
"Tags": [
"java",
"beginner",
"validation"
],
"Title": "Data validation for preventing blank entries"
} | 889 |
<p>I have created a <code>HashMap<string,int></code> in C++. I would like help determining if it is good or bad.</p>
<p>I have not handled the errors or successes with messages. I have also not implemented the load factor in this map. As of now, once the size limit is reached, no more keys are accepted. I have w... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-21T04:10:48.710",
"Id": "1627",
"Score": "5",
"body": "I suggest you look at the boost implementation of a TR1 unordered_map."
}
] | [
{
"body": "<blockquote>\n <p>How to implement the load factor concept, because the hash function o/p is dependent on the previous table size. If we are to change the table size, the old <code><key, value></code> pair will be lost.</p>\n</blockquote>\n\n<p>You will need to rehash when the table size chang... | {
"AcceptedAnswerId": "924",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-21T03:17:14.243",
"Id": "892",
"Score": "11",
"Tags": [
"c++",
"hash-map"
],
"Title": "Improving HashMap in C++"
} | 892 |
<p>I have this piece of code I would like some help with. I'm running a lengthy process that I want to interrupt at any time. The thing is, as you can see in the code, I have <code>if(stop)</code> everywhere, also in the methods inside the <code>for</code> (since they have <code>for</code> loops also).</p>
<p><code>st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-07T18:27:05.163",
"Id": "107105",
"Score": "0",
"body": "You can also look into using a cancellation token instead (http://msdn.microsoft.com/en-us/library/dd997396(v=vs.110).aspx)."
}
] | [
{
"body": "<p>Any answer given will be completely conditional. Can you be sure that stopping after step B will not have dire consequences related to the fact that step A was completed successfully? I recommend you break each section into work that must be completed with a chance to terminate before entering. Th... | {
"AcceptedAnswerId": "907",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-21T15:57:50.980",
"Id": "899",
"Score": "11",
"Tags": [
"c#"
],
"Title": "Interrupt lengthy for loops"
} | 899 |
<pre><code>public static class StringHelpers
{
public static string CapitalizeEachWord(this string sentence)
{
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;
if (String.IsNullOrEmpty(sentence))
{
return String... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-12T16:26:14.083",
"Id": "38729",
"Score": "0",
"body": "`ToTitleCase()` won't *uncapitalize* words that are in all caps. You should call it on the `.ToLower()` version of the string."
}
] | [
{
"body": "<p>You're right, your second method is way too complicated. It also doesn't handle the case where the string starts with a space (in which case <code>words[0]</code> will be the empty string and <code>letters[0]</code> will be out of bounds). Since all your method seems to be doing is to capitalize t... | {
"AcceptedAnswerId": "903",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-21T16:25:14.313",
"Id": "900",
"Score": "8",
"Tags": [
"c#",
"strings",
"extension-methods"
],
"Title": "Capitalize words in sentence"
} | 900 |
<p>I wrote as an exercise in Test-Driven Development a piece of Python code that contains two functions:</p>
<ul>
<li><code>roman2dec(roman)</code>, that converts a roman number (string) into a decimal number (int)</li>
<li><code>dec2roman(dec)</code>, that converts a decimal number (int) into a roman number (string)<... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-22T10:03:21.253",
"Id": "1661",
"Score": "0",
"body": "Make this into an extension module? http://www.ioccc.org/1987/wall.c (izajoke)"
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-22T10:56:05.373",
"I... | [
{
"body": "<p>First of all you should document the fact that your code does not work with numbers above 9999.</p>\n\n<p>Then I think your code will become a bit simpler, if you add a fourth row to your <code>d2r_table</code> for the thousands. To avoid repetition you can use a list comprehension:</p>\n\n<pre><c... | {
"AcceptedAnswerId": "905",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-21T16:54:18.110",
"Id": "902",
"Score": "10",
"Tags": [
"python",
"unit-testing",
"converting"
],
"Title": "Conversion from/to roman numbers"
} | 902 |
<p>I've gone back and forth a few times recently on my Perl coding style when it comes to module subroutines. If you have an object and you want to call the method <code>bar</code> with no arguments, then you can either do <code>$foo->bar()</code> or <code>$foo->bar</code>. At one point I started favoring the lat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T21:15:13.767",
"Id": "23449",
"Score": "0",
"body": "It's a very good idea not to underestimate the importance of readability to others, most probably not so informed about the aim of the program and/or the language. **Especially**... | [
{
"body": "<p>Because either is technically acceptable, you are right that it is a style issue and simply a case of choosing a coding convention.</p>\n\n<p>However, I think that you have hit a very important point. So few other languages that use parentheses for functions allow a parameterless function call wit... | {
"AcceptedAnswerId": "911",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-21T20:25:26.630",
"Id": "906",
"Score": "9",
"Tags": [
"perl",
"bioinformatics"
],
"Title": "Analyzing genetic tags"
} | 906 |
<p>I am creating a tab plugin. I want to know if there is a better way of doing this or if what I have is good. It works just fine, but there may be some shortcuts or a more optimized way of accomplishing this. I plan to replace the <code>startTab</code> variable with an options set, but I am not quite there yet.</p>
... | [] | [
{
"body": "<p>You could remove tab navigation from html and create it dynamically in plugin so the html will look like this:</p>\n\n<pre><code><div id=\"rfiTabs\">\n <div class=\"tabViews\" style=\"\">\n <div id=\"rfiBasic\">Test</div>\n <div id=\"rfiHome\">test this</div... | {
"AcceptedAnswerId": "910",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-21T20:42:20.877",
"Id": "908",
"Score": "5",
"Tags": [
"javascript",
"optimization",
"jquery",
"css",
"plugin"
],
"Title": "Creating a tab plugin"
} | 908 |
<p>Here is a snippet of code that generates a thumbnail from a given file. It works well, but is much slower than desired. Without using an external library (which I'm trying to avoid for learning purposes), is there anything that can be done to increase the speed?</p>
<p>I know the fastest way would be to retrieve ... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-22T13:07:59.917",
"Id": "1672",
"Score": "0",
"body": "Have you tried `image.getScaledInstance(thumbWidth, thumbHeight, Image.SCALE_FAST);`?"
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-23T18:41:20.397",... | [
{
"body": "<p>You probably reached the maximum speed you can achieve with the API you are using. You could try the following extra hints, just in case they’re not the default values:</p>\n\n<pre><code>g2dBuffer.setRenderingHint(RenderingHints.KEY_RENDERING,\n Renderi... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-21T22:11:42.180",
"Id": "912",
"Score": "6",
"Tags": [
"java",
"optimization",
"image"
],
"Title": "Optimized thumbnail generation"
} | 912 |
<p>I am using the JSON output of the MediaWiki API documented <a href="https://www.mediawiki.org/wiki/API:Main_page" rel="nofollow noreferrer">here</a> and <a href="https://en.wikipedia.org/w/api.php" rel="nofollow noreferrer">here</a>, and I have found that for Boolean values, it often returns an empty string if true ... | [] | [
{
"body": "<p>It is certainly better. You can improve it further:</p>\n\n<ol>\n<li>Use early exits to reduce arrow code.</li>\n<li>Use a JSON initializer for the result.</li>\n<li>Prefix boolean names with 'is'.</li>\n<li>Fix the 'user.lastEdited' bug.</li>\n</ol>\n\n<p>.</p>\n\n<pre><code>function processRespo... | {
"AcceptedAnswerId": "1035",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-22T04:03:59.627",
"Id": "916",
"Score": "8",
"Tags": [
"javascript",
"json"
],
"Title": "Processing an API's JSON response"
} | 916 |
<p>I have been generating English-language text from some machine-readable data, but now I want internationalization of my script to be relatively easy. The challenge is that some data might be missing and thus should be omitted from the output, possibly precluding any approach involving just "plugging in" numbers.</p>... | [] | [
{
"body": "<p>I see a couple of potential issues with regards to internationalization:</p>\n\n<ul>\n<li><p>pluralization is more complex than <code>(qty == 1 ? singular : plural)</code>. What about the value 0? Also in some languages, <a href=\"http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_... | {
"AcceptedAnswerId": "1013",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-22T04:17:43.040",
"Id": "917",
"Score": "8",
"Tags": [
"javascript"
],
"Title": "Generating readable text in a human language from machine-readable data"
} | 917 |
<p>The following extension method is being used in our code base:</p>
<pre><code>public static bool ToBool(this object src)
{
return src != null && ((string) src).ToBool(false);
}
</code></pre>
<p>It leverages off another extension method:</p>
<pre><code>public static bool ToBool(this string src, bool de... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-22T11:04:19.297",
"Id": "1665",
"Score": "1",
"body": "This does seem rather strange and unconventional - so you're basically treating null, 0, \"\", and \"0\" as false, and all other numbers as true. What is the reasoning behind this... | [
{
"body": "<p>I'd criticize:</p>\n\n<ul>\n<li>Extension methods on \"object\" should be avoided because of the broad scope, except for special cases (which such a \"ToBool\" method is not one). It also feels like an overuse of extension methods.</li>\n<li>The first one takes an \"object\", but really wants a st... | {
"AcceptedAnswerId": "921",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-22T10:50:10.730",
"Id": "920",
"Score": "8",
"Tags": [
"c#",
"extension-methods"
],
"Title": "Converting objects to type Bool"
} | 920 |
<p>I am implementing the command pattern in a project that I am working on and I have an interface, <code>ICommandFactory</code> that all of my commands are implementing. </p>
<p>When I run the application I want to dynamically gather all classes in the current assembly that implement that interface, thus producing a ... | [] | [
{
"body": "<p>Your code seems to do what it is supposed to do.</p>\n\n<p>I'm worried about the fact that you're hinting at the possibility of having multiple <code>CommandFactory</code> classes. Why would you want that? (I'm just asking. You might have very valid reasons.)</p>\n\n<p>I'm also wondering if you ac... | {
"AcceptedAnswerId": "933",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-22T20:57:16.000",
"Id": "928",
"Score": "6",
"Tags": [
"c#",
"design-patterns"
],
"Title": "IEnumerable of classes that implement a given interface at runtime"
} | 928 |
<p>I am stuck with this horrible object model coming back from a 3rd party product. It's six levels of objects deep, and I have to loop through the collection in each level, to get the values I need, in order to produce a small object model that I actually require.</p>
<p>The code ends up looking like this (with vari... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-22T22:13:05.133",
"Id": "1684",
"Score": "0",
"body": "Is it safe to assume that each layer does not implement `IEnumerable<T>`?"
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-22T22:40:18.610",
"Id": "... | [
{
"body": "<p>If you extract the innermost nested part as its own method that takes a LevelSixKey as its parameter, then create your own Enumerator over levelSixItems, the product of which is the same as all your nesting (and, honestly, simply moved all the nesting into it - or added to a list at the inside of ... | {
"AcceptedAnswerId": "942",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-22T21:41:01.967",
"Id": "931",
"Score": "11",
"Tags": [
"c#",
".net"
],
"Title": "Deep nesting when looping over an object model coming from a 3rd part"
} | 931 |
<p>I implemented a multistep form with the method described by Ryan Bates in <a href="http://www.asciicasts.com/episodes/217-multistep-forms" rel="nofollow">ep217</a> but I had some weird behavior when refreshing or moving between the steps <a href="http://rubyglasses.blogspot.com/2007/08/actsasgoodstyle.html" rel="nof... | [] | [
{
"body": "<p>I can't speak for that particular Railscast episode, but rails provides an idiomatic way to deal with validation errors. Taking your code as an example, I'd change it to look like this (using Rails 4.2):</p>\n\n<p><strong>app/controllers/profiles_controller.rb:</strong></p>\n\n<pre><code>class Pro... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-22T22:16:02.330",
"Id": "935",
"Score": "7",
"Tags": [
"ruby",
"ruby-on-rails",
"form"
],
"Title": "Developing a multistep form"
} | 935 |
<p>This is some Erlang code I wrote to output a string of all the IP addresses of the machine. The string is simply printed to the user for him to read.</p>
<pre><code>-module(ip).
-export([get_ip_address_string/0]).
get_ip_address_string() ->
{ok, IPAddress} = inet:getif(),
filter_ip_address(IPAddress).
... | [] | [
{
"body": "<p>First of all your variable <code>IPAddress</code> is misnamed. It sounds as if it contained a single IP address, but in fact it contains a list of multiple triples, where each one does not only contain an IP address, but also the corresponding broadcast address and netmask. You should probably cal... | {
"AcceptedAnswerId": "944",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-23T02:21:09.943",
"Id": "940",
"Score": "7",
"Tags": [
"functional-programming",
"erlang",
"ip-address"
],
"Title": "Erlang code to list all IP addresses"
} | 940 |
<p>I have written an Android application which downloads pdf files through web service. I am using kSoap2 android library to parse the response of web service which basically contains file name & file data. </p>
<p>I have written following code. Please review & tell how to increase the speed I think there is s... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-14T07:12:54.743",
"Id": "2234",
"Score": "2",
"body": "what are the sizes of these pdf's? you're buffering the entire things in memory before writing them out; I suspect even without your System.gc's to spice things up, you observe lo... | [
{
"body": "<ol>\n<li><p>Forcing <code>System.gc()</code> isn't a good practice.</p></li>\n<li><pre><code>outputStream = new FileOutputStream(pdfFile);\n bufferedOutputStream = new BufferedOutputStream(outputStream);\n</code></pre>\n\n<p>should be wrapped into 1 variable to do a single <code>close()</code... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-23T10:16:10.800",
"Id": "943",
"Score": "7",
"Tags": [
"java",
"android",
"soap"
],
"Title": "How to increase download speed using the following method?"
} | 943 |
<p>Trying to refactor this code and can't seem to think of a way to make it cleaner. <code>Type</code> is a property in my <code>Person</code> class.</p>
<pre><code>foreach (var item in list)
{
if (person.Type != PersonType.Employee && person.Type != PersonType.Manager && person.Type != PersonType... | [] | [
{
"body": "<p>I would probably go with code that looked like this.</p>\n\n<pre><code>list.ForEach(c => \n {\n if (DoAction(c.Type))\n {\n DoSomething();\n }\n });\n\n\nprivate static bool DoAction(Pe... | {
"AcceptedAnswerId": "953",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-23T15:10:37.940",
"Id": "946",
"Score": "8",
"Tags": [
"c#",
".net"
],
"Title": "Refactoring a bunch of and statements"
} | 946 |
<p>I am not very good with thread-safety and often fall prey to subtle issues in concurrency. Therefore, I hope that someone here might be able to tell me whether there is a subtle concurrency issue (race condition etc.) in the following code, or whether it’s fine. In particular, have I used <code>Monitor.Wait</code> a... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-23T18:56:24.593",
"Id": "1714",
"Score": "0",
"body": "This seems instinctively to be a serious misuse of Streams. When you start calling NotImplementedException in so many places, you need to question your approach. Given that you can... | [
{
"body": "<p>Depends what you're trying to do. Is it really possible to have multiple Read threads, as the comment suggests? If so then you're going to run a risk of having several Reads released at once and return in the wrong order. If not then why use <code>PulseAll</code> as opposed to <code>Pulse</code>?<... | {
"AcceptedAnswerId": "959",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-23T18:31:05.457",
"Id": "956",
"Score": "7",
"Tags": [
"c#",
"multithreading",
"thread-safety",
"stream"
],
"Title": "Implementation of costreams"
} | 956 |
<p>I have to generate a sequential number for <strong>groovy-grails</strong> app wide use and came up with the following. However, is there a better way to do this?</p>
<p>Domain classes:</p>
<pre><code>class RoastIdCounter {
int counter =0
static constraints = {
}
}
</code></pre>
<p>This one has no vie... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-30T23:43:53.077",
"Id": "68201",
"Score": "0",
"body": "Can you not simply declare the column in the db as auto increment?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-31T12:02:54.837",
"Id": "68301"... | [
{
"body": "<p>Have you considered using an <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicLong.html\" rel=\"nofollow\">AtomicLong</a> instead of the RoastIdCounterService? You can then call <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/Atomi... | {
"AcceptedAnswerId": "40997",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-23T20:04:32.897",
"Id": "958",
"Score": "9",
"Tags": [
"groovy",
"grails"
],
"Title": "Generating a sequential number for app-wide use"
} | 958 |
<p>I have a hierarchy of of groups, and I want to get a collection of all the lowest level groups (or leaves if we'll look at this as a tree).</p>
<p>I wrote the following code. Is it inefficient?</p>
<pre><code>public static class FeatureWeightGroupExtensions
{
public static IEnumerable<IFeatureWeightGroup>... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-24T15:35:19.190",
"Id": "1728",
"Score": "1",
"body": "Wow, I kept reading it as *feather weight* until I realised it says **feature** :-D"
}
] | [
{
"body": "<pre><code>return featureWeightGroup.ChildGroups.Aggregate(Enumerable.Empty<IFeatureWeightGroup>(),\n (allGroups, group) =>\n allGroups.Concat(GetLeafGroupsRecursive(group)));\n</code></pre>... | {
"AcceptedAnswerId": "969",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-24T10:04:59.017",
"Id": "966",
"Score": "5",
"Tags": [
"c#",
"linq",
"recursion"
],
"Title": "Is this Recursion + Linq example inefficient?"
} | 966 |
<p>I need to parse an invalid JSON string in which I find many repetitions of the same key, like the following snippet:</p>
<pre><code>[...]
"term" : {"Entry" : "value1", [.. other data ..]},
"term" : {"Entry" : "value2", [.. other data ..]},
[...]
</code></pre>
<p>I thought of appending a suffix to each key, and I d... | [] | [
{
"body": "<pre><code>import json\n\ndef fixup(pairs):\n return pairs\n\ndecoded = json.loads(bad_json, object_pairs_hook = fixup)\n</code></pre>\n\n<p>object_pairs_hook is a more recent addition. If you have an older version of python you may not have it. The resulting python object will contain lists of pai... | {
"AcceptedAnswerId": "974",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-24T13:03:07.473",
"Id": "968",
"Score": "5",
"Tags": [
"python",
"parsing",
"strings",
"json"
],
"Title": "Substitution of different occurrences of a string with changing patter... | 968 |
<p>I'm quite new to JavaScript, and I'd like a review of the code structure and syntax. It serves <a href="http://florent2.github.com/test-regexp-online/" rel="nofollow">this little online regexp test</a> (still a work in progress).</p>
<p>The whole code (JavaScript, CSS & HTML) <a href="https://github.com/Florent... | [] | [
{
"body": "<p>This code looks fine to me for a toy project. I especially appreciate the long names for identifiers.</p>\n\n<p>Now, it could look better:</p>\n\n<ul>\n<li><p>with more comments. You should describe the intent (the why behind the how) and the expected use case for the function: type and range of v... | {
"AcceptedAnswerId": "1014",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-24T15:41:31.883",
"Id": "972",
"Score": "7",
"Tags": [
"javascript",
"jquery"
],
"Title": "JavaScript portion of regexp tester"
} | 972 |
<p>As I'm creating a 3D Tic-Tac-Toe game, I'm having several modules inside my JavaScript application. For example, there is a 3D module which handles perspective calculations, whereas a Multiplayer module manages everything with relation to online playing.</p>
<p>Is it good practice to put functions of each module in... | [] | [
{
"body": "<p>I would recommend you use a closure like this:</p>\n\n<pre><code>var Obj = (function() {\n var privateState = null;\n return {\n A: 1,\n B: true,\n C: function() {\n return privateState; \n } \n };\n})();\n</code></pre>\n\n<p>The biggest reason w... | {
"AcceptedAnswerId": "976",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-24T18:30:22.743",
"Id": "975",
"Score": "10",
"Tags": [
"javascript"
],
"Title": "Separating and organising modules with objects?"
} | 975 |
<p>I am building a query that could end up look like this:</p>
<pre><code>SELECT "patients".* FROM "patients"
INNER JOIN "users" ON "users"."id" = "patients"."user_id"
WHERE (users.username LIKE '%Bob%' AND users.last_name LIKE '%Smith%'
AND users.active = '1' AND users.disabled = '1')
ORDER BY users.first_name DE... | [] | [
{
"body": "<p>First of all be very careful when building queries from request data. When building your <code>where</code> string, you're using parametrized queries, so that's fine. But in your <code>order</code> string, you're building actual SQL code from data you directly take out of <code>params</code>. Do N... | {
"AcceptedAnswerId": "979",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-24T22:49:56.587",
"Id": "977",
"Score": "5",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Ruby on rails complex select statement...there has to be a better way!"
} | 977 |
<pre><code><% i = 0 %>
<% @patients.each do |patient| %>
<tr class="<%= i % 2 == 0 ? 'Even' : 'Odd' %>">
<td><%= link_to patient.id, patient %></td>
<td><%= patient.user.username %></td>
<td><%= patient.user.first_name %></td>
... | [] | [
{
"body": "<p>First of all ruby has an <code>each_with_index</code> method, so you can do <code>@patients.each_with_index do |patient, i|</code> instead of keeping a counter manually.</p>\n\n<p>However with the conditional inside the loop that is still too much logic for the view in my opinion. What I'd do is d... | {
"AcceptedAnswerId": "982",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-24T23:18:49.393",
"Id": "978",
"Score": "6",
"Tags": [
"ruby",
"html",
"ruby-on-rails"
],
"Title": "Rails view to list users in a zebra-striped table"
} | 978 |
<p>Basically, I'm uploading an excel file and parsing the information then displaying what was parsed in a view.</p>
<pre><code>using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.Mvc;
using QuimizaReportes.Models;
using System.Collections.Generic;
using System;
namespace QuimizaReportes.Co... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-25T02:26:26.883",
"Id": "1761",
"Score": "0",
"body": "Should I call another Action, \"UploadComplete\" and **have that** callthe UploadComplete view instead of calling a View directly from the [POST]Index action? When do I know whethe... | [
{
"body": "<p>The logic for reading the Excel file (i.e. everything from <code>var connectionString</code> until before the <code>return</code>) belongs in a model method, not the controller.</p>\n\n<p>You might also want to handle the case when the uploaded file isn't an Excel file or it doesn't have the colum... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-25T02:25:03.077",
"Id": "981",
"Score": "6",
"Tags": [
"c#",
"mvc",
"asp.net-mvc-3",
"controller"
],
"Title": "Not feeling 100% about my Controller design."
} | 981 |
<p>I am been using a code pattern for recursive database actions in my applications.</p>
<p>I create two class objects of a database table, singular one (e.g Agent) for holding single record with all fields definition, plural one (e.g Agents) for database actions of that records like, select, insert, delete, update et... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-02T13:58:13.827",
"Id": "16819",
"Score": "1",
"body": "Just for clean up: 1. to see how to do generics in VB.Net ( see http://msdn.microsoft.com/en-us/library/w256ka79(v=vs.100).aspx ) and 2. if you would KoolKabin, if you believe pdr... | [
{
"body": "<p>What you're talking about is called object-relational mapping.</p>\n\n<p>You could do this, but it will be a fair amount of effort. Luckily many people have run into this same question before, answered it and open-sourced that solution. I suggest looking at using one of those solutions.</p>\n\n<p>... | {
"AcceptedAnswerId": "998",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-25T06:24:22.873",
"Id": "984",
"Score": "7",
"Tags": [
"object-oriented",
".net",
"database",
"vb.net"
],
"Title": "Recursive database actions"
} | 984 |
<p>I generally encounter a lot of <code>if</code>/<code>else</code>. I would like to get some suggestions on my code:</p>
<pre><code>if( $blnLogged && isset( $_POST['postReview'] ) )
{
if( $_SESSION['REVIEW']['SUBMITTED'] != '' )
{
$arrSharedData['blnRetSave'] = $_SESSION['REVIEW']['SUBMITTED']... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-25T08:05:50.150",
"Id": "1765",
"Score": "0",
"body": "For a minor readability improvement you can omit `=== true` since you control `$blnShowForm` and `!= ''` if `$_SESSION['REVIEW']['SUBMITTED']` will always be a string or `null`."
... | [
{
"body": "<p>One simple way to improve this is to package it in a function, and return (or throw an exception) after each <code>$strErrMsg = ...</code> line. This will flatten the function, and allow you to put the main functionality at the \"top level\" of the function.</p>\n\n<p>Even better might be to move ... | {
"AcceptedAnswerId": "986",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-25T06:46:56.983",
"Id": "985",
"Score": "4",
"Tags": [
"php"
],
"Title": "Submitting client reviews"
} | 985 |
<p>This class handles HTTP requests. It's a singleton class that parses URI to get the controller, method and parameters and then executes the controller's method.</p>
<p>Maybe <code>parseUri</code> should be in another class and maybe there is too much responsibility for this class.</p>
<p>I know that it can be impr... | [] | [
{
"body": "<p>Only something litle, don't write the closing <code>?></code> , because if there is a whitespace after and you try to modifiy the header anywhere else, it won't work and you will have very very long to find the whitespace.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 2.... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-25T14:34:57.060",
"Id": "990",
"Score": "4",
"Tags": [
"php",
"http"
],
"Title": "Handling HTTP requests"
} | 990 |
<p>I am currently learning myself a little F# and have written the following code to practice.</p>
<p>The code uses the Mono.Cecil library to inject some IL at the start of every method in each .net assembly found in a given directory. The IL will call a LogMe method in a Loggit.dll assembly.</p>
<p>I want to make th... | [] | [
{
"body": "<p>I only have two minor nitpicks with this code:</p>\n\n<pre><code>Seq.filter(fun file -> file.EndsWith(\"dll\") || file.EndsWith(\"exe\") ) |>\n</code></pre>\n\n<p>Perhaps this should say <code>\".dll\"</code> and <code>\".exe\"</code>. Or you could use <code>Path.GetExtension</code>.</p>\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-25T16:30:32.357",
"Id": "991",
"Score": "6",
"Tags": [
"functional-programming",
"f#"
],
"Title": "How can I make this F# more functional?"
} | 991 |
<p>I have a function that returns a set of values from a <code>Dictionary</code>.<br>
I don't currently want to allow it to throw <code>KeyNotFoundException</code>, so I'm filtering the keys out before I try to select the values.</p>
<p>I have a feeling this can be done in a more straightforward fashion, but I'm not s... | [] | [
{
"body": "<p>I would write it the obvious straight-forward LINQ way, which gives you good readability as well as lazy evaluation:</p>\n\n<pre><code>public IEnumerable<Resource> GetResources(IEnumerable<string> resourceNames)\n{\n return resourceNames\n .Where(name => resources.Contains... | {
"AcceptedAnswerId": "995",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-25T16:56:43.730",
"Id": "993",
"Score": "8",
"Tags": [
"c#"
],
"Title": "Pulling a subset of elements from a Dictionary"
} | 993 |
<p>Is it bad to do return render? I am doing this to NOT also allow a redirect. </p>
<pre><code>def create
@patient = Patient.new(params[:patient])
if !@patient.save
@patient.user.password = ''
@patient.user.password_confirmation = ''
return render is_admin? ? 'new_admin' : 'new'
else
... | [] | [
{
"body": "<p>Writing it like this makes it look the <code>render</code> returns a meaningful value that is then returned by create and used by the code that calls <code>create</code>, which is not the case. So instead I would write:</p>\n\n<pre><code>render is_admin? ? 'new_admin' : 'new'\nreturn\n</code></pre... | {
"AcceptedAnswerId": "997",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-25T18:39:09.897",
"Id": "996",
"Score": "10",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Return render in Ruby on Rails"
} | 996 |
<p>I am writing an application aimed at the desktop but using web technologies. It will have an HTML interface and a server written in Python using Flask will do all of the filesystem interaction. It will have the ability to edit user settings so I want to make it impossible for other users to interfere. This is a litt... | [] | [
{
"body": "<p>It's not secure because you delete the file with the port on. Finding open ports is easy. A better option is to bind only on localhost so that you can't connect from other computers at all. Figuring out the port is always going to be easy, so making that secret doesn't help. In fact it should be c... | {
"AcceptedAnswerId": "1010",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-25T20:44:42.203",
"Id": "1000",
"Score": "5",
"Tags": [
"python",
"security",
"flask"
],
"Title": "Security of simple client/server desktop app"
} | 1000 |
<p>I'm trying to port this little F# snippet while staying pythonic:</p>
<pre><code>["something"; "something else"; "blah"; "a string"] |> List.map (fun p -> p, p.Length) |> List.sortBy snd
</code></pre>
<p>In case you don't speak F#, it gets the length of each string, then sorts by length.</p>
<p>Output:</... | [] | [
{
"body": "<pre><code>data = [\"something\", \"something else\", \"blah\", \"a string\"]\nresult = [(x, len(x)) for x in sorted(data, key = len)]\n</code></pre>\n\n<p>Basically, its more straightforward to sort first then decorate. Although, I'm not sure why you would need the length of the list in your tuple. ... | {
"AcceptedAnswerId": "1004",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-25T23:44:49.373",
"Id": "1001",
"Score": "37",
"Tags": [
"python",
"beginner",
"strings",
"sorting",
"functional-programming"
],
"Title": "Sorting strings by length - funct... | 1001 |
<p>I am working on a helper method that maps properties from an <code>ExpandoObject</code> to a user supplied object and was wondering if the code could be cleaned up or made any more efficient. It currently has the correct behaviour from a simple test.</p>
<pre><code>public static class Mapper
{
public static void... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-03-11T00:05:40.340",
"Id": "507530",
"Score": "0",
"body": "If the ExpandoObject's are coming from JSON deserialization, might be simpler if you instead convert to `JObject`s. As seen [here](https://stackoverflow.com/q/30060974/199364)."
... | [
{
"body": "<p>I've come up with a few changes that should actually speed it up.</p>\n\n<pre><code>// By using a generic class we can take advantage\n// of the fact that .NET will create a new generic type\n// for each type T. This allows us to avoid creating\n// a dictionary of Dictionary<string, PropertyInf... | {
"AcceptedAnswerId": "1003",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2011-02-25T23:50:59.147",
"Id": "1002",
"Score": "12",
"Tags": [
"c#",
".net",
"reflection"
],
"Title": "Mapping ExpandoObject to another object type"
} | 1002 |
<p>I am looking for some help with improving this bilinear scaling SSE2 code on Core 2 CPUs.</p>
<p>On my Atom N270 and on an i7, this code is about 2x faster than the MMX code. But under Core 2 CPUs, it is only equal to the MMX code.</p>
<pre class="lang-c prettyprint-override"><code>void ConversionProcess::convert_... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-08T13:05:47.200",
"Id": "2102",
"Score": "2",
"body": "Posts like these make me feel stupid :-) Kudos to you for writing this!"
}
] | [
{
"body": "<p>Probably not what you wished to hear, but honestly, my suggestion would be to rewrite the code using SSE2 intrinsics and see what GCC (or MSVC) is able to do here with scheduling and loop unrolling.</p>\n\n<p>That said, you do not appear to be doing any prefetching. Why is the <code>prefetchnta</c... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-26T07:06:59.440",
"Id": "1006",
"Score": "7",
"Tags": [
"performance",
"c",
"assembly"
],
"Title": "Bilinear scaling using SSE2 on Core 2 CPUs"
} | 1006 |
<p>I have used code which looks a little like this in an app I'm working on:</p>
<pre><code>module App
module Settings
class << self
attr_accessor :console, :file
end
self.console ||= true
self.file ||= []
end
end
</code></pre>
<p>I decided to use this method because I like the i... | [] | [
{
"body": "<p>There is nothing really wrong with this but using a simple hash may be easier:</p>\n\n<pre><code>module App\n @@settings = {\n :console => true,\n :file => []\n }\n def self.settings\n @@settings\n end\nend\n</code></pre>\n\n<p>Your following code would then ... | {
"AcceptedAnswerId": "1685",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-26T19:01:35.590",
"Id": "1015",
"Score": "9",
"Tags": [
"ruby",
"ruby-on-rails",
"singleton",
"configuration"
],
"Title": "Storing a Ruby app's settings"
} | 1015 |
<p>I'm just wondering if the following is the best way to write a dao function. Should I get the entity manager before the transaction and close it after the transaction every time? Should I write transactions inside a dao?</p>
<pre><code>public void sendBack(Long requestId,String comments){
EntityManager em = g... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-28T08:10:28.343",
"Id": "62836",
"Score": "0",
"body": "I think you refer to this thread of stackoverflow. [Link](http://stackoverflow.com/questions/4031433/dao-and-service-layer-with-hibernate)"
}
] | [
{
"body": "<p>It depends on your app context. If im writting a web app Id create a filter which would getEntityManager(), begin() the transaction, then add it to the request scope, .doFilter() and pass it to the dao in the constructor (at the controller, of course).</p>\n\n<p>When it returns to the filter id co... | {
"AcceptedAnswerId": "6288",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-27T15:15:30.223",
"Id": "1021",
"Score": "4",
"Tags": [
"java",
"hibernate"
],
"Title": "Dao function using hibernate"
} | 1021 |
<p>Here is my problem abstracted to <code>Bird</code> classes. I know that number of <code>Bird</code>s will increase on the future and new behaviors might be needed. With 10 Birds first design might not look so simple and lead to lots of duplicated code. On the other hand, second design can be perceived as "class expl... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-27T16:35:56.397",
"Id": "1835",
"Score": "1",
"body": "The second example looks like typical Java design cruft."
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-27T17:18:21.607",
"Id": "1837",
"Score... | [
{
"body": "<p>The first one is definitely better. You should try to use as few classes as will get the job done and also favour lots of small methods over a few big methods. These will make your code easier to read, understand and maintain. I think you could improve on your first one a bit:</p>\n\n<pre><code>#i... | {
"AcceptedAnswerId": "1038",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-27T15:48:21.707",
"Id": "1022",
"Score": "14",
"Tags": [
"c++",
"inheritance",
"polymorphism"
],
"Title": "Design dilemma: extensibility vs simplicity"
} | 1022 |
<p>Here's what I've right now:</p>
<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import functools
import math
import time
class Timer(object):
def __init__(self):
self.__values = []
def start(self):
self.__start = time.time()
return self
def stop(self):
self._... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-28T08:37:25.880",
"Id": "1849",
"Score": "0",
"body": "As written it doesn't seem to handle recursion. If you move the start/stop time tracking into `profile()` it would."
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDat... | [
{
"body": "<pre><code>#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport functools\nimport math\nimport time\n\nclass Timer(object):\n def __init__(self):\n self.__values = []\n</code></pre>\n\n<p>You are using prefix __ to denote private attributess. This is perfectly valid and has special suppor... | {
"AcceptedAnswerId": "1109",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-28T03:43:07.433",
"Id": "1030",
"Score": "5",
"Tags": [
"python",
"python-2.x"
],
"Title": "Suggestions for a Profiler class in Python"
} | 1030 |
<p>Originally, I had everything in the base method #read_wall(). I'm not sure what happened with the array, but when I tried:</p>
<p><code>array = result + second + third + fourth</code>. I was left with data from only the original result. So I created this working disaster. <strong>Can you please help me refactor thi... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-28T08:29:07.057",
"Id": "1848",
"Score": "1",
"body": "Is it meaningful in Ruby to declare a local variable with the same name as a function and still expect to reference both in the same context? `second_wall ||= second_wall(fbuserid)... | [
{
"body": "<pre><code>def fourth_wall(fbuserid)\n result ||= graph.get_connections(fbuserid, 'feed')\n second ||= result.next_page\n third ||= second.next_page\n fourth ||= third.next_page\nend\n</code></pre>\n\n<p>A couple of problems here: <code>result</code>, <code>second</code>, <code>third</code> and <... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-28T05:25:48.470",
"Id": "1031",
"Score": "7",
"Tags": [
"ruby",
"pagination"
],
"Title": "Collecting friends' wall posts"
} | 1031 |
<p><strong>Option 1 - nice and simple</strong></p>
<pre><code>private void GetFileReady()
{
private StringBuilder fileContents = new StringBuilder();
using (var sr = new StreamReader("C:\A big file.txt"))
{
fileContents.Append(sr.ReadToEnd());
}
}
</code></pre>
<p><strong>Option ... | [] | [
{
"body": "<p>I don't think there's a significant difference between your two options when it comes to memory allocations. In both cases, you're reading the entire file into memory, which trumps any minor differences that might exist in the number of objects allocated by the two options. (Though both options a... | {
"AcceptedAnswerId": "1040",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-28T13:00:06.627",
"Id": "1037",
"Score": "2",
"Tags": [
"c#",
"comparative-review",
"io"
],
"Title": "Reading file contents into a string"
} | 1037 |
<p>It is an online learning application with different types of learnable items, that different users learn.</p>
<p>The users learn by spaced repetition (once right, wait a couple days, ask again), success is mirrored in stages and mistakes made.</p>
<p>I intend to use this for scientific data collection in the near ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T14:41:44.083",
"Id": "62283",
"Score": "0",
"body": "could you add the Schema picture to the question rather than a link? or along with a link?"
}
] | [
{
"body": "<p>You do have the field <code>languages</code> several times as a string. I'd create a general table <code>languages</code> with all language-related informations and have 1:m or n:m relations to other tables. </p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 2.5",
"Crea... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-28T13:58:30.093",
"Id": "1041",
"Score": "3",
"Tags": [
"mysql",
"sql",
"codeigniter"
],
"Title": "Database design for an online learning application"
} | 1041 |
<p>This a very simple function to expand the sizes between the given values.</p>
<p>For instance, if the input variable is "S-XL" then the function returns "S, M, L, XL".</p>
<p>Basically I'm not happy with this function. I think it's too complex for its purpose. </p>
<pre><code>function sizexpander($sizes) {
$... | [] | [
{
"body": "<p>You can use the function <code>array_slice</code> to take the subarray which contains the sizes from <code>$size1</code> to <code>size2</code>. And then use <code>implode</code> to turn this subarray into a comma-separated string. This will simplify your algorithm.</p>\n\n<p>You can also just use ... | {
"AcceptedAnswerId": "1044",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-02-28T14:05:07.063",
"Id": "1043",
"Score": "5",
"Tags": [
"php",
"array"
],
"Title": "Expanding sizes between given values"
} | 1043 |
<p>Here's a class that converts Hibernate proxies to normal classes. This is useful with GWT for example, when sending objects loaded from database to the GWT client.
Please review it.</p>
<pre><code>package ru.minogin.core.server.hibernate;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;... | [] | [
{
"body": "<p><code>doClean()</code> is crying out for decomposition. Compare</p>\n\n<pre><code>if (dirty instanceof PersistentList) {\n logger.debug(\"Object is a PersistentList\");\n\n PersistentList dirtyList = (PersistentList) dirty;\n List<Object> cleanList = new ArrayList<Object>();\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-02-28T16:33:15.073",
"Id": "1045",
"Score": "2",
"Tags": [
"java",
"converting",
"hibernate",
"proxy",
"gwt"
],
"Title": "Hibernate proxy converter for GWT"
} | 1045 |
<pre><code>namespace SharpDream.Api
{
public enum SourceType
{
Test,
Xml
}
public class UserFinder
{
private IUserInformationSource _sourceType;
private IParser _parserType;
private string _source;
public UserFinder(SourceType sourceType)
{
... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-03T21:55:04.473",
"Id": "1997",
"Score": "0",
"body": "Read up a bit on the Open-Closed Principle and how it applies to enums/switches: http://numainnovations.com/mentis-vulgaris/jason/software-development/is-your-code-solid-ocp-and-fi... | [
{
"body": "<p>This is looking pretty good to me. The main thing that stands out that I woudl change is that the UserFinder() method is somewhat large, and it isn't immediately understandable to me what each piece does. </p>\n\n<p>I would try to break that up into several smaller, descriptively named methods:</p... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-01T14:44:24.667",
"Id": "1053",
"Score": "2",
"Tags": [
"c#",
"api"
],
"Title": "Majorly refactored my code, is this good enough?"
} | 1053 |
<p>How can I improve on this rather ugly method that builds an HTML unordered list from an XML file?</p>
<p>I maintain a collection of ASP.NET webforms that all need to pull in the same site navigation as our main website. The forms have a master page that mimics the main site template, and we want any changes to the ... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-01T17:11:10.673",
"Id": "1878",
"Score": "0",
"body": "Welcome to codereview. In the future please use the code button (the one with the 1s and 0s) to format your code or indent it by four spaces. The `<pre>` tag does not enable syntax... | [
{
"body": "<p>The part that looks most problematic in your code is the <code>if</code> statement: the code in the <code>if</code> part and the <code>else</code> part is almost the same except that you prepend <code>urlPrefix</code> to the URL if it is relative. (Also you're only checking whether the node is the... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-01T16:03:01.533",
"Id": "1056",
"Score": "5",
"Tags": [
"c#",
"asp.net"
],
"Title": "Elegant approach to building unordered list from XML"
} | 1056 |
<p>Here's the code which I use for my Android custom cursor adapter which I use to bind data to my list view.</p>
<pre><code>public class MessageAdapter extends CursorAdapter {
private Cursor mCursor;
private Context mContext;
private final LayoutInflater mInflater;
public MessageAdapter(Context context... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-01T18:51:40.863",
"Id": "1887",
"Score": "0",
"body": "I'm still getting started on Android apps. What list item are you refering to?"
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-01T19:50:45.120",
"I... | [
{
"body": "<p>This is exactly* the way you should be using your <code>CursorAdapter</code>. I'm sure you're referring to \"recycling\" the Views as talked about when overriding the <code>getView()</code> method of a <code>BaseAdapter</code>.</p>\n\n<p>In the case of the <code>CursorAdapter</code>, all of that i... | {
"AcceptedAnswerId": "2201",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-01T16:10:38.723",
"Id": "1057",
"Score": "34",
"Tags": [
"java",
"android"
],
"Title": "Custom CursorAdapter Design"
} | 1057 |
<p>I'm working on a managed OpenGL game engine for C#, and here's how I'm managing shader parameters (uniforms). Is it "alright"? Could it be better? I'm a bit unsure about using generics in this case.</p>
<pre><code>public abstract class ShaderParameter
{
public readonly string Name;
internal readonly int Loc... | [] | [
{
"body": "<p>The biggest thing here is that you should make the ShaderParam class itself generic, not just its SetValue method. This will get rid of your type check and double cast (any time you have a type check or a double cast, chances are you're using the type system incorrectly). It will also get rid of... | {
"AcceptedAnswerId": "1069",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-01T17:23:45.270",
"Id": "1059",
"Score": "3",
"Tags": [
"c#",
"opengl"
],
"Title": "Shader parameters in managed OpenGL"
} | 1059 |
<p>I'm creating a game in C#, and I've created a <code>ScreenManager</code> so I can call</p>
<pre><code>ScreenManager.MoveToScreen(typeof(ScreenClassHere))
</code></pre>
<p>to move to other game states. However, I feel that my method of creating an instance of the class is... not very optimal. See for yourself.</p>
... | [] | [
{
"body": "<p>You could use generics</p>\n\n<pre><code>public static void MoveToScreen<T>() where T : Screen, new()\n{\n if (currentscreen != null) currentscreen.Remove();\n\n currentscreen = new T();\n currentscreen.Init();\n}\n</code></pre>\n\n<p>In this case, you'd have to call the method as</... | {
"AcceptedAnswerId": "1067",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-01T19:54:35.770",
"Id": "1066",
"Score": "7",
"Tags": [
"c#"
],
"Title": "Moving to other game states with ScreenManager"
} | 1066 |
<p>As far as I know the standard <a href="http://msdn.microsoft.com/en-us/library/system.delegate.createdelegate.aspx" rel="nofollow"><code>Delegate.CreateDelegate()</code></a> which allows to create a delegate by using reflection, doesn't allow doing something as follows when the first parameter of <code>method</code>... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-03T09:00:26.190",
"Id": "1963",
"Score": "0",
"body": "Why would you use such delegates? You're mentioning that it is generic but couldn't you simply use delegates constructor like so: `Action<object> execute = new Action(_owner.SomeMe... | [
{
"body": "<p>I feel like naming your first argument <code>firstArgument</code> will cause more confusion than it's worth. I would offer 2 overloads for this method.</p>\n\n<pre><code>// This overload will simply pass null to the main overload \n// for the sake of convenience.\npublic static T CreateCompatibleD... | {
"AcceptedAnswerId": "1646",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-02T02:55:01.627",
"Id": "1070",
"Score": "9",
"Tags": [
"c#",
"expression-trees"
],
"Title": "Generic advanced Delegate.CreateDelegate using expression trees"
} | 1070 |
<p>I've just given this as a response to an absolute beginner on SO, and I'm wondering how terrible it is.</p>
<p>Output for an odd number of lines:</p>
<pre><code>>
>>>
>>>>>
>>>
>
</code></pre>
<p>Output for an even number of lines:</p>
<pre><code>>
>>>
>>&... | [] | [
{
"body": "<blockquote>\n <p>better to declare first or does it not matter?</p>\n</blockquote>\n\n<p>No. These days most people believe variables should be declared as late as possible, right by where they are used.</p>\n\n<blockquote>\n <p>This code just seems so ugly.</p>\n</blockquote>\n\n<p>It is. A littl... | {
"AcceptedAnswerId": "1075",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-02T04:43:32.600",
"Id": "1071",
"Score": "11",
"Tags": [
"java",
"strings"
],
"Title": "Different character outputs using loops and strings"
} | 1071 |
<p>I have 3 simple similar event handler functions that I would like to refactor. Any suggestions?</p>
<pre><code>private void btnBuildingList_Click(object sender, EventArgs e)
{
selectedExportType = (int)ExportType.Building;
path = csvFilePath + String.Format("{0:yyyy-MM-dd}", datDate.DateTime) + ... | [] | [
{
"body": "<ol>\n<li><p>You can use an <em>Extract Method</em> refactoring to get rid of the duplicate code:</p>\n\n<pre><code>private static string GetExportFilePath(string csvFilePath, DateTime date, string fileSuffix)\n{\n return string.Format(\"{0}{1:yyyy-MM-dd}-{2}.csv\", csvFilePath, date, fileSuffix);... | {
"AcceptedAnswerId": "1078",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-02T09:03:55.197",
"Id": "1076",
"Score": "5",
"Tags": [
"c#",
"event-handling"
],
"Title": "Similar event handlers for buttons"
} | 1076 |
<p>A fully functional demo URL: <code>http://69.24.73.172/demos/index.html</code></p>
<p>Note that in FireFox there is a small horizontal scrollbar bug which I have fixed at home.</p>
<p><strong>HTML:</strong></p>
<pre><code><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" /> ... | [] | [
{
"body": "<p>I didn't have a look in detail, but some ideas/observations/remarks:</p>\n\n<ul>\n<li>You might save some <code>div</code> elements with using the <code>float</code> style (especially in your header). Try to avoid using <code>div</code>s for styling only and use the logical corresponding tags (for... | {
"AcceptedAnswerId": "1083",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-02T09:25:23.180",
"Id": "1077",
"Score": "8",
"Tags": [
"javascript",
"css",
"html"
],
"Title": "Demo of advertisment website"
} | 1077 |
<p>I have the following code which is a private method inside the form and retrieve all context menus from the form. I feel, that it is not that concise as it should be. Would be grateful for any suggestions.</p>
<pre><code> private IEnumerable<ContextMenuStrip> GetContextMenus()
{
var type = this.G... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-24T09:15:47.003",
"Id": "62862",
"Score": "0",
"body": "Kettic DataGridView is able to [create custom data grid context menus](http://www.kettic.com/winforms_ui/csharp_guide/gridview_context_menu_conditional.shtml) in C# to Data GirdVi... | [
{
"body": "<p>I can't imagine why do you do this via Reflection, I believe the same can be done by walking through <code>Controls</code> tree. Your method will not work if context menu has property <code>Generate member</code> set to <code>false</code> in designer.</p>\n\n<pre><code>var contextMenus = fields.Wh... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-02T11:26:32.510",
"Id": "1082",
"Score": "3",
"Tags": [
"c#",
".net",
"winforms"
],
"Title": "Retrieving context menus from the form"
} | 1082 |
<p>I have 3 methods(* BindingSource are bindingsources, context is data context, cache* -are some List for cache operations):</p>
<pre><code> private void AddUpdateRowDocuments()
{
try
{
tRANSMITDOCDOCUMENTSRELATIONSBindingSource.EndEdit();
var t = tRANSM... | [] | [
{
"body": "<p>Something along the lines of this. Generics aren't that difficult. Just replace every occurance of 'some desired type' with the generic identifier.</p>\n\n<pre><code>private void AddUpdateRow<T>(BindingSource bindingSource, List<T> cachedList)\n where T : ITransmitDocId\n{\n try\... | {
"AcceptedAnswerId": "1090",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-02T14:39:16.883",
"Id": "1089",
"Score": "6",
"Tags": [
"c#",
"linq"
],
"Title": "Suggest how to extract method"
} | 1089 |
<p>How can I use a more generic method to clean up the redundancy in the switch statement below?</p>
<p>I'm working on an ASP.NET webforms app that will have five identical user controls that I will be showing and hiding based on the value of a dropdown list. (I have already been down the path of trying to add and rem... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T14:49:08.073",
"Id": "16135",
"Score": "0",
"body": "Please don't use names like `UserControl`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T15:08:09.310",
"Id": "16136",
"Score": "0",
"... | [
{
"body": "<p>I would create a list of usercontrols. Based on the amount of controls that need to be visible, traverse the list and set x controls to visible.</p>\n\n<pre><code>protected void DisplayUserControls(List<UserControl> controls, int numberOfControls)\n{\n Contract.Requires( numberOfControls ... | {
"AcceptedAnswerId": "1092",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-02T14:54:17.263",
"Id": "1091",
"Score": "9",
"Tags": [
"c#",
"asp.net"
],
"Title": "Cleaning up a redundant switch statement"
} | 1091 |
<p>Is this, technically, a recursive function? It only gets called once by itself, but it cleaned up my code quite a bit, I think. Or, does it needlessly complicate the code?</p>
<pre><code>sub check_backlog {
my $topic = shift;
my $prev_backlog = shift;
my $backlog = undef;
my @status = `... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-02T18:16:22.410",
"Id": "1933",
"Score": "0",
"body": "Could you describe the intent of the code as well? I don't know enough PERL to entirely understand what you are actually doing, so I can't tell whether recursion is considered a go... | [
{
"body": "<p>Yes, every function which calls itself is considered a <a href=\"http://en.wikipedia.org/wiki/Recursion_%28computer_science%29\" rel=\"nofollow\">recursive function</a>.</p>\n\n<p>Recursion is really useful when traversing trees and such.</p>\n\n<p>As I don't fully understand Perl, I can't really ... | {
"AcceptedAnswerId": "1096",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-02T18:09:03.227",
"Id": "1095",
"Score": "4",
"Tags": [
"perl",
"subroutine"
],
"Title": "Is calling a function only twice a good use of recursion?"
} | 1095 |
<p>This is a simple linked list program which creates a list by appending an object at the tail. It compiles and runs perfectly.</p>
<p>Is the coding style, logic etc are fine? How can I improve this program? Is there anything redundant or did I miss out some important things?</p>
<pre><code>#include<iostream>... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-02T19:53:55.523",
"Id": "1946",
"Score": "0",
"body": "why not just use `std::list`?"
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-02T19:57:22.333",
"Id": "1947",
"Score": "4",
"body": "@AJG85... | [
{
"body": "<p>You should use std::list...\nBut if you only wanna learn how the Linked List works, i suggest the using of templates classes and functions for make the code more generic as possible...</p>\n\n<p>It isnt very difficult:</p>\n\n<pre><code>template <typename T> \n\nclass List\n{\npublic:\n /... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-02T19:47:02.693",
"Id": "1099",
"Score": "9",
"Tags": [
"c++",
"linked-list"
],
"Title": "Linked List program"
} | 1099 |
<p>Just as a refresher I put together a simple Map implementation and I would love to get some feedback on it.</p>
<pre><code>open System
open System.Collections.Generic
type Node<'a, 'b when 'a : comparison> = {
key : 'a
value : 'b
left : option<Node<'a, 'b>>
right : option<No... | [] | [
{
"body": "<h3>Second revision</h3>\n\n<p>Ok, first of all it would really help if you added some comments. I would also suggest giving your variables names which have more than one letter.</p>\n\n<p>In particular it would be a good idea to describe the algorithms being used. In particular you should document w... | {
"AcceptedAnswerId": "1165",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-02T20:38:17.347",
"Id": "1107",
"Score": "7",
"Tags": [
"f#",
"hash-map"
],
"Title": "Map implementation in F#"
} | 1107 |
<p>I have a function that returns an array and I want to check that a certain value is not set in the array.</p>
<pre><code>function testFunction() {
return array('key' => 404)
}
if (testFunction()['key'] < 404) {
// stay calm and carry on
}
else {
// uh oh
}
</code></pre>
<p>I understand that the ... | [] | [
{
"body": "<p>So, .. you want to simply check whether a certain key in an array is set to a certain value.</p>\n\n<p>You can't do this directly on the function call because <a href=\"https://stackoverflow.com/q/2282051/590790\">older PHP versions don't support array dereferencing</a>. You are right when saying ... | {
"AcceptedAnswerId": "1112",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-03T01:47:57.990",
"Id": "1111",
"Score": "1",
"Tags": [
"php"
],
"Title": "Best way to use an array that is returned from a function immediately in PHP"
} | 1111 |
<p>I would really appreciate it if someone could review my quicksort implementation. Additionally, I generated my list dynamically and wrote a couple of tests. Of course, I realize that the tests are not complete, but I decided to stop where I was and see if I could get some feedback.</p>
<pre><code>(defun categoriz... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-12-27T09:30:39.707",
"Id": "136241",
"Score": "0",
"body": "Asymptotically, this isn't a quicksort... appending lists the way you do it makes it more expensive than the textbook version. This also conses a lot of memory. Quicksort is best... | [
{
"body": "<p>Your formatting is weird. It's going to be a lot easier for other programmers to read your code if you use a more standard style. For example, you have lots of lines with nothing but a hanging parenthesis. Your functions have no docstrings. Sometimes you <code>use_underscores</code> and someti... | {
"AcceptedAnswerId": "1169",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-03T04:13:02.420",
"Id": "1114",
"Score": "5",
"Tags": [
"lisp",
"quick-sort",
"common-lisp"
],
"Title": "Lisp quicksort code"
} | 1114 |
<p>What it does is:</p>
<ol>
<li>Reads from a RSS feed using Google Feed API</li>
<li>Shows the list in an unordered list</li>
</ol>
<p>How good/bad is the code snippet?</p>
<pre><code>$(document).ready(function(){
var FeedManager = {
config : {
feedContainer : $('#feedContainer'),
fe... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-05T16:42:02.963",
"Id": "2056",
"Score": "0",
"body": "I think that you should take a look at jQuery TMPL."
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-10T18:06:17.980",
"Id": "2175",
"Score": "0... | [
{
"body": "<p>Looks ok, to be honest. A few minor changes I would make:</p>\n\n<p>I would pull this code out into a function</p>\n\n<pre><code>function ProcessFeedResult(result) {\n if (!result.error) {\n FeedManager.$feedContainer = FeedManager.config.feedContainer;\n for (var i = 0; i < re... | {
"AcceptedAnswerId": "1120",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-03T14:08:45.567",
"Id": "1118",
"Score": "15",
"Tags": [
"javascript",
"jquery",
"css",
"rss"
],
"Title": "Displaying RSS feeds from Google Feed API as HTML list"
} | 1118 |
<pre><code>class Pool(type):
pool = dict()
def __new__(clas, *a, **k):
def __del__(self):
Pool.pool[self.__class__] = Pool.pool.get(self.__class__, []) + [self]
a[-1]['__del__'] = __del__
return type.__new__(clas, *a, **k)
def __call__(clas, *a, **k):
if Pool.poo... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-03T16:54:13.780",
"Id": "1976",
"Score": "0",
"body": "Well, calling class variables \"clas\" annoys the heck out of me. klass or class_ is better IMO. But that's a matter of taste."
},
{
"ContentLicense": "CC BY-SA 2.5",
"... | [
{
"body": "<p>Name your arguments. If you know enough about what you'll have passed in to take item -1 of the positional argument list, you know enough to give it a name.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011... | {
"AcceptedAnswerId": "1161",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-03T14:23:53.130",
"Id": "1119",
"Score": "6",
"Tags": [
"python",
"design-patterns"
],
"Title": "python object pool with metaclasses"
} | 1119 |
<p>This takes an array of numbers then splits it into all possible combinations of the number array of size 4 then in another array puts the leftovers. As I want to take the difference in averages of the first column and the second.</p>
<pre><code>import itertools
#defines the array of numbers and the two columns
nu... | [] | [
{
"body": "<p>Not using numpy or scipy, but there are several things that can be improved about your code:</p>\n\n<ul>\n<li>This is minor, but in your comments you call your lists arrays, but it in python they're called lists</li>\n<li>Variable names like <code>col_one</code> and <code>col_two</code> aren't ver... | {
"AcceptedAnswerId": "1140",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-03T16:05:48.193",
"Id": "1121",
"Score": "7",
"Tags": [
"python",
"array",
"combinatorics"
],
"Title": "Splitting an array of numbers into all possible combinations"
} | 1121 |
<p>Is there a simple way to create a comma delimited string from a list of items <strong>without</strong> adding an extra ", " to the end of the string?</p>
<p>I frequently need to take an ASP.NET CheckBoxList and format the selected values as a string for insertion into an e-mail. It's straightforward to loop over th... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-03T21:25:04.690",
"Id": "1995",
"Score": "1",
"body": "Despite the answers, in this code, your delimiter should be a string, and trim end should call `delimiter.ToCharArray()` in order to make maintenance just a tad bit easier."
},
... | [
{
"body": "<p>As <a href=\"https://codereview.stackexchange.com/questions/1122/comma-delimited-string-from-list-of-items/1125#1125\"><strong>pdr</strong></a> has pointed out, it's best to use <a href=\"http://msdn.microsoft.com/en-us/library/57a79xd0.aspx\" rel=\"nofollow noreferrer\"><code>String.Join</code></... | {
"AcceptedAnswerId": "1125",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-03T16:20:24.897",
"Id": "1122",
"Score": "57",
"Tags": [
"c#",
"asp.net"
],
"Title": "Comma delimited string from list of items"
} | 1122 |
<pre><code>$privilegeStrings = array_filter($privileges, function ($s) { return is_string($s); } );
</code></pre>
<p>Is there a better way to specify that I want just the string values in the given array?</p>
| [] | [
{
"body": "<p>You could do:</p>\n\n<pre><code>$privilegeStrings = array_filter($privileges, 'is_string');\n</code></pre>\n\n<p><code>array_filter</code> passes every value of the array to the specified function. So you can just specify the function name and everything will be taken care of.</p>\n\n<p><a href=\"... | {
"AcceptedAnswerId": "1133",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-03T18:06:40.230",
"Id": "1129",
"Score": "7",
"Tags": [
"php",
"callback"
],
"Title": "Do nothing lamda..."
} | 1129 |
<p>I've been using FlexLib for its dockable toolbar feature. When you shrink the window, it will try to wrap rows if the stage width is less than the row width. Unfortunately, it won't reverse the process when you expand the window. To get around that, I wrote the following method to add to the class (the caller is ... | [] | [
{
"body": "<p>I have one little suggestion with regard to style. It is much better to invert your conditions to have the simpler code run first when it involves yielding control. It also helps you avoid excessive indentation. </p>\n\n<pre><code>var child:DockableToolBar = DockableToolBar(row.getChildAt(k));\n\n... | {
"AcceptedAnswerId": "1135",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-03T18:31:46.363",
"Id": "1132",
"Score": "4",
"Tags": [
"actionscript-3",
"actionscript",
"flex"
],
"Title": "Getting better speed from adjusting rows in a DockableToolBar"
} | 1132 |
<p>I often see this for custom events:</p>
<pre><code>void InvokeCustomEvent(EventArgs e)
{
var handler = CustomEvent;
if (handler != null) handler(this, e);
}
</code></pre>
<p>But is creating the handler variable required, best practice, or superfluous, when compared to:</p>
<pre><code>void InvokeCustomEven... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-04T09:19:34.847",
"Id": "2004",
"Score": "0",
"body": "IMO, it should be moved to StackOverflow, though I believe this question is already present there."
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-04T1... | [
{
"body": "<blockquote>\n <p>But is creating the handler variable required, best practice, or superfluous, when compared to:</p>\n</blockquote>\n\n<p>Yes, it is needed. Otherwise, <code>CustomEvent</code> could be set to <code>null</code> after you've checked for <code>null</code>, but before you've invoked it... | {
"AcceptedAnswerId": "1143",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-03T23:03:22.930",
"Id": "1142",
"Score": "8",
"Tags": [
"c#"
],
"Title": "Checking if an event is not null before firing it in C#"
} | 1142 |
<p>In answering a question on SO, I provided this example. The intention was to provide a thread safe service that queues requests to make directories. I figured I could definitely use some review on my use of threading, singletons and general Java skills. </p>
<pre><code>package mkdir;
import java.io.File;
import... | [] | [
{
"body": "<p><code>pendingDirs</code> should not be static. It's one thing to maintain a static instance to implement a singleton, but that object should interact with its state using normal instance variables. And you may as well initialize it in its declaration instead of the constructor.</p>\n\n<p>The servi... | {
"AcceptedAnswerId": "1153",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-04T05:37:50.993",
"Id": "1150",
"Score": "5",
"Tags": [
"java",
"thread-safety"
],
"Title": "Thread Safe Service to Perform Tasks in a Queue"
} | 1150 |
<p>I have the following code:</p>
<pre><code>private ScatterViewItem FindScatterViewOfSourceFile(SourceFile find)
{
foreach (ScatterViewItem svi in classScatterViews)
{
if ((svi.Tag as SourceFile).Equals(find))
{
return svi;
}
}
return null;
}
</code></pre>
<p>Now I'm asking mys... | [] | [
{
"body": "<p>So you have heard about the good practice that a method should only have one return statement.\nThis is generally true, but in your case I find it not to be necessary because the method is so small. The main reason for this 'rule' is readability, so you know what is going on. Both code samples are... | {
"AcceptedAnswerId": "1158",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-04T11:46:01.330",
"Id": "1156",
"Score": "10",
"Tags": [
"c#",
"algorithm"
],
"Title": "Is this a valid loop?"
} | 1156 |
<p>I'm currently creating an <a href="http://oauth.net/core/1.0a/" rel="nofollow noreferrer">OAuth</a> provider in Java using <a href="http://jersey.java.net/" rel="nofollow noreferrer">Jersey</a>. To the best of my knowledge Jersey does not provide a method to create oauth tokens so I'm creating my own.</p>
<p>For th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-07T21:21:42.403",
"Id": "31079",
"Score": "0",
"body": "I realize this is quite old, but any reason you wouldn't want to use `java.security.KeyPairGenerator` and generate, for example an _RSA key pair_ and use those?"
}
] | [
{
"body": "<blockquote>\n <p>Each token must be;</p>\n \n <ul>\n <li>non-sequential</li>\n <li>non-guessable</li>\n <li>unique</li>\n </ul>\n</blockquote>\n\n<p>Without reading into any of the OAuth specifics, if the above is the only criteria to which you must adhere, then I would suggest what you're do... | {
"AcceptedAnswerId": "1737",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-04T12:27:51.577",
"Id": "1159",
"Score": "14",
"Tags": [
"java",
"random",
"oauth",
"jersey"
],
"Title": "OAuth Provider token generation"
} | 1159 |
<p>I'm using <em>Entity Framework Code First CTP 5</em> for a current project. There is still no enum support in Entity Framework so this is what I am using in order to avoid having magic numbers or casts littered throughout my code.</p>
<p>Simplified Example:</p>
<p><strong>Domain Model Consumed by Code First</stron... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-11T17:36:06.577",
"Id": "53733",
"Score": "0",
"body": "I second Saeed's approach. Implementations here also might be of interest: [C# String Enums](http://stackoverflow.com/questions/424366/c-string-enums/4881040#4881040)"
}
] | [
{
"body": "<p>I think the biggest drawback to your approach is that you're adding complexity but not really getting the main benefit you're after, which is to avoid magic numbers. This code doesn't prevent you from using magic numbers since it automatically converts from any <code>int</code> to an <code>Addres... | {
"AcceptedAnswerId": "1166",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-04T17:20:48.717",
"Id": "1162",
"Score": "15",
"Tags": [
"c#",
"beginner",
"entity-framework"
],
"Title": "Dealing with Entity Framework's lack of enum support"
} | 1162 |
<p>I've been spending a long time working on this template, I'd like to know if its CSS/HTML is good, and mainly if it is speedy to load, accessible, semantic and SEO friendly.</p>
<p>I've tested it in IE7+, Chrome, FF and Safari and am happy with the output in each.</p>
<p><a href="http://69.24.73.172/demos/newDemo"... | [] | [
{
"body": "<p>My first point is that you have no :focus style for your links. If you navigate the page with the keyboard that would really help a lot to see where you are. Take this rule for example:</p>\n\n<pre><code>h3 a:hover\n{\n color: #1B676B;\n text-decoration:none;\n}\n</code></pre>\n\n<p>Just add... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-05T16:34:40.530",
"Id": "1170",
"Score": "6",
"Tags": [
"html",
"css"
],
"Title": "Web-page template"
} | 1170 |
<p>I've used jQuery for a long time, and now I'm going to do some animations with vanilla JS. Here's my code so far:</p>
<pre><code>var box = document.getElementById('box'),
a1end,
a2end,
cdend,
a3end,
a4end,
animate1 = setInterval(function() {
if (box.style.top === (window.innerHeight ... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-05T19:28:51.123",
"Id": "2057",
"Score": "3",
"body": "I see you're trying to use javascript. You should totally drop that and use jQuery. *smirk*"
},
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-05T19:48:01... | [
{
"body": "<p>You're repeating code blocks all over the place; you may want to abstract some out. For example, calling something like</p>\n\n<pre><code>function animatePxProperty(prop, limit, step, interval){\n if(!step) step = 1; //I miss optional arguments :(\n if(!interval) interval = 1;\n var anim ... | {
"AcceptedAnswerId": "2520",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-05T18:58:37.233",
"Id": "1171",
"Score": "8",
"Tags": [
"javascript"
],
"Title": "Animations with vanilla JS"
} | 1171 |
<p>This is going to be rather long and generic, so apologies in advance.</p>
<p>I've been reading a lot about Haskell lately, but I've never really programmed anything with it beyond simple experiments in ghci. So, I wanted to finally try and do some coding exercise that was easy but non-trivial and ended up choosing ... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-07T15:16:36.483",
"Id": "2083",
"Score": "0",
"body": "Maybe a more meaningful topic name?"
}
] | [
{
"body": "<p>One of Haskell's advantages is that there's a good number of high-quality parser libraries for it. Using one for this case might be a bit overkill, but since this is a learning exercise anyway it might be a good chance to pick up a parser library (e.g. parsec) as well. This could certainly come in... | {
"AcceptedAnswerId": "1177",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-06T12:05:18.200",
"Id": "1176",
"Score": "14",
"Tags": [
"functional-programming",
"haskell"
],
"Title": "Converting simple markup to HTML"
} | 1176 |
<p>I am doing a CS practice exercise in which you are supposed to sort exactly three numbers using only if statements. I wrote the following code in LISP and would appreciate any suggestions how to improve on my code. Thank you!</p>
<pre><code>(defun generate-three ()
(loop for l from 1 to 3 collect (random 25)))
... | [] | [
{
"body": "<p>It's been a while since I've used lisp, so I can't really critique your code for style or any common lisp gotchas.</p>\n\n<p>That said, the biggest thing I notice here is that the code for generating the 3 numbers, sorting them, and printing the result are all tightly coupled with each other. I w... | {
"AcceptedAnswerId": "1197",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-07T02:14:47.887",
"Id": "1179",
"Score": "5",
"Tags": [
"lisp",
"common-lisp"
],
"Title": "Sorting numbers in LISP"
} | 1179 |
<p>I wrote the following Ruby script several years ago and have been using it often ever since on a Bioinformatics computer cluster.</p>
<p>It pulls out a list of hosts from the Torque queuing system <code>qnodes</code>. It <code>ssh</code>'es and runs a command on all the nodes. Then it prints the output and/or error... | [] | [
{
"body": "<p>First of all, take a look at the <a href=\"http://net-ssh.github.com/ssh/v2/api/index.html\"><code>Net::SSH</code></a> library. I don't have much experience with it, so I don't know whether it supports all the options you need. But if it does, using it might be more robust than using the command l... | {
"AcceptedAnswerId": "1193",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-07T02:44:22.653",
"Id": "1180",
"Score": "10",
"Tags": [
"ruby",
"multithreading",
"networking",
"child-process"
],
"Title": "Ruby script on-all-nodes-run not only for teaching... | 1180 |
<p>This is a simple LISP program to read in three sides of a triangle and report what kind of triangle it is (or isn't). Any feedback would be much appreciated.</p>
<pre><code>(defun read-side (side) (format t "Enter a value for side ~d: ~%" side) (read))
(defun is-a-triangle (a b c) (if (and (< a (+ b c)) (< ... | [] | [
{
"body": "<p>Keep in mind that every form in lisp returns something. <code>(and foo bar baz)</code> returns <code>nil</code> if <code>foo</code>, <code>bar</code> or <code>baz</code> evaluates to <code>nil</code>, and <code>t</code> if all of them evaluate to non-<code>nil</code>. This means that anywhere you ... | {
"AcceptedAnswerId": "1201",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-07T04:23:33.903",
"Id": "1182",
"Score": "4",
"Tags": [
"lisp",
"common-lisp"
],
"Title": "Determine type of triangle in LISP"
} | 1182 |
<p>I want to create delegates to access properties of different objects without knowing them in advance.</p>
<p>I have the following definitions</p>
<pre><code>public delegate T MyMethod<K, T>(K data);
public static MyMethod<K, T> CreatePropertyGetter<K, T>(PropertyInfo property)
{
Method... | [] | [
{
"body": "<p>One suggestion is to create type -> type map of all the types you want to support instead of making a switch statement on strings.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-07T19:47:25.577",
"Id": "2085",
"Score": "... | {
"AcceptedAnswerId": "1190",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-07T18:59:10.373",
"Id": "1188",
"Score": "6",
"Tags": [
"c#",
".net"
],
"Title": "Best practice instantiating generic delegates and accessing property getters"
} | 1188 |
<p><a href="https://stackoverflow.com/questions/5212640/rails-how-to-create-different-views/5212690#5212690">I answered a question in stackoverflow</a> but I gave a solution that looks a little dirty to me, I'd like your opinion because I think there is a much smarter way to do it.</p>
<p>A <strong>guest</strong> user... | [] | [
{
"body": "<p>For the part you do not like, you can set a before_filter in ApplicationController. Therefore a redirect will not be necessary. Selection form can resubmit to the current page with \"view_type\" parameter.</p>\n\n<pre><code>#application_controller.rb\nbefore_filter :check_view_type, :only => [:... | {
"AcceptedAnswerId": "10319",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-07T20:33:02.680",
"Id": "1192",
"Score": "6",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "How to manage different views"
} | 1192 |
<p>I've got three tables I need query to display to a user for a web application I've written. Each table (Url, Note, Quote) has a foreign key relation to the User table. For every User, I need to sort all Bookmarks, Notes and Quotes based on a _date_created_ field, then deliver that to the template as one iterable. Th... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-08T05:32:28.283",
"Id": "2095",
"Score": "0",
"body": "You state that you want a sorted version, but nothing in your code sorts it. You also mention users being involved, but there are no users in your example code."
},
{
"Cont... | [
{
"body": "<p><strong>EDIT</strong> Removed previous version which was pretty much telling you to use the second method shown above. Your first method loads everything from the database twice. (Django may do some caching, but still) I'm not sure why you are putting everything in the dictionary.</p>\n\n<p>The pr... | {
"AcceptedAnswerId": "1195",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-08T05:18:13.247",
"Id": "1194",
"Score": "4",
"Tags": [
"python",
"django"
],
"Title": "Three-table queryset (full outer join?) in Django"
} | 1194 |
<p>I had a file that looked like this:</p>
<pre><code>Mar 06 22:00:00 [10.251.132.246] logger: 10.64.69.219 - - [06/Mar/2011:22:.....
Mar 06 22:00:00 [10.251.132.246] logger: 10.98.137.116 - - [06/Mar/2011:22:0....
</code></pre>
<p>that I wanted to split into smaller files using the ip address after "logger"</p>
<p>... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-08T14:08:25.693",
"Id": "2104",
"Score": "2",
"body": "Do you mind me asking why you'd want to split log files this way? It looks like you want to have a log per IP instead of one giant log. Is this for documentation purposes? Do you j... | [
{
"body": "<p>First of all it is a pretty wide-spread convention in ruby to use 2 spaces for indendation not 4. Personally I don't care, but there are some ruby developers who will complain when seeing code indented with 4 spaces, so you'll have an easier time just going with the stream.</p>\n\n<hr>\n\n<pre><co... | {
"AcceptedAnswerId": "1200",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-08T07:18:26.540",
"Id": "1196",
"Score": "7",
"Tags": [
"ruby"
],
"Title": "Splitting log file into smaller files"
} | 1196 |
<p>I have a <code>std::set<std::string></code> and I need to know the total number of characters (sum of all strings length):</p>
<pre><code>static size_t SumLength(size_t value, const std::string &str)
{
return str.length() + value;
}
size_t TotalLength(std::set<std::string> &stringSet)
{
... | [] | [
{
"body": "<p>You should make the parameter to <code>TotalLength</code> const, so you can use it on constant sets. Since <code>TotalLength</code> does not modify its argument, there is no reason not to use a const reference.</p>\n\n<p>Also this is a small thing, but I'd change the name of <code>SumLength</code>... | {
"AcceptedAnswerId": "1199",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-08T14:18:45.670",
"Id": "1198",
"Score": "6",
"Tags": [
"c++"
],
"Title": "Counting the total number of characters in an std::set<std::string>"
} | 1198 |
<p>I'm working on a network monitoring application, that pings an unknown number of hosts. I've made a class <code>PingHost</code> with a function <code>zping</code> and I called it with the help of a timer once every 2 seconds to let the 2 pings to finish, even if one of them gets <code>TimedOut</code>. But I think a ... | [] | [
{
"body": "<p>You can use <code>SendAsync</code>:</p>\n\n<pre><code>sender.PingCompleted += new PingCompletedEventHandler (PingCompletedCallback);\nsender.SendAsync(dest, timeout, buffer, options, textLabel);\n</code></pre>\n\n<p>And the callback:</p>\n\n<pre><code>private static void PingCompletedCallback (obj... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-08T16:50:51.400",
"Id": "1202",
"Score": "7",
"Tags": [
"c#",
"multithreading",
"networking"
],
"Title": "Multithreaded host pinging application"
} | 1202 |
<p>I wondering what people think of this game of life. I don't think it is working properly, but I am interesting in what people think of the general design.</p>
<pre><code>module GameOfLife where
import Data.List
--Our types
type Coord = (Int, Int)
origin = (0, 0)
--Think of an image more like an infinite manifold... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-17T07:21:11.207",
"Id": "28081",
"Score": "0",
"body": "Have a look at [Evaluating cellular automata is comonadic](http://blog.sigfpe.com/2006/12/evaluating-cellular-automata-is.html). Using comonads could nicely simplify the game desi... | [
{
"body": "<p>First, arranging your code from top to bottom level or vice versa would make this a little easier to read. Also, Haskell code formatting custom generally uses casing like <code>someThing</code> rather than <code>some_thing</code>.</p>\n\n<p>There are also a few items that could be more simply defi... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-09T03:42:59.360",
"Id": "1204",
"Score": "11",
"Tags": [
"haskell",
"game-of-life"
],
"Title": "Game of Life in Haskell"
} | 1204 |
<p>In C++, to simplify string conversion between <code>std::string</code> and <code>std::wstring</code>, I created the following utility template functions:</p>
<pre><code>#pragma once
#include <vector>
#include <string>
#include <cstring>
#include <cwchar>
#include <cassert>
template&l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-11-20T02:59:13.797",
"Id": "58819",
"Score": "0",
"body": "Why don't you use an enumeration type to represent the code page with? `int` is hardly discoverable..."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-09... | [
{
"body": "<p>Just a stylistic note, take it for what it's worth. I generally prefer to avoid:</p>\n\n<pre><code>if ( usual_case )\n{\n // lots of code\n}\nelse\n{\n // one line handler\n}\n</code></pre>\n\n<p>and instead prefer to go with less indentation, by handling error cases first:</p>\n\n<pre><code>if... | {
"AcceptedAnswerId": "1466",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-09T06:13:39.323",
"Id": "1205",
"Score": "14",
"Tags": [
"c++",
"strings",
"template",
"stl",
"casting"
],
"Title": "C++ string_cast<> template function"
} | 1205 |
<p>This Common Lisp exercise is to write a program that can calculate the weekday given a string of the format "M-D-Y." It was more challenging than I expected. If you have suggestions about how to simplify this code, I will be very grateful.</p>
<pre><code>;; 2.7 Day of Week. A program for converting Gregorian dat... | [] | [
{
"body": "<p>If you're allowed to use library functions, <code>split</code> already exists as part of <a href=\"http://weitz.de/cl-ppcre/\" rel=\"nofollow\">cl-ppcre</a>. </p>\n\n<hr>\n\n<p>There's a pretty rich set of date/time functions in the Lisp core that make this trivial. If it's for learning purposes, ... | {
"AcceptedAnswerId": "1211",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-03-09T06:23:30.530",
"Id": "1206",
"Score": "5",
"Tags": [
"datetime",
"lisp",
"common-lisp"
],
"Title": "Calculate the weekday from a date (M-D-Y)"
} | 1206 |
<p><a href="http://www.developer.com/design/article.php/3678856/MVC-in-a-JavaSwing-Application.htm">This article has left me a little confused.</a> </p>
<p>In explaining a method on how to design MVC into Java Swing apps the author defines the controller class as Singleton and relays a series of calls to the Controlle... | [] | [
{
"body": "<p>It's been a long time ago since I last used an MVC approach in Swing, but I immediately notice some things I wouldn't do.</p>\n\n<ol>\n<li>Don't use a singleton, <a href=\"http://blogs.msdn.com/b/scottdensmore/archive/2004/05/25/140827.aspx\" rel=\"nofollow\">singletons are evil!</a></li>\n<li>Pas... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2011-03-09T13:49:24.580",
"Id": "1212",
"Score": "5",
"Tags": [
"java",
"design-patterns",
"mvc"
],
"Title": "MVC Controller in Java Swing Apps - Singleton or public static"
} | 1212 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.