Most Popular
1500 questions
2677
votes
29 answers
Do I cast the result of malloc?
In this question, someone suggested in a comment that I should not cast the result of malloc. i.e., I should do this:
int *sieve = malloc(sizeof(*sieve) * length);
rather than:
int *sieve = (int *) malloc(sizeof(*sieve) * length);
Why would this…
Patrick McDonald
- 62,076
- 14
- 100
- 117
2661
votes
31 answers
2659
votes
36 answers
How do I check if a string contains a specific word?
Consider:
$a = 'How are you?';
if ($a contains 'are')
echo 'true';
Suppose I have the code above, what is the correct way to write the statement if ($a contains 'are')?
Charles Yeung
- 37,627
- 28
- 87
- 130
2659
votes
26 answers
Is there an equivalent of 'which' on the Windows command line?
As I sometimes have path problems, where one of my own cmd scripts is hidden (shadowed) by another program (earlier on the path), I would like to be able to find the full path to a program on the Windows command line, given just its name.
Is there…
namin
- 35,819
- 8
- 57
- 74
2656
votes
23 answers
How to change the commit author for one specific commit?
I want to change the author of one specific commit in the history. It's not the last commit.
I know about this question - How do I change the author of a commit in git?
But I am thinking about something, where I identify the commit by hash or…
MicTech
- 38,947
- 14
- 59
- 79
2656
votes
13 answers
How do I make Git ignore file mode (chmod) changes?
I have a project in which I have to change the mode of files with chmod to 777 while developing, but which should not change in the main repo.
Git picks up on chmod -R 777 . and marks all files as changed. Is there a way to make Git ignore mode…
Marcus Westin
- 26,901
- 4
- 16
- 11
2655
votes
14 answers
Why shouldn't I use mysql_* functions in PHP?
What are the technical reasons for why one shouldn't use mysql_* functions? (e.g. mysql_query(), mysql_connect() or mysql_real_escape_string())?
Why should I use something else even if they work on my site?
If they don't work on my site, why do I…
Madara's Ghost
- 165,920
- 50
- 255
- 304
2628
votes
66 answers
How can I fix 'android.os.NetworkOnMainThreadException'?
I got an error while running my Android project for RssReader.
Code:
URL url = new URL(urlToRssFeed);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader xmlreader =…
bejoy george
- 28,415
- 5
- 16
- 15
2610
votes
27 answers
Can (a== 1 && a ==2 && a==3) ever evaluate to true?
Moderator note: Please resist the urge to edit the code or remove this notice. The pattern of whitespace may be part of the question and therefore should not be tampered with unnecessarily. If you are in the "whitespace is insignificant" camp, you…
Dimpu Aravind Buddha
- 8,897
- 4
- 16
- 23
2610
votes
30 answers
How do I parse a string to a float or int?
How can I convert a str to float?
"545.2222" → 545.2222
How can I convert a str to int?
"31" → 31
Tristan Havelick
- 63,483
- 19
- 53
- 64
2608
votes
43 answers
How can I transition height: 0; to height: auto; using CSS?
I am trying to make a
- slide down using CSS transitions.
The
- starts off at height: 0;. On hover, the height is set to height:auto;. However, this is causing it to simply appear, not transition,
If I do it from height: 40px; to height:…
Hailwood
- 85,177
- 105
- 260
- 417
2605
votes
32 answers
Open a URL in a new tab (and not a new window)
I'm trying to open a URL in a new tab, as opposed to a popup window.
I've seen related questions where the responses would look something like:
window.open(url,'_blank');
window.open(url);
But none of them worked for me, the browser still tried to…
Mark
- 36,479
- 11
- 40
- 47
2599
votes
37 answers
How do I vertically center text with CSS?
I have a
element which contains text and I want to align the contents of this
vertically center.
Here is my
style:
#box {
height: 170px;
width: 270px;
background: #000;
font-size: 48px;
color: #FFF;
text-align:…
Irakli Lekishvili
- 32,032
- 33
- 109
- 169
2599
votes
51 answers
Does a finally block always get executed in Java?
Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is?
try {
something();
return success;
}
catch (Exception e) {
return failure;
}
finally {
…
jonny five
- 26,422
- 3
- 19
- 11
2592
votes
42 answers
Add table row in jQuery
What is the best method in jQuery to add an additional row to a table as the last row?
Is this acceptable?
$('#myTable').append('my data more data ');
Are there limitations to what you can add to a table like this (such as…
Darryl Hein
- 138,721
- 89
- 210
- 259