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"
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>>();
@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();
@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 / 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 / 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 / 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 / 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

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:

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