Skip to content

Instantly share code, notes, and snippets.

View Hungsiro506's full-sized avatar

Hưng Vũ Hungsiro506

View GitHub Profile
next_xid = 1
active_xids = set()
records = []
def new_transaction():
global next_xid
next_xid += 1
active_xids.add(next_xid)
return Transaction(next_xid)
// Purpose:
// - Ensures that a resource is deterministically disposed of once it goes out of scope
// - Use this pattern when working with resources that should be closed or managed after use
//
// The benefit of this pattern is that it frees the developer from the responsibility of
// explicitly managing resources
import scala.io.Source
import java.io._
@Hungsiro506
Hungsiro506 / Redis TestApp
Created October 30, 2017 07:52 — forked from uromahn/ Redis TestApp
Jedis test with Redis Cluster
Title file
case class SomeEvent(value: Long)
val events = Source
.tick(0 seconds, 250 millis, "")
.zipWithIndex
.map { case (_, l) =>
SomeEvent(l)
}
val group = Flow[SomeEvent].groupedWithin(100, 500 millis) // +/- 2 events per group
@Hungsiro506
Hungsiro506 / HyperLogLogStoreUDAF.scala
Created June 13, 2017 05:33 — forked from MLnick/HyperLogLogStoreUDAF.scala
Experimenting with Spark SQL UDAF - HyperLogLog UDAF for distinct counts, that stores the actual HLL for each row to allow further aggregation
class HyperLogLogStoreUDAF extends UserDefinedAggregateFunction {
override def inputSchema = new StructType()
.add("stringInput", BinaryType)
override def update(buffer: MutableAggregationBuffer, input: Row) = {
// This input Row only has a single column storing the input value in String (or other Binary data).
// We only update the buffer when the input value is not null.
if (!input.isNullAt(0)) {
if (buffer.isNullAt(0)) {