Skip to content

Instantly share code, notes, and snippets.

@kostapc
kostapc / CustomScope.kt
Created Mar 1, 2021 — forked from juliuscanute/CustomScope.kt
[Custom Coroutine Scope] #kotlin #coroutine
View CustomScope.kt
class CustomScope : CoroutineScope {
private var parentJob = Job()
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + parentJob
fun onStart() {
parentJob = Job()
}
View AsyncIoThread.kt
import kotlinx.coroutines.sync.Semaphore
import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicReference
object AsyncIoThread {
private val executor = Executors.newCachedThreadPool { run ->
val thread = Thread(run)
thread.name = "AsyncIoThread-${thread.name}"
thread.isDaemon = true
View PKCS8-PKCS1-format-conversion.md

The default format of keys was changed in OpenSSL 1.0. From OpenSSL 1.0 change log:

Make PKCS#8 the default write format for private keys, replacing the traditional format. This form is standardised, more secure and doesn't include an implicit MD5 dependency. [Steve Henson]

Good explanations of the difference between the two formats: https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem

Converting RSA private key:

@kostapc
kostapc / AsyncFlowEmission.kt
Last active Oct 7, 2020
kotlin async flow with floating parralel executions count
View AsyncFlowEmission.kt
package net.c0f3.labs.kotlin.flow
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@kostapc
kostapc / SomeGenerics.cs
Created Mar 2, 2020
Testing c# generics
View SomeGenerics.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SomeGenerics {
class Program {
static void Main(string[] args)
{
@kostapc
kostapc / AboutAsyncMain.cs
Created Jan 10, 2020
sample of c# async usage
View AboutAsyncMain.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace FunctionalExperiments
{
class AboutAsyncMain
@kostapc
kostapc / pmap.kt
Created Jan 9, 2020 — forked from slaypni/pmap.kt
Parallel map for kotlin
View pmap.kt
import kotlinx.coroutines.experimental.async
import kotlin.coroutines.experimental.CoroutineContext
suspend fun <T, R> Iterable<T>.pmap(context: CoroutineContext, transform: suspend (T) -> R): List<R> {
return this.map {
async(context) {
transform(it)
}
}.map { it.await() }
}
@kostapc
kostapc / get_img_meta.ps1
Created Aug 2, 2019
get EXIF metadata fields
View get_img_meta.ps1
$path = 'c:\tmp\some_pic_from_camera.jpg'
$shell = New-Object -COMObject Shell.Application
$folder = Split-Path $path
$file = Split-Path $path -Leaf
$objShell = $shell.Namespace($folder)
$shellfile = $objShell.ParseName($file)
#0..287 | Foreach-Object { '{0} = {1}' -f $_, $objShell.GetDetailsOf($null, $_) }
$hash = @{
@kostapc
kostapc / CSExtensionsMethods.cs
Created Apr 19, 2019
C# extensions methods example
View CSExtensionsMethods.cs
using System;
using System.Threading;
namespace FunctionalExperiments
{
class Program
{
static void Main(string[] args)
{
SomeEmptyClass someObject = new SomeEmptyClass();
View SimplePromise.cs
using System;
using System.Collections.Concurrent;
using System.Threading;
namespace FunctionalExperiments {
class ExecutionPool
{
private Boolean flag = true;
private readonly Thread thread;
private BlockingCollection<Func<bool>> taskQueue = new BlockingCollection<Func<bool>>();