Skip to content

Instantly share code, notes, and snippets.


Zach Klippenstein zach-klippenstein

View GitHub Profile
zach-klippenstein / DebugComposeBounds.kt
Last active Mar 5, 2021
Proof-of-concept of a composable that draws information about all its children on top of them.
View DebugComposeBounds.kt
@Composable fun App() {
DebugBounds {
Column(Modifier.background(Color.White).fillMaxSize()) {
BasicText("Some text")
BasicText("More text")
BasicText("Button", Modifier
.clickable { }
.background(Color.Blue, RoundedCornerShape(3.dp))
zach-klippenstein / ComposableDumper.kt
Last active Feb 1, 2021
Simple utility to dump the current Composition tree to logcat.
View ComposableDumper.kt
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.currentComposer
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.IntBounds
import androidx.ui.tooling.CallGroup
import androidx.ui.tooling.Group
import androidx.ui.tooling.NodeGroup
import androidx.ui.tooling.asTree
zach-klippenstein / DrawLayerDemo.kt
Last active Mar 22, 2021
Interactive demo of the drawLayer composable function. (screencap in comments)
View DrawLayerDemo.kt
import androidx.animation.PhysicsBuilder
import androidx.animation.Spring.DampingRatioHighBouncy
import androidx.animation.Spring.StiffnessLow
import androidx.compose.Composable
import androidx.compose.Model
import androidx.compose.remember
import androidx.ui.animation.animate
import androidx.ui.core.DrawClipToBounds
import androidx.ui.core.Text
import androidx.ui.core.drawLayer
View Host.kt
interface Host {
suspend fun getMovies(): List<Movies>
suspend fun setWatched(movie: Movie): Boolean
class HostImpl(
// You could have a different WorkerPool for each system you need to talk to
// that has its own throttling requirements.
private val workerPool: WorkerPool
zach-klippenstein / DatabaseWorkerPool.kt
Created Oct 24, 2018
Sketch of what a worker pool for limiting concurrent database operations might look like.
View DatabaseWorkerPool.kt
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.coroutineContext
class DatabaseExecutor(
nWorkers: Int,
context: CoroutineContext
) {
View CoroutineNamesTest.kt
class CoroutineNamesTest {
@Test fun coroutineNames() {
runBlocking(CoroutineName("parent")) {
println("parent: $coroutineContext")
launch {
println("unnamed child: $coroutineContext")
launch(CoroutineName("named child")) {
zach-klippenstein / SelectClauses.kt
Last active Jun 1, 2019
Helper methods to build select clauses for Kotlin coroutines
View SelectClauses.kt
package com.zachklipp.coroutines
import kotlinx.coroutines.experimental.DisposableHandle
import kotlinx.coroutines.experimental.intrinsics.startCoroutineCancellable
import kotlinx.coroutines.experimental.selects.SelectClause0
import kotlinx.coroutines.experimental.selects.SelectClause1
import kotlinx.coroutines.experimental.selects.SelectClause2
import kotlinx.coroutines.experimental.selects.SelectInstance
zach-klippenstein /
Last active Aug 29, 2015
Shell script for amending commits on a feature branch.
if [ "$1" = '-h' ]; then
cat <<-EOF
Usage: git-edit <branch> [args-to-commit]
e.g. If your tree looks like this:
* cc3cd23 (HEAD -> feat1) Feature 1.2
* 53f56c1 Feature 1
* 08355e5 (master) Initial commit.
zach-klippenstein / audiowave.go
Last active Dec 26, 2018
Terminal program that plays a sine wave.
View audiowave.go
//usr/local/bin/go run $0 "$@"; exit
Terminal program that plays a sine wave.
The pitch and volume can be controlled (help is shown in the UI).
go get