Skip to content

Instantly share code, notes, and snippets.

@arturaz
arturaz / VertxReadFileFlux.scala
Created June 9, 2020 20:44
Turn a Vertx file into Scala reactor flux which reads bytes upon demand
trait FileProps {
def size: Long
}
val vfs: FileSystem = ???
def readFlux(path: Path): Future[(FileProps, SFlux[Buffer])] =
vfs.propsFuture(path.toString).map { vertxFileProps =>
val props = new FileProps {
override def size = vertxFileProps.size()
import 'dart:io';
import 'package:functional_data/functional_data.dart';
import 'package:meta/meta.dart';
import 'package:zowo_lib/lib.dart';
part 'Config.g.dart';
@immutable
@FunctionalData()
@arturaz
arturaz / SSLUtil.scala
Last active March 30, 2020 09:24
Support for creating a java SSLContext from letsencrypt certificates using BouncyCastle and Scala.
package app.utils
import java.io.{FileReader, Reader}
import java.nio.file.Path
import java.security.cert.Certificate
import java.security.{KeyStore, Security}
import javax.net.ssl.{KeyManagerFactory, SSLContext, TrustManagerFactory}
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo
import org.bouncycastle.cert.X509CertificateHolder
@arturaz
arturaz / Fs2SevenZip.scala
Created March 26, 2020 21:30
Utility class to unzip 7zip archives using fs2 scala library
package app.utils
import java.io.{File, FileOutputStream, RandomAccessFile}
import cats.effect.{ConcurrentEffect, IO}
import com.typesafe.scalalogging.Logger
import fs2._
import fs2.concurrent.Queue
import net.sf.sevenzipjbinding._
import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream
@arturaz
arturaz / MyDBContext.scala
Last active February 28, 2020 09:52
Quill JSON Play support
class MyDBContext(
dataSource: DataSource with Closeable,
ec: ExecutionContextWithExecutor
) extends PostgresJdbcContext(SnakeCase, dataSource)
with Queries with Quotes with JsonB with Codecs
@arturaz
arturaz / kotlin.kt
Created January 28, 2020 10:45
Interoperability between scala and kotlin persistent collections
package zowo_shared.lib.compat
import kotlinx.collections.immutable.ImmutableCollection
import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentMapOf
import zowo_shared.lib.functional.ZOption
interface ICompatPersistentMap<K, V> {
val entries: ImmutableSet<Map.Entry<K, V>>
@arturaz
arturaz / gist:80cf15617aa4c83b719933958b5b4ec4
Created July 21, 2019 18:21
Windows API (Win32) to flash (blink) the taskbar window in Unity
https://github.com/tinylabproductions/tlplib/commit/3d96ea5e6d90d168ea41bc0d2470c7b2d86b74b0
@arturaz
arturaz / InteractiveBrokersDividends.scala
Created April 22, 2019 10:55
Little scala script for calculating the dividends and withholdings for them for InteractiveBrokers platform
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Path, Paths}
case class Identifier(ticker: String, isin: String)
val DescriptionRe = """^(.+?)\s*\((.+?)\).*$""".r
def read(path: Path): Map[Identifier, Vector[BigDecimal]] = {
val lines = Files.readAllLines(path, StandardCharsets.UTF_8)
var map = Map.empty[Identifier, Vector[BigDecimal]].withDefaultValue(Vector.empty)
@arturaz
arturaz / Conversions.cs
Created April 6, 2019 10:13
JVM and .NET compatible GUID usable in Unity that can be converted back and forth without any allocations.
using com.tinylabproductions.TLPLib.Data;
using Quantum;
namespace Game.code.quantum_bind {
public static class Conversions {
public static unsafe QGuid toQGuid(this SerializableGUID guid) {
var srcBytes = stackalloc byte[16];
var dstBytes = stackalloc byte[16];
*((ulong*) srcBytes) = guid.long1;
*((ulong*) (srcBytes + 8)) = guid.long2;
// photon does not serialize ulong by default
public static readonly IPhotonProperty<QGuid> PROP_USER_ID =
PhotonProperty.a(new TypedKey<long>("UserId_p0"))
.add(
PhotonProperty.a(new TypedKey<long>("UserId_p1")),
(l1, l2) => new QGuid((ulong) l1, (ulong) l2),
id => (long) id.long1,
id => (long) id.long2
);