In Act 2, Scene 2, Line 173
For if the sun breed maggots in a dead dog
The sun is a star. While its warmth and distance from the Earth helps create the perfect environment for life to thrive, it cannot breed. Hamlet's use of the word personifies the sun, giving it a quality that humans and other living creatures have (the ability to procreate). Logically, the sun doesn't breed the maggots in the dog—but it creates a perfect environment for it to thrive. This use of personification simplifies the science behind what Hamlet is saying while creating the image of the sun doing something only living creatures can do.
In Act 2, Scene 2, Lines 432 and 433
Striking too short at Greeks. His antique sword,
Rebellious to his arm, lies where it falls
Swords are inanimate objects; they can't be rebellious. The use of personification here was Shakespeare's way of describing a sword that's ineffective—one that this person is having trouble using. Instead of saying it doesn't work, Shakespeare calls it rebellious. This personifies the sword and creates a different image as opposed to "his antique sword, which he had trouble swinging, fell."