Risk and Safety in Online Learning and Optimization: Theory and Applications