I hope you remember the post on HTML character entities regarding this topic I wrote earlier. Below is one more method to write codes in your posts so that it does not work like a code but it looks like a box and can be copied and pasted to some other template file.
You can use pre (<pre>) tag in your post to embed your coding’s. This tag will “EXACTLY” show as it is. Exactly means it will not make any change in the display. Hence, be careful and have a check before you fully publish it.