Skip to content

Instantly share code, notes, and snippets.

Zach Klippenstein zach-klippenstein

Block or report user

Report or block zach-klippenstein

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Host.kt
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 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
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
zach-klippenstein / git-edit.sh
Last active Aug 29, 2015
Shell script for amending commits on a feature branch.
View git-edit.sh
#!/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 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).
Installation:
go get github.com/gizak/termui
@zach-klippenstein
zach-klippenstein / FunctionalStack.kt
Created Jan 31, 2015
Example of a simple functional data structure in Kotlin.
View FunctionalStack.kt
package com.example.funcstack
import java.util.NoSuchElementException
public trait FunctionalStack<out T> {
public val size: Int
public fun pop(): Pair<T, FunctionalStack<T>>
}
/**
@zach-klippenstein
zach-klippenstein / source_bench_test.go
Last active Aug 29, 2015
Comparative benchmarks of various methods of providing RNG sources to concurrent goroutines.
View source_bench_test.go
package source_bench_test
import (
"github.com/stretchr/testify/require"
"math/rand"
"sync"
"testing"
)
// See https://golang.org/src/math/rand/rand.go
@zach-klippenstein
zach-klippenstein / floatcomp_test.go
Last active Aug 29, 2015
Float Comparison Benchmark: Subtraction vs Multiplication
View floatcomp_test.go
package main
import (
"math"
"math/rand"
"runtime"
"testing"
)
const DELTA_MULT = 10000000000
View keybase.md

Keybase proof

I hereby claim:

  • I am zach-klippenstein on github.
  • I am zachklipp (https://keybase.io/zachklipp) on keybase.
  • I have a public key whose fingerprint is 01D0 C5AB 55E9 29A5 2337 E6CC 0EDD 53ED 8CE1 CD26

To claim this, I am signing this object:

You can’t perform that action at this time.