This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
static void reportInFlightQueries(Session session) { | |
Session.State state = session.getState(); | |
System.out.printf("State of %s:%n", session); | |
for (Host host : state.getConnectedHosts()) { | |
int connections = state.getOpenConnections(host); | |
int inFlight = state.getInFlightQueries(host); | |
System.out.printf("\t%s:\tconnections=%2s\tinFlight=%4s\tmean=%4s%n", | |
host, | |
connections, | |
inFlight, |
This file contains hidden or 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.Semaphore; | |
import java.util.concurrent.TimeUnit; | |
import com.codahale.metrics.ConsoleReporter; | |
import com.google.common.collect.ImmutableMap; | |
import com.google.common.util.concurrent.MoreExecutors; | |
import org.junit.ClassRule; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.scassandra.http.client.PrimingClient; |
This file contains hidden or 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
package com.datastax.driver.core; | |
import java.awt.Component; | |
import java.awt.Container; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.util.Iterator; | |
import java.util.Set; | |
import javax.swing.*; |