All Questions

Filter by
Sorted by
Tagged with
23339
votes
23answers
1.4m 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 miraculously makes the code almost six times faster: #include <algorithm> #include &...
19930
votes
80answers
8.1m views

How do I undo the most recent local commits in Git?

I accidentally committed the wrong files to Git, but I haven't pushed the commit to the server yet. How can I undo those commits from the local repository?
15686
votes
38answers
7.3m 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 Remote Branch $ git branch -d remotes/origin/bugfix error: branch 'remotes/origin/bugfix' not found. $ git branch -d ...
11183
votes
41answers
2.6m views

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

Moderator Note: Given that this question has already had sixty-seven answers posted to it (some of them deleted), consider whether or not you are contributing anything new before posting another one. ...
9812
votes
34answers
2.6m 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 "...
9435
votes
38answers
2.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....
8436
votes
21answers
727k views

What is 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. ...
8334
votes
32answers
2.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. Is there a way to undo this, so these files won't be included in the commit?
7822
votes
31answers
2.6m 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 branch? ...
7728
votes
58answers
5.8m views

How do I redirect to another webpage?

How can I redirect the user from one page to another using jQuery or pure JavaScript?
7725
votes
25answers
1.4m 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 ...
7671
votes
27answers
2.4m 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.
7647
votes
86answers
1.4m 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 ...
7432
votes
3answers
5.7m 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?
7365
votes
55answers
2.5m views

How do I 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?
7361
votes
79answers
5.9m views

How do I remove a particular element from an array in JavaScript?

I have an array of Numbers, and I'm using the .push() method to add elements to it. Is there a simple way to remove a specific element from an array? The equivalent of something like array.remove(...
7226
votes
27answers
1.0m 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 ...
7134
votes
9answers
490k views

Why does HTML think “chucknorris” is a color?

How come certain random strings produce colors when entered as background colors in HTML? For example: <body bgcolor="chucknorris"> test </body> ...produces a document with a ...
7033
votes
41answers
5.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 &...
6827
votes
49answers
1.9m views

Can comments be used in JSON?

Can I use comments inside a JSON file? If so, how?
6534
votes
38answers
960k 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 uses two ...
6507
votes
9answers
611k 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 ...
6404
votes
35answers
2.1m 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?
6357
votes
40answers
4.0m 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 following: A team member is modifying the templates for a website we are working on They are adding some images to the ...
6263
votes
27answers
4.8m 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. Now I'm trying to check out the remote test branch. I've tried: git ...
6093
votes
63answers
1.0m views

What is the difference between String and string in C#?

Example (note the case): string s = "Hello world!"; String s = "Hello world!"; What are the guidelines for the use of each? And what are the differences?
6093
votes
82answers
1.8m views

Is Java “pass-by-reference” or “pass-by-value”?

I always thought Java was pass-by-reference. However, I've seen a couple of blog posts (for example, this blog) that claim that it isn't. I don't think I understand the distinction they're making. ...
5668
votes
49answers
1.7m 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....
5657
votes
38answers
2.0m views

How do I remove a property from a JavaScript object?

Say I create an object as follows: var myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; What is the best way to remove the property regex to end up with ...
5605
votes
35answers
1.2m views

What is the difference between “px”, “dip”, “dp” and “sp”?

What is the difference between Android units of measure? px dip dp sp
5385
votes
21answers
1.7m views

Does Python have a ternary conditional operator?

If Python does not have a ternary conditional operator, is it possible to simulate one using other language constructs?
5276
votes
12answers
583k views

The definitive guide to form-based website authentication [closed]

Form-based authentication for websites We believe that Stack Overflow should not just be a resource for very specific technical questions, but also for general guidelines on how to solve ...
5271
votes
16answers
723k views

What are metaclasses in Python?

What are metaclasses and what do we use them for?
5261
votes
29answers
2.4m views

What does if __name__ == “__main__”: do?

What does the if __name__ == "__main__": do? # Threading example import time, thread def myfunction(string, sleeptime, lock, *args): while True: lock.acquire() time.sleep(...
5169
votes
69answers
1.8m views

What is the most efficient way to deep clone an object in JavaScript?

What is the most efficient way to clone a JavaScript object? I've seen obj = eval(uneval(o)); being used, but that's non-standard and only supported by Firefox. I've done things like obj = JSON.parse(...
5164
votes
37answers
3.6m views

How do I check whether a file exists without exceptions?

How do I see if a file exists or not, without using the try statement?
5097
votes
33answers
2.2m views

PUT vs. POST in REST

According to the HTTP/1.1 Spec: The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-...
5073
votes
35answers
1.3m views

How do I return the response from an asynchronous call?

I have a function foo which makes an Ajax request. How can I return the response from foo? I tried returning the value from the success callback as well as assigning the response to a local variable ...
4816
votes
40answers
1.7m views

How to disable text selection highlighting

For anchors that act like buttons (for example, Questions, Tags, Users, etc. at the top of the Stack Overflow page) or tabs, is there a CSS standard way to disable the highlighting effect if the ...
4796
votes
39answers
661k views

What is a plain English explanation of “Big O” notation?

I'd prefer as little formal definition as possible and simple mathematics.
4763
votes
57answers
2.8m 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?
4688
votes
42answers
5.9m 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 ...
4616
votes
24answers
1.0m views

How to 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 ...
4578
votes
9answers
910k views

How to pass “Null” (a real surname!) to a SOAP web service in ActionScript 3?

We have an employee whose surname is Null. Our employee lookup application is killed when that last name is used as the search term (which happens to be quite often now). The error received (thanks ...
4572
votes
16answers
1.2m 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? Does the HTTP protocol dictate it?
4522
votes
60answers
1.5m views

Get the source directory of a Bash script from within the script itself

How do I get the path of the directory in which a Bash script is located, inside that script? For instance, let's say I want to use a Bash script as a launcher for another application. I want to ...
4519
votes
15answers
810k views

“Thinking in AngularJS” if I have a jQuery background? [closed]

Suppose I'm familiar with developing client-side applications in jQuery, but now I'd like to start using AngularJS. Can you describe the paradigm shift that is necessary? Here are a few questions that ...
4494
votes
34answers
2.4m views

How to resolve merge conflicts in Git

How do I resolve merge conflicts in Git?
4448
votes
13answers
871k 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? ...
4432
votes
24answers
2.2m views

What is the difference between “INNER JOIN” and “OUTER JOIN”?

Also how do LEFT JOIN, RIGHT JOIN and FULL JOIN fit in?

15 30 50 per page