Skip to content

Instantly share code, notes, and snippets.

@hohonuuli
hohonuuli / Loom.java
Created October 19, 2022 04:06
Loom example for medium article
import jdk.incubator.concurrent.StructuredTaskScope;
// java --enable-preview --source 19 --add-modules jdk.incubator.concurrent Loom.java
public class Loom {
public static void main(String[] args) {
run();
}
public static void run() {
@hohonuuli
hohonuuli / voc_to_csv.sc
Created October 19, 2022 03:58
Scala script to convert Pascal VOC to CSV. For a medium article
#!/usr/bin/env -S scala-cli shebang --scala-version 3.2.0
//> using lib "org.scala-lang.modules::scala-xml:2.1.0"
import scala.xml.Elem
import java.io.File
import scala.xml.XML
import java.nio.file.Paths
import scala.util.Using
import java.nio.file.Files
<template>
<div class="map-box" id="maptest"></div>
</template>
<script>
import Vue from 'vue'
// If you need to reference 'L', such as in 'L.icon', then be sure to
// explicitly import 'leaflet' into your component
import L from 'leaflet'
@hohonuuli
hohonuuli / ifdo-to-fathomnet.sc
Last active May 26, 2022 01:26
Proof-of-concept to convert https://marine-imaging.com/fair/ifdos/iFDO-overview/ to FathomNet-friendly CSV
#!/usr/bin/env -S scala-cli shebang --scala-version 3.1.2
/*
Proof of concept to convert iFDO YAML to FathomNet CSV
Requirements:
- Install scala-cli https://scala-cli.virtuslab.org
Usage:
ifdo-to-fathomnet.sc <ifdo-yaml-file> > <fathomnet-csv-file>
@hohonuuli
hohonuuli / Logging.scala
Created May 2, 2022 16:33
Gist for Medium article
import java.lang.System.Logger
import java.lang.System.Logger.Level
import java.util.function.Supplier
/**
* * @author Brian Schlining
*/
object Logging:
case class LoggerBuilder(
@hohonuuli
hohonuuli / build_m1.sh
Last active March 16, 2022 19:35
Example build script for docker containers on M1/Arm
#!/usr/bin/env bash
echo "--- Building vars-kb-server (reminder: run docker login first!!)"
VCS_REF=`git tag | sort -V | tail -1`
docker buildx build --platform linux/amd64,linux/arm64 \
-t mbari/vars-kb-server:${VCS_REF} \
-t mbari/vars-kb-server:latest \
--push . \
@hohonuuli
hohonuuli / Logging.scala
Last active February 3, 2022 20:30
Simple pass through logger
import java.lang.System.Logger
import java.lang.System.Logger.Level
object Logging:
private def logAndReturn[T](obj: T, logger: Logger, level: Level, fn: T => String): T =
if logger.isLoggable(level) then
logger.log(level, fn(obj))
obj
@hohonuuli
hohonuuli / Transformer.scala
Last active November 2, 2021 20:30
Method to convert case classes to CSV
import java.net.URL
import scala.deriving.*
import scala.compiletime.{summonAll}
import java.nio.file.Path
/**
* Base function we use to convert case classes to CSV
* @param a The object to convert
*/
def transform[A : Transformer](a: A) = summon[Transformer[A]].f(a)
@hohonuuli
hohonuuli / fetch_async.scala
Last active October 25, 2021 19:39
Scala version of python download code in Medium article
#!/usr/bin/env scala
/*
@author Brian Schlining
@since 2021-10-25
Scala version of example code at
https://python.plainenglish.io/send-http-requests-as-fast-as-possible-in-python-304134d46604
*/
@hohonuuli
hohonuuli / scala3_microservices_autocannon2_results.csv
Last active September 25, 2021 22:36
Statistics for Medium Article on Scala 3 microservice benchmarks - autocannon2
Metric Cask Helidon http4s Javalin Scalatra Spark Java Vert.x Web ZIO Http
autocannon 2
latency (ms) 244.59 238.96 292.62 300.87 240.99 268.99 145.06 230.14
latency std (ms) 25.51 20.57 127.78 33.52 14.88 28.32 6.57 45.18
requests/sec 4058.55 4154.36 3856.9 3294.7 4119.7 3689.6 6850.6 4312.95
requests/sec std 210.95 191.57 166.87 85.13 96.84 124.06 104.82 116.38
transfer/sec (MB) 34.19 34.87 32.38 27.26 34.54 31.18 57.20 36.18
transfer/sec std 1.77 1.61 1.40 0.71 0.81 1.05 0.87 0.97
relative transfer % 59.8 61.0 56.6 47.7 60.4 54.5 100 63.3