Skip to content

Instantly share code, notes, and snippets.

@jeffsheets
jeffsheets / gist:4399922
Last active December 10, 2015 07:18
Jetty 8 JTA via JNDI lookup in Spring with Atomikos 3.8
<New id="tmjndi" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>java:/TransactionManager</Arg>
<Arg>
<New class="com.atomikos.icatch.jta.UserTransactionManager"/>
</Arg>
</New>
<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction">
<Arg>
@jeffsheets
jeffsheets / Datasources.groovy
Created August 6, 2013 20:23
Rollback transactions from multiple Datasource in Grails Integration Tests Prior to Grails 2.3.x, and with Grails 1.3.x on datasources plugin Fixed in 2.3.x
/*
Sample Datasources.groovy file for datasources 0.5 plugin with grails 1.3.x
*/
datasources = {
datasource(name: 'db2') {
domainClasses([com.sheetsj.domain.db2.MyObj, com.sheetsj.domain.db2.MyObj2])
services(['myDb2Stuff'])
driverClassName('com.ibm.db2.jcc.DB2Driver')
dialect(org.hibernate.dialect.DB2Dialect)
@jeffsheets
jeffsheets / SpringAsyncListenableFutureCallbackSpec.groovy
Created September 4, 2015 17:19
Spring Async ListenableFutureCallback Spock test to validate that onFailure is handling exceptions raised in Async method
package com.sheetsj.spring.async.test
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.Async
import org.springframework.scheduling.annotation.AsyncResult
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.test.context.ContextConfiguration
import org.springframework.util.concurrent.ListenableFuture
import org.springframework.util.concurrent.ListenableFutureCallback
@jeffsheets
jeffsheets / AbstractHandlerMethodMappingTestOverride.java
Created March 24, 2016 19:49
Spring MVC unit (minimal integration) test that uses Spring config for the controller setup
package org.springframework.web.servlet.handler
import org.springframework.web.context.WebApplicationContext
/**
* Workaround to register a controller with the WebAppContext because detectHandlerMethods is protected
*
* This allows our Mvc Unit tests to use the wired up Spring Jackson converters and mappers,
* without having to specify them individually in every test
*
@jeffsheets
jeffsheets / APoolHelper.groovy
Last active June 15, 2016 16:29
Grails setup for using Apache Commons Pool to pool JAX-WS Port Proxy WS Stub objects because creating the connections can be an expensive operation
import org.apache.commons.pool2.ObjectPool
import org.apache.log4j.Logger
class PoolHelper {
static Logger log = Logger.getLogger(PoolHelper)
/**
* Executes a closure using the object from the passed
* in Commons Pool, invalidating the object if an error is returned,
* and always returning it to the pool. Similar to how Groovy Sql methods work.
*/
@jeffsheets
jeffsheets / BinarySearch.groovy
Created August 8, 2016 13:53
BinarySearch, QuickSort, DepthFirstSearch, BreadthFirstSearch in groovy
class BinarySearch {
def bfs(def node, def result=[]) {
Queue queue = new LinkedList()
queue.add(node)
while (queue) {
def it = queue.poll()
result << it.val
@jeffsheets
jeffsheets / TreeTraversal.js
Created August 15, 2016 21:38
Javascript binary search, quick sort, depth first search, and breadth first search
//See full source with HTML at jsfiddle:
// https://jsfiddle.net/jeffsheets/ry2ns0s7/4/
function node(val, left, right) {
return {val: val, left: left, right: right, visited: false};
}
/*
@jeffsheets
jeffsheets / EMUserRepository.groovy
Last active March 23, 2017 17:53
UserRepository showing export false at type level, but export true at method level
//Filed Spring Data Rest bug
//https://jira.spring.io/browse/DATAREST-1034
//so check there for answers
@RepositoryRestResource(path='emUsers', exported = false)
interface EMUserRepository extends EnversRevisionRepository<EMUser, Long, Integer>, JpaSpecificationExecutor<EMUser> {
//Attempting, as an example, to expose only this /search/findByAuth0UserId endpoint
//but with @RepositoryRestResource(exported=false) this endpoint is not exported
//but with @RepositoryRestResource(exported=true) this endpoint is exported
@RestResource(exported = true)
@jeffsheets
jeffsheets / WorstFizzBuzzEver.java
Created July 14, 2016 19:35
Worst FizzBuzz Ever in Java
import java.util.Arrays;
public class WorstFizzBuzzEver {
public static final String BUZZ = "Fizz";
public static final String FIZZ = "Buzz";
/*
* This does Fizz Buzz
*/
@jeffsheets
jeffsheets / GwtSpockWidgetSpec.groovy
Last active April 30, 2018 21:27
GWT Spock test with GwtMockito for Google Web Toolkit client testing
package com.sheetsj.myapp.client.widget.fancy
import com.google.gwt.event.dom.client.KeyUpEvent
import com.google.gwt.user.client.ui.Widget
import com.google.gwtmockito.GwtMockito
import com.sheetsj.myproj.client.AppController
import com.sheetsj.myproj.client.widget.ErrorWidget
import org.mockito.Mockito
import spock.lang.Specification