Skip to content

Instantly share code, notes, and snippets.

View shawnhubbard's full-sized avatar

Shawn Hubbard shawnhubbard

View GitHub Profile
@shawnhubbard
shawnhubbard / all-the-repos.sh
Created August 17, 2015 13:45
Simple script for updating all repos in a given directory. Currently for Mercurial, but could easily be adapted for Git. Use with caution; it clears all changes before performing a pull.
#!/bin/bash
# Pull ALL THE REPOS
# Set to your target directory.
DEV=~/dev
pull_all_repos() {
(find $DEV -type d -name .hg | while read line; do cd $line && hg update -C && hg pull; done && echo -e "\033[0;32mALL THE REPOSITORIES have been pulled.\033[0m") || (echo -e "\033[0;31mThere was an error!\033[0m")
$SHELL
@shawnhubbard
shawnhubbard / Slider.js
Created February 10, 2015 17:03
Simple slider class
/*jslint indent: 2 */
/*global window*/
/*global console*/
/*global document*/
/*global HTMLElement*/
function Slider(options) {
'use strict';
var self = this;
@shawnhubbard
shawnhubbard / wp_get_proxy_page_content
Last active August 29, 2015 14:14
Get proxy page content, including ACF fields. Useful for archive or home templates.
/**
* Run a query to grab the post/page content and ACF meta content of a certain
* page, useful for archive, and home templates where content management is
* needed.
*
* @param int $id the id of the post/page you'd like to grab content from
* @param array $fields ACF field names you'd like to grab.
* @return array of post/page content
*/
function get_proxy_page_content( $id, $fields = array() )
@shawnhubbard
shawnhubbard / _justagrid.scss
Last active August 29, 2015 14:13
Simple SASS mixin for creating grids using the popular text-align: justify trick.
// Credit where due: http://www.barrelny.com/blog/text-align-justify-and-rwd/
@mixin justagrid($columns: 3, $hgutter: 30, $vgutter: 30, $width: 960) {
$box-width: ($width / $columns) - ($hgutter / 2);
list-style: none;
margin: 0;
padding: 0;
@shawnhubbard
shawnhubbard / wp-events-dissolve.php
Last active August 29, 2015 14:08
WP Dissolving Events Query
<?php
function sh_auto_dissolve_events( $query )
if ( is_admin() )
{
return $query;
}
if ( ! $query->is_main_query() )
@shawnhubbard
shawnhubbard / curtain.js
Created March 11, 2014 21:06
Set a section equal to the viewport height.
(function(){
var curtain = document.querySelector('#site-header');
var windowHeight = window.innerHeight;
var curtainHeight = windowHeight;
curtain.setAttribute('style', curtainHeight + 'px');
curtain.style.height = curtainHeight + 'px';
})();
@shawnhubbard
shawnhubbard / Simple mail library
Created November 21, 2013 16:24
Simple PHP mail library
<?php
///////////////////////////////
// Library
//////////////////////////////
class Simple_Mail
{
private $headers = '';
public $mail_config = array();
@shawnhubbard
shawnhubbard / is_page_level
Last active December 28, 2015 00:39
Find page or subpage levels in wordpress.
<?php
function is_page_level($level)
{
global $wp_query;
if ( ! is_page() )
{
return false;
}
@shawnhubbard
shawnhubbard / name_regex.rb
Created March 6, 2012 22:31
A Ruby regex for validating the input of first/last name in one field. Allows for "." and "," for abbreviations and suffixes like Jr. or Sr.
name_regex = /\A[a-z+]+((\s?[a-z]+[\.\,]?)+|([a-z]+[\.\,]?)+)\s?\z/i