Skip to content

Instantly share code, notes, and snippets.

View jeffrade's full-sized avatar

Jeff Rade jeffrade

View GitHub Profile
@jeffrade
jeffrade / process_params.sh
Last active February 19, 2019 22:46
Bash script that will pop a line item for a file and pass it to a command.
#!/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 $!`
@jeffrade
jeffrade / patch-repo-finish.sh
Created October 23, 2018 16:42
Bash Scripts to separate single dir to own git repo
#!/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 October 21, 2018 17:16
Java Abstract Class Instantiation and Overriding 101
/**
* Prints:
* creating A
* creating B
* in B print
*/
public class Main {
public abstract class A {
public A() {
@jeffrade
jeffrade / java-tools.sh
Created October 9, 2018 21:26
JDK Tools for Java Processes
##########################################################
### 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 June 6, 2018 20:59
How to create a `javaagent` executable jar
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 02:24
Covert a String object to String binary representation in 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 March 8, 2018 19:47
An iterative implementation of Quick Sort in 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 December 18, 2016 04:26
My personal Github identity for Keybase.io

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 October 23, 2016 00:43
Example of a Java class that is NOT thread-safe
public class NotThreadSafe {
private static final NotThreadSafe INSTANCE = new NotThreadSafe();
private boolean isEven = false;
private NotThreadSafe() {
super();
}