Skip to content

Instantly share code, notes, and snippets.

@fanatoly
fanatoly / Build.scala
Created June 5, 2014 14:19
multi-module-play
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "helloworld"
val appVersion = "1.0"
val appDependencies = Seq(
@fanatoly
fanatoly / LazyMap.scala
Created February 25, 2014 21:46
LazyMap ftw
package com.yieldmo.rtb.util
class LazyMap[A,B](delegate: Map[A,() => B]) extends scala.collection.immutable.Map[A,B]{
def get(key: A): Option[B] = delegate.get(key).map{ _() }
def iterator: Iterator[(A,B)] = delegate.iterator.map{ pair => (pair._1, pair._2()) }
def +[B1 >:B](kv: (A, B1)): Map[A, B1] = new LazyMap[A,B1](delegate + (kv._1 -> (() => kv._2)))
def -(key: A): Map[A, B] = new LazyMap[A,B](delegate - key)
}
@fanatoly
fanatoly / gist:6685873
Created September 24, 2013 14:48
tailrec
@tailrec
def fetchWithRetries(retries: Int): MultiFetchResponse = {
val resultMaybe = catching(classOf[IOException]) either {
simpleConsumer.multifetch(fetches : _*)
}
resultMaybe match{
case Left(e) =>
if(retries > 0) {
info("Unable to complete multifetch. Sleeping for %dms".format(config.fetcherBackoffMs), e)
Utils.swallow(logger.info, Thread.sleep(config.fetcherBackoffMs))
@fanatoly
fanatoly / gist:6071680
Created July 24, 2013 15:34
building a scalding megajar
import AssemblyKeys._
name := "traffic-jobs"
scalaVersion := "2.9.2"
description := "Traffic Analysis workflow"
libraryDependencies += "com.twitter" %% "scalding-core" % "0.8.6"
log_level :debug
log_location STDOUT
node_name 'fanatoly-mbp'
client_key '/Users/anatolyfayngelerin/dev/yieldmo/cfg/chef/repo/.chef/fanatoly-mbp.pem'
validation_client_name 'chef-validator'
validation_key '/Users/anatolyfayngelerin/dev/yieldmo/cfg/chef/repo/.chef/validation.pem'
chef_server_url 'http://chef.aws.in.yieldmo.com:4000'
syntax_check_cache_path '/Users/anatolyfayngelerin/dev/yieldmo/cfg/chef/repo/.chef/syntax_check_cache'
cookbook_path [ '/Users/anatolyfayngelerin/dev/yieldmo/cfg/chef/repo/cookbooks/' ]
knife[:aws_access_key_id] = 'REDACTED'