Skip to content

Instantly share code, notes, and snippets.

Jefe Johnson jeffjohnson9046

View GitHub Profile
@jeffjohnson9046
jeffjohnson9046 / kill-all-connections-to-db.sql
Created Jun 18, 2018
How to kill all connections to a Postgres database
View kill-all-connections-to-db.sql
-- Accepted answer from here: https://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '[your database name goes here]'
AND pid <> pg_backend_pid();
@jeffjohnson9046
jeffjohnson9046 / settings.json
Created Jun 30, 2020
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: https://github.com/Tyriar/vscode-snazzy/blob/master/snazzy.json
"terminalCursor.background": "#282a36",
"terminalCursor.foreground": "#97979b",
"terminal.selectionBackground": "#97979b33",
@jeffjohnson9046
jeffjohnson9046 / range-generator.js
Created Jun 27, 2020
A Javascript generator to generate a range of numbers
View range-generator.js
// Source:
// https://dev.to/ycmjason/how-to-create-range-in-javascript-539i
function* range(start, end) {
yield start;
if (start === end) {
return;
}
yield* range(start + 1, end);
}
@jeffjohnson9046
jeffjohnson9046 / create-saml-keystore.sh
Last active Jun 17, 2020
Create a SAML keystore for SSO
View create-saml-keystore.sh
# 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 / UuidHelper.java
Last active Jun 16, 2020
Convert UUID to byte array and vice versa. Useful for when UUIDs are stored in MySQL tables as VARBINARY(16)
View UuidHelper.java
import java.nio.ByteBuffer;
import java.util.UUID;
public class UuidAdapter {
public static byte[] getBytesFromUUID(UUID uuid) {
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
@jeffjohnson9046
jeffjohnson9046 / ant-condition-test.xml
Created Jun 11, 2020
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>
<condition property="isWebLogic">
<matches pattern="^(web)" string="${webContainer}" />
</condition>
</target>
@jeffjohnson9046
jeffjohnson9046 / sinatra-server.rb
Last active Jun 3, 2020
A simple sinatra server that accepts a POST with JSON content.
View sinatra-server.rb
# To make this server publicly available on the inter-webs while running from localhost, use ngrok, which can be found here:
# https://ngrok.com/download. Follow the installation instructions for ngrok and start it up:
#
# ./ngrok 4567 # (or whatever port you want to listen on).
#
# ngrok will spit out an ugly but unique URL. After ngrok starts up, you should be able to POST to the sinatra server:
#
# http://6eee766f.ngrok.com/payload
require 'sinatra'
require 'json'
@jeffjohnson9046
jeffjohnson9046 / title-case-filter.js
Created Mar 26, 2014
A title-case filter for AngularJs
View title-case-filter.js
// Came from the comments here: https://gist.github.com/maruf-nc/5625869
app.filter('titlecase', function() {
return function (input) {
var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;
input = input.toLowerCase();
return input.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, index, title) {
if (index > 0 && index + match.length !== title.length &&
match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
(title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &&
@jeffjohnson9046
jeffjohnson9046 / curl-cloud-config-props.sh
Last active May 8, 2020
use curl to check out a Spring Boot applicaion's configuration properties from a Spring Cloud Configuration service
View curl-cloud-config-props.sh
# 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 / find-foreign-keys.sql
Created May 4, 2020
Find all the foreign keys in a Postgres database.
View find-foreign-keys.sql
-- from here: https://dataedo.com/kb/query/postgresql/list-foreign-keys
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,
kcu.constraint_name
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
You can’t perform that action at this time.