All Questions
24,193,041
questions
3313
votes
20
answers
2.4m
views
How to iterate over a dictionary?
I've seen a few different ways to iterate over a dictionary in C#. Is there a standard way?
3313
votes
42
answers
2.1m
views
How do I pass a variable by reference?
I wrote this class for testing:
class PassByReference:
def __init__(self):
self.variable = 'Original'
self.change(self.variable)
print(self.variable)
def change(self, ...
3296
votes
22
answers
1.8m
views
How do I disable the resizable property of a textarea?
I want to disable the resizable property of a textarea.
Currently, I can resize a textarea by clicking on the bottom right corner of the textarea and dragging the mouse. How can I disable this?
3282
votes
45
answers
3.8m
views
How to add a column with a default value to an existing table in SQL Server?
How can I add a column with a default value to an existing table in SQL Server 2000 / SQL Server 2005?
3252
votes
14
answers
939k
views
event.preventDefault() vs. return false
When I want to prevent other event handlers from executing after a certain event is fired, I can use one of two techniques. I'll use jQuery in the examples, but this applies to plain-JS as well:
1. ...
3250
votes
11
answers
3.1m
views
Manually raising (throwing) an exception in Python
How do I raise an exception in Python so that it can later be caught via an except block?
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);
...
3242
votes
22
answers
1.6m
views
How do I modify a specific commit?
I have the following commit history:
HEAD
HEAD~
HEAD~2
HEAD~3
git commit --amend modifies the current HEAD commit. But how do I modify HEAD~3?
3238
votes
31
answers
4.5m
views
How do I concatenate two lists in Python?
How do I concatenate two lists in Python?
Example:
listone = [1, 2, 3]
listtwo = [4, 5, 6]
Expected outcome:
>>> joinedlist
[1, 2, 3, 4, 5, 6]
3236
votes
13
answers
3.8m
views
How do I make a time delay? [duplicate]
How do I put a time delay in a Python script?
3234
votes
7
answers
2.8m
views
Understanding Python super() with __init__() methods [duplicate]
Why is super() used?
Is there a difference between using Base.__init__ and super().__init__?
class Base(object):
def __init__(self):
print "Base created"
class ChildA(...
3232
votes
105
answers
1.4m
views
How do you disable browser autocomplete on web form field / input tags?
How do you disable autocomplete in the major browsers for a specific input (or form field)?
3228
votes
49
answers
1.5m
views
Detecting an undefined object property
How do I check if an object property in JavaScript is undefined?
3228
votes
59
answers
1.3m
views
How do I test a class that has private methods, fields or inner classes?
How do I use JUnit to test a class that has internal private methods, fields or nested classes?
It seems bad to change the access modifier for a method just to be able to run a test.
3224
votes
16
answers
6.1m
views
How do I change the size of figures drawn with Matplotlib?
How do I change the size of figure drawn with Matplotlib?
3222
votes
27
answers
5.0m
views
How do I check if a list is empty?
For example, if passed the following:
a = []
How do I check to see if a is empty?
3218
votes
34
answers
2.3m
views
Using async/await with a forEach loop
Are there any issues with using async/await in a forEach loop? I'm trying to loop through an array of files and await on the contents of each file.
import fs from 'fs-promise'
async function ...
3217
votes
66
answers
2.5m
views
How do I print colored text to the terminal?
How do I output colored text to the terminal in Python?
3213
votes
30
answers
1.2m
views
How do I find and restore a deleted file in a Git repository?
Say I'm in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I discover that I need to restore that file after deleting it.
I know I can ...
3209
votes
36
answers
2.8m
views
ssh "permissions are too open"
I get the following error from ssh:
Permissions 0777 for '/Users/username/.ssh/id_rsa' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will ...
3208
votes
14
answers
2.6m
views
I ran into a merge conflict. How do I abort the merge?
I used git pull and had a merge conflict:
unmerged: some_file.txt
You are in the middle of a conflicted merge.
How do I abandon my changes to the file and keep only the pulled changes?
3196
votes
12
answers
2.4m
views
How can I see the differences between two branches?
How can I see the differences between branches branch_1 and branch_2?
3182
votes
40
answers
1.1m
views
Should I use the datetime or timestamp data type in MySQL?
Would you recommend using a datetime or a timestamp field, and why (using MySQL)?
I'm working with PHP on the server side.
3182
votes
20
answers
293k
views
Is it possible to apply CSS to half of a character?
What I am looking for:
A way to style one HALF of a character. (In this case, half the letter being transparent)
What I have currently searched for and tried (With no luck):
Methods for styling half ...
3180
votes
19
answers
1.8m
views
What does " 2>&1 " mean?
To combine stderr and stdout into the stdout stream, we append this to a command:
2>&1
e.g. to see the first few errors from compiling g++ main.cpp:
g++ main.cpp 2>&1 | head
What does ...
3172
votes
54
answers
831k
views
How to stop EditText from gaining focus when an activity starts in Android?
I have an Activity in Android, with two elements:
EditText
ListView
When my Activity starts, the EditText immediately has the input focus (flashing cursor). I don't want any control to have input ...
3168
votes
22
answers
664k
views
How do I make function decorators and chain them together?
How do I make two decorators in Python that would do the following?
@make_bold
@make_italic
def say():
return "Hello"
Calling say() should return:
"<b><i>Hello</i>&...
3151
votes
27
answers
1.7m
views
How to set, clear, and toggle a single bit
How can I set, clear, and toggle a bit?
3151
votes
17
answers
867k
views
Is there an "exists" function for jQuery?
How can I check the existence of an element in jQuery?
The current code that I have is this:
if ($(selector).length > 0) {
// Do something
}
Is there a more elegant way to approach this? ...
3148
votes
34
answers
1.5m
views
How can I upload files asynchronously with jQuery?
I would like to upload a file asynchronously with jQuery.
$(document).ready(function () {
$("#uploadbutton").click(function () {
var filename = $("#file").val();
$.ajax({...
3146
votes
31
answers
4.5m
views
`git fetch` a remote branch
The remote repository contains various branches such as origin/daves_branch:
$ git branch -r
origin/HEAD -> origin/master
origin/daves_branch
origin/master
How do I switch to daves_branch in the ...
3146
votes
39
answers
1.2m
views
How can I check if a program exists from a Bash script?
How would I validate that a program exists, in a way that will either return an error and exit, or continue with the script?
It seems like it should be easy, but it's been stumping me.
3142
votes
24
answers
2.4m
views
HTTP GET with request body
I'm developing a new RESTful webservice for our application.
When doing a GET on certain entities, clients can request the contents of the entity.
If they want to add some parameters (for example ...
3135
votes
12
answers
786k
views
When should static_cast, dynamic_cast, const_cast, and reinterpret_cast be used?
What are the proper uses of:
static_cast
dynamic_cast
const_cast
reinterpret_cast
(type)value (C-style cast)
type(value) (function-style cast)
How does one decide which to use in which specific ...
3127
votes
70
answers
1.7m
views
How do I split a list into equally-sized chunks?
How do I split a list of arbitrary length into equal sized chunks?
See also: How to iterate over a list in chunks.
To chunk strings, see Split string every nth character?.
3118
votes
30
answers
1.7m
views
How can I change the commit author for a single commit?
I want to change the author of one specific commit in the history. It's not the latest commit.
Related: How do I change the author and committer name/email for multiple commits?
3111
votes
20
answers
3.3m
views
What is the difference between Python's list methods append and extend?
What's the difference between the list methods append() and extend()?
3111
votes
30
answers
916k
views
What is the difference between #include <filename> and #include "filename"?
What is the difference between using angle brackets and quotes in an include directive?
#include <filename>
#include "filename"
3104
votes
47
answers
3.0m
views
Is there a standard function to check for null, undefined, or blank variables in JavaScript? [duplicate]
Is there a universal JavaScript function that checks that a variable has a value and ensures that it's not undefined or null? I've got this code, but I'm not sure if it covers all cases:
function ...
3101
votes
21
answers
3.1m
views
How do I clone a Git repository into a specific folder?
The command git clone [email protected]:whatever creates a directory named whatever containing a Git repository:
./
whatever/
.git
I want the contents of the Git repository cloned into my ...
3095
votes
54
answers
1.3m
views
Is there a unique Android device ID?
Do Android devices have a unique ID, and if so, what is a simple way to access it using Java?
3093
votes
17
answers
1.1m
views
What is the difference between the 'COPY' and 'ADD' commands in a Dockerfile?
What is the difference between the COPY and ADD commands in a Dockerfile, and when would I use one over the other?
COPY <src> <dest>
The COPY instruction will copy new files from <...
3093
votes
16
answers
1.2m
views
What is the --save option for npm install?
I saw some tutorial where the command was:
npm install --save
What does the --save option mean?
3091
votes
43
answers
1.2m
views
How do I change the author and committer name/email for multiple commits?
How do I change the author for a range of commits?
3083
votes
41
answers
1.8m
views
How do I pass command line arguments to a Node.js program and receive them?
I have a web server written in Node.js and I would like to launch with a specific folder. I'm not sure how to access arguments in JavaScript. I'm running node like this:
$ node server.js folder
here ...
3080
votes
24
answers
1.5m
views
How to store objects in HTML5 localStorage/sessionStorage
I'd like to store a JavaScript object in HTML5 localStorage, but my object is apparently being converted to a string.
I can store and retrieve primitive JavaScript types and arrays using localStorage, ...
3073
votes
27
answers
3.8m
views
Deleting an element from an array in PHP
Is there an easy way to delete an element from an array using PHP, such that foreach ($array) no longer includes that element?
I thought that setting it to null would do it, but apparently it does ...
3068
votes
39
answers
2.5m
views
How can I know which radio button is selected via jQuery?
I have two radio buttons and want to post the value of the selected one.
How can I get the value with jQuery?
I can get all of them like this:
$("form :radio")
How do I know which one is selected?
3061
votes
16
answers
3.7m
views
How can I check for "undefined" in JavaScript? [duplicate]
What is the most appropriate way to test if a variable is undefined in JavaScript?
I've seen several possible ways:
if (window.myVariable)
Or
if (typeof(myVariable) != "undefined")
Or
if (...
3044
votes
21
answers
2.1m
views
How do I modify the URL without reloading the page?
Is there a way I can modify the URL of the current page without reloading the page?
I would like to access the portion before the # hash if possible.
I only need to change the portion after the domain,...