Most Popular
1500 questions
26419
votes
27 answers
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
#include
#include…
GManNickG
- 478,574
- 51
- 478
- 539
24353
votes
98 answers
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 kind of GUI text editor, then wipe the whole…
Hamza Yerlikaya
- 48,407
- 41
- 141
- 236
19219
votes
41 answers
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 origin/bugfix
error: branch 'origin/bugfix' not…
Matthew Rankin
- 430,686
- 38
- 120
- 160
13206
votes
39 answers
What is the difference between 'git pull' and 'git fetch'?
What are the differences between git pull and git fetch?
pupeno
- 267,428
- 120
- 345
- 578
12050
votes
48 answers
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 and distance - max_dist < self._median:
…
Alex. S.
- 136,035
- 18
- 52
- 61
11160
votes
38 answers
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 "standards" for the JSON content…
Oli
- 228,145
- 62
- 212
- 294
10632
votes
131 answers
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.
Walker
- 117,787
- 26
- 66
- 94
10507
votes
37 answers
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?
paxos1977
- 144,851
- 26
- 89
- 126
10445
votes
39 answers
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?
In case you need to rename a remote branch as…
Forrest
- 113,461
- 20
- 72
- 107
9752
votes
28 answers
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.
Here's the code:
#include
int main()
{
…
GManNickG
- 478,574
- 51
- 478
- 539
8994
votes
30 answers
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 explanation of this. I understand what a stack is. But,…
mattshane
- 89,977
- 3
- 16
- 5
8934
votes
57 answers
Can comments be used in JSON?
Can I use comments inside a JSON file? If so, how?
Michael Gundlach
- 101,260
- 11
- 35
- 39
8686
votes
48 answers
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 images directory (but forgets to add them under…
Jakub Troszok
- 91,803
- 10
- 39
- 51
8416
votes
10 answers
Why does HTML think “chucknorris” is a color?
Why do certain random strings produce colors when entered as background colors in HTML?
For example, the following code produces a page with a red background across all browsers and platforms:
test
On the…
user456584
- 83,299
- 12
- 73
- 107
8375
votes
64 answers
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?
Philip Morton
- 125,759
- 37
- 85
- 97