Skip to content

Instantly share code, notes, and snippets.

View Dierk's full-sized avatar

Dierk König Dierk

View GitHub Profile
module FizzBuzz
import Data.Vect
Rule : Type
Rule = (n: Int) -> (old: List String) -> (List String)
everyNthRule : (every: Int) -> (replacement: String) -> Rule
everyNthRule every replacement n old =
if (mod n every == 0) then old ++ [replacement] else old
@Dierk
Dierk / ParallelStreamTest.java
Created August 17, 2015 13:50
an impure parallel stream that should only map but actually serves as random number generator
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class ParallelStreamTest {
static class IntGenerator implements Supplier<Integer> {
private int current = 0;
@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 / MultipleButtonsDemo.groovy
Created January 1, 2017 20:02
GroovyFX: factory methods for a composite view
import static groovyx.javafx.GroovyFX.start
/**
Demo of using methods to create multiple nodes (here Buttons) as a composite view and use those
factory methods multiple times.
@author Dierk Koenig
*/
start {
sgb = delegate
@Dierk
Dierk / Ants.fr
Created December 8, 2016 15:47
AntHill simulation using Frege STM
module Ants where
import STM
import Control.Concurrent (forkIO, forkOS)
import Data.List (!!, nub, sortBy)
import System.Random
@Dierk
Dierk / Counter.tsx
Last active December 3, 2016 18:57
A graphical multiplication table in Typescript/React. See live at https://dierk.github.io/tryPux/beautifulMathInTS/index.html
import * as React from "react";
export interface HelloProps { compiler: string; framework: string; }
export interface HelloState { slices: number; table: number }
export class Hello extends React.Component<HelloProps, HelloState> {
constructor(props: HelloProps) {
super(props);
this.state = { slices:10, table:2 }
@Dierk
Dierk / Counter.elm
Last active December 1, 2016 09:31
A graphical multiplication table written in elm (see Counter.purs for the same in purescript). Live: https://dierk.github.io/tryPux/beautifulMathInElm/index.html
import Html exposing (Html, button, div, text)
import Html.App as App
import Html.Events exposing (onClick)
import Svg exposing (svg, circle, line)
import Svg.Attributes exposing (..)
import List exposing (map, (::))
main =
App.beginnerProgram { model = state, view = view, update = update }
@Dierk
Dierk / Counter.purs
Last active November 26, 2016 13:14
A graphical multiplication table written in PureScript/Pux, try at https://dierk.github.io/tryPux/beautifulMath/index.html
module App.Counter where
import Prelude (($), (+), (-), (*), (/), (>), const, show)
import Data.Array ((..), (:), mapWithIndex)
import Data.Int (toNumber, floor)
import Math (sin, cos, pi )
import Pux.Html (Html, div, span, button, text, canvas, svg, circle, line )
import Pux.Html.Attributes (width, height, viewBox, cx, cy, r, fill, x1, y1, x2, y2, stroke, strokeWidth)
import Pux.Html.Events (onClick)
@Dierk
Dierk / Main.purs
Created November 14, 2016 20:11
Monoidal Fizzbuzz in Purescript
module Main where
import Control.Monad.Eff.Console (log)
import Data.List.Lazy (take, zipWith, fromFoldable, cycle, iterate, foldr)
import Data.Monoid (mempty, (<>))
import Data.Maybe (Maybe(..), fromMaybe)
import Prelude ( show, map, ($), (+))
main = do
// Haskell-style iterate function in Groovy
Closure iterate(def value, Closure nextValue) {
return { value = nextValue value }
}
// use for iteration
def iter = iterate(0) { it + 1}