This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.Executors; | |
import java.util.concurrent.TimeUnit; | |
import com.google.common.base.Function; | |
import com.google.common.util.concurrent.*; | |
public class ListenableFuturesTest { | |
public static void main(String[] args) throws Exception { | |
ListeningScheduledExecutorService completer = MoreExecutors.listeningDecorator( | |
Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("completer").build())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' ) | |
abstract class Cache { | |
Cache parent | |
Closure loader | |
Cache(Closure loader) { | |
this.loader = loader | |
} | |
Cache(Cache parent) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the raw code as it was at the end of the session. | |
# | |
# In retrospect, the following could be improved: | |
# * @to_see is useless, two simple nested loops would work (or maybe keep it but shuffle it) | |
# * handle throttling better (instead of a lame DELAY) | |
# * I forgot to handle the case when I pick a pair by chance! | |
# * monitor game progress to avoid losing too many points | |
require "rest_client" | |
require "json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.crypto.Cipher; | |
public class CheckJceUnlimited { | |
public static void main(String[] args) throws Exception { | |
int maxAesLength = Cipher.getMaxAllowedKeyLength("AES"); | |
boolean unlimited = maxAesLength > 128; | |
System.out.println("JCE unlimited strength enabled: " + unlimited); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Naive solution (two passes) | |
def volume(l: List[Int]) = { | |
def peakRight(l: List[Int]) = l.foldRight(List(0)) { case (i, acc) => (i max acc.head) :: acc }.tail | |
def peakLeft(l: List[Int]) = peakRight(l.reverse).reverse | |
val waterLevels = peakLeft(l) zip peakRight(l) map { case (l, r) => l min r } | |
val volumes = l zip waterLevels map { case (g, w) => (w - g) max 0 } | |
volumes reduceLeft (_ + _) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.util.{Try, Success, Failure} | |
val f: Future[Int] = Future(1 / 0) | |
// answer C | |
def applyC[T](f: Future[T]): Future[Try[T]] = f.map(x => Try(x)) | |
// answer D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install graphite 0.9.10 on a Mac (Python 2.6 preinstalled) | |
# Gathered from my notes, might not be 100% accurate | |
brew install py2cairo | |
sudo pip install Django==1.3 | |
sudo pip install django-tagging | |
sudo pip install carbon | |
sudo pip install whisper | |
sudo pip install graphite-web | |
sudo pip install tagging # not sure if really useful |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# git-standup: find out what you did yesterday (or last friday). | |
# | |
# Setup: | |
# 1. Change AUTHOR if your git user doesn't match your unix account. | |
# 2. Save somewhere on your path, make executable. | |
# 3. git config --global alias.standup '!git-standup' | |
# 4. Profit. | |
# | |
# Original idea via @paulgreg (https://twitter.com/paulgreg/status/248686055727972352) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.util.Iterator; | |
import java.util.NoSuchElementException; | |
/** Streams the lines of a {@link BufferedReader} while applying some parsing method. */ | |
abstract class LineParsingIterator<T> implements Iterator<T> { | |
private final BufferedReader input; | |
private T buffered; // parsed but not yet returned to the client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Finds the version history of a POM in a Subversion repository */ | |
import scala.sys.process.Process | |
object Conf { | |
val url = "put the url of your POM here" | |
val svn = "svn --username xxx" | |
} | |
case class Revision(number: Int, date: String, version: String) { |