Skip to content

Instantly share code, notes, and snippets.

View jboner's full-sized avatar

Jonas Bonér jboner

View GitHub Profile
/**
* "Select" off the first future to be satisfied. Return this as a
* result, with the remainder of the Futures as a sequence.
*
* @param fs a scala.collection.Seq
*/
def select[A](fs: Seq[Future[A]])(implicit ec: ExecutionContext): Future[(Try[A], Seq[Future[A]])] = {
@tailrec
def stripe(p: Promise[(Try[A], Seq[Future[A]])],
heads: Seq[Future[A]],
@gkossakowski
gkossakowski / timeline.scala
Last active December 11, 2015 04:09
A helper script that generates little timeline out of data dumped by https://github.com/gkossakowski/scalac-aspects#typing-timings-typingtimingsaj
val input = Stream.continually(Console.readLine).takeWhile(_ != null)
val parsed = input.map(_.trim.split("\\s+").toSeq)
//parsed.take(100).foreach(println)
/** see CSS definition */
def color(hash: Int): String = {
val hashAbs = math.abs(hash)
val colors = Seq("primary", "secondary-a", "secondary-b", "complement")
@viktorklang
viktorklang / SerializedExecutionContext.scala
Created January 17, 2013 00:32
Wraps an ExecutionContext into a new ExecutionContext which will execute its tasks in sequence, always.
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.atomic.AtomicInteger
import scala.concurrent.ExecutionContext
import scala.util.control.NonFatal
import scala.annotation.tailrec
object SerializedExecutionContext {
def apply(batchSize: Int)(implicit context: ExecutionContext): ExecutionContext = {
require(batchSize > 0, s"SerializedExecutionContext.batchSize must be greater than 0 but was $batchSize")
new ConcurrentLinkedQueue[Runnable] with Runnable with ExecutionContext {
private final val on = new AtomicInteger(0)
@benjchristensen
benjchristensen / CallbackB.java
Last active June 3, 2025 15:11
CallbackB.java Example of using Callbacks for nested calls showing the incidental complexity that results and how eventually the asynchronous paths need to be synchronized together.
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
public class CallbackB {
/**
@viktorklang
viktorklang / NonblockingCache.scala
Last active December 11, 2015 23:38
Nonblocking cache
/*©2013 Viktor Klang*/
package akka.util
import java.util.concurrent.atomic.AtomicReference
import scala.concurrent.{ Future, ExecutionContext }
import scala.annotation.tailrec
class Cache[K, V](__ec: ExecutionContext, throughput: Int) extends AtomicReference[Map[K, V]] {
implicit val executor = SerializedSuspendableExecutionContext(throughput)(__ec)
@tailrec final def update(f: Map[K, V] ⇒ Map[K, V]): Map[K, V] = {
val v = get
val nv = f(v)
import scalaz._
import Scalaz._
import akka.actor.IO._
object IterateeZMonad {
implicit def iterateeZMonad[A] = new Monad[Iteratee] {
override def map[A, B](fa: Iteratee[A])(f: A ⇒ B): Iteratee[B] = fa map f
@pbailis
pbailis / list.md
Last active April 15, 2018 08:54
Quick and dirty (incomplete) list of interesting, mostly recent data warehousing/"big data" papers

A friend asked me for a few pointers to interesting, mostly recent papers on data warehousing and "big data" database systems, with an eye towards real-world deployments. I figured I'd share the list. It's biased and rather incomplete but maybe of interest to someone. While many are obvious choices (I've omitted several, like MapReduce), I think there are a few underappreciated gems.

###Dataflow Engines:

Dryad--general-purpose distributed parallel dataflow engine
http://research.microsoft.com/en-us/projects/dryad/eurosys07.pdf

Spark--in memory dataflow
http://www.cs.berkeley.edu/~matei/papers/2012/nsdi_spark.pdf

@nraychaudhuri
nraychaudhuri / gist:5169177
Created March 15, 2013 11:20
Simple REST example in Play 2
//routes file
GET /ping/:message controllers.Application.restCall(message: String)
//Then my controller
object Application extends Controller {
case class SomeMessage(m: String)
implicit val someMessageFormat: Format[SomeMessage] = Json.format[SomeMessage]
@viktorklang
viktorklang / InterruptibleCancellableFuture.scala
Last active June 1, 2020 13:45
Interruptible-Cancellable-scala.concurrent.Future
/*
Copyright 2018 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@seancribbs
seancribbs / 00demo.md
Last active December 16, 2015 17:09
Demo code from NoSQL Matters Cologne 2013