Skip to content

Instantly share code, notes, and snippets.

View peterkappus's full-sized avatar

Peter Kappus peterkappus

View GitHub Profile
@peterkappus
peterkappus / github.gs
Last active October 3, 2018 17:09
Get open github pull requests in Google Sheets - Google Script
//generic function to get JSON from a github API endpoint
function getJSON(url) {
// Your github username
username = "<USERNAME>"
// Your access token (see https://github.com/settings/tokens)
password = "<ACCESS_TOKEN>"
//basic auth using access token
var options = {};
options.headers = {"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)};
@peterkappus
peterkappus / docker_demo.sh
Last active January 5, 2019 10:20
Use docker to host a local html file with nginx!
# What is it? Use docker to host an html file using nginx!
# Pre-requisites: You've installed docker and logged into docker-hub
#make our html file
echo "<h1>Hello world</h1>" > index.html
#start docker and mount our current working directory into nginx
docker run -p 80:80 -v "$(PWD)":/usr/share/nginx/html:ro -d nginx
#go have a look!
@peterkappus
peterkappus / rails_docker_starter.sh
Last active August 6, 2019 15:56
New Docker, Rails, Postgres app in one bash script
#This script will create the required Dockerfile, docker-compose.yml, Gemfile, etc. and create a new rails app (using postgres)
#BEWARE! It will overwrite any existing files in the folder including Dockerfile, docker-compose.yml, and README.md
#the databses will be called "myapp_development", and "myapp_test"
cat << EOF > Dockerfile
FROM ruby:latest
#USER $USER
#make sure we don't get tripped up by any inherited proxies
#RUN unset HTTP_PROXY
#RUN unset HTTPS_PROXY
@peterkappus
peterkappus / run.sh
Last active May 23, 2018 16:37
Docker file mount demo.
#create a local html file
echo "<html><h1>Yo</h1></html>" > index.html
#start nginx inside a container
docker run -p 80:80 -v "$(PWD)":/usr/share/nginx/html:ro -d nginx &
#fire up a browser and point it at local host
open http://localhost
#get the container ID to kill it later...
@peterkappus
peterkappus / check_diskspace.sh
Last active July 16, 2018 09:51
Jenkins shell script job to Check the diskspace on a machine (specifically, see if the /usr mount is over 60% full)
# See if the /usr mount is over 60% full
# If so, exit with a status of 1. Otherwise, OK
df -h | grep "/usr" | grep -oP "\d+%" | grep -oP "\d+" | xargs -L1 -I{} bash -c 'if [ {} -ge 60 ]; then exit 1; else exit 0; fi'
# BONUS!
# remove any gz file older than 60 days which are type "file" (not directories)
find /path/to/logs/ -name "*.gz" -mtime +60 -type f -exec rm {} +
#zip any log file older than 10 days
find /path/to/logs/ -name "*.log" -mtime +10 -type f -exec gzip {} +
@peterkappus
peterkappus / install_docker_on_centos.sh
Last active May 13, 2018 21:27
Install Docker CE on RHEL/Centos (e.g. in a BBC VM)
# upgrade centos and make sure you have the docker repo
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# dunno why I had to do this but I did...any ideas?
sudo yum makecache fast
# Install these dependencies
sudo yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.33-1.git86f33cd.el7.noarch.rpm
sudo yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/pigz-2.3.3-1.el7.centos.x86_64.rpm
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
host: db
username: postgres
password:
development:
How to
For Centos (because that's what some companies give you for a VM)
Follow these steps:
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
yum install -y vim
vim /etc/nginx/nginx.conf
@peterkappus
peterkappus / user_create.sh
Created November 30, 2017 13:48
Easily create a sudoer, SSH-keyed new user on a linux machine
#!/bin/bash -e
#
# Creates user and adds public key
# Must be run as root
#
# Requires:
# 1) Full name
# 2) Username
# 3) Public key
@peterkappus
peterkappus / .gitignore
Created July 3, 2017 21:56
Dockerised Rails Development Environment (take 1)
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
/.bundle
# Ignore all logfiles and tempfiles.