Skip to content

Instantly share code, notes, and snippets.

@pilgrim2go
pilgrim2go / postgres-cheatsheet.md
Created September 20, 2017 06:03 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@pilgrim2go
pilgrim2go / psql-with-gzip-cheatsheet.sh
Created September 19, 2017 07:13 — forked from brock/psql-with-gzip-cheatsheet.sh
Exporting and Importing Postgres Databases using gzip
# This is just a cheat sheet:
# On production
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz
# On local
scp -C production:~/database.sql.gz
dropdb database && createdb database
gunzip < database.sql.gz | psql database
@pilgrim2go
pilgrim2go / checkDockerDisks.sh
Created August 15, 2017 08:34 — forked from robsonke/checkDockerDisks.sh
This Bash script will loop through all running docker containers on a host and list the disk usage per mount. In case it's breaching the 65%, it will email you.
#!/bin/bash
# get all running docker container names
containers=$(sudo docker ps | awk '{if(NR>1) print $NF}')
host=$(hostname)
# loop through all containers
for container in $containers
do
echo "Container: $container"
@pilgrim2go
pilgrim2go / formatFilename.py
Created August 1, 2017 05:10 — forked from seanh/formatFilename.py
Turn any string into a valid filename in Python.
def format_filename(s):
"""Take a string and return a valid filename constructed from the string.
Uses a whitelist approach: any characters not present in valid_chars are
removed. Also spaces are replaced with underscores.
Note: this method may produce invalid filenames such as ``, `.` or `..`
When I use this method I prepend a date string like '2009_01_15_19_46_32_'
and append a file extension like '.txt', so I avoid the potential of using
an invalid filename.
@pilgrim2go
pilgrim2go / logging_subprocess.py
Created July 21, 2017 03:48 — forked from bgreenlee/logging_subprocess.py
Variant of subprocess.call that accepts a logger instead of stdout/stderr #python
import subprocess
import select
from logging import DEBUG, ERROR
def call(popenargs, logger, stdout_log_level=DEBUG, stderr_log_level=ERROR, **kwargs):
"""
Variant of subprocess.call that accepts a logger instead of stdout/stderr,
and logs stdout messages via logger.debug and stderr messages via
logger.error.
What exactly is "iowait"?
To summarize it in one sentence, 'iowait' is the percentage
of time the CPU is idle AND there is at least one I/O
in progress.
Each CPU can be in one of four states: user, sys, idle, iowait.
Performance tools such as vmstat, iostat, sar, etc. print
out these four states as a percentage. The sar tool can
print out the states on a per CPU basis (-P flag) but most
@pilgrim2go
pilgrim2go / install-comodo-ssl-cert-for-nginx.rst
Created June 28, 2017 03:40 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@pilgrim2go
pilgrim2go / nginx.conf
Created June 28, 2017 02:35 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@pilgrim2go
pilgrim2go / docker-osx-shared-folders.rst
Last active June 7, 2017 05:06 — forked from codeinthehole/docker-osx-shared-folders.rst
How to share folders with docker containers on OSX

How to share a folder with a docker container on OSX

Mounting shared folders between OSX and the docker container is tricky due to the intermediate boot2docker VM. You can't use the usual docker -v option as the docker server knows nothing about the OSX filesystem - it can only mount folders from the boot2docker filesystem. Fortunately, you can work around this using SSHFS.

@pilgrim2go
pilgrim2go / XcodeBuildLogParser
Created May 24, 2017 05:00 — forked from danielpunkass/XcodeBuildLogParser
Example configuration file for Jenkins's build log parser plugin, including some rules for Xcode quirks
# don't treat any of these as errors, warnings or info
ok /setenv /
# ignore TidyXML warnings
ok /line [0-9]+ column [0-9]+ - Error:/
ok /line [0-9]+ column [0-9]+ - Warning:/
ok /[0-9]+ warning.+ error.+ found!/
# ignore weird warnings about build variables in Info.plist:
# e.g. "warning: ignoring operator ':rfc1034Identifier' on 'RSWebClientCore' for macro 'PRODUCT_NAME'"