The code posted is licensed under Creative Commons 4.0 BY-SA (or 3.0, it's complicated).
Both versions of this license allow you to use it in a commercial manner.
1 As it turns out, I'm not a lawyer and the situation it actually a lot more complicated than it might seem. The general gist is that users who signed up during the 3.0 era agreed that their posts would be published under CC-BY-SA 3.0. StackExchange, Inc. unilaterally decided that they would relicense everything under CC-BY-SA 4.0, which may not have been legal.
So the actual license status is...questionable. I personally have never heard of anyone getting sued for copying code from Stack Exchange or Stack Overflow. A gut feeling tells me that most people who post code as answers are inherently okay with that code being used. It's kind of the point of the website.
My personal opinion is you'll likely be fine, but if you absolutely need to be 100% sure, you should call a lawyer.