Skip to content

Instantly share code, notes, and snippets.

View agentgt's full-sized avatar

Adam Gent agentgt

View GitHub Profile
@agentgt
agentgt / ThreadLocalProvider.java
Last active October 27, 2017 07:32
Using Two different JAX-WS client implementations
package com.snaphop.jaxws;
import static java.util.Arrays.asList;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
@agentgt
agentgt / cleanup-maven.sh
Last active August 29, 2015 13:56
Delete releases
MAVEN_REPO=/home/maven/repo/release
PACKAGES="com/snaphop/snaphopsuite-web com/snaphop/snaphop-ats-web"
for p in $PACKAGES; do
PACKAGE=$MAVEN_REPO/$p
echo "Truncating $p"
@agentgt
agentgt / AbstractConfigResourcesFactoryBean.java
Last active August 29, 2015 13:56
Spring Configuration Overlaying
import static java.util.Arrays.asList;
import static org.springframework.util.StringUtils.hasText;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletContext;
import org.slf4j.Logger;
@agentgt
agentgt / TestSuites.java
Created January 23, 2014 18:05
JAXB classes for generating JUnit XML that Jenkins/Hudson can read.
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
@XmlRootElement(name="testsuites")
package com.snaphop.spring;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
@agentgt
agentgt / ExampleController.java
Last active December 27, 2022 00:37
Spring Immutable Object Web Data Binding
public class ExampleController {
@RequestMapping(value = {"/blah", ""})
public @ResponseBody Map<String, Object> blah(@Valid Blah blah, BindingResult errors, ModelMap model) {
if (errors.hasErrors()) {
return ModelUtils.mapBuilder().put("status", "errors").build();
}
return ModelUtils.mapBuilder().put("status", blah.getFirst() + " " + blah.getLast()).build();
}
public static class Blah {
@agentgt
agentgt / ResourceUtils.java
Created November 8, 2012 21:38
Classpath ResourceUtils
public class ResourceUtils {
private final static Supplier<Cache<ClasspathResourceKey, String>> cacheSupplier =
Suppliers.memoize(new Supplier<Cache<ClasspathResourceKey, String>>() {
@Override
public Cache<ClasspathResourceKey, String> get() {
return CacheBuilder.newBuilder().maximumSize(100).expireAfterAccess(10000, TimeUnit.SECONDS).build();
}
});
@agentgt
agentgt / Precondition.java
Created October 11, 2012 19:56
Extendable Preconditions like Guava's with custom exceptions and SLF4J formatting
package com.snaphop.util;
import javax.annotation.Nullable;
import org.slf4j.helpers.MessageFormatter;
import java.lang.IllegalArgumentException;
import java.lang.IllegalStateException;
public abstract class Precondition<ARG extends IllegalArgumentException, STATE extends IllegalStateException> {
@agentgt
agentgt / CrockfordIdGenerator.java
Created September 26, 2012 13:47
CrockfordIdGenerator.java
public class CrockfordIdGenerator {
public static String encodeBase32(UUID uuid) {
Long leastBits = uuid.getLeastSignificantBits();
Long mostBits = uuid.getMostSignificantBits();
byte[] bytes = ByteBuffer.allocate(16)
.putLong(mostBits)
.putLong(leastBits).array();
return new String(encodeBase32(bytes));
}
@agentgt
agentgt / XmlStreamObjectUtils.java
Created September 19, 2012 20:54
Turn XML Stream into an Object Iterator
package com.snaphop.util;
import static com.google.common.base.Preconditions.checkState;
import java.io.Reader;
import java.util.Iterator;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;