Simply paste the function below into your functions.php file:
function hasgallery(){ global $ post; return (strpos($ post->post_content,'[gallery') !== false); }
Once done, you can use it to detect if a post has a gallery.
Thanks to WordPress Stackexchange for the cool tip!