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 / Main.java
Last active August 17, 2021 20:36
Overlay a struct over a block of memory in C
// And similar in Panama (Azul java 16.0.2 with --add-modules jdk.incubator.foreign)
package com.bloidonia;
import jdk.incubator.foreign.GroupLayout;
import jdk.incubator.foreign.MemoryLayout;
import jdk.incubator.foreign.MemoryLayouts;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.SequenceLayout;
import java.lang.invoke.VarHandle;
@timyates
timyates / CoRepeat.kt
Last active October 31, 2017 15:11
Repeating Sequences in Kotlin
// 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) }
}

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 August 6, 2016 20:07
Download Public PBase Galleries with 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 20:42
Uncurry(?) in 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
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 January 6, 2016 22:43
Map deepMerge (less readable remix)
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 October 20, 2015 12:43
Infinite Spliterator? I have no idea if this is right... Looks right, but there are many opportunities for wrong...
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 {
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 July 30, 2015 08:14
Generating terminal gifs on OS X the free way

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)