Skip to content

Instantly share code, notes, and snippets.

@jhalterman
jhalterman / gist:fe70f5ef8abb4697d61d
Last active August 29, 2015 14:22
Set the JDK version on OSX
# Usage setjdk 1.8
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
fi
:cas (timeout 5000 (assoc op :type :info :value :timed-out)
(let [cas (reify Function
(apply [this, tr]
(let [
[value value'] (:value op)
key_var (byte-array (map byte key))
old_value (.getLong (Tuple/fromBytes (.get (.get tr (byte-array (map byte key))))) 0)
new_value (.pack (Tuple/from (into-array [value'])))]
(if (= old_value value)
(do
(deftest create-cas-test
(let [test (run!
(assoc
noop-test
:name "foundationdb"
:os ubuntu/os
:db db
:client (cas-register)
:model (model/cas-register)
:checker (checker/compose {:html timeline/html
@jhalterman
jhalterman / try-until-success.clj
Created November 20, 2015 00:12
Try until success
(defn try-until-success
"Accepts a try-fn to try a failure-fn to call upon failure, supplying the failure/exception. The try-fn is retried
until no failure is thrown."
[try-fn failure-fn]
(loop []
(if-let [result (try
(try-fn)
(catch Exception e
(failure-fn e)
nil))]
@jhalterman
jhalterman / ReentrantCircuit.java
Last active December 27, 2015 10:09
A circuit that accepts re-entrant open and close calls, allows waiting threads to be interrupted, and ensures fairness when releasing threads.
/**
* A circuit that accepts re-entrant {@link #open()} and {@link #close()} calls and ensures fairness
* when releasing {@link #await() waiting} threads.
*
* @author Jonathan Halterman
*/
public class ReentrantCircuit {
private final Sync sync = new Sync();
/**
@jhalterman
jhalterman / InterruptableWaiter.java
Created November 4, 2013 21:02
A waiter where waiting threads can be interrupted (as opposed to awakened).
/**
* A waiter where waiting threads can be interrupted (as opposed to awakened).
*
* @author Jonathan Halterman
*/
public class InterruptableWaiter {
private final Sync sync = new Sync();
private static final class Sync extends AbstractQueuedSynchronizer {
private static final long serialVersionUID = 4016766900138538852L;
@jhalterman
jhalterman / gist:9814465
Last active January 5, 2016 09:52
AbstractAppTest for testing Dropwizard Applications with TestNG. This implementation creates a single application for the entire test suite.
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.cli.ServerCommand;
import io.dropwizard.lifecycle.ServerLifecycleListener;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.testing.junit.ConfigOverride;
import java.util.Enumeration;
@jhalterman
jhalterman / gist:9814439
Last active January 5, 2016 09:52
AbstractResourceTest for testing resources in Dropwizard with TestNG
import io.dropwizard.Configuration;
import io.dropwizard.configuration.ConfigurationFactory;
import io.dropwizard.jackson.Jackson;
import io.dropwizard.jersey.DropwizardResourceConfig;
import io.dropwizard.jersey.jackson.JacksonMessageBodyProvider;
import io.dropwizard.logging.LoggingFactory;
import io.dropwizard.setup.Environment;
import java.io.File;
import java.io.FileNotFoundException;
@jhalterman
jhalterman / ThreadAwareExceptionTest.java
Last active May 27, 2017 03:54
Experiments in thread aware exceptions
import java.util.Arrays;
public class ThreadAwareExceptionTest {
static class ThreadAwareThread extends Thread {
Throwable entryPoint;
ThreadAwareThread(Runnable runnable) {
super(runnable);
}
@jhalterman
jhalterman / minscalaactors.scala
Created November 15, 2017 03:27 — forked from viktorklang/minscalaactors.scala
Minimalist Scala Actors
/*
Copyright 2012 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software