Skip to content

Instantly share code, notes, and snippets.

View christoph-frick's full-sized avatar

Christoph Frick christoph-frick

View GitHub Profile
@christoph-frick
christoph-frick / VaadinCompile.groovy
Created February 4, 2014 20:00
Compile Vaadin WidgetSet
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsClasspath")
includeTargets << grailsScript("_GrailsRun")
target(widgetset_init: "init") {
vaadinConfig = new ConfigSlurper(grails.util.Environment.current.name).parse(new File("${basedir}/grails-app/conf/VaadinConfig.groovy").text)
ant.property(name: "widgetset", value: vaadinConfig.vaadin.widgetset)
ant.property(name: "workers", value: "4")
ant.property(name: "widgetset-path", value: "")
ant.property(name: "client-side-destination", value: "web-app/VAADIN/widgetsets")
@christoph-frick
christoph-frick / _Events.groovy
Last active August 29, 2015 13:56
Build Vaadin Themes (scripts/_Events.groovy)
import com.vaadin.sass.internal.ScssStylesheet
eventCreateWarStart = { name, stagingDir ->
new File("${stagingDir}/VAADIN/themes/").eachDir {
def scssName = "${it}/styles.scss"
if (new File(scssName).exists()) {
ScssStylesheet scss = ScssStylesheet.get(scssName)
scss.compile()
def outFile = new File("$it/styles.css")
outFile.write(scss.toString())
curl -s -XDELETE localhost:9200/so_delete_parent >/dev/null
curl -s -XPUT localhost:9200/so_delete_parent/ -d '{ "settings": { "index": { "number_of_shards" : 2 } } }' >/dev/null
curl -s -XPUT localhosT:9200/so_delete_parent/childs/_mapping -d '{ "_parent": { "type": "parents" } }' >/dev/null
curl -s -XPUT localhost:9200/so_delete_parent/childs/A\?parent=1 -d '{ "doc": "parent 1" }'
curl -s -XPUT localhost:9200/so_delete_parent/childs/A\?parent=2 -d '{ "doc": "parent 2" }'
curl -s localhost:9200/so_delete_parent/childs/A\?parent=1 | json_pp
curl -s localhost:9200/so_delete_parent/childs/A\?parent=2 | json_pp
curl -s localhost:9200/so_delete_parent/childs/A\?parent=666 | json_pp
curl -s localhost:9200/so_delete_parent/childs/A | json_pp # fails with ES 1.0
@christoph-frick
christoph-frick / MultiLineField.groovy
Created June 27, 2014 07:41
Vaadin Multiline Field (List<String> in TextArea)
import com.vaadin.ui.Component
import com.vaadin.ui.CustomField
import com.vaadin.ui.TextArea
class MultiLineField extends CustomField<List<String>> {
private TextArea textArea = new TextArea()
MultiLineField() {
super()
@christoph-frick
christoph-frick / gist:118857c176c3f06efa16
Last active August 29, 2015 14:06
Disassembly of groovy's generated code for @singleton
/* groovy */
import groovy.transform.CompileStatic
@CompileStatic
@Singleton
class RegularSingleton {
void foo() { println 'foo' }
}
class Widget {
void doStuff() { println 'doing stuff' }
String sayStuff(String name) { return "Hello $name" }
void fail() { throw new RuntimeException("Boom") }
}
class WidgetService {
// our service now has all the methods, Widget has
@Delegate Widget widget = new Widget()
// adding other stuff is fine too
@christoph-frick
christoph-frick / runandcheck.groovy
Created October 18, 2014 16:42
Fluent groovy API to run and check several steps (code that usually is found in controllers with logs of errors checking) as seen in http://stackoverflow.com/questions/24034324/groovy-code-simplification-and-if-elimination
/* fluent run and test caller to get rid of if-else-cascades */
class RunAndCheck {
final Optional input
Optional output
RunAndCheck(Optional input=null) { this.input = input }
static RunAndCheck start(Closure action) { new RunAndCheck().run(action) }
import groovy.lang.BenchmarkInterceptor
class Bench {
static final String CSV = 'csv.csv'
void runOriginal() {
BigDecimal tot = 0G
new File(CSV).splitEachLine(";") { row ->
try {
@christoph-frick
christoph-frick / spring-run-vaadin.groovy
Created January 17, 2015 19:32
minimalistic springboot vaadin example; run with `spring run vaadin`
@Grapes([
@Grab('org.vaadin.spring:spring-boot-vaadin:0.0.3'),
@Grab('com.vaadin:vaadin-server:7.4.0.beta1'),
@Grab('com.vaadin:vaadin-client-compiled:7.4.0.beta1'),
@Grab('com.vaadin:vaadin-themes:7.4.0.beta1'),
])
import org.vaadin.spring.VaadinUI
import com.vaadin.server.VaadinRequest
import com.vaadin.ui.*
@christoph-frick
christoph-frick / stylish-so.css
Last active August 29, 2015 14:13
collection of fixes for stylish to make SO readable again
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("stackoverflow.com") {
body {
color: black;
background-color: #999;
font-family: "Liberation Sans";
}
.excerpt { color: black }
}