A 27-year-old man who racially abused a woman and launched a violent attack on a stranger has been locked up.