Skip to content

Instantly share code, notes, and snippets.

View Dierk's full-sized avatar

Dierk König Dierk

View GitHub Profile
@Dierk
Dierk / KanbanDemo.groovy
Created September 13, 2011 19:32
Classic concurrent producer-consumer problem with using a kanban system to avoid buffer overflows when consumers are slow
import groovyx.gpars.dataflow.DataFlowQueue
import groovyx.gpars.dataflow.operator.DataFlowPoisson
import static groovyx.gpars.dataflow.DataFlow.operator
import java.util.concurrent.atomic.AtomicInteger
def upstream = new DataFlowQueue() // empty trays travel back upstream to the producer
def downstream = new DataFlowQueue() // trays with products travel to the consumer downstream
def prodWiring = [inputs: [upstream], outputs: [downstream], maxForks: 3 ] // maxForks is optional
def consWiring = [inputs: [downstream], outputs: [upstream], maxForks: 3 ] // maxForks is optional
@Dierk
Dierk / build.gradle
Created October 7, 2011 22:43
build.gradle for setting up a new gradle-based project
apply plugin:'groovy'
apply plugin:'idea'
repositories { mavenCentral() }
dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.8.2'
}
task makeDirs(description:'make all dirs for project setup') << {
@Dierk
Dierk / pre-receive.groovy
Created February 9, 2012 23:50
a pre-receive hook to allow both: feature branches and agile CI
// a git pre-receive hook
// that automatically merges all pushes to feature branches
// into a dedicated continuous-integration (ci) branch.
// Since we cannot merge in a bare repo, we work on a temporary clone.
// Dierk Koenig
def ciBranch = 'master'
def mergeName = 'merge'
def hereDirPath = new File('.').canonicalPath
@Dierk
Dierk / SynchronousInMemoryClientConnector.groovy
Created July 16, 2013 13:33
/** An in-memory client connector without any asynchronous calls such that * technologies like GWT, Vaadin, or ULC can use it savely on the server side * without leaving the request thread. */
/*
* Copyright 2012-2013 Canoo Engineering AG.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Dierk
Dierk / StatelessKanbanFlowGOLmassive.groovy
Created August 28, 2013 13:01
Massively parallel stateless Game of Life with GPars KanbanFlow
import groovyx.gpars.dataflow.KanbanFlow
import groovyx.gpars.dataflow.KanbanLink
import groovyx.gpars.dataflow.KanbanTray
import groovyx.gpars.dataflow.ProcessingNode
import static groovyx.gpars.dataflow.ProcessingNode.node
/*
A massively parallel game of life with KanbanFlow.
Every cell signals to all neighbors when it has a new value.
Every cell waits for signals from all its neighbors.
@Dierk
Dierk / AntMoves.groovy
Created August 28, 2013 18:48
Massively parallel consistent ant moves
import groovy.transform.Immutable
import groovyx.gpars.dataflow.KanbanFlow
import groovyx.gpars.dataflow.KanbanLink
import groovyx.gpars.dataflow.KanbanTray
import groovyx.gpars.dataflow.ProcessingNode
import static groovyx.gpars.dataflow.ProcessingNode.node
/*
For a general introduction see https://gist.github.com/Dierk/6365780.
@Dierk
Dierk / build.gradle
Created September 15, 2013 00:28
compile against a special frege version, download and install if not yet there
/**
Making the Frege language available. Compiler and Runtime is all in one jar.
To be completed.
@author Dierk Koenig
*/
apply plugin:'java'
def frege_version = '3.21.190'
def qualifier = 'g714a7cc'
def frege_jar = file(System.properties.'user.home'+"/.frege/home/frege-${frege_version}.jar")
@Dierk
Dierk / CallJSR223.groovy
Created October 7, 2013 11:33
call frege from groovy via jsr223 integration
package com.canoo
import javax.script.*
//Get the Frege Script Engine
final frege = new ScriptEngineManager().getEngineByName("frege")
//Evaluate an expression
println frege.eval('show $ take 10 [2,4..]')
@Dierk
Dierk / ModularGroovyTraits
Created April 6, 2014 19:23
Using modular traits in Groovy 2.3.0-beta-1
trait HasId {
long id
}
trait HasVersion {
long version
}
trait Persistent {
boolean save() { println "saving ${this.dump()}" }
}
trait Entity implements Persistent, HasId, HasVersion {
@Dierk
Dierk / GroovyDelegatingTrait
Created April 8, 2014 20:48
Using Groovy traits with @DeleGate AST transform
// has all methods of List
trait ListLike {
@Delegate List linkedList = new LinkedList()
}
// stores anything but exposes only Strings
class StringList implements ListLike {
String get(int index) { linkedList.get(index).toString() }
}