Skip to content

Instantly share code, notes, and snippets.

View zedar's full-sized avatar

Robert Zakrzewski zedar

  • Twitter@zedar185
View GitHub Profile
@zedar
zedar / ratpackGetPublicAddress.md
Last active August 29, 2015 14:06
ratpack public address of your server

Ratpack handlers have access to ratpack internal components. Especially:

  • context - implements interface ratpack.handling.Context
  • registry - implements interface ratpack.registry.Registry
  • publicAddress - implements interface ratpack.server.PublicAddress

context and registry variables are accessible without declaration. The other has to be declared as handler parameter.

In order to get public address of ratpack application declare publicAddress variable in your handler. In ratpack.groovy file import:

@zedar
zedar / ratpackInstallAppJVMOptions.md
Created September 19, 2014 11:37
ratpack installApp & JVM options

Setting JVM options for ratpack app distribution

Ratpack uses gradle to build fat-jar distributions. It contains gradle application plugin.

$ ./gradlew installApp

Above command whole distribution should be in build/install/ratpack-application-name folder.

$ ./gradlew distZip
@zedar
zedar / ratpackGradleWatch.md
Last active July 18, 2019 13:53
ratpack gradle & watch for changes

Ratpack and runtime class reloading

Ratpack works very smoothly with spring-loaded library. It is defined as dependency in build.gradle file. Spring-loaded enables runtime hot class reloading.

dependencies {
    springloaded "org.springframework:springloaded:1.2.0.RELEASE"
}

But default configuration reloads only changes in Ratpack.groovy file.

@zedar
zedar / ratpackWithRemoteJmx.md
Last active August 29, 2015 14:06
ratpack with remote jmx

Intro

To enable remote jmx monitoring across firewall it is necessary to pass following JVM arguments:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=5999
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.rmi.port=5998

@zedar
zedar / ratpackRespondByContent.md
Last active August 29, 2015 14:05
ratpack respond by content

Ratpack handler with byContent response

Ratpack is a Java/Groovy framework for rapid development of microservices.

Define set of handlers in src/main/Ratpack.groovy. Define common prefix api for REST APIs.

import static ratpack.groovy.Groovy.groovyTemplate
import static ratpack.groovy.Groovy.ratpack
import org.slf4j.Logger

import org.slf4j.LoggerFactory

@zedar
zedar / ratpackWithLog4J2.md
Last active March 2, 2021 03:50
ratpack & log4j2 basic configuration

Install ratpack

Ratpack is microservices framework written in Java but with very strong Groovy support. Ratpack is set of libraries. There are 2 main tools required for ratpack project: gradle and lazybones. Both could be installed with gvm (Groovy enVironment Manager).

$ gvm install gradle
$ gvm install lazybones

Create project structure with lazybones.

@zedar
zedar / VagrantAndNginxAsProxy
Created July 16, 2014 12:22
Vagrant and nginx as proxy configuration
## Install vagrant:
* install virtualbox
* install vagrant
## Configure vagrant
$ mkdir vagrant
$ cd vagrant
@zedar
zedar / FilteringSelectClass.js
Last active August 29, 2015 14:02
dojo FilteringSelect with cached entries
declare([
"dojo/_base/declare",
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dijit/form/FilteringSelect"
], function(declare, JsonRest, Memory, Cache, FilteringSelect) {
var _class = declare("FilteringSelectClass", null, {
createFileringSelect: function(domNode) {
var memoryStore = new Memory(),
@zedar
zedar / circularObjStringify
Last active August 29, 2015 14:00
JSON.stringify - workaround for "converting circular structure to JSON"
// Assume obj is an object with circular structure
var cache = [];
var str = JSON.stringify(obj, function(key, value) {
if (typeof value === "object" && value !== null) {
if (cache.indexOf(value) !== -1) {
return;
}
cache.push(value);
}
return value;
@zedar
zedar / CSSFontsRewriterResourceMapper.groovy
Last active August 29, 2015 13:57
Grails resources plugin - add custom resource mapper to map urls from css files that contain ? or # attributes.
import org.grails.plugin.resource.CSSLinkProcessor
import org.grails.plugin.resource.mapper.MapperPhase
/**
* This mapper is the second phase of CSS rewriting but for fonts references.
* Some fonts, like awesome, require attributes after the '?'.
*
* It finds any "resource:" URIs and then re-relativizes the absolute URI that follows it, using the final
* locations of all the resources now that all the other CSS-processing mappers have been applied.
*