What about brainiac? It lists it as being "sometimes derogatory", but I usually hear it as an affectionate term, especially for someone younger than the person speaking.
Noun:
brainiac (plural brainiacs): (slang, sometimes derogatory) a very intelligent and usually studious, erudite person.
Edit:
I can't actually think of a time I've heard it used in a derogatory manner. I'm not really sure how to use it in such a way without it sounding weird.