Skip to content

Instantly share code, notes, and snippets.

Avatar

Paulius Imbrasas CremboC

View GitHub Profile
View getHex.java
public class BaseConversion {
private static final char[] HEXES = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
public static String getHex(long value) {
final StringBuilder hex = new StringBuilder(16);
byte[] result = new byte[8];
for (int i = 7; i >= 0; i--) {
result[i] = (byte) (value & 0xffL);
@CremboC
CremboC / impl.scala
Created Oct 17, 2019
fs2.Stream.mergeWith
View impl.scala
import cats.data.Ior
import cats.Monad
import cats.syntax.all._
import fs2.{Pipe, Pull, Stream}
def mergeWith[F[_]: Monad, A, B, C](
ls: Stream[F, A],
rs: Stream[F, B],
)(
ok: (A, B) => Boolean,
View hll-include-todays.sql
WITH base_users AS ( ... ),
country_users AS ( ... ),
todays_users AS (
SELECT
HLL_COUNT.INIT(user_id, 19) as sketch
FROM pageview_events
WHERE
_PARTITIONTIME = TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY)
country = ...
)
View freezing_test.scala
it("should handle rebalance with multiple consumers") {
withKafka { (config, topic) =>
createCustomTopic(topic, partitions = 300)
val maxP1 = 10000
val maxP2 = 20000
val produced1 = (0 until maxP1).map(n => s"key-$n" -> s"value->$n")
val produced2 = (maxP1 until maxP2).map(n => s"key-$n" -> s"value->$n")
val producedTotal = produced1.size.toLong + produced2.size.toLong
val mkConsumer = (id: String, queue: Queue[IO, CommittableMessage[IO, String, String]]) =>
View brokentest.scala
it("should handle rebalance") {
withKafka { (config, topic) =>
createCustomTopic(topic, partitions = 300)
val maxP1 = 10000
val maxP2 = 20000
val produced1 = (0 until maxP1).map(n => s"key-$n" -> s"value->$n")
val produced2 = (maxP1 until maxP2).map(n => s"key-$n" -> s"value->$n")
val producedTotal = produced1.size.toLong + produced2.size.toLong
val consumer1 = (queue: Queue[IO, CommittableMessage[IO, String, String]]) =>
View ioPar.scala
import $ivy.`org.typelevel::cats-core:1.0.1`
import $ivy.`org.typelevel::cats-effect:0.9`
import cats.effect.IO
import cats.implicits._
def f(s: String) = IO { Thread.sleep(1000); s }
def timeIO[A](f: IO[A]): A = {
val start = System.nanoTime
val result = f.unsafeRunSync()
View bfq.hs
module Main where
import System.Environment
import qualified RotatingQ as Q
import RotatingQ (Queue)
breadthFirst :: (a -> [a]) -> a -> [a]
breadthFirst b r = bf b [r]
bf :: (a -> [a]) -> [a] -> [a]
View latex.json
{
"draw_centered": true,
"line_numbers": false,
"highlight_line": false,
"gutter": false,
"spell_check": true,
"dictionary": "Packages/Language - English/en_GB.dic",
"translate_tabs_to_spaces": true,
"caret_style": "smooth",
"line_padding_top": 1,
View error.scala
Error:scalac: Error: the compiler instance must have -Yrangepos enabled
java.lang.RuntimeException: the compiler instance must have -Yrangepos enabled
at scala.sys.package$.error(package.scala:27)
at scala.meta.internal.scalahost.v1.online.DatabaseOps$XtensionCompilationUnitDatabase.$anonfun$toDatabase$1(DatabaseOps.scala:20)
at scala.meta.internal.scalahost.ReflectionToolkit$CompilationUnitCache.$anonfun$getOrElse$5(ReflectionToolkit.scala:92)
at scala.Option.getOrElse(Option.scala:121)
View typeclass.scala
trait Parser[A, B] {
def parse(in: A): B
}
object Parser {
implicit val intToStringParser: Parser[Int, String] =
(in: Int) => {
in.toString
}