The courts and the judges thereof may issue attachment for contempt and punish them summarily only in the following cases: (a) Misbehavior in the presence of the court, or so near thereto as to obstruct or interrupt the administration of justice; (b) violence or threats of violence to a judge or officer of the court, or to a juror, witness, or party going to, attending or returning from the court, for or in respect of any act or proceeding had, or to be had, in such court; (c) misbehavior of an officer of the court, in his official character; (d) disobedience to or resistance of any officer of the court, juror, witness, or other person, to any lawful process, judgment, decree or order of the said court. No court shall, without a jury, for any such contempt as is mentioned in subdivision (a) of this section, impose a fine exceeding $50, or imprison more than ten days. But in any such case the court may impanel a jury (without an indictment or any formal pleading) to ascertain the fine or imprisonment proper to be inflicted, and may give judgment according to the verdict. No court shall impose a fine for contempt, unless the defendant be present in court, or shall have been served with a rule of the court to show cause, on some certain day, and shall have failed to appear and show cause.