Skip to content

Instantly share code, notes, and snippets.

package kafka.perf
import java.util.concurrent.{CountDownLatch, Executors}
import java.util.concurrent.atomic.AtomicLong
import kafka.producer._
import org.apache.log4j.Logger
import kafka.message.{CompressionCodec, Message}
import java.text.SimpleDateFormat
import kafka.serializer._
import java.util._
@lazyval
lazyval / JavaApi.java
Last active August 29, 2015 14:01
toLong for java string
package com.github.lazyval;
public class JavaApi {
public static String foo() {
return "123";
}
}
@lazyval
lazyval / .gitignore
Last active August 29, 2015 14:01
uaagent compilation issues
# SBT
boot/
lib_managed/
target/
.history
# Eclipse
.cache
.classpath
.project
@lazyval
lazyval / PaintingFence.scala
Created July 22, 2014 20:37
optimization of fence painting
import scala.util.control.TailCalls._
def solve(l: List[(Int, Int)]): Int = {
def go(from: Int, to: Int, prevHeight: Int): TailRec[Int] = {
val max = to - from
val currHeight = l.slice(from, to).minBy(_._1)._1
val hStrokes = currHeight - prevHeight
// not sure it's legal, but in practice it seems that you always have only one item here
val List(split) = l.slice(from, to).filter(_._1 - currHeight == 0).map(_._2)
val indices: List[Int] = from :: split :: split + 1 :: to :: Nil
@lazyval
lazyval / count_files.bash
Created September 2, 2014 13:44
Utility that can be used to count files in a given directory
#!/bin/bash
countFiles () {
# call the recursive function, throw away stdout and send stderr to stdout
# then sort numerically
countFiles_rec "$1" 2>&1 >/dev/null | sort -nr
}
countFiles_rec () {
local -i nfiles
@lazyval
lazyval / pid.py
Last active August 29, 2015 14:20
PID controller made in python, see also http://www.csimn.com/CSI_pages/PIDforDummies.html
kp = 1.2
ki = 0.9
kd = 0.3
set_point = 50
prev_error = 0
cumulative_moving_average = 0
iteration = 0
def make_iteration(measured):
class Bar<B> {}
import kafka.api.FetchRequestBuilder
import kafka.cluster.Broker
import kafka.javaapi.{FetchRequest, TopicMetadataRequest}
import kafka.javaapi.consumer.SimpleConsumer
import kafka.message.Message
import scala.collection.JavaConverters._
class Reader(anyBroker: String, topic: String, partition: Int, offset: Int) {
val ClientId = "kafka-fetch-size-client"
@lazyval
lazyval / Emitter.java
Created June 23, 2016 08:42
Map Reduce 101
/**
* Collects results of map phase, persists it to temporary storage
* results with same key (globally) can be accessed together
*/
interface Emitter<M> {
void emit(String key, M result);
}
@lazyval
lazyval / HelloWorld.scala
Created July 19, 2017 08:05
hello scala!
object Hello extends App {
println("hello scala!")
}