Skip to content

Instantly share code, notes, and snippets.

View ethangardner's full-sized avatar

Ethan Gardner ethangardner

View GitHub Profile
@ethangardner
ethangardner / bulk-rename.ps1
Created August 28, 2015 03:04
Powershell script to bulk replace spaces with underscores in a directory of files
Dir | Rename-Item –NewName { $_.name –replace “ “,”_” }
@ethangardner
ethangardner / functions.php
Created August 26, 2015 16:25
Load Google Analytics in WP functions.php file
function wptheme_end_head_scripts() {
?>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('send', 'pageview');
@ethangardner
ethangardner / random_string.py
Last active August 29, 2015 14:22
Random String Generator
import random
promos = []
def random_chars():
return 'B' + ''.join(random.choice('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') for i in range(6))
while len(promos) < 2800:
promo = random_chars()
if promo not in promos:
@ethangardner
ethangardner / functions.php
Last active March 11, 2016 20:37
Loading scripts in functions.php and removing from header.php (recommended)
<?php
/**
* We've stripped the script tags from header.php and relocated them to functions.php
*/
// loads the external scripts
function wptheme_load_scripts() {
wp_deregister_script( 'jquery' ); // deregisters the version of jQuery shipped with WP so you can use Google's CDN
wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js' );
wp_enqueue_script( 'jquery' ); // actually loads it on the page
@ethangardner
ethangardner / header.php
Created May 6, 2015 20:50
Loading scripts in header.php (not recommended)
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php wp_title( '|', true, 'right' ); ?></title>
<!-- JS -->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/modernizr.js"></script>
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/script.js"></script>
@ethangardner
ethangardner / interstitial.js
Last active August 29, 2015 14:04
Interstitial ad object
ENGAGE.Interstitial = function(options) {
if (!(this instanceof ENGAGE.Interstitial)) {
return new ENGAGE.Interstitial(options);
}
if (typeof options !== "undefined") {
this.blocked_class = options.blocked_class || this.blocked_class;
this.close_control = options.close_control || this.close_control;
this.container = options.container || this.container;
this.countdown = options.countdown || this.countdown;
@ethangardner
ethangardner / scss-namespace-import
Last active August 29, 2015 13:56
Sass Namespace
$namespace: '#your-id';
#{$namespace} {
@include 'another-file';
}
@ethangardner
ethangardner / sql-order-by-random
Last active October 7, 2015 00:27
SQL - order by random
SELECT * FROM table ORDER BY NEWID()
-- mysql version
SELECT * FROM table ORDER BY uuid()
@ethangardner
ethangardner / gist:1991279
Last active November 17, 2020 06:18
Raphael JS Guitar Neck Diagram
/**
* @author Ethan Gardner
* @see: http://www.ethangardner.com/articles/drawing-with-raphael-js-plus-a-bonus-for-guitar-players/
*/
var paper = new Raphael(document.id("fretboard"), 1300, 300);
/**
* Set up a GTR object to be used for namespacing
* @see http://www.ethangardner.com/articles/javascript-namespace-strategy-for-large-applications/
@ethangardner
ethangardner / gist:1587281
Created January 10, 2012 05:52 — forked from wrboyce/gist:786460
pre-commit hook to automatically minify javascript/css
#!/usr/bin/zsh
COMPRESSOR=$(whence -p yui-compressor)
[ -z $COMPRESSOR ] && exit 0;
function _compress {
local fname=$1:t
local dest_path=$1:h
local min_fname="$dest_path/${fname:r}.min.${fname:e}"
$COMPRESSOR $1 > $min_fname