“Code” refers to language here. Both code mixing and code switching are only possible in case of bilinguals (or multi-linguals), i.e. people who know at least two (or more than two) languages.
Code mixing is simply mixing of two or more languages while communicating. Now, it is common for a speaker who knows two or more languages to take one word or more than one word from one language and introduce it while speaking another language.
If I know French as well as English, for example, there will be times when I will mix some English words in my French sentences. That’s, in fact, very common. Languages have this kind of affect on other languages. It is rare for Bilinguals to utter sentences that belong to purely one language.
One or few words are generally borrowed. Sometimes, it is because the speaker remembers a particular word in one language but, at that moment, isn’t able to use the parallel word in the language he is using. This happens generally in speech. Writing, which is more formal and careful presentation of speech, is generally free of code mixing and code switching (but it is still possible when there is a special requirement, for example, when adding some special, humorous effect, or in case it is an advertisement and marketing strategy etc.).
Code switching is similar to code mixing in that there is combination of two languages (in fact, many use the two terms interchangeably), but there is a small difference. In a single conversation if a language speaker who is speaking, for example, English switches to French (and again to English, may be), it will be code switching.
Here, the speaker is not mixing just a few words of one language in between the other language. He is speaking one language and then switching to another language. One sentence is spoken in one language and the second in another and so on.
Sometimes, there may not be a sharp boundary. One phrase of a single sentence might be in one language and the second in a different language. Note that in the latter case, the two phrases (one in English and second in French, for example) will be consistent in tense, number, etc.
Also, please note that I have taken the example of English and French, but code mixing and code switching is possible between all languages.