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
#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] {
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"
}
}
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
@ahoy-jon
ahoy-jon / CogroupDf.scala
Last active February 3, 2020 11:08
DataFrame.cogroup is the new HList.flatMap (UNFORTUNATELY, THIS IS VERY SLOW)
package org.apache.spark.sql.utils
import org.apache.spark.Partitioner
import org.apache.spark.rdd.{CoGroupedRDD, RDD}
import org.apache.spark.sql.catalyst.{CatalystTypeConverters, ScalaReflection}
import org.apache.spark.sql.execution.LogicalRDD
import org.apache.spark.sql.types.{ArrayType, StructField, StructType}
import org.apache.spark.sql.{SQLContext, DataFrame, Row}
import scala.reflect.ClassTag
import scala.reflect.runtime.universe.TypeTag
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
implicit val qTree:DeepEqual[QTree[Unit]] = DeepEqual.anyDeepEqual
//DeepEqual.gen[DescribeLong]
DeepEqual.gen[ParkaAnalysis].explainNotEqual(pa,paFromJson).foreach(println)
assert(pa == paFromJson)
}
}