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 / AliasExample.java
Last active January 29, 2021 22:14
Multiple selections of the same field with different arguments, under different aliases
import graphql.GraphQL;
import graphql.Scalars;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import graphql.schema.GraphQLSchema;
import static graphql.schema.FieldCoordinates.coordinates;
import static graphql.schema.GraphQLArgument.newArgument;
import static graphql.schema.GraphQLCodeRegistry.newCodeRegistry;
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
@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)
@olim7t
olim7t / Hello.scala
Created July 26, 2019 18:47
Test project to reproduce JAVA-1252, and check if JAVA-2365 will cause the same issue
// (in src/main/scala/example/)
package example
import com.datastax.oss.driver.api.core.cql.BatchType
import com.datastax.driver.dse.DseCluster
object Hello extends App {
// Test if JAVA-2365 creates a problem:
println(BatchType.LOGGED)
package com.datastax.oss.driver.mapper;
import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.BatchStatement;
import com.datastax.oss.driver.api.core.cql.BatchStatementBuilder;
import com.datastax.oss.driver.api.core.cql.BoundStatementBuilder;
import com.datastax.oss.driver.api.core.cql.DefaultBatchType;
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
@olim7t
olim7t / LogbackCapture.java
Created March 22, 2011 14:46
Temporarily captures Logback output (mostly useful for tests).
import static ch.qos.logback.classic.Level.ALL;
import static org.slf4j.Logger.ROOT_LOGGER_NAME;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
@olim7t
olim7t / Read2MbBlobs.java
Last active April 5, 2016 09:08
Test program to debug blob reading issue
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
public class Read2MbBlobs {
public static void main(String[] args) {
@olim7t
olim7t / IntToDateDemo.java
Last active January 21, 2016 16:04
Custom codec to handle CQL `date` columns as Java ints
import com.datastax.driver.core.*;
import com.datastax.driver.core.exceptions.InvalidTypeException;
import java.nio.ByteBuffer;
public class LongToDateDemo {
public static class LongToDateCodec extends TypeCodec<Integer> {
// Piggyback on the default codecs' implementation
@olim7t
olim7t / GatherAllListenAddresses.java
Created January 7, 2016 09:43
Use custom LBP to query system.local on each host
import com.datastax.driver.core.*;
import com.datastax.driver.core.policies.Policies;
import java.net.InetAddress;
public class GatherAllListenAddresses {
public static void main(String[] args) {
Cluster cluster = null;
try {
cluster = Cluster.builder()
// 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