body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I've created these 3 functions to count the value of letters in a word.</p>
<p>All these functions are functionally the same.</p>
<p>Apparently List comprehensions (<code>count_word3</code>) are usually seen as the most pythonic in these situations. But to me it is the least clear of the 3 examples.</p>
<p>Have I... | [] | [
{
"body": "<p>how's example 3 the least readable? I would write it a little better but you've got it right already:</p>\n\n<pre><code>def count_word3(word): \n return sum(ord(c) - 64 for c in word) \n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | {
"AcceptedAnswerId": "13865",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-20T10:54:47.693",
"Id": "13863",
"Score": "1",
"Tags": [
"python",
"comparative-review"
],
"Title": "Three ways to sum the values of letters in words"
} | 13863 |
<p>I want to perform some operations on the gridview (asp.net 4.0). So, to achieve this i have written a jquery function which i am calling on pageload but, because this function takes some time for execution my grid performance degrades (IE 8). Can i optimize it someway? </p>
<pre><code> $.each($("#divTab2GridInq... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-20T03:34:10.897",
"Id": "22371",
"Score": "4",
"body": "Not an optimisation, but two comments: (1) You seem to have multiple elements with the same id, which is invalid html and should be avoided - use classes; (2) The first line will ... | [
{
"body": "<p>The best that I can see if changing the IFs to switches, but overall, the speed of execution will not change.</p>\n\n<pre><code>switch (val){\n\ncase \"N\":\n// Code for N\nbreak;\n\ncase \"S\":\n// Code for S\nbreak;\n\ncase \"D\":\n// Code for D\nbreak;\n\ndefault:\n// For the rest, use \"not\" ... | {
"AcceptedAnswerId": "13870",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-20T03:25:52.763",
"Id": "13868",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Showing/hiding deletion buttons in a grid view"
} | 13868 |
<p>At the moment I am trying to create a Japanese rehearsal system, and it's working perfectly. However, I am not pleased with the code. Basically I had a .txt file called lesson1.txt. I saved it as UTF-8 so it can contain Japanese characters. </p>
<p>I had the problem that I couldn't directly use the Japanese charact... | [] | [
{
"body": "<p><code>X</code> is a very bad variable name.\nIt comes like a lightning from a clear sky there in the beginning.</p>\n\n<p>The following comment is good:</p>\n\n<pre><code>//$LineArray is an array in which each element contains a line of lesson1.txt\n// so for example: $LineArray[0] = \"γγ€γ\";\n</... | {
"AcceptedAnswerId": "13976",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-20T13:02:45.173",
"Id": "13872",
"Score": "2",
"Tags": [
"javascript",
"php",
"array"
],
"Title": "Japanese rehearsal system"
} | 13872 |
<p>Here is a simple Python script that I wrote with lots of help from the Python mailing list. I moves all the files of subdirectories to the top level directory. It works well for my use, but if there are things that can be improved then I would like to know. I ask in the interest of being a better Python programmer a... | [] | [
{
"body": "<p>I'll typically wrap the main body of my code in a python script in a function and break the code apart into more functions, allowing me to reuse that code later.</p>\n\n<pre><code>import os\nimport shutil\nimport sys\n\ndef flattenDirectory(location, action, actuallyMoveOrCopy=True):\n \"\"\" Th... | {
"AcceptedAnswerId": "13878",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-20T14:16:19.887",
"Id": "13876",
"Score": "2",
"Tags": [
"python"
],
"Title": "Python: flatten directories"
} | 13876 |
<p>I created simple app that read <code>~</code> delimited txt file, convert it to <code>[String]</code> and display quotes on screen.</p>
<ul>
<li>How would you improve this code? To be more Haskell like... </li>
<li>in <code>splitStr</code> <code>(c/=)</code> is faster than <code>(/=c)</code> by 20-50 ns. Why?</li>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T08:47:53.220",
"Id": "22636",
"Score": "0",
"body": "Re `(c/=)` -v- `(/=c)`: did you compile using optimisation (`-O` switch to ghc)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T11:56:37.280",
... | [
{
"body": "<p>I'm going to talk about your <code>splitStr</code> function.</p>\n\n<p>First, it's almost the same as <a href=\"http://hackage.haskell.org/packages/archive/split/latest/doc/html/Data-List-Split.html#v%3asplitOn\" rel=\"nofollow\"><code>splitOn</code></a> from Data.List.Split in the <a href=\"http:... | {
"AcceptedAnswerId": "15317",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-21T02:16:46.010",
"Id": "13888",
"Score": "3",
"Tags": [
"haskell"
],
"Title": "Simple quotes app"
} | 13888 |
<p>I don't see anyway for a SQL attack to happen with its all hard coded.</p>
<pre><code><?php
$db = mysql_connect('host', 'user', 'pass') or die('Could not connect: ' . mysql_error());
mysql_select_db('DBNAME') or die('Could not select database');
// Strings must be escaped to prevent SQL i... | [] | [
{
"body": "<p>Yes, it's secure because you aren't allowing any variable to be inserted as part of a query. However it is horribly inefficient as it violates the <a href=\"http://en.wikipedia.org/wiki/Don%27t_repeat_yourself\" rel=\"nofollow noreferrer\">DRY principle</a>: you are writing the same code out in a ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-21T20:19:22.760",
"Id": "13891",
"Score": "4",
"Tags": [
"php",
"sql",
"mysql",
"quiz"
],
"Title": "Updating quiz statistics in a database"
} | 13891 |
<p>This is a fraction of the binary writer I'm writing, and I'm trying find some way to improve it.</p>
<pre><code>using System;
using System.Collections.Generic;
public class ByteBuffer
{
// List used to hold all bytes that will be read
private List<byte> buffer = new List<byte>(32);
private... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-21T22:45:35.787",
"Id": "22426",
"Score": "0",
"body": "For what you're doing here, working with data at the bit level is overkill IMHO. The intrinsic type is the `byte` so you should work at _that_ level at a minimum. You won't gain... | [
{
"body": "<p>If you're after efficiency, you shouldn't write bit by bit. For example, if <code>bitIndex</code> is currently 3 and you're writing the full 8 bits, just two steps are necessary: writing 5 bits to one byte and then the remaining 3 bits to another byte.</p>\n\n<p>And depending on what you do, writi... | {
"AcceptedAnswerId": "13903",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-21T20:35:37.490",
"Id": "13892",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Byte buffer writer"
} | 13892 |
<p>I have started my hand at writing some scheme code. I am trying to get the first n primes. I plan to do so but first getting a list from <code>2</code> to <code>m</code>, and doing the following algorithm. Remove the first number and place in the primes list, remove all #'s from the initial list that are multiples o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-20T23:03:46.057",
"Id": "22427",
"Score": "0",
"body": "Just out of curiosity, wouldn't it be simpler to just build a list of primes by keeping track of the primes found, and for each number see if it is divisible by one of the already... | [
{
"body": "<p>In your function <code>firstnprimes</code> there is a typo near the end; more importantly it uses <code>append</code> but it is the wrong function to use there. What does <code>append</code> append? If called with two arguments the 2nd of which is a list, what must the first argument be - a list, ... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-20T22:36:09.953",
"Id": "13896",
"Score": "3",
"Tags": [
"homework",
"scheme",
"primes"
],
"Title": "Scheme, first timer first program, simple list removal technique"
} | 13896 |
<p>So far, I've used this in a few places and it seems solid.</p>
<p>This is what I usually do to make a singleton:</p>
<pre><code>// Assume x86 for now
#ifdef _MSC_VER
#include <intrin.h> // for _mm_pause
#else
#include <xmmintrin.h> // for _mm_pause
#endif
#include <cstdint>
#include &l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-22T02:12:50.213",
"Id": "22441",
"Score": "1",
"body": "Unfortunately it is broken in a couple of ways. 1) Double checked locking does not work correctly. 2) Order of initialization problems. Full review to come. But it is much easier ... | [
{
"body": "<p>Your use of underscore is correct for variables. <strong>BUT</strong> the actual rules are complex enough, that using them at the start of an identifier is not a good idea. Do you know what all the rules for underscore as the first character of an identifier are? See <a href=\"https://stackoverflo... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-22T01:09:20.403",
"Id": "13901",
"Score": "3",
"Tags": [
"c++",
"singleton",
"template-meta-programming"
],
"Title": "Singleton with template wrapper"
} | 13901 |
<p>I have a little experience with Python and am trying to become more familiar with it. As an exercise, I've tried coding a program where the ordering of a list of players is determined by the roll of a die. A higher number would place the player ahead of others with lower numbers. Ties would be broken by the tied pl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T10:01:02.427",
"Id": "22499",
"Score": "0",
"body": "Is there a reason for calling a dice \"die\"? BTW you can find some Python style guides [here](http://meta.codereview.stackexchange.com/a/495/10415)"
},
{
"ContentLicense"... | [
{
"body": "<p>Here's one way it could be done with a lot less code:</p>\n\n<pre><code>from itertools import groupby\nfrom operator import itemgetter\nfrom random import randint\n\ndef rank_players(playerList):\n playerRolls = [(player, randint(1, 6)) for player in playerList]\n playerGroups = groupby(\n ... | {
"AcceptedAnswerId": "13921",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-22T01:13:54.113",
"Id": "13902",
"Score": "1",
"Tags": [
"python",
"random",
"tree",
"simulation"
],
"Title": "Die-rolling for ordering"
} | 13902 |
<p>Answer in <a href="https://stackoverflow.com/questions/3140826/windows-system-time-with-millisecond-precision">this question</a> contains <code>DateTimePrecise</code> class that should return current date with millisecond precision. But class is pretty bug and complicated. So I wrote my own version which seems work ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-22T17:58:31.867",
"Id": "22462",
"Score": "0",
"body": "You now need to be able to compare this instance to another or to any object, etc. so there are things like IComparable, IEquitable, ..."
},
{
"ContentLicense": "CC BY-SA ... | [
{
"body": "<p>If you don't need a precise <code>DateTime</code>, only differences, then don't use <code>DateTime</code> at all. I think you should work only with <code>TimeSpan</code>s.</p>\n\n<p>This will avoid confusion, because with your class, it looks like <code>DateTimePrecise\n.CurDateTime()</code> is be... | {
"AcceptedAnswerId": "18813",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-22T10:18:43.380",
"Id": "13908",
"Score": "4",
"Tags": [
"c#",
"datetime"
],
"Title": "DateTimePrecise - current DateTime with millisecond precision"
} | 13908 |
<pre><code>a=raw_input()
prefix_dict = {}
for j in xrange(1,len(a)+1):
prefix = a[:j]
prefix_dict[prefix] = len(prefix)
print prefix_dict
</code></pre>
<p>Is there any possibility of memory error in the above code?</p>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T04:57:24.287",
"Id": "22478",
"Score": "0",
"body": "A memory error? Please explain."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T16:02:52.827",
"Id": "22510",
"Score": "0",
"body": "@J... | [
{
"body": "<p>The slice operator in <code>a[:j]</code> creates a copy of the sublist so is perfectly possible that you get a MemoryError.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T23:50:19.463",
"Id":... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-22T12:07:51.700",
"Id": "13910",
"Score": "2",
"Tags": [
"python",
"strings",
"hash-map"
],
"Title": "Creating a dictionary of all prefixes of a string in Python"
} | 13910 |
<p>Can someone please help to rewrite / tidy up this?</p>
<pre><code>// News Article Slideshow
var periodToChangeSlide = 5000;
var pp_slideshow = undefined;
var currentPage = 0;
$('#news-feature-img-wrap li').css('display', 'list-item').slice(1).css('display', 'none');
$('#news-items li:first').addClass('active');
$... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T05:37:02.763",
"Id": "22482",
"Score": "0",
"body": "It would be nice to have example html."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T17:09:06.883",
"Id": "30061",
"Score": "0",
"bod... | [
{
"body": "<p>Without HTML we could not do too much, but here is what I noticed right away.</p>\n\n<p>I would definately use more of the chaining that is provided with jQuery.</p>\n\n<pre><code>$(\"#news-feature-wrap #news-items li\").click(function () {\n $(this).parent().addClass('active').siblings().remov... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-22T23:23:47.503",
"Id": "13912",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"html",
"css"
],
"Title": "Custom jQuery Slider"
} | 13912 |
<h1>Code</h1>
<h2>Sudoku.java</h2>
<pre><code>public class Sudoku implements ISudoku {
/**
* Generates wildcard values in case of conflict with the keys of the
* Sudoku. Ensures all characters are alphanumeric, does not generate the
* same wildcard twice, and tries to keep the wildcard as short as... | [] | [
{
"body": "<p><code>List<String></code> is not good way, use <code>Set<Character></code> to store (<code>return false</code> if wildcard exists) your wildcard.</p>\n\n<p>So you will avoid the <code>\"\" +</code> (very bad way) and use <code>Character.ValueOf(char));</code></p>\n",
"comments": [
... | {
"AcceptedAnswerId": "14168",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T00:20:13.953",
"Id": "13914",
"Score": "3",
"Tags": [
"java",
"design-patterns",
"sudoku"
],
"Title": "Is this Sudoku a good use of the Fluent Builder Pattern?"
} | 13914 |
<h1>Solution to 99 lisp problems: P08, with functional javascript</h1>
<blockquote>
<p>If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not be changed.</p>
</blockquote>
<pre><code>* (compress '(a a a a b c c a a d e e e e))
(A B C A ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T05:19:21.410",
"Id": "22479",
"Score": "0",
"body": "Wouldn't a loop or recursive calling be a better idea?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T05:20:39.443",
"Id": "22480",
"Score... | [
{
"body": "<p>I don't think you need so much complexity in javascript. It's not a fully functional language, don't try to make it so.</p>\n\n<pre><code>var arr = [\n 'a', 'a', 'a', 'b', 'b', 'c', 'd', 'd', 'a', 'e', 'e', 'e'\n];\n\narr = arr.filter( function( el, i ) {\n // return if the current isn't the... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T01:51:29.713",
"Id": "13917",
"Score": "1",
"Tags": [
"javascript",
"lisp",
"functional-programming"
],
"Title": "Solution to 99 lisp problems: P08 with functional javascript"
} | 13917 |
<p>I am teaching myself C, and feel like I am just starting to get the hang of pointers and arrays (I come from Python, where everything is magic). I'm looking for reviews, especially if I'm doing anything wrong. In this code I wrote my own <code>strcat()</code> function, though it needs 3 args instead of the standar... | [] | [
{
"body": "<ol>\n<li><p>What's not magic in C is that pointers can be null, and assigning to <code>NULL</code> will cause segfault. The same applies to <code>[]</code> access on <code>char*</code> that are <code>NULL</code>.</p></li>\n<li><p>You've created a function with a return type, but you never return an... | {
"AcceptedAnswerId": "13934",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T05:12:15.843",
"Id": "13920",
"Score": "3",
"Tags": [
"c",
"strings"
],
"Title": "Custom strcat() with different arguments"
} | 13920 |
<p>Sass (<strong>S</strong> yntactically <strong>A</strong> wesome <strong>S</strong> tyle <strong>s</strong> heets) extends traditional CSS by providing several features available in other programming languages, particularly object-oriented languages, but that are not available to CSS3 itself. Sass provides features s... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T06:38:01.517",
"Id": "13922",
"Score": "0",
"Tags": null,
"Title": null
} | 13922 |
Sass is a CSS preprocessor which enables advanced features not available in normal CSS. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T06:38:01.517",
"Id": "13923",
"Score": "0",
"Tags": null,
"Title": null
} | 13923 |
<p>Here is part of my build system. </p>
<pre><code>guessCompilers :: Options -> IO Options
guessCompilers options = foldl (>>=) (return options) modifiers where
modifiers =
[guessMetapost
-- guessAsymptote,
-- guessTex,
-- guessLatex,
-- guessXelatex
]
guessMetapost ::... | [] | [
{
"body": "<p>Pattern match instead of using <code>isJust</code> and <code>fromJust</code>. (You could use <code>maybe</code> instead of pattern matching, but I think pattern matching is clearer in this case.)</p>\n\n<p>This eliminates the possibility of forgetting to ensure a value is a Just before calling <co... | {
"AcceptedAnswerId": "13930",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T07:34:54.270",
"Id": "13927",
"Score": "2",
"Tags": [
"haskell",
"null",
"compiler",
"tex"
],
"Title": "Using a compiler specified on the command line or automatically dete... | 13927 |
<p>I'm trying to validate some results that I see when using <a href="http://www.scl.ameslab.gov/netpipe/" rel="noreferrer">NetPipe</a> to test some connectivity between a couple of Linux boxes (over various hardware). So, I concocted this simple client and server to do the same and I cannot seem to get the same number... | [] | [
{
"body": "<p>Not much to comment on, this program is pretty straightforward. A few notes:</p>\n<ul>\n<li><p>The user of the client has a lot of information to input.</p>\n<blockquote>\n<pre><code> fprintf(stderr, "Usage: %s <Server IP> <Server Port> <Iterations> <Gap>\\n", ... | {
"AcceptedAnswerId": "41034",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T10:15:10.290",
"Id": "13933",
"Score": "9",
"Tags": [
"c",
"performance",
"socket",
"tcp"
],
"Title": "Stupidly simple TCP client/server"
} | 13933 |
<p>I have this code that places a marker and on mouse-over this marker is scaled out and then back to the 'original' scale:</p>
<pre><code>this.drawPerson = function () {
self.svg.append("path")
.attr("d", personPath)
.attr("transform", "translate(100,100)scale(0.1)")
.attr("class", "member"... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T08:40:56.977",
"Id": "22579",
"Score": "1",
"body": "What's wrong with it as it stands? Performance?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T09:28:46.387",
"Id": "22581",
"Score": "0",... | [
{
"body": "<p>There does not seem to be a great way of solving this.</p>\n\n<p>The best I can propose is to capture the style that you will re-set to into a function and use that function both during initialization and mouseout, this makes the code DRY'er, but not necessarily nicer:</p>\n\n<pre><code>this.drawP... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T11:42:51.093",
"Id": "13935",
"Score": "5",
"Tags": [
"javascript",
"optimization",
"svg",
"d3.js"
],
"Title": "Optimizing mouse in/out"
} | 13935 |
<p>I'm creating a class to describe a "zigzag line" fit to a set of data. It implements my interface Fittable, which just contains <code>evaluate()</code> (I have mulitple kinds of curves that all implement this interface). I created the private inner class <code>Node</code> to describe a vertex. It will give the slope... | [] | [
{
"body": "<p>First, <a href=\"https://stackoverflow.com/questions/2586290/is-catching-a-null-pointer-exception-a-code-smell\">don't catch <code>NullPointerExceptions</code></a>. Not only is it slightly more inefficient, it's a terrible code smell. Instead, do this:</p>\n\n<pre><code>if(floor != null){\n d1 ... | {
"AcceptedAnswerId": "13939",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T15:42:10.773",
"Id": "13938",
"Score": "1",
"Tags": [
"java"
],
"Title": "Linearized Fit to Data"
} | 13938 |
<p>When checking for existence of a substring I have been doing this:</p>
<pre><code>var that = "ok hello cool";
if( that.indexOf('hello') + 1 ) {
}
</code></pre>
<p>Instead of: </p>
<pre><code>if( that.indexOf('hello') != -1 ) {
}
</code></pre>
<p>Am I overlooking something or is there a reason not to do this... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T19:02:35.120",
"Id": "22536",
"Score": "1",
"body": "`if( ~that.indexOf('hello') )` is usually used"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T20:48:41.593",
"Id": "22549",
"Score": "3",
... | [
{
"body": "<p>Well, I believe the second one is more obvious what's going on...</p>\n\n<pre><code>if( that.indexOf('hello') != -1 ) {\n}\n</code></pre>\n\n<p>That's all to it however, both expressions are valid and perfectly ok.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"Co... | {
"AcceptedAnswerId": "13943",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T18:54:19.177",
"Id": "13941",
"Score": "5",
"Tags": [
"javascript"
],
"Title": "indexOf() + 1 vs indexOf() != -1"
} | 13941 |
<p>This is a Python script to save imgur pictures posted to reddit.com forums. I'm looking for an assessment on the design of this script and any web security issues that might exist.</p>
<p>Obvious shortcomings: it only downloads image links <a href="https://i.imgur.com/xx.png" rel="nofollow noreferrer">http://i.imgu... | [] | [
{
"body": "<ul>\n<li><p>Never do <code>except Exception:</code>, <em>especially</em> not to <code>pass</code>. You probably want to be catching <code>KeyError</code>s specifically, or using <code>dict.get</code> in the first case, and in the other cases adjust accordingly.</p></li>\n<li><p>There's no need to do... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T19:11:45.803",
"Id": "13945",
"Score": "3",
"Tags": [
"python",
"json",
"image",
"reddit"
],
"Title": "Download image links posted to reddit.com"
} | 13945 |
<p>I have an array of strings which are file names <code>files</code>, and an array of allowed file types or suffixes <code>allowed_types</code>. I want to filter out files which don't end with an allowed suffix.</p>
<p>This does the trick, but I'm wondering if anyone can suggest a neater solution? Such as a way keep ... | [] | [
{
"body": "<p>How about this?</p>\n\n<pre><code>valid_files = Dir.entries(path).select do |f| \n allowed_types.any? {|suffix| f.end_with? suffix}\nend\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T1... | {
"AcceptedAnswerId": "13948",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T12:52:01.320",
"Id": "13947",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Neatest way to filter an array of strings by another array in ruby"
} | 13947 |
<p>I have written code exclusively in both C and C++. I see clear advantages in both and therefore have recently began using them together. I have also read, what I would consider, outrageous comments claiming that to code in C is outright dumb, and it is the language of past generations. So, in terms of maint... | [] | [
{
"body": "<p>You can't write <code>exclusively in both C and C++</code>.</p>\n<p>You can write</p>\n<ul>\n<li>exclusively in C</li>\n<li>exclusively in C++</li>\n<li>or using a combination of the two <strong>different</strong> languages.</li>\n</ul>\n<blockquote>\n<p>to code in C is outright dumb, and it is th... | {
"AcceptedAnswerId": "13953",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T21:43:04.607",
"Id": "13949",
"Score": "1",
"Tags": [
"c++",
"c"
],
"Title": "What are the draw backs, if any, in using C and C++ together? Is doing so considered correct by the la... | 13949 |
<p><strong>About Data:</strong> 3D data (100x100x20). </p>
<p><strong>Computation/Formula and Method:</strong> I am trying to compute the sum of squared differences along rows, columns and angles for various time differences.</p>
<pre><code>%% Grid and time paramters
%# Grid parameters
nRows=100;
nCol=100;
InitLag_R... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-18T01:40:02.383",
"Id": "22551",
"Score": "0",
"body": "As a start, check out `pdist` - you can probably use that to do the bulk of it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-18T01:59:05.153",
... | [
{
"body": "<p>Here's a way to do it using <code>pdist</code> to generate both the differences in value, plus logical indices that you can use to select which distances you wish to look at/use further.</p>\n\n<pre><code>D1 = [1 2 3;4 5 6;7 8 9];\nD2 = [9 8 7;6 5 4;3 2 1];\nD = cat(3,D1,D2);\n\nD(:,:,1) =\n\n 1 ... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-07-17T22:34:44.313",
"Id": "13950",
"Score": "1",
"Tags": [
"matrix",
"matlab"
],
"Title": "Computing the sum of squared differences"
} | 13950 |
<p>This is the stripped down version of my update action for a Posts (blog post) controller:</p>
<pre><code>Posts.update = function(req, res){
_.extend(req.post, {
title: req.body.title
, author: req.body.author
, body: req.body.body
});
post.save();
};
</code></pre>
<p>This way feels ... | [] | [
{
"body": "<p>How about <a href=\"http://documentcloud.github.com/underscore/#pick\" rel=\"nofollow\"><code>_.pick()</code></a>?</p>\n\n<pre><code>Posts.update = function(req, res){\n _.extend(req.post, _.pick(req.body, 'title', 'author', 'body'));\n post.save();\n};\n</code></pre>\n",
"comments": [],... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T00:10:27.580",
"Id": "13957",
"Score": "2",
"Tags": [
"javascript",
"mvc",
"node.js"
],
"Title": "Is there a better way to update fields in an web app?"
} | 13957 |
<p>My view submits data to the controller using Json objects which contains child objects.It allows users to add/remove/modify the relationship with child entities(authors,categories,LIbraryBookCopy). Users can only select authors and categories from list but can update/add LibraryBookCopy object.</p>
<p>This is my fi... | [] | [
{
"body": "<p>I don't code in C#, so just two generic notes:</p>\n\n<ol>\n<li><p>The following comments are good candidates for method names:</p>\n\n<ul>\n<li><code>//Assign categories to book</code>: <code>assignCategories</code>, <code>assignCategoriesToBook</code></li>\n<li><code>//Assign authors to book</co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T05:51:52.317",
"Id": "13961",
"Score": "1",
"Tags": [
"c#",
"asp.net-mvc-3",
"entity-framework"
],
"Title": "Many to many crud using entity framework 4.1"
} | 13961 |
<p>This craps game simulator is based on someone else's posted Python code that I've redone for practice. I'm interested in improving readability and making it more pythonic. I used <code>unittest</code> instead of <code>nose</code> because I'm using an online IDE.</p>
<pre><code>from random import randrange
import un... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2020-02-27T17:37:24.210",
"Id": "466862",
"Score": "0",
"body": "I can give my 2 cents in regard to the naming conventions. Using snake case for the variables' names would be definitely more pythonic, for example `come_out` instead of `comeOut... | [
{
"body": "<p>Some general comments first.</p>\n\n<ol>\n<li><p>There's no need to make your throws in strings for the outcomes - you can use tuples instead. e.g.</p>\n\n<pre><code>self.outcomes = { (2,):False, (5,5):True }\n</code></pre></li>\n<li><p>If you pass a \"wrong\" set of dice throws (say \\$[4,5]\\$),... | {
"AcceptedAnswerId": "13966",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T06:37:08.500",
"Id": "13962",
"Score": "2",
"Tags": [
"python",
"game",
"random",
"dice"
],
"Title": "Craps dice game simulator"
} | 13962 |
<p>I am working on a personal iPhone ObjC project, and was recently getting frustrated with how tedious importing the same set of headers over and over was getting⦠So I created a header file that literally only imports other header files, and looks something along the lines of this:</p>
<pre><code>//BackboneTools.h
#... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-18T09:33:32.230",
"Id": "31575",
"Score": "0",
"body": "Be sure to read and understand this: http://qualitycoding.org/precompiled-headers/\nIt tells you about some ways PCHs cripple your code."
}
] | [
{
"body": "<p>You can import all you need in <code>AppName_Prefix.pch</code> header. And all this imported headers will be available app-wide. </p>\n\n<p>But I think this isn't good idea. In most cases it's helpful to see which other classes and parts of application current class depends of.</p>\n",
"commen... | {
"AcceptedAnswerId": "14001",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T07:18:53.893",
"Id": "13963",
"Score": "4",
"Tags": [
"objective-c",
"import"
],
"Title": "Import management"
} | 13963 |
<p>I need your opinion on writing a constructor that's clean code and unit test friendly.</p>
<p>Option 1 :</p>
<pre><code>var res1 = bigObject.GetResource1();
var res2 = bigObject.GetResource2();
var res3 = bigObject.GetResource3();
var myObject = new Foo(bigObject, res1, res2, res3);
//and the foo ctor just initial... | [] | [
{
"body": "<p>I'm not sure if this argument applies to your use case, but option 1 invites inconsistencies. Someone (even you) might pass resource values that are incompatible with each other. If you rely on any kind of relationship between <code>bigObject</code> and the resources, definitely use option 2.</p>\... | {
"AcceptedAnswerId": "13970",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T09:54:56.743",
"Id": "13965",
"Score": "1",
"Tags": [
"c#",
"unit-testing",
"constructor"
],
"Title": "Get resources inside or outside constructor?"
} | 13965 |
<p>This is my current method for populating the sub-items of <code>ListView</code> controls. I like this method for two reasons... </p>
<p>1) I don't have to keep up with the display order of the columns.</p>
<p>2) If I enable column re-ordering, I don't have to change anything with the code. </p>
<p>So, the questio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T13:49:09.367",
"Id": "22604",
"Score": "0",
"body": "What's wrong with your expected problem of editing the font color? How is this not possible with your code (with obvious changes to actually *try* something, since your code does ... | [
{
"body": "<p>If you want to avoid the late bound <code>.Text</code> and <code>.Tag</code> you could just create your own private type, say <code>LVI</code>, containing these two properties and implicit <code>Widening</code> <code>CType</code> operators for <code>ListViewItem</code> and <code>ListViewItem.ListV... | {
"AcceptedAnswerId": "14009",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T11:14:00.683",
"Id": "13969",
"Score": "2",
"Tags": [
"vb.net"
],
"Title": "Method for populating ListViewSubItems"
} | 13969 |
<p>I would like to find a more efficienct way to use jQuery for my question and answer page.</p>
<p>Here is the code which I want to change. If a <code>.q_container</code> is clicked, I want its corresponding answer <code>div</code> will slide down.</p>
<pre><code>$(document).ready(function() {
$('#qc1').hover(
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T12:55:09.883",
"Id": "22600",
"Score": "0",
"body": "Do you want the answer to open when clicked or hovered?"
}
] | [
{
"body": "<p><strong>Working Demo</strong> <a href=\"http://jsfiddle.net/jEjYp/2/\">http://jsfiddle.net/jEjYp/2/</a></p>\n\n<p>Rest feel free to play around with the code or demo.</p>\n\n<p>Hope it fits your cause. <code>:)</code></p>\n\n<p><strong>code</strong></p>\n\n<pre><code>$(document).ready(function() {... | {
"AcceptedAnswerId": "13972",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T03:26:02.990",
"Id": "13971",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"performance",
"html",
"css"
],
"Title": "jQuery substitute for multiple hovers"
} | 13971 |
<p>The main advantage of this pattern is when I often create and destroy objects, which in this case are often used.</p>
<p>I made this because I needed to track several short timers at the same time, but it can also be used for stuff like missiles or else.</p>
<pre><code>#include <vector>
#include <queue&g... | [] | [
{
"body": "<p>Don't do this:</p>\n\n<pre><code>using namespace std;\n</code></pre>\n\n<p>In anything other than a toy this will cause problems. </p>\n\n<p>I don't like this:</p>\n\n<pre><code>#define itv(TYPE) std::vector<TYPE>::iterator\n</code></pre>\n\n<p>With C++11 this type if thing has been resolv... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T19:19:35.117",
"Id": "13979",
"Score": "5",
"Tags": [
"c++",
"design-patterns",
"stl"
],
"Title": "Simple object pool template container in C++"
} | 13979 |
<p>I have a map that I want to 'expand' into an infinite sequence in the following manner:</p>
<pre><code>{0 'zero 3 'three 10 'ten}
=>
('zero 'zero 'zero 'three 'three 'three 'three 'three 'three 'three 'ten 'ten 'ten ...)
</code></pre>
<p>The indexes of the map indicating the index of the sequence where the valu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T21:04:59.637",
"Id": "22619",
"Score": "0",
"body": "oh, you want 'zero from 0th, then 'three from third, then 'ten from tenth?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T21:07:52.387",
"Id":... | [
{
"body": "<p>It really depends on your specific goals. The code as it is is very\nlazy, but also recomputes quite a lot by accessing the map on every\nsingle step.</p>\n\n<p><code>(iterate inc 0)</code> can be more easily written as <code>(range)</code> as noted again\nbelow and the definition of <code>expand... | {
"AcceptedAnswerId": "106278",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T20:45:26.770",
"Id": "13982",
"Score": "8",
"Tags": [
"clojure"
],
"Title": "Expanding a map into an infinite sequence"
} | 13982 |
<p>In re-writing my PHP framework vervPHP, I've created the following class:</p>
<pre><code>class storage {
private static $instance;
public $db = null; // Holds a database connection object
public $user = null; // Holds user related information for custom auth
public $data = array(); // Array of data ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T21:08:21.247",
"Id": "22937",
"Score": "0",
"body": "I think you've misunderstood the concept of singleton here. From my understanding a singleton class should not be instantiated with the constructor and therefore should not have o... | [
{
"body": "<p>I think you are going to the wrong direction with this kind of aproach. First you are creating a Singleton while propably you don't need to use it. Second you are mixing things in one God object which is also a bad design in an object-oriented environment.\nAnd what is this init() function? Just l... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-24T23:31:56.297",
"Id": "13986",
"Score": "5",
"Tags": [
"php",
"object-oriented",
"singleton",
"dependency-injection"
],
"Title": "Storage class, dependency injection and single... | 13986 |
<p>I would like to optimize the code to be efficient. Basically the code finds and generates an Anova table with the p-value also computed.</p>
<p>I am inputting a text file with data delimited with commas.</p>
<p><strong>This is the main function that calls the methods in the library file:</strong></p>
<pre><code>u... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T07:47:57.163",
"Id": "22628",
"Score": "0",
"body": "Quick question: How much data is expected to be in your file? In the millions? In the thousands?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25... | [
{
"body": "<p>Use <a href=\"http://www.dotnetcurry.com/ShowArticle.aspx?ID=608\" rel=\"nofollow\">Parallel.For</a> instead of <code>for</code>, and the same for <code>foreach</code>.<br>\nExample:</p>\n\n<pre><code>var lines = File.ReadAllLines(\"data.txt\");\nList<List<double>> numbers = new List&l... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T06:35:06.630",
"Id": "13993",
"Score": "5",
"Tags": [
"c#",
"performance",
".net"
],
"Title": "Finding and generating an Anova table"
} | 13993 |
<p>Here is the book question:</p>
<blockquote>
<p>Modify the <code>CatFile</code> function in the program so that it uses
<code>WriteConsole</code> rather than <code>WriteFile</code> when the standard output handle
is associated with a console.</p>
</blockquote>
<p>And here is my solution:</p>
<pre><code>stati... | [] | [
{
"body": "<p>From a quick thought - Shouldn't WriteFile actually work when hOutFile is the console?</p>\n\n<p>Otherwise I guess that you may need to check whether GetStdHandle(...) == hOutFile.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T08:13:08.833",
"Id": "13996",
"Score": "1",
"Tags": [
"c",
"windows",
"console"
],
"Title": "Is my WriteConsole solution correct?"
} | 13996 |
<p>I think here is something wrong with code. I use a class with methods to get tenants from DB:</p>
<pre><code> public List<CrmTenant> GetAllTenants()
{
List<CrmTenant> tenantsList = new List<CrmTenant>();
try
{
var crmTenants =
from tenan... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T09:11:39.290",
"Id": "22640",
"Score": "0",
"body": "Why do you think there is something wrong with your code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T10:22:37.190",
"Id": "22757",
"Sc... | [
{
"body": "<p>I can see some room for improvement:</p>\n\n<ol>\n<li>Most importantly, you shouldn't hide exceptions like this. You should most likely let the exceptions bubble up and let the called decide what to do when an exception happens. And if you return <code>null</code>, it means you will either have to... | {
"AcceptedAnswerId": "14000",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T08:29:59.540",
"Id": "13997",
"Score": "2",
"Tags": [
"c#",
".net",
"linq",
"classes"
],
"Title": "Class with methods to retrieve data with Linq to sql"
} | 13997 |
<p>What do you think of my own implementation of the extension method <code>SelectMany</code>?
Motivating criticism is always welcome.</p>
<pre><code>public static IEnumerable<TResult> MySelectMany<T, TResult>(this IEnumerable<T> source, Func<T, IEnumerable<TResult>> selector)
{
var t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T10:35:18.767",
"Id": "22646",
"Score": "1",
"body": "You're doing this just as a learning exercise, right? Otherwise, reimplementing framework code doesn't make much sense."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creati... | [
{
"body": "<p>The <code>as</code> cast in the return statement is entirely redundant, it doesnβt serve a purpose.</p>\n\n<p>Furthermore, The problem with this implementation is that itβs not lazy. You should use a <code>yield</code> generator instead.</p>\n\n<pre><code>public static IEnumerable<TResult> M... | {
"AcceptedAnswerId": "14004",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-07-25T10:14:34.973",
"Id": "14002",
"Score": "1",
"Tags": [
"c#",
"reinventing-the-wheel",
"linq",
"extension-methods"
],
"Title": "My own implementation of Linq SelectMany exten... | 14002 |
<p>How do I better calculate the definite integral? I am using a function to integrate and another to find the factorial recursively.</p>
<p>I'l like to better the algorithm or the efficiency or even the accuracy for that matter.</p>
<pre><code> public static double testStatistic(double meanTreatmentSumOfSquares, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T07:28:57.950",
"Id": "22654",
"Score": "3",
"body": "There is no question here, only a task. Focus on a specific part and then a specific question related to it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2... | [
{
"body": "<p>Check source code of the <a href=\"http://www.gnu.org/software/gsl/manual/html_node/\" rel=\"nofollow\">GSL library</a> that is really well designed.\nIt includes implementations of many numerical integration algorithms.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T07:27:59.547",
"Id": "14005",
"Score": "3",
"Tags": [
"c#",
"algorithm",
".net",
"performance"
],
"Title": "Definite integral calculation in C#"
} | 14005 |
<p>I'm trying to make a drop down menu with click event. I have this HTML structure:</p>
<pre><code><ul id="menubar">
<li class="menu1">
<a href="#">Menu 1</a>
<ul class="submenubar">
<li class="submenu1"><a href="#">Submenu 1<... | [] | [
{
"body": "<p>Probably something like this would enable you to extract it. Basically I'd suggest looping through hiding everything then setting the one you want to open, you could be clever and check if the menu selected is already one, but hopefully this will give you the idea:</p>\n\n<pre><code>$(\"menubar ul... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T10:09:38.193",
"Id": "14006",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "jQuery auto increment for class name"
} | 14006 |
<p>I have the following datastructure to perform a longest-match lookup via nested dicts. For example. <code>cs['a b c d']</code> with <code>a</code> and <code>a b c</code> being in the structure will return <code>a b c</code> and the remainder <code>d</code>.</p>
<p>I wonder if there's a better way to implement the <... | [] | [
{
"body": "<pre><code>class CommandStorage(object):\n \"\"\"Stores multi-part commands.\n\n Performs fast lookups returning the command and any arguments which were\n not part of the command.\n \"\"\"\n\n def __init__(self, commands={}):\n self._root = {}\n self._commands = {}\n</co... | {
"AcceptedAnswerId": "14041",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T19:42:58.020",
"Id": "14021",
"Score": "2",
"Tags": [
"python",
"lookup"
],
"Title": "Longest-match lookup via nested dicts"
} | 14021 |
<p>My job required me to learn jQuery the last couple of weeks, but it's a mess and I do not know how to structure my code in an acceptable manner. I come from a Java and PHP background and have never touched JavaScript before.</p>
<p>I've searched the web for some guidelines, but I could not find anything of real val... | [] | [
{
"body": "<p>once you define a group of objects with jquery, you only have to loop through them if you want each one to do something different. </p>\n\n<p>the <code>each</code> function actually loops through each item, allowing you do do something different to each object.</p>\n\n<p>for example, you put</p>\n... | {
"AcceptedAnswerId": "14026",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T20:10:32.530",
"Id": "14022",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "New at jQuery, lack of structure"
} | 14022 |
<p>Im trying to teach myself enough to start using more OOP in php. This is what Ive come up with. Is there any reason why any of this is done wrong, or should be done another way?</p>
<pre><code> class workers {
private $name;
function __construct($name){
$this->name=$n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T19:46:03.877",
"Id": "22688",
"Score": "2",
"body": "note: make it `isBoss`, and return a boolean."
}
] | [
{
"body": "<p>I would set the workers class as <code>abstract</code> (as pointed out by Andreas). </p>\n\n<p>Also, I would use a shared member variable in the parent class which is set in each child's constructor. Also, I wouldn't use a static function to print the object as a string, that's more suited for <co... | {
"AcceptedAnswerId": "14025",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T19:24:51.413",
"Id": "14023",
"Score": "0",
"Tags": [
"php",
"object-oriented"
],
"Title": "advice on polymorphism"
} | 14023 |
<p>I have written a module in my application that makes extensive use of dynamic LINQ to produce Linq/SQL queries based on user interface selection.
Currently, the Linq-SQL translation is resulting in very unoptimised query results, so I am looking at ways to get LINQ to improve the SQL that it is producing.</p>
<p>Th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T17:07:53.277",
"Id": "22700",
"Score": "0",
"body": "How do you actually generate the LINQ query?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T17:18:39.177",
"Id": "22701",
"Score": "0",
... | [
{
"body": "<p><code>Company_contacts.Any(x => x.Company_contacts.Cust_order_header.Any(y => y.Order_time >= @0))</code></p>\n\n<p>That should put the joins in for you. Right now it is not referencing the objects you use in the query through their relationships so it is writing the SQL out as though the... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-25T16:59:25.220",
"Id": "14029",
"Score": "5",
"Tags": [
"sql",
"performance",
"linq"
],
"Title": "Producing queries based on user interface selection"
} | 14029 |
<p>I'm looking for a new job, and a company who had a role I was going for asked me to do a programming exercise. It consisted of making a web application of two or more pages that took a person's name and a number, and then rendered the number converted to words. I sent it off and they replied saying that the code was... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T01:35:22.690",
"Id": "22710",
"Score": "0",
"body": "I've noticed that I forgot to remove the top 4 lines from IntToWords, I'll leave it in though so you can judge the code that I sent off."
}
] | [
{
"body": "<p>I'm going to focus only on <code>IntToWords()</code>, nothing else (although I think using ASP.NET MVC is considered a better practice than plain ASP.NET).</p>\n\n<p>I can see several problems with that code:</p>\n\n<ol>\n<li>You repeat yourself too much. All the code from thousands up to quadrill... | {
"AcceptedAnswerId": "14043",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T00:46:36.557",
"Id": "14033",
"Score": "3",
"Tags": [
"c#",
".net",
"unit-testing",
"interview-questions",
"numbers-to-words"
],
"Title": "Convert number to words (web ... | 14033 |
<p>General advice for a change. This is an implementation of message queues that I'm going to use for some work on an actors model library.</p>
<pre><code>(defclass message-queue ()
((messages :accessor messages :initarg :messages :initform nil)
(last-cons :accessor last-cons :initarg :last-cons :initform nil
... | [] | [
{
"body": "<p>I noticed you defined full read/write accessors on all the slots on your message queue class, yet you bypass all of that and just use with-slots. Are you planning on exporting those accessors as part of the API? It seems like you wouldn't want to encourage people to monkey with those slot values, ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T02:47:28.103",
"Id": "14036",
"Score": "3",
"Tags": [
"common-lisp",
"queue"
],
"Title": "Message queues in Common Lisp"
} | 14036 |
<p>A while ago I used this code to load content into a <code>div</code> using jQuery <code>load</code>. I repeated the code for all the clicks to load different pages in the same <code>div</code>.</p>
<p>Is there any other way to do this?</p>
<pre><code>$("#button1").click(function(){
$('#div1').load('page1.php')... | [] | [
{
"body": "<h3>Option 1:</h3>\n\n<p>If your buttons and pages are actually numbered like that, you can simply extract the number from the ID:</p>\n\n<pre><code>var $container = $('#div1');\n\n$('[id^=button]').click(function() {\n $container.load('page' + this.id.match(/\\d+$/)[0] + '.php');\n});\n</code></p... | {
"AcceptedAnswerId": "14038",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T03:11:00.520",
"Id": "14037",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Loading content into a div"
} | 14037 |
<p>In the code below , i'm only able to get PHP arrays in javascript to work when I hard code the value . Is this the only way to get it to work, or is their a way to copy the entire PHP array into Javacript . Right now I'm tempted to just create a function chart() for each set of PHP array values. As in rather then wr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T04:41:03.110",
"Id": "22711",
"Score": "0",
"body": "As you can see I've already tried to combine the array values and run split(), but this hasn't worked ..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012... | [
{
"body": "<p>This is the solution I came up with </p>\n\n<p>// in Javascript</p>\n\n<pre><code>var ArrayA = '<?php echo implode(\",\",$AnswerA); ?>';\n var Aname = ArrayA.split(\",\");\n</code></pre>\n\n<p>I know this isn't the best way to do it,but it works </p>\n",
"comments": [],
"meta_dat... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T04:39:58.433",
"Id": "14039",
"Score": "1",
"Tags": [
"javascript",
"php"
],
"Title": "Have to hardcode Array values when using PHP arrays in JS"
} | 14039 |
<p>Can you please check if I've written the code correctly?</p>
<p>The task was:</p>
<ul>
<li>Calculate the user's month of birth as a a number, where January = 0 through to December = 11. </li>
<li>Take the string entered </li>
<li>Get the substring, being the first three characters </li>
<li>Convert to uppercase </... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T11:33:17.393",
"Id": "22718",
"Score": "2",
"body": "@Zirak I've run it, and it works properly. But As I've said, I'm new to programming, and I want to make sure I've covered everything."
},
{
"ContentLicense": "CC BY-SA 3.0... | [
{
"body": "<p>Everything looks good. </p>\n\n<p>That said, <a href=\"http://kangax.github.com/es5-compat-table/#showold\" rel=\"nofollow\"><code>array.indexOf</code> wasn't supported in Internet Explorer until version 9.</a></p>\n\n<p>If you need that support, the Mozilla Developer Network has a <a href=\"https... | {
"AcceptedAnswerId": "14117",
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T11:23:21.737",
"Id": "14044",
"Score": "3",
"Tags": [
"javascript",
"strings",
"beginner",
"datetime"
],
"Title": "Calculating user birth information"
} | 14044 |
<p>I am interested in finding out what is the correct way of implementing error handling for this situation in C#.</p>
<p>The system tries to do an operation. If the operation succeeded (returns a non-error code), the system logs in a log database that the operation was succesfull. If the operation returns a error cod... | [] | [
{
"body": "<p>You could combine the try-catch blocks:</p>\n\n<pre><code>int response = -1; //some error code\nvar logging = false;\ntry\n{\n //some code to prepare the operation - may cause exceptions\n response = DoOperation();\n //some code to clean after the operation - may cause exceptions\n\n ... | {
"AcceptedAnswerId": "14048",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T13:35:49.550",
"Id": "14046",
"Score": "2",
"Tags": [
"c#",
"exception",
"error-handling"
],
"Title": "Suggestions for improving error handling"
} | 14046 |
<p>I setup simple CRUD in Django</p>
<pre><code>from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.urlresolvers import reverse_lazy
from django.http import HttpResponseRedirect
from intentions.models import User,Prayer,Intention
from intentions.forms import Inte... | [] | [
{
"body": "<p>1.Using <code>render</code> shortcut function is more preferable than <code>render_to_response</code>. The difference is explained on <a href=\"https://stackoverflow.com/a/5154458/455833\">SO</a> </p>\n\n<pre><code>def index(request):\n intentions = Intention.objects.all();\n return render('... | {
"AcceptedAnswerId": "14067",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T14:19:14.473",
"Id": "14047",
"Score": "2",
"Tags": [
"python",
"django"
],
"Title": "Need advice of refactoring views.py"
} | 14047 |
<p>I am currently writing a rather large client-side JS application which is made of of multiple modules, each in different files (before compiling). I am using Node.js to build the final script based on all the individual modules. </p>
<p>For the script to work properly all modules must be added in the proper order, ... | [] | [
{
"body": "<p>I have an experience with requirejs as a dependency management framework, it allows the compiling on the server side with the following snippet </p>\n\n<pre><code>node r.js -o path/to/buildconfig.js\n</code></pre>\n\n<p>the config</p>\n\n<pre><code>// **r.js** configuration\n({\n appDir : \"../\"... | {
"AcceptedAnswerId": "14308",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T15:24:19.837",
"Id": "14049",
"Score": "2",
"Tags": [
"javascript",
"node.js"
],
"Title": "Build process for compiling client JS modules into one script"
} | 14049 |
<p>I am trying to eliminate unwanted namespaces, and I know there's a better way to do this. This code works, but it's remedial and redundant.</p>
<pre><code>string sPattern = "xmlns:d5p1=\"http://www.w3.org/2001/XMLSchema-instance\" d5p1:nil=\"true\"";
string sPattern2 = "d5p1:nil=\"true\" xmlns:d5p1=\"http://www.w3... | [] | [
{
"body": "<p>Well, the first thing I'd do is put the patterns in a list, and loop through matching them. The second thing would be general cleanup; use namespaces where you can, one-liner if/else clauses don't need braces, use var where the type is obvious, etc etc. This gets rid of that if-elseif structure an... | {
"AcceptedAnswerId": "14052",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T19:56:39.263",
"Id": "14051",
"Score": "3",
"Tags": [
"c#",
"regex",
"xsd",
"namespaces"
],
"Title": "Eliminating unwanted namespaces"
} | 14051 |
<p>I am writing a program for my trading application. Over the months the program has been growing steadily, and what is used to be a small program now I would call a medium size program (about 1000-2000 lines in total), and it will keep growing as I add more features to it. It has grown to a point where it start to g... | [] | [
{
"body": "<p>Ideas:</p>\n\n<p><em>Do</em> create methods and call them. That does <em>not</em> defeat... And it's easy - just select that code and click: Refactor -> Extractmethod.</p>\n\n<p>Create <em>classes</em> and so, your variables will not pollute other classes with their names.</p>\n\n<p>You <em>can</e... | {
"AcceptedAnswerId": "14059",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-26T18:39:57.517",
"Id": "14054",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Program for a trading application"
} | 14054 |
<p>I needed to write a function today in JavaScript that would return all elements based on a given attribute. </p>
<p>e.g retrieve all elements that have an id attribute in them. </p>
<p>The function I wrote for this is as follows:</p>
<pre><code>function getElements(attrib) {
// get all dom elements
var el... | [] | [
{
"body": "<p>I'm not too familiar with JS, so just three generic notes:</p>\n\n<ol>\n<li><p>It seems to me that the <code>elements[i].attributes.length > 0</code> check is unnecessary because the statements inside the following <code>for</code> loop won't if <code>elements[i].attributes.length</code> is zer... | {
"AcceptedAnswerId": "14063",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T01:06:24.087",
"Id": "14061",
"Score": "8",
"Tags": [
"javascript",
"dom"
],
"Title": "JavaScript function to get DOM elements by any attribute"
} | 14061 |
<p>Is large use of closures actually a bad thing for readability and maintainability of the code? For example, consider the following code with (comments removed on purpose):</p>
<pre><code>$withMobile = function($c) { return $c->getMobile() !== null; };
$extractAll = function($c) { return $c; };
$extractId = f... | [] | [
{
"body": "<p>It's not that bad β one can quickly grasp what it is doing and where is it going, which should be good news. I would personally recommend however the following when dealing with closures:</p>\n\n<ul>\n<li>If the closure is only to be used once, hardcode it into the arguments. That way it's a bit e... | {
"AcceptedAnswerId": "14176",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T03:34:09.347",
"Id": "14064",
"Score": "3",
"Tags": [
"php"
],
"Title": "Closures power and concise style vs readability and maintainability?"
} | 14064 |
<p>I've been working on a simple program to output values to the console as a learning project, and I stumbled across an article advising against using 2D containers, suggesting to simulate them instead with a 1D vector/container. I immediately proceeded to try to create a ridiculous class that converted input X and Y... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T16:59:43.663",
"Id": "22774",
"Score": "0",
"body": "If you are simulating a 2D vector with a 1D vector, you should still be able to use the 2D syntax `m[1][1]`."
}
] | [
{
"body": "<h3>Simple Review of code</h3>\n\n<p>In this pass I will do a simple review of the code you have written.<br>\nI think there are some problems with the design of your interface but I will deal with those completely separately so this part of the review is solely on the code you have written and assum... | {
"AcceptedAnswerId": "14082",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T03:34:39.903",
"Id": "14065",
"Score": "2",
"Tags": [
"c++",
"template",
"vectors",
"container"
],
"Title": "Simple container class with templates"
} | 14065 |
<p>I needed to IP block something in nginx and I ended up with duplicated <code>proxy_forward</code> code. How can I refactor and un-duplicate this?</p>
<pre><code>server{
location /admin{
allow 123.90.250.0/24;
allow 123.66.148.0/24;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_... | [] | [
{
"body": "<p>You may move proxy settings to 'server' block. But proxy_pass should stay at 'location' block</p>\n\n<pre><code>upstream foo {\n server 127.0.0.1:8080;\n}\n\nserver{\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header Host $http_host;\n proxy_redirect off;... | {
"AcceptedAnswerId": "14069",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T03:45:03.713",
"Id": "14066",
"Score": "2",
"Tags": [
"nginx"
],
"Title": "Unduplicating prox_pass in nginx location blocks"
} | 14066 |
<p>I need to define custom calendars and, in particular, test a <code>DateTime</code> for being a holiday. My current code is shown below. Is there a more concise/better way of doing this, preferably without sacrificing performance?</p>
<pre><code>let private isHoliday2011 (dt:DateTime) =
match dt.DayOfWeek with
|... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T17:38:01.167",
"Id": "22775",
"Score": "0",
"body": "I think your code is as good as it gets. All the other answers involving data structures sacrifice performance for no real gain in clarity. To tweak your code for clarity, you cou... | [
{
"body": "<p>I think using a list would be better - something like</p>\n\n<pre><code>let holidays = (1,3)::(1,4)::...\nlet isHoliday2011 (dt:DateTime) =\n let d,m = dt.Month, dt.Day\n holidays |> List.exists (fun (mm,dd) -> m=mm && d=dd)\n</code></pre>\n",
"comments": [],
"meta_data... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T09:41:16.837",
"Id": "14070",
"Score": "2",
"Tags": [
"algorithm",
"f#"
],
"Title": "Is there a better way of defining custom calendars?"
} | 14070 |
<p>I have a set of <code>if</code>/<code>else</code> statements that trigger certain actions. As a first step, I was thinking about moving the logic in each <code>if</code> statement to be its own function, but are there any recommendations on what design patterns can help clean this code up?</p>
<p>I guess I am tryin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T03:41:03.960",
"Id": "22758",
"Score": "0",
"body": "Have a look at [The Clean Code Talks](http://www.youtube.com/watch?v=4F72VULWFvc)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T03:42:03.233",
... | [
{
"body": "<p>In this case, in every step you could do:</p>\n\n<pre><code>buckets.secondContainer.empty();\nbuckets.firstContainer.transferTo(buckets.secondContainer);\nbuckets.firstContainer.fill();\n</code></pre>\n\n<p>Then inside each function you could test if there is anything to do and if not, return.</p>... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T03:39:05.743",
"Id": "14073",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Finding a way to obtain some volume of water using a large and small bucket"
} | 14073 |
<p>I have following model and database created using Entity Framework. Is it proper TPT Inheritance?</p>
<p>Is it possible to make the base class as <strong>abstract</strong>?</p>
<p>Model</p>
<p><img src="https://i.stack.imgur.com/ecczh.jpg" alt="enter image description here"></p>
<p>Database</p>
<p><img src="htt... | [] | [
{
"body": "<p>Yes, it is a proper TPT inheritance and yes, you can mark your base class as abstract.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T07:48:17.530",
"Id": "14097",
"ParentId": "14077",
... | {
"AcceptedAnswerId": "14097",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T13:56:21.023",
"Id": "14077",
"Score": "1",
"Tags": [
"c#",
".net",
"object-oriented",
"entity-framework"
],
"Title": "Is it proper TPT Inheritance"
} | 14077 |
<p>I'm learning Python by converting a BASIC (BlitzPlus) program I wrote based on article at <a href="http://gamedeveloper.texterity.com/gamedeveloper/201002?pg=42#pg43" rel="nofollow">http://gamedeveloper.texterity.com/gamedeveloper/201002?pg=42#pg43</a> for random dungeon generation.</p>
<p>I've basically used Googl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T20:22:03.263",
"Id": "22804",
"Score": "3",
"body": "First thought? Separation of concerns. Generating a random dungeon does not equal drawing a random dungeon. Separate your functionality into a part that generates a data structure... | [
{
"body": "<p>It reads very much as a Basic program, but it's a reasonable first(ish) python program.</p>\n\n<p>Steps to improve it:\nTurn your existing global code into a \"main\" function, and call it via</p>\n\n<pre><code>if __name__ == \"__main__\":\n main()\n</code></pre>\n\n<p>Move all your global vari... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T15:33:29.307",
"Id": "14079",
"Score": "2",
"Tags": [
"python"
],
"Title": "Random dungeon generator"
} | 14079 |
<p>I have a serious nesting of <code>if</code>s in a helper code and I would like to making cleaner. I would like to avoid <code>case</code> if possible as well.</p>
<p>I know there is probably a more object-oriented approach to this but I can't seem to know how.</p>
<p>I'm flooded with stuff like this:</p>
<pre><co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T18:07:04.593",
"Id": "22776",
"Score": "0",
"body": "If the return values are mutually exclusive, it seems like it would make more sense to have print_flight_options_status contain a symbol that is updated by the various things you ... | [
{
"body": "<p>There is a <code>case</code>-variant which may be a bit better:</p>\n\n<pre><code>x = ''\ncase \n when x == 'xxy'\n puts '=xxy'\n when x.empty?\n puts 'is empty'\n else\n puts \"well, I don't know, what it is\"\n end\n</code></pre>\n\n<p>In your case, you could use:</p>\n\n<pre><code>... | {
"AcceptedAnswerId": "14085",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T17:13:23.217",
"Id": "14080",
"Score": "2",
"Tags": [
"ruby"
],
"Title": "Printing flight statuses"
} | 14080 |
<p>After posting a question about <a href="https://stackoverflow.com/questions/11680176/alphanumeric-hash-a-z-0-9">Alphanumeric Hash generation</a> on StackOverflow, the most helpful answer was to change the conversion method from pulling 5-bit chunks of a binary hash value, to instead changing the number to base-36. <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T12:41:43.393",
"Id": "22797",
"Score": "0",
"body": "could you show us some sample input and output so we can verify our solutions? At the moment I'm not sure how many bytes will normally be in `toConvert`..."
},
{
"ContentL... | [
{
"body": "<p>Have you considered using <code>System.Numerics.BigInteger</code> to avoid having to do the math yourself?</p>\n\n<p><code>BigInteger.DivRem</code> even allows you to do both calculations at once.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | {
"AcceptedAnswerId": "14088",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T18:11:29.573",
"Id": "14084",
"Score": "6",
"Tags": [
"c#",
"algorithm",
"bitwise"
],
"Title": "Base-36 encoding of a byte array"
} | 14084 |
<p>So here we are, using a <code>StringBuilder</code> to build an email body. I know there's a lot on StackOverflow and endless debate/discussion around how best to concatenate strings.</p>
<ul>
<li>Can this be done in fewer lines of code in C#?</li>
<li>Can this be done better using templating?</li>
</ul>
<p>My goal... | [] | [
{
"body": "<p>I have used one template engine in <a href=\"/questions/tagged/c%23\" class=\"post-tag\" title=\"show questions tagged 'c#'\" rel=\"tag\">c#</a> by name <a href=\"https://github.com/formosatek/dotliquid/wiki/DotLiquid-for-Developers\" rel=\"nofollow\">DotLiquid</a> to resolve similar problems. </p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-27T22:54:07.377",
"Id": "14089",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Building an email body"
} | 14089 |
<p>I am building a dynamic site. All data will be served through an index.php in my webroot, using jquery to update the content. In webroot, I have a folder 'i/' which contains the files I want to include. The main include files contain code which will be used on every page: globals.php, globals.css, globals.js, etc. p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T01:01:42.170",
"Id": "22789",
"Score": "0",
"body": "Your function has a syntax error, and [it doesn't output anything](http://codepad.org/Mxo4yoGN). What's the desired output?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>Don't make your directory structure so vague. Coming into this with no knowledge of your system how am I supposed to know what the \"i\" directory is? Just call it includes. Also, it is usually a good idea to separate your files based on their types so that they are easier to find. There are many ... | {
"AcceptedAnswerId": "14172",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T00:41:56.863",
"Id": "14091",
"Score": "0",
"Tags": [
"php"
],
"Title": "php function for gathering includes...is there a better way than this?"
} | 14091 |
<p>I want to allow users to share documents (and other stuff) in a database-driven application.</p>
<p>I have designed the following schema to allow for this (PostgreSQL). Some of the tables like <code>Party</code> are skeletal for simplicity.</p>
<p>Diagram (minus lookup tables):</p>
<p><img src="https://i.stack.imgur... | [] | [
{
"body": "<p>I would definitely rename <code>onlyOwnerCanChangePermissions</code>, maybe to <code>permissive</code> or <code>restrictPermissions</code> or something like that.</p>\n\n<p>I would also definitely remove <code>item.ownerId</code>, create a new RoleType <code>owner</code> and propagate an <code>ite... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-07-28T02:53:16.043",
"Id": "14093",
"Score": "6",
"Tags": [
"sql",
"mysql",
"postgresql"
],
"Title": "Schema for Google Docs-like sharing"
} | 14093 |
<p>I use a global variable to fit my need:</p>
<pre><code>scores = {}
def update():
global scores
# fetch data from database
scores = xxx
class MyRequestHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
def choice_with_score(items):
# return a key r... | [] | [
{
"body": "<p>You could use a class to keep your <code>scores</code> inside a defined scope and not use the globals. This way it's fairly easy to test and you don't have to deal globals. All you need to ensure is that you always pass the same instance. You could probably do it using some sort Singleton patterns... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T04:38:35.750",
"Id": "14094",
"Score": "5",
"Tags": [
"python",
"tornado"
],
"Title": "Is there a better way to do get/set periodically in tornado?"
} | 14094 |
<p>I need to write some code that checks thousands of websites, to determine if they are in English or not.
Below is the source code. Any improvements would be appreciated.</p>
<pre><code>import nltk
import urllib2
import re
import unicodedata
ENGLISH_STOPWORDS = set(nltk.corpus.stopwords.words('english'))
NON_ENGLIS... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T13:57:47.007",
"Id": "23972",
"Score": "0",
"body": "Does your code work as you intend it to? What problems do you see with it? (To help us focus on those...)"
}
] | [
{
"body": "<p>Some of your functions behave a bit unconventionally.</p>\n<p><code>checkEnglish()</code> only returns 1 or 0. It would be clearer to return <code>True</code> or <code>False</code>, and rename the function to <code>isEnglish()</code>.</p>\n<hr />\n<p><code>getPage()</code> won't allow retrieval o... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T07:57:33.870",
"Id": "14098",
"Score": "2",
"Tags": [
"python",
"parsing",
"natural-language-processing"
],
"Title": "NLTK language detection code in Python"
} | 14098 |
<p>I have written a generic <code>Collection</code> class which allows me to add and remove items from an encapsulated <code>std::list</code>. The collection will raise an event when an item has been added or removed.</p>
<p>Normally I would have derived this class from the <code>std::list</code>, but I have been stro... | [] | [
{
"body": "<p>Yes.</p>\n\n<p>But you also want to expose the types of the iterator:</p>\n\n<pre><code>template <typename T>\nclass Collection\n{\n // Since we are going to mention the container type\n // in multiple places actually give it a shorter name.\n // This also helps if you change the co... | {
"AcceptedAnswerId": "14104",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T12:35:02.857",
"Id": "14099",
"Score": "2",
"Tags": [
"c++"
],
"Title": "Collection in C++"
} | 14099 |
<p>I am new to<code>boost::thread</code> and am making a producer-consumer with a <code>Monitor</code>. This is how I've coded it so far:</p>
<pre><code>//{ Declarations in header
private:
boost::condition_variable _condition;
boost::mutex _mutex;
std::deque<RawMatrix*> _queue;
b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T19:08:36.393",
"Id": "22802",
"Score": "1",
"body": "We can review the first part of the code here. But this is probably not the best site to ask `ho`w to do something; first its off-topic but secondly there are fewer experts roamin... | [
{
"body": "<p>Why do you insist on putting the '<em>' on members. It makes them look so ugly. Also most identifiers beginning with '</em>' are reserved so you need to be careful. If you must use decade old conventions (that have been abandoned) to identify members use 'm_` as the prefix.</p>\n\n<p>The reason I ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T13:18:13.937",
"Id": "14100",
"Score": "2",
"Tags": [
"c++",
"multithreading",
"boost",
"producer-consumer"
],
"Title": "boost::thread producer consumer"
} | 14100 |
<p>I'm a beginner in JavaScript. I wrote this code so the main image get set on whatever thumbnail image the user clicks. </p>
<p>And if the user didn't click on any image the main photo get changed every 10 seconds. </p>
<p>Here's my code (I feel like I'm doing some unnecessary work here in the timers but I can't f... | [] | [
{
"body": "<p>This code could use some changes</p>\n\n<ul>\n<li>Using <code>window.onload</code> is a bit old skool, consider using <a href=\"https://stackoverflow.com/a/559161/7602\">this</a>.</li>\n<li>If you put <code>id=\"mainImage\"</code> on the image instead of on the div, you can change your code to <co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T18:22:05.850",
"Id": "14103",
"Score": "6",
"Tags": [
"javascript",
"html",
"beginner",
"css"
],
"Title": "A script for a photo gallery/slideshow"
} | 14103 |
<p>I have this function that calculates average. I don't want it to look like this. I am hoping for a less cliche average function because I see that most people's look like this.</p>
<pre><code>function mean(array) {
var num=0;
for (var i=1;i<=array.length;i++) num=num+array[i];
var divide=num/array.le... | [] | [
{
"body": "<p>First of all, your code is incorrect. Arrays have a starting index of <code>0</code>, not <code>1</code>. Furthermore, <code>array.length</code> is one more than the last filled index (because the length is 1 based, and the array is 0 based. Yes, this is confusing.) So you're starting by not inclu... | {
"AcceptedAnswerId": "14107",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T20:01:16.653",
"Id": "14106",
"Score": "8",
"Tags": [
"javascript",
"beginner"
],
"Title": "JavaScript function to calculate the average of an array"
} | 14106 |
<pre><code>def json_response(response):
assert response.code == 200, 'bad http response'
return json.loads(response.body)
def custom_json_response(response):
response = json_response(response)
assert 'answer' in response, 'invalid custom json'
return response['answer']
</code></pre>
<p>The code lo... | [] | [
{
"body": "<p>I'm not sure I'm directly responding to your points, since I don't think I get what you're aiming for, but:</p>\n\n<ul>\n<li><p><code>assert</code>s shouldn't be used for these types of checks (I personally don't use them at all, but if you are going to use them, they're for checking invariants)</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-28T22:33:18.300",
"Id": "14110",
"Score": "2",
"Tags": [
"python",
"functional-programming"
],
"Title": "Safe composition in python"
} | 14110 |
<p>If you use capturing parenthesis in the regular expression pattern in Python's <code>re.split()</code> function, it will include the matching groups in the result (<a href="http://docs.python.org/library/re.html#re.split" rel="nofollow">Python's documentation</a>).</p>
<p>I need this in my Clojure code and I didn't... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T20:33:50.170",
"Id": "79236",
"Score": "3",
"body": "For what it's worth, [clojure.contrib.string/partition](http://clojuredocs.org/clojure_contrib/clojure.contrib.string/partition) does this exactly."
}
] | [
{
"body": "<p>You can adjust you implementation to be a lazy-seq for some added performance:</p>\n\n<pre class=\"lang-lisp prettyprint-override\"><code>(use '[clojure.string :as string :only [blank?]])\n\n(defn re-tokenizer [re text]\n (let [matcher (re-matcher re text)]\n ((fn step [last-index]\n (wh... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-29T08:49:34.703",
"Id": "14113",
"Score": "3",
"Tags": [
"python",
"regex",
"clojure"
],
"Title": "Implementation of Python's re.split in Clojure (with capturing parentheses)"
} | 14113 |
<p>Below is an algorithm to generate all pairwise combinations for a set of random variables. <a href="http://en.wikipedia.org/wiki/All-pairs_testing" rel="nofollow">See here</a> for an explanation of what constitutes a minimal all-pairs set. The algorithm below works but I feel that it is inefficient. Any suggestions ... | [] | [
{
"body": "<p>This is not generating correct pairwise combinations.</p>\n\n<p>Input data</p>\n\n<pre><code>[['Requests'],\n ['Create','Edit'],\n ['Contact Name','Email','Phone','Subject','Description','Status','Product Name','Request Owner','Created By','Modified By','Request Id','Resolution','To Address'... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-29T20:02:46.787",
"Id": "14120",
"Score": "7",
"Tags": [
"python",
"algorithm",
"combinatorics"
],
"Title": "Pairwise Combinations Generator"
} | 14120 |
<p>I have just written a solution to the following problem: </p>
<blockquote>
<p>We all know the classic "guessing game" with higher or lower prompts. lets do a role reversal; you create a program that will guess numbers between 1-100, and respond appropriately based on whether users say that the number is too high ... | [] | [
{
"body": "<p>It seems to me that you understand the concept correctly, but your implementation is horrible. That's because you don't need the whole <code>_possibleAnswers</code> list at all, you should just keep two numbers: the lower bound and the upper bound, you can compute everything you need from that.</p... | {
"AcceptedAnswerId": "14122",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-29T20:25:39.847",
"Id": "14121",
"Score": "4",
"Tags": [
"c#",
"game",
"binary-search"
],
"Title": "Number-guessing game in C#"
} | 14121 |
<p>Part of an application that I am building in CakePHP 2.1 needs to send out an e-mail based on a template from a database. The end user is able to set the from, reply to, to, cc, and bcc addresses. Because the user could enter just about anything, I need to process those addresses into a usable array that I can pass ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T17:19:47.457",
"Id": "23228",
"Score": "0",
"body": "Our team was kicked off the project due to budget concerns before I got the chance to refactor this code. Oh well."
}
] | [
{
"body": "<p>Alright, I have a number of suggestions. Some of which will invalidate others. The reason I'm keeping these \"invalid\" bits in is because they are just good practice and I'm trying to pass that along. In order to get the most from this you will have to read all the way through.</p>\n\n<p>First of... | {
"AcceptedAnswerId": "14170",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-29T23:46:06.227",
"Id": "14127",
"Score": "2",
"Tags": [
"php"
],
"Title": "Process list of e-mail addresses in PHP 5.3"
} | 14127 |
<p>So I feel like I'm a good coder, but that's from my point of view. Can you take a look at my code and give me some tips or criticize me on my code. Or give me some tips or things to add or make things smaller.</p>
<p>console class</p>
<pre><code> public class console {
public static void main(String[] ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T05:24:27.390",
"Id": "22838",
"Score": "5",
"body": "Consistent spacing and indenting will help you and the reviewers."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T07:01:47.260",
"Id": "22872",... | [
{
"body": "<p>Some tips:</p>\n\n<ul>\n<li>In Java there is a convention - names of classes start with uppercase letter</li>\n<li>Instance variables like <code>JTextArea</code> etc. should be private and not static. Static fields should be used very rarely.</li>\n<li>Every Swing component should be created and c... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T02:24:18.807",
"Id": "14130",
"Score": "2",
"Tags": [
"java",
"parsing",
"swing"
],
"Title": "Can you guys look at my java project and give me some tips?"
} | 14130 |
<p>Here is my method:</p>
<pre><code>// can change
DWORD step[2] = { 0xAC, 0x723A };
packageType = 1;
DWORD computeLevel(DWORD blockNum)
{
DWORD num = (blockNum / 0x70E4) * step[1];
if (blockNum < 0x70E4)
return num + step[0];
return (1 << packageType) + num;
}
</code></pre>
<p>I am tryi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T06:19:48.550",
"Id": "22842",
"Score": "1",
"body": "Are there any characteristics of blockNum that we need to be aware of? Occurs sequentially with no gaps? Essentially random on each call? Only in a specific range?"
},
{
"... | [
{
"body": "<p>I'll expand on this later when I get a chance, but something immediately jumps out at me:</p>\n\n<pre><code>DWORD num = (blockNum / 0x70E4) * step[2];\nif (blockNum < 0x70E4)\n</code></pre>\n\n<p>You could rearrange this and potentially save a few operations:</p>\n\n<pre><code>DWORD computeLeve... | {
"AcceptedAnswerId": "14138",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T05:21:50.107",
"Id": "14133",
"Score": "0",
"Tags": [
"c++",
"optimization"
],
"Title": "How can I optimize this for speed? (C++)"
} | 14133 |
<p>I hava a collection of schedules - <code>EventSchedules</code>. I want to select from this collection today, tomorrow and after tomorrow schedules. The day start from 06:00 and end 6:00 of next day. </p>
<p>Examples:</p>
<ul>
<li>For today the query return events start in range: 30 July 2012 06:00 - 31 July 2012 ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T07:59:03.373",
"Id": "22853",
"Score": "0",
"body": "What kind of collection is `EventScheduleList`? Does performance matter to you or is readability more important? How big is the collection? Is it already sorted?"
},
{
"Co... | [
{
"body": "<p>I can see two issues with your code:</p>\n\n<ol>\n<li><p>It doesn't work. Because the local variables <code>filterTimeStart</code> and <code>filterTimeEnd</code> are put in the closure, and the <code>Where()</code> lambdas are executed only when you iterate the resulting enumerables, all of your s... | {
"AcceptedAnswerId": "14140",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T06:39:42.537",
"Id": "14135",
"Score": "0",
"Tags": [
"c#",
"linq",
"scheduled-tasks"
],
"Title": "Collection of schedules"
} | 14135 |
<p>I have been looking at a couple of different approaches on how I can notify the UI about messages coming from the ViewModel, and wanted to see if this seemed appropriate or if it is too coupled. (We already have a static class that deals with notifications that I am trying to wrap for now, and maybe remove at a late... | [] | [
{
"body": "<p>If you are looking for a general approach for notifications (I imagine something along the lines of a \"notification tray\", so corrent me if I'm wrong), this is, how I do it:</p>\n\n<p>The notification is always realyed through the Messenger class from one ViewModel to another. The ViewModel of t... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T14:24:38.283",
"Id": "14147",
"Score": "2",
"Tags": [
"c#",
"wpf",
"mvvm"
],
"Title": "MVVM notification messages"
} | 14147 |
<p>When I realized that the code below has a major problem in what it'll do (it'll just update the database with information currently in the database), I was told that there are a lot of mistakes.</p>
<p>Please point out the mistakes to me, suggest improvements and how to avoid the mistakes in the future.</p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T15:16:46.653",
"Id": "22876",
"Score": "4",
"body": "This code uses .NET 1.0 technology. You can still learn and use that but step quickly into Entity Framework."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2... | [
{
"body": "<p>I'm not sure why you're using your own built classes to access the database when .net has a very complete set of classes that can be used for data access.</p>\n\n<p>Just looking at your syntax, I see the same functionality, so to me that is a waste of development time.</p>\n\n<p>Also, it seems whi... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T15:08:03.507",
"Id": "14149",
"Score": "11",
"Tags": [
"c#",
"mysql"
],
"Title": "Updating user information"
} | 14149 |
<p>I'm looking for a better more efficient way to write some code I have where I"m synchronizing two lists. Basically, the first list is a list of devices I need to check. The second list is a list of devices that I have already checked with dates. I need to synchronize the two lists so I only check devices that are... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T16:41:35.483",
"Id": "22878",
"Score": "0",
"body": "You're used to writing SQL queries with outer joins, don't you? :-)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T17:05:08.843",
"Id": "22880... | [
{
"body": "<p>I haven't tested this due to time constraints, and lack of knowledge of the data, but from my understanding of the problem, this should work.</p>\n\n<p>I have taken the linq join queries, two for the insert, two for the delete and created two IEnumerable.Where clauses, one for insert, one for dele... | {
"AcceptedAnswerId": "14154",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T16:18:11.583",
"Id": "14150",
"Score": "2",
"Tags": [
"c#",
"linq"
],
"Title": "Synchronization of two lists"
} | 14150 |
<p><strong>Edit:</strong> I updated the JavaScript modules in <a href="http://enlargeyourpassword.com" rel="nofollow">http://enlargeyourpassword.com</a> to use scope(). You can see the result in the source of the page, and get an idea of the process by looking at the <a href="https://github.com/eric-brechemier/enlargey... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T17:09:26.507",
"Id": "22882",
"Score": "0",
"body": "If you know about [AMD](http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition) and [RequireJS](http://requirejs.org) etc.. why did you create this?"
},
{
"ContentLi... | [
{
"body": "<p>I could suggest you to have a look at requirejs (http://requirejs.org/) and plugin (https://github.com/tbranyen/use.js) for it for synchronous loading scripts to respect dependencies</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T16:... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T17:02:54.817",
"Id": "14153",
"Score": "8",
"Tags": [
"javascript",
"library"
],
"Title": "Usability of API to declare modules in JavaScript"
} | 14153 |
<p>I'm using the following pattern in my mobile app. The code snippet below manages a stopwatch.</p>
<p>Is there a way to simplify the code for better readability and probably getting away from needing to use <code>MyApp.stopwatch.</code> inside it? Somehow in some cases using <code>this</code> instead works, and in s... | [] | [
{
"body": "<p>This is what I came up with (untested):</p>\n\n<p>I got rid of your settings-stuff, introduced a variable <code>self</code> so there's no interference with <code>this</code>, moved your initialization code to the only place it is (and can ever be) called from, extracted a method for padding and ev... | {
"AcceptedAnswerId": "15042",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T22:26:34.870",
"Id": "14157",
"Score": "5",
"Tags": [
"javascript",
"optimization",
"design-patterns",
"timer"
],
"Title": "Managing a stopwatch mobile app"
} | 14157 |
<p>This morning I decided to write this question: <a href="https://stackoverflow.com/questions/11727571/are-there-problems-if-i-have-a-verbose-datatype/11727723#11727723">https://stackoverflow.com/questions/11727571/are-there-problems-if-i-have-a-verbose-datatype/11727723#11727723</a></p>
<p>I don't really explain my ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T22:56:08.120",
"Id": "22908",
"Score": "1",
"body": "For readabilitiy I prefer the curly brackets in conditions and loops, one place I saw you could use var. I dont mind the `nested IDictionary`'s, if you did wrap them up in another... | [
{
"body": "<p><code>IDictionary<string, IDictionary<Levels, IList<ProblemRule>>></code> is difficult to understand and maintain. I don't know enough about your problem domain to give you reasonably sounding names for classes, but I'll try.</p>\n\n<p>In your <code>LoadProblems</code> method, I ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-30T22:30:13.627",
"Id": "14158",
"Score": "4",
"Tags": [
"c#",
"algorithm",
"object-oriented"
],
"Title": "How to refactor a verbose datatype?"
} | 14158 |
<p>I am building a website that uses Amazon S3 to host its image (and other) files.</p>
<p>I require that images displayed on the website look like they come from my site and not from Amazon (so we are talking on the request/response level). What I have done is created a controller which all these files will pass thr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-11-06T16:54:02.633",
"Id": "126154",
"Score": "0",
"body": "Can't this problem be solved easier by [Customizing Amazon S3 URLs with CNAMEs](http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html#VirtualHostingCustomURLs)?"
}... | [
{
"body": "<p>I don't understand the point in using this pattern:</p>\n\n<pre><code> catch (WebException ex)\n {\n var state = (RequestState)result.AsyncState;\n\n if (state.Response != null)\n state.Response.Close();\n\n AsyncManager.Parameters[\"webException\"] = ex;\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T05:01:28.953",
"Id": "14160",
"Score": "2",
"Tags": [
"c#",
"mvc",
"asynchronous",
"asp.net-mvc-3",
"amazon-s3"
],
"Title": "Amazon S3 pass-through controller"
} | 14160 |
<p>I'm writing a results wrapper for a <a href="https://github.com/dtuite/dinosaurus" rel="nofollow">gem which wraps a Thesaurus API</a>. Basically, when you lookup a word in the thesaurus, the results come back in approximately this JSON form:</p>
<pre><code>{
'noun' => {
'syn' => ['array', 'of', 'synonym... | [] | [
{
"body": "<p>1) I believe that depending on popular and stable libraries is not a problem. Though I prefer more opinionated approach: to <code>symbolize_keys!</code>.</p>\n\n<p>2) You <code>define_method</code> looks clear enough, IMHO </p>\n\n<p>3) You may simplify grouped like this:</p>\n\n<pre><code>def gro... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T10:15:11.653",
"Id": "14162",
"Score": "2",
"Tags": [
"ruby"
],
"Title": "Reasonable ActiveSupport dependency and define_method usage?"
} | 14162 |
<p>I'm writing am application that I've previously posted questions on here, but I'm looking for similar advice if possible. I am looking for how best to write my code, as I have a working example, but to me it feels long winded.</p>
<p>The application first grabs 3 tables via DataContext:-</p>
<pre><code> var... | [] | [
{
"body": "<p>The only change I would make would be to remove the two statements where you create the lists <em>sms</em> and <em>email</em>. They are redundant: by adding the EmailAddress and MobileNumber to the query where you are creating the <em>initialList</em>, you can do a select on the <em>initialList</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T12:48:42.360",
"Id": "14165",
"Score": "4",
"Tags": [
"c#",
"beginner",
"linq"
],
"Title": "Parsing notification information from distribution lists"
} | 14165 |
<p>I need some useful functions that faster than the original. (Original - C++'s functions)</p>
<p>For example:</p>
<pre><code>#include <time.h>
#include <stdio.h>
#include <Windows.h>
struct TestMemory {
double a,b,c;
};
void* __TestMemory__Sample=0;
int WINAPI WinMain(HINSTANCE h1,HINSTANCE... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T21:20:16.663",
"Id": "22939",
"Score": "1",
"body": "1) Did you turn on the optimizer. 2) Did you check to see if your code has been removed by the optimizer. 3) Check that you are timing what you think you are timming."
},
{
... | [
{
"body": "<p>Beware of optimising things, trying to get tiny improvements. By running your program with varying optimisation settings, I got the following ratios (memcpy/memset):</p>\n\n<ul>\n<li>1.8</li>\n<li>1.0</li>\n<li>0.8</li>\n<li>5.1</li>\n</ul>\n\n<p>I think you can use these to prove anything you lik... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T18:40:22.693",
"Id": "14174",
"Score": "-2",
"Tags": [
"performance",
"c",
"memory-management",
"windows",
"winapi"
],
"Title": "Zeroing memory on Windows"
} | 14174 |
<p>Techies--
This routine does more once the channels + the subsets of existing batch arrays are re-distributed for processing. However, the success of that will only work as well as the initial splits. The threshold value is dubbed here, but it will come from app.config as configurable setting. Obviously the jagged st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T20:20:45.397",
"Id": "22935",
"Score": "2",
"body": "What kind of review are you looking for? Are there performance problems? Are you looking at ways of doing things differently, just looking for code improvements?"
}
] | [
{
"body": "<p>I like the formatting, use of white space and tabs.</p>\n\n<p>I'm not sure what THRESHOLD is supposed to represent or where its set, but in the example, I'd make it a const.</p>\n\n<p>I would do the check for 0 right below the assignment:</p>\n\n<pre><code>if (THRESHOLD == 0)\n{\n ...\n\n re... | {
"AcceptedAnswerId": "14177",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T19:37:10.037",
"Id": "14175",
"Score": "2",
"Tags": [
"c#"
],
"Title": "C#; Working code--needs review"
} | 14175 |
<p>I'm designing a small intranet-based time-tracking web app that accepts an unknown number of data "rows" which each consist of 7 form fields. Rows can by dynamically added by the browser.</p>
<p><strong>Can I do better?</strong></p>
<p>Given this (partial) example POST data:</p>
<pre><code>$_POST['project'] =>... | [] | [
{
"body": "<blockquote>\n <p>is this iteration pattern safe?</p>\n</blockquote>\n\n<p>Safe for what? Safe for a database? We can't tell you that! There's no code for your database entry function. What you have here is perfectly safe, but that's excluding any type of insert into a database. To safely protect yo... | {
"AcceptedAnswerId": "42926",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T21:51:17.750",
"Id": "14179",
"Score": "1",
"Tags": [
"html",
"php5",
"codeigniter",
"form"
],
"Title": "Is this a sensible form iteration pattern for a web form with an un... | 14179 |
<p>Any comments are welcome. However I'd like to call specific attention to my... interpretation of the N-Tier application architecture and how I'm consuming data. Note that the namespacing and inline comments have been factored out for brevity.</p>
<h3>The Data Tier (DataModel.csproj)</h3>
<pre><code>// Base class f... | [] | [
{
"body": "<p>I agree that exposing <strong>IRepository<></strong> to the presentation layer is bad.</p>\n\n<p>The reason it's bad is that your Business Logic Tier (BLT) might want to enforce business-y rules on the access of data. That's what the business layer is for, after all.</p>\n\n<p>Your heart is in ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T23:12:39.280",
"Id": "14182",
"Score": "7",
"Tags": [
"c#",
"asp.net-mvc-3",
"mvc"
],
"Title": "ASP.NET MVC using an N-Tier Model and DDD"
} | 14182 |
<p>I'm using the cosine function in C++ to simulate flashing for a sprite in my game. The method looks like this:</p>
<p>(anything in the <code>sf</code> namespace is part of the SFML graphics library)</p>
<pre><code>void Player::update(const float& deltaTime)
{
mAccumulatedTime += deltaTime;
float opacit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T03:08:23.530",
"Id": "22954",
"Score": "0",
"body": "Is delta time in seconds or milli seconds?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T03:18:39.463",
"Id": "22955",
"Score": "1",
... | [
{
"body": "<p>Is it critical that you flash on the maximum? You could change it to flash as it crosses a value if not.</p>\n\n<pre><code>double CalcOpacity( const float& accTime )\n{\n return (cosf(PERIOD*mAccumulatedTime)) * AMPLITUDE;\n}\n\nvoid Player::update(const float& deltaTime)\n{\n float ... | {
"AcceptedAnswerId": "14192",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T01:36:14.973",
"Id": "14183",
"Score": "7",
"Tags": [
"c++",
"sfml"
],
"Title": "Cosine function period"
} | 14183 |
<p>Looking for a code review, as working alone on a project and don't have anyone who could possible help me.</p>
<pre><code>if ($('.qp-content-right-scroll-panel').is(':visible')) {
var isLiveData = $("input:radio[name=preview-options]").val();
if (type.indexOf('DASHBOARD_LAYOUT') != -1) {
var base =... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T03:51:43.147",
"Id": "22957",
"Score": "0",
"body": "Step 1 is running your code through a beautifier. People will put more effort into viewing your code if you present it properly"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>From the looks of it, you are using jQuery as your JavaScript library. Here are the improvements that I think will make your code better.</p>\n\n<p>Don't duplicate code. Use functions (objects).</p>\n\n<p>For example:\n<strong>flashObj</strong> must be accessible to this function.</p>\n\n<pre><cod... | {
"AcceptedAnswerId": "14195",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T02:11:40.463",
"Id": "14185",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Radio button selection and flash object initialization"
} | 14185 |
<p>This Python code parses string representations of Reversi boards and converts them into bit string suitable for use by a bitstring module: <code>b = BitArray('0b110')</code> or bitarray module: <code>a = bitarray('000111')</code> if <code>blackInit</code> and <code>whiteInit</code> are initialized as empty strings.<... | [] | [
{
"body": "<pre><code>def parse_board(board):\n def map_black(spot):\n</code></pre>\n\n<p>This name suggests that the function is a variant on map. Whereas its actually intended to be used as a parameter on map</p>\n\n<pre><code> return str(int(spot == 'B'))\n def map_white(spot):\n return... | {
"AcceptedAnswerId": "14202",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T05:03:43.310",
"Id": "14187",
"Score": "1",
"Tags": [
"python",
"strings",
"parsing"
],
"Title": "Reversi text board parsing to bitfield"
} | 14187 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.