Skip to content

Instantly share code, notes, and snippets.

View Dierk's full-sized avatar

Dierk König Dierk

View GitHub Profile
@Dierk
Dierk / RNG.java
Last active March 22, 2016 22:36
adding numbers one to ten can easily lead to random results when done in parallel
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Stream;
public class RNG {
static Supplier<Integer> countGen(AtomicInteger i) {
return (()-> i.getAndIncrement());
}
@Dierk
Dierk / SillyClock.fr
Created February 4, 2016 12:06
A silly clock using Frege STM
module SillyClock where
import STM
import Control.Concurrent
type Counter = TVar Int
newCounter :: STM Counter
newCounter = TVar.new 0
@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 / 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 / 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 / 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 / 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 / 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 / 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 / FunctionRecord.fr
Created March 18, 2015 09:02
Protype-base "subclassing" with immutable records
module FunctionRecord where
data FRecord = FRecord {
parent :: FRecord,
name :: String,
toString :: (FRecord -> String)
}
prototype = FRecord { parent = prototype, name = undefined, toString = (\r -> r.name) }
dierk = prototype.{ name = "Dierk" }