Skip to content

Instantly share code, notes, and snippets.

💩
...

Tim Yates timyates

💩
...
Block or report user

Report or block timyates

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@timyates
timyates / CoRepeat.kt
Last active Oct 31, 2017
Repeating Sequences in Kotlin
View CoRepeat.kt
// Version using experimental co-routines in 1.1 thanks to @voddan on Slack
import kotlin.coroutines.experimental.buildSequence
fun <T> Sequence<T>.repeat() : Sequence<T> = buildSequence {
while(true) yieldAll(this@repeat)
}
fun main(args: Array<String>) {
sequenceOf(1, 2, 3).repeat().take(6).forEach { i -> println(i) }
}
View keybase.md

Keybase proof

I hereby claim:

  • I am timyates on github.
  • I am tim_yates (https://keybase.io/tim_yates) on keybase.
  • I have a public key whose fingerprint is AADD 8CA6 0A80 20EE 11D1 96AF 5FA1 D919 F8A8 5C13

To claim this, I am signing this object:

@timyates
timyates / pbase.groovy
Created Aug 6, 2016
Download Public PBase Galleries with Groovy
View pbase.groovy
@Grab('net.sourceforge.nekohtml:nekohtml:1.9.16')
def outFolder = new File("/folder/to/download/to")
outFolder.mkdirs()
def url = 'http://www.pbase.com/USERNAME/GALLERYNAME&page=all'
def parser = new org.cyberneko.html.parsers.SAXParser()
new XmlSlurper(parser).parse(url)
.'**'
@timyates
timyates / uncurry.groovy
Created May 5, 2016
Uncurry(?) in Groovy
View uncurry.groovy
// Change a method reference into a closure that takes the delegate as the first parameter
import org.codehaus.groovy.runtime.MethodClosure
def uncurry(MethodClosure c) {
{a, ...b -> a."$c.method"(*b) }
}
// So uncurrying Number.plus gives us a closure that will take {x, y -> x.plus(y)}
def plus = uncurry(Number.&plus)
assert plus(1, 2) == 3
View SlangFizzBuzz.java
package fizzbuzz;
import javaslang.collection.Stream;
import javaslang.control.Option;
import static javaslang.control.Option.none;
import static javaslang.control.Option.some;
public class SlangFizzBuzz {
public static void main(String[] args) {
@timyates
timyates / test.groovy
Last active Jan 6, 2016
Map deepMerge (less readable remix)
View test.groovy
def a = [foo: [foo: true, bar: true]]
def b = [foo: [bar: false, baz: true]]
Map.metaClass.deepMerge = { Map other ->
(delegate.keySet() + other.keySet()).collectEntries { key ->
def (d, o) = [delegate, other]*.get(key)
if(d instanceof Map && o instanceof Map) {
[key, d.deepMerge(o)]
}
else {
@timyates
timyates / ParallelStreamTest.java
Created Oct 20, 2015
Infinite Spliterator? I have no idea if this is right... Looks right, but there are many opportunities for wrong...
View ParallelStreamTest.java
import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.IntConsumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class ParallelStreamTest {
View Source.java
package com.bloidonia.meddling;
@FunctionalInterface
public interface Source<T> {
default void yield(T value) {
System.out.println(value);
}
default void run() {
apply(this);
@timyates
timyates / README.md
Created Jul 30, 2015
Generating terminal gifs on OS X the free way
View README.md

Didn't work any of this out, I just stuck things together that I found on the web

First, install the things:

brew install imagemagick
brew install ffmpeg

Then, I have a small (600px wide) iTerm window with a big font. Load Quicktime, and record screen (just the area of the terminal)

Trim and save the mov somewhere (lets say ~/Documents/term.mov)

@timyates
timyates / Stairs.groovy
Last active Aug 29, 2015
Groovy version of Frege-stairs doodle
View Stairs.groovy
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 ->
You can’t perform that action at this time.