On the similarities between generalized rank and Hamming weights and their applications to network coding