Skip to content

Instantly share code, notes, and snippets.

View djangofan's full-sized avatar

Jon Austen djangofan

View GitHub Profile
@djangofan
djangofan / gist:2939268
Created June 15, 2012 23:56
Groovy script to watch a directory for changes in JDK1.7
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.*;
// requires JDK 1.7.0+
Path tmpPath = Paths.get( args[0])
WatchService watchService = FileSystems.getDefault().newWatchService()

Keybase proof

I hereby claim:

  • I am djangofan on github.
  • I am djangofan (https://keybase.io/djangofan) on keybase.
  • I have a public key ASBhRXM__QMBKBSS6qRsTKTVbYrZOoZlIBZuqDHklasJLQo

To claim this, I am signing this object:

@djangofan
djangofan / java_acp_exam_1.8_study_notes.txt
Last active August 7, 2021 16:46
java acp exam 1.8 study notes
Java 1.8 ACP Exam Study Factoids
------------------------
http://docs.oracle.com/javase/specs/jls/se8/html/index.html
http://stackoverflow.com/documentation/java/topics
http://www.programcreek.com/simple-java/
https://www.compilejava.net/
IOException and NumberFormatException are always thrown programmatically while other exceptions such as ArrayIndexOutOfBounds, ExceptionInitializerError, and NullPointerException are thrown by the JVM at runtime.
Initialize all local variables (unless they arent used)!
// see build.gradle for imports
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;
...
public abstract class Utilities {
public static final Logger logger = LoggerFactory.getLogger( "AnyUniqueStringHere" );
...
public static void printLoggerState() {
@djangofan
djangofan / test.xml
Created July 27, 2012 04:46
XML file sample
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root testAttr="testValue">
<result>
<child>data1</child>
<child>A1343358848.646</child>
<child>
<internal>
<data>one</data>
<data>two</data>
<unique>Z1343358848.646</unique>
@djangofan
djangofan / MultiThreadedJUnitRunner.java
Last active February 18, 2021 00:57
A multi-threaded JUnit runner example.
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
/**
* Runs all tests in parallel and waits for them to complete.
@djangofan
djangofan / QueryManager.java
Created July 19, 2018 21:33
An example of QueryManager in Java for JPA
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.HashMap;
import java.util.Map;
public class QueryBuilder {
private final EntityManager entityManager;
private final Map<String, Object> parameters = new HashMap<>();
private String resultSetMapping;
private String query;
@djangofan
djangofan / get_home.bat
Created December 8, 2011 00:11
DOS batch file to find JAVA_HOME
@ECHO OFF
:: ------------------------------------------------------------------
:: JavaHome.bat - search for and set JAVA_HOME
:: 1. If JAVA_HOME is set in system environment, do nothing else.
:: 2. If javahome.txt already exists, use that value
:: 3. If those fail, search parent directories for java.exe
:: 4. Finally, try looking in the registry for other Java installations
:: Note- Script does not add trailing slash to JAVA_HOME variable
:: Note- JBINARY var can be set to JRE or JDK detection
:: ------------------------------------------------------------------
@djangofan
djangofan / private_key.java
Created December 20, 2012 16:10
Get private key from a Java keystore file using Groovy
import java.security.Key
import java.security.KeyStore
if (args.length < 3)
throw new IllegalArgumentException('Expected args: <Keystore file> <Keystore format> <Keystore password> <alias> <key password>')
def keystoreName = args[0]
def keystoreFormat = args[1]
def keystorePassword = args[2]
def alias = args[3]
@djangofan
djangofan / instructions_ibm_mq_server.txt
Last active July 30, 2020 00:01
IBM MQ 9.1 server in 5 minutes...
#!/bin/bash
# https://github.com/ibm-messaging/mq-container/blob/master/docs/usage.md
# https://github.com/ibm-messaging/mq-container/blob/master/docs/developer-config.md
## https://www.blazemeter.com/blog/ibm-mq-testing-with-jmeter-learn-how
# https://localhost:9009/ibmmq/console
## User: admin
## Password: passw0rd
# http://localhost:9157/metrics
# Version found at: https://hub.docker.com/_/ibm-mq-advanced -- 9.1.2.0