Highest scored questions
24,189,471 questions
5803
votes
28
answers
4.0m
views
How do I create a directory, and any missing parent directories?
How do I create a directory at a given path, and also create any missing parent directories along that path? For example, the Bash command mkdir -p /path/to/nested/directory does this.
5800
votes
41
answers
5.5m
views
Loop (for each) over an array in JavaScript
How can I loop through all the entries in an array using JavaScript?
5791
votes
47
answers
4.7m
views
How do I squash my last N commits together?
How do I squash my last N commits together into one commit?
5707
votes
26
answers
5.4m
views
How to determine the URL that a local Git repository was originally cloned from
I pulled a project with several forks on GitHub, but forgot which fork it was. How do I determine which fork I pulled?
5659
votes
28
answers
5.0m
views
How can I access the index value in a 'for' loop?
How do I access the index while iterating over a sequence with a for loop?
xs = [8, 23, 45]
for x in xs:
print("item #{} = {}".format(index, x))
Desired output:
item #1 = 8
item #2 = ...
5644
votes
47
answers
2.2m
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....
5586
votes
23
answers
2.1m
views
What's the difference between tilde(~) and caret(^) in package.json?
After I upgraded to the latest stable node and npm, I tried npm install moment --save. It saves the entry in the package.json with the caret ^ prefix. Previously, it was a tilde ~ prefix.
Why are ...
5515
votes
50
answers
4.6m
views
How do I replace all occurrences of a string?
Given a string:
string = "Test abc test test abc test test test abc test test abc";
This seems to only remove the first occurrence of abc in the string above:
string = string.replace('abc', ...
5509
votes
11
answers
700k
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 ...
5506
votes
13
answers
3.3m
views
How do I exit Vim?
I am stuck and cannot escape. It says:
type :quit<Enter> to quit VIM
But when I type that it simply appears in the object body.
5503
votes
37
answers
1.7m
views
How do I add an empty directory to a Git repository?
How do I add an empty directory (that contains no files) to a Git repository?
5489
votes
77
answers
3.3m
views
How do I create a GUID / UUID?
How do I create GUIDs (globally-unique identifiers) in JavaScript? The GUID / UUID should be at least 32 characters and should stay in the ASCII range to avoid trouble when passing them around.
I'm ...
5485
votes
34
answers
4.7m
views
How do I make a flat list out of a list of lists?
I have a list of lists like
[
[1, 2, 3],
[4, 5, 6],
[7],
[8, 9]
]
How can I flatten it to get [1, 2, 3, 4, 5, 6, 7, 8, 9]?
If your list of lists comes from a nested list ...
5469
votes
78
answers
4.9m
views
How can I validate an email address in JavaScript?
I'd like to check if the user input is an email address in JavaScript, before sending it to a server or attempting to send an email to it, to prevent the most basic mistyping. How could I achieve this?...
5467
votes
35
answers
5.5m
views
Regular expression to match a line that doesn't contain a word
I know it's possible to match a word and then reverse the matches using other tools (e.g. grep -v). However, is it possible to match lines that do not contain a specific word, e.g. hede, using a ...
5436
votes
37
answers
3.8m
views
How do I resolve merge conflicts in a Git repository?
How do I resolve merge conflicts in my Git repository?
5399
votes
106
answers
4.6m
views
How do I make the first letter of a string uppercase in JavaScript?
How do I make the first character of a string uppercase if it's a letter, but not change the case of any of the other letters?
For example:
"this is a test" → "This is a test"
&...
5396
votes
42
answers
850k
views
What is a plain English explanation of "Big O" notation?
I'd prefer as little formal definition as possible and simple mathematics.
5285
votes
26
answers
2.7m
views
What is the difference between INNER JOIN and OUTER JOIN?
What is the difference between INNER JOIN and OUTER JOIN?
How do LEFT OUTER JOIN, RIGHT OUTER JOIN, and FULL OUTER JOIN fit in?
5228
votes
68
answers
5.0m
views
How do I check whether a checkbox is checked in jQuery?
I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery.
For example, if the age checkbox is checked, then I need to show a textbox to enter ...
5157
votes
67
answers
3.1m
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(...
5135
votes
24
answers
851k
views
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
What is this?
This is a collection of questions that come up now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
This ...
5098
votes
127
answers
5.0m
views
How can I horizontally center an element?
How can I horizontally center a <div> within another <div> using CSS?
<div id="outer">
<div id="inner">Foo foo</div>
</div>
5097
votes
28
answers
2.6m
views
How can I delete a remote tag?
How can I delete a Git tag that has already been pushed?
5021
votes
31
answers
1.4m
views
What is the difference between a URI, a URL, and a URN? [closed]
What is the difference between a URL, a URI, and a URN?
5003
votes
63
answers
3.7m
views
How do I check if an array includes a value in JavaScript?
What is the most concise and efficient way to find out if a JavaScript array contains a value?
This is the only way I know to do it:
function contains(a, obj) {
for (var i = 0; i < a.length; i++...
4978
votes
35
answers
3.5m
views
Undo a Git merge that hasn't been pushed yet
I accidentally ran git merge some_other_branch on my local master branch. I haven't pushed the changes to origin master. How do I undo the merge?
After merging, git status says:
# On branch master
# ...
4926
votes
38
answers
4.6m
views
How do I get a timestamp in JavaScript?
I want a single number that represents the current date and time, like a Unix timestamp.
4833
votes
50
answers
1.9m
views
How do I clone all remote branches?
My master and development branches are tracked remotely on GitHub. How do I clone both these branches?
4807
votes
32
answers
1.4m
views
How do I update or sync a forked repository on GitHub?
I forked a project, made changes, and created a pull request which was accepted. New commits were later added to the repository. How do I get those commits into my fork?
4792
votes
9
answers
957k
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 is:
<...
4779
votes
36
answers
1.2m
views
What is the difference between @staticmethod and @classmethod in Python?
What is the difference between a method decorated with @staticmethod and one decorated with @classmethod?
4771
votes
67
answers
2.8m
views
How do I read / convert an InputStream into a String in Java?
If you have a java.io.InputStream object, how should you process that object and produce a String?
Suppose I have an InputStream that contains text data, and I want to convert it to a String, so for ...
4741
votes
43
answers
2.0m
views
How do I remove a submodule?
How do I remove a Git submodule?
Why can't I do
git submodule rm module_name?
4694
votes
38
answers
3.2m
views
How slicing in Python works
How does Python's slice notation work? That is: when I write code like a[x:y:z], a[:], a[::2] etc., how can I understand which elements end up in the slice?
See Why are slice and range upper-bound ...
4607
votes
44
answers
3.9m
views
Setting "checked" for a checkbox with jQuery
I'd like to do something like this to tick a checkbox using jQuery:
$(".myCheckBox").checked(true);
or
$(".myCheckBox").selected(true);
Does such a thing exist?
4548
votes
35
answers
3.5m
views
How do I check if a directory exists or not in a Bash shell script?
What command checks if a directory exists or not within a Bash shell script?
4510
votes
8
answers
605k
views
Why does Google prepend while(1); to their JSON responses?
Why does Google prepend while(1); to their (private) JSON responses?
For example, here's a response while turning a calendar on and off in Google Calendar:
while (1);
[
['u', [
['smsSentFlag', ...
4500
votes
15
answers
857k
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 ...
4498
votes
42
answers
5.7m
views
How do I delete a commit from a branch?
How do I delete a commit from my branch history? Should I use git reset --hard HEAD?
4498
votes
26
answers
951k
views
How is Docker different from a virtual machine?
I keep rereading the Docker documentation to try to understand the difference between Docker and a full VM. How does it manage to provide a full filesystem, isolated networking environment, etc. ...
4484
votes
47
answers
6.7m
views
How can I find the index for a given item in a list?
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index 1?
4459
votes
22
answers
2.4m
views
Undoing a git rebase
How do I easily undo a git rebase? A lengthy manual method is:
checkout the commit parent to both of the branches
create and checkout a temporary branch
cherry-pick all commits by hand
reset the ...
4459
votes
56
answers
2.5m
views
Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?
The following are two methods of building a link that has the sole purpose of running JavaScript code. Which is better, in terms of functionality, page load speed, validation purposes, etc.?
...
4439
votes
73
answers
1.5m
views
How do I avoid checking for nulls in Java?
I use x != null to avoid NullPointerException. Is there an alternative?
if (x != null) {
// ...
}
4420
votes
17
answers
6.1m
views
Iterating over a dictionary using a 'for' loop, getting keys
d = {'x': 1, 'y': 2, 'z': 3}
for key in d:
print(key, 'corresponds to', d[key])
How does Python recognize that it needs only to read the key from the dictionary? Is key a special keyword, or is ...
4419
votes
35
answers
1.1m
views
How can I enumerate an enum?
How can you enumerate an enum in C#?
E.g., the following code does not compile:
public enum Suit
{
Spades,
Hearts,
Clubs,
Diamonds
}
public void EnumerateAllSuitsDemoMethod()
{
...
4418
votes
42
answers
2.1m
views
Change an HTML input's placeholder color with CSS
Chrome v4 supports the placeholder attribute on input[type=text] elements (others probably do too).
However, the following CSS doesn't do anything to the placeholder's value:
input[placeholder], [...
4374
votes
132
answers
1.9m
views
How can I close/hide the Android soft keyboard programmatically?
I have an EditText and a Button in my layout.
After writing in the edit field and clicking on the Button, I want to hide the virtual keyboard when touching outside the keyboard. Can someone provide a ...
4347
votes
35
answers
1.8m
views
What are the differences between a HashMap and a Hashtable in Java?
What are the differences between a HashMap and a Hashtable in Java?
Which is more efficient for non-threaded applications?