Skip to content

Instantly share code, notes, and snippets.

View astockwell's full-sized avatar

Alex Stockwell astockwell

View GitHub Profile
var output = document.getElementById('output');
function assert( outcome, description ) {
var li = document.createElement('li');
li.className = outcome ? 'pass' : 'fail';
li.appendChild( document.createTextNode( description ) );
output.appendChild(li);
};
@astockwell
astockwell / script.js
Created June 1, 2013 00:15
Simple JS timing/performance/latency testing script (via http://kellegous.com/j/2013/01/26/layout-performance/)
var Now;
if (typeof performance !== 'undefined' && performance.now) {
Now = function() {
return performance.now();
};
} else if (Date.now) {
Now = function() {
return Date.now();
};
} else {
@astockwell
astockwell / header.php
Created May 30, 2013 18:13
Creates edit post/page button in wordpress (only displays if user is logged in) so you can hide the terrible admin bar.
<!-- Place in "body > header" or equivalent -->
<?php edit_post_link( __('Edit'), '<span class="edit-link">', '</span>' ); ?>
@astockwell
astockwell / script.js
Last active December 17, 2015 18:09
Poor-man's Javascript performance timing, via http://kellegous.com/j/2013/01/26/layout-performance/
var Now;
if (typeof performance !== 'undefined' && performance.now) {
Now = function() {
return performance.now();
};
} else if (Date.now) {
Now = function() {
return Date.now();
};
} else {
@astockwell
astockwell / loop.php
Created May 2, 2013 22:59
WP_Query by meta_value first letter
<?php
$args = array(
'post_type' => 'faculty',
'meta_query' => array(
// 'relation' => 'AND',
// array(
// 'key' => 'online-extra-type',
// 'value' => 'Your Space',
// 'compare' => '='
// ),
@astockwell
astockwell / cpt_tax.php
Last active December 16, 2015 13:59
Pristine Wordpress Custom Post Type (and Related Custom Taxonomy) Declaration
<?php
function xyz_create_cpt_animal() {
$label_singular = 'Animal';
$label_plural = $label_singular . 's';
$labels = array(
'name' => __($label_plural),
'singular_name' => __($label_singular),
'add_new' => __('Add New'),
@astockwell
astockwell / loop.php
Last active December 14, 2015 11:38
Pristine Wordpress loop examples
<?php // Referencing http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts ?>
<?php
// EXAMPLE new WP_Query object
?>
<?php
// Query posts by new criteria.
$args = array(
'posts_per_page' => -1,
@astockwell
astockwell / search.php
Created January 4, 2013 21:34
Google Custom Search v2 Include Code for Wordpress - WORKING
<?php get_header(); ?>
<section>
<!-- Put the following javascript before the closing </head> tag. -->
<script>
(function() {
var cx = '000000000000000000000:aaa1aa1aa1a';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
@astockwell
astockwell / wp-config.php
Last active May 19, 2019 23:03
One wp-config.php file to rule them all (multiple environments)
// One wp-config.php file for multiple environments setup from http://www.messaliberty.com/2010/01/how-to-create-a-single-wp-config-file-for-local-and-remote-wordpress-development/
if ($_SERVER['REMOTE_ADDR']=='127.0.0.1' || $_SERVER['REMOTE_ADDR']=='localhost' || preg_match('/^192\.168\.5\./', $_SERVER['REMOTE_ADDR'])) {
define('WP_ENV', 'local');
} elseif ($_SERVER['HTTP_HOST']=='tld.stagingurl.com') {
define('WP_ENV', 'staging');
} else {
define('WP_ENV', 'production');
}
if ( WP_ENV == 'local' ) {
@astockwell
astockwell / script.js
Last active October 13, 2015 15:28
Detect if element exists on page in jQuery
if ($('.lt-ie8').is('*')) {
//code
}