Skip to content

Instantly share code, notes, and snippets.

@kostapc
kostapc / gw.ps1
Last active November 10, 2023 14:13
powershell gradle short alias
### https://gist.github.com/kostapc/3912562751e3aaf05d5bdbb337b5431c
#
# gw fast - just build. Skip tests and checkstyle
# gw tree :path:to:project file.txt - print dependencies tree to file
# gw local - install to local maven repository
#
# After script downloading you should unblock it: Unblock-File -Path 'C:\%PATH_TO_SCRIPT%\gw.ps1'
#
$path = ".\gradlew.bat"
@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
@kostapc
kostapc / ConcurrentMultiValuedMap.java
Created March 30, 2017 17:44
concurrent MultiValuedMap implementation
public class ConcurrentMultiValuedMap<K,V> implements MultiValuedMap<K,V> {
private Map<K, Collection<V>> storage = new ConcurrentHashMap<>();
@Override
public int size() {
return storage.size();
}
@Override

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() }
}