All Questions

2464 votes
23 answers
469k views

How to make a great R reproducible example

When discussing performance with colleagues, teaching, sending a bug report or searching for guidance on mailing lists and here on Stack Overflow, a reproducible example is often asked and always ...
209 votes
12 answers
4.2m views

What is a NullPointerException, and how do I fix it?

What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them? What methods/tools can be used to determine the cause so that you stop the exception from causing the program ...
6709 votes
42 answers
2.1m views

How do I return the response from an asynchronous call?

How do I return the response/result from a function foo that makes an asynchronous request? I am trying to return the value from the callback, as well as assigning the result to a local variable ...
Felix Kling's user avatar
2769 votes
27 answers
2.2m views

How can I prevent SQL injection in PHP?

If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example: $unsafe_variable = $_POST['user_input']; ...
2275 votes
37 answers
3.8m views

RegEx match open tags except XHTML self-contained tags

I need to match all of these opening tags: <p> <a href="foo"> But not self-closing tags: <br /> <hr class="foo" /> I came up with this and wanted to make ...
1867 votes
26 answers
2.3m views

What is a NullReferenceException, and how do I fix it?

I have some code and when it executes, it throws a NullReferenceException, saying: Object reference not set to an instance of an object. What does this mean, and what can I do to fix this error?
3969 votes
36 answers
589k views

Is floating-point math broken?

Consider the following code: 0.1 + 0.2 == 0.3 -> false 0.1 + 0.2 -> 0.30000000000000004 Why do these inaccuracies happen?
Cato Johnston's user avatar
4229 votes
1 answer
3.2m views

The Definitive C++ Book Guide and List

This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from ...
723 votes
23 answers
4.7m views

How do I compare strings in Java?

I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug. Is == bad? When should it ...
1815 votes
40 answers
990k views

What is an undefined reference/unresolved external symbol error and how do I fix it?

What are undefined reference/unresolved external symbol errors? What are common causes, and how do I fix and prevent these errors?
Luchian Grigore's user avatar
1363 votes
29 answers
2.2m views

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP

I'm running a PHP script and continue to receive errors like: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php on line 10 Notice: Undefined index: my_index C:\wamp\www\...
2723 votes
14 answers
260k views

Why shouldn't I use mysql_* functions in PHP?

What are the technical reasons for why one shouldn't use mysql_* functions? (e.g. mysql_query(), mysql_connect() or mysql_real_escape_string())? Why should I use something else even if they work on ...
Madara's Ghost's user avatar
1674 votes
23 answers
1.1m views

Event binding on dynamically created elements?

I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off. This happens on page ready ...
Eli's user avatar
  • 98.7k
2798 votes
30 answers
393k views

Should I cast the result of malloc (in C)?

In this question, someone suggested in a comment that I should not cast the result of malloc. i.e., I should do this: int *sieve = malloc(sizeof(*sieve) * length); rather than: int *sieve = (int *) ...
Patrick McDonald's user avatar
1914 votes
16 answers
636k views

How to access the correct `this` inside a callback

I have a constructor function which registers an event handler: function MyConstructor(data, transport) { this.data = data; transport.on('data', function () { alert(this.data); ...
Felix Kling's user avatar
778 votes
20 answers
885k views

PHP parse/syntax errors; and how to solve them

Everyone runs into syntax errors. Even experienced programmers make typos. For newcomers, it's just part of the learning process. However, it's often easy to interpret error messages such as: PHP ...
643 votes
15 answers
402k views

How to avoid using Select in Excel VBA

I've heard much about the understandable abhorrence of using .Select in Excel VBA, but I am unsure of how to avoid using it. I am finding that my code would be more re-usable if I were able to use ...
BiGXERO's user avatar
  • 7,194
3248 votes
45 answers
484k views

JavaScript closure inside loops – simple practical example

var funcs = []; // let's create 3 functions for (var i = 0; i < 3; i++) { // and store them in funcs funcs[i] = function() { // each should log its value. console.log("My value:", i); ...
nickf's user avatar
  • 543k
3407 votes
41 answers
1.2m views

What's the problem with "using namespace std;"?

I have heard using namespace std; is wrong, and that I should use std::cout and std::cin directly instead. Why is this? Does it risk declaring variables that share the same name as something in the ...
akbiggs's user avatar
  • 34.8k
916 votes
7 answers
305k views

Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference

Given the following examples, why is outerScopeVar undefined in all cases? var outerScopeVar; var img = document.createElement('img'); img.onload = function() { outerScopeVar = this.width; }; img....
Fabrício Matté's user avatar
246 votes
5 answers
55k views

How to make good reproducible pandas examples

Having spent a decent amount of time watching both the r and pandas tags on SO, the impression that I get is that pandas questions are less likely to contain reproducible data. This is something that ...
Marius's user avatar
  • 59.7k
52 votes
1 answer
212k views

Reference - What does this regex mean?

What is this? This is a collection of common Q&A. This is also a Community Wiki, so everyone is invited to participate in maintaining it. Why is this? regex is suffering from give me ze code type ...
1286 votes
39 answers
281k views

Reference - What does this error mean in PHP?

What is this? This is a number of answers about warnings, errors, and notices you might encounter while programming PHP and have no clue how to fix them. This is also a Community Wiki, so everyone is ...
568 votes
30 answers
543k views

PHP mail function doesn't complete sending of e-mail

<?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: yoursite.com'; $to = '[email protected]'; $subject = 'Customer ...
user3818620's user avatar
  • 5,723
611 votes
7 answers
202k views

Why does jQuery or a DOM method such as getElementById not find the element if I put the script element near the top of the page?

What are the possible reasons for document.getElementById, $("#id") or any other DOM method / jQuery selector not finding the elements? Example problems include: jQuery silently failing to ...
Felix Kling's user avatar
7750 votes
91 answers
2.7m views

Is Java "pass-by-reference" or "pass-by-value"?

I always thought Java uses pass-by-reference. However, I read a blog post which claims that Java uses pass-by-value. I don't think I understand the distinction the author is making. What is the ...
1135 votes
32 answers
1.3m views

How can I access and process nested objects, arrays, or JSON?

I have a nested data structure containing objects and arrays. How can I extract the information, i.e. access a specific or multiple values (or keys)? For example: var data = { code: 42, ...
Felix Kling's user avatar
1358 votes
13 answers
212k views

UTF-8 all the way through

I'm setting up a new server and want to support UTF-8 fully in my web application. I have tried this in the past on existing servers and always seem to end up having to fall back to ISO-8859-1. Where ...
mercutio's user avatar
  • 22.4k
63 votes
1 answer
60k views

Official locator strategies for the webdriver

In the official W3C webdriver documentation, it's clearly stated that the location strategies are: State Keyword ----------------------------------------------- CSS selector ...
Merc's user avatar
  • 16.9k
2300 votes
19 answers
808k views

Why can templates only be implemented in the header file?

Quote from The C++ standard library: a tutorial and handbook: The only portable way of using templates at the moment is to implement them in header files by using inline functions. Why is this? (...
MainID's user avatar
  • 29.8k

15 30 50 per page
1
2 3 4 5
73720