Skip to content

Instantly share code, notes, and snippets.

// было
val best = found.foldLeft(DoerAvailability(null, 0, null)) { (best, cur) ⇒
if (best.availability > cur.availability) best
else cur
}
// стало
val best = found.reduce { (best, cur) ⇒
if (best.availability > cur.availability) best
// было
lastCheckinNode match {
case Some(node) ⇒ {
if (node == route.routeTemplate.fromNode) {
workload match {
case 0 ⇒ 10
case x if x > 0 ⇒ 0
case x ⇒ 6 - x
}
} else {
// initiator
// send synced message
SimpleSync(articleTerminator, TerminateArticle(1L, 1)) onSucces {
// sync ok, article successfully removed
} onFailure {
// sync fail
}
@kulikov
kulikov / gist:3141627
Created July 19, 2012 08:42
Dead horse theory

Dead horse

  1. ​Купить более мощный кнут.
  2. Сменить наездника.
  3. Говорить: «А мы ​всегда так скачем — на дохлых лошадях».
  4. Создать комитет по изучению ​лошади.
  5. Посетить другие компании, чтобы узнать их опыт скачек на ​дохлых лошадях.
  6. Начать разрабатывать стандарты езды на мертвых ​лошадях.
  7. Создать специальную команду из сильных специалистов для ​оживления лошади.
  8. Создать курсы для персонала по езде на дохлых ​лошадях.
Continue(otherService ? "my message") onSuccess {
case r ⇒ println("Yahhooo! onSuccess: " + r)
} onFailure {
case e ⇒ println("Fail: " + e)
}
otherService ? "my message" continueSuccess {
case r ⇒ println("Yahhooo! onSuccess: " + r)
@kulikov
kulikov / gist:3596468
Last active October 9, 2015 23:38
akka: execute future callbacks in current actor thread
package com.libitec.sce.util.actor
import akka.actor.{ActorRef, Actor}
import akka.dispatch.Future
/**
* Message wrapper
*/
sealed protected case class ContinuationMessageWrapper[T](message: T, handler: PartialFunction[T, Unit])
private def useRedis[T](handler: (Jedis) ⇒ T): T = {
val jedis = redisPool.getResource
try {
handler(jedis)
} finally {
redisPool.returnResource(jedis)
}
}
/**
* Finds acceptable route or creates a new route from possible templates to the given neighbour node
* @since 07.09.12 18:32
* @author kulikov
*/
def returnRouteTo(node: NodeInfo, need: NeedInfo) {
val routesToTargetNode = outgoingRoutes filter (_._2.routeTemplate.toNode == node)
// find scheduled route, if not exists - find instant route
// if has't ready routes - create and return new instant route
"/doer/:doerId/:sortBy": (doerId, sortBy) ->
"widget": "//mainLayout"
"params":
"doerId": doerId
"sortBy": sortBy
@kulikov
kulikov / gist:3721626
Created September 14, 2012 12:25
scala: Finds available doer for the route and send it back
/**
* Finds available doer for this route and send it back
*/
def findDoerForRoute(route: RouteInfo) {
val originalSender = sender
def doerNotFound(reason: Option[_] = None) {
self ! RegisterUnassignedRoute(route)
originalSender ! DoerNotFound(reason.orNull)
}