Skip to content

Instantly share code, notes, and snippets.

View mindcube's full-sized avatar

Scott Landes mindcube

View GitHub Profile
@mindcube
mindcube / gist:9849213
Created March 29, 2014 05:46
Generate a tuple of years in descending order in Python
from datetime import date, strftime
def _list_years(self):
x = 1
years = ()
today = date.today()
for x in range(15):
year = today - timedelta(days=365 * x)
years += (year.strftime('%Y'),)
x += 1
@mindcube
mindcube / gist:7537798
Created November 19, 2013 00:16
Get web server response time
curl -s -w %{time_total}\\n -o /dev/null http://www.site.com
@mindcube
mindcube / auto-fancybox.js
Last active March 1, 2018 12:13
JS: Function that automatically pops up a fancybox window by using hash link.
// Function to automatically pop up lightbox window.
if (window.location.hash) {
var hash = window.location.hash;
if (hash == '#registration_form') {
$('.fancybox').fancybox().trigger('click');
}
}
@mindcube
mindcube / gist:4733021
Created February 7, 2013 18:26
echo last WordPress query
<?php echo $GLOBALS['wp_query']->request; ?>
@mindcube
mindcube / gist:4724974
Last active December 12, 2015 05:49
Function to extract the subdomain off of a url
<?php
function extract_subdomain () {
$url_parts = explode( '.',$_SERVER['HTTP_HOST'] );
unset( $url_parts[0] );
$domain = implode( '.', $url_parts );
return $domain;
}
?>
@mindcube
mindcube / display-template.php
Created January 29, 2013 15:58
A function to display the full path and file name of the loaded WordPress template. For debugging and development.
<?php
function display_custom_template( $template ) {
echo '<!--TEMPLATE:'.$template.'-->';
}
add_filter( 'template_include', 'display_custom_template' );
?>
@mindcube
mindcube / gist:4635449
Created January 25, 2013 15:52
PHP: Turn on PHP and debug warnings
// Debug mode (uncomment below to enter debug mode)
define('WP_DEBUG', true);
error_reporting(E_ALL);
ini_set('display_errors', True);
@mindcube
mindcube / gist:4635168
Created January 25, 2013 15:19
PHP: Insert WordPress template file name and path
// For debugging - show template file
add_action('wp_head', 'show_template');
function show_template() {
global $template;
?><!-- TEMPLATE: <?php print_r($template);?>--><?php
}