Most Popular
1500 questions
2762
votes
38 answers
Extract filename and extension in Bash
I want to get the filename (without extension) and the extension separately.
The best solution I found so far is:
NAME=`echo "$FILE" | cut -d'.' -f1`
EXTENSION=`echo "$FILE" | cut -d'.' -f2`
This is wrong because it doesn't work if the file name…
ibz
- 44,461
- 24
- 70
- 86
2751
votes
93 answers
Generate random string/characters in JavaScript
I want a 5 character string composed of characters picked randomly from the set [a-zA-Z0-9].
What's the best way to do this with JavaScript?
Tom Lehman
- 85,973
- 71
- 200
- 272
2743
votes
48 answers
Compare two dates with JavaScript
Can someone suggest a way to compare the values of two dates greater than, less than, and not in the past using JavaScript? The values will be coming from text boxes.
Alex
- 39,265
- 21
- 45
- 42
2739
votes
22 answers
How to sort a list of dictionaries by a value of the dictionary in Python?
How do I sort a list of dictionaries by a specific key's value? Given:
[{'name': 'Homer', 'age': 39}, {'name': 'Bart', 'age': 10}]
When sorted by name, it should become:
[{'name': 'Bart', 'age': 10}, {'name': 'Homer', 'age': 39}]
masi
- 118
- 3
- 5
- 9
2734
votes
40 answers
How do I install pip on Windows?
pip is a replacement for easy_install. But should I install pip using easy_install on Windows? Is there a better way?
mit
- 11,083
- 11
- 50
- 74
2731
votes
92 answers
Get all unique values in a JavaScript array (remove duplicates)
I have an array of numbers that I need to make sure are unique. I found the code snippet below on the internet and it works great until the array has a zero in it. I found this other script here on Stack Overflow that looks almost exactly like it,…
Mottie
- 84,355
- 30
- 126
- 241
2730
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
- 33,492
- 33
- 111
- 169
2726
votes
20 answers
How do I refresh a page using JavaScript?
How do I refresh a page using JavaScript?
luca
- 36,606
- 27
- 86
- 125
2717
votes
55 answers
How do I import an SQL file using the command line in MySQL?
I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the command line.
I have a Windows Server 2008 R2 installation. I placed the .sql file on the C drive, and I tried this command
database_name <…
Jaylen
- 39,043
- 40
- 128
- 221
2710
votes
57 answers
How to upgrade all Python packages with pip
Is it possible to upgrade all Python packages at one time with pip?
Note: that there is a feature request for this on the official issue tracker.
thedjpetersen
- 27,857
- 4
- 26
- 28
2709
votes
25 answers
How do I get the last element of a list?
How do I get the last element of a list?
Which way is preferred?
alist[-1]
alist[len(alist) - 1]
Janusz
- 187,060
- 113
- 301
- 369
2709
votes
33 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
For the reverse, see Convert integer to string in Python and Converting a float to a string without rounding it.
Please instead use…
Tristan Havelick
- 67,400
- 20
- 54
- 64
2708
votes
64 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
- 29,385
- 5
- 19
- 15
2707
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
- 172,118
- 50
- 264
- 308
2699
votes
32 answers
Check if a variable is a string in JavaScript
How can I determine whether a variable is a string or something else in JavaScript?
Olical
- 39,703
- 12
- 54
- 77