Check the faq for the ethiopian part they have very good threads
Thailand was a buffer state, separating British controlled Asia with french controlled indo-china. They were also united and had a strong army, their economy wasn't that bad either. Another thing is they would use the other as a bargaining chip, if France tried to invade them, they would say Britain wouldn't like it very much, and the same the other way around.
They did lose some bits of land to each, but the majority of the country was kept under control by Thailand(Siam at the time)
King Chulalongkorn gets much of the popular and academic credit for maintaining Thai sovereignty in Thai accounts of this issue. While giving the king this much credit is easy to question given that criticism of the monarchy is difficult in Thailand and given that royal patronage is responsible for an awful lot of scholarship (especially before about 1930) the poplar narrative isn't inaccurate.
Chula studied in Switzerland and upon returning to rule set about massive modernization projects in his kingdom, no doubt because of exposure he had to prevailing European opinions as to Asia and other colonial targets at the time. He rapidly modernized the military, established much stronger trade relations, promulgated a new dress code among his citizens (there are easy to find images of posters from that time telling people to not dress up in old fashioned sarongs but instead in very British looking shirts and pants) and famously asked his wife to grow her hair long (Thai women before then kept their hair short, just like the men). Chula was also a remarkable diplomat and had a strong group of excellent and trusted advisors and his ability to play the French in Cambodia against the British in Burma was, in my option, more responsible for maintaining Thai independence than the other already mentioned measures. To this day only two Thai monarchs are generally referred to in spoken Thai by using the most honorific titular prefix of "Tan" (perhaps "His Holiness" as generally only monks are referred to this way), Chulalongkorn and the current king (Chula's great grandson).
It's important to remember, however, that Thailand hardly escaped from colonialism unschathed. If you look at maps of Siam before the French and English got there you will see that Cambodia is a tiny blob and Burma barely a sliver. Of course these maps are from Thai accounts, but at that point in history after endless alternating wars between the two fronts Thailand had all but crushed opposing rule in those neighboring nations and was the clear regional superpower (again, interestingly, because of the nature of warfare in a densely vegetated pre-industrial world, these victories were sealed more by political adroitness than military might). Thailand lost not only huge land concessions to France and England but was also forced into a lot of very disadvantageous trade agreements that would persist for a very long time (the British in particular were loathe to enter into any fairer an agreement) that would essentially halt Thailand's development relative to other countries in Asia (notably Japan) that most experts at the time would have placed on more even footing. Thailand's close association with America to this day (American nationals are the only foreigners allowed to own a home and the land underneath it in Thailand -- everyone else has to enter into weird legal fictions or 99 year leases) is due to America being the first to release Thailand from these lopsided agreements, which was immediately used by Thailand as leverage to get out of the other ones.
There are surprisingly few written histories of Thailand and almost all have an obvious pro-monarchy slant, which is however generally admitted to and given that Thailand has had generally very good monarchs (IMO) not as big a problem as it could be in other places. Anyway, the best place to start is Baker and Phongpaichit's "A History of Thailand," published by Cambridge University.