Reprogram Leonardo with Mega2560

I accidentally wrote a stupid piece of code on my leonardo that now will endlessly print the letter d and put my mouse in a certain place, and I cant upload a blank sketch to stop it because of this. I want to reprogram it via the pins with my mega2560. Is this possible? I could not find a tutorial online that didn't require extra equipment. If not, is there a way to clear the sketch off of it?

Thanks.

Plug it in and double-tap reset on the leo to make it stay in the bootloader, and upload a clean sketch to it.