Skip to content

Instantly share code, notes, and snippets.

View morj's full-sized avatar

Pavel Nikitin morj

  • JetBrains
  • Munich, Germany
View GitHub Profile
@morj
morj / PrimitiveFlow.kt
Created April 16, 2024 17:49
Primitive flow
import kotlinx.coroutines.runBlocking
import java.util.concurrent.atomic.AtomicInteger
interface Flow<out T> {
suspend fun collect(collector: FlowCollector<T>)
}
fun interface FlowCollector<in T> {
suspend fun emit(value: T)
}
@file:Suppress("UNCHECKED_CAST")
package circlet.platform.server.application
import java.util.concurrent.atomic.*
class BusyWaitSingleton<T>(private val factory: () -> T) {
private val value = AtomicReference<State>(State.Empty)
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlin.random.Random
suspend fun build(): () -> Unit {
val number = Random(239).nextInt()
return withContext<() -> Unit>(CoroutineName("produce value")) {
delay(1)
@morj
morj / dump.clj
Last active September 19, 2019 19:39
(def bootstrap-invoke
'(fn
[^java.lang.invoke.MethodHandles$Lookup caller
^String methodName
^java.lang.invoke.MethodType methodType
^String varName]
(do
(when (nil? huj.SampleNS/var_x_var)
(set! huj.SampleNS/var_x_var
(clojure.lang.Var. huj.SampleNS/ns (clojure.lang.Symbol/intern varName))))
@morj
morj / temp.clj
Created September 19, 2019 15:10
(ns clojure.tools.emitter.temp
(:refer-clojure :exclude
[eval macroexpand-1 macroexpand load])
(:require [clojure.tools.analyzer.jvm :as a]
[clojure.tools.emitter.jvm :as j]
[clojure.tools.analyzer :refer [macroexpand-1 macroexpand]]
[clojure.tools.analyzer.passes :refer [schedule]]
[clojure.tools.analyzer.env :as env]
[clojure.tools.analyzer.utils :refer [mmerge]]
[clojure.tools.emitter.jvm.emit :as e]
@file:Suppress("KDocMissingDocumentation")
import io.ktor.client.HttpClient
import io.ktor.client.engine.apache.Apache
import io.ktor.client.request.get
import kotlinx.coroutines.Runnable
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import java.util.concurrent.ThreadFactory
import java.util.concurrent.TimeUnit
package sandbox
import jetbrains.exodus.entitystore.PersistentEntityStoreImpl
import jetbrains.exodus.env.EnvironmentConfig
import jetbrains.exodus.env.EnvironmentImpl
import jetbrains.exodus.env.Environments
import jetbrains.exodus.io.FileDataReader
import jetbrains.exodus.log.LogConfig
import kotlinx.coroutines.experimental.future.await
import kotlinx.coroutines.experimental.runBlocking
package sandbox
import jetbrains.exodus.io.Block
import jetbrains.exodus.io.DataReader
import jetbrains.exodus.io.FileDataReader
import jetbrains.exodus.io.RemoveBlockType
import jetbrains.exodus.log.Log
import jetbrains.exodus.log.LogUtil
import mu.KLogging
import software.amazon.awssdk.core.AwsRequestOverrideConfig
open class SuspendAwareThrowable(message: String?) : Throwable(message) {
companion object : KLogging()
private val _cause = AtomicReference<Throwable>(null)
override fun fillInStackTrace(): Throwable {
return if (logger.isDebugEnabled) {
super.fillInStackTrace()
} else {
this
typealias LArray1 = Array<LongArray?>
typealias LArray2 = Array<LArray1?>
typealias LArray3 = Array<LArray2?>
typealias LArray4 = Array<LArray3?>
typealias LArray5 = Array<LArray4?>
typealias LArray6 = Array<LArray5?>
@Suppress("ConvertTwoComparisonsToRangeCheck")
class LongBitTree : Iterable<Long> {
@Suppress("NOTHING_TO_INLINE")