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 = ""
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());
@danveloper
danveloper / Main.java
Created January 15, 2015 16:05
Netty Read Channel Only When I Want To
public static void main(String[] args) throws Exception {
EventLoopGroup elg = new NioEventLoopGroup();
Bootstrap b = new Bootstrap()
.group(elg)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.config().setAutoRead(false);
@danveloper
danveloper / MainController.java
Created April 13, 2015 20:38
Spring Boot Hello World JSON No Annotations
package app;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.boot.SpringApplication;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.web.servlet.ModelAndView;
@danveloper
danveloper / a.md
Last active August 29, 2015 14:25
optimization question

Optimization Question

Does JavaScript optimize for a function that is defined within the context of another function?

For example, are the following examples canonically represented (in performance terms) after compilation, or is one approach favored optimally over the other?

Inner-function

function sortMyThings() {
@danveloper
danveloper / gist:2782111
Created May 24, 2012 15:06
grails-maven-plugin issues
http://jira.grails.org/browse/MAVEN-86
- Fixed with commit 6e4e2ad, pull request 15
http://jira.grails.org/browse/MAVEN-118
- Can be closed? grails-webflow no longer exists as a dependency
http://jira.grails.org/browse/MAVEN-84
- Not an issue anymore? java.home is an exposed property from maven, and there are no more references to java.version
http://jira.grails.org/browse/MAVEN-68
@danveloper
danveloper / BigValueType.java
Created August 29, 2012 13:28
Huge enumeration problem w/ Spring-loaded
// This class WILL be reloaded
enum BigValueType
{
enum0,
enum1,
enum2;
HugeEnum[] hugeEnums;
BigValueType() {
package com.danveloper.ant.tasks
import grails.build.logging.GrailsConsole
import org.apache.tools.ant.BuildException
import org.apache.tools.ant.DirectoryScanner
import org.apache.tools.ant.taskdefs.MatchingTask
import org.apache.tools.ant.types.Path
import org.apache.tools.ant.types.Reference
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.grails.web.pages.GroovyPageCompiler