You can use the code I've posted on StackOverflow and other StackExchange sites under CC0 license (or alternatively under MIT or ISC, if CC0 is not suitable in your situation).
Basically this means that you can freely copy it and paste into your open-source or proprietary project without any consequences. You don't have to put my name anywhere. However, I recommend you put links to relevant pages for future reference.