Skip to content

Instantly share code, notes, and snippets.

@aphexmunky
aphexmunky / web.xml
Created October 20, 2012 02:12
Spring Jersey Contrib
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-context.xml</param-value>
</context-param>
@aphexmunky
aphexmunky / key-generation.java
Created October 24, 2012 09:40
Java Key Generation
@Value("${encryption.key}")
String encryptionKey;
private Key generateKey(String salt) throws Exception {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] hash = md.digest((encryptionKey + salt).getBytes("UTF-8"));
byte[] key = Arrays.copyOf(hash, 16);
return new SecretKeySpec(key, ALG);
}
@aphexmunky
aphexmunky / MockitoVoid.java
Created October 25, 2012 10:12
Mockito verify void interactions
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
return new Object();
}
}).when(mock).voidMethodThatNeedsVerifying;
@aphexmunky
aphexmunky / SymmetricEncryption.java
Created October 26, 2012 14:11
Encryption Bean
package com.thehutgroup.thirdpartyplatform.service;
public interface SymmetricEncryption {
public String encrypt(String plainText, String salt);
public String encrypt(String plainText, int salt);
public String decrypt(String encryptedText, String salt);
public String decrypt(String encryptedText, int salt);
@aphexmunky
aphexmunky / build.gradle
Created November 14, 2012 09:07
JAXB task in gradle
def generatedResources = "src/main/generated-sources"
task jaxb(){
description 'Converts xsds to classes'
def jaxbTargetDir = file( generatedResources )
jaxbTargetDir.deleteDir()
doLast {
jaxbTargetDir.mkdirs()
@aphexmunky
aphexmunky / build.gradle
Created November 14, 2012 09:20
gradle snippet
sourceSets.main.java.srcDirs += 'src/main/generated-sources'
@aphexmunky
aphexmunky / benchmark.groovy
Last active September 27, 2018 14:31
benchmark closure
def benchmark = { closure ->
start = System.currentTimeMillis()
closure.call()
now = System.currentTimeMillis()
now - start
}
def originalTime = benchmark {
productList.each { productId ->
def param = [productId]
@aphexmunky
aphexmunky / Snippet.java
Created January 21, 2013 10:55
JDom XML pretty print
package com.thehutgroup.sherlock.domain;
import java.io.StringReader;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
public class Snippet {
@aphexmunky
aphexmunky / getwork.json
Last active December 11, 2015 18:28
bitcoin getwork
{
"midstate" : "f216ca85dba879b20f6243997b81df0706dcee58604823e867bf6410b703f459",
"data" : "000000024424e630e0924f88c89d8f74b0babdcfdcb6976196de99af00000128000000008a4ca094d0b15296fce5a5ba7c1707ff261f7e171ddfffa168284bfd755262545103bf421a05a6b100000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000",
"hash1" : "00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000",
"target" : "0000000000000000000000000000000000000000000000b1a605000000000000"
}
@aphexmunky
aphexmunky / getblock.json
Created January 26, 2013 11:48
bitcoin getblock 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048
{
"hash" : "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
"confirmations" : 213125,
"size" : 215,
"height" : 1,
"version" : 1,
"merkleroot" : "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
"tx" : [
"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
],