Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff Rade jeffrade

View GitHub Profile
@jeffrade
jeffrade / openssl.x509.sh
Last active Sep 11, 2019
Bash script to check certificate information - uses openssl.
View openssl.x509.sh
#!/bin/sh
if [ -z "$1" ]
then
echo "Please supply a domain, e.g. www.example.com"
exit 1
fi
echo | openssl s_client -servername $1 -connect $1:443 2>/dev/null | openssl x509 -text
echo "Saving public ./cert.pem..."
@jeffrade
jeffrade / patch-repo-finish.sh
Created Oct 23, 2018
Bash Scripts to separate single dir to own git repo
View patch-repo-finish.sh
#!/usr/bin/env bash
# To run this script, you must checkout the NEW_REPO
# repo and have it in the same dir as OLD_REPO.
#
# First execute the reset-repo.sh
# Then execute the patch-repo-start.sh
# Then execute:
# $ ./patch-repo-finish.sh
cd ../../NEW_REPO/
@jeffrade
jeffrade / Main.java
Created Oct 21, 2018
Java Abstract Class Instantiation and Overriding 101
View Main.java
/**
* Prints:
* creating A
* creating B
* in B print
*/
public class Main {
public abstract class A {
public A() {
@jeffrade
jeffrade / java-tools.sh
Created Oct 9, 2018
JDK Tools for Java Processes
View java-tools.sh
##########################################################
### This file is not meant to be executed as a script! ###
### Usually found in $JAVA_HOME/bin ###
##########################################################
# Simply run this when you have any Java process running (launches a GUI). Choose your pid.
jconsole
# Run the following three commands in succession then navigate to http://localhost:7000/:
jps # To find your Java <pid>
@jeffrade
jeffrade / ExampleAgent.java
Created Jun 6, 2018
How to create a `javaagent` executable jar
View ExampleAgent.java
import java.lang.instrument.Instrumentation;
/**
* Let's say you have an existing application that is an executable jar file (e.g. app.jar)
* Define this class a directory of your choosing.
* Then create the following manifest.txt file:
* <code> $ echo "Premain-Class: ExampleAgent" > manifest.txt</code>
* Then create the jar file for this class:
* <code> $ jar cmf manifest.txt example-agent.jar *.class</code>
* Lastly, start your existing app.jar like so:
@jeffrade
jeffrade / StringToBinary.java
Last active May 25, 2018
Covert a String object to String binary representation in Java
View StringToBinary.java
public class StringToBinary {
// https://stackoverflow.com/a/917190
public static void main(String[] args) {
final String s = args.length > 0 ? args[0] : "foo";
final byte[] bytes = s.getBytes();
StringBuilder binary = new StringBuilder();
for (byte b : bytes) {
int val = b;
System.out.println("byte b=" + b);
@jeffrade
jeffrade / QuickSort.java
Created Mar 8, 2018
An iterative implementation of Quick Sort in Java
View QuickSort.java
import java.util.Queue;
import java.util.LinkedList;
public class QuickSort {
private int[] arr;
private Queue<int[]> queue;
public QuickSort(int[] arr) {
super();
@jeffrade
jeffrade / keybase.md
Created Dec 18, 2016
My personal Github identity for Keybase.io
View keybase.md

Keybase proof

I hereby claim:

  • I am jeffrade on github.
  • I am jeffrade (https://keybase.io/jeffrade) on keybase.
  • I have a public key whose fingerprint is 7720 4120 B545 1B89 1E8E 60E3 C332 9294 B0EA F9FB

To claim this, I am signing this object:

@jeffrade
jeffrade / NotThreadSafe.java
Created Oct 23, 2016
Example of a Java class that is NOT thread-safe
View NotThreadSafe.java
public class NotThreadSafe {
private static final NotThreadSafe INSTANCE = new NotThreadSafe();
private boolean isEven = false;
private NotThreadSafe() {
super();
}