Skip to content

Instantly share code, notes, and snippets.

View ahoy-jon's full-sized avatar
🐋
Thinking!

Jonathan Winandy ahoy-jon

🐋
Thinking!
View GitHub Profile
import scala.annotation.{ nowarn, tailrec }
import kyo.*
val a = 1
def doSomething(): Unit = {
println("do")
println("something")
}
//> using scala 3.4.2
//> using dep "io.swagger.core.v3:swagger-annotations-jakarta:2.2.22"
//> using dep "com.softwaremill.sttp.tapir:tapir-core_3:1.11.0"
import io.swagger.v3.oas.annotations.media.{Schema => OpenApiSchema}
import sttp.tapir.*
import sttp.tapir.generic.auto.*
#awk '
function chunk_mod(s) {
len = 6 # 6 digits in case of 32-bit awk version
result = 0
while (length(s) > 0) {
chunk = substr(s, 1, len)
s = substr(s, len + 1)
result = (result * (10 ^ length(chunk)) + chunk) % 97
}
return result
@ahoy-jon
ahoy-jon / Main.scala
Created April 15, 2023 08:25
Read - write Kafka - Sans protections
import org.apache.kafka.clients.consumer.{ConsumerConfig, KafkaConsumer}
import org.apache.kafka.common.serialization.{StringDeserializer, StringSerializer}
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig
import org.apache.avro.generic.GenericRecord
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerConfig, ProducerRecord}
import java.util.Properties
import scala.jdk.CollectionConverters._

Keybase proof

I hereby claim:

  • I am ahoy-jon on github.
  • I am ahoy_jon (https://keybase.io/ahoy_jon) on keybase.
  • I have a public key whose fingerprint is 2D1F 3333 68BF 23E6 0B5F 97EC AA13 2117 84F5 5FCC

To claim this, I am signing this object:

sealed abstract class Cont[Result, +H] {
final def map[H2](fn: H => H2): Cont[Result, H2] = flatMap(h => Cont.pure(fn(h)))
final def flatMap[H2](fn: H => Cont[Result, H2]): Cont[Result, H2] = Cont.FlatMapped(this, fn)
def apply(fn: H => Result): Result
}
object Cont {
case class Wrap[Result, H](f: (H => Result) => Result) extends Cont[Result, H] {
def toIterator[R, E, A](
stream: ZStream[R, E, A]
): ZManaged[R, Nothing, Iterator[Either[E, A]]] = {
/*
* Internal state of a Iterator pulling from a ZStream
*
* It starts as Running
*
* when Running , on pull (hasNext), pull the ZStream and switch to Closed or Value
* when Value , on consume (next), return the Value and switch to Running
sealed trait Path
case class Field(name: String, child: Option[Path]) extends Path {
override def toString: String = child match {
case None => name
case Some(path) => s"$name.$path"
}
}
class ToIterator private (runtime: Runtime[Any]) {
def unsafeCreate[V](q: UIO[stream.Stream[_,V]]): Iterator[V] =
new Iterator[V] {
import ToIterator._
var state: State[V] = Running
val synchronousBlockQueue: BlockingQueue[ValueOrClosed[V]] = new SynchronousQueue[ValueOrClosed[V]]
object ZioToSparkIterator {
def toIterator[E, A](q: UIO[stream.Stream[E, A]]): Iterator[Either[E, A]] = new Iterator[Either[E, A]] {
sealed trait State
case object Running extends State
sealed trait ValueOrClosed extends State
case object Closed extends ValueOrClosed
case class Value(value: Either[E, A]) extends ValueOrClosed