Skip to content

Instantly share code, notes, and snippets.

View tfentonz's full-sized avatar

Tom Fenton tfentonz

  • MAGIQ Software
  • Christchurch, New Zealand
  • 14:10 (UTC +12:00)
  • LinkedIn in/tfentonz
View GitHub Profile
@tfentonz
tfentonz / dig-spf.md
Last active September 5, 2016 10:36
dig spf command

dig spf command

$ dig +noall +answer @emily.ns.cloudflare.com roadsafetyrisk.co.nz txt
roadsafetyrisk.co.nz.  	900    	IN     	TXT    	"v=spf1 mx include:sendgrid.net -all"

Note: RFC 7208 section 3.1 SPF SPF records MUST be published as a DNS TXT.

@tfentonz
tfentonz / rsync.sh
Created September 5, 2016 22:50
rsync command
rsync -vaz -e "ssh -l USER" \
--perms \
--exclude-from FILE \
--delete-excluded \
/path/to/sync/ \
123.45.6.78:/path/to/sync/

wget options

wget -r -q --user $FTP_USER --password $FTP_PASS ftp://erewhon.co.nz/some/path/ --cut-dirs=1 -nH -N

Logging and input file:
  -q,  --quiet                     quiet (no output)
  
Download:
 -N, --timestamping don't re-retrieve files unless newer than
@tfentonz
tfentonz / aws_cli.md
Last active December 1, 2016 05:04
Amazon CLI Commands

Amazon CLI Commands

EC2

Get instance public hostname

Substitute <NAME> for instance name.

$ aws ec2 describe-instances --query 'Reservations[].Instances[].PublicDnsName' --filters Name=tag:Name,Values= --output text 
@tfentonz
tfentonz / elasticsearch_rest_api.md
Last active November 24, 2016 04:01
Elasticsearch REST API
@tfentonz
tfentonz / aws_postgres_db_instances.sh
Last active December 6, 2016 00:58
Ouput array of DB instances with PostgreSQL engine
#!/bin/bash
aws rds describe-db-instances --query 'DBInstances[].{DBName:DBName,Engine:Engine,EngineVersion:EngineVersion}' |
jq '[.[] | select(.Engine == "postgres") | {db_name:.DBName,engine:.Engine,engine_version:.EngineVersion}]'
exit 0
#!/bin/bash
# Requires an S3 bucket with website redirect for zone apx
# e.g. example.com -> www.example.com
# See http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
# for alias target hosted zone ID.
hosted_zone_id="ZABCDEFGHIJ1K"
alias_target_hosted_zone_id="Z1WCIGYICN2BYD"
aws route53 change-resource-record-sets \
@tfentonz
tfentonz / readonly_user.sql
Last active July 7, 2017 00:00
PostgreSQL read only user
psql <database>
CREATE USER <user> WITH PASSWORD '<password>' VALID UNTIL 'infinity';
GRANT CONNECT ON DATABASE <database> TO <user>;
GRANT USAGE ON SCHEMA public TO <user>;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO <user>;
GRANT SELECT ON ALL TABLES IN SCHEMA public to <user>;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO <user>;
ln -nfs /usr/local/Cellar/postgis/2.3.2/share/postgresql/extension/postgis.control /usr/local/Cellar/postgresql@9.5/9.5.6/share/postgresql@9.5/extension/postgis.control
ln -nfs /usr/local/Cellar/postgis/2.3.2/share/postgresql/extension/postgis--2.3.2.sql /usr/local/Cellar/postgresql@9.5/9.5.6/share/postgresql@9.5/extension/postgis--2.3.2.sql
@tfentonz
tfentonz / docker-exited.sh
Last active September 3, 2017 21:33
Docker exited containers state
docker inspect $(docker ps -q --filter status=exited) |
jq '.[].State | { Status: .Status, ExitCode: .ExitCode, FinishedAt: .FinishedAt }'