Most of the examples of code you gave are trivial pieces of code, not expressions of "art". Copyrights isn't intended to protect trivial things (e.g. you cannot copyright "howdy!"), more elaborate expressions (like e.g. a speech you give for accepting your webby award), are perfectly copyrighted, from the moment you create it.
Copyright is automatic, you do not need (and outside the US you even cannot) register or need to claim it, by creating the "work of art" it is automatically yours. You can donate the rights away to the public domain if you would choose to do so.
All software by definition falls under copyright rules.