Skip to content

Instantly share code, notes, and snippets.

@danveloper
danveloper / RxRatpack.groovy
Created February 20, 2014 18:42
RxRatpack
@Grab("io.ratpack:ratpack-rx:0.9.1")
import ratpack.launch.*
import ratpack.rx.internal.*
def cfg = LaunchConfigBuilder.baseDir(new File("/tmp")).build()
def rx = new DefaultRxBackground(cfg.background)
def list = ['fee', 'fie', 'fo', 'fum']
def str = ""
@danveloper
danveloper / BuildConfig.groovy
Created November 12, 2013 16:24
Test Forking by System Property
def forkTests = System.properties['grails.project.fork.test'] ? Boolean.getBoolean("grails.project.fork.test") : true
grails.project.fork = [
test: forkTests ? [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 768, daemon: true] : false,
run: [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 768, forkReserve: false],
war: [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 768, forkReserve: false],
console: [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 768]
]
@danveloper
danveloper / build.gradle
Created November 11, 2013 22:34
Grails 2.3.2 Gradle Build File
buildscript {
repositories {
mavenCentral()
maven { url 'http://repo.grails.org/grails/repo' }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT"
}
}
repositories {
@danveloper
danveloper / build.gradle
Created November 4, 2013 00:03
Avatar Gradle Build File
apply plugin: 'groovy'
apply plugin: 'idea'
repositories {
flatDir { dirs 'lib' }
maven { url "https://maven.java.net/content/repositories/releases" }
mavenCentral()
}
sourceCompatibility = '1.8'
@danveloper
danveloper / Main.groovy
Created October 30, 2013 03:35
Embedded Glassfish Runner that doesn't suck.
class Main {
static void main(args) {
def glassfish = new GlassFishProperties().with {
setPort "http-listener", 8080
GlassFishRuntime.bootstrap().newGlassFish(it).with {
start()
it
}
}
glassfish.commandRunner.run "deploy", args?.getAt(0)
@danveloper
danveloper / Application.groovy
Created October 10, 2013 18:00
An example of using the Spring Integration Groovy DSL with a JMS channel adapter to an embedded ActiveMQ JMS broker
package com.danveloper.springboot
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.integration.dsl.groovy.IntegrationContext
import org.springframework.integration.dsl.groovy.builder.AbstractIntegrationBuilderModuleSupport
@danveloper
danveloper / CountdownTagLib.groovy
Created July 26, 2013 15:27
Grails Countdown Timer TagLib
class CountdownTagLib {
static namespace = "ct"
def down = { args ->
out << """
<span id='conf-countdown'></span>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-countdown/1.6.1/jquery.countdown.min.js"></script>
<script>
(function() {
@danveloper
danveloper / StringMixins.groovy
Created July 26, 2013 07:02
This is a mixin class that is resolvable with the package location and class naming convention resolution strategy.
package groovy.runtime.metaclass.java.lang
import groovy.json.JsonSlurper
class StringMixins {
// Must be static & must take an instance of the receiver as the first vararg
static def toJson(String input) {
new JsonSlurper().parseText(input)
}
@danveloper
danveloper / MixinResolvingMetaClass.java
Last active December 20, 2015 06:38
This is the custom meta class that we'll be giving to all classes so that we can resolve the mixins through a location and class nomenclature convention.
package com.objectpartners.groovy.ext;
// imports...
class MixinResolvingMetaClass extends MetaClassImpl {
static final Map<Class, Class> cachedMixins = new ConcurrentHashMap<>();
MixinResolvingMetaClass(MetaClassRegistry registry, Class theClass) {
super(registry, theClass);
}
@danveloper
danveloper / CustomMetaClassCreationHandle.java
Created July 26, 2013 06:26
Custom MetaClass Creation Handler for Groovy
package com.objectpartners.groovy.ext;
import groovy.lang.MetaClass;
import groovy.lang.MetaClassRegistry;
import org.codehaus.groovy.runtime.GeneratedClosure;
import org.codehaus.groovy.runtime.metaclass.ClosureMetaClass;
class CustomMetaClassCreationHandle extends MetaClassRegistry.MetaClassCreationHandle {
protected MetaClass createNormalMetaClass(Class theClass,MetaClassRegistry registry) {