Skip to content

Instantly share code, notes, and snippets.

@bmchild
bmchild / AllFieldsOrNone .java
Created September 26, 2012 19:42
AllFieldsOrNone SpringMVC 3 JSR-303 Validator
/**
*
*/
package com.bmchild.validation.constraints;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.METHOD;
@bmchild
bmchild / XMLService.java
Created August 22, 2013 21:09
A Dom4J Utility
/**
*
*/
package com.bmchild.service.xml;
import java.io.IOException;
import java.io.InputStream;
import org.dom4j.Document;
import org.dom4j.Node;
@bmchild
bmchild / CasLogin.java
Created May 2, 2014 22:08
Simple CAS Java Rest Client
package com.bmchild.pocrestclient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Logger;
@bmchild
bmchild / .bash_profile
Created January 3, 2017 22:33
function to zip text + encrypt, 2 params (text to encrypt, filename w/o extension). Add to .bash_profile
#function to zip text + encrypt, 2 params (text to encrypt, filename w/o extension)
function zipe() {
echo "$1" > $2.txt && zip -e $2.zip $2.txt && rm $2.txt
}
@bmchild
bmchild / file.java
Created April 9, 2012 13:15
Get Entity Class from spring JpaRepository
@SuppressWarnings("rawtypes")
public static Class<?> getEntity(JpaRepository repo) {
Type clazzes = getGenericType(repo.getClass())[0];
Type[] jpaClass = getGenericType(getClass(clazzes));
return getClass( ((ParameterizedType)jpaClass[0]).getActualTypeArguments()[0]);
}
public static Type[] getGenericType(Class<?> target) {
if (target == null)
return new Type[0];
String filePath = this.getClass().getClassLoader().getResource("folder/file.txt").getFile();
String fileContent = new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8);
@bmchild
bmchild / ListSplit.java
Created January 3, 2014 23:07
Splitting a list
/**
* creates a list of lists where each list.size() <= <code>length</code>
* @param list
* @param length
* @return
*/
public static <T> List<List<T>> split(List<T> list, final int length) {
List<List<T>> parts = new ArrayList<List<T>>();
final int size = list.size();
for (int i = 0; i < size; i += length) {
/*
* Business logic service
*/
public class MyBusinessService {
private SomeService someService;
public void executeSomeLogic(MyLogicOperator input) {
Something thing = new Something();
/*
* Business logic service
*/
public class MyBusinessService {
private SomeService someService;
public void executeSomeLogic(String input) {
Something thing = new Something();
/*
* Business Logic Test
*/
@RunWith(MockitoJUnitRunner.class)
public class MyBusinessServiceTest {
@Mock
private AnotherService anotherService;
@Mock