Stackoverflow code has a license (not per post, but a blanket one depending on which year - https://stackoverflow.com/help/licensing it's mostly CC BY-SA.) I've written corporate policies that emphasize that you can learn from SO answers, but (as you point out) they basically never fit exactly - and you should include a link to the original so when the next Ubuntu LTS breaks your clever hack, we can see if someone has already posted a fix :-)