In general, the code - as you have written it - is your property, and the smart idea is not.
By submitting the code to StackOverflow, you are exercising a right of ownership. According to their terms, you give them irrevocable rights to publish and license the code onwards, etc.
The problem is that you may have not had the right to grant that license in the first place.