Skip to content

Instantly share code, notes, and snippets.


Jefe Johnson jeffjohnson9046

View GitHub Profile
jeffjohnson9046 / .vimrc
Created July 1, 2021 14:09
My vim settings
View .vimrc
set laststatus=2
set nu
syntax on
set statusline= " clear the statusline for when vimrc is reloaded
set statusline+=%-3.3n\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%m%r%w " flags
set statusline+=[%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{strlen(&fenc)?&fenc:&enc}, " encoding
View create-postgres-db-and-schema.sql
CREATE USER [database owner name] WITH CREATEROLE ENCRYTPED PASSWORD '[database owner's password]';
CREATE DATABASE [database name] OWNER [database owner name];
-- connect to [database name]
-- log in as [database owner name] to [database name] db
CREATE SCHEMA [schema name];
jeffjohnson9046 / settings.json
Created June 30, 2020 23:40
My settings.json for VS Code
View settings.json
"workbench.iconTheme": "material-icon-theme",
"workbench.startupEditor": "newUntitledFile",
"workbench.colorCustomizations": {
"editorRuler.foreground": "#1a1a1a",
// Came from snazzy.json, here:
"terminalCursor.background": "#282a36",
"terminalCursor.foreground": "#97979b",
"terminal.selectionBackground": "#97979b33",
jeffjohnson9046 / range-generator.js
Created June 27, 2020 17:07
A Javascript generator to generate a range of numbers
View range-generator.js
// Source:
function* range(start, end) {
yield start;
if (start === end) {
yield* range(start + 1, end);
jeffjohnson9046 / ant-condition-test.xml
Created June 11, 2020 20:35
A quick test of condition elements in ant
View ant-condition-test.xml
<project name="condition-test" default="all">
<target name="condition">
<condition property="isTomcat">
<matches pattern="^(tomcat)" string="${webContainer}" />
<condition property="isWebLogic">
<matches pattern="^(web)" string="${webContainer}" />
jeffjohnson9046 / find-foreign-keys.sql
Created May 4, 2020 21:12
Find all the foreign keys in a Postgres database.
View find-foreign-keys.sql
-- from here:
select kcu.table_schema || '.' ||kcu.table_name as foreign_table,
'>-' as rel,
rel_tco.table_schema || '.' || rel_tco.table_name as primary_table,
string_agg(kcu.column_name, ', ') as fk_columns,
from information_schema.table_constraints tco
join information_schema.key_column_usage kcu
on tco.constraint_schema = kcu.constraint_schema
and tco.constraint_name = kcu.constraint_name
jeffjohnson9046 /
Last active June 24, 2022 21:38
Connect to a private AWS RDS instance that is only accessible through a bastion (and not the internet)
# Assume the following scenario:
# * You have a bastion/jump server that is publicly available
# * You have an RDS instance that is _not_ publicly accessible, but the bastion can get to it
# We have this setup with some of our k8s clusters: the cluster was created via kops, which _also_ sets up a VPC, a
# bastion server, all that good stuff. We use a "private" network topology to minimize public access to any of the
# resources in the cluster.
# We _also_ create our RDS instances in the same VPC. The bastion and nodes get access to the RDS instance, but it isn't
# available to us common folk out here on the internet. That's good; we want to minimize access to the database, too.
jeffjohnson9046 /
Created February 13, 2020 19:37
A fancy jq filter to turn JSON output into a CSV format
# From the second answer here - this SO answer gets all the credit:
# This is the filter to convert JSON to CSV output:
# NOTE: This filter only works on "flat" JSON; nested properties don't work with this filter as-is.
jq -r '(.[0] | keys_unsorted) as $keys | ([$keys] + map([.[ $keys[] ]])) [] | @csv'
# For example:
aws ec2 describe-instances \
--region us-west-2 \
jeffjohnson9046 / ec2-instance-query.zsh
Last active October 10, 2022 13:57
Look up an EC2 Instance by public IP across more than one region
View ec2-instance-query.zsh
# This is the function I created that's a wee bit less shitty than the file above. I created a file called (oddly enough)
# ec2-instance-query.zsh and put it in my ~/.oh-my-zsh/custom directory. After sourcing my ~/zshrc, I have a fancy-pants
# function for querying EC2 instances and ElasticIP addresses for a given IP:
function ec2-instance-query() {
echo "Finding EC2 information for IP $1:"
for r in `aws ec2 describe-regions --output text | cut -f4 | grep "us-"`
aws ec2 describe-instances \
--region $r \
--filter "Name=network-interface.addresses.association.public-ip, Values=$1" \
jeffjohnson9046 / set-aws-env.zsh
Last active November 3, 2022 12:47
A zsh script for setting the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables
View set-aws-env.zsh
# I have several AWS profiles in my ~/.aws/config thus there are several access keys and secret keys in my
# ~/.aws/credentials file. Sometimes (e.g. when using kops or kubectl) I need to have the AWS_ACCESS_KEY_ID
# and AWS_SECRET_ACCESS_KEY environment variables set. There doesn't seem to be a way to use the aws cli to set these
# environment variables for me, so... well... here we are.
# This script will:
# * Look at the ~/.aws/credentials file for the specified profile
# * Get the next two lines beneath the profile name, which are the access_key_id and secret_key respectively
# * Export those two values as environment variables