Skip to content

Instantly share code, notes, and snippets.

View garystafford's full-sized avatar
💭
Happily Coding!

Gary A. Stafford garystafford

💭
Happily Coding!
View GitHub Profile
#!/usr/bin/env ruby
require 'aws-sdk'
# initialize S3 client
s3_client = Aws::S3::Client.new(region: 'us-east-1')
# initialize KMS client
kms_client = Aws::KMS::Client.new(region: 'us-east-1')
@quiver
quiver / retrieve-EC2-region-information-from-metadata.md
Last active March 14, 2024 16:42
retrieve EC2's region from instance metadata

Sometimes you want to retrieve EC2 insntances' region information.

You can query that information through instance metadata(169.254.169.254).

$ curl --silent http://169.254.169.254/latest/dynamic/instance-identity/document
{
  "privateIp" : "172.31.2.15",
  "instanceId" : "i-12341ee8",
  "billingProducts" : null,
 "instanceType" : "t2.small",
@iconara
iconara / queries.sql
Last active November 13, 2023 22:26
Low level Redshift cheat sheet
-- Table information like sortkeys, unsorted percentage
-- see http://docs.aws.amazon.com/redshift/latest/dg/r_SVV_TABLE_INFO.html
SELECT * FROM svv_table_info;
-- Table sizes in GB
SELECT t.name, COUNT(tbl) / 1000.0 AS gb
FROM (
SELECT DISTINCT datname, id, name
FROM stv_tbl_perm
JOIN pg_database ON pg_database.oid = db_id
@domenic
domenic / 0-github-actions.md
Last active April 8, 2024 23:35
Auto-deploying built products to gh-pages with Travis

Auto-deploying built products to gh-pages with GitHub Actions

This is a set up for projects which want to check in only their source files, but have their gh-pages branch automatically updated with some compiled output every time they push.

A file below this one contains the steps for doing this with Travis CI. However, these days I recommend GitHub Actions, for the following reasons:

  • It is much easier and requires less steps, because you are already authenticated with GitHub, so you don't need to share secret keys across services like you do when coordinate Travis CI and GitHub.
  • It is free, with no quotas.
  • Anecdotally, builds are much faster with GitHub Actions than with Travis CI, especially in terms of time spent waiting for a builder.
@garystafford
garystafford / helpful-git-commands.sh
Last active May 17, 2023 00:34
Helpful git commands
###############################################################################
# Helpful Git/GitHub commands and code snippets
###############################################################################
#### Remove/Squash All History on Master - CAUTION! ####
# https://stackoverflow.com/a/26000395/580268
git checkout --orphan latest_branch \
&& git add -A \\
&& git commit -am "Remove/squash all project history" \
&& git branch -D master \
@garystafford
garystafford / helpful-docker-commands.sh
Last active October 12, 2023 16:51
My list of helpful docker commands
###############################################################################
# Helpful Docker commands and code snippets
###############################################################################
### CONTAINERS ###
docker stop $(docker ps -a -q) #stop ALL containers
docker rm -f $(docker ps -a -q) # remove ALL containers
docker rm -f $(sudo docker ps --before="container_id_here" -q) # can also filter
# exec into container
@rusllonrails
rusllonrails / UBUNTU DOCKER FIG ERROR
Created August 14, 2014 12:16
UBUNTU DOCKER FIG ERROR
FIX FOR: Couldn't connect to Docker daemon at http+unix://var/run/docker.sock - is it running?
Change the DOCKER_OPTS in /etc/default/docker to:
DOCKER_OPTS="-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock"
Ruslan Khamidullin [1:57 PM] netstat -ant |grep 4243
tcp 0 0 127.0.0.1:4243 0.0.0.0:* LISTEN
Ruslan Khamidullin [1:57 PM] export DOCKER_HOST=tcp://localhost:4243
@Kartones
Kartones / postgres-cheatsheet.md
Last active April 30, 2024 19:47
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -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)
@lttlrck
lttlrck / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote