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 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.*;
/* Basic j.u.l config for simple projects */
import java.util.logging.Level;
import java.util.logging.Logger;
public class Jul{
static {
Logger.getLogger("").setLevel(Level.SEVERE);
final Logger myLogger = Logger.getLogger("com.mycompany");
myLogger.setLevel(Level.FINEST);
import java.util.Calendar._
import java.util.GregorianCalendar
import java.util.GregorianCalendar._
import java.util.TimeZone
// A calendar in Paris' time zone (GMT+1)
val cfr = new GregorianCalendar
cfr.setTimeZone(TimeZone.getTimeZone("Europe/Paris"))
// A calendar at GMT+0
@olim7t
olim7t / Breaks.java
Created December 16, 2010 19:47
Utility class to simulate dependencies between breakpoints in the Eclipse debugger.
/*
* Copyright (c) 2010, Olivier Michallat
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,