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
val phones = List("91125426", "97 625 992", "911", "9761") | |
def isConsistent(pl: List[String]) = { | |
val sorted = pl.map(_.replaceAll(" ", "").replaceAll("-","")).sorted | |
sorted.tail.foldLeft((true, sorted.head)){ | |
case (bPrev, str) => | |
(bPrev._1 && !str.startsWith(bPrev._2), str) | |
}._1 | |
} | |
isConsistent(phones) |
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
def takeWhileR[A](s: Stream[A], f: A => Boolean): Stream[A] = | |
s.foldRight(Stream[A]())((h, t) => | |
if (f(h)) Stream(h) #::: t | |
else Stream.apply()) | |
def takeWhileL[A](s: Stream[A], f: A => Boolean): Stream[A] = | |
s.foldLeft(Stream[A]())((t, h) => | |
if (f(h)) Stream(h) #::: t | |
else Stream.apply()) |
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 snippet | |
/** | |
* Created by walidus on 27/06/17. How to override the implicit val with c? | |
*/ | |
object ImplicitTest extends App{ | |
implicit val overrider = MyClass.c // works | |
Util.print() | |
} | |
object Util { |
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
byobu new -d -s $$ && tmux send -t $$ 'sbt -mem 1600 run' ENTER |
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
Replace all numbers with that number of '?': | |
java like: | |
import java.util.regex.Pattern | |
val NKasString = "?" | |
val p = Pattern.compile("[0-9]+") | |
val m = p.matcher("\"a2a12a2\"") | |
val sb = new StringBuffer() | |
while (m.find()) { |
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 sys.process._ | |
import java.time.LocalDateTime | |
object SendMailMain { | |
def main(args: Array[String]) { | |
val start = LocalDateTime.now() | |
(1 to 1000).par.foreach { i => | |
print(s"$i ") | |
val out = s"echo anything $i" #| s"sendmail 123456789@[192.168.2.118]" !; |
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.annotation.tailrec | |
import scala.collection.JavaConversions._ | |
object Solution { | |
def solutionShortest(A: Array[Int]): Int = { | |
// fake from https://github.com/khatwaniNikhil/codility-scala/blob/master/src/com/codility/lesson1/TapeEquilibrium.scala | |
val sumAccum = A.scanLeft(0L)(_ + _).tail | |
(1 to A.size - 1).map(p => | |
scala.math.abs( |
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
// generate cyclic sending mail wiht rotation on chosen data | |
private def generateMailsSending(sentmails: Meter): Cancellable = { | |
import sys.process._ | |
val getNextHeaderSet: () => ClientHeaders = { | |
def b(): Stream[ClientHeaders] = headers.toStream #::: b | |
var cyclicIterator: Stream[ClientHeaders] = b() | |
() => { | |
val tail = cyclicIterator.tail |
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
// cancel sheduler and cloase file as one cancelable | |
private def fileLogger(): Cancellable with Object {def cancel(): Boolean; def isCancelled: Boolean} = { | |
val w = new BufferedWriter(new FileWriter( | |
s"../metrics_${TcpUtil.firstPartFromIp}_${numberOfClients}_${LocalTime.now()}.dat")) | |
val scheduled = context.system.scheduler.schedule(Config.STAT_PROBE_DURATION, Config.STAT_PROBE_DURATION) { | |
w.write( LineLog.toFileString(LocalTime.now(), | |
beats.getCount, fails.getCount, closings.getCount, receives.getCount, reconnects.getCount)+"\n") | |
w.flush() | |
} |
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.nio.file.Paths | |
val pwd = Paths.get(".").toAbsolutePath().normalize().toString() |
NewerOlder