Skip to content

Instantly share code, notes, and snippets.

@danveloper
danveloper / MainGroovy.groovy
Created Jun 11, 2015
Ratpack 0.9.17 WebSocket Streaming
View MainGroovy.groovy
import com.google.inject.Inject
import com.google.inject.Scopes
import org.reactivestreams.Publisher
import ratpack.exec.ExecController
import ratpack.form.Form
import ratpack.func.Function
import ratpack.groovy.Groovy
import ratpack.guice.Guice
import ratpack.server.RatpackServer
import ratpack.server.ServerConfig
@danveloper
danveloper / MainController.java
Created Apr 13, 2015
Spring Boot Hello World JSON No Annotations
View MainController.java
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 / Main.java
Created Jan 15, 2015
Netty Read Channel Only When I Want To
View Main.java
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 / a.md
Last active Apr 14, 2016
Ratpack 0.9.13 Performance on EC2 c4.8xlarge
View a.md

starting the app

* app starts with `-Dratpack.epoll=true` to enable the Netty `EpollEventLoop`
# ./wrk -t72 -c3000 -d30s http://localhost:5050
Running 30s test @ http://localhost:5050
  72 threads and 3000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     4.82ms    9.03ms 229.22ms   95.25%
 Req/Sec 9.58k 3.52k 34.54k 70.33%
@danveloper
danveloper / a.groovy
Last active Oct 11, 2018
Standalone Ratpack Groovy 0.9.13
View a.groovy
@GrabResolver(name='netty', root='http://clinker.netty.io/nexus/content/repositories/snapshots')
@Grab('io.ratpack:ratpack-groovy:0.9.13-SNAPSHOT')
import ratpack.handling.Handler
import ratpack.server.*
RatpackServer.of { spec -> spec
.config(ServerConfig.noBaseDir())
.handler {
{ ctx -> ctx.render "Hello World!" } as Handler
}
@danveloper
danveloper / ratpack.md
Created Jan 10, 2015
Ratpack as of 0.9.13
View ratpack.md

build.gradle

buildscript {
  repositories {
    jcenter()
    maven { url "http://oss.jfrog.org/oss-snapshot-local" }
    maven { url "http://clinker.netty.io/nexus/content/repositories/snapshots" }
  }
 dependencies {
@danveloper
danveloper / foo.java
Created Dec 29, 2014
Spring RestController PUT/Update
View foo.java
@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 / stream.example.js
Created Aug 13, 2014
Collection Stream Processing in JavaScript with Java 8 & Nashorn
View stream.example.js
// 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) {
View WebFlowScope.java
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);
}
View RxRatpack.groovy
@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 = ""