Skip to content

Instantly share code, notes, and snippets.

View stollcri's full-sized avatar

Christopher Stoll stollcri

View GitHub Profile
@stollcri
stollcri / docker_publish.make
Last active August 23, 2016 15:26
Makefile to publish a set of Docker images to a registry
# vim: set syntax=Makefile
# images will be pushed to a repository named: PRODUCT_NAME-DOCKER_IMAGE
# the repository must already exist (create it from the AWS console)
PRODUCT_NAME = my_product
# docker image tag (only set if variable is unset)
# 'DOCKER_IMAGE_TAG=:test make' can be used to publish with the label 'test'
DOCKER_IMAGE_TAG ?= :latest
# list of docker images to build (space separated)
DOCKER_IMAGES = frontend backend database
# the registry where the images will be pushed
@stollcri
stollcri / run_script_from_sql.sql
Created August 17, 2016 11:12
Kick off a shell script from a SQL script
COPY (SELECT 1) TO PROGRAM '/var/lib/postgresql/scripts/do_sys_thing.sh';
@stollcri
stollcri / random_password.sh
Created August 2, 2016 12:15
Shell script to generate a random 32 character alphanumeric string
#!/bin/sh
USER_PASSWORD=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo $USER_PASSWORD
@stollcri
stollcri / macro_example.make
Last active August 23, 2016 15:28
Make file macro function to perform pip install
# vim: set syntax=Makefile
# define at top of file
define PIP_INSTALL
@if [ ! $(shell echo ${VIRTUAL_ENV}) ]; then \
set +o nounset; \
source ${VIRTUALENVPATH}/bin/activate; \
set -o nounset; \
fi; \
cd external-code/ && pip install $1
endef
@stollcri
stollcri / commits_by_pr.py
Created May 16, 2016 13:12
Get commits (or files) associated with a list of GitHub pull requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Given a list of GitHub Pull Requests
# Return the associated commits or files
#
# How to run this command (to see commits):
# cat prs.txt | ./commits_by_pr.py stollcri stollcri my_repo
# -or-
# ./commits_by_pr.py stollcri stollcri my_repo prs.txt > commits.txt
@stollcri
stollcri / list_all_crontab.sh
Created December 28, 2015 20:54
List all crontabs
#!/bin/bash
for user in $(cut -f1 -d: /etc/passwd); do echo $user; sudo crontab -u $user -l; done
@stollcri
stollcri / chrome_HSTS_clear.md
Last active January 4, 2024 05:09
Clear 307 HSTS redirects in Google Chrome

To clear 307 HSTS redirects in Google Chrome (if you experimenting with SSL -- you probably wouldn't want to do this for a site that you do not opperate, since it is there to protect you), go to the following URL and delete the site.

chrome://net-internals/#hsts

@stollcri
stollcri / jerkins-node-mocha-start.sh
Created December 9, 2015 14:47
Start Node.js and wait for it to be running, then run Mocha.js tests
# start node, silence output, and send to the background
npm start > /dev/null &
# give node a chance to start
if [ -f "$(which curl)" ]; then
LOOP_PASS=0
TEST_STAT="999"
# wait (maximum 15 seconds) until node is ready
while [ "$TEST_STAT" != "200" -a $LOOP_PASS -lt 15 ]; do
CURL_STAT=$(curl -sI http://localhost)
#!/bin/bash
#
# Refresh data in AWS RDS database
#
# Add to cron: aws_db_sync.sh &> aws_db_sync.log
# or
# Call by: aws_db_sync.sh &> aws_db_sync.log &
# tail -f aws_db_sync.log
if [ ! -r ~/.my.cnf ]; then
@stollcri
stollcri / aws_s3_sync.sh
Created December 4, 2015 13:11
Synchronize files to AWS S3
$SRC_DIR=/var/www/htdocs
cd $SRC_DIR/images
DIR_SIZE=$(du . -hS | tail -n1 | awk '{print $1}')
echo "Syncing s3://BUCKET_NAME/images/ ($DIR_SIZE)"
/usr/local/bin/aws s3 sync . s3://BUCKET_NAME/images/ --storage-class STANDARD --exclude '.*' --exclude '*.php'
cd $SRC_DIR/images-old
DIR_SIZE=$(du . -hS | tail -n1 | awk '{print $1}')
echo "Syncing s3://BUCKET_NAME/images-old/ ($DIR_SIZE)"