Most Popular

1500 questions
4234
votes
1 answer

The Definitive C++ Book Guide and List

This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to…
grepsedawk
  • 5,881
  • 5
  • 23
  • 22
4195
votes
126 answers

How to 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. I assume that this is a simple piece of code, but where can I find an…
4188
votes
33 answers

How to 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() { foreach (Suit suit in Suit) { …
Ian Boyd
  • 233,966
  • 238
  • 834
  • 1,160
4176
votes
22 answers

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. without being as heavy? Why is deploying software to a…
zslayton
  • 48,617
  • 9
  • 36
  • 49
4150
votes
35 answers

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?
dmanxiii
  • 49,767
  • 10
  • 31
  • 23
4147
votes
35 answers

How do I check if a directory exists in a Bash shell script?

What command checks if a directory exists or not, within a Bash shell script?
Grundlefleck
  • 119,469
  • 24
  • 90
  • 111
4125
votes
69 answers

How do I copy to the clipboard in JavaScript?

What is the best way to copy text to the clipboard (multi-browser)? I have tried: function copyToClipboard(text) { if (window.clipboardData) { // Internet Explorer window.clipboardData.setData("Text", text); } else { …
Santiago Corredoira
  • 44,971
  • 8
  • 50
  • 56
4118
votes
34 answers

What exactly is RESTful programming?

What exactly is RESTful programming?
hasen
  • 155,371
  • 64
  • 187
  • 227
4100
votes
37 answers

How can I pair socks from a pile efficiently?

Yesterday I was pairing the socks from the clean laundry and figured out the way I was doing it is not very efficient. I was doing a naive search — picking one sock and "iterating" the pile in order to find its pair. This requires iterating over n/2…
amit
  • 172,148
  • 26
  • 225
  • 324
4088
votes
36 answers

How do I remove a submodule?

How do I remove a Git submodule? By the way, is there a reason I can't simply do git submodule rm whatever ?
R. Martinho Fernandes
  • 219,040
  • 71
  • 423
  • 503
4069
votes
37 answers

How do I UPDATE from a SELECT in SQL Server?

In SQL Server, it is possible to insert rows into a table with an INSERT.. SELECT statement: INSERT INTO Table (col1, col2, col3) SELECT col1, col2, col3 FROM other_table WHERE sql = 'cool' Is it also possible to update a table with SELECT? I…
jamesmhaley
  • 42,906
  • 8
  • 33
  • 49
4049
votes
41 answers

Finding the index of an item in a list

Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index 1?
Eugene M
  • 44,769
  • 14
  • 37
  • 43
3958
votes
41 answers

Create ArrayList from array

I have an array that is initialized like: Element[] array = {new Element(1), new Element(2), new Element(3)}; I would like to convert this array into an object of the ArrayList class. ArrayList arraylist = ???;
Ron Tuffin
  • 52,199
  • 24
  • 63
  • 76
3920
votes
14 answers

grep a file, but show several surrounding lines?

I would like to grep for a string, but also show the preceding five lines and the following five lines as well as the matched line. How would I be able to do this?
Mark Harrison
  • 283,715
  • 120
  • 322
  • 449
3913
votes
70 answers

How do I generate random integers within a specific range in Java?

How do I generate a random int value in a specific range? I have tried the following, but those do not work: Attempt 1: randomNum = minimum + (int)(Math.random() * maximum); Bug: randomNum can be bigger than maximum. Attempt 2: Random rn = new…
user42155
  • 47,097
  • 25
  • 58
  • 59