Skip to content

Instantly share code, notes, and snippets.

View nwillc's full-sized avatar

Nwillc nwillc

View GitHub Profile
@nwillc
nwillc / Nodelist.kt
Created May 30, 2018 01:09
NodeList interface
public interface NodeList {
public Node item(int index);
public int getLength();
}
@nwillc
nwillc / Loop.kt
Last active May 30, 2018 02:27
Looping over a nodelist
for (i in 0 .. (nodelist.length - 1)) {
if (nodelist.item(i).nodeType == Node.ELEMENT_NODE) {
return nodelist.item(i)
}
}
@nwillc
nwillc / ForEach1.kt
Last active May 30, 2018 02:50
First attempt at forEach
fun NodeList.forEach(block: Node.() -> Unit) {
for (i in 0 .. (length - 1)) {
item(i).block()
}
}
// And used it like...
nodelist.forEach {
if (it.nodeType == Node.ELEMENT_NODE) {
return it
}
@nwillc
nwillc / ForEach2.kt
Created May 30, 2018 01:33
Second attempt at forEach
inline fun NodeList.forEach(block: Node.() -> Unit) {
for (i in 0 .. (length - 1)) {
item(i).block()
}
}
buildscript {
ext {
springBootVersion = spring_boot_version
kotlin_version = kotlin_version
}
repositories {
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
assertj_version=3.10.0
junit_platform_version=1.2.0
jupiter_version=5.2.0
jvm_version=1.8
kotlin_version=1.2.50
serialization_version=0.5.1
spring_boot_version=2.0.3.RELEASE
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication
class Application
fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
@Controller
class StatusMapController {
@GetMapping("/status")
fun statusMap(model: Model, @RequestParam(defaultValue = "prod") env: String): String {
@nwillc
nwillc / ksvg-example1.kt
Last active October 18, 2018 01:40
KSVG Example
val svg = svg {
width = 200
height = 200
rect {
title {
body = "A Blue Rectangle"
}
x = 50
y = 50
width = 20
@nwillc
nwillc / OldExceptionHandling.java
Last active October 25, 2018 02:53
Old Java exception handling
Reader reader = null;
try {
reader = new FileReader("input.txt");
// Use the input
} catch (FileNotFoundException e) {
// Handle possible exception
} catch (IOException e2) {
// Handle another exception
} finally {
if (reader != null) {