A homeless man who attacked a nurse and a member of ambulance staff has been jailed for eight months.