Skip to content

Instantly share code, notes, and snippets.

View ethangardner's full-sized avatar

Ethan Gardner ethangardner

View GitHub Profile
@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 / 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 / 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
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 / 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 / get_apache_user.sh
Created October 9, 2015 19:42
Detect user running Apache process
ps -ef | grep httpd | grep -v `whoami` | grep -v root | head -n1 | awk '{print $1}';
@ethangardner
ethangardner / .htaccess
Created October 20, 2015 16:35
Redirect old domain to www version of a new domain
# BEGIN Redirects
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^newdomain\.com$ [NC]
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>
# END Redirects
@ethangardner
ethangardner / jshint.config
Created November 6, 2015 16:01
JSHint config object for Gruntfile
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,