A man who threatened and called a police officer a “f***ing b***bag” has avoided jail.