Skip to content

Instantly share code, notes, and snippets.

View tobyweston's full-sized avatar

Toby tobyweston

View GitHub Profile
@tobyweston
tobyweston / gist:3733592
Created September 16, 2012 18:17
Example of sales rate and manual tax amount (WTF)
<expenses type="array">
<expense>
<nominal-code>285</nominal-code>
<expense-type>Accommodation and Meals</expense-type>
<dated-on type="date">2011-12-05T00:00:00Z</dated-on>
<gross-value type="decimal">-8.85</gross-value>
<sales-tax-rate type="decimal">20.0</sales-tax-rate>
<description>Subsistence</description>
<manual-sales-tax-amount type="decimal">0.09</manual-sales-tax-amount>
</expense>
@tobyweston
tobyweston / gist:3733479
Created September 16, 2012 17:57
Sales tax calculations
public class TaxRate extends AbstractValueType<Double> {
public static TaxRate taxRate(Double value) {
return new TaxRate(value);
}
private TaxRate(Double value) {
super(value);
}
@tobyweston
tobyweston / gist:3362116
Created August 15, 2012 18:19
c3p0 configuration settings
class ProductionHibernateConfiguration implements HibernateConfiguration {
@Override
public Properties getProperties(String connectionUrl, String userName, String password) {
Properties properties = new Properties();
properties.setProperty("hibernate.connection.driver_class", "net.bull.javamelody.JdbcDriver");
properties.setProperty("hibernate.connection.driver", "oracle.jdbc.driver.OracleDriver");
properties.setProperty("hibernate.connection.url", connectionUrl);
properties.setProperty("hibernate.connection.username", userName);
properties.setProperty("hibernate.connection.password", password);
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
@tobyweston
tobyweston / gist:2841959
Created May 31, 2012 08:38
Avoid finalizer problems with JMocks SingleThreadedPolicy
public static class SingleThreadedPolicyAvoidingFinaliseProblems extends SingleThreadedPolicy {
@Override
public Invokable synchroniseAccessTo(final Invokable mockObject) {
final Invokable synchronizedMockObject = super.synchroniseAccessTo(mockObject);
return new Invokable() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
if (Thread.currentThread().getName().equalsIgnoreCase("Finalizer"))
return mockObject.invoke(invocation);
return synchronizedMockObject.invoke(invocation);
@tobyweston
tobyweston / gist:2819829
Created May 28, 2012 15:56
When running genuine multithreaded test with JMock, I don't want to synchronise
Name: Interrupter-Thread-1
State: BLOCKED on java.lang.Object@381eb0c6 owned by: main
Total blocked: 1 Total waited: 0
Stack trace:
org.jmock.lib.concurrent.Synchroniser.synchroniseInvocation(Synchroniser.java:82)
org.jmock.lib.concurrent.Synchroniser.access$000(Synchroniser.java:23)
org.jmock.lib.concurrent.Synchroniser$1.invoke(Synchroniser.java:74)
org.jmock.lib.legacy.ClassImposteriser$4.invoke(ClassImposteriser.java:136)
com.google.code.tempusfugit.temporal.Clock$$EnhancerByCGLIB$$489249d6.create(<generated>)
@tobyweston
tobyweston / gist:2157239
Created March 22, 2012 09:01
mapping widget - a little bit of yuk
public static class ButtWipe {
public static <K, V> MapBuilder<K, V> map(K key, V value) {
return new MapBuilder<K, V>().map(key, value);
}
public static class MapBuilder<K, V> extends HashMap<K, V> {
private MapBuilder() {
}
@tobyweston
tobyweston / octopress_me
Created February 9, 2012 19:04
What am I doing wrong with local Ocotpress generate?
# my _config.yml section
root: /
permalink: /blog/:year/:month/:day/:title/
source: source
destination: public/blog
code_dir: downloads/code
category_dir: blog/categories
This deploys fine to github pages (https://github.com/tobyweston/blog) and with a CNAME badrobot.com
@tobyweston
tobyweston / AnnouncerTest.java
Created November 18, 2011 16:31
Is this how the Announcer is used?
package auctionsniper.util;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.EventListener;