Skip to content

Instantly share code, notes, and snippets.

View olim7t's full-sized avatar

Olivier Michallat olim7t

  • DataStax
  • San Jose, CA
View GitHub Profile
@olim7t
olim7t / graphite.sh
Last active December 12, 2015 09:39
Install Graphite 0.9.10 on a Mac
# 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
@olim7t
olim7t / FutureToTry.scala
Last active December 28, 2015 21:09
Coursera / Reactive Programming in Scala / Week 3 / Combinators on Futures Sample code for answers C and D of the quiz.
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
// 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 (_ + _)
}
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);
}
}
@olim7t
olim7t / extreme_memory_client.rb
Last active August 29, 2015 14:01
My solution for Sophie's Extreme Memory challenge (https://github.com/sophietk/xke-memory-server)
# 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"
@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) {
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()));
@olim7t
olim7t / gist:08026acfff09e475390d
Created December 8, 2014 09:35
Monitor inFlight queries of DataStax Java driver
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,
@olim7t
olim7t / gist:e53ca1a25e25dd1551be
Created December 11, 2014 16:52
Java driver test using SCassandra.
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;
@olim7t
olim7t / SwingClient.java
Last active August 29, 2015 14:11
Swing client to expose Cassandra java driver internals in tests
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.*;