Skip to content

Instantly share code, notes, and snippets.

Jeff Rade jeffrade

View GitHub Profile
@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();
}
@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 / 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 / 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 / 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 / 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 / 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 / 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 / process_queue.sh
Last active Feb 3, 2019
Bash Script (infinite loop) to Upload Files to AWS S3 Glacier
View process_queue.sh
#!/bin/bash
QUEUE_DIR="./queue"
COMPLETED_DIR="./completed"
S3_BUCKET_NAME="<YOUR_BUCKET_NAME_HERE>"
OLDEST_FILENAME=""
echo "Running..."
while :; do
echo "Finding oldest file..."
@jeffrade
jeffrade / process_params.sh
Last active Feb 19, 2019
Bash script that will pop a line item for a file and pass it to a command.
View process_params.sh
#!/bin/bash
echo "Starting..."
param=`sed -e 1$'{w/dev/stdout\n;d}' -i~ params.out`
while [[ -n $param ]]; do
echo "Starting process for $param..."
<some-command> $param &
curr_pid=`echo $!`
You can’t perform that action at this time.