Skip to content

Instantly share code, notes, and snippets.

/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import CoroutineSingletons.UNDECIDED
import arrow.atomic.Atomic
import arrow.atomic.loop
import arrow.atomic.value
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
@kyay10
kyay10 / Beep.kt
Created December 9, 2023 23:03
A Kotlin beep function
import kotlinx.coroutines.delay
import java.io.InputStream
import java.nio.ByteBuffer
import javax.sound.sampled.AudioFormat
import javax.sound.sampled.AudioInputStream
import javax.sound.sampled.AudioSystem
import javax.sound.sampled.Clip
import kotlin.math.sin
import kotlin.time.Duration
import kotlin.time.DurationUnit
@kyay10
kyay10 / ContextReceivers.kt
Last active July 30, 2023 20:45
Experiment with typeclasses using context receivers
@file:OptIn(ExperimentalContracts::class) @file:Suppress("SUBTYPING_BETWEEN_CONTEXT_RECEIVERS")
import kotlin.contracts.*
@Target(AnnotationTarget.FUNCTION)
annotation class Concept
inline fun <A, B, R> withContexts(
a: A, b: B, block: context(A, B) () -> R
): R {
@kyay10
kyay10 / BindingContext.kt
Last active June 9, 2022 21:54
convenience extensions for BindingContext from kotlin-compiler-embeddable 1.7.0
@file:Suppress("unused", "MemberVisibilityCanBePrivate")
import org.jetbrains.kotlin.backend.common.CodegenUtil
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
import org.jetbrains.kotlin.codegen.getCallLabelForLambdaArgument
import org.jetbrains.kotlin.codegen.isValueArgumentForCallToMethodWithTypeCheckBarrier
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.js.translate.utils.BindingUtils