Skip to content

Instantly share code, notes, and snippets.

View goldobin's full-sized avatar

Oleksandr Goldobin goldobin

View GitHub Profile
@goldobin
goldobin / Base64Codecs.scala
Last active October 5, 2015 07:41
Base64 codecs for Scala (JDK8)
object Base64Codecs {
private val base64Encoder = Base64.getEncoder
private val base64Decoder = Base64.getDecoder
private def toBase64String(bytes: Array[Byte]): String = {
base64Encoder.encodeToString(bytes)
}
private def parseBase64String(s: String): Array[Byte] = {
base64Decoder.decode(s)
@goldobin
goldobin / ByteStringConverters.scala
Last active November 6, 2017 08:06
Converters for UUID and String to ByteString for Scala
object ByteStringConverters {
implicit val DefaultByteOrder = ByteOrder.BIG_ENDIAN
implicit class UUIDWithToByteString(uuid: UUID) {
def toByteString = ByteString(
ByteBuffer
.allocate(16)
.putLong(uuid.getMostSignificantBits)
.putLong(8, uuid.getLeastSignificantBits)
)
@goldobin
goldobin / HexCodecs.scala
Last active October 5, 2015 07:40
Hex Codec for Scala
object HexCodecs {
private def parseHexChar(c: Char): Int = {
val b =
if (c >= '0' && c <= '9')
c - '0'
else if (c >= 'a' && c <= 'f')
(c - 'a') + 10
else if (c >= 'A' && c <= 'F')
(c - 'A') + 10
else
import java.util.UUID
import java.nio.ByteBuffer
object UuidConverters {
implicit class BigIntToUuid(v: BigInt) {
def toUuid: UUID = {
val bb: ByteBuffer = ByteBuffer.wrap(v.toByteArray)
val high: Long = bb.getLong
val low: Long = bb.getLong
new UUID(high, low)
import org.slf4j.MDC;
import java.util.HashMap;
import java.util.Map;
import java.util.function.*;
public final class DiagnosticsContext {
private final Map<String, String> context = new HashMap<>();