This file contains hidden or 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
| /** | |
| * Created by cristipopovici on 12/18/13. | |
| */ | |
| trait LifeCycle { | |
| def startup(): Unit | |
| def shutdown(): Unit | |
| } |
This file contains hidden or 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
| trait M[T] { | |
| def plus(x:T,y:T): T | |
| def zero: T | |
| } | |
| implicit object IntM extends M[Int] { | |
| def plus(x:Int, y:Int) = x + y | |
| def zero = 0; | |
| } |
This file contains hidden or 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 controllers | |
| import play.api._ | |
| import play.api.mvc._ | |
| import play.api.libs.json._ | |
| // you need this import to have combinators | |
| import play.api.libs.functional.syntax._ | |
| object Application extends Controller { | |
This file contains hidden or 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
| OpenTsDb Usefull queries | |
| * show all metrics | |
| GET /suggest?type=metrics | |
| * put datapoint | |
| PUT /api/put | |
| { | |
| "timestamp" : 1391952958, |
This file contains hidden or 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
| var power = function (base, exponent) { | |
| if (exponent === 1) { | |
| return base; | |
| } | |
| return base * power(base, exponent - 1); | |
| }; | |
| var fibb = function (n) { | |
| if (n === 0 || n === 1) { | |
| return 1; |
This file contains hidden or 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 play.api.mvc.{Results, SimpleResult, RequestHeader, Filter} | |
| import scala.concurrent.Future | |
| case class BasicAuthFilter() extends Filter { | |
| private[this] val username = "joe" | |
| private[this] val password = "secret" | |
| override def apply(f: (RequestHeader) => Future[SimpleResult])(rh: RequestHeader): Future[SimpleResult] = { | |
| rh.headers.get("Authorization").map { basicAuth => | |
| val (user, pass) = decodeBasicAuth(basicAuth) |
This file contains hidden or 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
| type BuildingStringMapper = Building => String | |
| val buildingCode = (b: Building) => b.getBuildingCode | |
| // works OK | |
| val buildingHeaders = Map[String, BuildingStringMapper]( | |
| "Building Code" -> buildingCode | |
| ) | |
| // does not work. Can I define function literals as inline map values?? | |
| val buildingHeaders = Map[String, BuildingStringMapper]( |
This file contains hidden or 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 quickSort(l:List[Int]):List[Int] = l match { | |
| case Nil => l | |
| case head :: tail => | |
| val (l,r) = tail.partition(_ < head) | |
| quickSort(l) ::: head :: quickSort(r) | |
| } |
This file contains hidden or 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 | |
| /** | |
| * Created by CristianPopovici on 9/29/2016. | |
| */ | |
| sealed trait List[+T] { | |
| @tailrec | |
| final def forEach(f:T => Unit): Unit = | |
| this match { |
This file contains hidden or 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 PdfReplace extends App { | |
| val pageNumberToReplace = 22 | |
| val sourcePathStr = "C:\\..." | |
| val destPathStr = "C:\\..." | |
| val pageToReplacePath = "C:\\" | |
| val sourceInput = new FileInputStream(new File(sourcePathStr)) | |
| val pageToReplaceInput = new FileInputStream(new File(pageToReplacePath)) |
OlderNewer