I make such cuts and pastes into my favourite text editor, named appropriately, where I can then carefully look for extraneous characters, and ensure that I'll be running what I expect to be running. I'm strongly adverse to cutting and pasting code snippets into an interactive shell: who knows what extra commands might be picked up by the cut & paste operation?
Once your text file has the verified commands saved, they can then be executed with the built-in command
source <filename>