Skip to content

Instantly share code, notes, and snippets.

View ethangardner's full-sized avatar

Ethan Gardner ethangardner

View GitHub Profile
@ethangardner
ethangardner / normalize_spaces.sh
Created November 25, 2015 15:11
Nomalize spaces in a directory
find . \( -name '*.scss' -o -name '*.html' -o -name '*.js' -o -name '*.php' \) ! -type d -exec bash -c 'expand -t 4 "$0" > /tmp/e && mv /tmp/e "$0"' {} \;
@ethangardner
ethangardner / emad-deploy-git-log-diff.md
Created December 18, 2015 16:53
Using git logs and diffs with emad to deploy

Most recent commit

git show --pretty="format:" --name-only | sort | uniq > deploy.txt && emad --env production --only 0 --files-from deploy.txt && rm deploy.txt

Modified files using diff

git diff --name-only > deploy.txt && emad --env production --only 0 --files-from deploy.txt && rm deploy.txt
@ethangardner
ethangardner / git-zip-modified-files.md
Last active January 6, 2016 21:28
Zip modified files

Last Commit

git archive --format=zip HEAD `git diff HEAD^ HEAD --name-only` > a.zip

Diffs between 2 commits

tar -czf <file> $(git diff --name-only SHA1..SHA2)
<?php
// this file lives in the site's theme directory
if( defined( 'EMA_ENVIRONMENT' ) !== true || constant( 'EMA_ENVIRONMENT' ) === 'prod' ) { {
// do stuff
} ?>
@ethangardner
ethangardner / rpm-repo-update.sh
Created February 2, 2016 16:07
Add most recent rpm repo to CentOS/RHEL
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm &&
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm;
@ethangardner
ethangardner / restart-apache.sh
Created February 2, 2016 16:08
Restart Apache without reboot
sudo service httpd restart
@ethangardner
ethangardner / .htaccess
Last active March 11, 2016 19:45
Redirect non-www version of a domain to www
# BEGIN Redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
</IfModule>
# END Redirect
var track = {
google: {
event: function(args) {
if (typeof ga === "function") {
if (args.constructor !== [].constructor) {
new Error('This function takes an array as the argument. You passed a ' + typeof args);
}
else if( args.length < 2 || args.length > 5 ) {
new Error('This function needs an array of 2 to 5 items. You passed ' + args.length);
}
@ethangardner
ethangardner / wp-plugin-activation-error.php
Created September 6, 2016 14:55
Captures activation errors for WP plugins
<?php
// https://www.toddlahman.com/the-plugin-generated-x-characters-of-unexpected-output-during-activation/
function plugin_activate_save_error() {
ob_clean();
update_option( 'plugin_error', ob_get_contents() );
}
add_action( 'activated_plugin', 'plugin_activate_save_error' );
/* Then to display the error message: */
echo get_option( 'plugin_error' );