All Questions
22,735,443
questions
26459
votes
27
answers
1.7m
views
Why is processing a sorted array faster than processing an unsorted array?
Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data (before the timed region) miraculously makes the loop almost six times faster.
#include &...
24456
votes
99
answers
11.2m
views
How do I undo the most recent local commits in Git?
I accidentally committed the wrong files to Git but didn't push the commit to the server yet.
How can I undo those commits from the local repository?
The only way seems to be to copy the edits in some ...
19279
votes
41
answers
10.0m
views
How do I delete a Git branch locally and remotely?
I want to delete a branch both locally and remotely.
Failed Attempts to Delete a Remote Branch
$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.
$ git branch -d ...
13241
votes
39
answers
3.2m
views
What is the difference between 'git pull' and 'git fetch'?
What are the differences between git pull and git fetch?
12110
votes
48
answers
2.9m
views
What does the "yield" keyword do?
What is the use of the yield keyword in Python? What does it do?
For example, I'm trying to understand this code1:
def _get_child_candidates(self, distance, min_dist, max_dist):
if self._leftchild ...
11191
votes
37
answers
3.5m
views
What is the correct JSON content type?
I've been messing around with JSON for some time, just pushing it out as text and it hasn't hurt anybody (that I know of), but I'd like to start doing things properly.
I have seen so many purported &...
10712
votes
134
answers
10.1m
views
How can I remove a specific item from an array?
How do I remove a specific value from an array? Something like:
array.remove(value); // removes all elements with value
I have to use core JavaScript. Frameworks are not allowed.
10542
votes
37
answers
4.4m
views
How do I undo 'git add' before commit?
I mistakenly added files to Git using the command:
git add myfile.txt
I have not yet run git commit. Is there a way to undo this, so these files won't be included in the commit?
10521
votes
39
answers
4.3m
views
How do I rename a local Git branch?
I don't want to rename a remote branch, as described in Rename master branch for both local and remote Git repositories.
How can I rename a local branch which hasn't been pushed to a remote repository?...
9771
votes
28
answers
926k
views
What is the "-->" operator in C/C++?
After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4.
...
9021
votes
30
answers
1.8m
views
What and where are the stack and heap?
Programming language books explain that value types are created on the stack, and reference types are created on the heap, without explaining what these two things are. I haven't read a clear ...
8974
votes
57
answers
3.2m
views
Can comments be used in JSON?
Can I use comments inside a JSON file? If so, how?
8741
votes
50
answers
6.8m
views
How do I force "git pull" to overwrite local files?
How do I force an overwrite of local files on a git pull?
The scenario is the following:
A team member is modifying the templates for a website we are working on
They are adding some images to the ...
8440
votes
10
answers
712k
views
Why does HTML think “chucknorris” is a color?
Why do certain random strings produce colors when entered as background colors in HTML?
For example, bgcolor="chucknorris" produces a red background:
<body bgcolor="chucknorris"> ...
8397
votes
65
answers
3.0m
views
How do I check if an element is hidden in jQuery?
Is it possible to toggle the visibility of an element, using the functions .hide(), .show() or .toggle()?
How would you test if an element is visible or hidden?
8203
votes
30
answers
1.2m
views
What does "use strict" do in JavaScript, and what is the reasoning behind it?
Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error:
Problem at line 1 character 1: Missing "use strict" statement.
Doing some searching, I ...
7919
votes
40
answers
7.0m
views
How do I check out a remote Git branch?
Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.
How do I check out the remote test branch? I've tried:
git checkout ...
7707
votes
58
answers
7.3m
views
How do I redirect to another webpage?
How can I redirect the user from one page to another using jQuery or pure JavaScript?
7682
votes
41
answers
2.8m
views
How to remove local (untracked) files from the current Git working tree
How do you delete untracked local files from your current working tree?
7654
votes
27
answers
3.1m
views
How to modify existing, unpushed commit messages?
I wrote the wrong thing in a commit message.
How can I change the message? The commit has not been pushed yet.
7624
votes
86
answers
1.6m
views
How do JavaScript closures work?
How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand closures themselves?
I ...
7618
votes
41
answers
8.6m
views
How do I revert a Git repository to a previous commit?
How do I revert from my current state to a snapshot made on a certain commit?
If I do git log, then I get the following output:
$ git log
commit a867b4af366350be2e7c21b8de9cc6504678a61b`
Author: Me &...
7544
votes
42
answers
4.1m
views
What does if __name__ == "__main__": do?
What does this do, and why should one include the if statement?
if __name__ == "__main__":
print("Hello, World!")
7446
votes
93
answers
2.4m
views
Is Java "pass-by-reference" or "pass-by-value"?
I always thought Java uses pass-by-reference.
However, I've seen a blog post that claims that Java uses pass-by-value.
I don't think I understand the distinction they're making.
What is the ...
7438
votes
41
answers
1.2m
views
var functionName = function() {} vs function functionName() {}
I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.
The previous developer used two ...
7414
votes
3
answers
7.2m
views
How to check whether a string contains a substring in JavaScript?
Usually I would expect a String.contains() method, but there doesn't seem to be one.
What is a reasonable way to check for this?
7366
votes
11
answers
763k
views
Why is subtracting these two times (in 1927) giving a strange result?
If I run the following program, which parses two date strings referencing times 1 second apart and compares them:
public static void main(String[] args) throws ParseException {
SimpleDateFormat sf ...
7352
votes
32
answers
2.5m
views
Does Python have a ternary conditional operator?
Is there a ternary conditional operator in Python?
7247
votes
32
answers
1.9m
views
How can I make Git "forget" about a file that was tracked, but is now in .gitignore?
There is a file that was being tracked by Git, but now the file is on the .gitignore list.
However, that file keeps showing up in git status after it's edited. How do you force Git to completely ...
7232
votes
65
answers
1.2m
views
What is the difference between String and string in C#?
What are the differences between these two and which one should I use ?
string s = "Hello world!";
String s = "Hello world!";
7055
votes
34
answers
2.8m
views
How do I remove a property from a JavaScript object?
Say I create an object as follows:
let myObject = {
"ircEvent": "PRIVMSG",
"method": "newURI",
"regex": "^http://.*"
};
How should I ...
6828
votes
24
answers
1.0m
views
What are metaclasses in Python?
What are metaclasses? What are they used for?
6760
votes
54
answers
9.1m
views
How do I find all files containing specific text on Linux?
I'm trying to find a way to scan my entire Linux system for all files containing a specific string of text. Just to clarify, I'm looking for text within the file, not in the file name.
When I was ...
6672
votes
40
answers
4.9m
views
How do I check whether a file exists without exceptions?
How do I check whether a file exists or not, without using the try statement?
6380
votes
43
answers
1.9m
views
How to return the response from an asynchronous call
I have a function foo which makes an asynchronous request. How can I return the response/result from foo?
I am trying to return the value from the callback, as well as assigning the result to a local ...
6328
votes
43
answers
2.8m
views
How do I merge two dictionaries in a single expression?
I want to merge two dictionaries into a new dictionary.
x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
z = merge(x, y)
>>> z
{'a': 1, 'b': 3, 'c': 4}
Whenever a key k is present in both ...
6218
votes
35
answers
1.4m
views
What is the difference between "px", "dip", "dp" and "sp"?
What is the difference between these Android units of measure?
px
dip
dp
sp
6019
votes
39
answers
3.0m
views
What is the difference between POST and PUT in HTTP?
According to RFC 2616, § 9.5, POST is used to create a resource:
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the ...
6002
votes
68
answers
4.0m
views
How do I include a JavaScript file in another JavaScript file?
Is there something in JavaScript similar to @import in CSS that allows you to include a JavaScript file inside another JavaScript file?
5994
votes
21
answers
1.4m
views
Move the most recent commit(s) to a new branch with Git
I'd like to move the last several commits I've committed to master to a new branch and take master back to before those commits were made. Unfortunately, my Git-fu is not strong enough yet, any help?
...
5842
votes
45
answers
2.5m
views
How to disable text selection highlighting
For anchors that act like buttons (for example Questions, Tags, Users, etc. which are located on the top of the Stack Overflow page) or tabs, is there a CSS standard way to disable the highlighting ...
5802
votes
37
answers
2.0m
views
What's the difference between using "let" and "var"?
ECMAScript 6 introduced the let statement.
I've heard that it's described as a local variable, but I'm still not quite sure how it behaves differently than the var keyword.
What are the differences? ...
5764
votes
74
answers
2.2m
views
How can I get the directory where a Bash script is located from within the script itself?
How do I get the path of the directory in which a Bash script is located, inside that script?
I want to use a Bash script as a launcher for another application. I want to change the working directory ...
5761
votes
37
answers
3.5m
views
How do I discard unstaged changes in Git?
How do I discard changes in my working copy that are not in the index?
5713
votes
64
answers
4.1m
views
How do I execute a program or call a system command?
How do I call an external command within Python as if I'd typed it in a shell or command prompt?
5653
votes
48
answers
2.0m
views
Which equals operator (== vs ===) should be used in JavaScript comparisons?
I'm using JSLint to go through JavaScript, and it's returning many suggestions to replace == (two equals signs) with === (three equals signs) when doing things like comparing idSele_UNVEHtype.value....
5520
votes
11
answers
653k
views
The definitive guide to form-based website authentication [closed]
Moderator note:
This question is not a good fit for our question and answer format with the topicality rules which currently apply for Stack Overflow. We normally use a "historical lock" for ...
5414
votes
17
answers
1.5m
views
What is the maximum length of a URL in different browsers?
What is the maximum length of a URL in different browsers? Does it differ among browsers?
Is a maximum URL length part of the HTTP specification?
5398
votes
32
answers
2.9m
views
How to change the URI (URL) for a remote Git repository?
I have a repo (origin) on a USB key that I cloned on my hard drive (local). I moved "origin" to a NAS and successfully tested cloning it from here.
I would like to know if I can change the URI of "...
5383
votes
40
answers
4.9m
views
For-each over an array in JavaScript
How can I loop through all the entries in an array using JavaScript?