Skip to content

Instantly share code, notes, and snippets.

View zach-klippenstein's full-sized avatar

Zach Klippenstein zach-klippenstein

View GitHub Profile
@zach-klippenstein
zach-klippenstein / DebugComposeBounds.kt
Last active June 26, 2022 01:38
Proof-of-concept of a composable that draws information about all its children on top of them.
@Composable fun App() {
DebugBounds {
Column(Modifier.background(Color.White).fillMaxSize()) {
BasicText("Some text")
Spacer(Modifier.size(10.dp))
BasicText("More text")
Spacer(Modifier.size(5.dp))
BasicText("Button", Modifier
.clickable { }
.background(Color.Blue, RoundedCornerShape(3.dp))
@zach-klippenstein
zach-klippenstein / ComposableDumper.kt
Last active June 26, 2022 01:38
Simple utility to dump the current Composition tree to logcat.
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
zach-klippenstein / DrawLayerDemo.kt
Last active October 21, 2021 10:59
Interactive demo of the drawLayer composable function. (screencap in comments)
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
interface Host {
suspend fun getMovies(): List<Movies>
suspend fun setWatched(movie: Movie): Boolean
close()
}
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
zach-klippenstein / DatabaseWorkerPool.kt
Created October 24, 2018 16:19
Sketch of what a worker pool for limiting concurrent database operations might look like.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.coroutineContext
class DatabaseExecutor(
nWorkers: Int,
context: CoroutineContext
) {
class CoroutineNamesTest {
@Test fun coroutineNames() {
runBlocking(CoroutineName("parent")) {
println("parent: $coroutineContext")
launch {
println("unnamed child: $coroutineContext")
}
launch(CoroutineName("named child")) {
@zach-klippenstein
zach-klippenstein / SelectClauses.kt
Last active August 20, 2021 16:39
Helper methods to build select clauses for Kotlin coroutines
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
zach-klippenstein / git-edit.sh
Last active August 29, 2015 14:26
Shell script for amending commits on a feature branch.
#!/bin/zsh
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
zach-klippenstein / audiowave.go
Last active September 1, 2022 19:39
Terminal program that plays a sine wave.
//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).
Installation:
go get github.com/gizak/termui