Skip to content

Instantly share code, notes, and snippets.

View alexy's full-sized avatar

Alexy Khrabrov alexy

View GitHub Profile
278270
> runMain ammonite.repl.Repl
[info] Running ammonite.repl.Repl
Loading Ammonite Repl...
@ load.ivy("com.chuusai" %% "shapeless" % "2.1.0")
@ import shapeless._
import shapeless._
@ 1 :: "lol" :: List(1, 2, 3) :: HNil
package org.setup.syslog.plain;
import javafx.util.Pair;
import org.joda.time.DateTime;
import org.joda.time.format.*;
import scala.collection.mutable.ArrayBuilder;
import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
import java.util.regex.Matcher;
@alexy
alexy / Build.scala
Created May 17, 2012 05:36
copy-dependencies
import sbt._
import Keys._
object MyBuild extends Build {
lazy val copyDependencies = TaskKey[Unit]("copy-dependencies")
def copyDepTask = copyDependencies <<= (update, crossTarget, scalaVersion) map {
(updateReport, out, scalaVer) =>
updateReport.allFiles foreach { srcPath =>
@alexy
alexy / HelloKitty.scala
Created April 29, 2012 19:36
joinLeft differs from joinRight, both are larger than expected, ++ causes NPE
object PairsNews {
type RankerPairs = DList[(Long, Iterable[(Long, Long))]
def main(a: Array[String]) = withHadoopArgs(a) { case args =>
case object o extends ScallopConf(args) {
val date = opt[String]("date", descr = "generate pairs for new regs after that date")
val allRankerPairsBase = opt[String]("base", descr = "directory where all ranker-pairs are stored, per day",
default = Some("fatpipe/generated"))
@alexy
alexy / Common.scala
Created April 20, 2012 05:33
compose method and function
def readUserScores(fileName: String): List[UserScore] = {
val serocs = ((Nil: List[UserScore]) /:
io.Source.fromFile(fileName).getLines()
// .map(_.split("\t")).map(array2Pair(_))
// .map(((x:String) => x.split("\t")) andThen array2Pair)
// .map(((_:String).split("\t")) andThen array2Pair)
.map( array2Pair _ compose (_.split("\t")))
) { case (l, e) => e :: l }
serocs.reverse
@alexy
alexy / Common.scala
Created April 20, 2012 04:42
composing method and function
def array2Pair(a: Array[String]): UserScore = {
if (a.size != 2) throw new NotArray2
(a(0).toLong, a(1).toDouble)
}
io.Source.fromFile(fileName).getLines().map(_.split("\t")).map(array2Pair(_))
@alexy
alexy / minscalaactors.scala
Created April 12, 2012 21:37 — forked from viktorklang/minscalaactors.scala
Minimalist Scala Actors
©2012 Viktor Klang
object Actor {
import java.util.concurrent.{ConcurrentLinkedQueue, Executor}
import java.util.concurrent.atomic.{AtomicBoolean}
type Behavior = Any => Effect
sealed trait Effect { def getOrElse(old: Behavior): Behavior }
case object Stay extends Effect { def getOrElse(old: Behavior): Behavior = old }
case class Become(like: Behavior) extends Effect { def getOrElse(old: Behavior): Behavior = like }
@alexy
alexy / Mongo.scala
Created April 11, 2012 00:56
finding and updating a mongo object with casbah, clueless edition
def putStat[T](id: String, k: String, v: T, coll: MongoCollection = ms): Unit = {
Console.err.println("putting mongo stat: _id->%s, %s->%s".format(id,k,v))
val newVal = Map(k -> v)
coll.findOneByID(id) match {
case Some(obj) => coll.update(obj, obj + (k -> v))
case _ => coll.insert(MongoDBObject("_id"->id, k->v))
}
}
@alexy
alexy / HelloKitty.scala
Created April 9, 2012 23:58
reusing Scoobi intermediates
val soiBy1: DList[Edge] =
if (o.fromKey()) {
val soiByK: DList[String] = convertKeyFromSequenceFile(o.soiByFile())
soiByK map { k => val c = k.split(","); (c(4).toLong, c(1).toLong) }
}
else fromDelimitedTextFile(o.soiByFile(),o.sep) {
case Long(u) :: Long(v) :: _ => (u,v)
}
val soiBy2: DList[Edge] = if (o.flip()) soiBy1 ++ soiBy1.map(_.swap) else soiBy1