Skip to content

Instantly share code, notes, and snippets.

@kostapc
kostapc / docker-clean.ps1
Created August 8, 2023 13:38
Cleanup docker env for free space
# also avoid "Docker environment should have more than 2GB free disk space" error
Write-Host "stopping all dockers" -ForegroundColor DarkRed
docker stop $(docker ps -a -q)
Write-Host "removing all docker" -ForegroundColor DarkRed
docker rm $(docker ps -a -q)
Write-Host "===================" -ForegroundColor DarkRed
Write-Host "performing docker system prune" -ForegroundColor DarkRed
docker system prune --volumes -f
docker ps -a
Write-Host "docker-clean done" -ForegroundColor DarkRed
@kostapc
kostapc / CustomScope.kt
Created March 1, 2021 19:50 — forked from juliuscanute/CustomScope.kt
[Custom Coroutine Scope] #kotlin #coroutine
class CustomScope : CoroutineScope {
private var parentJob = Job()
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + parentJob
fun onStart() {
parentJob = Job()
}
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

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 October 7, 2020 12:50
kotlin async flow with floating parralel executions count
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 March 2, 2020 11:15
Testing c# generics
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 January 10, 2020 11:24
sample of c# async usage
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 January 9, 2020 11:37 — forked from slaypni/pmap.kt
Parallel map for kotlin
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 August 2, 2019 09:22
get EXIF metadata fields
$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 April 19, 2019 17:43
C# extensions methods example
using System;
using System.Threading;
namespace FunctionalExperiments
{
class Program
{
static void Main(string[] args)
{
SomeEmptyClass someObject = new SomeEmptyClass();