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
name := """test-rjs""" | |
version := "1.0-SNAPSHOT" | |
lazy val root = (project in file(".")).enablePlugins(PlayScala, SbtWeb) | |
scalaVersion := "2.11.1" | |
libraryDependencies ++= Seq( | |
jdbc, |
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 play.api.db.slick.DB | |
def allSamplesJson = Action { implicit request => | |
request.session.get("l").map { | |
case "i" => DB.withSession { implicit dbs => | |
val all = models.CodeSampleTable.allSamples() | |
Ok(Json.toJson(all)) | |
} | |
case _ => Unauthorized(unautStr) | |
}.getOrElse { |
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.concurrent.duration.Duration | |
import scala.concurrent.{ExecutionContext, Future} | |
import scala.reflect.ClassTag | |
import play.api.cache.CacheApi | |
object FutureCache { | |
def getOrElse[A](key: String, expiration: Duration = Duration.Inf)(f: => Future[A])(implicit cache: CacheApi, ct: ClassTag[A], executionContext: ExecutionContext): Future[A] = { | |
cache.get[A](key) match { | |
case Some(a) => Future.successful(a) | |
case _ => |
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
trait RateLimitingController { | |
this: Controller with ControllerHelpers => | |
// Abstract cache member | |
def cache: play.api.cache.CacheApi | |
// Function to check if current IP exceeds limit for request path | |
def checkRateLimit[A](implicit request: Request[A]): Boolean = { | |
val limit: Int = getConfigInt("ratelimit.limit") | |
val timeoutSecs: Int = getConfigInt("ratelimit.timeout") |
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 utils.caching | |
import scala.concurrent.duration.Duration | |
import scala.concurrent.{ExecutionContext, Future} | |
import scala.reflect.ClassTag | |
import play.api.cache.CacheApi | |
object FutureCache { | |
def getOrElse[A](key: String, expiration: Duration = Duration.Inf)(orElse : => Future[A])(implicit cache: CacheApi, ct: ClassTag[A], executionContext: ExecutionContext): Future[A] = { | |
cache.get[A](key) match { |
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
2744470 / 2053936 | |
text/RG-50.030.0001_trs_en.txt Warsaw 0.009380871 | |
text/RG-50.030.0001_trs_en.txt 19 0.002966492 | |
text/RG-50.030.0001_trs_en.txt Varka 0.0020976267 | |
text/RG-50.030.0001_trs_en.txt Gesha 0.0020976267 | |
text/RG-50.030.0001_trs_en.txt Slovakia 0.0020976267 | |
text/RG-50.030.0001_trs_en.txt Amy 0.0020976267 | |
text/RG-50.030.0001_trs_en.txt wasa 0.0020976267 | |
text/RG-50.030.0001_trs_en.txt upa 0.0020976267 | |
text/RG-50.030.0002_trs_en.txt Lodz 0.006228336 |
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
# First, log into the EHRI staging server | |
# Actually open a bunch of shells | |
# In one of them, tail the following file, which will give us some information | |
# about what goes wrong when something inevitably goes wrong | |
tail -f /opt/webapps/neo4j-version/data/log/console.log | |
# Next, in another shell, copy the file(s) to be ingested to the server | |
# and place them in /opt/webapps/data/import-data/de/de-002409 | |
# (de-002409 is ITS's EHRI ID.) |
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 controllers; | |
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.CompletionStage; | |
import akka.actor.ActorRef; | |
import akka.actor.ActorSystem; | |
import akka.actor.Props; | |
import akka.actor.UntypedActor; | |
import com.google.inject.Inject; |
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
implicit def longMapReads[T](implicit r: Reads[T]): Reads[Map[Long, T]] = Reads[Map[Long, T]] { jv => | |
jv.validate[Map[String, T]].flatMap { obj => | |
obj.foldLeft[JsResult[Map[Long,T]]](JsSuccess(Map.empty)) { | |
case (JsSuccess(o, p), (k, v)) => | |
try { | |
JsSuccess(o + (k.toLong -> v)) | |
} catch { | |
case e: IllegalArgumentException => | |
val e = ValidationError(s"Value: '$k' cannot be converted to a Long") | |
JsError(p, e) |
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
#!/usr/bin/env python | |
import sys, requests | |
if len(sys.argv) < 1: | |
print("usage: scopecontent.py <url>") | |
sys.exit(1) | |
def scope_content(url): | |
r = requests.get(url, headers={"Authorization": "Bearer EHRI-Dev"}) |