How to run a piece of code when addon is just activated
This is an example addon that will execute the function "load_fonts" when blender starts,  it use the handlers to run a function at blender start :

import os
import bpy
from bpy.app.handlers import persistent

@persistent
def load_fonts(scene):
    font_dir = bpy.context.user_preferences.filepaths.font_directory
    for file in os.listdir(font_dir):
        if file.endswith(".ttf"):  
            bpy.data.fonts.load(font_dir+file)

def register():
    bpy.app.handlers.load_post.append(load_fonts)

def unregister():
    bpy.app.handlers.load_post.remove(load_fonts)

if __name__ == "__main__":
    register()


you can call the function  you want inside the register() function, but you can't get access to the scene :

def load_fonts(scene):
    print("addon activated ")

def register():
    load_fonts()


if __name__ == "__main__":
    register()


to overcome this problem you can use handlers to access the scene as @CoDEmanX shows in this thread :  example

import os
import bpy
from bpy.app.handlers import persistent

@persistent
def load_fonts(scene):
    bpy.app.handlers.scene_update_pre.remove(load_fonts)
    font_dir = bpy.context.user_preferences.filepaths.font_directory
    for file in os.listdir(font_dir):
        if file.endswith(".ttf"):  
            bpy.data.fonts.load(font_dir+file)

def register():
    bpy.app.handlers.scene_update_pre.append(load_fonts)

def unregister():
    pass

if __name__ == "__main__":
    register()