Skip to content

Instantly share code, notes, and snippets.

View hipjim's full-sized avatar
🌴
On vacation

Cristian Popovici hipjim

🌴
On vacation
  • Timisoara
View GitHub Profile
@hipjim
hipjim / scala-basic-arithmetic.scala
Created January 28, 2019 10:52
Scala simple DSL - basic arithmetic ops
object Test extends App {
trait CanAdd[T] {
def plus(a:T, b:T):T
def minus(a:T, b:T):T
def or(a:T, b:T):T
def devide(a:T, b:T):T
}
@hipjim
hipjim / patients_api.md
Last active January 23, 2018 07:57
HCI

GET all patients:

GET https://uvt-hci-lab.herokuapp.com/patients.json

CREATE patient:

POST https://uvt-hci-lab.herokuapp.com/patients.json

{"firstname":"Test", "lastname":"User", "age":44, "phone":"0788122321"}
@hipjim
hipjim / pdfReplacePage.scala
Last active October 4, 2016 16:02
PdfReplacePage.scala
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))
@hipjim
hipjim / list.scala
Last active October 3, 2016 14:03
scala list impl
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 {
@hipjim
hipjim / quicksort.scala
Created March 25, 2016 15:31
scala quicksort
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)
}
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](
@hipjim
hipjim / gist:6803401b23aa0a9b7444
Created June 19, 2014 20:01
play framework basic auth filter
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)
@hipjim
hipjim / gist:10262758
Last active August 29, 2015 13:58
recursive js
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;
@hipjim
hipjim / gist:8899607
Last active August 29, 2015 13:56
OpenTsdb utils
OpenTsDb Usefull queries
* show all metrics
GET /suggest?type=metrics
* put datapoint
PUT /api/put
{
"timestamp" : 1391952958,
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 {