Skip to content

Instantly share code, notes, and snippets.

@GeePawHill
GeePawHill / YzView.kt
Created December 27, 2020 17:35
To TDD or not to TDD?
package org.geepawhill.yz
import tornadofx.*
class YzView : View() {
val model = YzModel(YzGame())
override val root = pane {
hbox {
button("Start") {
@GeePawHill
GeePawHill / Area.kt
Created December 27, 2020 18:08
To TDD Or Not To TDD? Round 2
package org.geepawhill.dungeon
import java.lang.Integer.max
import java.lang.Integer.min
data class Area(val west: Int, val north: Int, val east: Int, val south: Int) {
val longest: Int get() = max(east - west, south - north)
val size = (east - west) * (south - north)
@GeePawHill
GeePawHill / Channel.kt
Created June 13, 2021 19:02
Humble Object Example
package org.geepawhill.rws
import java.io.*
import java.net.Socket
class SocketWrapper(val input: InputStream, val output: OutputStream, val machine: String) {
constructor(socket: Socket) : this(socket.getInputStream(), socket.getOutputStream(), socket.inetAddress.toString())
}
class Channel(socket: SocketWrapper, private val listener: Listener) : Talker, Runnable {
@GeePawHill
GeePawHill / gist:9fa0b38eec2fa47876e4bf7c230cd951
Last active September 21, 2021 16:09
Exquisite re-framing of the Blind Men and the Elephant
The relationality of all experience contains challenges to our understanding of organizations that we have
barely begun to come to terms with. I can illustrate this by extending the metaphor of the blind men and
the elephant. In its conventional telling, each blind man had a grip on a different part of the beast, and
they were unable to agree on what it was really, really like, that is, as one of Kuhn's "fixed and neutral
experiences." But there is more, for the elephant isn't just standing there but instead ambles through the
forest and the veldt. The blind men are trying to understand the system as it evolves and as their experience
of it unfolds. The blind man clinging to a leg experiences an elliptical forward motion. He who has the
misfortune to have hold of the tail is jerked and whipped about in a random fashion. A few feet forward, his
colleague, in the crotch, is periodically flooded and/or pasted with output that seems to have nothing to do
with the beast's motion or with the feel of the sur
I want to use a single gradle+intellij project to build, run, and test multiple arbitrary binaries created from a single repo and source tree. Some notes:
1) A typical example is the robot world project I'm doing for We Think Code. I want one tree, and I want to use it to build/run/test two clients, a service, and a making app.
2) By "one source tree" I mean one .../src/... hierarchy, with main/test/resources below it. Intellij handles this well. Multiple trees are harder to both organize and navigate.
3) I know how to use sub-projects with source dependencies. I don't care for them. Intellij's gradle runs are already slower than their native ones, and when you throw in multiple sub-projects for each run, they get even slower.
A classic "switch on type" in Java. The draw method interrogates its parameter's class, and decides what to do as a resuilt.
interfact Thing { }
class Wall implemnts Thing { }
class Door implements Thing { }
class Chest implements Thing { }
@GeePawHill
GeePawHill / gist:9d4bb8a21531f369e90be5e86207a2bb
Created August 10, 2022 01:49
A Real World Kotlin Builder
// Snippet one: This code creates an ImageView control inside of a Pane.
val root = pane {
imageview {
image = Image("/bucket.png")
isPreserveRatio = true
}
}
// Snippet two: This is the signature of the function imageview that's being called in the above snippet
class GildedRoseTest {
@Test
fun `sulfuras never changes`() {
val items = arrayOf(Item(SULFURUS_NAME, Int.MAX_VALUE, 80))
val app = GildedRose(items)
app.updateQuality()
assertThat(items[0].name).isEqualTo(SULFURUS_NAME)
assertThat(items[0].sellIn).isEqualTo(Int.MAX_VALUE)
assertThat(items[0].quality).isEqualTo(80)
@GeePawHill
GeePawHill / gist:4ccd8718129723be636e324808f54682
Created September 22, 2022 15:52
Second rework of test.
@Test
fun `sulfuras never changes`() {
val item = updateQuality(Item(SULFURUS_NAME, Int.MAX_VALUE, 80))
with(item) {
assertThat(name).isEqualTo(SULFURUS_NAME)
assertThat(sellIn).isEqualTo(Int.MAX_VALUE)
assertThat(quality).isEqualTo(80)
}
}
@GeePawHill
GeePawHill / gist:e37fac2a11604801a617061b77a03f6f
Created September 22, 2022 15:59
Third Version of Test Code
@Test
fun `sulfuras never changes`() {
assertBeforeAndAfter(SULFURUS_NAME, Int.MAX_VALUE, 80, Int.MAX_VALUE,80)
}
@Test
fun `sulfuras never changes even with weird values`() {
// NOTE: Gilded rose does not enforce quality or sellin for sulfuras
assertBeforeAndAfter(SULFURUS_NAME,-1,-3,-1,-3)
}