Skip to content

Instantly share code, notes, and snippets.

View johanprinsloo's full-sized avatar

Johan Prinsloo johanprinsloo

View GitHub Profile
@kerryrodden
kerryrodden / .block
Last active September 15, 2025 05:59
Sequences sunburst
license: apache-2.0
@helena
helena / TopAByBJob.scala
Last active December 20, 2015 21:08
TopAByBJob is a daily job which pulls .pailfile data with pathing by date/time and type from S3. Data must be grouped by A and B, sorted by B, then only written for the top n (keep) for each A, based on B (count), descending. I wrote all of the base jobs such as DailyJobWithKeep (for use by daily jobs needing a 'keepN') extends DailyJob extends …
class TopAByBJob(args: Args) extends DailyJobWithKeep(args, classOf[ProtobufTypeForS3PathPartition]) with TypeAFilters {
PailSource.source[FooProtobuf](rootpath, structure, directories).read
.mapTo('pailItem -> ('b, 'a)) { e: FooProtobuf ⇒ e.b -> calculateA(e) }
.filter('a) { n: String ⇒ n.nonEmpty }
.groupBy(('b, 'a)) { _.size('count) }
.groupBy('b) { _.sortedReverseTake[(Long, String, String)](('count, 'b, 'a) -> 'tcount, keep) }
.flatMapTo('tcount -> ('count, 'b, 'a)) { t: (List[(Long, String, String)]) ⇒ t }
.write(Tsv(outputdir))
}
@mpilquist
mpilquist / OsgiConfigFactory.scala
Created July 15, 2013 18:07
Automatic discovery of reference.conf files in OSGi
import scala.collection.JavaConverters._
import java.net.URL
import java.util.Enumeration
import com.typesafe.config._
import org.osgi.framework.Bundle
import org.osgi.framework.wiring._
object OsgiConfigFactory {
/* A better way to tag types?
*
* 1) object Time: here we are distinguishing between different uses of a Long,
* yet there is no boxing whatsoever.
*
* main calls start: ()J
* main calls timed: (Function0, J)
* Function0 gives up the result: ()J
* timed calls now: ()J
* timed calls elapsed$extension: (JJ)J
@gre
gre / deploy.sh
Last active October 8, 2021 00:33
Super-small scripts for easy PlayFramework deployment
#!/bin/bash
REMOTE=play@SERVER_IP
REMOTE_APP=/home/play/PROJECT_NAME/
sbt stage || exit 1;
rsync -va target/ $REMOTE:$REMOTE_APP/target;
ssh $REMOTE "cd $REMOTE_APP; ./stop.sh";
ssh $REMOTE "cd $REMOTE_APP; ./start.sh";
@nikolavp
nikolavp / gist:5488026
Created April 30, 2013 10:59
Cassandra upstart job
description "Cassandra is a distributed (peer-to-peer) system for the management and storage of structured data."
author "nikola.petrov@ontotext.com"
start on filesystem
stop on runlevel[016]
@drstevens
drstevens / OptionMap.scala
Last active December 15, 2015 19:49
This example demonstrates benefits of using fold/cata instead of map and getOrElse on Option[T]. There are, of course, occasions when pattern matching is preferable as well.
Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_15).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val opt: Option[Int] = Some(10)
opt: Option[Int] = Some(10)
scala> val typeCheckFail = opt map (_ + "2") getOrElse (3)
typeCheckFail: Any = 102
@gecemmo
gecemmo / metrics-in-spray
Last active December 14, 2015 19:19
Code for potential usage in spray for metrics
import spray.json._
import spray.http.HttpBody
import spray.httpx.marshalling._
import spray.httpx.unmarshalling._
import spray.http.MediaTypes._
import spray.routing.directives._
import spray.routing._
import spray.http._
import spray.json.DefaultJsonProtocol
import spray.httpx.SprayJsonSupport
@patriknw
patriknw / ClusterRegistrySpec.scala
Last active May 28, 2019 10:58
Example of how to implement a simple cluster wide actor registry.
/**
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.contrib.pattern
import language.postfixOps
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory
import akka.actor.Actor
@milessabin
milessabin / gist:4719811
Created February 6, 2013 02:50
Sneak preview for NEScala
scala> def foo[A, B, C](a: SNat[A], b: SNat[B], c: SNat[C])(implicit ssum: SSum[A, B, C]) = ssum
foo: [A, B, C](a: shapeless.SNat[A], b: shapeless.SNat[B], c: shapeless.SNat[C])(implicit ssum: shapeless.SSum[A,B,C])shapeless.SSum[A,B,C]
scala> foo(2, 3, 5)
res0: shapeless.SSum[Int(2),Int(3),Int(5)] = $anon$1@53d76e96
scala> foo(2, 3, 7)
<console>:15: error: could not find implicit value for parameter ssum: shapeless.SSum[Int(2),Int(3),Int(7)]
foo(2, 3, 7)
^