Skip to content

Instantly share code, notes, and snippets.

View erikhuizinga's full-sized avatar
🤖
Testing droids...

Erik Huizinga erikhuizinga

🤖
Testing droids...
View GitHub Profile
@erikhuizinga
erikhuizinga / script.main.kts
Last active March 1, 2021 14:02
UniFlow out of order state publishing
// Run with:
// kotlinc -script script.main.kts
@file:Repository("https://jcenter.bintray.com")
@file:DependsOn("io.uniflow:uniflow-core:0.11.6")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5")
import io.uniflow.core.flow.*
import io.uniflow.core.flow.data.UIEvent
import io.uniflow.core.flow.data.UIState
@erikhuizinga
erikhuizinga / 7-wonders-duel-solo.kts
Last active November 13, 2020 20:10
7 Wonders Duel: Solo helper in Kotlin Script
val setup = """
ℹ️ SETUP
Set up the Age I cards like in a normal game, but sit so you're facing the first row of cards in the structure.
The zone to the left of the card structure is your City. The zone to the right of the structure is the Leader's City. Begin the game by giving 7 coins to yourself and none to the Leader.
Shuffle all the Wonder cards and draw 3. Choose 2 of these cards for yourself and give the third to the Leader.
Do this a second time. You will therefore start with 4 Wonder cards in your city and 2 in the Leader's City.
The Leader's 2 Wonder cards are treated as if already constructed. Immediately apply the following effects if they are on the Leader's Wonders:
@erikhuizinga
erikhuizinga / CoroutineCrashes.kt
Created June 30, 2020 16:42
Demo of Kotlin coroutine crash machinery
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
fun main() =
package com.example
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test
import org.junit.function.ThrowingRunnable
/**
* JUnit 4.13 test
*/
import kotlin.math.PI
fun main() {
val shapes = listOf(
Square(1.0),
Square(2.0),
Circle(3.0)
)
val shapeVisitors = listOf(
package com.example
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.collect
@erikhuizinga
erikhuizinga / ViewModelOnClearedTest.kt
Created May 27, 2019 19:29
Koin scoped view model
package com.example
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModel
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.koin.androidx.scope.currentScope
@erikhuizinga
erikhuizinga / CartesianProduct.kt
Last active August 14, 2023 08:24
Kotlin function for cartesian product of any number of sets of any size
import kotlin.reflect.KFunction
typealias CartesianProduct = Set<List<*>>
/**
* Create the cartesian product of any number of sets of any size. Useful for parameterized tests
* to generate a large parameter space with little code. Note that any type information is lost, as
* the returned set contains list of any combination of types in the input set.
*
* @param a The first set.
@erikhuizinga
erikhuizinga / Pro Pro.terminal
Last active December 4, 2019 13:27
erikhuizinga's Pro Pro macOS Terminal profile
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBrightWhiteColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OV05TV2hpdGVcTlNDb2xvclNwYWNlViRjbGFzc00w
LjUwMzc5NTU0NjQAEAOAAtIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqIS
FFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FIUF1k
@erikhuizinga
erikhuizinga / CopyOnWriteArrayListBehaviour.java
Created June 18, 2018 11:18
Demo of CopyOnWriteArrayList behaviour: while iterating through a previously nonempty list, clearing the list does not influence the iteration: all elements that existed when the iterator was created exist, despite the list being cleared while iterating.
package com.example;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
public class CopyOnWriteArrayListBehaviour {
// Change this to a regular ArrayList to see what different behaviour the CopyOnWriteArrayList has