Skip to content

Instantly share code, notes, and snippets.

View JCotton1123's full-sized avatar

Jesse Cotton JCotton1123

View GitHub Profile
@JCotton1123
JCotton1123 / mysql-query-time-test.sh
Last active February 11, 2016 01:42
Simple script to measure the time it takes to execute a series of MySQL queries
#!/bin/bash
user='root'
password=''
function usage() {
echo "usage: $0 <query-file> <default-database>"
exit 1
}
@JCotton1123
JCotton1123 / generate-ssl-cert.sh
Created February 3, 2016 21:54
Generate an SSL certificate and key with multiple subject alternative names
#!/bin/sh
subject='/C=US/ST=California/L=San Francisco/O=Organization/OU=Operations/CN=*.orgdev.net/emailAddress=operations@org.co'
subject="${subject}/subjectAltName=DNS.1=orgdev.net,DNS.2=*.orgdev.net,DNS.3=dev.orgdev.net,DNS.4=*.dev.orgdev.net"
openssl genrsa -out server.key 2048
openssl req -new -key server.key -sha256 -nodes -subj "$subject" > server.csr
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
@JCotton1123
JCotton1123 / setup-s3s3mirror.sh
Last active January 18, 2016 18:28
s3s3mirror setup
# Ideally, run this from a EC2 instance within the same
# region as your source and destination buckets
apt-get update -y
apt-get install -y git openjdk-7-jdk
git clone https://github.com/cobbzilla/s3s3mirror.git
cd s3s3mirror
export AWS_ACCESS_KEY_ID=
@JCotton1123
JCotton1123 / gist:7759674
Last active December 30, 2015 01:59
Linux CLI snippets
## All IPs
egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
## Find a distinct list of file exts within a specified directory
find ./ -type f -name "*.*" -exec basename {} \; | rev | cut -d. -f 1 | sort | uniq | rev
## Find files with the supplied exts (linux)
find ./ -regextype posix-extended -regex ".*(mp3|mp4|pdf|PDF|doc|zip|ZIP|wav|gz)$"
## Find files with supplied exts (mac)
@JCotton1123
JCotton1123 / postfix-sasl-auth.sh
Created November 21, 2013 07:20
Postfix relay SASL authentication
#!/bin/sh
cd /etc/postfix
sed -i 's/#relayhost = \[an.ip.add.ress\]/relayhost = [smtp.mailgun.org]:587/g' main.cf
echo >> main.cf
echo "smtp_sasl_auth_enable = yes" >> main.cf
echo "smtp_sasl_password_maps = static:USERNAME:PASSWORD" >> main.cf
echo "smtp_sasl_security_options = noanonymous" >> main.cf
echo >> main.cf
/etc/init.d/postfix restart
@JCotton1123
JCotton1123 / apache-vhost-report.php
Last active December 28, 2015 15:19
Apache Vhost Report
#!/usr/bin/php
<?php
$directory = $argv[1];
$output_column_headings = array(
"Config File",
"Virtual Host",
"ServerName",
"DocumentRoot",
@JCotton1123
JCotton1123 / bench.sh
Created September 30, 2013 02:09
Apache Bench script - needs some work
#!/usr/local/bin/bash
numberOfRequestsValues="10 20 40"
concurrencyValues="1 2 4"
abCmd="/usr/local/sbin/ab"
for url in $(cat $1); do
echo "# $url"
echo
@JCotton1123
JCotton1123 / add-ga.sh
Last active December 24, 2015 05:09
Add Google analytics snippet to files with the ability to filter on file extension and mime type
#!/bin/bash
# This is the snippet that will be added to each file
includeGAString="<!--#include virtual=\"/includes/ga.inc\" -->"
#includeGAString="<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');
#
@JCotton1123
JCotton1123 / export-mailgun-bounces.php
Created October 22, 2015 20:30
Export bounces from Mailgun
#!/usr/bin/php
<?php
## Constants
define('MAILGUN_API_ENDPOINT','https://api.mailgun.net/v3');
define('API_CREDENTIALS_STRING','api:key-');
define('DEFAULT_DOMAIN','');
## Main
if($argc != 2){
@JCotton1123
JCotton1123 / chef-repo-pin-versions.sh
Last active October 13, 2015 05:23
Numerous Chef related cleanup snippets
for cookbook in $(ls); do
knife cookbook metadata from file $cookbook/metadata.rb
done
for cookbook in $(ls); do
echo "Processing cookbook $cookbook"
if [ ! -d $cookbook ]; then
continue
fi
deps=$(cat $cookbook/metadata.json | python -c 'import sys, json; print "\n".join(json.load(sys.stdin)["dependencies"].keys())')