Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jeffjohnson9046's full-sized avatar

Jefe Johnson jeffjohnson9046

View GitHub Profile
@jeffjohnson9046
jeffjohnson9046 / ssh-tunnel-to-private-rds.sh
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
jeffjohnson9046 / mssql-find-foreign-key-references.sql
Created November 10, 2017 22:11
MS SQL Server: for a given table, find all "child" tables that reference it
-- Based on answer from here:
-- https://stackoverflow.com/questions/483193/how-can-i-list-all-foreign-keys-referencing-a-given-table-in-sql-server
SELECT
child.name AS child_table,
fk.constraint_column_id AS fk_part_no,
c.name AS foreign_key_column
FROM
sys.foreign_key_columns AS fk
JOIN
sys.tables child
@jeffjohnson9046
jeffjohnson9046 / curl-cloud-config-props.sh
Last active May 26, 2022 17:35
use curl to check out a Spring Boot applicaion's configuration properties from a Spring Cloud Configuration service
# Occasionally I want to see the application properties that are pulled down from the Spring Cloud Config service that provides
# content to our Spring Boot apps. Since I seem to have to re-discover this every time, I figured I'd write it down to help me
# remember.
#
# Additional docs can be found here: https://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html
# To see the output in YML format
curl -u {the user name}:{the user password} http://{the domain:port}/{the application name}-{the spring profile name}.yml
# For example:
@jeffjohnson9046
jeffjohnson9046 / sql-server-generate-random-date.sql
Created July 31, 2015 23:36
MSSQL - Generate a random datetime value for a given year.
DECLARE @RandomDate datetime
SELECT @RandomDate =
DATEADD(day, ROUND(DATEDIFF(day, '2015-01-01', '2015-12-31') * RAND(CHECKSUM(NEWID())), 0),
DATEADD(second, CHECKSUM(NEWID()) % 48000, '2015-01-01'))
/* Verify */
SELECT RandomDate = @RandomDate
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]
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON DATABASE [database name] FROM PUBLIC;
REVOKE ALL ON ALL TABLES IN SCHEMA public FROM PUBLIC;
-- log in as [database owner name] to [database name] db
CREATE SCHEMA [schema name];
@jeffjohnson9046
jeffjohnson9046 / jq-json-to-csv.sh
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:
# https://stackoverflow.com/questions/32960857/how-to-convert-arbitrary-simple-json-to-csv-using-jq
# 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
jeffjohnson9046 / .vimrc
Created July 1, 2021 14:09
My vim settings
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
@jeffjohnson9046
jeffjohnson9046 / create-saml-keystore.sh
Last active June 3, 2021 21:49
Create a SAML keystore for SSO
# Create a password-protected keystore. Change the -keypass value to a password that meets your password policy. LastPass (or some other password generator) can come in handy here for creating a password.
keytool -genkeypair -alias my-service-provider -keypass password -keyalg RSA -keysize 2048 -keystore my-sso-keystore.jks
# Use openssl to get the identity provider's public key as a file named sso.crt.
openssl s_client -connect my-sso-domain.example.com:443 > sso.crt
# Open the sso.crt file in any editor and remove everything around the BEGIN and END lines. If required, concatenate with any intermediate certificates.
vi sso.crt
# When done editing, the file should look similar to this:
@jeffjohnson9046
jeffjohnson9046 / kops-export-config.sh
Last active May 8, 2021 22:36
How to update kubectl to see a new Kubernetes cluster
# This is something that I always forget and had a surprisingly hard time finding (or better yet, understanding). Here's the
# scenario: a colleague creates a new kubernetes cluster, named" cluster-foo.example.com". You want to look at it (for
# troubleshooting, updating the deployment, whatever). To get your kubectl installation to "see" the new cluster, take the
# following steps:
# ASSUMPTION: You have pointed kops to some location where the cluster configurations are stored
# (I have this in my ~/.bash_profile):
export KOPS_STATE_STORE=s3://example-state-store
# Use kops to get the list of clusters
@jeffjohnson9046
jeffjohnson9046 / jquery-deferred-promise-example.js
Last active October 28, 2020 20:53
A quick example of how to use deferred and promise in jquery
// jsfiddle: https://jsfiddle.net/Lkxtryvp/1/
var myAwesomeLoop = function(x) {
// This is the magic sauce right here - you're creating a unit of work that will be done at some
// point in the future. We're not exactly sure when, but the deferred object will notify us when
// it's done (by calling "resolve()" or "reject()" on itself).
var deferred = $.Deferred();
// We'll create a simple loop to concatenate some values together. This simulates where the
// actual, for-real work would be done (e.g. an AJAX request, some sort of long-running calculation, etc)