Skip to content

Instantly share code, notes, and snippets.

@crakjie
crakjie / Cargo.toml
Last active September 1, 2023 16:34
arrow rust
[package]
name = "ckfunc"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
arrow = { version = "45.0.0", features = ["ipc_compression"] }
intmap = "2.0.0"
@crakjie
crakjie / Transactioner.scala
Created October 14, 2019 16:23
cats effect transaction keeper
import cats._
import implicits._
import cats.effect._
import concurrent._
import cats.effect.implicits._
/**
* The transactioner help to make transaction by unsuring the transaction is open before runing task and task are ended before close
* @tparam F
*/
@crakjie
crakjie / splitIn.scala
Created September 25, 2019 12:45
Split a list into n list containing an even number of element
/** Split a list in n List */
def splitIn[A](n: Int)(l: List[A]): List[List[A]] = {
l.zipWithIndex
.foldLeft(Array.fill(n)(List.empty[A])) {
case (b, a) =>
b(a._2 % n) = a._1 :: b(a._2 % n)
b
}
.filter(_.nonEmpty)
.map(_.reverse)(collection.breakOut)
@crakjie
crakjie / Dichotomy.scala
Created December 19, 2018 09:23
Looking for the last point in a continuous function where the predicat "test" is true
import scala.annotation.tailrec
//Looking for the last point in a continuous function where the predicat "test" is true
@tailrec
def dichotomy(lower : Double, upper: Double)( test: Double => Boolean) : Double = {
val gap = (upper-lower)/ 2
val middle = lower + gap
if(gap <= 1)
lower
else if(test(middle)) {
if(middle == lower) //Float or Double precision error
@crakjie
crakjie / Kafka-lag.md
Last active August 21, 2018 14:29
Kafka lag

Lag sum by consumer.

./kafka-consumer-groups.sh --new-consumer  --bootstrap-server localhost:9092 --describe --group csa_aggregator | tail -n +3 | awk '{ sum[$7] += $3 } END { for(i in sum) print i, sum[i] }'

Speed by consumer , the 10 number is '10 second' of sampling. the result is in message by secondes.

paste <(./kafka-consumer-groups.sh --new-consumer  --bootstrap-server localhost:9092 --describe --group csa_aggregator | tail -n +3 | awk '{ sum[$7] += $3 } END { for(i in sum) print i, sum[i] }' ) \
&lt;(sleep 10 &amp;&amp; ./kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --describe --group csa_aggregator | tail -n +3 | awk '{ sum[$7] += $3 } END { for(i in sum) print i, sum[i] }') | \
@crakjie
crakjie / Docker GraalVm on alpine
Created August 1, 2018 13:29
Dockerfile that that create a ready to used graalvm
FROM alpine:3.8
MAINTAINER crakjie
ARG http_proxy
ARG https_proxy
RUN apk --update add --no-cache \
bash \
wget \
def |>[A,B]( a : A)(f : A => B ) : B = f(a)
@ 2 |> Some.apply
res16: Some[Int] = Some(2)
@crakjie
crakjie / keepRight
Created February 21, 2018 10:05
optimistique sequance that prefer good result to bad ones
def keepRight[F[_], G[_, _], B, C](l: F[G[B, C]])(
implicit //proofs
G: Bifoldable[G],
Me: scalaz.MonadError[G[B, ?], B],
F: MonadPlus[F],
Mobf: Monoid[F[B]], // proof we had a zero
Moc: Monoid[F[C]], // proof we had a zero
Mob: Monoid[B], // proof we can fold
eqB: scalaz.Equal[F[B]],
eqC: scalaz.Equal[F[C]],
@crakjie
crakjie / case-class-pool.scala
Last active September 12, 2017 14:16
Try to have a case class pooling
abstract case class Toto private[Toto] (i: Int, j: String) {
val hashCodeVal : Int
override def hashCode() : Int = hashCodeVal
def copy(i: Int = i, j: String = j) = {
Toto(i,j)
}
}
object Toto {
val totoPool = scala.collection.mutable.WeakHashMap[Int, Toto]()
@crakjie
crakjie / git-clean-branches
Created November 23, 2015 18:03
Delete each branch that already in the branch master. Put it in you path and you will have auto complete functionality of git.
#!/bin/bash
while read -r line
do
if [ "$line" != "origin/master" ] && [ "$line" != "origin/HEAD -> origin/master" ]
then
inMaster=$(git branch master --contains $line)
if [ "$inMaster" = " master" ] || [ "$inMaster" = "* master" ]
then
branchName=${line#origin/}
echo "$inMaster"