Skip to content

Instantly share code, notes, and snippets.

@Tetraquark
Tetraquark / ProduceBuilder.kt
Created February 2, 2020 10:33
What is channel? ProduceBuilder
@ExperimentalCoroutinesApi
public fun <E> CoroutineScope.produce(
context: CoroutineContext = EmptyCoroutineContext,
capacity: Int = 0,
@BuilderInference block: suspend ProducerScope<E>.() -> Unit
): ReceiveChannel<E>
@Tetraquark
Tetraquark / CreateChannelExmpl.kt
Created February 2, 2020 10:32
What is channel? CreateChannelExmpl
import kotlinx.coroutines.channels.Channel
val channel = Channel<Int>()
@Tetraquark
Tetraquark / ChannelInterface.kt
Created February 2, 2020 10:30
What is channel? ChannelInterface
public interface Channel<E> : SendChannel<E>, ReceiveChannel<E>
@Tetraquark
Tetraquark / ChannelBuilderFun.kt
Created February 2, 2020 10:29
What is channel? ChannelBuilderFun
public fun <E> Channel(capacity: Int = RENDEZVOUS): Channel<E>
@Tetraquark
Tetraquark / BroadcastChannelInterface.kt
Created February 2, 2020 10:29
What is channel? BroadcastChannelInterface
public fun openSubscription(): ReceiveChannel<E>
public fun cancel(cause: CancellationException? = null)
@Tetraquark
Tetraquark / BroadcastChannelBuilder.kt
Created February 2, 2020 10:26
What is channel? Article gists, BroadcastChannelBuilder
public fun <E> BroadcastChannel(capacity: Int): BroadcastChannel<E>
import ru.tetraquark.kexperiments.callbacktosuspend.SomeJavaApi
import kotlinx.coroutines.*
import kotlin.Exception
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
fun main() = runBlocking {
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SomeJavaApi {
private static final String SUCCESS_RESULT = "SUCCESSFUL_CALL";
private static final long WORK_DELAY = 1000L;
@Tetraquark
Tetraquark / discordpy-chatbot.py
Last active March 16, 2019 10:35
Example of simple discord chatbot based on discord.py library
#
# Example of simple discord chatbot based on discord.py library
# For article (Russian language): http://tetraquark.ru/archives/377
#
import discord
import asyncio
import requests
DISCORD_BOT_TOKEN = 'DISCORD_APP_TOKEN'
@Tetraquark
Tetraquark / fastica_exmp.py
Last active December 11, 2019 16:06
Simple example of using FastICA algorithm
#
# Testing of FastICA algorithm from sklearn library.
# Author: tetraquark | tetraquark.ru
# Article URL (RUS language): http://tetraquark.ru/archives/311
#
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import FastICA
# Length of the sources signals