The general idea of these two sentences is: make friends with people with high status, don't flatter; Make friends with people with low status, don't despise them.
These two poems, "Making friends is not flattering, making friends is not profane", come from the Book of Changes.