Skip to content

Instantly share code, notes, and snippets.

View tunings.adoc

Ratpack Production Tunings

# cat /etc/security/limits.conf

*         hard    nofile      500000
*         soft    nofile      500000
root      hard    nofile      500000
root      soft    nofile      500000
View ratpack-map-and-flatmap.groovy
/**
* The `Promise#map` method is used to retrieve
* a value asynchronously (via a `Promise`) and
* transform it synchronous to a new value.
*/
class MappingSpec extends Specification {
@AutoCleanup
ExecHarness harness = ExecHarness.harness()
@danveloper
danveloper / MainGroovy.groovy
Created June 11, 2015 15:52
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 / convert.sh
Last active December 5, 2018 18:51
Java to Groovy converter in bash!!
View convert.sh
#!/bin/sh
find . -iname "*.java" -exec sed s/\;$// {} \;
@danveloper
danveloper / build.gradle
Created October 28, 2018 11:15
adding ignore-exceptions-ast to Gradle build
View build.gradle
apply plugin: 'groovy'
apply plugin: 'idea'
repositories {
maven { url "https://dl.bintray.com/danveloper/maven" }
}
dependencies {
compile 'com.github.danveloper.ast:ignore-exceptions-ast:1.0.0-rc-2'
}
@danveloper
danveloper / a.groovy
Last active October 11, 2018 18:11
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 January 10, 2015 19:14
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 / urlshortener.groovy
Created November 8, 2012 21:55
The 48-Line Volatile URL Shortener
View urlshortener.groovy
import java.net.ServerSocket
def socket = 8281, password = "danrulz"
enum Database {
INSTANCE;
def table = [:]
def shortCodeTable = [:]
def insert = { String url ->
Sequence.INSTANCE.counter++
def id = Sequence.INSTANCE.counter
def shortCode = new BigInteger(id).toString(36)+BigInteger.valueOf(Math.round(Math.random()*1000)).toString(36)
@danveloper
danveloper / Providers.groovy
Created December 11, 2012 22:46
This is how I implement the Provider pattern in Groovy.
View Providers.groovy
package com.danveloper.providers
import com.danveloper.support.ApplicationHolder as AH
import org.hibernate.SessionFactory as SF
public interface Provider<T> {
T get()
}
class Support {
@danveloper
danveloper / overlapcollapse.groovy
Created February 28, 2013 17:37
collapse overlapping ranges in list
View overlapcollapse.groovy
List.metaClass.collapse = {->
def start,end
def reverse = delegate[0]?.getAt(0)-delegate[0]?.getAt(-1) > 0
def expanded = delegate.flatten().unique().sort()
def result = (reverse ? expanded.reverse() : expanded).inject([]) { l, n ->
start = start == null ? n : start
end = end == null ? n : end
if ((reverse?n+1:n-1)==end) {
end = n