Most Popular
1500 questions
2265
votes
32 answers
How do I generate a random int number?
How do I generate a random integer in C#?
Rella
- 62,177
- 103
- 350
- 621
2261
votes
4 answers
What does the ??!??! operator do in C?
I saw a line of C that looked like this:
!ErrorHasOccured() ??!??! HandleError();
It compiled correctly and seems to run ok. It seems like it's checking if an error has occurred, and if it has, it handles it. But I'm not really sure what it's…
Peter Olson
- 131,160
- 48
- 197
- 239
2261
votes
11 answers
How to replace a character by a newline in Vim
I'm trying to replace each , in the current file by a new line:
:%s/,/\n/g
But it inserts what looks like a ^@ instead of an actual newline. The file is not in DOS mode or anything.
What should I do?
If you are curious, like me, check the question…
Vinko Vrsalovic
- 253,260
- 52
- 326
- 367
2259
votes
38 answers
Finding duplicate values in a SQL table
It's easy to find duplicates with one field:
SELECT email, COUNT(email)
FROM users
GROUP BY email
HAVING COUNT(email) > 1
So if we have a table
ID NAME EMAIL
1 John asd@asd.com
2 Sam asd@asd.com
3 Tom asd@asd.com
4 Bob …
Alex
- 32,503
- 25
- 86
- 132
2257
votes
31 answers
How to get an enum value from a string value in Java
Say I have an enum which is just
public enum Blah {
A, B, C, D
}
and I would like to find the enum value of a string, for example "A" which would be Blah.A. How would it be possible to do this?
Is the Enum.valueOf() the method I need? If so,…
Malachi
- 31,986
- 17
- 62
- 96
2255
votes
35 answers
What's the simplest way to print a Java array?
In Java, arrays don't override toString(), so if you try to print one directly, you get the className + '@' + the hex of the hashCode of the array, as defined by Object.toString():
int[] intArray = new int[] {1, 2, 3, 4,…
Alex Spurling
- 51,267
- 23
- 67
- 73
2248
votes
12 answers
Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?
I am doing some numerical optimization on a scientific application. One thing I noticed is that GCC will optimize the call pow(a,2) by compiling it into a*a, but the call pow(a,6) is not optimized and will actually call the library function pow,…
xis
- 23,504
- 9
- 41
- 58
2244
votes
71 answers
How do I center text horizontally and vertically in a TextView?
How do I center the text horizontally and vertically in a TextView, so that it appears exactly in the middle of the TextView in Android?
pupeno
- 267,428
- 120
- 345
- 578
2244
votes
31 answers
How do you parse and process HTML/XML in PHP?
How can one parse HTML/XML and extract information from it?
RobertPitt
- 55,891
- 21
- 113
- 158
2243
votes
5 answers
What is the copy-and-swap idiom?
What is this idiom and when should it be used? Which problems does it solve? Does the idiom change when C++11 is used?
Although it's been mentioned in many places, we didn't have any singular "what is it" question and answer, so here it is. Here is…
GManNickG
- 478,574
- 51
- 478
- 539
2234
votes
47 answers
How to concatenate text from multiple rows into a single text string in SQL Server
Consider a database table holding names, with three rows:
Peter
Paul
Mary
Is there an easy way to turn this into a single string of Peter, Paul, Mary?
JohnnyM
- 27,076
- 10
- 35
- 36
2228
votes
27 answers
How to write a switch statement in Ruby
How do I write a switch statement in Ruby?
readonly
- 326,166
- 107
- 202
- 204
2224
votes
18 answers
Calling a function of a module by using its name (a string)
How do I call a function, using a string with the function's name? For example:
import foo
func_name = "bar"
call(foo, func_name) # calls foo.bar()
ricree
- 33,639
- 13
- 34
- 27
2223
votes
9 answers
What is the purpose of .PHONY in a Makefile?
What does .PHONY mean in a Makefile? I have gone through this, but it is too complicated.
Can somebody explain it to me in simple terms?
Lazer
- 85,489
- 111
- 272
- 354
2222
votes
25 answers
How to change the cursor into a hand when a user hovers over a list item?
I've got a list, and I have a click handler for its items:
- foo
- goo
user246114
- 48,235
- 41
- 111
- 147