Skip to content

Instantly share code, notes, and snippets.

@joemcgill
joemcgill / form_validation_browser_plug
Created November 27, 2013 18:04
When using HTML5 forms elements and validation, interrupt a browser's default invalidation message and plug in your own validation code (e.g., append an invalid class to the input and style accordingly).
document.addEventListener('invalid', (function(){
return function(e){
//prevent the browser from showing default error bubble/ hint
e.preventDefault();
// optionally fire off some custom validation handler
myvalidationfunction(e);
};
})(), true);
@joemcgill
joemcgill / .bash_prompt
Created December 13, 2013 19:21
Custom bash prompt, inspired by Paul Irish's dotfiles repo.
#!/bin/bash
# @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt”
# Shamelessly copied from https://github.com/gf3/dotfiles
default_username='joemcgill'
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
@joemcgill
joemcgill / show_img_vars.php
Last active October 14, 2016 08:11
A poor man's var_dump for the image_send_to_editor() filter in Wordpress. Throw this in your functions.php file and add an image to your post to see what get's passed. Filter it however you want to return the image however you want.
<?php
function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
// round up all the variables that get passed so we can test them
$vars = "html = $html\n";
$vars .= "id = $id\n";
$vars .= "caption = $caption\n";
$vars .= "title = $title\n"; // this will end up blank no matter what
$vars .= "align = $align\n";
$vars .= "url = $url\n";
@joemcgill
joemcgill / better_wp_images.php
Last active October 14, 2016 08:11
A set of function to improve the markup of images inserted into the editor in Wordpress.
<?php
function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
// remove alignment class from the image
$html = preg_replace( '/ class=".*"/', '', $html );
// return the normal html output you would expect
$figure = "<figure class='image-inline";
if ($align == 'left' | 'right') {
$figure .= " align".$align;
@joemcgill
joemcgill / wp_pinterest_hovers.js
Created January 2, 2014 19:54
Automatically add Pinterest pin overlays to Wordpress blog images. This should eventually be turned into a plugin probably.
/**
* Pinterest Overlay Code
* @require jQuery 1.8
*/
var bs_pinButtonURL = "//link.to/image.png";
var bs_pinButtonHeight = 72;
var bs_pinButtonWidth = 72;
var bs_yourUrl = $(location).attr('host');
var bs_pinButtonPos = "bottomright";
@joemcgill
joemcgill / grunt-watch-livereload.js
Last active August 29, 2015 13:57
This is an example of setting up a grunt watch task to use grunt-contrib-connect and livereload.
// The rest of the grunt file goes here
watch: {
// The rest of your watch tasks go here
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
// YOUR LIST OF FILES TO WATCH
@joemcgill
joemcgill / gist:9236cb10f271035414e6
Last active August 29, 2015 14:01
Grunt watch task example for Pattern Lab
watch: {
options: {
livereload: {
options: {livereload: '<%= connect.options.livereload %>'},
files: [
'public/**/*'
]
}
},
html: {
# This is a template .gitignore file for git-managed WordPress projects.
#
# Fact: you don't want WordPress core files, or your server-specific
# configuration files etc., in your project's repository. You just don't.
#
# Solution: stick this file up your repository root (which it assumes is
# also the WordPress root directory) and add exceptions for any plugins,
# themes, and other directories that should be under version control.
#
# See the comments below for more info on how to add exceptions for your
@joemcgill
joemcgill / gist:ec7f018875ceb0cbff3e
Last active August 29, 2015 14:03
WP Custom User Meta
<?php
/**
* Add custom user fields/meta info
*/
add_action( 'show_user_profile', 'wu_custom_user_meta', 9 );
add_action( 'edit_user_profile', 'wu_custom_user_meta', 9 );
function wu_custom_user_meta( $user ) {
// create nonce field
@joemcgill
joemcgill / .htaccess
Created July 24, 2014 17:28
Wordpress Dev Uploads Directory Trick
# Attempt to load files from production if they're not in our local version
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Replace http://productionsite.com with your production site's domain name
RewriteRule (.*) http://productionsite.com/wp-content/uploads/$1
</IfModule>