Skip to content

Instantly share code, notes, and snippets.

Jefe Johnson jeffjohnson9046

Block or report user

Report or block jeffjohnson9046

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jeffjohnson9046
jeffjohnson9046 / UuidHelper.java
Last active Dec 12, 2019
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 / ruby-ldap-sample.rb
Last active Nov 14, 2019
Some VERY basic LDAP interaction in Ruby using Net::LDAP.
View ruby-ldap-sample.rb
#######################################################################################################################
# This Gist is some crib notes/tests/practice/whatever for talking to Active Directory via LDAP. The (surprisingly
# helpful) documentation for Net::LDAP can be found here: http://net-ldap.rubyforge.org/Net/LDAP.html
#######################################################################################################################
require 'rubygems'
require 'net/ldap'
#######################################################################################################################
# HELPER/UTILITY METHOD
@jeffjohnson9046
jeffjohnson9046 / k8s-get-docker-container-memory.sh
Created Oct 19, 2019
Get the currently used and maximum available memory for a Docker container running in Kubernetes
View k8s-get-docker-container-memory.sh
# These commands demonstrate how to determine how much memory is availble on a k8s worker node and how much memory is
# available to the k8s _container_ hosted on that node.
# Source:
# https://shuheikagawa.com/blog/2017/05/27/memory-usage/
#
# Other interesting articles:
# https://docs.docker.com/engine/docker-overview/#the-underlying-technology
# https://docs.docker.com/config/containers/resource_constraints/
#
# These values are approximations, because according to the first article, calculating/determining available memory
@jeffjohnson9046
jeffjohnson9046 / percent-filter.js
Last active Sep 18, 2019
Format percentages in AngularJS
View percent-filter.js
// In app.js or main.js or whatever:
// var myApp = angular.module('askchisne', ['ngSanitize', 'ngAnimate', 'ui.bootstrap', 'ui.bootstrap.tpls']);
// This filter makes the assumption that the input will be in decimal form (i.e. 17% is 0.17).
myApp.filter('percentage', ['$filter', function ($filter) {
return function (input, decimals) {
return $filter('number')(input * 100, decimals) + '%';
};
}]);
@jeffjohnson9046
jeffjohnson9046 / sinatra-server.rb
Last active Aug 31, 2019
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 / create-saml-keystore.sh
Last active Aug 8, 2019
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 / spring-cloud-config-decrypt-curl.sh
Last active Aug 5, 2019
Use the Spring Cloud Config service to encrypt/decrypt an encrypted value
View spring-cloud-config-decrypt-curl.sh
# Encrypt
curl -sbiL -X POST http://localhost:8888/encrypt -d '[the value you want to encrypt]'
# Decrypt
curl -sbiL -X POST http://localhost:8888/decrypt -d '[the encrypted value, without the "{cipher}" prefix]'
@jeffjohnson9046
jeffjohnson9046 / .psqlrc
Last active Aug 3, 2019
A .psqlrc file gathered from various sources, for use with PostgreSQL
View .psqlrc
-- Set client encoding
\encoding UTF8
\set QUIET 1
-- print 'NULL' (instead of a blank) for any columns that have a null value
\pset null 'NULL'
-- Do not automatically commit after every statement
\set AUTOCOMMIT off
@jeffjohnson9046
jeffjohnson9046 / rename-first-char-to-uppercase.sh
Last active Jul 30, 2019
Rename files/directories so that the first letter is upper-case on OS X
View rename-first-char-to-uppercase.sh
# Assume you have a directory structure that looks something like this:
ls -alh /path/to/my/directory
drwxr-xr-x 38 jeffjohnson staff 1.2K Jul 18 11:07 ./
drwxr-xr-x 6 jeffjohnson staff 192B Jun 23 15:00 ../
drwxr-xr-x 10 jeffjohnson staff 320B Aug 28 2017 foo/
drwxr-xr-x 12 jeffjohnson staff 384B Dec 18 2017 bar/
drwxr-xr-x 11 jeffjohnson staff 352B Feb 26 2018 baz/
-rw-r--r-- 1 jeffjohnson staff 1.8M Aug 14 2017 some-update.sql
# list continues...
@jeffjohnson9046
jeffjohnson9046 / .mongrc.js
Created Jun 27, 2019
A prompt for the mongo shell that displays the user you're logged in as and the database you're pointed at.
View .mongrc.js
/**
Set the mongo shell prompt to display [user name]@[database name]. If the user or database name cannot
be captured, then display "<none>" instead.
*/
var prompt = function() {
var user = db.runCommand({connectionStatus : 1}).authInfo.authenticatedUsers[0].user || "<none>";
var dbLabel = db.getName() || "<none>";
return user + "@" + dbLabel + ">";
}
You can’t perform that action at this time.