Execute Code When Activating a Plugin

If you want to execute some code when activating a plugin, use this snippet:

register_activation_hook( __FILE__, 'wpkb_plugin_activation' );

function wpkb_plugin_activation() {
  // my code
}