Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 = ""
public interface WebFlowScope {
static final Map scopeMap = new HashMap();
Object getAttribute(Object key);
default public Object put(Object key, Object val) {
scopeMap.put(key, val);
return getAttribute(key);
}
@danveloper
danveloper / stream.example.js
Created August 13, 2014 01:43
Collection Stream Processing in JavaScript with Java 8 & Nashorn
// Reference to ArrayList type
var List = Java.type("java.util.ArrayList");
// An interface that provides default implementations for java.util.function.{Consumer,Function}
var ConsumingFunction = Java.type("midwestjs.nashorn.ConsumingFunction");
// Convert appropriately
function toFunc(fn) {
return new ConsumingFunction() {
apply: function(a) {
@danveloper
danveloper / foo.java
Created December 29, 2014 02:38
Spring RestController PUT/Update
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public HttpEntity update(@PathVariable String id, HttpServletRequest request) throws IOException {
ProductDetail existing = find(id);
ProductDetail updated = objectMapper.readerForUpdating(existing).readValue(request.getReader());
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("productId", updated.getProductId());
propertyValues.add("productName", updated.getProductName());
propertyValues.add("shortDescription", updated.getShortDescription());
propertyValues.add("longDescription", updated.getLongDescription());