Most Popular

1500 questions
3615
votes
11 answers

What does the explicit keyword mean?

What does the explicit keyword mean in C++?
Skizz
  • 69,698
  • 10
  • 71
  • 108
3611
votes
14 answers

What is __init__.py for?

What is __init__.py for in a Python source directory?
Mat
  • 82,161
  • 34
  • 89
  • 109
3609
votes
62 answers

How can I pretty-print JSON in a shell script?

Is there a (Unix) shell script to format JSON in human-readable form? Basically, I want it to transform the following: { "foo": "lorem", "bar": "ipsum" } ... into something like this: { "foo": "lorem", "bar": "ipsum" }
AnC
3589
votes
39 answers

What is dependency injection?

There have been several questions already posted with specific questions about dependency injection, such as when to use it and what frameworks are there for it. However, What is dependency injection and when/why should or shouldn't it be used?
AR.
  • 39,615
  • 9
  • 44
  • 52
3587
votes
10 answers

Does Python have a string 'contains' substring method?

I'm looking for a string.contains or string.indexof method in Python. I want to do: if not somestring.contains("blah"): continue
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
3585
votes
33 answers

When to use LinkedList over ArrayList in Java?

I've always been one to simply use: List names = new ArrayList<>(); I use the interface as the type name for portability, so that when I ask questions such as this, I can rework my code. When should LinkedList be used over ArrayList and…
sdellysse
  • 39,108
  • 9
  • 25
  • 24
3553
votes
48 answers

How do I loop through or enumerate a JavaScript object?

I have a JavaScript object like the following: var p = { "p1": "value1", "p2": "value2", "p3": "value3" }; How do I loop through all of p's elements (p1, p2, p3...) and get their keys and values?
Tanmoy
  • 44,392
  • 16
  • 45
  • 55
3534
votes
22 answers

403 Forbidden vs 401 Unauthorized HTTP responses

For a web page that exists, but for which a user does not have sufficient privileges (they are not logged in or do not belong to the proper user group), what is the proper HTTP response to serve? 401 Unauthorized? 403 Forbidden? Something else? What…
3528
votes
32 answers

Git refusing to merge unrelated histories on rebase

During git rebase origin/development the following error message is shown from Git: fatal: refusing to merge unrelated histories Error redoing merge 1234deadbeef1234deadbeef My Git version is 2.9.0. It used to work fine in the previous version.…
Shubham Chaudhary
  • 47,722
  • 9
  • 78
  • 80
3526
votes
77 answers

Why is the Android emulator so slow? How can we speed up the Android emulator?

I have got a 2.67  GHz Celeron processor, and 1.21  GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android Emulator should start fairly quickly on such a machine, but for me, it doesn't. I have followed all the…
Andrie
  • 3,451
  • 3
  • 16
  • 3
3521
votes
29 answers

Commit only part of a file's changes in Git

When I make changes to a file in Git, how can I commit only some of the changes? For example, how could I commit only 15 lines out of 30 lines that have been changed in a file?
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106
3520
votes
30 answers

How do I list all the files in a commit?

How can I print a plain list of all files that were part of a given commit? Although the following lists the files, it also includes unwanted diff information for each: git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
Philip Fourie
  • 111,587
  • 10
  • 63
  • 83
3479
votes
30 answers

How do I convert a String to an int in Java?

How can I convert a String to an int? "1234" → 1234
Unknown user
  • 44,551
  • 16
  • 38
  • 42
3478
votes
30 answers

How to concatenate string variables in Bash

In PHP, strings are concatenated together as follows: $foo = "Hello"; $foo .= " World"; Here, $foo becomes "Hello World". How is this accomplished in Bash?
Strawberry
  • 66,024
  • 56
  • 149
  • 197
3478
votes
21 answers

How can I add new keys to a dictionary?

How do I add a new key to an existing dictionary? It doesn't have an .add() method.
lfaraone
  • 49,562
  • 17
  • 52
  • 70