The primer actually explains how it works just not the actual code.
As far as actual code goes I can explain again the logic of it, how to actually do it will depend on the language you choose.
The first thing for cloaking is to have a reason that you want to show someone different content than they are requesting. This also includes specific information based on who the user is.
The example used in the primer is language specific content based on browser language settings. You could also have country specific content which you would like to serve to users identifiable to a certain country of residence.
We need to figure out what information will identify these people as needing specific content. The two scenarios have similar testing params
1. for language you need to test the browser for a language setting and respond accordingly
2. you would need to get the ip and attribute it to a certain country
steps would be something like
1. You get the info you are testing for from the user
2. compare info with the options you have stored (db probably)
3. get content intende for this type of user or send default
4. serve the page
It isn't really tough but it all depends on what you are cloaking for. There are also other types of users you can target with specific content obviously but the general scenario remains the same.