Skip to content

Instantly share code, notes, and snippets.

trait EnvArgs extends FieldArgs {
@Required
var env = _
}
trait SQLArgs extends FieldArgs {
@Required
var url: String = _
@Required
var driver: String = _
@Required
var user: String = _
@Required
var password: String = _
}
import com.quantifind.sumac.{FieldArgs, ArgMain}
class RangeArgs extends FieldArgs {
var from: Int = 0
var to: Option[Int] = None
@FileExists
var file: File = _
}
class FileRange extends ArgMain[RangeArgs] {
def main(args: RangeArgs) {
val lines = scala.io.Source.fromFile(args.file).getLines
import com.quantifind.sumac.ArgMain
object HelloMain extends ArgMain[HelloArgs] {
def main(args: HelloArgs) {
println(s"Hello ${args.message}")
}
}
import com.quantifind.sumac.FieldArgs
class HelloArgs extends FieldArgs {
var message: String = "world"
}
class MyArgs extends FieldArgs with ConfigArgs {
override val configPrefix = "com.example.config"
@Required
var env: String = "dev"
var timeout: Option[Duration] = None
@Required
var db1: SQLArgs = new SQLArgs {}
@Required
var db2: SQLArgs = new SQLArgs {}
@Mortimerp9
Mortimerp9 / RefreshEvery.scala
Created May 2, 2014 21:07
Sort of a lazy val, but that refreshes itselfs every so often; or a temporary cache for a value T, will be refreshed at a minimun at the specified interval.
import com.twitter.util.{Duration, Time}
/**
* Sort of a lazy val, but that refreshes itselfs every so often; or a temporary cache for a value T,
* will be refreshed at a minimun at the specified interval.
* In practice, the refresh is done only when the value is accessed, so there are no guarantees
* to when it will actually be refreshed. You can just be sure that it won't be refreshed if two calls
* are made within `every`.
*/
class RefreshEvery[T](every: Duration)(refresh: => T) {
@Mortimerp9
Mortimerp9 / keybase.md
Created March 18, 2014 13:05
Keybase proof

Keybase proof

I hereby claim:

  • I am Mortimerp9 on github.
  • I am mortimer (https://keybase.io/mortimer) on keybase.
  • I have a public key whose fingerprint is 67A4 6F85 0705 0682 E304 956F B74C 491C 79F0 062D

To claim this, I am signing this object:

@Mortimerp9
Mortimerp9 / gist:9097361
Created February 19, 2014 17:46
(_<o.O) java cat.
public class Bar {
class O {
int O = 0;
}
int _ = 10;
O o = new O();
Boolean foo = (_<o.O);
@Mortimerp9
Mortimerp9 / HelloAkka.scala
Created January 31, 2014 11:48
TypedActorRef for akka using unboxed tagged types. This does not type the messages, it only allows you to require a particular type of actor when taking `ActorRef` as parameter. This is useful when you are passing actors reference around and you are sure of the implementation type of this actor. It makes reading complex Akka code a bit easier, b…
//Hello world from https://github.com/typesafehub/activator-hello-akka
import TypedActorRef._
import akka.actor.{ActorRef, ActorSystem, Props, Actor}
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
val system = ActorSystem("helloakka")