Skip to content

Instantly share code, notes, and snippets.

View okadots's full-sized avatar

Oka Tai-Lee okadots

View GitHub Profile
@joshdcomp
joshdcomp / reusable.js
Last active January 26, 2016 21:37
When writing event handlers, manipulate elements relative to the element was clicked to avoid unintended consequences.
/**
* The way this is written there are 2 major assumptions:
*
* 1) There will only ever be one `.email_subscribe` on the page (and if there’s more,
* they’re all going to open/close at the same time)
* 2) These elements will exist on document load…so if these things get built by js or are
* loaded after docload, these click events won’t do anything
*/
$('.subscribe-close').on('click', function(){
$('.email_subscribe').removeClass('email_subscribe--opened');
@justinph
justinph / validate_gravatar.php
Created March 19, 2013 16:49
In wordpress, a better way to check if an author has a gravatar or not. Sometimes you might want to check to see if a gravatar exists and not display any image if there isn't one. Uses the wordpress HTTP and caching apis. A better version of this: http://codex.wordpress.org/Using_Gravatars#Checking_for_the_Existence_of_a_Gravatar
/**
* Utility function to check if a gravatar exists for a given email or id
* @param int|string|object $id_or_email A user ID, email address, or comment object
* @return bool if the gravatar exists or not
*/
function validate_gravatar($id_or_email) {
//id or email code borrowed from wp-includes/pluggable.php
$email = '';