Skip to content

Instantly share code, notes, and snippets.

import com.codahale.metrics.Gauge;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricRegistry;
import com.sensus.common.database.hikari.SingletonMetricsRegistry;
import com.sensus.util.timing.Timeout;
import com.sms.db.manager.DatabaseState;
import com.sms.db.manager.DatabaseType;
import com.sms.db.manager.DbConnector;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
@samhendley
samhendley / ExampleToString.java
Created July 29, 2016 13:36
Nullable ToString generator for Intellij
class SampleToString {
@Override
public String toString() {
return "KeyManagementState{" +
"repId=" + repId +
(managementState == null ? "" : ", managementState:" + managementState) +
(desiredState == null ? "" : ", desiredState:" + desiredState) +
(lastAction == null ? "" : ", lastAction:" + lastAction) +
(lastActionResult == null ? "" : ", lastActionResult:" + lastActionResult) +
(lastActionTime == null ? "" : ", lastActionTime:" + lastActionTime) +
@samhendley
samhendley / ApplicationContextDumper.java
Last active August 29, 2015 14:05 — forked from aleung/ApplicationContextDumper.java
Slightly improved version that ignores beans that can be considered "root" objects (prototypes, SmartLifecycle,BeanFactoryPostProcessor,ApplicationContextAware)
package leoliang.springtest;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.support.AbstractRefreshableApplicationContext;
import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.observables.ConnectableObservable;
import rx.subscriptions.Subscriptions;
import rx.util.functions.Func1;
public class SettableObservable<T> {
private final Observer<T> observer;
@samhendley
samhendley / FutureWatcher.java
Last active September 1, 2022 16:33
FutureWatcher utility class as alternative Observable.from(future)
import com.sensus.util.threading.DelayedWorkExecutor;
import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.subscriptions.BooleanSubscription;
import rx.util.functions.Func1;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
@samhendley
samhendley / ModelWithUUIDTest.scala
Created April 25, 2011 19:51
Test case showing # of calls to newUUID
package org.totalgrid.reef.models
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.squeryl._
import org.squeryl.PrimitiveTypeMode._
import java.util.UUID
@samhendley
samhendley / ExampleModelTest.scala
Created January 25, 2011 19:45
Test Suite showing squeryl bugs in 0.9.4-RC2
package reef.persistence.squeryl
import org.scalatest.{ FunSuite, BeforeAndAfterAll, BeforeAndAfterEach }
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.squeryl.{ Schema, Table, KeyedEntity }
import org.squeryl.PrimitiveTypeMode._
@samhendley
samhendley / Most Recent Row for each point
Created January 13, 2011 15:19
Query to be replicated
Select
Measurement.pointId,
Measurement.measTime
from Measurement
inner join (
select max(Measurement.measTime) as t1,
Measurement.pointId as p1
from Measurement
where Measurement.pointId in (1, 2, 5, 10)
group by pointId
@samhendley
samhendley / NestedTransactionExceptionTest.scala
Created December 14, 2010 15:51
NestedTransactionExceptionTest.scala
class Foo(val value: String) extends KeyedEntity[Long] {
val id: Long = 0
}
object FooSchema extends Schema {
val foos = table[Foo]
def reset() = {
drop // its protected for some reason
create
@samhendley
samhendley / Commands
Created November 8, 2010 20:17
cassandra.pgp
#This is the command you would normally try
#gpg --keyserver wwwkeys.eu.pgp.net --recv-keys F758CE318D77295D && gpg --export --armor F758CE318D77295D | sudo apt-key add -
#replace with:
wget http://gist.github.com/raw/668194/336603c2b2cd4a576c3ec97932c7ca70dc9e1e6e/cassandra.pgp
sudo apt-key add cassandra.pgp