Skip to content

Instantly share code, notes, and snippets.

View isterin's full-sized avatar

Ilya Sterin isterin

View GitHub Profile
@isterin
isterin / pattern.scala
Last active September 15, 2015 18:37
Scala pattern matching
import java.util
import java.util.{Map => JMap, List => JList}
import scala.reflect.runtime.universe._
object PatternMatching extends App {
val o: JMap[String, Any] = new util.HashMap[String, Any]()
val o2: JList[JMap[String, Any]] = new util.ArrayList[JMap[String, Any]]()
@isterin
isterin / node_verify.js
Last active August 29, 2015 14:21
CoreTechCorp Advanced Auth Verification
app.post('/verify', function(req, res) {
var digest = crypto.createHmac('sha1', '--- priv key----').update("---pub key---").digest(encoding="base64");
if (req.body.sig_verify == digest) {
res.redirect('/demo/success.html')
}
else {
res.redirect("/demo/failure.html")
}
});
def find[A](s:Seq[A], e:A => Boolean):Option[A] = {
s match {
case Seq(h,t) if e(h) => Some(h)
case Nil => None
case _ => find(s.tail, e)
}
}
@isterin
isterin / VoltDbClientProvider.scala
Last active August 29, 2015 14:03
VoltDB Client Provider for Guice
class VoltDbClientProvider @Inject()(settings: AppSettings) extends Provider[Client] {
val cf = settings.getSection("voltdb")
val nodes = cf.getConfigList("nodes").toList
var client: Option[Client] = None
private val executor = Executors.newCachedThreadPool(new ThreadFactory() {
def newThread(runnable: Runnable): Thread = {
val thread = new Thread(runnable, "Retry Connection")
thread.setDaemon(true)
@isterin
isterin / jettyexception
Created July 2, 2014 20:16
Jetty/Scalatra exception
20:06:26.509 [qtp1697386933-197] ERROR c.c.c.r.a.resources.ResultsResource - Parsing the request body failed, because:
org.eclipse.jetty.io.EofException: null
at org.eclipse.jetty.server.HttpInput$3.noContent(HttpInput.java:473) ~[jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
at org.eclipse.jetty.server.HttpInput.read(HttpInput.java:124) ~[jetty-server-9.2.1.v20140609.jar:9.2.1.v20140609]
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) ~[na:1.8.0_05]
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) ~[na:1.8.0_05]
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) ~[na:1.8.0_05]
at java.io.InputStreamReader.read(InputStreamReader.java:184) ~[na:1.8.0_05]
at java.io.BufferedReader.read1(BufferedReader.java:210) ~[na:1.8.0_05]
at java.io.BufferedReader.read(BufferedReader.java:286) ~[na:1.8.0_05]
abstract class BaseResource
extends ScalatraServlet with FutureSupport with JacksonJsonSupport with SwaggerSupport with Imports {
override protected val applicationName = Some("messaging-api")
protected def applicationDescription = "Messaging Services API"
protected implicit val defaultTimeout = Timeout(5 seconds)
override val jsonpCallbackParameterNames: Iterable[String] = Some("callback")
@isterin
isterin / DDL
Created March 28, 2014 16:54
Voltdb problem
CREATE TABLE results (
event_id BIGINT NOT NULL,
race_id BIGINT NOT NULL,
bracket_id BIGINT NOT NULL,
interval_id BIGINT NOT NULL,
entry_id BIGINT NOT NULL,
iv_time_millis BIGINT NOT NULL,
iv_gun_time_millis BIGINT NOT NULL,
bib VARCHAR(15),
pace VARCHAR(23),
@isterin
isterin / Runner
Created March 11, 2014 17:19
Scalatra jetty 9.1.3 issue with standalone deployment
object Runner {
// this is my entry object as specified in sbt project definition
def main(args: Array[String]) {
val port = if (System.getenv("PORT") != null) System.getenv("PORT").toInt else 8080
val server = new Server(port)
val context = new WebAppContext()
context setContextPath "/"
context.setResourceBase("src/main/webapp")
@isterin
isterin / BAD REQUEST
Last active August 29, 2015 13:57
Scalatra
new AsyncResult {
val is = Future {
try {
val results = searchService.findEntry(eventId.toLong, term, limit)
Ok("DUDE")
}
catch {
case e:Throwable => e.printStackTrace(); Ok(e.getMessage)
}
}
@isterin
isterin / user.js
Last active January 2, 2016 15:29
/*
* /routes/user.js
*/
/*
* /users -> list
* /user/:id -> get
* /users/:id -> get
*
*/