Skip to content

Instantly share code, notes, and snippets.

View gkhays's full-sized avatar

Garve Hays gkhays

View GitHub Profile
@gkhays
gkhays / showargs.sh
Last active September 14, 2016 16:08
Show bash command line arguments
#!/bin/bash
# http://commons.apache.org/proper/commons-exec/commandline.html
# http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_07.html
while [ $# -gt 0 ]
do
echo "$1"
shift
done
import java.io.*;
/**
* @see <a href="http://alvinalexander.com/java/edu/pj/pj010016">Running system commands in Java applications</a>
* /
public class JavaRunCommand {
public static void main(String args[]) {
String s = null;
@gkhays
gkhays / setenv.sh
Created October 28, 2015 14:31 — forked from terrancesnyder/setenv.sh
./setenv.sh - example setenv.sh with defaults set for minimal time spent in garbage collection
#! /bin/sh
# ==================================================================
# ______ __ _____
# /_ __/___ ____ ___ _________ _/ /_ /__ /
# / / / __ \/ __ `__ \/ ___/ __ `/ __/ / /
# / / / /_/ / / / / / / /__/ /_/ / /_ / /
#/_/ \____/_/ /_/ /_/\___/\__,_/\__/ /_/
# Multi-instance Apache Tomcat installation with a focus
# on best-practices as defined by Apache, SpringSource, and MuleSoft
@gkhays
gkhays / PasswordMask.java
Last active January 6, 2022 07:13
How to mask a password when input from the console. Contains a work-around for running within Eclipse; see Eclipse bug #122429.
package org.gkh;
import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
public class ConsoleUtil {
/**
@gkhays
gkhays / JavaDocHowTo.java
Last active March 18, 2016 21:14
JavaDoc Common Usage
/**
* Represents the Microsoft Azure AD service. The methods to which you should
* pay attention are {@link #executeJSONChunkRequest(JSONObject, String, int)}
* and {@link #setConfigData(String, int, String, JSONObject)}. These are
* respectively where data requests from <code>DaaS</code> come and where the
* service is configured.
* <p>
* This is the class referenced by collector templates. E.g.
*
* <pre>
@gkhays
gkhays / ReadFile.md
Last active July 7, 2022 20:03
Some methods to read a file from disk into a string.

Read a File from Disk into a String

Various methods for reading the contents of a file from disk into a string.

Using NIO

One-liner bonus! 😄

String contents = new String(Files.readAllBytes(Paths.get(fileName)));

Markdown Quick Start

This is my attempt to capture some of the things I (relatively) frequently do in Markdown. It is by no means definitive, but I always seem to forget these ones.

Links

Inline-style links use parentheses immediately after the link text. For example:

This is an [example link](http://example.com/).
@gkhays
gkhays / JUnit.md
Last active July 13, 2017 13:58
Some new JUnit tricks...

How Many Assertions Per Unit Test

There is a really good exchange on Programmers Stack Exchange on the number of assertions to have in a single unit test: Is it OK to have multiple asserts in a single unit test?

Proper unit tests should fail for exactly one reason, that's why you should be using one assert per unit test.

More Assertions for JUnit

The "match at least one" example below relies on Hamcrest matchers. There is an alternative to Hamcrest, see AssertJ documentation.

@gkhays
gkhays / Docker-Java.txt
Last active March 18, 2016 21:19 — forked from HennIdan/Docker-Java.txt
Installing Java from Oracle
# Download and unarchive Java
RUN mkdir /opt && curl -jksSLH "Cookie: oraclelicense=accept-securebackup-cookie"\
http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz \
| tar -xzf - -C /opt &&\
ln -s /opt/jdk1.7.0_79 /opt/jdk &&\
rm -rf /opt/jdk/*src.zip \
/opt/jdk/lib/missioncontrol \
/opt/jdk/lib/visualvm \
/opt/jdk/lib/*javafx* \
/opt/jdk/jre/lib/plugin.jar \
@gkhays
gkhays / Apache Commons and Log4J Logging.md
Last active January 19, 2024 13:52
Logging with Log4j and Apache Commons

Apache Commons and Log4J Logging

This article illustrates a quick start to using Log4J and commons logging. Obtaining a log factory and logging to various levels is fairly straight-forward. What can be tricky is getting the properties files correct. The code snippet below depends on:

  • commons-logging-1.1.jar
  • log4j-1.2.16.jar
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;