Skip to content

Instantly share code, notes, and snippets.

View mgodave's full-sized avatar
🤟
move along, nothing to see here...

Dave Rusek mgodave

🤟
move along, nothing to see here...
  • Denver, CO
  • 23:17 (UTC -06:00)
View GitHub Profile
object AsyncStreams {
def collect[E](streams: Seq[AsyncStream[E]]): AsyncStream[E] = {
AsyncStream.fromFuture(
Future.collect(
streams.map(_.head)
).map(_.flatten)
).flatMap(AsyncStream.fromSeq) ++ collect(streams)
}
}
import com.twitter.util.{Var, Witness}
import org.mockito.Matchers.anyInt
import org.mockito.Mockito.{times, verify}
import org.scalatest.mockito.MockitoSugar
import org.scalatest.prop.PropertyChecks
import org.scalatest.{MustMatchers, WordSpec}
class VarsTest extends WordSpec with MustMatchers with PropertyChecks with MockitoSugar {
def max[T](values: Var[T])(implicit ord: Ordering[T]): Var[T] = {
class UpdateClass {
var _x = 1
def update(x: Int) = {
_x = x
}
}
val u = new UpdateClass()
println(u._x) // prints 1
u() = 2

Keybase proof

I hereby claim:

  • I am mgodave on github.
  • I am daverusek (https://keybase.io/daverusek) on keybase.
  • I have a public key whose fingerprint is 3DF3 2C1A 47C9 F842 A196 64EE F584 6BA0 56DA 28B2

To claim this, I am signing this object:

package org.robotninjas.util.pool;
import com.google.common.base.Ticker;
import org.apache.commons.pool2.BaseObjectPool;
import org.apache.commons.pool2.KeyedObjectPool;
import org.apache.commons.pool2.KeyedPooledObjectFactory;
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
package org.robotninjas.util.netty;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
@mgodave
mgodave / gist:8495373
Last active January 3, 2016 17:19
Talk abstract

Using "A Note on Distributed Computing" and "Seven Fallacies of Distributed Computing" as a guide I would like to explore the topic of distributed programming in Java. Starting with a gentle introduction to the challenges of programming in a distributed environment I will then look at some historical approaches used on the JVM and address their shortcomings. I will then explore some more modern approaches which address many of the concerns laid out in Waldo's seminal paper and discuss some of what must be considered when programming distibuted systems in Java. I will close out the talk by discussing some frameworks and libraries which make this task easier, including other languages built on top of the JVM.

Q: Is this talk: "Just Open a Socket"? - Talk to Sean.

I think what I'm trying to communicate is that everyone is telling us how bad RPC and Distributed Objects are, so what am I supposed to do?! Why are they bad and what am I supposed to do instead, what are good best practices? What does distributed pr

package org.robotninjas.util.concurrent;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.util.concurrent.*;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;
public class Test implements StateMachine {
@Override
public void applyOperation(@Nonnull ByteBuffer entry) {
System.out.println(entry.getLong());
}
public static void main(String... args) throws Exception {
ClusterConfig config = ClusterConfig.from(
@mgodave
mgodave / gist:7646319
Last active April 3, 2019 08:41
Create a single value Observable from a Guava ListenableFuture.
public static <T> Observable<T> create(ListenableFuture<T> future, Executor executor) {
AsyncSubject<T> subject = AsyncSubject.create();
future.addListener(() -> {
try {
T value = future.get();
subject.onNext(value);
subject.onCompleted();
} catch (Exception e) {
subject.onError(e);
}