Skip to content

Instantly share code, notes, and snippets.

View mikehearn's full-sized avatar

Mike Hearn mikehearn

View GitHub Profile
@mikehearn
mikehearn / di-helpers.kt
Created December 21, 2017 17:37
Simple dependency helpers
package net.corda.node.internal
import java.time.Clock
import java.time.Duration
import java.time.Instant
import java.time.ZoneId
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
/**
@mikehearn
mikehearn / hello.js
Last active September 30, 2017 22:57
Hello World in JavaFX using Nashorn
// Run like this: jjs -fx hello.js
load("fx:base.js");
load("fx:controls.js");
load("fx:graphics.js");
// Set the title bar.
$STAGE.title = "Hello World!";
// Create a button and place it in a layout that will center it.
var button = new Button();
button.text = "Say 'Hello World'";
button.onAction = function() print("Hello World!");
@mikehearn
mikehearn / hello.html
Last active September 30, 2017 22:50
HTML version of the JavaFX JavaScript hello world sample
<html>
<head>
<title>Hello World!</title>
<style>
div.centered {
padding: 1em;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
enum SortBy {
Featured,
Relevance,
PriceLowToHigh,
PriceHighToLow,
Reviews
}
@PermazenType
class AmazonSearch(
@mikehearn
mikehearn / jlink --list-plugins
Created June 19, 2017 08:55
Output of jlink --list-plugins in Java 9 EA build 172

Keybase proof

I hereby claim:

  • I am mikehearn on github.
  • I am hearn (https://keybase.io/hearn) on keybase.
  • I have a public key ASAtBlfHGFrnjtqS-telpy4tveHymEWbfRtzMnMQYgKOMgo

To claim this, I am signing this object:

@mikehearn
mikehearn / puzzle.kt
Created February 9, 2016 20:32
Kotlin version of the NYT Puzzles program
import java.io.File
import kotlin.system.measureTimeMillis
fun main(args: Array<String>) {
val name = if (args.size > 1) args[0] else "/usr/share/dict/words"
val time = measureTimeMillis {
repeat(200) {
go(name)
}
@mikehearn
mikehearn / linear.kt
Created December 14, 2015 21:11
Rough sketch of possible linear types in kotlin (doesn't work with today's compiler)
open class LinearVal<T>(private val _v: T) {
open operator fun invoke(): T {
return _v
}
inline fun move(): LinearVal<T> {
if (this !is UnavailableLinearVal)
throw AssertionError()
@Suppress("DEPRECATION")
return __dupe()
@mikehearn
mikehearn / gist:7274375de2950e10f56f
Last active August 29, 2015 14:24
ThreadBox/UIThreadBox
class ThreadBox<T>(private val data: T) {
synchronized fun use<R>(block: (T) -> R): R = block(data)
synchronized fun useWith<R>(block: T.() -> R): R = data.block()
}
class UIThreadBox<T>(private val data: T) {
fun use(block: (T) -> Unit): Unit = if (Platform.isFxApplicationThread()) block(data) else Platform.runLater { block(data) }
fun useWith(block: T.() -> Unit): Unit = if (Platform.isFxApplicationThread()) data.block() else Platform.runLater { data.block() }
/** Does a blocking get from the UI thread - danger of deadlock if not used properly! */
public static class AnimatedBindInfo {
@Nullable public Timeline timeline;
public NumberBinding bindFrom;
public Runnable onAnimFinish;
}
public static AnimatedBindInfo animatedBind(Node node, WritableDoubleValue bindTo, NumberBinding bindFrom) {
bindTo.set(bindFrom.doubleValue()); // Initialise.
bindFrom.addListener((o, prev, cur) -> {
AnimatedBindInfo info = (AnimatedBindInfo) node.getUserData();