body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I'm working on a clone of <a href="http://www.kongregate.com/games/crovy/hunter-story" rel="nofollow">Hunter Story</a>. You shoot monsters with your bow. Recently I implemented collision detection, this is all working correctly, and I don't think the code needs any dramatic optimisations. The only thing I'm a bit wo... | [] | [
{
"body": "<p>You could add an abstract <code>onCollision()</code> method to Entity and move the <code>CheckCollision</code> method to Entity so it would be: </p>\n\n<pre><code>arrow.checkCollision(monster)\n</code></pre>\n\n<p>That is all that I can think of, it looks pretty solid to me.</p>\n",
"comments... | {
"AcceptedAnswerId": "25510",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T17:44:35.623",
"Id": "25346",
"Score": "2",
"Tags": [
"java",
"object-oriented"
],
"Title": "Collision detection implementation"
} | 25346 |
<p>Depending on external OO libraries is really bad, using prototypes/new has some limitations, using only hashes has others. Dealing with classes was always a pain in JavaScript and it didn't help that every library has it's own way to deal with ti. But since some time I've finally "set" with this design:</p>
<pre><c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T20:10:48.940",
"Id": "39295",
"Score": "0",
"body": "What is the point of privates if anybody can retrieve them? Normally privates are only accessible to the actual methods, not to the public."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>What about regular inheritance? Is <code>extend</code> supposed to be the superclass?</p>\n\n<pre><code>foo = { foo: \"bar\" };\n\na = my_class(foo);\nb = my_class(foo);\n\na.foo = \"baz\";\nconsole.log(b.foo);\n\n--> \"baz\";\n</code></pre>\n\n<p>I would expect <code>a</code> and <code>b</code... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-22T20:07:42.747",
"Id": "25350",
"Score": "1",
"Tags": [
"javascript",
"optimization",
"object-oriented"
],
"Title": "I've finally found a satisfactory way to create classes on JavaS... | 25350 |
<p>I wanted to review my design strategy for CSV parser.
I have 4 CSV files, which have different layouts as shown below.
Each row of a CSV file will be mapped to a class. For example, if <code>CSV_FILE_A</code> has 10 rows, a list contains 10 objects of ObjA will be returned after calling parser function. For CSV_FILE... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T16:10:41.377",
"Id": "39337",
"Score": "0",
"body": "do you really need a different type to be sent back for each file type? I think a better design would like record set : one class representing a row of data; with properties : ge... | [
{
"body": "<p>For starters, consider having an abstract class to do the line-by-line reading, and having your concrete classes implement the code on converting one line into the desired object?</p>\n\n<p>Also, the multiple <code>if-else-if</code> can be slightly improved by replacing it with a <code>switch</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T00:28:58.613",
"Id": "25354",
"Score": "4",
"Tags": [
"java",
"design-patterns",
"csv"
],
"Title": "Design Strategy of CSV Parser"
} | 25354 |
<p>After experimenting with a <a href="https://codereview.stackexchange.com/questions/25248/sorted-trie-implementation-in-c">sorted trie implementation in C</a>, I felt that I understood tries pretty well, but was having trouble explaining how they work. Since the C code was based on existing code, I wanted to try it a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T08:58:25.470",
"Id": "39328",
"Score": "0",
"body": "Just personal preference, but I think you're using a weird coding style. `while (++i <= len)` isn't something comprehensible. Not using braces for `if`, etc. The code is pretty, b... | [
{
"body": "<p>Well, first of all, my optimization is an overhaul of your method. The concept is still tries. But I went for the JS route for several reasons:</p>\n\n<ul>\n<li><p>We're in JavaScript. Linked lists in C would be like Arrays/Objects in JS. Since we have them available, why not use them instead?</p>... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T06:24:12.743",
"Id": "25359",
"Score": "13",
"Tags": [
"javascript",
"linked-list",
"hash-map",
"trie"
],
"Title": "Simple trie implementation in JavaScript"
} | 25359 |
<p>I have 3 classes: a transmitter, a view for displaying and a recording view for flushing the screen contents into a file. The view and the recording view classes register themselves from their constructor in the transmitter, which keeps them in a HashMap. The transmitter implements all the view and recording view cl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T16:53:00.480",
"Id": "39341",
"Score": "1",
"body": "Why no reflection? Have you considered code generation (compile time or runtime)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T21:04:22.480",
... | [
{
"body": "<p>Why no reflection? Have you considered code generation (compile time or runtime)?</p>\n\n<hr>\n\n<p>Here's an idea based on proxies and reflection. I haven't actually tried any of this, so the idea might break down at some point, but here goes.</p>\n\n<p>Create an interface for the transmitter tha... | {
"AcceptedAnswerId": "25499",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T08:03:21.840",
"Id": "25361",
"Score": "1",
"Tags": [
"java",
"delegates"
],
"Title": "Refactoring Java transmitter delegate implementation"
} | 25361 |
<pre><code><div id="members">
<div id="inputRow0">
<input id="input0_0" class="input" type="text" /><br/>
<input id="input0_1" class="input" type="text" /><br/>
<input id="input0_2" class="input" type="text" />
</div>
<div id="inputR... | [] | [
{
"body": "<p>What problem are you trying to solve? I've left your code doing the same things but rather than interrogate the DOM each time I've cached everything in local variables. </p>\n\n<pre><code>// Execute code in an Immediately Invoked Function Expression (IIFE)\n// This helps stop your variables pollut... | {
"AcceptedAnswerId": "25373",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T13:22:46.883",
"Id": "25369",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html",
"form"
],
"Title": "Showing or hiding groups of three text fields"
} | 25369 |
<p>My team and I wrote the following Nhibernate wrapper which gives generic retrieval and save/update functions and a possibility to send a function as a paramater which may contain several save/update calls which will be committed or rollback transactionally:</p>
<pre><code>public class DB
{
private const... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T15:23:59.107",
"Id": "39427",
"Score": "0",
"body": "Why do this instead of the standard way? This seems unnecessarily complex."
}
] | [
{
"body": "<ul>\n<li><p>If a method returns false it is a failure, it also is failure if it throws. If you had (could?) stick with exceptions only: </p>\n\n<p>try { /* do sthg*/ return true; } catch (Exception) { return false; }</p></li>\n</ul>\n\n<p>constructs would be unnecessary. You already have two: in <... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T13:37:08.463",
"Id": "25370",
"Score": "1",
"Tags": [
"c#"
],
"Title": "A Generic NHibernate wrapper with transactionality"
} | 25370 |
<p>In response to my <a href="https://codereview.stackexchange.com/questions/25155/is-this-method-doing-too-much">previous question</a>, I've refactored my class quite a bit. I've truncated my class a bit, because I have several methods that are very similar, with the exception of the query for the database. The class ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T17:05:01.637",
"Id": "39344",
"Score": "1",
"body": "Am I the only one left who hates `var`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T17:13:56.760",
"Id": "39345",
"Score": "6",
"bo... | [
{
"body": "<p>It looks like some of the methods are simply calculating the max or average. You might be able to move these types of calculations into the queries by using the corresponding aggregate functions. For example:</p>\n\n<pre><code>SELECT MAX(pump_press) FROM myDatabase\nSELECT AVG(torque) FROM myDatab... | {
"AcceptedAnswerId": "25380",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T14:36:40.790",
"Id": "25372",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Is this class too over the top?"
} | 25372 |
<p>I just started learning C and the online book contained the exercise 'implement a stack'. So I did, but thought I'd put it here, because I still don't feel comfortable with pointers.</p>
<p>So here it is:</p>
<pre><code>#include <stdlib.h>
#include <stdio.h>
struct StackItem {
struct StackItem *pr... | [] | [
{
"body": "<p>Your code looks nice and compiles cleanly - good signs. Some comments, nevertheless:</p>\n\n<ul>\n<li><p>all functions except <code>main</code> should be declared <code>static</code></p></li>\n<li><p>the opening brace { for a function should be in column 0</p></li>\n<li><p><code>stack_print</code... | {
"AcceptedAnswerId": "25378",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T14:57:12.883",
"Id": "25374",
"Score": "4",
"Tags": [
"c",
"stack"
],
"Title": "Another stack implementation (in C)"
} | 25374 |
<p>Instead of using the ProgressBar plugin, this script displays the progress bar for async requests on the page. Could anyone provide any feedback on this, especially if there will be any issues like cross browser compatibility, etc?</p>
<pre><code><div class="overlay">
<div class="progress">
&... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-27T15:43:46.420",
"Id": "50935",
"Score": "0",
"body": "There are websites to test browser compatibility; or, you can test across the main browsers yourself, I download safari, opera, firefox, ie 9 and 10 to test websites"
},
{
... | [
{
"body": "<p>My 2 cents : </p>\n\n<ul>\n<li><p>I definitely learned something today, I didnt know about <code>ajaxStart</code> / <code>ajaxStop</code>, excellent question.</p></li>\n<li><p>In my eyes this should work on most recent browsers, but as Skippy says, you ought to test yourself on every browser.</p><... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T16:24:12.850",
"Id": "25379",
"Score": "11",
"Tags": [
"javascript",
"jquery",
"asp.net",
"css",
"ajax"
],
"Title": "Display progress bar to show async request status usin... | 25379 |
<p>I've finally finished my converter and have determined that it works, but I'm trying to make it cleaner and/or more practical (primarily with the <code>switch</code> statements). I could probably put more things into functions, but it'll be needless unless I can replace the <code>switch</code> statements with somet... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T17:30:32.073",
"Id": "39346",
"Score": "0",
"body": "Are you willing to the code tied to ASCII? If so, the easiest simplification I see is to use c - '0' to get offsets. Like `decimal += (*iter - '0') * calculatePower(16, exponent)`... | [
{
"body": "<p>You repeated calls to <code>calculatePower</code> are rather inefficient. There is no need to\ncall this every time round a loop. In <code>binaryToDecimal</code>, you could do this:</p>\n\n<pre><code> std::string::const_reverse_iterator i = b.rbegin();\n for (int exp = 0; i != b.rend(); ++... | {
"AcceptedAnswerId": "25390",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T16:35:01.423",
"Id": "25381",
"Score": "5",
"Tags": [
"c++",
"integer",
"number-systems"
],
"Title": "Decimal/binary/hex converter"
} | 25381 |
<p>I wrote this code for <a href="http://projecteuler.net/index.php?section=problems&id=75" rel="noreferrer">Project Euler problem 75</a>, which asks how many integers ≤ 1500000 exist, where the integer is a perimeter length that can be divided into three integer-length sides of a right triangle in one unique way.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T20:06:05.227",
"Id": "39364",
"Score": "0",
"body": "Probably not what you are looking for but in my opinion if you are worried about run time, then python is not the right language to use. It is hard to fine tune and optimize in ge... | [
{
"body": "<p>For the record, this is <a href=\"http://projecteuler.net/index.php?section=problems&id=75\" rel=\"noreferrer\">Project Euler problem 75</a>.</p>\n\n<h3>1. Admonition</h3>\n\n<p>You write:</p>\n\n<blockquote>\n <p>Please note that I am not looking for a different calculating method (I am sure... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T18:12:36.453",
"Id": "25388",
"Score": "25",
"Tags": [
"python",
"performance",
"programming-challenge",
"computational-geometry"
],
"Title": "Speed up solution to Project Eul... | 25388 |
<p>Say, there is a class with some methods, that have <code>try catch</code> blocks. I need to accumulate messages from all inner exceptions of generated exception and use <code>throw new Exception(exceptionMessages)</code>. <br />
I came up with two possible solutions:</p>
<ol>
<li>Create a private method, concatenat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T20:37:49.333",
"Id": "39365",
"Score": "0",
"body": "Both approaches are the same but I would preferred 1st one (SomeMethod1()) - it's more clear that you are rethrowing exception and not just swallowing it"
},
{
"ContentLi... | [
{
"body": "<h2>Svick is right</h2>\n\n<p>Use the AggregateException class to collect all exceptions you need. With AggregateException everyone can prepare it's own code to handle the multiple exception situation but with your original solution they have to handle a huge string in a stock exception class. How ca... | {
"AcceptedAnswerId": "25404",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T19:14:55.710",
"Id": "25391",
"Score": "4",
"Tags": [
"c#",
"exception-handling",
"exception"
],
"Title": "Accumulating inner exception messages"
} | 25391 |
<p>I need to fast fill a memory block in C#, so I wrote something like this (in Free Pascal Compiler + Lazarus in 64 bit mode):</p>
<pre><code>// ECX = Ptr64
// EDX = Count
// R8 = Value
PROCEDURE Fill64 (VAR Ptr64; Count: QWord; Value: QWord);
BEGIN
ASM
PUSH RDI
MOV RDI, RCX // Destination In... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T22:09:12.217",
"Id": "39371",
"Score": "2",
"body": "have you tested it against other possible implementations for speed?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T09:32:47.330",
"Id": "3940... | [
{
"body": "<p>Unfortunately the answer is CPU-dependent. For example <a href=\"https://android.googlesource.com/kernel/omap/+/038b0a6d8d32db934bba6a24e74e76e4e327a94f/arch/x86_64/lib/memset.S\">here</a> is Android's memset implementation: it uses <code>rep stosq</code> for some CPUs and a different more complic... | {
"AcceptedAnswerId": "43178",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-04-23T19:35:36.323",
"Id": "25393",
"Score": "7",
"Tags": [
"c#",
"assembly",
"delphi"
],
"Title": "Fastest fill memory with specified 64-bit value"
} | 25393 |
<p>I'm currently following the tutorials over at <a href="http://www.rubymonk.org" rel="noreferrer">RubyMonk</a>, and one of the problems I need to solve is to write a <code>subtract</code> function that would meet these conditions:</p>
<blockquote>
<ul>
<li>invoking <code>subtract(4, 5)</code> should return <code... | [] | [
{
"body": "<p>Some notes:</p>\n\n<ul>\n<li><p><code>def subtract *numbers</code>: While Ruby allows to omit parens, the community consensus is that it makes signatures harder to read. </p></li>\n<li><p><code>(numbers.drop 1)</code>: When you have to write parens like this, it's a signal that you should just wri... | {
"AcceptedAnswerId": "25395",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T19:50:34.913",
"Id": "25394",
"Score": "6",
"Tags": [
"ruby"
],
"Title": "Subtraction accumulator"
} | 25394 |
<p>The following code I devised to compute a <a href="http://en.wikipedia.org/wiki/Determinant" rel="nofollow">determinant</a>:</p>
<pre><code>module MatrixOps where
determinant :: (Num a, Fractional a) => [[a]] -> a
determinant [[x]] = x
determinant mat =
sum [s*x*(determinant (getRest i mat)) | i <- [0..n... | [] | [
{
"body": "<p>Just a few thoughts:</p>\n\n<ul>\n<li>Your method (IIUC) is conceptually correct, but has computation complexity <em>O(n!)</em> where <em>n</em> is the dimension of a given matrix. If you need better complexity (polynomial in <em>n</em>), you have to use another solution, such as using PLU decompo... | {
"AcceptedAnswerId": "25405",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-23T23:20:18.513",
"Id": "25397",
"Score": "2",
"Tags": [
"haskell",
"functional-programming",
"recursion"
],
"Title": "Recursive Determinant"
} | 25397 |
<p>Below is the basic shell of an application I am working on that is part of a Webhosting Control Panel. This part is for the DNS records management.</p>
<p>So in my code below, I have taken away all the main functionality as it's not relevant to my question and to make it less cluttered.</p>
<p>On the page I have b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T05:26:22.343",
"Id": "39387",
"Score": "0",
"body": "Is this code standalone? or are there other parts of your application using this `dnsRecords` stuff? which parts?"
}
] | [
{
"body": "<p>What you are doing seems pretty much the standard way to do this sort of thing with Javascript and jQuery . </p>\n\n<p>A few pointers:</p>\n\n<p>Often, you wrap functions with other anonymous functions, for example:</p>\n\n<pre><code>$(\"#dnsTitle a.save\").click(function() {\n zPanel.loader.sh... | {
"AcceptedAnswerId": "25409",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T02:32:17.920",
"Id": "25398",
"Score": "-2",
"Tags": [
"javascript"
],
"Title": "Structuring Events in JavaScript"
} | 25398 |
<p>Inspired by xkcd and a couple of praising blog posts, I decided to try out Lisp. It seemed that the best-supported dialect was Racket, itself a variant of Scheme, so I went with that and wrote an infix mathematical expression parser to get familiar with the basic concepts.</p>
<p>That was a mind-bending experience ... | [] | [
{
"body": "<p>Here are my review comments on the tokeniser:</p>\n\n<ol>\n<li><p>It's unusual to prefix symbols with <code>-</code>. The indentation should be enough to tell you the \"nesting level\" of the inner functions, without having to put <code>-</code>s in front.</p></li>\n<li><p>Your inner <code>-tokeni... | {
"AcceptedAnswerId": "25406",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T03:05:21.077",
"Id": "25400",
"Score": "3",
"Tags": [
"lisp",
"scheme",
"racket"
],
"Title": "Scheme/Racket: idiomatic infix math evaluator"
} | 25400 |
<p>Database schema: describes the structure of the information within a database system. The schema is formalized using integrity constraints, which may be expressed as a series of sentences to describe the data, structure of the database and properties of the database. The database schema provides the blue print for f... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T04:19:24.727",
"Id": "25401",
"Score": "0",
"Tags": null,
"Title": null
} | 25401 |
<p>I have the following contact form included with my wordpress theme as a template.</p>
<p>Now a user on Stackoverflow pointed out that this form has some serious security vulnerabilities.</p>
<p>Could someone please point them out and tell me where I can improve</p>
<p>Form:</p>
<pre><code><?php
/*
* Template... | [] | [
{
"body": "<p>And they didn't give ANY more detail? That was mean! </p>\n\n<p>I think they meant cross site scripting attacks since your form does not check for the form's referrer, or remove html or JavaScript, and you echo out what the user has typed in that means they could add JavaScript to your site. Conce... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T08:12:40.540",
"Id": "25416",
"Score": "3",
"Tags": [
"php",
"security",
"form"
],
"Title": "Wordpress php Contact Form - Security flaws"
} | 25416 |
<p>I got a piece of code I'm not pleased with; Does anyone would have a better idea?</p>
<pre><code>def myFunc(verbose=True):
if not verbose:
print = functools.partial(globals()['print'], file=open(os.devnull, 'w'))
else:
# Required, othewise I got the error 'local print variable was referenced... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T09:57:35.307",
"Id": "39409",
"Score": "2",
"body": "It might be worth having a look at the logging facilities offered by Python."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T01:25:19.057",
"Id... | [
{
"body": "<p>It depends on what you are looking to do. For localized 'quiet' code, I use this:</p>\n\n<pre><code>class NoStdStreams(object):\n def __init__(self,stdout = None, stderr = None):\n self.devnull = open(os.devnull,'w')\n self._stdout = stdout or self.devnull or sys.stdout\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T08:13:16.783",
"Id": "25417",
"Score": "2",
"Tags": [
"python"
],
"Title": "Is there a better way to make a function silent on need?"
} | 25417 |
<p>I'm not a C programmer, just wanted to make a fast solution to the <a href="https://projecteuler.net/problem=15" rel="nofollow">problem</a>. </p>
<blockquote>
<p>Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-12-31T10:31:22.657",
"Id": "137107",
"Score": "2",
"body": "Those are binomial coefficients right? So \\$\\frac{n!}{(n-k)!k!}\\$ where \\$n = 40\\$ and \\$k = 20\\$ should do it?"
}
] | [
{
"body": "<p>I do not know whether my suggestion makes code faster, but it sure does make it shorter and probably equally fast. It calculates the possibilities dynamically, using the observation that number of ways to get to a square is the sum of numbers of ways to get to the top and the left square, as does ... | {
"AcceptedAnswerId": "25426",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T09:15:11.203",
"Id": "25419",
"Score": "4",
"Tags": [
"c",
"programming-challenge",
"dynamic-programming"
],
"Title": "Project Euler #15 -- count possible lattice paths"
} | 25419 |
<p>This is used to display an accordion with a list of connections using JavaFX. Can you help me to optimize the code to make it much simpler?</p>
<pre><code>package sqlbrowser.navigation;
import java.util.ArrayList;
import java.util.List;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.Observable... | [] | [
{
"body": "<pre><code>scroll.getStyleClass().add(\"stacked-titled-panes-scroll-pane\");\nscroll.setPrefSize(395, 580);\nscroll.setLayoutX(5);\nscroll.setLayoutY(32);\n</code></pre>\n\n<p>these lines can go inside <code>makeScrollable()</code>, which in turn could be refactored with <code>initNavigation()</code>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T13:23:20.947",
"Id": "25424",
"Score": "1",
"Tags": [
"java",
"javafx"
],
"Title": "Displaying an accordion with a list of connections"
} | 25424 |
<p>I'm working on JavaScript <a href="http://en.wikipedia.org/wiki/Bookmarklet" rel="nofollow noreferrer">bookmarklet</a> that lets users send a text and link to a site.</p>
<p>This is the bookmarklet:</p>
<pre><code>javascript:(function(){new_script=document.createElement('SCRIPT');new_script.src='http://bookmarklet.e... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T14:19:53.987",
"Id": "39423",
"Score": "0",
"body": "Where's the `void()` function defined and why are you using it?"
}
] | [
{
"body": "<p>The loader could be simplified to the following:</p>\n\n<pre><code>javascript:(function () {document.getElementsByTagName('head')[0].appendChild(document.createElement('script')).src = 'http://bookmarklet.example.com/js/bookmarklet.js?v=1'}());\n</code></pre>\n\n<ul>\n<li>No more variables. By the... | {
"AcceptedAnswerId": "25434",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T14:11:41.833",
"Id": "25427",
"Score": "1",
"Tags": [
"javascript",
"optimization"
],
"Title": "JavaScript - Does this bookmarklet need some optimization?"
} | 25427 |
<p>I still have to implement API keys for client auth, but so far this is what I have for users. This was built using WebAPI and SimpleMembership with Forms Auth:</p>
<p><strong>Is Authenticated:</strong></p>
<pre><code>public class AccountController : ApiController
{
public static DtoService _service = new DtoServi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T14:59:06.997",
"Id": "39425",
"Score": "0",
"body": "I think you should not have your logout be a POST operation."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T19:44:59.757",
"Id": "39444",
... | [
{
"body": "<p>Lets start with your URI's.</p>\n\n<p>GET /api/isAuthenticated - This is not restful I guess. isAuthenticated doesn't sound like it is a resource, instead it sounds like it is a method returning true or false. May be it would help if you read more on Restful architecture.</p>\n\n<p>POST /api/login... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T14:12:55.090",
"Id": "25428",
"Score": "3",
"Tags": [
"c#",
".net",
"mvc",
"api"
],
"Title": "REST-ish API Account Controller"
} | 25428 |
<p>I just wrote the following javascript (jQeury loaded):</p>
<pre><code>var valid, ui;
try {
$.each(this._cache, function() {
$.each(this, function() {
$.each(this, function() {
if (this.label.toLowerCase() === valueLowerCase) {
valid = true;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T15:40:31.403",
"Id": "39430",
"Score": "4",
"body": "Exceptions should be used in exceptional circumstances, not in logic of the application. By exceptional circumstances, I mean they should only be used when something unexpected h... | [
{
"body": "<p>As Jef Vanzella mentioned, exceptions are for unexpected bad things, not for jumping out of control flow. Hence the second option is better, but it is still substandard code.</p>\n\n<p>Instead of using <code>this</code>, you should have a meaningful parameter name in your function declaration.</p>... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T15:22:29.630",
"Id": "25432",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"exception-handling",
"jquery-ui"
],
"Title": "Exceptions for control flow"
} | 25432 |
<p>I built a code piece that makes it easy to execute a set of <strong>sequential</strong> operations, that might depend on the same parameter value (passed across the execution) or might need a particular parameter.
There's also a possibility to manage an error from within the operations, by implementing <code>IRevers... | [] | [
{
"body": "<p>It does not look like you ever reference <code>IExecutableOperation<T></code> or <code>IInternalOperation<T></code> directly, so I would take the YAGNI approach and roll them both into <code>IOperation<T></code>.</p>\n\n<p>With that done, <code>Operation<T></code> would imp... | {
"AcceptedAnswerId": "25451",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T16:28:42.433",
"Id": "25435",
"Score": "3",
"Tags": [
"c#",
"design-patterns",
"generics",
"covariance"
],
"Title": "Sequential Execution: Orchestrator Pattern"
} | 25435 |
<p>Below is the code I have written. I started yesterday with prime numbers and playing around with them. What the code does it determines the "prime gap" between primes numbers, prints them, then finds the gap between these numbers, prints, etc. It starts to create a very cool pattern <a href="https://math.stackexchan... | [] | [
{
"body": "<p>Ok, so you do not need temporary List. You can change the code to reuse the same List, primesLL. Also I have changed the List to arrayList, since accessing elements by index is costly for LinkedList. Try this and see if it improves. </p>\n\n<pre><code>import java.awt.BorderLayout;\nimport java.awt... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T16:45:52.360",
"Id": "25436",
"Score": "3",
"Tags": [
"java",
"optimization",
"primes",
"swing"
],
"Title": "Sierpinski gasket - patterns from primes"
} | 25436 |
<p>I have a table with 'nested' inputs that need to be checked or unchecked when a button 'select all' is pressed. There are several levels that can be toggled with their respective 'select all' button. In my code I have a repetitive <code>.each()</code> statement where the second one tests if there are differing num... | [] | [
{
"body": "<p>In general, you would have an easier time doing this if your \"nested rows\" were <em>actually</em> nested. However - that leads to a variety of other layout problems, etc.</p>\n\n<p>That said - here is a simpler way to accomplish what I think you're looking for:</p>\n\n<p><strong>jQuery code</str... | {
"AcceptedAnswerId": "25441",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T18:27:04.543",
"Id": "25440",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "jquery checking nested input with repetitive code"
} | 25440 |
<p>My goal is to have a reusable pattern for doing concurrent stream-processing in Go. </p>
<ul>
<li>The stream has to be closable from any node. </li>
<li>Errors should cleanly close the stream and forward the error to the consumer.</li>
<li>Should have a nice API</li>
</ul>
<p>Here's what I came up with: <a href="h... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T19:49:04.850",
"Id": "25447",
"Score": "2",
"Tags": [
"api",
"go",
"stream"
],
"Title": "Stream-chaining"
} | 25447 |
<p>A few months ago, I wrote a query selector that seems to outperform the query selectors in the popular GP libraries by a pretty hefty margin. I'm wondering if I overlooked something. It seems odd that with all the manpower behind these other projects. It's this easy to come up with something that outperforms them.</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T22:23:07.990",
"Id": "39462",
"Score": "1",
"body": "It could be that the addition of the succeeding CSS revisions could have made libraries perform more complex parsing and additional filtering. Some libraries also use the native [... | [
{
"body": "<p>My 2 cents,</p>\n\n<ul>\n<li>Well commented</li>\n<li>Naming is never confusing</li>\n<li>Quite readable</li>\n</ul>\n\n<p>for my edification\n* why <code>[eval][0]('this')</code> instead of <code>eval('this')</code>, to trick lint?</p>\n\n<p>As far as I can tell, your library is fast because you ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T21:48:06.107",
"Id": "25452",
"Score": "8",
"Tags": [
"javascript",
"performance",
"dom",
"query-selector"
],
"Title": "Very fast query selector"
} | 25452 |
<p>I have either created something beautiful or something monstrous, and I'm not really sure which, and I don't know where else to turn but here. What I've done:</p>
<pre><code>var MyObject = function(opts) {
//init code, set vals, runs when 'new MyObject()' is called
}
MyObject.prototype = (function() {
//p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T22:37:31.810",
"Id": "39466",
"Score": "1",
"body": "`publicFunc3` can't see `myPrivateFunction`... sort of smells. And of course privates don't have a `this`, which sort of defeats OO design. Why not just wrap the whole thing in a ... | [
{
"body": "<p>The commenters pretty much said it all:</p>\n\n<ul>\n<li><code>publicFunc3</code> can't see <code>myPrivateFunction</code> <- not good</li>\n<li><p>I would declare <code>function() { /* uses myPrivateFunction() */ }</code> as a private function and then just return a pointer to it:</p>\n\n<pre>... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T22:07:48.617",
"Id": "25454",
"Score": "5",
"Tags": [
"javascript",
"design-patterns"
],
"Title": "Possibly mixing prototype and module pattern"
} | 25454 |
<p>This works as intended, but was wondering if there is a more efficient way of coding this.</p>
<pre><code>if (window.location.href.indexOf('/search/') >= 0) {
switch ($.cookie("Layout")) {
case "Poster":
$("link:first").attr("href", "../css/list.css");
break;
case "Des... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T23:16:58.560",
"Id": "39473",
"Score": "0",
"body": "well i guess both, but i wouldn't want to compromise execution time so that it looks nicer."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T23:18:1... | [
{
"body": "<p>This seems a bit simpler (<em>in terms of code repeating</em>)</p>\n\n<pre><code>var Layout = {\n 'Poster': {\n href: 'css/list.css'\n },\n 'Description': {\n href: 'css/desc.css'\n }\n};\n\nfunction setLink(file, pathFix) {\n $('link:first').attr('href', pathFix +... | {
"AcceptedAnswerId": "25456",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T23:03:45.190",
"Id": "25455",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Movie search layout tweaks with cookie persistence"
} | 25455 |
<p>I am trying to create a treenode structure based on a database table for a Dungeons and Dragons character creation program I am working on. I have come up with an incredibly confusing way to do it, but I am wondering if anyone can give me some better ideas on how to do this more efficiently. I have a tables called... | [] | [
{
"body": "<p>I like the use of white space and indentation, makes the code easy to read.</p>\n\n<p>I would start using <code>var</code> for your variable declarations. It keeps the code cleaner, and easier for your eyes to scan.</p>\n\n<p>Remove the <code>// Do Nothing</code> if statements. It is redundant a... | {
"AcceptedAnswerId": "25462",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T01:32:44.330",
"Id": "25459",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Dynamic Treenode Creation"
} | 25459 |
<p>I need somebody to review and polish my GUI code for my very very simple chat client. I haven't built any of the server sockets, so I'll do that later, but for now I just want people to tell me how crap my code is and how I can make it better. I'll post the full code below, but keep in mind that it is built to be as... | [] | [
{
"body": "<p>Your code was mostly good. Starting from the top of the program and working down, I'll list my changes.</p>\n<ul>\n<li><p>I added a global string with the application name, since you used it in more than one place. Now, you only have one string to change when you want to change the version numbe... | {
"AcceptedAnswerId": "25500",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T01:45:33.963",
"Id": "25461",
"Score": "1",
"Tags": [
"java",
"swing",
"gui"
],
"Title": "Simple chat room Swing GUI"
} | 25461 |
<p>Let's say I have a key 'messages' that is usually a list, but might be None, or might not be present. So these are all valid inputs:</p>
<pre><code>{
'date': 'tuesday',
'messages': None,
}
{
'date': 'tuesday',
'messages': ['a', 'b'],
}
{
'date': 'tuesday',
}
</code></pre>
<p>If I want to retrieve ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T08:32:02.767",
"Id": "39495",
"Score": "1",
"body": "Consider using a `collections.defaultdict`."
}
] | [
{
"body": "<p>You have to check for the existence of 'messages' AND the content of 'messages'. It's the same thing you have, but I would write it as:</p>\n\n<pre><code>if 'messages' in d and d['messages'] is not None:\n for m in d['messages']:\n do_something(m)\n</code></pre>\n",
"comments": [],
... | {
"AcceptedAnswerId": "25470",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T02:54:02.610",
"Id": "25465",
"Score": "15",
"Tags": [
"python",
"hash-map"
],
"Title": "Set a default if key not in a dictionary, *or* value is None"
} | 25465 |
<p>I have the library that I have found to be very useful when creating dynamic content rich web applications. I call it DO.js. It allows me to create entire DOM structures inside of Javascript in a similar manner that HTML markup should look. Additionally, it does it all without writing any HTML strings. It uses a hie... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T09:25:41.210",
"Id": "39500",
"Score": "0",
"body": "Please include the code in your question, we shouldn't have to follow five different links to see it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-... | [
{
"body": "<p>A more typical approach these days, if you <em>have to</em> create a lot of DOM objects in javascript, is to use a templating system, such as <a href=\"http://mustache.github.io/\" rel=\"nofollow\">Mustache</a> (see also <a href=\"http://icanhazjs.com/\" rel=\"nofollow\">iCanHazjs</a>), and thus t... | {
"AcceptedAnswerId": "25561",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T19:37:21.900",
"Id": "25475",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "DO.dom: Creating large DOM structures in Javascript"
} | 25475 |
<p>I have a multi dimensional array like this:</p>
<pre><code>[0] =>
['batch_id'] => '1'
['some_stuff'] => 'values'
[0] =>
['unit_id'] => '12'
['some_stuff'] => 'values'
[1] =>
['unit_id'] => '41'
['some_stuff'] => 'values'
</code></pre>
<p>T... | [] | [
{
"body": "<p>I suppose the result you want to have is this:</p>\n\n<pre><code> Array\n (\n [1] => Array\n (\n [stuff] => values\n [units] => Array\n (\n [12] => Array\n (\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-24T11:43:07.467",
"Id": "25476",
"Score": "1",
"Tags": [
"php",
"recursion"
],
"Title": "Assign value of nested array as array key"
} | 25476 |
<p>I'm taking a scripting language course with no prior scripting language or Linux experience, though I've taken classes in VB, Java, and C++. Our first assignment is to write a script that will traverse the directory tree of the location the script is run from and rename the files according to some predetermined rule... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-27T11:54:45.537",
"Id": "39597",
"Score": "0",
"body": "Not what you were asking, but be aware of the linux command `rename` ([see here](http://en.wikipedia.org/wiki/Util-linux), or [here for windows](http://gnuwin32.sourceforge.net/pa... | [
{
"body": "<p>It seems correct to me except these lines:</p>\n\n<pre><code>$s1 =~ s/\\.cxx/\\.cpp/g;\n$s1 =~ s/\\.hxx/\\.h/g;\n$s1 =~ s/\\.(cxx|hxx)//g;\n</code></pre>\n\n<p>There're no needs to do the substitution <strong>g</strong> lobal and also you need to anchor the regex at the end:</p>\n\n<pre><code>$s1 ... | {
"AcceptedAnswerId": "25492",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T08:46:46.777",
"Id": "25480",
"Score": "1",
"Tags": [
"file-system",
"perl"
],
"Title": "Perl script to rename files in a directory tree"
} | 25480 |
<p>We had a requirement to remove the port number from the <code>Request.Url.AbsoluteUr</code> <strong>i.e</strong></p>
<p><strong>Actual:</strong></p>
<blockquote>
<p><code>https://mysitename:443/Home/Index</code></p>
</blockquote>
<p><strong>Expected:</strong></p>
<blockquote>
<p><code>https://mysitename/Home... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T11:28:59.540",
"Id": "39511",
"Score": "0",
"body": "What if you have URL like `https://mysitename:443/Home/Index:443`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T12:05:38.643",
"Id": "39515"... | [
{
"body": "<p>Use UriBuilder and set Port to -1</p>\n\n<pre><code>Uri oldUri = new Uri(\"http://myhost:443/Home/Index\");\nUriBuilder builder = new UriBuilder(oldUri);\nbuilder.Port = -1;\nUri newUri = builder.Uri;\n</code></pre>\n\n<p>In case you want to remove the port part only when it is default, e.g. 80 fo... | {
"AcceptedAnswerId": "25486",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T10:58:34.807",
"Id": "25485",
"Score": "9",
"Tags": [
"c#",
"asp.net",
"asp.net-mvc-4",
"url"
],
"Title": "Truncate port number from absolute Uri"
} | 25485 |
<p>I am currently trying to implement a very simple MVC framework as a way of helping me understand how they work. My base controller class has 2 properties, a model and a view. All controllers have a generic view class property however only certain controllers have a model. </p>
<p>I needed a way of obtaining the nam... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T12:29:39.080",
"Id": "39518",
"Score": "0",
"body": "`get_class($this);` But \"that in the constructor I can check to see if a model class exists and instantiate one if so\" makes no sense"
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>Looks fine to me; though somethings to think about. Do you need to run get_class? Or might it be better to have a model variable in the child class</p>\n\n<pre><code>class Blog extends Controller\n{\n private $modelClass = 'Blog';\n}\n</code></pre>\n\n<p>The overhead of get_class might be small... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T12:27:46.553",
"Id": "25488",
"Score": "2",
"Tags": [
"php",
"mvc"
],
"Title": "What is the best way to get the child class name for use in a parent class"
} | 25488 |
A stream is a series of data elements (characters, bytes or complex packets) which can be accessed or made accessible in a serial fashion. Random access is not possible. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T12:31:21.637",
"Id": "25490",
"Score": "0",
"Tags": null,
"Title": null
} | 25490 |
<p>Is there a better way to write the JS for this? I'm asking because I read from somewhere that using <code>.hover</code> isn't recommended. Also, if I move the mouse in and out of the box really fast, the box fades in and out the exact number of times I entered/left the box. How do I prevent this?</p>
<p><a href="ht... | [] | [
{
"body": "<p>This type of functionality is what <a href=\"http://api.jquery.com/hover/\" rel=\"nofollow\"><code>.hover()</code></a> was designed for. I wouldn't recommend using anything else. As far as avoiding building up a queue of events when hovering, jQuery has the <a href=\"http://api.jquery.com/stop/\" ... | {
"AcceptedAnswerId": "25496",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T13:02:45.777",
"Id": "25491",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"html",
"css"
],
"Title": ".hover() for fading effect"
} | 25491 |
<p>I am achieving a hover state per continent through:</p>
<pre><code>var continentId =""
function getID(continentId){
jQuery.each(mapObject.mapData.paths, function(i, val) {
if (val.continent == continentId){
continentCodes[i] = "#3e9d01";
mapObject.series.regions[0].se... | [] | [
{
"body": "<p>You are looking to remove the copy pasted code, to make it more DRY.</p>\n\n<p>Beyond that, it seems that really whether you <code>getID</code> or <code>removeGetID</code>, you set a number of ID's and then update <code>mapObject</code>. Furthermore, it seems that you do not need to update mapObje... | {
"AcceptedAnswerId": "39227",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T14:15:46.523",
"Id": "25493",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Jvector Map add/remove function shorten code"
} | 25493 |
<p>I'm now developing an instant messaging system but I'm a little confused: I can't decide which approach I have to choose!</p>
<p>I want you to tell me what is good/bad with this programming approach. One friend of mine said it's difficult to read, but it works.</p>
<pre><code>/*! | (c) 2012, 2013 by Bellashh*/
/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T16:37:03.590",
"Id": "39530",
"Score": "0",
"body": "Quick question, from a user's (not developer's) point of view: How do we access `Friends`, `People` and `Conferences`? Do we get them through a function or do we access the arrays... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>drop <code>functions</code>, it is too long and it's obvious that <code>alert</code> in <code>ChatProvider.utils.alert()</code> is a function. Furthermore, specifically for <code>alert</code>, that should be under <code>UI</code> in my mind</li>\n<li>Your functio... | {
"AcceptedAnswerId": "42685",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T15:13:47.863",
"Id": "25495",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Instant messaging system"
} | 25495 |
<p>I create this class method to Enter Selected Items Form CheckboxList to associated resource I use ADO.net & store Proc to insert data can someone help me to improve it and make to so clean instead of my Hacks BTW I use Microsoft Enterprise Lib</p>
<pre><code>public static void Insert(List<int> listSkills... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T16:48:13.547",
"Id": "39531",
"Score": "0",
"body": "Any reason why you're not using some ORM?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T17:42:27.067",
"Id": "39535",
"Score": "0",
"... | [
{
"body": "<pre><code>catch (Exception ex)\n{\n throw ex;\n}\n</code></pre>\n\n<p>This code doesn't make any sense. If you want to rethrow an exception, use just <code>throw;</code>, so that the stack trace is not reset. But if that's all you do in your <code>catch</code> block, then there is no reason to us... | {
"AcceptedAnswerId": "25610",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T15:50:38.410",
"Id": "25497",
"Score": "1",
"Tags": [
"c#",
"asp.net"
],
"Title": "Insert Selected item in listbox using Ado.net and stor proc"
} | 25497 |
<p>I have a simple Java model Class called Person which have a constructor that receives a JSONObject. In that constructor I get the values from the JSONObject and put in my instance variables. This is just a simple question but which way is best?</p>
<pre><code>public Person(JSONObject personJsonObject) {
// With... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T17:58:19.950",
"Id": "39569",
"Score": "0",
"body": "This is a lot about your preference.\nWhat did you choose initially?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T18:02:13.267",
"Id": "3957... | [
{
"body": "<p>If you have setter methods (<code>setName</code>, <code>setFullName</code>) in your class, then your constructor should call the setter methods.</p>\n\n<pre><code>setName(personJsonObject.getString(\"name\"));\n</code></pre>\n\n<p>If you don't have setter methods in your class (your class is immut... | {
"AcceptedAnswerId": "25505",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T17:07:55.313",
"Id": "25502",
"Score": "1",
"Tags": [
"java",
"constructor"
],
"Title": "Java constructor should use setter?"
} | 25502 |
<p>This is a function I just wrote that tries to condense a set of strings into grouped lines. It actually works, but looks ugly. Is there a better way to achieve the same thing?</p>
<p><strong>Take 4</strong> <em>filtering empty strings first and dropping the <code>if line</code> on the final <code>yield</code></em><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T06:36:57.987",
"Id": "39557",
"Score": "1",
"body": "In take 3, `if line:` is redundant unless you have empty strings in `strings`. If you do have empty strings, you probably should filter out all of them earlier on."
},
{
"... | [
{
"body": "<p><strong>RECURSIVE SOLUTION:</strong>\n<em>NOTE: it assumes that the input <code>strings</code> is already sorted. You could sort this at every call of the function, but this seems like unnecessary overhead.</em></p>\n\n<pre><code>def recursiveMerge(strings=[], current_line='', line_length=40, resu... | {
"AcceptedAnswerId": "25512",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T20:54:11.293",
"Id": "25508",
"Score": "4",
"Tags": [
"python",
"iteration"
],
"Title": "Python line condenser function"
} | 25508 |
<p>This method allows for the execution of parameterized commands within a DAL class, and I tried to make it as reusable as possible. It works well but it feels a bit verbose to me. Is there a way to simplify this or is it good as is?</p>
<pre><code>/// <summary>
/// Retrieves records from the specified data sou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T21:52:33.347",
"Id": "39546",
"Score": "1",
"body": "Is there a requirement to have to have parameters?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T22:14:26.120",
"Id": "39547",
"Score": "... | [
{
"body": "<p>Why is it static?</p>\n\n<p>First off, I would remove the check for no parameters. You've already checked that it is not null, if somebody passes in an empty list, the <code>foreach</code> for parameters will just be ignored.</p>\n\n<p>As svick said, I would not return a null value if no results ... | {
"AcceptedAnswerId": "25518",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T21:11:03.633",
"Id": "25509",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Proper way to execute parameterized commands within a method"
} | 25509 |
<p>original code example</p>
<pre><code>if (var1 == null) {
String msg = "var 1 is null";
logger.log(msg);
throw new CustomException(msg);
}
if (var2 == null) {
String msg = "var 2 is null";
logger.log(msg);
throw new CustomException(msg);
}
if (var3 == null) {
String msg = "var 3 is null";... | [] | [
{
"body": "<p>The second version removes some duplication, so it's better, but usually you should choose one of logging and rethrowing. Frameworks/appservers usually catch and log uncatched exceptions so you will have two (or more) entries for the same exception it the log file which makes debugging hard.</p>\n... | {
"AcceptedAnswerId": "25522",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T09:56:23.773",
"Id": "25520",
"Score": "1",
"Tags": [
"java",
"logging"
],
"Title": "Encapsulating logging and throwing exceptions into a method. Bad practice?"
} | 25520 |
<p>I have often read about how important clear and efficient code is. Also often people talk and write about 'beautiful' code. Some hints and critic from experienced developers for the following code would be extremely helpful to me. Another question that I often ask myself is about list comprehensions: I feel that in ... | [] | [
{
"body": "<ul>\n<li>The list comprehension <code>[x for x in range(0,1001)]</code> is redundant, as <code>range</code> already returns a list in Python 2. In Python 3 one can use <code>list(range(1001))</code></li>\n<li>Write a <a href=\"http://www.python.org/dev/peps/pep-0257/\" rel=\"noreferrer\">docstring</... | {
"AcceptedAnswerId": "25537",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T10:18:21.683",
"Id": "25521",
"Score": "5",
"Tags": [
"python",
"primes",
"palindrome"
],
"Title": "Calculating all prime palindromes from 0 to 1000 and printing the largest"
} | 25521 |
<p>I have a class which is responsible for waiting until a message is added to a message list and then sending it off to get processed.</p>
<ul>
<li><code>withdrawMessages</code> waits for a message. I wait for a total of 2 minutes for a message to appear. I do this to keep the connection alive on my browser.</li>
<li... | [] | [
{
"body": "<ol>\n<li><p>It looks like you only have one lock, so you can't have deadlock; but for future reference, you can add deadlock detection to the program, see for example <a href=\"http://meteatamel.wordpress.com/2012/03/21/deadlock-detection-in-java/\" rel=\"nofollow\">this blog post</a> but there are ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-25T22:24:12.793",
"Id": "25523",
"Score": "1",
"Tags": [
"java",
"multithreading",
"thread-safety"
],
"Title": "Sending messages for processing"
} | 25523 |
<p>I usually find the .js files to be quite messy and the truth is that mine are even worse than the average as, being soft, I'm not the sharpest tool neither at jQuery nor JavaScript.</p>
<p>I would really appreciate if someone could give me a heads up about improving the readability (and point me bad practices) of t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T12:13:04.320",
"Id": "39566",
"Score": "1",
"body": "How do you organize your code in other languages? Don't you put the code in semantically named files?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-... | [
{
"body": "<p>As Dagg said in his comment, try to cache things as much as possible - I haven't tested this code but you could do something like this:</p>\n\n<pre><code>(function ($, window) {\n // Do stuff when the DOM is ready.\n $(function () {\n\n $('form').on(\"click\", \"div.toggler\", functio... | {
"AcceptedAnswerId": "25535",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T11:43:26.750",
"Id": "25526",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "JQuery code to toggle an edit form"
} | 25526 |
<p>I'm trying to update my website's code to HTML5's semantic and structural elements, but I'm not very sure with the <code>section</code>s and <code>article</code> element.</p>
<p>Here's the structure of my page:</p>
<pre><code><body>
<header id="heaven" style="background-image: url(" ./images/header/2.... | [] | [
{
"body": "<p>When in doubt about which element to use, always refer to the spec. It will tell you exactly where and when it is appropriate to each element(s).</p>\n\n<p>For a section here's is what the MDN spec has to say:</p>\n\n<blockquote>\n <p>The HTML Section Element (<code><section></code>) repres... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T13:42:06.863",
"Id": "25528",
"Score": "2",
"Tags": [
"html",
"html5"
],
"Title": "Update HTML4 to new HTML5 Semantic/Structural Elements"
} | 25528 |
<p>I have a list in Prolog like this: </p>
<pre><code>Puzzle = [ A1, A2, A3,
B1, B2, B3,
C1, C2, C3 ].
</code></pre>
<p>And I want every variable in the list to be a number in the range of 1 to 9.
Currently I'm doing this like so:</p>
<pre><code>between(1,9, A1),
between(1,9, A2),
% ...
betwee... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T14:35:30.167",
"Id": "39579",
"Score": "0",
"body": "Before moving on, I would strongly advise you to actually try to learn the language. What you are asking here is _very_ basic and fundamental to using the language."
}
] | [
{
"body": "<p>Once you will have to hardcode your list to include all the variables from A1 to I9. Then you can iterate through it:</p>\n\n<pre><code>foreach(X, Your_list) do between(1, 9, X).\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA ... | {
"AcceptedAnswerId": "25531",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T14:21:01.743",
"Id": "25529",
"Score": "1",
"Tags": [
"prolog"
],
"Title": "Range of all variables in List in Prolog"
} | 25529 |
<p>I would like to hear your feedback on the link below that lets users add a link to a website. I read that <code>javascript:void(0)</code> is <a href="https://stackoverflow.com/questions/134845/href-attribute-for-javascript-links-or-javascriptvoid0">suggested</a> instead of a <code>#</code> for the <code><a href="... | [] | [
{
"body": "<p>First of all, <a href=\"https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/void\" rel=\"nofollow\">void</a> is an operator, not a function. The parentheses are extraneous; it should be written as <code>void 0</code>.</p>\n\n<p><code>href=\"#\"</code> should be avoided for the ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T17:31:16.993",
"Id": "25540",
"Score": "1",
"Tags": [
"javascript",
"html"
],
"Title": "Submitting the current webpage to a bookmarking site"
} | 25540 |
<p>I am trying to code <a href="http://en.wikipedia.org/wiki/Battleship_%28game%29" rel="nofollow">Battleship</a>. It should be a text one-player game against computer where computer and human player take turns in shooting at opponent's ships. I decided to start implementation with this part: <em>A human types target c... | [] | [
{
"body": "<p>Perhaps <code>GamePlan</code> would better be named eg. <code>Board</code>? English is not my mother tongue, but AFAIK game plan == strategy.</p>\n\n<p>1,3,4: The ships are static, they just occupy some space on the board. However, a ship object would be aware which squares belong to the ship, and... | {
"AcceptedAnswerId": "25547",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T18:28:20.937",
"Id": "25541",
"Score": "6",
"Tags": [
"python",
"battleship"
],
"Title": "Designing a simple Battleship game in Python"
} | 25541 |
<p>Please help make this code more cleaner. It's a part of window procedure that notifies my renderer <em>before</em> client area of window resized.</p>
<p>I need to check two combinations of bit blags: some of them must be set, and some must be not. How to do it without bunch of temp variables? (and probably calculat... | [] | [
{
"body": "<p>You first need to select the bits in the flag you want to test by ANDing them with a mask containing all the bits. </p>\n\n<p>This will zero all the bits that aren't being tested.</p>\n\n<p>You then just need to check the value of the bits you want so the masks and values are:</p>\n\n<pre><code>co... | {
"AcceptedAnswerId": "25552",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T18:55:35.930",
"Id": "25543",
"Score": "2",
"Tags": [
"c++",
"bitwise"
],
"Title": "Simplify bit flags checking code"
} | 25543 |
<p>I want to retrieve id and name per skill. It works but is it well done? I would like to stay with minidom but all advices will be appreciated.</p>
<pre><code># This is only part of XML that interesting me:
# <skill>
# <id>14</id>
# <skill>
# <name>C++</name>
# </skil... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T21:27:55.170",
"Id": "39591",
"Score": "0",
"body": "Your xml doesn't seem to match your code (and is also not well formed)."
}
] | [
{
"body": "<p>This is probably as good as you can get with minidom.</p>\n<p>However, consider ditching minidom--it's really only there when you <em>absolutely, postively</em> need some kind of DOM api and only have the standard library. Note the <a href=\"http://docs.python.org/2/library/xml.dom.minidom.html\" ... | {
"AcceptedAnswerId": "25553",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T18:59:07.863",
"Id": "25544",
"Score": "2",
"Tags": [
"python",
"xml"
],
"Title": "Parsing XML with double nested tags using mindom"
} | 25544 |
<p>This is a basic sorting function written in jQuery that moves items in the DOM around to create empty spaces for a droppable(). Since there is so much going on in a droppable over event, i'd love some feedback on how this could be done better. </p>
<p><strong>This is all in a function called on the over event of th... | [] | [
{
"body": "<p>Here you have some general thoughts:</p>\n\n<ol>\n<li><p>First of all, cache jQuery elements (<code>var $this = $(this);</code> instead of multiple executions of <code>$(this)</code>). <a href=\"http://jsfiddle.net/tomalec/pXPdS/1/\" rel=\"nofollow\">http://jsfiddle.net/tomalec/pXPdS/1/</a></p></l... | {
"AcceptedAnswerId": "25625",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T19:30:35.857",
"Id": "25546",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"jquery-ui"
],
"Title": "Jquery sortable style function"
} | 25546 |
<p>This is the first time I've written a class in Java to do encryption using AES. Since security is involved I would love it if someone could take a look at it and let me know if anything is wrong with my implementation. Additionally, any feedback about shortcuts I could have taken or sloppy processes I've used would ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-27T15:36:24.350",
"Id": "39603",
"Score": "0",
"body": "My first suggestion is to make refactor a little bit your constructor. Start by making a Method `getCipherInstance()` put your try catches in that method. Then make another method... | [
{
"body": "<p>Here's my final implementation with the changes based on @Robert Snyder's comment:</p>\n\n<blockquote>\n <p>My first suggestion is to make refactor a little bit your constructor.\n Start by making a Method <code>getCipherInstance()</code> put your try catches in\n that method. Then make another... | {
"AcceptedAnswerId": "36640",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T20:02:35.310",
"Id": "25548",
"Score": "10",
"Tags": [
"java",
"cryptography"
],
"Title": "AES-128 encryption class"
} | 25548 |
<p>The code checks many more conditions like the one below. I was thinking to memoize it, but I can't think about how (writers block). How else could I optimize this? I know it seems silly, but my code is spending the majority of the time in the function.</p>
<pre><code>def has_three(p, board):
"""Checks if player... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T21:13:37.580",
"Id": "39589",
"Score": "4",
"body": "Can you post the entire function and some input and expected output? Also, what the function is supposed to do?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | [
{
"body": "<p>We really need to know more about the game to help you properly. Also, why is your program spending so much time in this function? (Are you doing some kind of lookahead, with this function being part of the evaluation?)</p>\n\n<p>If this is a game like <a href=\"http://en.wikipedia.org/wiki/Gomoku... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T21:10:59.193",
"Id": "25550",
"Score": "2",
"Tags": [
"python",
"performance"
],
"Title": "Checking a board to see if a player has three in a row"
} | 25550 |
<p>I recently made <a href="http://ucsd.edu/timeline/" rel="nofollow noreferrer">this campus timeline</a> for my university. When viewing the timeline on a mobile device (not a tablet), the navbar changes so that you can jump to the previous or next decade by clicking one of the arrows.</p>
<p>I'm concerned about the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-07-29T23:11:53.877",
"Id": "180596",
"Score": "0",
"body": "Randomly stumbled across this very old question of mine and now I can tell the past version of me and anyone else reading that jQuery's animate is extraordinarily inefficient and... | [
{
"body": "<pre><code>//html and body don't change in the lifetime of the page, no sense fetching them everytime\n//thus we move it out of the handler into a static scope\nvar html_body = $('html,body');\n\n//Use the context parameter and keep your code short. It acts like `find`.\n//I suggest you delegate at a... | {
"AcceptedAnswerId": "25571",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-26T23:07:54.077",
"Id": "25555",
"Score": "2",
"Tags": [
"javascript",
"performance",
"jquery",
"html",
"animation"
],
"Title": "Timeline animations"
} | 25555 |
<p>I'm putting together a little application and it requires about 6 <code>if</code> statements to verify actions, here's the code I'm using:</p>
<pre><code>if($player[0]['value'] == $server->clean_attr($row['attr1'])) {
if($player[1]['value'] == $server->clean_attr($row['attr2'])) {
if($player[2]['v... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T20:22:31.320",
"Id": "39640",
"Score": "0",
"body": "I'd change your attr names if you can for readability"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-09-26T21:28:04.593",
"Id": "193730",
"Score... | [
{
"body": "<p>You could separate the array checks and the conditional: create a walker and store the result of a failed comparison in a separate container. Then check just that stored value:</p>\n\n<h3>Walker</h3>\n\n<pre><code>function walk_players( &$player, $key, $context )\n{\n $server = $context['... | {
"AcceptedAnswerId": "25558",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-27T05:40:47.910",
"Id": "25556",
"Score": "-4",
"Tags": [
"php"
],
"Title": "Too much nesting"
} | 25556 |
<p>I have the following C++ program:</p>
<pre><code>#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
void printVector (std::vector<int>& vec)
{
for (int a = 0; a < vec.size(); a++)
std::cout << (char)vec[a] << ", ";
}
int main ()
{... | [] | [
{
"body": "<p>I'm by far no expert, and I might be wrong on some of my statements, so take them as a basis for discussion. Anyway, I am trying to learn about code quality in C++ myself, so I'm giving it a shot.</p>\n\n<ol>\n<li><code>printVector</code> should take the argument as const-ref, because the vector i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-27T12:12:16.360",
"Id": "25562",
"Score": "5",
"Tags": [
"c++",
"optimization",
"game",
"hangman"
],
"Title": "Code Review for Hangman in C++"
} | 25562 |
<p>In MS excel, a date is also represented as a numeric value, with 1-Jan-1900 as the first day. Also in VBA there are dateAdd and dateDiff functions. dateAdd adds a given unit (day, month quarter or a year) to a date. dateDiff returs the difference between the numeric values of two dates. I have written a scheme code ... | [] | [
{
"body": "<p>I don’t have many or deep comments, but since there aren’t any answers yet, here are mine, for what they’re worth.</p>\n\n<p>You have a lot of chains of calls to car and cdr. I would tend to use the c*r shortcuts instead. And when possible, I’d use first, second, third, etc. instead. e.g. Instead ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-27T17:29:42.383",
"Id": "25566",
"Score": "0",
"Tags": [
"scheme",
"datetime"
],
"Title": "Numeric Value for a Date, dateAdd and dateDiff"
} | 25566 |
<p>I've been working in PHP since almost three years ago. In this time I built a framework as base for my projects.</p>
<p>I want it to be improved, and which other best option there are that use StackExchange?, so I decided to post this here.</p>
<p>The framework is hosted in GitHub:
<a href="https://github.com/CPed... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-27T20:50:50.667",
"Id": "39610",
"Score": "0",
"body": "Sorry, but a whole library is too much for us to review. Per the [FAQ], you need to include the code you want reviewed in your question (not just link to it). And it should be a r... | [
{
"body": "<p>Instead of this block:</p>\n\n<pre><code>foreach ($a as $key => $value) {\n if($value == ''){\n unset($a[$key]);\n }\n}\n</code></pre>\n\n<p>You could simply use <a href=\"http://fr2.php.net/array_filter\" rel=\"nofollow\"><code>array_filter()</code></a> without the second paramete... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-27T18:15:01.800",
"Id": "25567",
"Score": "2",
"Tags": [
"php",
"mvc"
],
"Title": "Delos MVC PHP Framework"
} | 25567 |
<p>This application is a "Student Registration System" using JDBC with Oracle as part of our school project. It works as it stands right now.</p>
<p>Questions:</p>
<ol>
<li>What is a better way to structure the project? Why?</li>
<li>Any 'crimes' committed in the code?</li>
</ol>
<p>Details:</p>
<ul>
<li>I've decid... | [] | [
{
"body": "<p>The first 'crime' is a <a href=\"http://en.wikipedia.org/wiki/SQL_injection\" rel=\"nofollow\">SQL injection</a> vulnerability. You are using a <code>PreparedStatement</code> when inserting, which is great. You avoided the problem there. But this is a problem:</p>\n\n<pre><code>String query = \"SE... | {
"AcceptedAnswerId": "25597",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-27T23:24:03.510",
"Id": "25572",
"Score": "4",
"Tags": [
"java",
"jdbc"
],
"Title": "Student Registration System"
} | 25572 |
<p>I wanted to wrap the <a href="https://github.com/tulskiy/jkeymaster" rel="nofollow">jkeymaster</a> library in a Clojure wrapper (for my own use, but perhaps also to save others some time). I'm just learning Clojure so I'm still not quite sure what "idiomatic libraries/APIs" look like. In Ruby, I would have created a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T02:13:43.513",
"Id": "39701",
"Score": "0",
"body": "I rewrote slightly to have provider instead return a (partial register provider), which the user can then use to register a new key directly, thus exposing only one function to th... | [
{
"body": "<p>As a wrapper goes I think this looks fine. The feedback I do have is that I wouldn't use <code>let</code> as often as you do and would use the <a href=\"https://clojuredocs.org/clojure.core/-%3E\" rel=\"nofollow\">treading macro</a> <code>(-> ...)</code> instead. </p>\n\n<p>For example:</p>\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T01:27:16.537",
"Id": "25575",
"Score": "4",
"Tags": [
"clojure"
],
"Title": "API wrapper for Clojure"
} | 25575 |
<p>I am working on a program in which 10000 random non-repeating numbers are selectively sorted into ascending order"</p>
<pre><code>import java.util.Random;
public class Sorting {
public static void main (String[] args){
//Here, we initiate an array with the integers
//1 through 10,000 in order.... | [] | [
{
"body": "<p>I tested it and it works as it should. I would only like to remark a couple of things. </p>\n\n<p>You may want to split your long commented function into shorter ones:</p>\n\n<ul>\n<li><p><code>static int[] InitArray(int length){...}</code></p></li>\n<li><p><code>static int[] SelectionSort(int[]ar... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-04-28T02:01:58.780",
"Id": "25576",
"Score": "6",
"Tags": [
"java",
"sorting",
"random"
],
"Title": "Sorting random non-repeating numbers"
} | 25576 |
<p>I have not completed this but want to make my own template library for wrapping the Win32 API to make it compatible with std::string/std::wstring... Here's a sample of what I've worked with so far. </p>
<p>My questions are:</p>
<ol>
<li>Is this a good idea? </li>
<li>Is it acceptable to undefine Windows API macros... | [] | [
{
"body": "<blockquote>\n<p>I have not completed this but want to make my own template library for wrapping the Win32 API to make it compatible with std::string/std::wstring...</p>\n<p>Is this a good idea?</p>\n</blockquote>\n<p>If you have the time to do that as an exercise, probably (there should be <em>a lot... | {
"AcceptedAnswerId": "25618",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T04:40:09.853",
"Id": "25581",
"Score": "3",
"Tags": [
"c++",
"template",
"windows",
"winapi"
],
"Title": "std::string/std::wstring template wrapper for Win32 API"
} | 25581 |
<p>I'm a bit confused if saving the information to session code below, belongs in the controller action as shown below or should it be part of my Model? </p>
<p>I would add that I have other controller methods that will read this session value later.</p>
<pre><code>public ActionResult AddFriend(FriendsContext viewMod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T08:47:53.373",
"Id": "39624",
"Score": "1",
"body": "Why are you asking this twice? http://stackoverflow.com/questions/16260442/mvc-does-putting-data-in-cache-or-session-belong-in-controller"
}
] | [
{
"body": "<h2>Yes</h2>\n\n<p>Yes it belong s to the controller. If you are interacting with HTTP... stuff then you should do it in your MVC tier in your N-tier application stack. If you would put this thing in the model then it would be in your business logic and then you would have a hard dependency on the Ht... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T08:21:10.257",
"Id": "25583",
"Score": "1",
"Tags": [
"c#",
"asp.net-mvc",
"session"
],
"Title": "Saving data to a session"
} | 25583 |
<p>How would you write this jQuery code cleaner and better? I'm a beginner.</p>
<pre><code>$.extend({
misTip : function($tipSettings) {
$tip = $tipSettings.tip ? $tipSettings.tip : '';
$closeTime = $tipSettings.closeTime ? $tipSettings.closeTime : 1500;
$refresh = $tipSettings.refresh;
delete $tipSett... | [] | [
{
"body": "<p>You are using several global variables in the code, which should be local.</p>\n\n<p>You are prefixing variable names with <code>$</code> for no apparent reason, that only makes the code harder to read.</p>\n\n<p>You can use the <code>||</code> operator instead of the conditional operator to check... | {
"AcceptedAnswerId": "25590",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T09:14:43.780",
"Id": "25585",
"Score": "-1",
"Tags": [
"javascript",
"beginner",
"jquery-ui"
],
"Title": "Tip dialog jQuery plugin"
} | 25585 |
<p>The function <code>func(int m,int n)</code> outputs (for m = 3, n = 5):</p>
<pre><code>3
34
345
34
3
</code></pre>
<p>I came up with this code:</p>
<pre><code>void func(int m,int n)
{
for(int i=1;i<n-m+2;i++)
{ int k=i;
int j=m;
while(k>0)
{
System.out.print(j);
k--;j++;
}
Syst... | [] | [
{
"body": "<p>You can do it recursively:</p>\n\n<pre><code>void func(int m,int n) {\n if (m == n) {\n System.out.println(m);\n } else {\n func(m, n - 1);\n for (int i = m; i <= n; i++) {\n System.out.print(i);\n }\n System.out.println(\"\");\n func(m, n - 1);\n }\n}\n</code></pre>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T09:50:56.760",
"Id": "25587",
"Score": "3",
"Tags": [
"java",
"performance",
"formatting"
],
"Title": "Number pyramid in Java"
} | 25587 |
<p>I've been teaching myself Ruby this weekend. First of all, I am aware that there is a built-in sort function. I've written this code strictly as an exercise.</p>
<p>I have background primarily in C# and Javascript, so this is a change of pace for me.</p>
<p>If you are a seasoned professional with a lot of Ruby e... | [] | [
{
"body": "<p>Here's my two cents on this.</p>\n\n<ul>\n<li><p>For starters, swapping two elements can be expressed in ruby this way :</p>\n\n<pre><code>a, b = b, a\n</code></pre></li>\n<li><p>Instead of : </p>\n\n<pre><code>a = []\ni = 0\nuntil i === 1000\n a.push(i)\n i += 1\nend \n</code></pre>\n\n<p>use a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T20:10:08.603",
"Id": "25596",
"Score": "1",
"Tags": [
"ruby",
"sorting",
"quick-sort"
],
"Title": "Quicksort in Ruby!"
} | 25596 |
<p>This is a simple packet sniffer that turns on LEDs when there's network activity. It works by picking up filters in a configuration file and listen for activity in those filters. When there's a captured packet, it sets a bit in a bit-mask that corresponds to the filter index in the config file. Then, once all the fi... | [] | [
{
"body": "<p>Your code looks nice and compiles cleanly (once I filled in the blanks). I\nhave a few comments, the main one being your lack of functions. Putting\neverything in main is not practicable beyond a certain size and you have\nexceeded that size. Various functions should be extracted from main,\nin... | {
"AcceptedAnswerId": "25614",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-28T21:22:41.263",
"Id": "25600",
"Score": "3",
"Tags": [
"c",
"linux",
"networking"
],
"Title": "lightweight packet sniffer review"
} | 25600 |
<p>I'd like anyone here to help me clean up my code. It's about calculating men's risk of getting coronary heart disease. <a href="https://gist.github.com/akosijiji/57d0da84b24ea9f6dd0e" rel="nofollow">Here's the link to my method</a>.</p>
<pre><code>private void calculateForMen(){
// TODO
// For Men
// 20–34 year... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T11:39:46.937",
"Id": "39657",
"Score": "0",
"body": "Longest single method EVER! So first thing you need to look up is how to use methods / refactor. Second your indention levels are a bit out of sync. That is first glance. I'll edi... | [
{
"body": "<p>So I'm not going to show you what a interface is (since I am at work) but I can show you a small blurb of what i'm talking about. Note that the number I put into this are not meant to be accurate, they are just to get you started.</p>\n\n<pre><code>interface Patient\n{\n int getAgePoints();\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T11:05:03.743",
"Id": "25611",
"Score": "2",
"Tags": [
"java",
"beginner",
"android"
],
"Title": "Calculating men's risk of getting coronary heart disease"
} | 25611 |
<p>I am working with an application that will have sub forms. The primary form opens above the system tray, and on mouse-over, secondary windows will open right next to the primary. When I use the <code>Me.location = New Point ()</code> and then assign the point, it works great… until I change PC's and the user has a d... | [] | [
{
"body": "<p>Why don't you simply subtract the width and height of your form from the value obtained by the Screen class?</p>\n\n<pre><code>Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width\nDim intY As Integer = Screen.PrimaryScreen.Bounds.Height\n\nSecondForm.Location = new Point(intX - SecondForm.Widt... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-27T23:59:57.730",
"Id": "25612",
"Score": "2",
"Tags": [
"vb.net"
],
"Title": "Screen resolution"
} | 25612 |
<p>Is there a way of writing this correctly working query more efficiently? I'm asking only to learn LINQ better:</p>
<pre><code> var cpuInfo = edgeLPs
.GroupBy(k => k.CPU.ID, e => e.CPU)
.ToDictionary(k => k.Key, v => new
{
LogicalProcs = v.First().LogicalProcessorsC... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T14:38:34.797",
"Id": "39672",
"Score": "0",
"body": "What is the type of `edgeLPs`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T16:06:42.263",
"Id": "39674",
"Score": "0",
"body": "It'... | [
{
"body": "<p>First, the usual disclaimer about performance: most of the time, you shouldn't worry much about it. If you find that your code is too slow, you should measure to find out which part is causing the slowdown and improve that. Trying to make code that's not performance critical more efficient is ofte... | {
"AcceptedAnswerId": "25639",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T13:32:15.263",
"Id": "25615",
"Score": "5",
"Tags": [
"c#",
"linq"
],
"Title": "LINQ Group query - simplifying"
} | 25615 |
<p>As the question states: have I missed some obvious security vulnerabilities in this code? Particularly interested in XSS...</p>
<p>I'm trying to create something more robust that <a href="http://php.net/manual/en/function.strip-tags.php" rel="nofollow">strip_tags</a>, but simpler than <a href="http://htmlpurifier.o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T16:10:47.727",
"Id": "39676",
"Score": "2",
"body": "Are you attempting to allow users to input a limited subset of tags? if not, the best solution is to throw out everything you've written for sanitizing input, and just make sure t... | [
{
"body": "<p>It would help if you explained exactly why you think this approach is more robust than using strip_tags. It will certainly be likely to be a lot slower.</p>\n\n<p>From a quick inspection it doesn't seem to filter CSS behaviours nor data URIs.</p>\n\n<p>If it were me I'd be building on to strip_tag... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T15:11:42.537",
"Id": "25620",
"Score": "3",
"Tags": [
"php",
"html",
"parsing"
],
"Title": "Have I missed some obvious XSS vulnerabilities?"
} | 25620 |
<p>Say I have a code snippet like this </p>
<pre><code> if(string.Compare(isStandardFlag,"STANDARD",true)==0)
{
hearingID = centreSession.standardID;
centreSession.standardOutcomeID
= disciplineSvc.SaveResultA(hearingID,OffenceID, Outcome);
centreSession.standardOutcomeNoteI... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T16:35:17.417",
"Id": "39680",
"Score": "0",
"body": "What is the reason that you need to save the results in different properties?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T16:40:27.530",
"I... | [
{
"body": "<p>First, it looks like the <code>ID</code>, <code>OutcomeID</code> and <code>OutcomeNoteID</code> belong together, so I think it it makes sense to extract them into a separate class (though my naming of it is just a guess):</p>\n\n<pre><code>class Hearing\n{\n public int ID { get; private set; }\... | {
"AcceptedAnswerId": "25623",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T15:38:08.467",
"Id": "25621",
"Score": "1",
"Tags": [
"c#",
"design-patterns"
],
"Title": "It there a pattern used to process a same function but assign the result to a different v... | 25621 |
<p>I have two pieces of they which do almost the same thing. They both return the most common base class of two types. They differ in two aspect:</p>
<ol>
<li>If one of the arguments is <code>null</code>, code A returns <code>null</code> and code B returns <code>object</code>.</li>
<li>If one of the arguments is an in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T20:15:57.370",
"Id": "39692",
"Score": "0",
"body": "I definitely find the first option more readable"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T20:36:12.030",
"Id": "39693",
"Score": "1"... | [
{
"body": "<p>Which is more readable is quite a subjective question, however if you ask me I choose the first option. There's however something that bothers me more. You should never allow a potential exception to propagate in your code (this is returning null, you'll find yourself asking again if x is null, an... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T18:07:28.170",
"Id": "25628",
"Score": "3",
"Tags": [
"c#",
"functional-programming"
],
"Title": "GetCommonBaseClass: Readabiliy and Functionality"
} | 25628 |
<p>i need to create a cache class to avoid making the same calculations more than needed. My idea was something really basic like</p>
<pre><code>class transient_cache {
static private $cache = array();
static public function get_value( array $obj, $key ) {
// $obj is an array( $object, $method )
... | [] | [
{
"body": "<p>I would say that there isn't a correct or incorrect way of achieving this. Everyones requirements differ.</p>\n\n<p>You probably want to expand this out, there's a lot going on in the one static method you have in that class. Whilst I don't have anything against mediator patterns, I would probably... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T18:54:08.517",
"Id": "25630",
"Score": "2",
"Tags": [
"php",
"design-patterns",
"cache"
],
"Title": "How to create a simple stateless cache class in PHP"
} | 25630 |
<p>I am new to Ruby and would like some help with re-factoring my code.</p>
<pre><code>class Beam
def initialize
puts "Please specify span of beam"
@span = gets.chomp.to_f
puts "How many number of point loads do you want?"
@pointLoadNos = gets.chomp.to_i
@pointLoad = Array.new(@pointLoadNos)
@... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T21:53:55.850",
"Id": "39694",
"Score": "3",
"body": "For future reference, please give some background/context on what your code's supposed to accomplish. Yes, we can glean it from reading the code, but a simple \"This class models ... | [
{
"body": "<p>I would write something like:</p>\n\n<pre><code>class Beam\n def prompt msg\n # a bit kung-fu, sorry\n puts msg while gets.strip!.empty?\n yield $_\n end\n def initialize \n @span = prompt \"Please specify span of beam\", &:to_f\n @pointLoadNos = pro... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-29T19:44:07.897",
"Id": "25633",
"Score": "1",
"Tags": [
"beginner",
"ruby",
"physics"
],
"Title": "Calculating reactions to load on a beam"
} | 25633 |
<p>So for practice with Javascript, I wrote this lightweight widget factory which is similar in functionality (okay, that's a bit of a stretch) to jQuery's UI Widget factory. I was hoping I could get some pointers as far as idiom usage and also if there are any glaring problems with the below code. </p>
<pre><code>var... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T08:15:31.963",
"Id": "39712",
"Score": "0",
"body": "You're missing the `var` keyword in several places."
}
] | [
{
"body": "<ul>\n<li><p>Although DOM elements can be used like normal JavaScript objects, I'd avoid attaching JavaScript other than handlers. The problem is when they form <a href=\"https://stackoverflow.com/q/1493453/575527\">circular references</a>. In browser garbage collectors, they won't collect garbage if... | {
"AcceptedAnswerId": "25641",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T03:09:33.770",
"Id": "25640",
"Score": "0",
"Tags": [
"javascript",
"jquery-ui"
],
"Title": "Roll your own widget factory"
} | 25640 |
<p>I chanced upon this code written by the Solution Architect for an MS CRM project and I am lost for words. Am I going crazy or is this code OK?</p>
<pre><code>string returnedOptionSetStringValue=string.Empty;
int returnedInt = 0;
Utils.RetrieveOptionSetLabelOrValue(CRMAccess.xrmService, Contact.EntityLogicalName, "... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T09:57:36.987",
"Id": "39713",
"Score": "0",
"body": "I wouldn't say it's bad practice or bad code exactly - it's just not idiomatic for C#. This kind of code would be very familiar for someone who came from a C++/COM/Win32 backgroun... | [
{
"body": "<p>This is done when you want to catch any modifications inside the method you'r calling. </p>\n\n<p>returnedInt is a value type, so he pass it as a <a href=\"http://msdn.microsoft.com/en-us/library/14akc2c7.aspx\" rel=\"nofollow\">ref</a>erence to ensure the above.\nreturnedOptionSetStringValue is a... | {
"AcceptedAnswerId": "25675",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T07:10:13.777",
"Id": "25644",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Using ref for value types"
} | 25644 |
<p>I want to efficiently (few intermediate objects) and neatly (few lines and easy to read) filter an array, removing <em>and returning</em> rejected items. So like a call to delete_if except instead of returning the remaining items, returning the deleted items.</p>
<p>Here's some code that works:</p>
<pre><code>ary ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T11:22:23.827",
"Id": "39718",
"Score": "0",
"body": "`deleted = ary - ary.select(&:someproc)` seems totally fine to me"
}
] | [
{
"body": "<p>it is <a href=\"http://ruby-doc.org/core-2.0/Array.html#method-i-delete_if\" rel=\"nofollow\">built-in</a> : </p>\n\n<pre><code>ary.delete_if( &:odd? )\n</code></pre>\n\n<p><strong>EDIT</strong></p>\n\n<p>Sorry, misread your question. You can do this :</p>\n\n<pre><code>deleted = ary.select( &... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T10:58:23.017",
"Id": "25648",
"Score": "6",
"Tags": [
"ruby",
"array"
],
"Title": "A pattern to destructively extract items from an array"
} | 25648 |
<p>Since I didn't find a way to properly transform JavaScript object to JSON with PHP, I wrote a snippet.</p>
<hr>
<p>Lets assume the following excerpt from Google Fonts JavaScript API:</p>
<pre><code>WebFontConfig = {
google: { families: [ 'Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic,700italic... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T14:56:34.050",
"Id": "39727",
"Score": "0",
"body": "possible duplicate of [Parsing Javascript (not JSON) in PHP](http://stackoverflow.com/questions/1554100/parsing-javascript-not-json-in-php)"
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>As this works for you and as there is no javascript interpreter in PHP unless you install it (there is a V8 PHP extension IIRC), I would say you did this right so far.</p>\n\n<p>Which else criteria could there be than your own ones? You should probably write unit and acceptance tests for it. And r... | {
"AcceptedAnswerId": "25654",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T14:50:09.323",
"Id": "25653",
"Score": "3",
"Tags": [
"javascript",
"php",
"json",
"lookup"
],
"Title": "JavaScript object to JSON"
} | 25653 |
<p>I have written my first jQuery plugin using one of the design patterns suggested on jQuery's site: <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">http://docs.jquery.com/Plugins/Authoring</a>. </p>
<p>As listed below in the description comment, it's purpose is to provide keyboard and mouse navigat... | [] | [
{
"body": "<p>A late review:</p>\n\n<ul>\n<li>Yes, declaring variables without <code>var</code> is criminal, your approach will do. Do read up on the <a href=\"http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript\" rel=\"nofollow\">revealing module pattern</a> to avoi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T16:14:37.740",
"Id": "25656",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "jQuery highlightNavigation plugin"
} | 25656 |
<p>I'm coming close to finishing a site where there are a number of jQuery functions going on. They all work, but the page is just running a bit too clunky. The fading in and out is just not as smooth as it should be, especially on the contact link, and the auto page scrolling is a little jumpy.</p>
<p>I've cached as ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T14:55:56.527",
"Id": "39769",
"Score": "0",
"body": "I took a quick look at the page. Where do you turn off the sound?"
}
] | [
{
"body": "<p>Clunky is what happens when the browser is using much of the CPU. This could be some animation, timers that keep firing, or something else. In your case:</p>\n\n<ul>\n<li><p>You're streaming an mp3 in the background. It's a 5MB file, too big. I suggest you shrink that mp3, maybe lower its bitrate ... | {
"AcceptedAnswerId": "25670",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T16:46:14.410",
"Id": "25657",
"Score": "2",
"Tags": [
"javascript",
"performance",
"jquery",
"animation"
],
"Title": "Scrolling, fade-in, and fade-out effects feeling clunk... | 25657 |
<p>I've posted here before and got pretty helpful reviews. How does my code look now? To keep it really helpful, I just copied this from the middle of one of my projects.</p>
<pre><code> <?php
function findSimilarityBetweenImages($imagePathA, $imagePathB, $accuracy){
//if images are png
$imageA = imagec... | [] | [
{
"body": "<p>Since your question is about coding style, consider to adhere to <a href=\"https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md\">PSR-2</a>.</p>\n\n<p>Your color comparision function is bloated. 'If the expression is true, then return true, else, if the express... | {
"AcceptedAnswerId": "25770",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T19:56:32.153",
"Id": "25660",
"Score": "4",
"Tags": [
"php",
"image"
],
"Title": "Finding similarities between images"
} | 25660 |
<p>It took me a lot of poking around and unit testing to get the code to look like it is right now. So I have a XML file which in part looks like this</p>
<pre><code><FunctionKeys>
<Name>F13</Name>
<Name>F14</Name>
<Name>F15</Name>
<Name>F16</Name>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T20:34:14.063",
"Id": "39739",
"Score": "0",
"body": "Could you use XmlSerializer to do what you are after or would you prefer to stick with this approach?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-... | [
{
"body": "<p>Sticking with the approach you used how about this as an alternative.</p>\n\n<pre><code>public override void Load(string elementText)\n {\n var ele = XElement.Parse(elementText);\n\n var xElement = ele.Element(\"FunctionKeys\");\n if (xElement != null && xElement.Ha... | {
"AcceptedAnswerId": "25662",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-30T20:24:35.650",
"Id": "25661",
"Score": "2",
"Tags": [
"c#",
"array",
"linq",
"parsing",
"xml"
],
"Title": "XML to Windows.Forms.Keys List"
} | 25661 |
<p>Can someone help me with the following micro optimization for the F# code for lexicographic permutation?</p>
<p>I have code in C# which runs for 0.8s. As a learning practice, I translated it into F#. However, it becomes 2.9s. Just out of curiosity, I am wondering why my code in F# runs that slow? Are there any impr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T00:35:40.603",
"Id": "39744",
"Score": "0",
"body": "Well, have you tried profiling the code to find out what slows it down?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T15:58:54.253",
"Id": "4... | [
{
"body": "<p>You're not comparing apples to apples. The F# code is generic whereas the C# only works with <code>int</code> arrays. Remove every occurrence of <code>inline</code> and add a type annotation to <code>toNextLexicographic</code>: </p>\n\n<pre><code>let toNextLexicographic (myArray: int[])\n</code></... | {
"AcceptedAnswerId": "27551",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T00:05:52.463",
"Id": "25666",
"Score": "3",
"Tags": [
"c#",
"f#",
"combinatorics",
"comparative-review"
],
"Title": "My implementation of lexicographic permutation in F# is... | 25666 |
<p>Recently I have been developing a SASSified version of Dave Gamache's <a href="http://getskeleton.com/" rel="nofollow">Skeleton CSS</a> front-end framework. I have publicly posted the code on <a href="https://github.com/atomicpages/skeleton-sass" rel="nofollow">github</a> as well as a <a href="http://atomicpages.git... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T00:12:44.760",
"Id": "25669",
"Score": "4",
"Tags": [
"css",
"sass"
],
"Title": "SaSSified version of Skeleton CSS"
} | 25669 |
<p>Here is my shopping cart class! I want it to be perfect and never to have to implement it.</p>
<p>What improvements would you do?</p>
<h2>New : IComparable</h2>
<pre><code>interface IComparable
{
public function equals($object);
}
</code></pre>
<h2>New : ICartItem</h2>
<pre><code>interface ICartItem extends... | [] | [
{
"body": "<p>I would reccomend to use <code>if(session_id() == ''){ //do }</code> instead of <code>if(!isset($_SESSION)) { // do}</code> because $_SESSION can be set while the session is closed.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": "25689",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T01:10:45.107",
"Id": "25671",
"Score": "4",
"Tags": [
"php",
"e-commerce"
],
"Title": "My perfect shopping cart class"
} | 25671 |
<p>There is a lib code, trying to parse an Element Tree object. If exception happens, it either returns an empty dict of dict or a partially constructed object of such type. In this case, caller needs to parse the results to see if parsing is correctly handled or not. Or in other words, the returned dict is not determi... | [] | [
{
"body": "<pre><code>def parse_ET(self, ETObj):\n</code></pre>\n\n<p>Python style guide recommends lowercase_with_underscores for both function and parameter names</p>\n\n<pre><code> if ETObj == None: return None\n</code></pre>\n\n<p>Use <code>is None</code> to check for None. However, consider whether you ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T01:14:45.523",
"Id": "25672",
"Score": "1",
"Tags": [
"python",
"exception"
],
"Title": "How to handle returned value if an exception happens in a library code"
} | 25672 |
<pre><code>private static List<ConstrDirectedEdge> kruskalConstruct(ConstructionDigraph CG) {
int current = CG.srcVertexIndex();
boolean visited[] = new boolean[CG.V()];
visited[current] = true;
UF uf = new UF(CG.V());
List<ConstrDirectedEdge> feasibleNeighbours = new ArrayList<Const... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T13:17:37.520",
"Id": "39767",
"Score": "0",
"body": "Why would getFeasibleNeighbours modify visited and uf?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T17:25:45.523",
"Id": "39792",
"Score... | [
{
"body": "<p>If <code>visited</code> and <code>uf</code> are so tightly coupled with the feasibleNeighbor-calculation, maybe you should have something like a <code>FeasibleNeighborCalculator</code> class which is holding all of this stuff, and which you can ask for the next neighbor list?</p>\n",
"comments... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T01:36:48.380",
"Id": "25673",
"Score": "7",
"Tags": [
"java",
"graph"
],
"Title": "Simplifying finding neighbors in graph"
} | 25673 |
<p>I am working on my own PHP MVCframework. Now I want to know where to get and specify my entities.</p>
<p>For example, should I do this:</p>
<pre><code>class User_Model extends Model {
private $name;
public getName() {}
public setName($var) {}
public getAllUsers() {}
public getUser() {}
public saveUser(User_M... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T17:36:03.190",
"Id": "40000",
"Score": "0",
"body": "The type hinting in saveUser should be User not Entity. I like the second example more."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T10:19:57.12... | [
{
"body": "<p>Model and Entity mean very similar things to me, an Entity being something like an instance of a Model.</p>\n\n<p>What might be of use to you is to rename the Model class in the second example into a Collection class (Repository even). You would retrieve Entities from a Collection and save them ba... | {
"AcceptedAnswerId": "25912",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T09:24:09.280",
"Id": "25676",
"Score": "5",
"Tags": [
"php",
"mvc",
"comparative-review"
],
"Title": "Defining entries"
} | 25676 |
<p>Calling code and attempt at building session variables:</p>
<pre><code>DataTable dtServerVars = clCommonFunctions.TryAutoLogin("europe\\MrTest");
Session["CablingUserID"]= dtServerVars.Rows[0]["CablingUserID"].ToString();
Session["CablingUseremail"] = dtServerVars.Rows[0]["CablingUseremail"].ToString();
Session["Ca... | [] | [
{
"body": "<p>First your TryAutoLogin:</p>\n\n<ul>\n<li>A <code>SqlConnection</code> is <code>IDisposable</code>. Use it in combination with <code>using</code>.</li>\n<li>You have some duplicate lines of code, like <code>seCmd.CommandType = CommandType.StoredProcedure;</code>.</li>\n<li><code>dtServerVars</code... | {
"AcceptedAnswerId": "25678",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T10:13:12.780",
"Id": "25677",
"Score": "2",
"Tags": [
"c#",
"sql",
"asp.net"
],
"Title": "Building session-variables from a SQL stored procedure"
} | 25677 |
<p>Inspired by a recent question that caught my interest (now <a href="https://codereview.stackexchange.com/questions/25642/re-arrange-letters-to-produce-a-palindrome">deleted</a>), I wrote a function in Python 3 to rearrange the letters of a given string to create a (any!) palindrome:</p>
<ol>
<li>Count the occurrenc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-08-14T17:26:20.193",
"Id": "184519",
"Score": "0",
"body": "Rather than checking if you already have a letter with odd frequency, you can just count how many you have total, and if it is not equal to mod2 of the length of the string, it c... | [
{
"body": "<pre><code>from collections import deque, Counter\n\n\ndef palindrome_from(letters):\n \"\"\"\n Forms a palindrome by rearranging :letters: if possible,\n throwing a :ValueError: otherwise.\n :param letters: a suitable iterable, usually a string\n :return: a string containing a palindr... | {
"AcceptedAnswerId": "25680",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T12:39:17.153",
"Id": "25679",
"Score": "4",
"Tags": [
"python",
"algorithm",
"palindrome"
],
"Title": "Create palindrome by rearranging letters of a word"
} | 25679 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.