Dismiss
Announcing Developer Story

You’re more than your resume. Show off what you’ve built.

Check out my Developer Story →
15869
votes
13answers
868k views

Why is it faster to process a sorted array than an unsorted array?

Here is a piece of C++ code that seems very peculiar. For some strange reason, sorting the data miraculously makes the code almost six times faster. #include <algorithm> #include <ctime> #...
11877
votes
48answers
3.8m views

How to undo last commit(s) in Git?

I committed the wrong files to Git. How can I undo that commit?
8584
votes
31answers
3.2m views

How to delete a Git branch both locally and remotely?

I want to delete a branch both locally and on my remote project fork on GitHub. Successfully Deleted Local Branch $ git branch -D bugfix Deleted branch bugfix (was 2a14ef7). Note: The uppercase -...
7688
votes
27answers
1.8m views

How to modify existing, unpushed commits?

I wrote the wrong thing in a commit message. Alternatively, I've forgotten to include some files. How can I change the commit message/files? The commit has not been pushed yet.
7198
votes
31answers
1.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 "...
6769
votes
34answers
1.4m views

What are the differences between 'git pull' and 'git fetch'?

What are the differences between git pull and git fetch?
6546
votes
82answers
884k 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 ...
5861
votes
19answers
460k views

What is the name of the “-->” operator in 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. ...
5656
votes
58answers
3.2m views

How to redirect to another page in jQuery?

How can I redirect the user from one page to another using jQuery?
5499
votes
30answers
1.1m 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....
5372
votes
22answers
886k 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 ...
5227
votes
40answers
3.3m views

How to check if one string contains another 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?
5166
votes
28answers
1.3m views

How to undo 'git add' before commit?

I mistakenly added files 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?
4985
votes
20answers
686k 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 ...
4935
votes
38answers
1.6m views

How to check if an element is hidden in jQuery?

It is 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?

15 30 50 per page