Section 24. No part of any building used for habitation nor that part of any lot within fifty feet of any building so used shall, except as permitted by section twenty-three, be used for the storage, keeping or handling of any article or material that is or may become dangerous to the public safety as a fire menace, and no part of any such building shall be used as a carpenter shop or paint shop, nor for the storage, keeping or handling of excelsior, shavings, sawdust, cotton, paper stock, feathers or rags, except under such terms and conditions as the head of the fire department may prescribe in writing.