This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
usage() { | |
echo "usage:" | |
echo " $0 -k <key.pk8> -c <cert.x509.pem> [-o <keystore.jks>] [-s <keystore_password>]" | |
if [ -n "$1" ] ; then | |
echo "FILE: \"$1\" NOT FOUND" | |
fi | |
exit 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
GITEA_VERSION="1.21.8" | |
apt update && apt upgrade -y | |
apt install git openssh-server -y | |
adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git | |
wget -O gitea https://dl.gitea.io/gitea/$GITEA_VERSION/gitea-$GITEA_VERSION-linux-amd64 | |
chmod +x gitea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Thread safe shared resources. | |
* | |
* ```kotlin | |
* // await 1s with the resource | |
* fun run(pool: ResourcePool<*>) = launch { pool { delay(1.seconds) } } | |
* | |
* // Pool of 2 usable elements at the same time | |
* val pool = ResourcePool<Unit>(2) { Unit } | |
* (0 ..< 120).map { run(pool) }.joinAll() // elapsed time ~60s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Read the [InputStream] and yield a [CharSequence] every time a new line is found. | |
* | |
* @receiver The [InputStream] to parse. | |
* @return a sequence of each line in the stream. (without new lines) | |
*/ | |
fun InputStream.lineSequence(): Sequence<CharSequence> = lineSequence { read() } | |
fun Reader.lineSequence(): Sequence<CharSequence> = lineSequence { read() } | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Parse arguments with gnu syntax. | |
* | |
* When parsing, the name given to [onArgument] can be: | |
* - `null` if found value has no hyphen. | |
* - A short option if the value starts with a hyphen. (`-s`) | |
* - A long option if the value starts with a double hyphen. (`--long`) | |
* | |
* The `getValue` can be used to get the next non-hyphen value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
fun CoroutineScope.onMain(action: suspend CoroutineScope.() -> Unit) = | |
launch(Dispatchers.Main, block = action) | |
fun CoroutineScope.onIo(action: suspend CoroutineScope.() -> Unit) = | |
launch(Dispatchers.IO, block = action) | |
fun CoroutineScope.onDefault(action: suspend CoroutineScope.() -> Unit) = | |
launch(Dispatchers.Default, block = action) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.serialization.Serializable | |
/** | |
* Utility class to work with hexadecimal strings. | |
* | |
* Two hex values with same [raw] should be equals. | |
* Even if one was created with lower cased hex and the other with upper cased hex. | |
* | |
* It contains : | |
* - static helpers to encode [fromString] and decode [toString] in hexadecimal strings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.channels.Channel | |
import kotlinx.coroutines.channels.ClosedReceiveChannelException | |
import kotlinx.coroutines.isActive | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking | |
import kotlinx.coroutines.sync.Mutex | |
import kotlinx.coroutines.sync.withLock | |
import java.lang.ref.WeakReference |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T : Enum<T>> enumGetBy(default: T, predicate: (T) -> Boolean): T = | |
enumGetByOrNull(predicate) ?: default | |
inline fun <reified T : Enum<T>> enumGetByOrNull(predicate: (T) -> Boolean): T? = | |
enumValues<T>().find(predicate) | |
inline fun <reified T : Enum<T>> enumGetByName(name: String, default: T): T = | |
enumGetBy(default) { it.name == name } | |
inline fun <reified T : Enum<T>> enumGetByNameOrNull(name: String): T? = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Either<out L, out R> { | |
abstract val left: L | |
abstract val right: R | |
abstract fun invert(): Either<R, L> | |
} | |
class Left<out L>(override val left: L) : Either<L, Nothing>() { | |
companion object { | |
@JvmStatic |
NewerOlder