This file contains hidden or 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.DelicateCoroutinesApi | |
import kotlinx.coroutines.channels.ReceiveChannel | |
import kotlinx.coroutines.runBlocking | |
import kotlinx.coroutines.sync.Mutex | |
import kotlinx.coroutines.sync.withLock | |
import java.io.InputStream | |
class ChannelInputStream(val channel: ReceiveChannel<ByteArray>) : InputStream() { | |
private var buffer: ByteArray? = null | |
private var bufferIndex = 0 |
This file contains hidden or 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 android.util.Base64 | |
import com.google.gson.Gson | |
import com.google.gson.JsonParseException | |
import com.google.gson.TypeAdapter | |
import com.google.gson.TypeAdapterFactory | |
import com.google.gson.reflect.TypeToken | |
import com.google.gson.stream.JsonReader | |
import com.google.gson.stream.JsonToken | |
import com.google.gson.stream.JsonWriter |
This file contains hidden or 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
/** | |
* Transform the given dotted string [str] to a sequence of string. | |
* Example: `"key.value"` -> `["key", "value"]` | |
* | |
* - All values are trimmed of whitespaces. `" a. b .c "` -> `["a", "b", "c"]` | |
* - An empty point `"."`, multiple points `".."` produces nothing. -> `[]` | |
* - Leading point(s) `".key"`, `"..key"` or trailing point(s) `"key."`, `"key.."` are omitted -> `["key"]` | |
* - Multipoint between elements `"key..value"` are like single point -> `["key", "value"]` | |
* | |
* @param str The dotted string to parse |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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. |
NewerOlder