Was writing some code the other day, and then wanted to have similar functionality in a different area of the codebase. I did not want to directly copy and paste, as I consider this to be a very recognizable code smell. Basically, copying and pasting is a clear indicator that there is similar structure that is not being realized. It is similar to making up really complicated equations and models for why planets in the sky do loop-de-loops, and then understanding that they all revolve around the sun. That understanding simplifies things.
However, it was tough to think about what needed to be abstracted out of the solution that I was going to use. What I did was to copy the original to another area, change it to work in that context, and then factor out the common parts as best as possible to a library function. I expect to use this function a few times, so this seems to make the most sense from a flexibility and maintenance perspective.