Most Popular
1500 questions
1116
votes
23 answers
Why can't variables be declared in a switch statement?
I've always wondered this - why can't you declare variables after a case label in a switch statement? In C++ you can declare variables pretty much anywhere (and declaring them close to first use is obviously a good thing) but the following still…

Rob
- 76,700
- 56
- 158
- 197
1115
votes
18 answers
Shell: How to call one shell script from another shell script?
I have two shell scripts, a.sh and b.sh.
How can I call b.sh from within the shell script a.sh?

Praveen
- 11,459
- 4
- 16
- 7
1115
votes
45 answers
How to add dividers and spaces between items in RecyclerView
This is an example of how it could have been done previously in the ListView class, using the divider and dividerHeight parameters:

EyesClear
- 28,077
- 7
- 32
- 43
1114
votes
13 answers
How can I trigger the same function from multiple events with jQuery?
Is there a way to have keyup, keypress, blur, and change events call the same function in one line or do I have to do them separately?
The problem I have is that I need to validate some data with a db lookup and would like to make sure validation is…

shaneburgess
- 15,702
- 15
- 47
- 66
1114
votes
13 answers
In Bash, how can I check if a string begins with some value?
I would like to check if a string begins with "node" e.g. "node001". Something like
if [ $HOST == node* ]
then
echo yes
fi
How can I do it correctly?
I further need to combine expressions to check if HOST is either "user1" or begins with…

Tim
- 1
- 141
- 372
- 590
1114
votes
38 answers
What is the difference between a port and a socket?
This was a question raised by one of the software engineers in my organisation. I'm interested in the broadest definition.

Richard Dorman
- 23,170
- 16
- 45
- 49
1113
votes
16 answers
How to link to part of the same document in Markdown?
I am writing a large Markdown document and would like to place a table of contents of sorts at the beginning that will provide links to various locations in the document. How can I do this?
I tried using:
[a link](# MyTitle)
where MyTitle is a…

recipriversexclusion
- 13,448
- 6
- 34
- 45
1113
votes
53 answers
Format JavaScript date as yyyy-mm-dd
I have a date with the format Sun May 11,2014. How can I convert it to 2014-05-11 using JavaScript?
function taskDate(dateMilli) {
var d = (new Date(dateMilli) + '').split(' ');
d[2] = d[2] + ',';
return [d[0], d[1], d[2],…

user3625547
- 11,159
- 3
- 12
- 6
1113
votes
10 answers
How do I check file size in Python?
How do I get the size of a file in Python?

5YrsLaterDBA
- 33,370
- 43
- 136
- 210
1113
votes
23 answers
How can I get the current stack trace in Java?
How do I get the current stack trace in Java, like how in .NET you can do Environment.StackTrace?
I found Thread.dumpStack() but it is not what I want - I want to get the stack trace back, not print it out.

ripper234
- 222,824
- 274
- 634
- 905
1113
votes
16 answers
Find which version of package is installed with pip
Using pip, is it possible to figure out which version of a package is currently installed?
I know about pip install XYZ --upgrade but I am wondering if there is anything like pip info XYZ. If not what would be the best way to tell what version I am…

Alexis
- 23,545
- 19
- 104
- 143
1112
votes
17 answers
Update Git submodule to latest commit on origin
I have a project with a Git submodule. It is from an ssh://... URL, and is on commit A. Commit B has been pushed to that URL, and I want the submodule to retrieve the commit, and change to it.
Now, my understanding is that git submodule update…

Thanatos
- 42,585
- 14
- 91
- 146
1112
votes
13 answers
Get the value in an input text box
What are the ways to get and render an input value using jQuery?
Here is one:
$(document).ready(function() {
$("#txt_name").keyup(function() {
alert($(this).val());
});
})