Differential geometry construction of anomalies and topological invariants in various dimensions