Skip to content

Instantly share code, notes, and snippets.

View twyatt's full-sized avatar

Travis Wyatt twyatt

View GitHub Profile
@twyatt
twyatt / settings.gradle.kts
Created July 6, 2024 06:11
Include sibling projects as composite builds via `local.properties`
// Configure sibling composite projects (`../<project>`) by adding `composite.<project>=true` to `local.properties`.
java.util.Properties()
.apply {
rootProject.projectDir
.resolve("local.properties")
.normalize()
.takeIf(File::exists)
?.let { java.io.FileInputStream(it) }
?.use(::load)
}
@twyatt
twyatt / release-notes-condenser.go
Created March 12, 2024 09:39
Reads release notes from clipboard and prints condensed version to console.
/* Reads release notes from clipboard and prints condensed version to console.
*
* **BEFORE**
*
* - Update ktlint to v1.0.1 (#92)
* - Update dependency gradle to v8.3 (#86)
* - Update dependency gradle to v8.4 (#91)
* - Update dependency org.slf4j:slf4j-simple to v2.0.9 (#90)
* - Update ktlint to v1 (major) (#89)
*
@twyatt
twyatt / Package.swift
Last active August 3, 2023 16:55
Datadog 1.22.0 xcodebuild failure
// swift-tools-version:5.8
import PackageDescription
let package = Package(
name: "MyPackage",
platforms: [
.iOS(.v11)
],
products: [
@twyatt
twyatt / ChannelSendExceptions.kt
Created April 15, 2021 08:11
Exceptions thrown when sending to closed/cancelled Channel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.coroutineScope
suspend fun main() = coroutineScope<Unit> {
val receive = Channel<Int>()
receive.cancel() // ReceiveChannel
// java.util.concurrent.CancellationException: RendezvousChannel was cancelled
runCatching { receive.send(1) }.onFailure { println(it) }
val send = Channel<Int>()
@twyatt
twyatt / async-await.kt
Last active December 30, 2020 22:28
Experiment to confirm that multiple Coroutines will all suspend when calling `Deferred.await` (and all get the resulting failure)
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope
suspend fun <T> Deferred<T>.awaitCatching(launchNumber: Int, startTime: Long) = try {
await()
} catch (t: Throwable) {
@twyatt
twyatt / comparison.md
Last active December 1, 2020 20:12
try-finally vs. invokeOnCompletion

The invokeOnCompletion will always be invoked, but it has a number of different characteristics vs. its try counterpart.

try-catch-finally invokeOnCompletion
  • suspend functionality
  • Predictable threading/context
  • Familiar semantics
  • Adheres to Coroutine cancellation
  • Blocking execution on arbitrary thread
  • No guarantees around execution timing
  • Implementation must be fast, non-blocking, and thread-safe
  • Exceptions are wrapped with CompletionHandlerException1
GlobalScope.launch(Dispatchers.IO) {
    try {
 // todo
@twyatt
twyatt / osx-apps.md
Last active October 5, 2020 05:13
OS X Apps
brew install httpie
brew install bat
@twyatt
twyatt / cheatsheet.md
Last active January 25, 2024 13:14
CBOR cheatsheet

CBOR cheatsheet

Major type Description Binary Shorthand
0 an unsigned integer 000_xxxxx unsigned(#)
1 a negative integer 001_xxxxx negative(#-1)
2 a byte string 010_xxxxx bytes(n)
3 a text string 011_xxxxx text(n)
4 an array of data items 100_xxxxx array(n)
5 a map of pairs of data items 101_xxxxx map(n)
@twyatt
twyatt / output.txt
Created August 22, 2019 05:45
Kotlin Coroutine Experiment: 2 Flows, 1 Channel
pollChars
← CharData(value=a)
← CharData(value=b)
pollNumbers
← NumberData(value=-1)
← NumberData(value=0)
← NumberData(value=1)
pollChars
← CharData(value=c)
pollNumbers
@twyatt
twyatt / GattExtensions.kt
Last active April 8, 2019 19:49
Provides a shorthand for writing to a characteristic using a service and characteristic UUID. https://github.com/JuulLabs-OSS/able
package com.example.myapplication
import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.BluetoothGattService
import com.juul.able.experimental.Gatt
import com.juul.able.experimental.WriteType
import com.juul.able.experimental.throwable.writeCharacteristicOrThrow
import java.util.UUID
class GattServiceNotFound(uuid: UUID) : Exception("GATT service $uuid not found.")