This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.spotify | |
import org.scalatest.prop.GeneratorDrivenPropertyChecks | |
import org.scalatest.{FlatSpec, Matchers} | |
class ExampleTest extends FlatSpec with Matchers with GeneratorDrivenPropertyChecks { | |
implicit override val generatorDrivenConfig = | |
PropertyCheckConfig(minSize = 100, maxSize = 200) | |
"strings" should "have same length when lowercased / uppercased" in { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Meter(val value: Double) extends AnyVal { | |
def toFeet = new Feet(value * 3.281) | |
} | |
class Feet(val value: Double) extends AnyVal { | |
def toMeter = new Meter(value / 3.281) | |
} | |
object Example { | |
def convert(meter: Meter): Feet = { | |
meter.toFeet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.MathContext | |
import shapeless.datatype.record._ | |
object Example extends App { | |
case class BigBoy(x: BigDecimal) | |
implicit def compareBigDecimals(x: BigDecimal, y: BigDecimal): Boolean = { | |
println("custom bigdecimal comparison invoked") | |
x.compareTo(y) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Hello extends App { | |
println("hello scala!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bar<B> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder