The default if code does not have any notice anywhere is that it is copyrighted, and no license is given to anyone to use it, so any use of it is a violation.
At least in the US, all creative works are copyrighted by default (such as this comment, which does not include a notice of such, but is copyrighted).
Because of that, the default assumption of anyone would be that anything is copyrighted and cannot be used for any purpose outside of fair use unless there is a specific license granting additional usage.
If they had put explicit copyright notices in the code snippets, I'd assume otherwise.
In the case of a random blog, the code likely does not have an associated license, meaning it is copyrighted and any derivative use of it (i.e. copying it) is a violation of their copyright.
In the case of stackoverflow, their ToS require people who post code to share it under a Creative Commons license [0]. Unfortunately, if the author of the post didn't realize that, it's possible they did not have the original copyright and couldn't make that assignment, so you still may have to do your own due diligence.
Where things work as intended on stackoverflow, you are required to provide attribution.
Your assumptions are backwards, and it sounds like that results in you violating copyright.
In general I suffer from NIH complex so don’t really copy code from those places ;)
Most(*) small snippets of code (e.g., 1-10 lines) on Stack Overflow are probably not copyrightable, at least not under U.S. law. You don't need a license to copy and use something that's not copyrightable.
(*) But not all. As usual, it depends.
U.S. government works are not eligible for copyright.
Some works do not have sufficient creative element to be covered by copyright, or the other user may be using only the non-covered elements of the work (factual collections, or see recipes).
But probably most important, fair use is a limitation to the exclusive rights of copyright, in spite of copyright holders' frequent assertions that "any other use without written consent is prohibited". A use may be fair even against the express wishes of a valid copyright holder, as fair use is not infringement. Factors to be evaluated in fair use include, but are limited to:
(1)the purpose and character of the use, including whether such use is of a commercial nature or is for nonprofit educational purposes;
(2)the nature of the copyrighted work;
(3)the amount and substantiality of the portion used in relation to the copyrighted work as a whole; and
(4)the effect of the use upon the potential market for or value of the copyrighted work.
https://www.copyright.gov/fair-use/https://www.law.cornell.edu/uscode/text/17/107 see 107-112 for other limitations of copyright.
A license notice provides a clear explanation of the rights and responsibilities of the user. This dissuades most any notion of "lack of intent" as the restrictions are put in your face from the start.
I have a bunch of code in a repository or set of repositories. I got confused and thought this file was one we created/had a license to reuse rather than a piece of third-party code, and thus copied it into a different project.
// Please keep this line & LICENSE: <license> <year> <name> <email>