Generalized symmetries in mechanics and field theories