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
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()));
@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) {
@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"
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);
}
}
// 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 (_ + _)
}
@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
@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 / git-standup.sh
Created October 1, 2012 08:44
git-standup: find out what you did yesterday (or last friday)
#!/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)
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
/* 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) {