Skip to content

Instantly share code, notes, and snippets.

View gkhays's full-sized avatar

Garve Hays gkhays

View GitHub Profile
@gkhays
gkhays / StringUtils.java
Created August 6, 2013 20:49
Quick and dirty C# style isNullOrEmpty helper for Java.
package org.test;
public class Utils
{
private Utils() {}
/**
* Determines whether or not the given string is null or contains an empty
* value.
* @param s
@gkhays
gkhays / ClientThread.java
Last active December 20, 2015 23:19
This is a set of classes used to test FIPS 140-2 and SSL communications in general. The OpenSSL s_server and s_client utilities are a great resource to use as partners in the testing process.
package org.gkh.net;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.logging.Logger;
@gkhays
gkhays / minecraft-server
Created June 17, 2014 15:04
Run Minecraft Server as a Daemon
I liked this one the best: http://www.minecraftforum.net/topic/74402-setup-linux-daemon/.
1) Get the code snippet below into a file in /etc/init.d/. This will be referenced as FILENAME henceforth. I used:
/etc/init.d/minecraft-server:
minecraft-server
#! /bin/sh
#
# network Bring up/down networking
@gkhays
gkhays / mc-parselog
Created June 17, 2014 15:14
Minecraft Server Log One-Liners
Create a list of users based on logins
grep "logged in with entity id" server.log | cut -f4 -d" " | sort -u > users.txt
Get connection information:
Date/Time, Name, and IP Address
grep logged server.log | cut -f1,2,4,5 -d" "
Get disconnect information:
Date/Time, Name
grep disconnect server.log | cut -f1,2,4 -d" "
@gkhays
gkhays / Java-Mail.md
Last active January 5, 2022 19:31
How to use JavaMail to send email via an SMTP server. I was recently working with a server component that allowed for scheduling reports, which included email notification. I wanted to isolate the email notification portion. Check. :)

JavaMail

SMTP test driver using JavaMail version 1.5.2.

# SSL/TLS port: 465
# Otherwise: 587
smtp.host=smtp.mail.yahoo.com
smtp.port=465
smtp.useSsl=true
package org.gkh.test;
/*
* Utility class for converting to and from hexadecimal.
*/
public class HexUtil {
private static final int SEG_SIZE = 16;
private static final char[] hexDigits = {
@gkhays
gkhays / StringSwitch.java
Created July 3, 2014 21:46
Prior to JDK 1.7, you had to use an approximation to evaluate strings in a switch statement. Much easier now!
package org.gkh.test;
/*
* Prior to JDK 1.7, you had to use an approximation to evaluate strings in a
* switch statement. See the following links.
* http://www.xefer.com/2006/12/switchonstring
* http://stackoverflow.com/questions/338206/switch-statement-with-strings-in-java
* http://docs.oracle.com/javase/7/docs/technotes/guides/language/strings-switch.html
*/
public class StringSwitch {
@gkhays
gkhays / TestQueuingThread.java
Last active August 29, 2015 14:03
A simple inter-process communication (IPC) utility that watches for the creation of tiles in a specific subdirectory and then queues them for processing. Currently hard-coded to watch a subdirectory called "Locker" located in the test directory relative to the execution path.
package org.gkh.test;
import java.nio.file.Path;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
/**
* This is a demonstration Producer/Consumer that queues and dequeues new file
* items as they are created in the directory we are watching.
*
@gkhays
gkhays / JrxmlParser.java
Created July 7, 2014 19:40
A simple JasperReports parser that also demonstrates issues with UTF-8 encoded XML files.
package org.gkh.test;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@gkhays
gkhays / GoogleAuthCode.java
Last active August 29, 2015 14:20
Working with Google APIs
package com.netiq;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Properties;