All Questions

27293 votes
25 answers
1.9m views

Why is processing a sorted array faster than processing an unsorted array?

In this C++ code, sorting the data (before the timed region) makes the primary loop ~6x faster: #include <algorithm> #include <ctime> #include <iostream> int main() { // ...
GManNickG's user avatar
  • 501k
26533 votes
108 answers
14.6m 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 do I undo those commits from the local repository?
20374 votes
41 answers
11.7m views

How do I delete a Git branch 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 origin/bugfix error: branch 'origin/bugfix' not found....
13859 votes
37 answers
3.5m views

What is the difference between 'git pull' and 'git fetch'?

What are the differences between git pull and git fetch?
Pablo Fernandez's user avatar
12953 votes
52 answers
3.4m views

What does the "yield" keyword do in Python?

What functionality does the yield keyword in Python provide? For example, I'm trying to understand this code1: def _get_child_candidates(self, distance, min_dist, max_dist): if self._leftchild and ...
Alex. S.'s user avatar
  • 146k
11989 votes
150 answers
12.8m views

How can I remove a specific item from an array in JavaScript?

How do I remove a specific value from an array? Something like: array.remove(value); Constraints: I have to use core JavaScript. Frameworks are not allowed.
Walker's user avatar
  • 133k
11693 votes
41 answers
5.6m views

How can I rename a local Git branch?

How can I rename a local branch which has not yet been pushed to a remote repository? Related: Rename master branch for both local and remote Git repositories How do I rename both a Git local and ...
Forrest's user avatar
  • 126k
11584 votes
39 answers
3.9m views

Which JSON content type do I use?

There are many "standards" for the JSON content type: application/json application/x-javascript text/javascript text/x-javascript text/x-json Which one do I use, and where? I assume ...
Oli's user avatar
  • 239k
11399 votes
38 answers
5.7m 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. How do I undo this so that these changes will not be included in the commit?
oz10's user avatar
  • 157k
10169 votes
26 answers
1.0m 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. ...
9728 votes
54 answers
8.7m views

How do I force "git pull" to overwrite local files?

How do I force an overwrite of local files on a git pull? My local repository contains a file of the same filename as on the server. error: Untracked working tree file 'example.txt' would be ...
Jakub Troszok's user avatar
9589 votes
62 answers
3.6m views

Can comments be used in JSON?

Can I use comments inside a JSON file? If so, how?
Michael Gundlach's user avatar
9448 votes
30 answers
1.9m views

What and where are the stack and heap?

What are the stack and heap? Where are they located physically in a computer's memory? To what extent are they controlled by the OS or language run-time? What is their scope? What determines their ...
mattshane's user avatar
  • 94.5k
8847 votes
9 answers
783k 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"> ...
user456584's user avatar
  • 88.3k
8708 votes
44 answers
8.9m 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 ...
Juri Glass's user avatar
  • 90.6k
8699 votes
67 answers
3.2m views

How do I check if an element is hidden in jQuery?

How do I toggle the visibility of an element using .hide(), .show(), or .toggle()? How do I test if an element is visible or hidden?
Philip Morton's user avatar
8494 votes
32 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, ...
Mark Rogers's user avatar
  • 97.4k
8351 votes
36 answers
2.5m views

How do I make Git forget about a file that was tracked, but is now in .gitignore?

I put a file that was previously being tracked by Git onto the .gitignore list. However, the file still shows up in git status after it is edited. How do I force Git to completely forget the file?
Ivan's user avatar
  • 102k
8265 votes
47 answers
4.7m 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!") If you are trying to close a question where someone should be ...
Devoted's user avatar
  • 182k
8185 votes
43 answers
3.3m views

How do I remove local (untracked) files from the current Git working tree?

How do I delete untracked local files from the current working tree?
readonly's user avatar
  • 351k
7957 votes
31 answers
3.0m views

Does Python have a ternary conditional operator?

Is there a ternary conditional operator in Python?
Devoted's user avatar
  • 182k
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 ...
7698 votes
58 answers
7.9m views

How do I redirect to another webpage?

How can I redirect the user from one page to another using jQuery or pure JavaScript?
venkatachalam's user avatar
7641 votes
27 answers
3.9m 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.
Laurie Young's user avatar
7639 votes
42 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 ways ...
Richard Garside's user avatar
7615 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 ...
7609 votes
41 answers
11.3m 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 &...
Crazy Serb's user avatar
  • 76.3k
7570 votes
11 answers
806k views

Why is subtracting these two epoch-milli Times (in year 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 ...
Freewind's user avatar
  • 197k
7555 votes
68 answers
1.3m 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!";
7541 votes
56 answers
11.2m views

Find all files containing a specific text (string) on Linux?

How do I find all files containing a specific string of text within their file contents? The following doesn't work. It seems to display every single file in the system. find / -type f -exec grep -H '...
Nathan's user avatar
  • 77k

15 30 50 per page
1
2 3 4 5
806890