I'd argue that people who open-source code expect other people to learn from it in a small way of snippets and that constitutes fair-use.
https://stackoverflow.com/help/licensing
Copying code samples from a copyrighted work for use in a commercial product is not fair use.
I'd argue that people who open-source code expect other people to learn from it in a small way of snippets and that constitutes fair-use.