Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Bennett ditn

View GitHub Profile
@ditn
ditn / ConwayCompose.kt
Created Oct 11, 2020
Conway's Composable Game of Life
View ConwayCompose.kt
private val rand = Random(0)
private const val CELL_SIZE = 50
private val ALIVE_COLOR = Color.White
private val DEAD_COLOR = Color.Black
private val BooleanToVector: TwoWayConverter<Boolean, AnimationVector1D> = TwoWayConverter(
{ AnimationVector1D(if (it) 1f else 0f) },
{ it.value == 1f }
)
@Composable
@ditn
ditn / DynamicMeshNetwork.kt
Created Sep 30, 2020
Dynamic Mesh Network animation in Compose
View DynamicMeshNetwork.kt
private val PARTICLE_COLOR = Color.White
private val LINE_COLOR = Color.White
private const val PARTICLE_QUANTITY = 100
private const val DEFAULT_SPEED = 2
private const val VARIANT_SPEED = 1
private const val DEFAULT_RADIUS = 4
private const val VARIANT_RADIUS = 2
private const val LINK_RADIUS = 200
// TODO: 30/09/2020 These should be measured but are only used to calculate
// the initial position
View TransactionSenderExtension.kt
fun TransactionSender.logTransaction(eventLogger: EventLogger): TransactionSender =
TransactionLogger(this, eventLogger)
@ditn
ditn / ktlint.gradle.kts
Created Dec 7, 2018
ktlint with Gradle Kotlin DSL
View ktlint.gradle.kts
val ktlint by configurations.creating
dependencies {
ktlint(Libraries.ktlint)
}
tasks.register<JavaExec>("ktlint") {
group = "verification"
description = "Check Kotlin code style."
classpath = ktlint
@ditn
ditn / blockstack_verification.txt
Created May 21, 2018
Verifying my Blockstack ID
View blockstack_verification.txt
Verifying my Blockstack ID is secured with the address 16RnXJ8orEyoEdZGWYQRRxudjrYuQNPoYS https://explorer.blockstack.org/address/16RnXJ8orEyoEdZGWYQRRxudjrYuQNPoYS
@ditn
ditn / idiomatic_ternary_function.kt
Created Apr 26, 2018
Idiomatic ternary function in Kotlin
View idiomatic_ternary_function.kt
val builder = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(icon)
// Excluded for brevity
.apply {
if (AndroidUtils.is19orHigher()) {
setVibrate(longArrayOf(100))
} else {
setVibrate(longArrayOf())
}
}
@ditn
ditn / generic_ternary_function.kt
Last active Apr 26, 2018
Generic ternary function
View generic_ternary_function.kt
fun <T> T.ternaryBuilder(
predicate: () -> Boolean,
trueFunc: T.() -> T,
falseFunc: T.() -> T
): T = if (predicate()) this.trueFunc() else this.falseFunc()
@ditn
ditn / naive_ternary_builder_use.kt
Created Apr 26, 2018
Naive Kotlin builder use
View naive_ternary_builder_use.kt
val builder = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(icon)
// Excluded for brevity
.ternaryBuilder(
{ AndroidUtils.is19orHigher() },
{ setVibrate(longArrayOf(100)) },
{ setVibrate(longArrayOf()) }
)
.setContentText(text)
@ditn
ditn / naive_builder_extension.kt
Last active Apr 26, 2018
naive_high_order_extension
View naive_builder_extension.kt
private fun NotificationCompat.Builder.ternaryBuilder(
predicate: () -> Boolean,
trueFunc: NotificationCompat.Builder.() -> NotificationCompat.Builder,
falseFunc: NotificationCompat.Builder.() -> NotificationCompat.Builder
): NotificationCompat.Builder = if (predicate()) this.trueFunc() else this.falseFunc()
@ditn
ditn / kotlin_builder_breakout.kt
Last active Apr 26, 2018
builder pattern in kotlin with breakout
View kotlin_builder_breakout.kt
val builder = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(icon)
// Excluded for brevity
.setContentText(text)
if (AndroidUtils.is19orHigher()) {
builder.setVibrate(longArrayOf(100))
} else {
builder.setVibrate(longArrayOf())
}