Skip to content

Instantly share code, notes, and snippets.

View jeffjohnson9046's full-sized avatar

Jefe Johnson jeffjohnson9046

View GitHub Profile
@jeffjohnson9046
jeffjohnson9046 / UuidHelper.java
Last active July 14, 2024 12:38
Convert UUID to byte array and vice versa. Useful for when UUIDs are stored in MySQL tables as VARBINARY(16)
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 / dm_io_virtual_file_stats.sql
Created December 26, 2015 19:56
MS SQL Server database file I/O stats
SELECT
a.io_stall, -- Total time, in milliseconds, that users waited for I/O to be completed on the file.
a.io_stall_read_ms, -- Total time, in milliseconds, that the users waited for reads issued on the file.
a.io_stall_write_ms, -- Total time, in milliseconds, that users waited for writes to be completed on the file.
a.num_of_reads, -- Number of reads issued on the file.
a.num_of_writes, -- Number of writes made on this file.
--a.sample_ms, a.num_of_bytes_read, a.num_of_bytes_written, a.io_stall_write_ms,
( ( a.size_on_disk_bytes / 1024 ) / 1024.0 ) AS size_on_disk_mb,
db_name(a.database_id) AS dbname,
b.name,
@jeffjohnson9046
jeffjohnson9046 / setjdk.sh
Created May 24, 2016 15:00
A function for switching between Java JDKs on OS X
# I'm in a situation where I have multiple JDKs installed for various projects. While I'm sure there are a million was to handle this
# issue (a number of sites recommended jenv), I just wanted a quick & easy way to switch between JDKs that are installed on my machine.
# I took the following steps:
#
# 1. Add the functions below to your ~/.bash_profile
# 2. Source your ~/.bash_profile (command is . ~/.bash_profile) or exit and reload your terminal window
#
# These functions came from here: https://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/, so all credit goes to the author of that article
function setjdk() {
if [ $# -ne 0 ]; then
#!/usr/bin/perl -w
#-----------------------------------------------------------------------------------------------------------------------------------------
# File: aws-email-sender.pl
#
# Desc: Send an email via Amazon SES.
#
# Code for this gist came from this article: https://blog.vpetkov.net/2015/11/29/sending-html-emails-with-perl-to-a-remote-smtp-with-tls/
# To install the packages/libraries required to support this script, the following commands were used:
#
# cpan Email::Sender
SELECT DISTINCT TABLE_NAME, TABLE_SCHEMA
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN (/* list of column names go here */)
AND TABLE_SCHEMA IN (/* list of schemas go here */);
@jeffjohnson9046
jeffjohnson9046 / uuid-to-varbinary-16.sql
Created November 16, 2016 17:06
MySQL - Generate a UUID and convert it to VARBAINARY(16) for storage
SELECT UNHEX(REPLACE(UUID(),'-',''))
@jeffjohnson9046
jeffjohnson9046 / mysql-foreign-key-reference-lookup.sql
Created January 6, 2017 00:05
MySQL - Identify other tables that reference a table by a foreign key constraint
SELECT *
FROM information_schema.KEY_COLUMN_USAGE
WHERE table_schema = /* the schema you're interested in */
AND referenced_table_name = /* name of the table that is referenced by other tables via foreign key */;
@jeffjohnson9046
jeffjohnson9046 / cli-prompt.sh
Last active April 12, 2017 22:26
Command prompt that shows current git branch
GREEN='\[\033[0;32m\]'
YELLOW='\[\033[0;33m\]'
NC='\[\033[0m\]' # No Color
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo "*"
}
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
@jeffjohnson9046
jeffjohnson9046 / mysql-convert-varbinary-to-uuid.sql
Last active February 21, 2017 22:48
functions for converting a UUID stored as VARBINARY(16) into its UUID form and vice versa
/*
* From here: http://mysql.rjweb.org/doc.php/uuid
*/
-- Convert a formatted UUID to a BINARY(16)
CREATE FUNCTION UuidToBin(_uuid CHAR(36))
RETURNS BINARY(16)
LANGUAGE SQL DETERMINISTIC CONTAINS SQL SQL SECURITY INVOKER
RETURN
UNHEX(CONCAT(
SUBSTR(_uuid, 15, 4),
@jeffjohnson9046
jeffjohnson9046 / spring-cli-encryption-setup.sh
Last active April 7, 2018 00:05
How I set up my Mac for encrypting values using Spring on the command line
# Install the Spring Boot CLI via homebrew (https://brew.sh/)
brew update
brew tap pivotal/tap
brew install springboot
# Download the Java 8 JCE from here: http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
# Extract the .zip file somewhere. There should be three files:
#
# local_policy.jar
# README.txt