Skip to content

Instantly share code, notes, and snippets.

@awilmore
awilmore / .gitconfig
Created October 8, 2018 03:32
Personal ~/.gitconfig
[user]
name = abc
email = abc@abc.com
[core]
excludesfile = ~/.gitignore_global
[color]
ui = auto
@awilmore
awilmore / ExceptionTester
Created May 23, 2012 10:22
Standard Exception Constructor Tester
package com.awilmore.testutils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import junit.framework.Assert;
public class ExceptionTester extends Assert {
public ExceptionTester(Class<?> exceptionClass) {
@awilmore
awilmore / Base64Util
Created May 23, 2012 10:19
Java Base64 Utils
package com.awilmore.stringutils;
import static javax.xml.bind.DatatypeConverter.parseBase64Binary;
import static javax.xml.bind.DatatypeConverter.printBase64Binary;
public class Base64Util {
public static String decode(String encoded) {
byte[] decoded = parseBase64Binary(encoded);
return new String(decoded);
@awilmore
awilmore / IOUtil.java
Created May 23, 2012 10:18
Fast nio InputStream to OutputStream Copy
package com.awilmore.ioutils;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
@awilmore
awilmore / GetAndSetExampleTest
Created May 23, 2012 02:53
Andrew's Get And Set Tester
import static com.iaglimited.testing.util.GetterSetterTestProvider.shouldSetAndGet;
import org.junit.Test;
import com.iaglimited.testing.util.GetterSetterTestFilter;
public class GetAndSetExampleTest {
@Test
public void shouldSupportCorectGetterSetterBehaviour() {
@awilmore
awilmore / PrimeSpec.scala
Created May 22, 2012 12:13
Scala Specs Example
import org.specs2.mutable._
import org.junit.runner._
import org.specs2.runner._
@RunWith(classOf[JUnitRunner])
class PrimeSpec extends Specification {
"The 'Prime' object" should {
"determine prime" in {
Prime.is(7919) must beTrue
@awilmore
awilmore / ScalaExamples.scala
Created May 22, 2012 11:39
Various Scala Examples
// Find character with largest Unicode value
"Hello".reduceLeft((x, y) => if(x > y) x else y)
// Sum the unicode numeric value of the characters in "Hello World"
println("Hello World".foldLeft(0)((x, y) => x + y))
// Filter characters with even Unicode values
"Hello".filter(c => c % 2 == 0) // Filter characters with even Unicode values
"Hello".filter(_ % 2 == 0)
@awilmore
awilmore / ReflectionTestUtilsExampleTest.java
Created May 22, 2012 11:24
Populating Private Autowired Fields via Spring ReflectionTestUtils
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
@RunWith(MockitoJUnitRunner.class)
public class ReflectionTestUtilsExampleTest {
@Mock private SomeDependency mockSomeDependency;
@awilmore
awilmore / StatementLoader.java
Created May 22, 2012 11:22
SQL Statement Loader via Spring IO Resource
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
@awilmore
awilmore / SpringJUnitIOResourceExampleTest.java
Created May 22, 2012 11:20
Loading SQL Resources Using Spring IO Resource Annotation
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({