How do I split a string in Java?
I want to split the string `"004-034556"` into two strings by the delimiter `"-"`: ``` part1 = "004"; part2 = "034556"; ``` That means the first string will contain the characters before `'-'`, and t...
How do I check if a list is empty?
For example, if passed the following: ``` a = [] ``` How do I check to see if `a` is empty?
Convert string "Jun 1 2005 1:33PM" into datetime
How do I convert the following string to a [datetime](https://docs.python.org/3/library/datetime.html#datetime-objects) object? ``` "Jun 1 2005 1:33PM" ```
How do I compare strings in Java?
I've been using the `==` operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into `.equals()` instead, and it fixed the bug. Is `==` bad? When shou...
How can I validate an email address in JavaScript?
I'd like to check if the user input is an email address in JavaScript, before sending it to a server or attempting to send an email to it, to prevent the most basic mistyping. How could I achieve this...
- Modified
- 28 Jul at 07:55
Find the current directory and file's directory
How do I determine: 1. the current directory (where I was in the shell when I ran the Python script), and 2. where the Python file I am executing is?
How do I perform an IF...THEN in an SQL SELECT?
How do I perform an `IF...THEN` in an `SQL SELECT` statement? For example: ``` SELECT IF(Obsolete = 'N' OR InStock = 'Y' ? 1 : 0) AS Saleable, * FROM Product ```
- Modified
- 26 Mar at 06:9
How do I replace all occurrences of a string in JavaScript?
Given a string: ``` s = "Test abc test test abc test test test abc test test abc"; ``` This seems to only remove the first occurrence of `abc` in the string above: ``` s = s.replace('abc', ''); ``` ...
- Modified
- 24 Jul at 23:55
What does if __name__ == "__main__": do?
What does this do, and why should one include the `if` statement? ``` if __name__ == "__main__": print("Hello, World!") ``` --- [Why is Python running my module when I import it, and how do I ...
- Modified
- 14 Nov at 02:6
How do I execute a program or call a system command?
How do I call an external command within Python as if I had typed it in a shell or command prompt?
- Modified
- 15 Dec at 01:6
How do I delete a commit from a branch?
How do I delete a commit from my branch history? Should I use `git reset --hard HEAD`?
- Modified
- 8 Jul at 04:44
How do I vertically center text with CSS?
I have a `<div>` element which contains text and I want to align the contents of this `<div>` vertically center. Here is my `<div>` style: ``` #box { height: 170px; width: 270px; background: #00...
- Modified
- 16 Sep at 07:13
`git fetch` a remote branch
The remote repository contains various branches such as `origin/daves_branch`: ``` $ git branch -r origin/HEAD -> origin/master origin/daves_branch origin/master ``` How do I switch to `daves_branch`...
- Modified
- 19 Feb at 18:25
How do I get the current time?
How do I get the current time?
How to round to at most 2 decimal places, if necessary
I'd like to round at most two decimal places, but . Input: ``` 10 1.7777777 9.1 ``` Output: ``` 10 1.78 9.1 ``` How can I do this in JavaScript?
- Modified
- 5 May at 15:28
How do I test for an empty JavaScript object?
After an AJAX request, sometimes my application may return an empty object, like: ``` var a = {}; ``` How can I check whether that's the case?
- Modified
- 17 Jan at 13:22
How do I POST JSON data with cURL?
I use Ubuntu and installed [cURL](https://en.wikipedia.org/wiki/CURL) on it. I want to test my Spring REST application with cURL. I wrote my POST code at the Java side. However, I want to test it with...
- Modified
- 3 Oct at 19:34
Message 'src refspec master does not match any' when pushing commits in Git
I clone my repository with: ``` git clone ssh://xxxxx/xx.git ``` But after I change some files and `add` and `commit` them, I want to push them to the server: ``` git add xxx.php git commit -m "TE...
- Modified
- 25 Dec at 22:18
How do I get a timestamp in JavaScript?
I want a single number that represents the current date and time, like a [Unix timestamp](https://en.wikipedia.org/wiki/Unix_time).
- Modified
- 7 Aug at 21:40
What is a NullPointerException, and how do I fix it?
What are Null Pointer Exceptions (`java.lang.NullPointerException`) and what causes them? What methods/tools can be used to determine the cause so that you stop the exception from causing the program...
- Modified
- 26 May at 16:15
Using global variables in a function
How do I create or use a global variable inside a function? How do I use a global variable that was defined in one function inside other functions? --- `global``UnboundLocalError`[UnboundLocalError...
- Modified
- 9 Sep at 14:53
How do I make a flat list out of a list of lists?
I have a list of lists like `[[1, 2, 3], [4, 5, 6], [7], [8, 9]]`. How can I flatten it to get `[1, 2, 3, 4, 5, 6, 7, 8, 9]`? --- [python list comprehensions; compressing a list of lists?](https://...
- Modified
- 10 Sep at 09:22
Get the full URL in PHP
I use this code to get the full URL: ``` $actual_link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; ``` The problem is that I use some masks in my `.htaccess`, so what we see in the URL i...
Accessing the index in 'for' loops
How do I access the index while iterating over a sequence with a `for` loop? ``` xs = [8, 23, 45] for x in xs: print("item #{} = {}".format(index, x)) ``` Desired output: ``` item #1 = 8 item #2...
How do I get the row count of a Pandas DataFrame?
How do I get the number of rows of a pandas dataframe `df`?