Skip to content

Instantly share code, notes, and snippets.

View timyates's full-sized avatar

Tim Yates timyates

  • Manchester, UK
View GitHub Profile
@timyates
timyates / Stairs.groovy
Last active June 26, 2023 22:50
Groovy version of Frege-stairs doodle
import java.awt.Color
import java.awt.Graphics2D
import static java.awt.RenderingHints.*
import java.awt.image.BufferedImage
import groovy.transform.Immutable
@Immutable class Point { double x, y }
@Immutable class Trail { Point first, second, third, last }
Closure<Point> bearing = { Point start, Point over ->
@timyates
timyates / fizzbuzz.pony
Last active August 29, 2015 14:20
First go at FizzBuzz in pony-lang
type FbVal is (U64, (String|None))
type FbNext is (FbActor | None)
actor FbActor
var _env : Env
var _mod : U64
var _word : String
var _next : FbNext
new create(env: Env, mod: U64, word : String, next: FbNext = None) =>
/***** BEGIN LICENSE BLOCK *****
* Version: CPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Common Public
* License Version 1.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.eclipse.org/legal/cpl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
@timyates
timyates / PairedFizzBuzz.java
Last active August 29, 2015 14:19
Type insanity, and a non-general path to a functional FizzBuzz in Java 8
package fizzbuzz;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@timyates
timyates / FBJ8.java
Created April 18, 2015 19:08
Java 8 FizzBuzz with no conditionals, and no RxJava
package fizzbuzz;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@timyates
timyates / arrowdoc.groovy
Created April 11, 2015 09:10
ascii-image and document-builder sitting in a tree
@Grab(group='com.craigburke.document', module='pdf', version='0.3.1')
@Grab(group='com.craigburke.document', module='word', version='0.3.1')
@Grab('com.bloidonia:ascii-image:1.1')
import com.bloidonia.asciiimage.AsciImageProcessor
import java.awt.image.BufferedImage
import java.awt.RenderingHints
import java.awt.Color
import javax.imageio.ImageIO
import com.craigburke.document.builder.PdfDocumentBuilder
@timyates
timyates / arrow.groovy
Last active February 9, 2022 00:07
Using AsciImage from Groovy
// Requires Groovy 2.4+ and Java 8
@Grab('com.bloidonia:ascii-image:1.1')
import com.bloidonia.asciiimage.AsciImageProcessor
import java.awt.image.BufferedImage
import java.awt.RenderingHints
import java.awt.Color
AsciImageProcessor.fromLines([
'. . . . . . .',
'. . 3 . . . .',
@timyates
timyates / AsciImage.groovy
Last active October 11, 2015 19:00
First pass at a Groovy clone of ASCIImage
package com.bloidonia.asciiimage
import java.awt.*
import java.awt.geom.*
import java.awt.image.BufferedImage
import java.util.List
class AsciImage {
static enum Type { POINT, PATH, LINE, ELLIPSE }
@timyates
timyates / dream.groovy
Last active August 29, 2015 14:16
Filed under "wouldn't it be nice" ;-)
def matcher = ~/(?<year>\d\d\d\d)-(?<month>\d\d)-(?<day>\d\d)/
switch('2014-10-10') {
case matcher: { year, month, day ->
println "On day $day of month $month, in the year $year"
}
}
@timyates
timyates / SupplierCircuitBreaker.java
Created February 21, 2015 22:44
Saturday night with Java 8 and Circuit Breakers...
import rx.Observable;
import rx.functions.Func4;
import rx.subjects.BehaviorSubject;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.function.Supplier;
public class SupplierCircuitBreaker<T> implements Supplier<T> {