Skip to content

Instantly share code, notes, and snippets.

View peterkappus's full-sized avatar

Peter Kappus peterkappus

View GitHub Profile
@peterkappus
peterkappus / month_to_quarter.txt
Created November 14, 2016 11:59
Convert month number to financial quarter (e.g. month 3 => quarter 4; month 10 => quarter 3)
(((month_num+8)%12)*4/12)+1
@peterkappus
peterkappus / rails_app_starter_2016.md
Last active November 20, 2016 13:17
How I've been making rails apps in 2016

How I make rails apps in 2016

This is a quick step-by-step guide for how I've been getting quick proof-of-concept rails apps up and running in 2016. Mostly for my own reference. Feedback welcome :)

Run it on Heroku

It’s just easier... Who needs to mess with devops in 2016?

  • Create an account at heroku.com
  • Install the Heroku command line tools on your machine
@peterkappus
peterkappus / how_i_make_rails_apps.md
Last active June 30, 2017 16:22
A regularly updated file on how I make rails apps.

How I make rails apps

This is a quick step-by-step guide for how I've made my latest rails app. Check the edit date to know when it was updated. Duh. ;)

Run it on Heroku

It’s just easier... Who needs to mess with devops these days.

  • Create an account at heroku.com
  • Install the Heroku command line tools on your machine

Get your machine ready

@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.
@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.
@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
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
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
host: db
username: postgres
password:
development:
@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
@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 {} +