Sometimes being counter picked can't be avoided (because you're first pick, or your teammates are unwilling/unable to trade). So when you get counter picked mid/top, what is the best way to deal with it?
There are a couple of things you can do, and many of these apply to just general playing the game, not only when counterpicked.
Learn to farm under the tower. Its pretty hard to do in some cases, and takes a fair bit of practice. There are a couple of guides around about how to do it, but nothing beats practicing, even if its in a custom game.
Try and guess who you will be facing and change your runes if possible. I have to admit I'm terrible at this and generally build my rune pages with some form of AR/MR by default (and cause I'm too lazy to switch runes)
Play passively and wait for them to make a mistake. A lot of players get really annoyed when you sit by your tower and farm minions, and eventually the frustration gets the better of them. This is especially true of champions that are generally really strong early game, as they are used to getting lots of kills. If you get counterpicked and you manage to still farm, and harass them occassionally, and get through laning phase without dying, then its more than anyone could expect of you.
Dont be a slave to the meta. Just because you picked Ryze doesnt mean you have to go mid. If you were counter picked severly, or even if you are just being outplayed, ask for a switch. It can make things a little more difficult, having people play in lanes they arent used to, but you may even find that switching it up like that is enough to throw the enemy team off. LB expecting Ryze in mid and finding Cait might just be enough to give Cait an edge.
Ask for help. It's a team game, and if you are having issues helping the team, then its better to swallow your pride and ask for help than remain silent and feed. Some people will always be assholes and give you grief for asking for help, but most of the time your team will understand.
Change up your item build. Sacrifice some damage for a bit of extra MR/AR/HP. Item builds have to be flexible, there is no one size fits all.
Dont stop farming when your tower is destroyed. Quite often I see a tower go down in a lane and instantly the lane jumps into gank mode. They rush to another lane and spend so much time trying to gank or leeching their teammates farm when they could be farming their own lane still. This is especially true for the ad carry.
Realise that losing a tower early is not always a bad thing. Sure, losing a tower can be a pain, and no one likes to lose a tower, but it does put the farming more in your court. All of a sudden you can farm on your side of the map, where they have to either go off somewhere else, or put themselves in serious risk of a gank.
Realise that if you were counterpicked, and the other player is of similar skill level to you, that you will most likely die a few times. There's very few things you can do to avoid it. Just try not to lose your head when it happens. Dont use this as an excuse and tell the rest of your team it isnt your fault, because no one likes to hear excuses. Just take a breath, figure out what you did wrong, and go back in there.
tl;dr; (cause I know I probably wouldnt read all that) Play passively, keep calm, be flexible (runes/masteries/build/lane) and farm as much as possible without taking risks.
Farm, farm, farm, farm! All I can say is, buy a lot of health pots and play defensive, ask your jungler for ganks and cross your fingers and hope that the other lanes wins.