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 io.github.izmailoff | |
import akka.actor._ | |
import akka.actor.SupervisorStrategy.{Stop, Restart} | |
import scala.concurrent.duration._ | |
class Supervisor extends Actor { | |
override def preStart = | |
println("STARTED SUPERVISOR") |
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
// This is an example of how one can use MongoRecord and it's `meta` object MongoMetaRecord without | |
// using regular Scala singleton object. | |
// | |
// This way you can set Mongo DB connection identifier for each meta object and have multiple | |
// meta objects available. Usually you would not want to do that unless you use multiple databases | |
// in the same application. My motivation was that Spray unit tests would run concurrently with Akka | |
// ActorSystem and regular Lift dependency injection would not work because it's scope is ThreadLocal. | |
// | |
// Some more details here: | |
// https://groups.google.com/forum/#!topic/liftweb/5NfI9DxQ99Q |
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
// this is unfinished, but shows the idea | |
// It's an answer to: | |
// http://stackoverflow.com/questions/25028214/merging-scala-maps#comment38926797_25028214 | |
package com.izmailoff | |
class LazyMap[A, B, C, D](x: Map[A, B], y: Map[A, C], f: (Option[B], Option[C]) => Option[D]) | |
extends Map[A, D] { | |
def get(key: A): Option[D] = |
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
// This was run in Scala REPL: | |
scala> trait A { | |
| println("CREATED A") | |
| def n: String | |
| } | |
defined trait A | |
scala> |
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
// Liquibase SBT dependency is something like this: | |
// "org.liquibase" % "liquibase-core" % "3.0.5" | |
import java.sql.Connection | |
import liquibase.Liquibase | |
import liquibase.resource.FileSystemResourceAccessor | |
import liquibase.database.DatabaseFactory | |
import liquibase.database.jvm.JdbcConnection | |
import liquibase.resource.ClassLoaderResourceAccessor | |
import net.liftweb.common.Logger |
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 FormFieldsToJson extends App { | |
if(args.length != 1) { | |
println("Usage: FormDataParser <form data>") | |
System.exit(1) | |
} | |
val fieldDelimiter = "----" | |
val fieldNLines = 3 | |
val data = args(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
#!/bin/bash | |
# Keep calling some API every second and check that it's working (status 200). | |
# If any other HTTP status is received print an error. | |
# | |
# Useful for observing server downtime and such. | |
while true | |
do | |
status="$(curl -sL -w '%{http_code}' https://api.com/something -o /dev/null)" |
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
#!/bin/sh | |
exec scala "$0" "$@" | |
!# | |
import scala.io.Source | |
val url = "https://work.caltech.edu/lectures.html" | |
val html = Source fromURL(url) mkString | |
val href = """<a href="\s*(.+?)\s*">""".r | |
val links = (for (m <- href findAllMatchIn html) yield m group 1) toList |
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.concurrent._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.duration._ | |
def someFunction(a: Int, b: Int): Future[Int] = Future(a * b) | |
val args = Map( | |
(true, true) -> List((0,0), (0,1), (1,0), (1,1)), | |
(true, false) -> List((0,0), (1,0)), | |
(false, true) -> List((0,0), (0,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
object Stats { | |
type Observations = List[Double] | |
def mean(xs: Observations) = xs.sum / xs.size | |
def variance(xs: Observations) = { | |
val m = mean(xs) | |
xs.map{ x => math.pow(x - m, 2) }.sum / (xs.size - 1) | |
} |