From my understanding, it's fine to copy Stack Overflow code so long as you fully understand it (so as to not copy vulnerabilities, etc). I am wondering what the proper way to attribute code is if I have copied it. Previously I have just added a comment with a URL to the source, but I also know that the site's content is licensed under CC BY-SA 4.0: https://creativecommons.org/licenses/by-sa/4.0/. I find the requirements a bit complicated (copywrite notice, license notice, disclaimer notice, ...). In practice, do I need all that for a small bit of code, or does a URL suffice?
Apologies if this is the wrong sort of question for Stack Overflow.
An example of the sort of credit expected under the license: