Skip to content

Instantly share code, notes, and snippets.

View ethangardner's full-sized avatar

Ethan Gardner ethangardner

View GitHub Profile
@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 / scss-namespace-import
Last active August 29, 2015 13:56
Sass Namespace
$namespace: '#your-id';
#{$namespace} {
@include 'another-file';
}
@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 / 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 / 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 / GoogleCDNfallback.html
Created October 5, 2010 17:43
code snippet to offer fallback to local file if google's ajax api is unavailable
<!-- From http://github.com/paulirish/html5-boilerplate -->
<!-- Grab Google CDN's jQuery. fall back to local if necessary -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>!window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')</script>
@ethangardner
ethangardner / yql_flickr.php
Created December 21, 2010 02:02 — forked from avinashbangar/yql_flickr.php
using yql to access flickr photos via api
<!-->
Following code gets information about photos from Flickr via YQL for the given search term
Author : avinash
Email : avinash@tutkiun.com
<-->
<h2>Using YQL to Access the Flickr API</h2>
<form name='upcoming_form'>
@ethangardner
ethangardner / MooTools-1.3-XML-parsing.js
Created January 11, 2011 23:03
MooTools 1.3 XML parsing with Slick
//XHR to retrieve an atom feed and parse the result
//with MooTools Slick selector engine
new Request({
url: '/index.php?format=feed&type=atom',
data : 'xml',
method: 'get',
onComplete: function(responseText, responseXML) {
console.log(Slick.search(responseXML, 'entry > title'));
}
}).send();
@ethangardner
ethangardner / Mootools-1.2-XML-parsing.js
Created January 11, 2011 22:21
Mootools 1.2 XML sitemap parsing
new Request({
url: '/sitemap.xml',
method: 'get',
onSuccess: function(responseText, responseXML) {
responseXML.getElements('url').each(function(url) {
alert(item.getElement('loc').get('text'));
});
}
}).send();
@ethangardner
ethangardner / combine-files-from-command-line.txt
Created January 28, 2011 19:37
Combine Multiple Files using Linux or Cygwin command line
#code from article at http://beardscratchers.com/journal/compressing-css-and-javascript-with-yui-compressor
JSDIR="./www/js"
echo "1. Combining Javascript"
# Combine all the javascript to a single temporary file
cat $JSDIR/mootools-1.2-core.js \
$JSDIR/mootools-1.2-more.js \
$JSDIR/functions.js \