body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<pre><code>import random
from random import choice
import os
import time
import texttable
class Stack():
def __init__(self, replay, winnings):
self.start_amount = 100
self.stored_bet = 0
self.stored_end = 0
self.replay = replay
if self.replay == 0:
self.stored_... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T19:55:30.220",
"Id": "24693",
"Score": "0",
"body": "about `DECK()` class; [it is convention to use CapWords for class names](http://www.python.org/dev/peps/pep-0008/#class-names)."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<ol>\n<li>Python convention is to name classes with CamelCase, not ALL_CAPS</li>\n<li>Don't use 1 and 0 for boolean values, use True and False</li>\n<li>Don't mix UI and logic. You should have some classes/functions that implement the rules for the game, and completely different classes/functions for... | {
"AcceptedAnswerId": "15225",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T19:43:45.973",
"Id": "15219",
"Score": "8",
"Tags": [
"python",
"game",
"playing-cards"
],
"Title": "Blackjack game in Python"
} | 15219 |
<p>I am practicing using the Prototype pattern and to do so, I am building a simple CRUD app that allows me to view, add, and delete customers.</p>
<p><a href="http://jsfiddle.net/phillipkregg/cfafr/146/" rel="nofollow">Here</a> is a JsFiddle for you to see what I've got so far.</p>
<pre><code>// Create customer 'cla... | [] | [
{
"body": "<p>Here's are a few things that I noticed.</p>\n\n<h1>1</h1>\n\n<p>The control and flow of the application needs to be seperated into smaller logical groups.\nThe <code>customers</code> should be a container and controller for the customers, not the otherway around. \nFor example, <code>Customer.prot... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T20:29:22.417",
"Id": "15220",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"crud"
],
"Title": "CRUD app for managing customers"
} | 15220 |
<p>I've written this code to convert an integer number into its word representation. I've tested it for many cases and it seems to be working as expected.</p>
<p>For example:</p>
<ul>
<li>1000 displayed as "One Thousand"</li>
<li>99999 displayed as "Ninety nine thousand nine hundred ninety nine"</li>
<li>999999999 di... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T01:04:16.057",
"Id": "24698",
"Score": "1",
"body": "Although this is targeting c# and may be slighter different you might find this Code Review question useful - http://codereview.stackexchange.com/questions/14033/convert-number-to... | [
{
"body": "<p>Some notes:</p>\n\n<ol>\n<li><p><code>wordForm</code> should be <code>StringBuilder</code>: <a href=\"https://stackoverflow.com/questions/73883/string-vs-stringbuilder\">https://stackoverflow.com/questions/73883/string-vs-stringbuilder</a> Actually, I'd rename it to <code>result</code> too to make... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T00:56:28.350",
"Id": "15224",
"Score": "7",
"Tags": [
"java",
"converting",
"numbers-to-words"
],
"Title": "Converting an integer number into its word representation"
} | 15224 |
<p>I'm trying to build simple pattern matching in a string.</p>
<p>ie., Given a <code>template</code> of: <code>"Hello ${1}"</code> and an <code>input</code> of <code>"Hello world"</code>, I'd like to be able to return a map of <code>1='world'</code>.</p>
<p>This test demonstrates what I'm trying to acheive:</p>
<pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T19:56:15.350",
"Id": "24732",
"Score": "0",
"body": "`NUMERIC_VARIABLES.matcher(sourcestring);` shouldn't be `NUMERIC_VARIABLES.matcher(template)`?"
}
] | [
{
"body": "<p>Just a side note: You could avoid the <code>(String)</code> casting if you used a <code>Map</code> (a <code>HashMap</code>, for example) instead of <code>Properties</code>. <code>Properties</code> has a design flaw: it should not extend <code>Hashtable</code>. </p>\n\n<p><em>Effetcive Java, 2nd E... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T03:20:33.147",
"Id": "15226",
"Score": "2",
"Tags": [
"java",
"regex"
],
"Title": "String pattern matching - method needs improving"
} | 15226 |
<p>Here is my solution to <a href="http://www.reddit.com/r/dailyprogrammer/comments/z3a4y/8302012_challenge_93_easy_twoway_morse_code/" rel="nofollow">reddit.com/r/dailyprogrammer #93 (easy)</a>., which is a Python script that translates between English and Morse code.</p>
<p>Is <code>String_To_Translate</code> a good... | [] | [
{
"body": "<p>Minor points:</p>\n\n<ol>\n<li><code>self.Translated</code> should be <code>self.translated</code>.</li>\n<li>The use of <code>re</code> may be bit of overkill for what you want it for.</li>\n<li>If you use a space in the text, you get told that it's being replaced by a space.</li>\n<li>Create con... | {
"AcceptedAnswerId": "15234",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T05:23:31.903",
"Id": "15228",
"Score": "5",
"Tags": [
"python",
"morse-code"
],
"Title": "Python implementation of a Morse code translator"
} | 15228 |
<p>I was wondering if anyone could give me a little bit of help with optimizing a tree-structure in C++. I'm currently developing a dictionary program for a school project but want to take it a bit further in my spare time.</p>
<p>A little bit of info: The dictionary is a simple class which contains a node. Each node ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T16:57:45.637",
"Id": "24723",
"Score": "0",
"body": "Your analyses of complexity is wrong; :-) The complexity is O(ln(n)) for both search and insert. As n is based on the size of the dictionary not the word length. I don't think I h... | [
{
"body": "<p>Dictionary is a very common word. I am thinking that there may be high possibility of clashing with existing software. I tend to try an make my include guards unique by including the namespace as part of the guard (My base namespace is also my website name so it is unique).</p>\n\n<pre><code>#ifnd... | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T05:26:31.067",
"Id": "15229",
"Score": "3",
"Tags": [
"c++",
"optimization",
"tree",
"hash-map",
"lookup"
],
"Title": "Dictionary tree optimization"
} | 15229 |
<p>I made a function that returns the number displayed for pagination. I want to get something like this (parentheses is the only show where the active site):</p>
<p>if pages < 10</p>
<pre><code>1 2 3 4 5 6 7 8 9 10
</code></pre>
<p>if pages > 10</p>
<pre><code>1 2 3 ... 20 [30] 40 ... 78 79 80
</code></pre>
<p... | [] | [
{
"body": "<ol>\n<li><p>Your code doesn't run as written. It needs a function definition.</p></li>\n<li><p>Your design needs work. Suppose the current page is 30 and the list of pages says \"... 20 [30] 40 ...\" as in your example. How do I get to page 29 or page 31? It doesn't look as if these page numbers wil... | {
"AcceptedAnswerId": "15239",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T10:57:40.653",
"Id": "15235",
"Score": "5",
"Tags": [
"python"
],
"Title": "how to generate numbers for pagination?"
} | 15235 |
<p>I have been working on a class to use Reflection to interrogate other PHP classes and interfaces, what I want to know from anyone with more experience of this is, is there anything else I can add, or is there a better way of doing the things I am trying to do.</p>
<p>In essence I want to be able to use the interrog... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T13:47:29.093",
"Id": "24717",
"Score": "1",
"body": "If you are doing this project for the experience, that's fine. But if you are doing it for those reasons you gave, then a much better, and easier, solution would be to adopt a goo... | [
{
"body": "<p>There are a few things that stood out. I understand this is prototype code, but some of the things I am seeing shouldn't even be present in prototypes. So, I'm just going to treat this as a normal review and point out everything, just in case. As for helping everyone, a good IDE still does this an... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T12:33:03.723",
"Id": "15236",
"Score": "1",
"Tags": [
"php",
"reflection"
],
"Title": "PHP class and interface interrogation using reflection"
} | 15236 |
<p>I began programming recently. I am trying to implement a simple trial-division algorithm for finding all primes up to some number (it is much more "primitive" algorithm than the Sieve of Eratosthenes). Can you please find what's wrong with my code?</p>
<pre><code>#range function:
range = function (a,b,c){
var ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-18T23:26:38.243",
"Id": "25576",
"Score": "1",
"body": "Is this code working? I'm a little confused at the request \"Can you please find what's wrong with my code?\""
}
] | [
{
"body": "<p>Try using this instead.</p>\n\n<pre><code>// `isPrime` adopted from http://www.javascripter.net/faq/numberisprime.htm\nvar isPrime = function (n) {\n if (isNaN(n) || !isFinite(n) || n % 1 || n < 2) {\n return false;\n }\n if (n % 2 === 0){\n return (n === 2);\n }\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T15:07:52.017",
"Id": "15240",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "Simple trial division in JavaScript"
} | 15240 |
<p>I am doing my research about scheduling by using Matlab. I am a new Matlab user and I have a problem with time execution of my following code:</p>
<pre><code>clc
clear all
A=8;
B=12;
C=10;
ProcessTime= [ 11 11 11 11 4 4 4 4 4 4 4 2 ]; %Converting Matrice
RandomMatriceA=zeros(A,B,C);
RandomMatriceB=zeros(A,B,C);
Su... | [] | [
{
"body": "<p>My best guess given the information:\nYou are doing some expensive ismember operations. You can try to get rid of them by tracking Done in a different way.</p>\n\n<p>Perhaps you can use a more efficent way to do it in the same location, or perhaps you need to move it inside the loop and do it in a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T16:50:31.583",
"Id": "15242",
"Score": "5",
"Tags": [
"optimization",
"performance",
"beginner",
"matrix",
"matlab"
],
"Title": "Processing random matrices"
} | 15242 |
<p>Just seeing if there is anyway to shorten these for statements?</p>
<pre><code>...
fillMonthSelect: function() {
var month = new Date().getMonth() + 1;
for (var i = 1; i <= 12; i++) {
$('.card-expiry-month').append($('<option value="'+i+'" '+(month === i ? "selected" : "... | [] | [
{
"body": "<p>String building in code is typically messy, especially without a native <code>String.Format()</code> or <code>sprintf()</code> in Javascript. Building HTML is the worst offender, too.</p>\n\n<p>Other than using a templating engine, like <a href=\"http://icanhazjs.com/\" rel=\"nofollow\">ICanHaz.j... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T19:53:49.927",
"Id": "15249",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Anyway to shorten these for statements?"
} | 15249 |
<p>I'm trying to implement a lexer in Haskell. For easy console input and output, I've used an intermediate data type <strong>Transition Table</strong>.</p>
<pre><code>type TransitionTable = [(Int, Transitions String Int)]
type Transitions a b = [(a, b)]
</code></pre>
<p>I want to take input from the user for all the... | [] | [
{
"body": "<p>In order to repeat an action ad nauseum, you can use <a href=\"http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v%3aforever\" rel=\"nofollow\"><code>forever</code></a>. But you don't really need to use that here, you can just do it the way you've done it so far. ... | {
"AcceptedAnswerId": "15255",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T20:02:53.507",
"Id": "15250",
"Score": "4",
"Tags": [
"haskell",
"functional-programming"
],
"Title": "Writing an infinitely running( while(true) { } ) user input function in haske... | 15250 |
<p>For <a href="http://tour.golang.org/#60" rel="noreferrer">this exercise</a> I have done this:</p>
<pre><code>func between(start, end, value byte) bool{
if value > end {
return false
} else if value < start {
return false
}
return true
}
func (r rot13Reader) Read(p []byte) (n in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-01T12:32:36.703",
"Id": "24753",
"Score": "0",
"body": "Incidentally, this code assumes that the input string contains no character code > 127, otherwise it won’t work. That’s not necessarily a problem though. Just pointing it out."
... | [
{
"body": "<p>I don’t know Go but here are a few general things that I noticed:</p>\n\n<pre><code>func between(start, end, value byte) bool {\n if value > end {\n return false\n } else if value < start {\n return false\n }\n return true\n}\n</code></pre>\n\n<p>As a general patter... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-01T00:09:59.737",
"Id": "15256",
"Score": "13",
"Tags": [
"beginner",
"go",
"caesar-cipher"
],
"Title": "Rot13 Reader in Go"
} | 15256 |
<p>I am animating 1400 objects trying to create a 'twinkling effect'. As the user moves the mouse faster more hexagon shapes pop into full opacity and have varying fade out rates. The version in the fiddle fills the space with enough color but feels jerky and clumpy. If I lessen the fade_time variable amounts it is smo... | [] | [
{
"body": "<p>You are most certainly using a wrong tool for the job. <code><canvas></code> element and <code>requestAnimationFrame()</code> are your friends.</p>\n\n<p>Also, I'd expect opacity animation to tax the graphics stack heavily (unless GPU accelerated, perhaps.) If the background color is going t... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-01T02:41:11.487",
"Id": "15259",
"Score": "4",
"Tags": [
"javascript",
"performance",
"raphael.js",
"animation"
],
"Title": "Animating opacity of 1400 Raphael.js objects hurts an... | 15259 |
<p>I created this very simple stack concept's implementation.
Could you tell me if it is correct and clean? Do you see any bad coding habits?</p>
<pre><code>public class MyStack
{
private static final int MAXELEMENTS = 10;
private int[] elements;
private int numElements;
public MyStack()
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T09:58:58.693",
"Id": "24769",
"Score": "2",
"body": "Will you ever want to put anything other than an `int` into the `Stack`? In that case, you should take a look at generics. In [one of my previous reviews](http://codereview.stacke... | [
{
"body": "<p>Some small notes:</p>\n\n<ol>\n<li><p>According to the <a href=\"http://www.oracle.com/technetwork/java/codeconventions-142311.html#430\" rel=\"nofollow\">Code Conventions for the Java Programming Language</a>,</p>\n\n<blockquote>\n <p>if statements always use braces {}.</p>\n</blockquote>\n\n<p>... | {
"AcceptedAnswerId": "15263",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-01T15:41:08.720",
"Id": "15262",
"Score": "6",
"Tags": [
"java",
"stack"
],
"Title": "Java and stacks: correct implementation?"
} | 15262 |
<p>Can anyone help me prettify this code? The idea is to combine adjacent time spans so</p>
<p>[0:00-1:00, 1:00-2:00, 3:00-4:00] becomes [0:00-2:00, 3:00-4:00]</p>
<pre><code>private static IEnumerable<Span> CombineAdjacentSpans(IEnumerable<Span> spans)
{
var combined = new List<Span>();
var... | [] | [
{
"body": "<p>I would make three changes</p>\n\n<ol>\n<li><p>Drop the <code>ToList()</code> as you are working on <code>IEnumerable<Span></code> anyway and are not making use of list indexes.</p></li>\n<li><p>Take in account overlapping spans by testing for <code>span.Start <= candidate.End</code> inst... | {
"AcceptedAnswerId": "15267",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-01T16:17:12.460",
"Id": "15264",
"Score": "3",
"Tags": [
"c#",
"algorithm"
],
"Title": "Prettify this code - combine items in a list"
} | 15264 |
<p>I needed a <code>boost.any</code> look-a-like, that could handle a <code>std::unique_ptr</code>. I came up with this. Please provide some C++11 criticism.</p>
<pre><code>#ifndef ANY_HPP
# define ANY_HPP
#include <cassert>
#include <stdexcept>
#include <typeinfo>
#include <type_traits>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T12:05:28.117",
"Id": "24773",
"Score": "0",
"body": "You mention `unique_ptr`. Why is `content` not a `unique_ptr`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T22:37:34.700",
"Id": "24786",
... | [
{
"body": "<p>Instead of </p>\n\n<pre><code> std::type_info const& type() const noexcept\n {\n return content ? content->type() : typeid(void);\n }\n</code></pre>\n\n<p>I would recommend:</p>\n\n<pre><code> std::type_info const& type() const noexcept\n {\n return con... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-01T20:38:09.127",
"Id": "15269",
"Score": "17",
"Tags": [
"c++",
"c++11",
"pointers",
"variant-type"
],
"Title": "boost::any replacement with std::unique_ptr support"
} | 15269 |
<p>How can this be minimized?</p>
<pre><code>// remove accent
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input);
input = System.Text.Encoding.UTF8.GetString(bytes);
// make it all lower case
input = input.ToLower();
// remove stop words
input = System.Text.RegularExpressions.Regex.Replace(input, "\\b" + strin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T09:19:26.907",
"Id": "24766",
"Score": "0",
"body": "What is the final intent of this snippet?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T10:14:08.923",
"Id": "24770",
"Score": "0",
"... | [
{
"body": "<blockquote>\n<pre><code>// remove accent\n</code></pre>\n</blockquote>\n\n<p>Actually, no. The following code is just a lossless conversion to and from UTF-8 which doesn’t change the text.</p>\n\n<p>In the following, I’d coalesce the regular expressions – if nothing else, this is way more efficient.... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T08:03:57.620",
"Id": "15274",
"Score": "5",
"Tags": [
"c#",
"regex"
],
"Title": "Combining regex"
} | 15274 |
<p>I would like to know what is null test in java? How to rewrite the below code by avoiding null test. I was asked this question in an online test. I'll be grateful for any help offered.</p>
<pre><code>String mystere() throws IOException {
InputStream input = null;
try {
input = new InputStream(n... | [] | [
{
"body": "<p>The <code>null</code> test is the <code>input != null</code> condition here.</p>\n\n<p>In your code if the constructor of the stream throws an exception the reference remains <code>null</code> so there is no way to call <code>close</code> on it, therefore the constructor call could be before the <... | {
"AcceptedAnswerId": "15276",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T09:13:20.723",
"Id": "15275",
"Score": "5",
"Tags": [
"java"
],
"Title": "what is Null Test in java? and how to rewrite the code to do the same by avoiding null test"
} | 15275 |
<p>I am working on a small serialization function which serializes form input to json.</p>
<p>Here is the fiddle:
<a href="http://jsfiddle.net/jdQfj/2/" rel="nofollow">http://jsfiddle.net/jdQfj/2/</a></p>
<p>I have currently no idea how to split up the array declarations let alone a combination of array and object de... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T04:56:41.617",
"Id": "24795",
"Score": "1",
"body": "I thought it would hard to know how the code works without an example. However when it helps you I can do ;)"
}
] | [
{
"body": "<p>Here's what I came up with:</p>\n\n<pre><code>var addNestedPropToObj = function (obj, name, value) {\n var path = name.split('.'),\n current = obj,\n len = path.length - 1,\n i = 0;\n for (; i < len; i++) {\n current[path[i]] = current[path[i]] || {};\n current = cu... | {
"AcceptedAnswerId": "15293",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T11:08:29.617",
"Id": "15277",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery serializeObject function"
} | 15277 |
<p>I am looking for a general review of my project <a href="https://github.com/JamesMcMahon/mockjson.py" rel="noreferrer">here</a>. I have written some Python, but not enough to feel confident in my ability to produce idiomatic code.</p>
<pre><code>#!/usr/bin/env python
"""mockjson.py: Library for mocking JSON object... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T08:09:24.103",
"Id": "24797",
"Score": "0",
"body": "It would be better if you comment(heavily) on your code so that it could be easily understood."
}
] | [
{
"body": "<h3>1. Introduction</h3>\n\n<p>This review grew to be very long, so I'll say up front that you shouldn't take the length of this to heart: your code is not bad, especially if you are new to Python. There's always a lot of things to say about a piece of code of this length, and idiomatic Python has a ... | {
"AcceptedAnswerId": "15294",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T13:06:09.280",
"Id": "15280",
"Score": "8",
"Tags": [
"python",
"json"
],
"Title": "JSON templates in Python"
} | 15280 |
<p>I'm developing a small website which is responsive, and I'm planning on displaying a number of items ( <a href="http://www.chaoscod3r.com" rel="nofollow">Demo</a> ) on the page. As you can see in the link the items are displayed just fine, but what I'm trying to do is calculate the exact number of items that would f... | [] | [
{
"body": "<p>The best and easiest way to do this would be to place the items in a box container with a pre-computed height and width. Then in order to find the max amount of items that can be placed in the container, you just divide the area of the box container by the area of an item.</p>\n\n<p>I used this me... | {
"AcceptedAnswerId": "15297",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T16:59:49.927",
"Id": "15281",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Refine a math calculation function"
} | 15281 |
<p>I know this is extremely trivial, but would you call the extension method below <code>Remove</code> or <code>RemoveMany</code>? Please provide justification.</p>
<pre><code>public static void Remove<TEntity>(this DbSet<TEntity> set, IEnumerable<TEntity> entities)
where TEntity : class
{
fo... | [] | [
{
"body": "<p>I'd consider calling it <code>RemoveAll</code>.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T19:07:54.043",
"Id": "24779",
"Score": "1",
"body": "Interesting idea, but one possible problem with `RemoveAll()`... | {
"AcceptedAnswerId": "15284",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T18:16:47.833",
"Id": "15282",
"Score": "5",
"Tags": [
"c#"
],
"Title": "Should I call this extension method Remove or RemoveMany?"
} | 15282 |
<p>I'd like a review of this implementation of Async in ASP.NET 2.0 web form page below. Let me know if I am missing something.</p>
<p><strong>AsyncPagesASPNET20.aspx</strong></p>
<pre><code><%@ Page Language="C#" Async="true" AutoEventWireup="true" CodeFile="AsyncPagesASPNET20.aspx.cs" Inherits="AsyncPagesASPNET... | [] | [
{
"body": "<p>Overall a very cleanly written class. It is easy to follow and understand.</p>\n\n<p>A couple of suggestions though.</p>\n\n<p>Make the reader class variable a Property with a private setter. This will eliminate the ability to reassign it from outside of the class. I would also rename it Reader... | {
"AcceptedAnswerId": "15290",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T21:05:18.810",
"Id": "15287",
"Score": "3",
"Tags": [
"c#",
"asp.net",
"asynchronous"
],
"Title": "AsyncPages in ASP.NET 2.0"
} | 15287 |
<p>I'm writing an API and want to be able to pass in the attributes of a model without prefixing them with the name of the model.</p>
<p>I wrote this little extension to <code>ActiveRecord</code> in order to make it happen:</p>
<pre><code>module ActiveRecord
class Base
def self.filter_attributes(hash)
has... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T21:27:06.753",
"Id": "26542",
"Score": "1",
"body": "As Fivell says, it's pretty pointless. You're doing the same thing that the mass assignment protection is doing for you already. But if you want parameter filtering, instead of ma... | [
{
"body": "<p>Honsetly, I don't see any sense in your extension.\nCan you tell me what is the difference between </p>\n\n<pre><code>@idea = Idea.create(Idea.filter_parameters(params))\n</code></pre>\n\n<p>and </p>\n\n<pre><code>@idea = Idea.create(params)\n</code></pre>\n\n<p>mass assignment sanitizing make thi... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-02T23:00:02.837",
"Id": "15289",
"Score": "3",
"Tags": [
"ruby",
"ruby-on-rails",
"active-record"
],
"Title": "Cleaning parameters before passing them to a model"
} | 15289 |
<p>I want an experienced Haskeller to critique my code and offer changes/suggestions (so I can learn the idioms of the language and culture around Haskell).</p>
<p>I've been using a <a href="http://en.wikipedia.org/wiki/Tabula_recta" rel="nofollow">Tabula Recta</a> for my passwords and used a Python script someone wro... | [] | [
{
"body": "<p>Too much IO — most of this code could be pure. Seed the pure random generator with crypto source, you don't need to read from it every time, if you really want crypto source for this. <code>tabulay'</code> and <code>tabulax'</code> look suspiciously like <code>map</code>. <code>symb</code> in <cod... | {
"AcceptedAnswerId": "15305",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T05:29:45.143",
"Id": "15291",
"Score": "8",
"Tags": [
"beginner",
"haskell",
"cryptography"
],
"Title": "Generating a tabula recta"
} | 15291 |
<p>I have a Scala (Play!) application that must get and parse some data in JSON from an external service. I want to be able to gently handle failure in the response format, but it is becoming messy. What I am doing right now is, for instance,</p>
<pre><code>def columnsFor(json: JsValue): Option[Map[String, String]] =
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-26T08:26:54.313",
"Id": "84624",
"Score": "0",
"body": "and become more worse if you need async call to the database with `Future()` =)"
}
] | [
{
"body": "<p>Having monads in your data structures is not messy, they allow you always to flatten their content during nested calculation steps. A simple definition of them can be:</p>\n\n<pre><code>trait Monad[A] {\n def map[B](f: A => B): Monad[B]\n def flatMap[B](f: A => Monad[B]): Monad[B]\n}\n</co... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T09:05:32.753",
"Id": "15295",
"Score": "7",
"Tags": [
"parsing",
"scala",
"json",
"exception-handling"
],
"Title": "Handling parsing failure in Scala without exceptions"
} | 15295 |
<p>I have to create a website in Classic ASP, and I really want to do a clean design so I will try to put everything in Classes and Models to emulate the ViewModel Pattern.</p>
<p>So can you tell me if this approach of creating objects is good because I will use it everywhere</p>
<pre><code>Class User
Public Name... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-04T05:10:19.500",
"Id": "24831",
"Score": "3",
"body": "I don't see any problems with the supplied code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T15:17:51.633",
"Id": "57941",
"Score": "0"... | [
{
"body": "<p>I am not a big VB person, but I would think that if you give your class a Dispose method you should use it rather than setting it to nothing, I know this is kind of the same thing, but if you aren't going to use the Method don't create the method, it's extra stuff. if you are going to use it in t... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T10:55:34.380",
"Id": "15300",
"Score": "5",
"Tags": [
"object-oriented",
"vbscript",
"asp-classic"
],
"Title": "VbScript/ASP Classic good OOP Pattern"
} | 15300 |
<p>I wrote this login method: </p>
<pre><code> [HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel logModel, string returnUrl)
{
if (!ModelState.IsValid)
{
TempData[Keys.ACCOUNT_TEMPDATA_LOGINSTATUS] = LoginStatus.InvalidCredentials;
return ... | [] | [
{
"body": "<p>If you can, I would encrypt the password entered before it is passed back to the service. This will eliminate any chance it could be intercepted. As for the rest of your first question, I think the how you process is up to you. I don't think there is a right or wrong answer.</p>\n\n<p>Now onto ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T17:17:33.513",
"Id": "15303",
"Score": "3",
"Tags": [
"c#",
"asp.net",
"asp.net-mvc-3"
],
"Title": "Asp.net MVC login method"
} | 15303 |
<p>I wrote a program that generates a set of <a href="http://en.wikipedia.org/wiki/Elementary_cellular_automaton" rel="nofollow noreferrer">1D</a> <a href="http://mathworld.wolfram.com/ElementaryCellularAutomaton.html" rel="nofollow noreferrer">cellular automaton</a>. Basically, it generates this (rule 150):</p>
<p><i... | [] | [
{
"body": "<p>Warning: this hasn't been rigorously tested (<em>i.e.</em>, with a known seed)!</p>\n\n<p>There are a couple of things that can be tried without majorly changing things:</p>\n\n<ol>\n<li><p>Grid.center - you already know what it is on initialisation, so create a normal variable for it and remove t... | {
"AcceptedAnswerId": "15311",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T17:25:49.123",
"Id": "15304",
"Score": "6",
"Tags": [
"python",
"performance",
"cellular-automata"
],
"Title": "Generating a 1D cellular automata in Python"
} | 15304 |
<p>I just created this during a live screencast. The people who were on there were <em>very</em> critical of almost every line of code. They say I am a horrible coder and know nothing. Looking at this tax calculator, would you say I'm an OK coder?</p>
<p><a href="http://www.phpu.cc/repo/phpu-training/5.tax-calc/" rel... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T23:53:41.387",
"Id": "24822",
"Score": "2",
"body": "horrible coder tag sounds pretty harsh. I'm not a php guru but from a read-ability point of view the code looks clean and easy to follow."
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<p>Are you a horrible programmer...no probably not. </p>\n\n<p>Is there room for improvement? There usually is.</p>\n\n<p>here's my two cents: I see one factory class, but then you have a whole-lotta creation work going on throughout the rest of your code <code>new fMoney</code>, <code>new TaxBrac... | {
"AcceptedAnswerId": "15313",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T20:06:41.493",
"Id": "15307",
"Score": "13",
"Tags": [
"php",
"php5",
"finance"
],
"Title": "Heavily-criticized tax calculator"
} | 15307 |
<p>So I'm writing an abstraction layer that wraps a telephony RESTful service for sending text messages and making phone calls. I should build this in such a way that the low-level provider, in this case Twilio, can be easily swapped without having to re-code the higher level interactions.</p>
<p>I'm using a package t... | [] | [
{
"body": "<p>In circumstances like you have here; the almost lowest level layer wrapping a dependency, it can be hard to see another layer lower to allow abstraction, but remember this: The lowest level wrapper of a dependency is a literal straight pass-through.</p>\n\n<p>This means, if you take the twilio api... | {
"AcceptedAnswerId": "15309",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T19:09:33.397",
"Id": "15308",
"Score": "5",
"Tags": [
"php",
"design-patterns",
"unit-testing",
"mobile"
],
"Title": "Wrapping a telephony RESTful service for sending text ... | 15308 |
<p>I needed a class where I could store an instance of any type. The goal was an interface as follows:</p>
<pre><code>class TypeMap {
template<typename T>
T& get();
};
</code></pre>
<p>Such that:</p>
<ul>
<li>Iff <code>&m1 == &m2</code> then <code>&m1.get<T>() == &m2.get<T... | [] | [
{
"body": "<p>I don't see why you use <code>void*</code> as a key, when that pointer is always a <code>TypeMap*</code>.</p>\n\n<p>You could use a <code>std::map<TypeMap*, T*></code> as <code>TypeMapDetail<T></code>'s member. (Yes, <code>std::less<X*></code> is a safe total ordering, even thou... | {
"AcceptedAnswerId": "42482",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-04T11:52:41.080",
"Id": "15316",
"Score": "7",
"Tags": [
"c++",
"template-meta-programming"
],
"Title": "Type to instance map"
} | 15316 |
<p><strong>This is the existing code. Clearly way too much is going on in this index method and furthermore it's untested (and hard to test in its current form).</strong></p>
<pre><code> def index
# @s = ""
# @now=DateTime.now
@from = params[:from]? ('01/01/'+params[:from]).to_date : '01/01/1991'.to_date
... | [] | [
{
"body": "<p>Create a model to hold all the logic and call that with parameters and have tests for the model methods:</p>\n\n<blockquote>\n <p>Unit Tests</p>\n</blockquote>\n\n<pre><code>require 'spec_helper'\n\ndescribe \"Prepare Search methods\" do\n\n describe \"PrepareSearch#start_date\" do\n\n subjec... | {
"AcceptedAnswerId": "15319",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-04T13:43:27.967",
"Id": "15318",
"Score": "0",
"Tags": [
"ruby",
"controller"
],
"Title": "How can I refactor this oversized Ruby method into smaller bits and have unit tests for them... | 15318 |
<p>This is used to change a Cyrillic word with a stress marker into the same Cyrillic word but with the stress marker separately represented as a number. As I want to return two values I pass two parameters by reference. I assume there is at most only one stress marker per word.</p>
<p>What could I improve here?</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T08:34:16.707",
"Id": "24919",
"Score": "0",
"body": "It appears that I have found another solution to the problem. I stumbled across php's multibyte string functions and I am thus able to avoid using this implementation myself. Grea... | [
{
"body": "<p>Normally I would look at the PHP manual and make sure you aren't recreating a function that already exists, but I have no experience with non ASCII characters so i don't feel comfortable with the terminology to look this up. I would suggest that you make sure of this though. This sounds like somet... | {
"AcceptedAnswerId": "15328",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-04T15:25:56.890",
"Id": "15321",
"Score": "3",
"Tags": [
"php"
],
"Title": "Modifying stress markers in Cyrillic words"
} | 15321 |
<pre><code>(!empty($student->former_name) ? print $student->former_name : '');
</code></pre>
<p>I only want to print out the former name if it is not empty, nothing else.</p>
<p>I imagine I do not need the else part of it, but I do not know how to do it like that without the else.</p>
<p>I want to shorthand th... | [] | [
{
"body": "<p>Why not just</p>\n\n<pre><code>echo $student->former_name\n</code></pre>\n\n<p>If its empty, it will be an empty string and thus the same thing. There is no way to remove the else from a ternary statement. The only other way to write that would be like so:</p>\n\n<pre><code>echo empty( $student... | {
"AcceptedAnswerId": "15325",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-04T15:37:03.790",
"Id": "15324",
"Score": "3",
"Tags": [
"php"
],
"Title": "Print out a student's former name if it is not empty"
} | 15324 |
<p>I have just finished another page of my project and everything is working just great with the following code example. </p>
<p>My first concern is whether you could recommend something to make my code look more beautiful or probably more secure? As I have no user input, I suppose this code can not be <a href="https:... | [] | [
{
"body": "<p><strong>Beautifying Your Code</strong></p>\n\n<p>You could start by dropping some of these parenthesis. This is purely a stylistic choice, but I view it like this: The more parenthesis there are, the harder the code is to read, especially if nesting parenthesis. If the parenthesis are necessary an... | {
"AcceptedAnswerId": "15338",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-04T19:16:43.157",
"Id": "15334",
"Score": "2",
"Tags": [
"php",
"mysql"
],
"Title": "Procedural PHP code for showing videos on the page, sorting them in different ways. Is this good? ... | 15334 |
<p>Here's my solution to Project Euler <a href="http://projecteuler.net/problem=40">problem 40</a>.</p>
<pre><code>import operator
import math
def levels(n):
return 9 * n * 10 ** (n - 1)
def face_value(i):
def level_filler(i):
n = 1
yield 1
while i > levels(n):
yield i... | [] | [
{
"body": "<h3>1. Bug</h3>\n\n<p>Your program contains a bug. The second digit of 123456... is 2, but:</p>\n\n<pre><code>>>> d(2)\n3\n</code></pre>\n\n<p>However, solving Project Euler problem 40 only relies on you having the correct result for <code>d(10**i)</code>, and this you got right.</p>\n\n<h3>... | {
"AcceptedAnswerId": "15347",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-04T21:37:48.357",
"Id": "15336",
"Score": "11",
"Tags": [
"python",
"project-euler"
],
"Title": "Help me make my Python code clearer"
} | 15336 |
<p>Very simple requirements here:</p>
<ol>
<li>connect to web service</li>
<li>check if account number exists</li>
<li>if it exists update it</li>
<li>if it does not exist create the account</li>
</ol>
<p>I have accomplished this with the code below I am wondering if this is efficient and secondly if there is a bette... | [] | [
{
"body": "<p>I would move the operations on the web service out to their own class:</p>\n\n<pre><code>public class AccountRepository\n{\n private readonly void _webService;\n\n public AccountRepository()\n {\n //authentication header\n\n var header = new AuthenticationHeader\n ... | {
"AcceptedAnswerId": "15341",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-04T23:51:34.737",
"Id": "15340",
"Score": "2",
"Tags": [
"c#",
"xml",
"web-services"
],
"Title": "Using XML from web service with switch"
} | 15340 |
<p>first here is the code:</p>
<pre><code>Part 1
$('#monhpf').keyup(function()
{
/* General variable(s) */
var monhpf = $('#monhpf').val();
if(monhpf=="")
{
$('#monhpf').css('border-color',red);
$('.mondayErrors').text(emptyField).show();
}else ... | [] | [
{
"body": "<pre><code>$('#monhpf,#monmpf').keyup(function()\n{\n var mon = $(this);\n var monValue = mon.val();\n // continue using mon\n});\n</code></pre>\n\n<p>Warning: Not Tested!</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T18:19:36.88... | {
"AcceptedAnswerId": "15354",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T08:01:31.640",
"Id": "15342",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"ajax"
],
"Title": "Possible redundant code improvement"
} | 15342 |
<p>The application needs to keep a secret which is known to logged in windows user. User enters secret in windows form's text box which is read by application. This is in form of <code>System.String</code>. Now I have to persist this secret into a XML file. And later able to decipher it back and use it.</p>
<p><strong... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T17:21:18.720",
"Id": "26796",
"Score": "0",
"body": "Just a small point, in cryptography unencrypted data is referred to as `clear text` and encrypted data is referred to as `cipher text`."
}
] | [
{
"body": "<ol>\n<li>Your code is correct. I usually use Encoding.UTF8 because it is more compact for typical character sets.</li>\n<li>SecureString is kind of a useless class. It is meant to never keep a secret unencrypted even in memory. This would only help if an attacker could read your processes memory. If... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T13:19:18.843",
"Id": "15346",
"Score": "11",
"Tags": [
"c#",
".net",
"security",
"cryptography"
],
"Title": "Using System.Security.Cryptography.ProtectedData, do you see any i... | 15346 |
<p>I'm working on a config class for PHP, where I can easily bring in config options. Any improvements/suggestions are appreciated.</p>
<p><strong>Example usage:</strong></p>
<pre><code>echo Config::get('database.host');
// Returns: localhost
</code></pre>
<p><strong>Example config file:</strong></p>
<pre><code><... | [] | [
{
"body": "<p>You can continue to use a class if you want, but I think making a config class is overkill. Just a plain config file with constants should be good enough. It has less overhead and less abstraction. As for loading a specific config file, you can use a helper function to simulate what you have here,... | {
"AcceptedAnswerId": "15351",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T14:46:36.560",
"Id": "15348",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"classes",
"php5"
],
"Title": "PHP Config Class"
} | 15348 |
<p>After a week of searching and testing each approach via <code>Stopwatch</code>,
I came to this method using the fastest way possible to capture screen into a bitmap and then to a <code>byte[]</code>.</p>
<ol>
<li><p>Is it possible to make it any faster using parallel features or any idea I have not taken into acc... | [] | [
{
"body": "<p>There are a few things I see at a glance:</p>\n\n<ul>\n<li>If you have to enclose a section of code within a method in region\ntags, you should be pulling that code out into a helper method. You\ncould probably split this method into several. Don't worry about\noverhead of extra method calls -- ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T14:48:09.430",
"Id": "15349",
"Score": "4",
"Tags": [
"c#",
"performance",
"image"
],
"Title": "Comparing screen captures using unsafe / API calls"
} | 15349 |
<p>I am setting a few vars in JavaScript. I typically like to make my code really readable so that it's easy to go back and edit. I have a few questions about the code below:</p>
<p>1) Is this is a good way to break up the setting of the vars? The comment seems redundant, but it seems to really help break up the cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T16:33:43.207",
"Id": "24877",
"Score": "1",
"body": "don't use `new Array()` go for the array literal `var SBTextArray = [\"Company Name A - Z\",\"Company Name Z - A\", ....];` [read more here](http://stackoverflow.com/questions/109... | [
{
"body": "<p>Your code is great so far.\nThe only tip I can think of is to wrap grouped variables inside a namespace / singleton.\nThis would make it easier to debug and perform operations of group of related elements.</p>\n\n<pre><code> // GENERAL VARS\nvar UpRate = 250,\n DownRate = UpRate,\n OpenHe... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T16:26:51.270",
"Id": "15352",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Setting vars in jQuery / JavaScript"
} | 15352 |
<p>I'm new to iOS development and I'm having trouble figuring out how to efficiently load my app's data at launch time. My app consists of a UITableView that is populated with a list of songs. Each cell displays data about the song: current user rating(if rated) and avg. user rating (avg. rating of all users). I'm usin... | [] | [
{
"body": "<p>Consider following scheme -</p>\n\n<p>Each song has a key <code>numberOfRatings</code> and a key <code>averageRating</code>.\nTheir initial value is 0.</p>\n\n<p>When user rates a song with <code>newRating</code>, you change the value of <code>averageRating</code> according to this formula</p>\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T16:34:10.717",
"Id": "15353",
"Score": "3",
"Tags": [
"optimization",
"objective-c",
"ios"
],
"Title": "Data model code review for iOS app"
} | 15353 |
<p>My logger posted below makes use of condition variables in order to notify the "flusher" thread that new items are available. The notification occurs every time a message is logged.</p>
<p>My questions are:</p>
<ul>
<li>If the notification immediately follows the log action then does that mean that the queue will ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T17:16:46.003",
"Id": "24883",
"Score": "0",
"body": "Does `mCondition.notify_one();` flush, or merely send a message to another thread?"
}
] | [
{
"body": "<p>The main thing I'm noticing is that you have a \"Throw a lock at the problem\" approach (and eww <code>mMember</code>).</p>\n\n<p>You really need a true concurrent queue- these can operate atomically (for any <code>T</code>). If you download, say, TBB, it ships with a <code>concurrent_queue</code>... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T17:09:30.280",
"Id": "15356",
"Score": "1",
"Tags": [
"c++",
"multithreading"
],
"Title": "Performance and correctness of my threaded logger?"
} | 15356 |
<p>I am using jQuery 1.7.2</p>
<p>I have two ways of writing the same code. One way seems more verbose and the other seems more flexible. Is this the only difference? Is there any performance difference? Is there a better way of writing these?</p>
<p>Code sample #1 uses two named functions so they are reusable. It's ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T17:54:41.497",
"Id": "24886",
"Score": "2",
"body": "If you have to re-use them, use named functions. If you won't be re-using them, there's no point in using named functions (other than for debugging purposes)."
},
{
"Conte... | [
{
"body": "<p>Generally speaking, anonymous (unnamed) functions are completely acceptable within the land of Javascript. They are used frequently and without prejudice, so don't be afraid of them.</p>\n\n<p>That said, I'm not a fan of the second code sample. Without an understanding of the jQuery API, I don't r... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T17:26:37.863",
"Id": "15358",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Should I use unnamed or named functions?"
} | 15358 |
<p><strong>The goal of this question:</strong><br/>
Your goal here is to find a security hole in my code which allows a user to create input that contains a script doing anything they want, without that script being stopped by my code.</p>
<p>Please bear in mind that that is the ONLY goal of this post. I am not so muc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T18:26:07.723",
"Id": "24891",
"Score": "2",
"body": "I'm pretty sure this is the wrong site for this. You might try your luck at Code Golf or SO or something. This site is only for reviews. If you want the code reviewed, that's fine... | [
{
"body": "<p>The filter doesn't block inline javascript.</p>\n\n<p>Example 1:</p>\n\n<p><code><body onscroll=alert(1)><br><br><br><br><br><br>...<br><br><br><br><input autofocus></code></p>\n\n<p>Example 2:</p>\n\n<p><code><form id=\"te... | {
"AcceptedAnswerId": "15371",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T18:16:36.923",
"Id": "15361",
"Score": "4",
"Tags": [
"javascript",
"php",
"html",
"parsing",
"regex"
],
"Title": "Is my PHP script/embed remover robust?"
} | 15361 |
<p>Did I write this code to correctly be tail call optimized? Am I forcing computations more than I need with <code>!</code>? Did I generally write this asynchronously correctly to allow sends and receives to occur in their own time? Is this using multiple threads needlessly? Other general critiques?</p>
<pre><code>op... | [] | [
{
"body": "<p>It seems you are using asyncGetInput and asyncGetReponse to introduce concurrency, although this is a noble goal it is kind of useless because you are only using those from other workflows which are already running in the thread pool anyway. In that case it would be ok to make a synchronous call f... | {
"AcceptedAnswerId": "18954",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T21:10:22.343",
"Id": "15364",
"Score": "2",
"Tags": [
".net",
"functional-programming",
"asynchronous",
"f#",
"recursion"
],
"Title": "simple stupid F# async telnet cli... | 15364 |
<p>I am working on asp.net/MVC and I need to read a value from my web.config file. Splitting the list into multiple keys is not an option.</p>
<pre><code><add key="DepartAssign" value="Depart1:PersonAssignTo1; Depart2:PersonAssignTo2"/>
</code></pre>
<p>I handled the problem by doing the following (which I am s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T21:57:47.537",
"Id": "24908",
"Score": "1",
"body": "Wouldn't it be better if you used `Dictionary<string, string>` instead of two `List`s?"
}
] | [
{
"body": "<p>You could create your own custom section in your config file.</p>\n\n<p>First define what each record looks like:</p>\n\n<pre><code>public class Department : ConfigurationSection\n{\n [ConfigurationProperty(\"name\", IsRequired = true)]\n public string Name\n {\n get { return (stri... | {
"AcceptedAnswerId": "15368",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T21:13:16.030",
"Id": "15365",
"Score": "3",
"Tags": [
"c#",
"asp.net",
"asp.net-mvc-3"
],
"Title": "Creating a list of pairs after splitting the string containing all of the se... | 15365 |
<p>I would like a review on this code, and how I could make it better.</p>
<pre><code>#include <boost/bind/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/function.hpp>
#include <boost/thread/thread.hpp>
#include <boost/signals2/mutex.hpp>
#include <stdi... | [] | [
{
"body": "<p>If you are going to disable the copy and assignment operators then don't define the body:</p>\n<pre><code>Timer(const Timer &other); // don't do this {} \nTimer &operator=(const Timer &other); // {}\n</code></pre>\n<p>This way if you accidentally use them (inside your clas... | {
"AcceptedAnswerId": "15388",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T22:39:52.780",
"Id": "15369",
"Score": "2",
"Tags": [
"c++",
"singleton",
"timer",
"boost"
],
"Title": "Singleton Boost-based timer"
} | 15369 |
<p>I have a simple cache service that i am using inside my WPF prism application, i am concerned about the thread safety of it - we will be accessing this via multiple threads and using the current code it has started deadlocking, it works fine without the locks but obviously this is not acceptable.</p>
<p>How can i g... | [] | [
{
"body": "<p>I don't see any reason why your code should deadlock. Deadlocks require at least two locks (or similar constructs) used at the same time, but there is only one lock in your code. The only potential for deadlocok I can see is if some <code>loadFunc</code> also used locking.</p>\n\n<p>And your code ... | {
"AcceptedAnswerId": "15376",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T08:27:01.100",
"Id": "15374",
"Score": "3",
"Tags": [
"c#",
".net",
"multithreading",
"thread-safety"
],
"Title": ".Net caching service - thread safety"
} | 15374 |
<p>I have this piece of code I developed but it doesn't look efficient to me, can anyone improve it please.</p>
<pre><code> private void AddToDataBase(SPItemEventProperties properties)
{
DataAccess DA = new DataAccess(ConnectionString());
DetailsRow result = DA.GetDetails(properties.WebUrl);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T09:08:53.393",
"Id": "24924",
"Score": "0",
"body": "Hello TimeToThine. How do you suppose anyone can answer that **without knowing what your conditions are?** Your question is at risk of being closed as \"not a real question\" if y... | [
{
"body": "\n\n<p>Since I don't have the SharePoint libraries I wasn't able to test my solution, but it should work.</p>\n\n<ol>\n<li>Use proper indentation and formatting.</li>\n<li><code>== true</code> is redundant and can be removed.</li>\n<li><p>Instead of the following:</p>\n\n<pre class=\"lang-cs prettypr... | {
"AcceptedAnswerId": "15377",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T09:05:23.867",
"Id": "15375",
"Score": "0",
"Tags": [
"c#",
"sharepoint"
],
"Title": "too many conditions"
} | 15375 |
<p>I'm rather new to Clojure and so I decided to program a Connect Four for fun and learning.</p>
<p>The code below is a Clojure implementation of this <a href="https://stackoverflow.com/questions/4261332/optimization-chance-for-following-bit-operations">bitboard algorithm</a>.</p>
<p>The whole code can be found here... | [] | [
{
"body": "<p>The <code>bit-check-board</code> can be indeed improved. This is what I got by just joining together common parts, even though I guess it could be further improved:</p>\n\n<pre><code>(defn check [c x]\n (bit-and c (bit-shift-right c x)))\n\n(defn bit-check-board\n \"Checks whether given bitboard... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T09:39:52.457",
"Id": "15378",
"Score": "4",
"Tags": [
"lisp",
"functional-programming",
"clojure",
"bit-twiddling"
],
"Title": "Connect Four: Bitboard checking algorithm"
} | 15378 |
<p>I don't write too many bash scripts and I can usually struggle my way through getting the odd thing I need working, but my scripts always seem to feel a bit brittle. Below is a script I wrote for adding trusted timestamps to commits in a Git repository. I would appreciate any feedback on ways I could improve it.</... | [] | [
{
"body": "<p>You can use a <a href=\"http://en.wikipedia.org/wiki/Here_document\" rel=\"nofollow\"><em>here document</em></a> to avoid all those calls to <code>echo</code>:</p>\n\n<pre><code>cat <<END\nUsage: git-timestamp [options] command [revision]\n\n options\n -h - Show this usage info. All other ... | {
"AcceptedAnswerId": "15386",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T12:17:17.763",
"Id": "15380",
"Score": "6",
"Tags": [
"beginner",
"bash",
"git",
"openssl"
],
"Title": "Adding trusted timestamps to Git commits"
} | 15380 |
<p>I want to refactor my code but I can't find and much simplier one. Can you please suggest on how to refactor the code below without using a loop? maybe using only array functions? TIA</p>
<pre><code><?php
$week_no = array(2,3,4);
$days = array('TU', 'WE', 'TH');
foreach ($week_no as $n) {
foreach ($days as $... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T10:30:09.507",
"Id": "24940",
"Score": "4",
"body": "that's the simple and the fastest way to do it !!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T10:31:50.597",
"Id": "24941",
"Score": "0... | [
{
"body": "<p>How about this for some madness:</p>\n\n<pre><code>function weekday($a, $b){global $days; return \"$a $b\".join(\" $b\", $days);};\n$out = explode(' ', trim(array_reduce($week_no, 'weekday')));\n</code></pre>\n\n<p><em>(Urm, yes well maybe not...)</em></p>\n\n<p>Sometimes to attain elegance you ha... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T10:28:53.563",
"Id": "15382",
"Score": "2",
"Tags": [
"php"
],
"Title": "Is there simplier than this one in PHP?"
} | 15382 |
<p>How can I make this code snippet be improved to become more professional?</p>
<pre><code>(function($){
$.fn.showMenu = function(options){
return this.each(function(){
$this = $(this);
var high = $this.outerHeight(),
scrollHeight = $this.get(0).scrollHeight;
$this.bind('... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-17T16:10:50.380",
"Id": "25516",
"Score": "0",
"body": "Have you considered using CSS animations instead?"
}
] | [
{
"body": "<p>You could also use .hover, if you are going for shorter code.\n<a href=\"http://api.jquery.com/hover/\" rel=\"nofollow\">Jquery Hover</a></p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T18:11:40.740... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T15:16:44.517",
"Id": "15385",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Function to show/hide a menu on hover"
} | 15385 |
<p>I'm working on a feature for the <a href="http://github.com/jessemiller/HamlPy" rel="nofollow">HamlPy (Haml for Django)</a> project:</p>
<h2>About Haml</h2>
<p>For those who don't know, Haml is an indentation-based markup language which compiles to HTML:</p>
<pre><code>%ul#atheletes
- for athelete in athelete... | [] | [
{
"body": "<h3>1. Answers to your questions</h3>\n<ol>\n<li><p>If the goal of the project is to be able to include Haml in attribute values, then you've got no choice but to switch to your own parser. I haven't looked at the set of test cases, but it does seem plausible that you are going to introduce incompati... | {
"AcceptedAnswerId": "15450",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T22:45:31.233",
"Id": "15395",
"Score": "5",
"Tags": [
"python",
"parsing",
"django",
"haml"
],
"Title": "Python parser for attributes in a HAML template"
} | 15395 |
<p>I've been learning Python for about a year and now I'm trying to improve my JavaScript. I wrote this simple d3 visualization that shows your Facebook friends as a force-directed graph. Here's a <a href="http://ecmendenhall.github.com/d3friendgraph/" rel="nofollow">live version</a> and here's <a href="https://github.... | [] | [
{
"body": "<p>I couldn't test out your application since I don't have a facebook account but here are some tips:</p>\n\n<h1>1) Use dot notation instead of bracket notation to access known property names.</h1>\n\n<p>Old Code: </p>\n\n<pre><code>friends[sourceIndex]['value'];\n</code></pre>\n\n<p>New Code:</p>\n\... | {
"AcceptedAnswerId": "15820",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T22:52:47.377",
"Id": "15396",
"Score": "8",
"Tags": [
"javascript",
"performance",
"graph",
"d3.js",
"facebook"
],
"Title": "D3 visualization of a Facebook friend graph... | 15396 |
<p>I have to read in a file full of <code>int</code>s, print them in reverse order, and then calculate the median and the mode of the set.</p>
<p>At first I struggled with figure out a way to calculate the mode. It seemed so simple but I just couldn't translate the steps into code. I did come up with a solution and it... | [] | [
{
"body": "<p>Try not to use the built-in array unless you have a constant sized data.</p>\n\n<pre><code>typedef int IntArr[MAX_ELEMENTS];\n</code></pre>\n\n<p>What happens if you have more than MAX_ELEMENTS.<br>\nIn C++ you would generally use a vector to hold this information.</p>\n\n<pre><code> typedef std::... | {
"AcceptedAnswerId": "15411",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T23:18:38.187",
"Id": "15397",
"Score": "4",
"Tags": [
"c++",
"array"
],
"Title": "Calculating the mode of a set of ints"
} | 15397 |
<p>I am posting the <strong>a</strong> section of the model of my application.</p>
<p>Any/all feedback would be very helpful as I am trying to build my PHP skills, but I will ask a couple specific questions that might help others as well. </p>
<ol>
<li><p>Is my escaping, as is, effective enough?</p></li>
<li><p>I tr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-12-05T13:49:43.540",
"Id": "403958",
"Score": "0",
"body": "Curious why you limit error output instead of properly catching and handling exceptions - `@$this->data['action'] = $a['action'];`. If this buggers up, you'll never know."
}
] | [
{
"body": "<p>This is better, still a bit long, but unavoidably so. I might reiterate a few things from my last answer, but it is only because I'm too lazy to read it again to make sure I'm not. Sounds kind of ironic, but I do find it easier to just write it, rather than read it :)</p>\n\n<p><strong>General Ove... | {
"AcceptedAnswerId": "15421",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T02:06:11.793",
"Id": "15400",
"Score": "4",
"Tags": [
"php",
"database",
"mvc"
],
"Title": "How can I improve my PHP model for my HTML5/JS mobile app?"
} | 15400 |
<p>I am developing a WinForm application that extracts data from our database and draws a tree like structure on the form. For the users to get a better idea of how the data is structured.</p>
<p>The database is designed in such a way, that data looks like tree structures. Based on that I can fetch the data and draw t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T14:02:07.663",
"Id": "25003",
"Score": "0",
"body": "have I overlooked something, or is it true that each node's `Location` has to be manually assigned?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07... | [
{
"body": "<p>First things first, lose the #region tags. They do nothing but clutter up your code.</p>\n\n<p>I would make all of the class variables that are assigned at the top of OINode constants</p>\n\n<pre><code>public const int NodeDiamenter = 55;\nprivate const string FontString = \"Tahoma\";\nprivate re... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T07:57:10.820",
"Id": "15406",
"Score": "3",
"Tags": [
"c#",
"optimization"
],
"Title": "Drawing Tree Structures"
} | 15406 |
<p>I wrote this little script in PHP a bit ago. It takes a .csv file and outputs a .txt file with certain data arranged in a "psuedo-array" looking format. I recently started messing around with Ruby so I decided to redo it. It wound up essentially as an exact translation, though.</p>
<p>Is there a simpler / more Ruby... | [] | [
{
"body": "<pre><code>img = \"#{row[0]}\".downcase\npart = \"#{row[2]}\"\nloc = \"#{row[5]}\"\ncountry = \"#{row[4]}\"\nfocus = \"#{row[3]}\"\ndesc = \"#{row[8]}\"\nlink = \"#{row[9]}\"\n</code></pre>\n\n<p>The only difference between writing <code>\"#{ expression }\"</code> (without anything else in the strin... | {
"AcceptedAnswerId": "15415",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T15:21:04.360",
"Id": "15413",
"Score": "8",
"Tags": [
"ruby",
"csv"
],
"Title": "Outputting a .txt file from a .csv file"
} | 15413 |
<p>I'd like your opinion on something. I have the following class:</p>
<pre><code>public class ApplicationClock
{
void tick(object _)
{
lock (tickLock)
{
try
{
MessageBroker.Publisher.Publish(new Tick());
}
catch (Exception e)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T19:27:14.117",
"Id": "25013",
"Score": "0",
"body": "If it's launched from the bootstrapper and there is only ever one instance launched at app start is there any need to provide locking?"
},
{
"ContentLicense": "CC BY-SA 3.... | [
{
"body": "<p>Looks mostly ok, just some issues around coupling:</p>\n\n<p>Consider one of the following</p>\n\n<ol>\n<li>Pass <code>MessageBroker.Publisher</code> via the <code>ApplicationClock</code> constructor as an external dependency (preferably an interface). This will make the current implicit dependenc... | {
"AcceptedAnswerId": "55156",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T15:35:44.163",
"Id": "15414",
"Score": "4",
"Tags": [
"c#",
"multithreading",
"asp.net-mvc-4"
],
"Title": "Using a recurring System.Threading.Timer in an Mvc Application"
} | 15414 |
<p>I haven't done Java coding in years, but I thought I would give it a shot for a job interview. I have a few questions:</p>
<ol>
<li><p>Why is this error handling considered poor? How am I supposed to be doing it?</p></li>
<li><p>What error catching should I be doing in a <code>finally</code> clause?</p></li>
<li><p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T20:29:43.017",
"Id": "25018",
"Score": "0",
"body": "Was there any indication as to why `getContents` should return `Object`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T21:53:08.863",
"Id": "... | [
{
"body": "<p>Let me start off by saying how ridiculous the restrictions are:</p>\n\n<pre>\nYou are free to use any library/technique, except for java.net.Url, java.net.URI \nor java.net.UrlConnection.\nSolutions using these classes will not be accepted.\n</pre>\n\n<p>The fact is that the apache libraries which... | {
"AcceptedAnswerId": "15426",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T20:01:25.350",
"Id": "15420",
"Score": "11",
"Tags": [
"java",
"interview-questions",
"exception-handling",
"http"
],
"Title": "Exception handling, et al - How do I make th... | 15420 |
<p>Currenty coding a PHP script that will have a CRON to auto run it.
The point is that it checks the user in Mysql and if it has expired, it will delete it from the admin table and set status to expired.
I have used time() and then when it gets INSERT When his trial starts, it starts for example "1347054850" in the "S... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-06-11T07:43:54.517",
"Id": "429670",
"Score": "0",
"body": "what is steam in $steam =$q['steam'];?"
}
] | [
{
"body": "<ol>\n<li><p>Proper and consistent indentation would improve the readability a lot. Here is mine:</p>\n\n<pre><code><?php\n $Sql = new mysqli(\"localhost\", \"root\", \"*******\", \"serveradmin\");\n if ($Sql->connect_error) { \n die(\"Sorry, Could not connect (\" . $Sql->connec... | {
"AcceptedAnswerId": "15448",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T21:56:28.663",
"Id": "15425",
"Score": "3",
"Tags": [
"php",
"mysql"
],
"Title": "PHP Check user and delete if expired"
} | 15425 |
<p>My original code is:</p>
<pre><code>let (upPosition, downPosition, leftPosition, rightPosition) =
match myMove.MyDirection with
| Direction.Up -> (GoUp y, y, GoLeft x, GoRight x)
| Direction.Down-> (y, GoDown y, GoLeft x, GoRight x)
| Direction.Left -> (GoUp y, GoDown y, GoLeft x, x)
|... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T23:23:20.107",
"Id": "25021",
"Score": "0",
"body": "I have to say, I'm a bit puzzled by this code. Why are there 4 values to represent a position? And why does the original code call both `GoLeft` and `GoRight` when the input is `D... | [
{
"body": "<p>It's tough to review only <em>part</em> of the code, because there are often small improvements which could be made but they depend on knowing the structure of the entire program -- for example, why are you using a tuple to pass around the positions (<code>(upPosition, downPosition, leftPosition, ... | {
"AcceptedAnswerId": "15446",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-07T22:06:22.017",
"Id": "15428",
"Score": "5",
"Tags": [
"f#",
"coordinate-system"
],
"Title": "Determining directions for a 2D boad"
} | 15428 |
<p>I realised that <a href="https://codereview.stackexchange.com/q/15316/6313">what I was doing</a> wasn't particularly smart, so I switched to a different approach. This costs more dynamic allocations but has a much simpler implementation:</p>
<pre><code>#pragma once
#include <boost/utility.hpp>
#include <... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-10-19T17:56:27.210",
"Id": "450242",
"Score": "4",
"body": "Can you please provide example code to use this in a small program?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-08T07:55:40.883",
"Id": "15431",
"Score": "9",
"Tags": [
"c++",
"c++11",
"boost",
"hash-map"
],
"Title": "Take two on type to instance map"
} | 15431 |
<p>I've written a project for handling various Facebook things and I ran into the issue where one project named the users profile <code>Profile</code> while normally they would be named <code>UserProfile</code>. When I was checking if the <code>FacebookUser</code> model was related to a <code>User</code>, I could just... | [] | [
{
"body": "<p>You can use django.contrib.auth.get_user_model() instead of importing User directly. Note that I also explicitly included the ObjectDoesNotExist exception.</p>\n\n<p><a href=\"https://docs.djangoproject.com/en/2.2/topics/auth/customizing/\" rel=\"nofollow noreferrer\">https://docs.djangoproject.co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-08T10:58:57.410",
"Id": "15432",
"Score": "7",
"Tags": [
"python",
"django"
],
"Title": "Finding the profile name for a join in my Facebook auth backend"
} | 15432 |
<p>Please review for any unnecessary casting, memory leaks, wrong use of pthread call, or validation problems in the given code.</p>
<pre><code>/**********************************************************************
* FILENAME :thread_1.c
* DESCRIPTION:Contains Code for a program that demonstrates the
* ... | [] | [
{
"body": "<p>Align your code better.<br>\nIt probably has tabs (replace them with space before pasting) in it that make reading it hard on a website.</p>\n\n<p>Please declare one variable per line:</p>\n\n<pre><code>int t,ret,numthreads = 0,thread_success = 0,*iptr;\n</code></pre>\n\n<p>You are not saving anyt... | {
"AcceptedAnswerId": "15436",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-08T12:10:44.683",
"Id": "15434",
"Score": "4",
"Tags": [
"c",
"casting",
"pthreads"
],
"Title": "Demonstration of pthread calls"
} | 15434 |
<p>I'd like to hear some thoughts on my simple anagram finder, written in Scala. I mainly wrote this as a first go at writing some serious Scala, and I wanted to try out the Scalaz library.</p>
<p>I'm coming from a Java background, with minimal experience with functional languages. Things I'd ideally like feedback on:<... | [] | [
{
"body": "<p>Some suggestions to improve your code:</p>\n\n<p><code>xs.sortWith((e1, e2) => (e1 < e2))</code> is identical to <code>xs.sorted</code></p>\n\n<p>If you are not interested in <code>Stem.word</code> you can place it into companions' apply-method:</p>\n\n<pre><code>object Stem {\n def apply(w... | {
"AcceptedAnswerId": "15445",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-08T17:10:39.503",
"Id": "15437",
"Score": "16",
"Tags": [
"scala",
"scalaz"
],
"Title": "Simple anagram finder using Scala and some Scalaz"
} | 15437 |
<p>I have written some code to simple add/mod/del to a table called person. I would like comments on where this code could be comprising on security. I have used the PDO library in php.</p>
<p>GetPerson.php ( use this to retrieve details of a person using ajax )</p>
<pre><code><?php
include '../classes/person.ph... | [] | [
{
"body": "<p>It's been a while since I've done any major php code; so I may be a bit rusty.</p>\n\n<h2>GetPerson.php</h2>\n\n<ul>\n<li><p><strong><code>$id</code> validations</strong><br>\nThis isn't bad really; mostly because the final state is integer. If the final state was a String, then you would have to ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-08T18:42:19.740",
"Id": "15438",
"Score": "2",
"Tags": [
"php",
"security"
],
"Title": "Is this simple add/mod/del/jquery code secure enough?"
} | 15438 |
<p>I'm not sure if this is the right way to do this, but I want to simply this script and hopefully use CSS3 animations. The code is really large, and parts are very irrelevant, so I'm wondering if I should first get rid of all the irrelevant parts, then go from there?</p>
<p>Here's the code:</p>
<pre><code>var _targ... | [] | [
{
"body": "<blockquote>\n <p>I'm wondering if I should first get rid of all the irrelevant parts</p>\n</blockquote>\n\n<p>Yes. Especially since source control will keep any code you may want in the future. If it is not being used it is just taking up resources to maintain it. <em>(e.g. everytime you read this ... | {
"AcceptedAnswerId": "15455",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-08T23:55:28.990",
"Id": "15441",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"event-handling"
],
"Title": "Handling a dragging gesture using jQuery"
} | 15441 |
<p>I want to randomly permute a finite list in the most effective and efficient way in C#. My attempt is as follows.</p>
<pre><code>/*===================================*
* Compile it to produce Shuffle.exe *
* ==================================*/
using System;
using System.Collections.Generic;
using System.IO;
nam... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T14:28:40.610",
"Id": "34870",
"Score": "0",
"body": "For what it's worth, there's [a library](http://www.codeproject.com/Articles/26050/Permutations-Combinations-and-Variations-using-C-G) which can do this for you."
}
] | [
{
"body": "<p>Here's what I came up with, it needs to be cleaned up and documented some more, but here's the gist. </p>\n\n<p>Since the random accesses into Lists<> turn out to be slow (especially removing items), we can get rid of that.</p>\n\n<p>So, make an array of numbers. </p>\n\n<p>Assign those numbers... | {
"AcceptedAnswerId": "15452",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-09T16:17:58.293",
"Id": "15449",
"Score": "7",
"Tags": [
"c#",
"algorithm",
"random"
],
"Title": "Randomly Permute Elements in a List"
} | 15449 |
<p>In an attempt to begin learning Scala, I've taken a stab at creating a simple wrapper around Java's File & FileInputStream in order to read lines from a file. This functionality already exists in the Source class and is just a learning exercise. </p>
<p>If you were building this wrapper in Scala, is there anyth... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T08:45:24.893",
"Id": "25085",
"Score": "0",
"body": "Looks pretty good! The only big thing I found out is in the for-comprehension: don't use `val` there. In 2.10 it's use is forbidden. ;)"
}
] | [
{
"body": "<p>Looks ok. A <code>Traversable</code> is a more interesting way to do this, since you can then auto-close the resource. There's one thing I took an issue to:</p>\n\n<pre><code>private val inputStream = new FileInputStream(file.javaFile)\n\nprivate val lineIterator = new BufferedLineIterator(inputSt... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T00:40:32.950",
"Id": "15457",
"Score": "12",
"Tags": [
"scala"
],
"Title": "Simple wrapper around Java's File & FileInputStream"
} | 15457 |
<p>I have a simple inheritance framework:</p>
<pre><code>class BaseValidator
{
protected virtual void Validate()
{
// Base validator code .....
}
}
class PhoneValidator:BaseValidator
{
public override void Validate()
{
base.Validate();
// custom validation logic...
}
}... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T21:47:57.533",
"Id": "25058",
"Score": "0",
"body": "Will you always call base.Validate(); from the sub-classes?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T22:06:47.407",
"Id": "25059",
"... | [
{
"body": "<p>Well, there are probably several good solutions, but the first one that comes to mind is to shift to an <em>interface-based</em> approach rather than an inheritance based one. You might define an IValidation interface that defines a Validation method, which each class implementor could then custom... | {
"AcceptedAnswerId": "15462",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T15:44:51.047",
"Id": "15458",
"Score": "1",
"Tags": [
"c#",
"design-patterns",
".net",
"validation"
],
"Title": "Solving an unwieldy inheritance framework function"
} | 15458 |
<p>We have a hidden div in a master page. When we want to display a message, we send a function a message to display, and it turns that div from .Visible false to .Visible true, and fills the div with the message. For all intents and purposes, this works and we haven't really had much trouble with it. I just feel th... | [] | [
{
"body": "<p>Not actually 100% sure if this will work for you but could you use Session variables to achieve what you are after?</p>\n\n<pre><code> public sealed class MessageInfo\n {\n private readonly string title;\n\n private readonly string text;\n\n public MessageInfo(string tit... | {
"AcceptedAnswerId": "15471",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T01:20:10.537",
"Id": "15464",
"Score": "7",
"Tags": [
"c#",
".net",
"asp.net"
],
"Title": "ASP.Net, C#, and alert/display messages"
} | 15464 |
<p>Today I built a <code>linspace</code> function in Python's C API:</p>
<pre><code>static PyObject *
linspace(PyObject * self, PyObject * args)
{
int n, i;
double start, end;
if (!PyArg_ParseTuple(args, "ddi:linspace", &start, &end, &n))
return NULL;
if (n <= 1)
return... | [] | [
{
"body": "<ol>\n<li><p>I can't see any obvious memory leaks. If you're worried, then you might start out by seeing what <a href=\"http://docs.python.org/library/sys.html#sys.getrefcount\" rel=\"nofollow\"><code>sys.getrefcount</code></a> tells you.</p></li>\n<li><p>You will need to package up your array-of-dou... | {
"AcceptedAnswerId": "15475",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T02:32:58.947",
"Id": "15465",
"Score": "7",
"Tags": [
"python",
"c",
"native-code"
],
"Title": "Linspace method build in Python's C API"
} | 15465 |
<p>I need comments on my JPA code. Am I doing it correctly? I need some advice on best practices in Java.</p>
<p>I have this method below:</p>
<pre><code>public Comics add(Comics comics) {
EntityManager em = EMF.get().createEntityManager();
EntityTransaction tx = null;
try{
tx = em.getTransaction(... | [] | [
{
"body": "<p>The way you are handling the exception will result in the method returning normally whether or not the method has succeeded. This is bad API design. Better design would be to either return some special value to indicate failure or (better) to allow the exception to propagate, or throw a differen... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T03:29:13.350",
"Id": "15467",
"Score": "8",
"Tags": [
"java",
"exception-handling"
],
"Title": "Coding style and best practice regarding exception-handling"
} | 15467 |
<p>I have written a piece of code by taking help from <a href="http://oswaldatwork.thetaoofamp.com/2009/10/scaling-images-in-php-done-right/" rel="nofollow">this link</a>. For generating thumbnail, I create a temporary scaled image and then copy from that image. I am assuming that it is resource intensive. </p>
<p>Set... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T09:50:28.973",
"Id": "25089",
"Score": "1",
"body": "This is a small recommendation. You should wrap this all in a class. This makes everything modular so you can easily reference the image source without having to manually go throu... | [
{
"body": "<p>Please don't count this as an answer. I've never done anything with any of the image libraries before, so I can't help you with the specifics. I would have put this into a comment, but its obviously too big. However, here are a few things to ponder.</p>\n\n<p>First, in regards to the comments Keir... | {
"AcceptedAnswerId": "15490",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T08:53:09.010",
"Id": "15470",
"Score": "4",
"Tags": [
"php",
"optimization",
"algorithm"
],
"Title": "PHP code to scale images and generate thumbnails"
} | 15470 |
<p>Can you please provide a general review the following PHP code (with MySQLi)?</p>
<p>The query involves an <code>INSERT INTO</code> statement:</p>
<pre><code>public function __i($table, $arr) { $c=$this->connection;
foreach ( $arr as $name => $val):
$param1.=$name . ",";
$param2.="?,";
endf... | [] | [
{
"body": "<p>Well, there's no context, so I can't be sure of exactly what you want, so I will assume a general review. In the future, please provide a little intro, even if its only to say, \"please review and tell me how I can do better.\" Just dumping code is rather vague, for instance, this question could j... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-09-10T11:05:38.820",
"Id": "15474",
"Score": "2",
"Tags": [
"php",
"mysqli"
],
"Title": "PHP MySQLI Insert Command"
} | 15474 |
<p>I have written code which does the following:</p>
<ol>
<li><p>The main goal is to fetch emails from inbox and spam folders and store them in a database. It fetches emails from Gmail, GMX, web.de, Yahoo and Hotmail.</p>
<p>The following attributes are stored in a MySQL database:</p>
<p><code>Slno</code>, <code>messag... | [] | [
{
"body": "<p>Well, for starters, I would put the mailbox information into a configuration file, properties file, database table, etc. Anywhere besides hard coded.</p>\n\n<p>Second, your <code>main()</code> method is totally out of control and needs to be broken up. I would suggest reading up about refactoring ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T13:49:12.857",
"Id": "15480",
"Score": "7",
"Tags": [
"java",
"beginner",
"email"
],
"Title": "Fetching emails from various clients to store in a database"
} | 15480 |
<p>The statement of the problem is there are 2 files, one has a set of intervals i.e. 0-10, 3-40, etc which may be repetitive. The second file has a set of numbers which are also repetitive. The exercise is to get a count of the intervals, a number in the 2nd file would fit into.</p>
<p>Intervals.txt</p>
<pre><code>0... | [] | [
{
"body": "<p>OK. Since this is homework I am going to limit my points to hints (I may add more in a week or so).</p>\n\n<ol>\n<li><p>Why are you doing this?</p>\n\n<pre><code>if(file.is_open())\n</code></pre></li>\n<li><p>This is an anti-pattern (in every language not just C++):<br>\nRemember the eof (part of ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T14:37:31.007",
"Id": "15482",
"Score": "1",
"Tags": [
"c++",
"optimization",
"interval"
],
"Title": "Getting a count of intervals"
} | 15482 |
<p>Three radio buttons and a text box, grouped in one group box... Just when I select one of those radio button the text box gets enabled, for the other two radio buttons it should be disabled. Here is the code that comes to mind at first, but it looks ugly to me becuase I have copy pasted the same AllowMissingData() m... | [] | [
{
"body": "<p>This cleans it up a little. Removes the if statement at least:</p>\n\n<pre><code>private void AllowMissingData()\n{\n MissingDataValueTextBox.Enabled = AllowBlankRadioButton.Checked;\n MissingDataValueTextBox.Text = AllowBlankRadioButton.Checked ? MissingDataValueTextBox.Text : System.Strin... | {
"AcceptedAnswerId": "15491",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T14:52:43.270",
"Id": "15483",
"Score": "3",
"Tags": [
"c#"
],
"Title": "A shorter way of Enablling/Disabling a text box from RadioButton selections"
} | 15483 |
<p>I have developed a prototype framework (MVVM) where control on the form is bound to a model property using a naming convention and its UI behavior is controlled using custom attributes.</p>
<ol>
<li><p>As of now the control name is divided into two parts - 3 part prefix and then the Name of the property in model to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-16T09:55:05.753",
"Id": "40609",
"Score": "1",
"body": "Do you have a sample project so that it can be tested?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-21T17:34:27.077",
"Id": "73027",
"Score... | [
{
"body": "<p>IMHO Anything that relies on controls' <code>Tag</code> property is fishy. In 15 years of VB4-5-6/VBA and then WinForms development, every single time I saw the <code>Tag</code> property assigned, there was a better way to solve the problem. I think using that property more often than not violates... | {
"AcceptedAnswerId": "35949",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T15:23:17.570",
"Id": "15485",
"Score": "3",
"Tags": [
"c#",
"winforms",
".net-2.0"
],
"Title": "Automatic Databinding of controls to Model"
} | 15485 |
<p>I am looking for some different approaches to this following OOP scenario.</p>
<pre><code> Dim pb As Object = Nothing
If radCars.Checked = True Then
Dim productBase As ProductsBase(Of CarColumns)
productBase = New Cars(fileLocation)
pb = productBase
ElseIf radTrucks.Checked = True Then
D... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T20:39:21.677",
"Id": "25118",
"Score": "0",
"body": "I'm not a VB.Net guy, but instead of object, why don't you make pb a ProductsBase?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-11T13:51:07.583",
... | [
{
"body": "<p>I would agree that defining pb as an object is a code smell and should be eliminated. </p>\n\n<p>Either in addition or instead of having Cars and Trucks inherit from ProductsBase(of T) it should implement an interface. </p>\n\n<p>Suggested Interface:</p>\n\n<pre><code>Public Interface IProducts\n\... | {
"AcceptedAnswerId": "15502",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T16:41:57.553",
"Id": "15489",
"Score": "3",
"Tags": [
".net",
"object-oriented",
"design-patterns",
"vb.net",
"generics"
],
"Title": "OOP: Need tips of my approach in .... | 15489 |
<p>I just wanted to gather your opinion on my little JavaScript library. It features <code>Math</code>, <code>String</code>, <code>Array</code>, <code>canvas</code> and <code>location</code> extensions, as well as some useful animation and timing classes I came up with:</p>
<pre><code>/* ====================== */
/* =... | [] | [
{
"body": "<p>Here are some tips.</p>\n\n<h1>1)</h1>\n\n<p>Avoid using java keywords. In Math.rand, there is a variable called <code>float</code>.\nTry calling it <code>toFloat</code>.</p>\n\n<h1>2)</h1>\n\n<p>It's best not to browser sniff. Detect for features instead.</p>\n\n<p>Old Code:</p>\n\n<pre><code>fun... | {
"AcceptedAnswerId": "15498",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T17:28:49.500",
"Id": "15492",
"Score": "6",
"Tags": [
"javascript",
"library"
],
"Title": "JavaScript library for Math, String, Array, canvas and location extensions"
} | 15492 |
<p>I have a library that accepts a file-like object but assumes that it has a valid <code>.name</code> unless that name is <code>None</code>. This causes it to break when I pass e.g. <code>someproc.stdout</code> as it has a name of <code><fdopen></code>. Unfortunately the attribute cannot be deleted or overwritte... | [] | [
{
"body": "<p>Something to watch out for with your approach is that Python calls certain special methods without looking them up via <code>__getattribute__</code>. For example, the <code>__iter__</code> method:</p>\n\n<pre><code>>>> w = InterceptAttrWrapper(open('test'), 'attr', 'value')\n>>> ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T18:33:34.687",
"Id": "15494",
"Score": "6",
"Tags": [
"python"
],
"Title": "Intercept read access to a certain object attribute"
} | 15494 |
<p>Only current and next element (<code>cNum</code>) is to be shown; in case it is the last element in the structure - the first element should be shown.</p>
<pre><code>var childNum = $('#h').roundabout("getChildInFocus");
var cNum = (Number(childNum)) + 2;
if (cNum == 5) cNum = 1;
$("#h li").hide();
$("#h li:nth-chi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T19:27:35.837",
"Id": "25114",
"Score": "1",
"body": "What is cNum used for? It's really confusing."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-21T14:09:42.307",
"Id": "25725",
"Score": "0",
... | [
{
"body": "<p>Here are a few tips.</p>\n\n<h2>1)</h2>\n\n<p><code>childNum</code> is not needed since it's only used once.</p>\n\n<p>Old Code:</p>\n\n<pre><code>var childNum = $('#h').roundabout(\"getChildInFocus\");\nvar cNum = (Number(childNum)) + 2;\n</code></pre>\n\n<p>New Code: </p>\n\n<pre><code>var cNum ... | {
"AcceptedAnswerId": "15497",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T18:35:02.580",
"Id": "15495",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Hiding all list items except the current and next element"
} | 15495 |
<p>I've finally gotten around to learning Lisp/functional programming. However, what I've noticed is that I'm trying to bring ideas back into JavaScript.</p>
<h1>Example</h1>
<h2>Before</h2>
<pre><code>var myPlacemark,
myLineString;
myLineString = ge.createLineString('');
myLineString.setLatitude(100);
myLineSt... | [] | [
{
"body": "<p>While using a closure to prevent polluting the global namespace is a good idea, you shouldn't be passing in random data like that. The way you are doing it, you are forcing the reader to scroll to the bottom of the function call before reading the function body - that's just plain confusing for no... | {
"AcceptedAnswerId": "15509",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T19:47:16.603",
"Id": "15496",
"Score": "7",
"Tags": [
"javascript",
"functional-programming"
],
"Title": "Overusing JavaScript closures?"
} | 15496 |
<p>I got the solution for the question asked <a href="https://stackoverflow.com/questions/12286998/uiviewcontroller-do-not-rotate-to-landscape">here</a>, but I don't like how the code is written.</p>
<p>This part of the code rotates the screen if it's in landscape and sets the size to match the screen. I don't like th... | [] | [
{
"body": "<p>I think that you can rewrite the code in a more OO way, with the help of an <a href=\"https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html#//apple_ref/occ/cl/NSDictionary\" rel=\"nofollow\">NSDictionary</a> and settin... | {
"AcceptedAnswerId": "15500",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T13:33:30.167",
"Id": "15499",
"Score": "4",
"Tags": [
"objective-c",
"image"
],
"Title": "Adjusting a landscape screen"
} | 15499 |
<p>I have a third party component that I am trying to write unit tests around. The problem is that I can't mock the object and there is no interface. </p>
<p>I decided to create an interface and a wrapper class calling into the code for the sake of mocking. I looked into the class definition that is generated by Visua... | [] | [
{
"body": "<p>Congratulations! You have successfully utilized the object-oriented design pattern known as the <a href=\"https://en.wikipedia.org/wiki/Adapter_pattern\">Adapter Pattern</a>. I think that looks perfectly good. Though, I wouldn't check <code>pop3</code> for <code>null</code> in the <code>Dispose()<... | {
"AcceptedAnswerId": "15503",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T21:29:26.467",
"Id": "15501",
"Score": "9",
"Tags": [
"c#",
"unit-testing"
],
"Title": "Creating a wrapper class to use for mocking that uses IDisposable"
} | 15501 |
<p>I really don't get why it has to take so much to make such a little function. Here's what I have.</p>
<pre><code>template <typename A, typename B> auto add(A a, B b) -> decltype(a + b) {
return a + b;
}
</code></pre>
<p>Is there a way to shrink this code while maintaining its ability to take different ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T22:38:46.283",
"Id": "25127",
"Score": "3",
"body": "I think 3 lines is relatively short for a piece of code that supports all types that can be used with `operator +`. Without the declytype it would be infinitely long as you need t... | [
{
"body": "<p>You may want to take a look at <a href=\"http://pfultz2.github.com/Pythy/\" rel=\"nofollow\">Pythy</a>. </p>\n\n<p>What you want seems a lot like:</p>\n\n<pre><code>PYTHY(add, x, y) (\n return x + y;\n)\n</code></pre>\n\n<p>Make sure to read this part of the article, as pointed out by Konrad:</... | {
"AcceptedAnswerId": "15511",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T22:22:15.213",
"Id": "15504",
"Score": "4",
"Tags": [
"c++"
],
"Title": "How do I make this simple addition code less verbose?"
} | 15504 |
<p>I got some homework in which I had to take the novel War and Peace and put it into a HashSet and TreeSet respectively. I had to time it, to check differences and my question is whether my implementation is good or not.
If the way I calculate time is even accurate. I am using</p>
<pre><code>System.currentMillis()
</... | [] | [
{
"body": "<p>To measure the time taken, you should use <a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#nanoTime%28%29\"><code>System.nanoTime</code></a>. That should <em>only</em> be used for \"stopwatch\" type operations - never for taking the \"current system time\" in a wall-clock w... | {
"AcceptedAnswerId": "15507",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T23:22:57.783",
"Id": "15505",
"Score": "26",
"Tags": [
"java",
"homework",
"set",
"benchmarking"
],
"Title": "HashSet and TreeSet"
} | 15505 |
<p>Now this is something I've looked into, and while I have a "working" solution, I don't like it.</p>
<p><strong>Background:</strong></p>
<p>Through our intranet website, we want to run a process that copies a file from another machine, unzips it, and then analyzes the content. As the file is large, this takes some... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-12-31T13:09:25.300",
"Id": "407193",
"Score": "0",
"body": "did you tried using ***SignalR*** ?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-02-08T09:35:06.413",
"Id": "412204",
"Score": "0",
"body... | [
{
"body": "<p>Have you considered using <a href=\"http://signalr.net/\" rel=\"nofollow\">SignalR</a>?</p>\n\n<p>As their homepage states, it's a \"library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. What is \"real-time web\" functionality? It's... | {
"AcceptedAnswerId": "41046",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-11T03:29:57.077",
"Id": "15510",
"Score": "2",
"Tags": [
"c#",
"asp.net"
],
"Title": "Making a page update based on the progress of a process"
} | 15510 |
<p>I am trying to place <code>JButton</code>s from an array onto a <code>JFrame</code>. The way I'm doing it is having it test how many more buttons are left, and if buttons have been placed at the edge of the frame. The end result is an ugly piece of code.</p>
<pre><code>JButton[] grid = new JButton[2501];
JFrame Ma... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-11T09:50:16.323",
"Id": "25165",
"Score": "1",
"body": "Make `15` a constant, calculate `749` from the MapFrame.bounds and it will be fine."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-12T10:33:29.787",
... | [
{
"body": "<p>In order to find a more elegant solution, we first need to <em>identify</em> the problems; only then can we <em>solve</em> them:</p>\n\n<ul>\n<li><p><strong>Magic Numbers</strong><br>\nOne of the confusing things about this snippet is that we <em>constantly</em> <sup>(pun intended)</sup> come acro... | {
"AcceptedAnswerId": "15517",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-11T07:45:34.037",
"Id": "15513",
"Score": "5",
"Tags": [
"java",
"swing"
],
"Title": "How can I make placing JButtons from an array more elegant?"
} | 15513 |
<p>How can I make this more readable, faster, and make the GUI more appealing? </p>
<p><strong><code>CreditCard</code> class:</strong></p>
<pre><code>import java.util.*;
public class CreditCards {
private String prefix;
private String length;
public CreditCards(String p, String l) {
prefix = p;... | [] | [
{
"body": "<ol>\n<li><p>Construction like</p>\n\n<pre><code>boolean pre = getPrefix().equals(\"4\") ? true:false;\n</code></pre>\n\n<p>is redundant. The following is ok:</p>\n\n<pre><code>boolean pre = getPrefix().equals(\"4\");\n</code></pre>\n\n<p>just as </p>\n\n<pre><code>if(pre && len) {\n retur... | {
"AcceptedAnswerId": "15518",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-11T10:30:56.997",
"Id": "15516",
"Score": "2",
"Tags": [
"java",
"validation",
"swing",
"e-commerce"
],
"Title": "GUI-based credit card checker"
} | 15516 |
<p>How can I DRY these scopes?</p>
<pre><code> scope :reputed, -> {
joins{reputations.outer}.
where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ?', LOWEST_VOTE, true]}
}
scope :reputed_or_mine, ->(user) {
joins{reputations.outer}.
where{['coalesce(rs_reputations.v... | [] | [
{
"body": "<pre><code>'coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = true OR (? AND purchases.user_id = ?)',\nLOWEST_VOTE,\n!user.id.nil?,\n(if user.id.nil? then -1 else user.id end)\n</code></pre>\n\n<p>This is semantically equivalent to both, but the AND in the third clause prevents it ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-11T12:39:33.173",
"Id": "15520",
"Score": "4",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Scopes chaining by OR"
} | 15520 |
<p>I've been working with the RaphaelJS '<a href="http://raphaeljs.com/australia.html" rel="nofollow">australia map</a>' example that displays text in a DIV when a state is clicked on. However I'm having difficulty working with it to create different events and functions. </p>
<p>I want to be able to duplicate the 'di... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T16:38:48.043",
"Id": "25174",
"Score": "2",
"body": "That is actually reasonably compact, straightforward code. Which part were you hoping to simplify, exactly? One thought: if the click handler is what you're focusing on, you can... | [
{
"body": "<p>I gave it a shot.</p>\n\n<pre><code>window.onload = function () {\n var R = Raphael(\"paper\", 532, 500),\n attrs = {\n fill: \"#0B0\",\n stroke: \"#fff\",\n \"stroke-width\": 3,\n cursor: \"pointer\"\n },\n paths = [\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-10T10:13:28.113",
"Id": "15521",
"Score": "2",
"Tags": [
"javascript",
"raphael.js"
],
"Title": "Simplify Raphael JS code: display text in DIV on click event"
} | 15521 |
<p>I've been working on a class to handle dependency injection across some code akin to a micro-framework. This is also my first real dive into any sort of <em>wrapper</em> for dependency injection. I decided to write a pseudo-intelligent dependency provider that recursively constructs dependencies. I also included the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-12T21:01:43.717",
"Id": "25238",
"Score": "0",
"body": "TIL: DI Containers and Registry pattern. From my newly acquired understanding, this looks like both. Registry pattern by \"making\" classes, and a Container because there's a bunc... | [
{
"body": "<ol>\n<li>It depends on how you use it. Your \"sharedObjects\" part would probably fit Registry pattern if you start using it as global object. On the other hand usually Registry does not create objects, but rather store them. Your implementation is a proper container as long as you don't start passi... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-11T19:57:45.287",
"Id": "15527",
"Score": "6",
"Tags": [
"php",
"dependency-injection"
],
"Title": "Dependency Injection Provider/Container"
} | 15527 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.