You have to figure out how the code is made available. If you find code posted on the web somewhere without a license you must assume that it's not meant to be used. However, for small code fragments (such as are commonly posted on stackoverflow) I think you're OK. Using code you didn't write in a contest or for a homework assignment is plagiarism (you're claiming it's your work when it's not) and you shouldn't do it. For use on "real projects", i.e. commercially, read the license and see what it tells you.
For things I've written and have posted on my site for reuse, I make sure that each chunk of code has a copy of the license (I favor the MIT license, which essentially says you can do anything you want with the code except claim that you wrote it).
I hope this helps.