Skip to content

Instantly share code, notes, and snippets.

@oillio
oillio / MyServiceImpl.java
Created October 5, 2016 20:05
bi-directional stream gRPC with RxJava
public class MyServiceImpl extends DeviceServiceGrpc.DeviceServiceImplBase {
@Override
public StreamObserver<GetLocationRequest> getLocations(StreamObserver<GetLocationResponse> responseObserver) {
RequestBridge<GetLocationRequest> request = new RequestBridge<>();
ResponseBridge response = new ResponseBridge((ServerCallStreamObserver) responseObserver);
request.map(this::doGetLocation)
.subscribe(response);
return request;
}
public class TriggerStep extends AbstractStepImpl {
private final String spec;
@DataBoundConstructor
public TriggerStep(String spec) {
this.spec = spec;
}
public String getSpec() {
@oillio
oillio / gist:ad293c464de43f7ff10efe8b0ceac466
Last active June 6, 2016 17:40
terraform concat panic
2016/06/06 11:22:58 [INFO] Terraform version: 0.7.0 rc1 301da85f30239e87b30db254a25706a6d41c2522
2016/06/06 11:22:58 [DEBUG] Detected home directory from env var: /Users/djasek
2016/06/06 11:22:58 [DEBUG] Detected home directory from env var: /Users/djasek
2016/06/06 11:22:58 [DEBUG] Attempting to open CLI config file: /Users/djasek/.terraformrc
2016/06/06 11:22:58 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2016/06/06 11:22:58 [DEBUG] Detected home directory from env var: /Users/djasek
2016/06/06 11:22:58 [TRACE] Graph after step *terraform.ConfigTransformer:
module.envTesting - *terraform.GraphNodeConfigModule
provider.aws - *terraform.GraphNodeConfigProvider
@oillio
oillio / DropwizardEntityFilteringFeature.java
Last active August 9, 2022 15:32
A workaround to use, in Dropwizard, entity filtering functionality provided by org.glassfish.jersey.media:jersey-media-json-jackson
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import lombok.extern.slf4j.Slf4j;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.jersey.CommonProperties;
import org.glassfish.jersey.ServiceLocatorProvider;
import org.glassfish.jersey.internal.InternalProperties;
import org.glassfish.jersey.internal.util.PropertiesHelper;
import org.glassfish.jersey.jackson.internal.JacksonFilteringFeature;
@oillio
oillio / gist:ab285dfbc482500cc1bd
Created July 24, 2014 21:02
Update versions and release with git flow and maven
git-flow release start $NEWVER
mvn versions:set -DnewVersion=$NEWVER versions:update-child-modules -DgenerateBackupPoms=false -Prpm -Pintegration
git commit -m "Update to release version."
export GIT_MERGE_AUTOEDIT=no
git-flow release finish -m '$NEWVER' $NEWVER
mvn versions:set -DnewVersion=$NEWVER-SNAPSHOT versions:update-child-modules -DgenerateBackupPoms=false -Prpm -Pintegration
mvn release:update-versions --batch-mode -DautoVersionSubmodules=true -Prpm -Pintegration
git commit -a -m "Prepare for new version."
class ProbNode:
"""Stores the probability of getting a specific number of colluding nodes within a group.
Also contains the remaining nodes and colluding nodes in the network that are not in the group."""
def __init__(self, nodes, colluding, group, quorum, upstream_prob):
self.prob = upstream_prob * ((binomial(colluding, quorum) * binomial(nodes-colluding,group-quorum))/binomial(nodes, group))
self.nodes = nodes - group
self.colluding = colluding - quorum
def rcoin_control(pnodes, group, quorum, required_groups):
if required_groups == 0:
public static IObservable<WState> WindowOpensAndCloses<T>(this IObservable<IObservable<T>> This, bool verify_exclusive = true) {
var state = WState.Close;
var ret = Observable.Merge(This.Select(_ => WState.Open),
This.SelectMany(x => x.Materialize())
.Where(x => x.Kind == NotificationKind.OnCompleted ||
x.Kind == NotificationKind.OnError)
.Select(_ => WState.Close));
if(verify_exclusive) return ret.Do(x =>
{
@oillio
oillio / log4netLogger.cs
Created January 30, 2011 02:08
A simple wrappert to convert a log4net ILog into a ReactiveUI ILog
using System;
using log4net.Core;
using ReactiveUI;
namespace Logger {
public class log4netLogger : ILog {
private readonly log4net.ILog _log;
public log4netLogger(string prefix)
//MultiDictionary is a Dictionary-like object that can store multiple values for the same key.
public class MultiDictionary<TKey, TValue> :ICollection<KeyValuePair<TKey, TValue>>, ICollection {
private Dictionary<TKey, HashSet<TValue>> _collection = new Dictionary<TKey,HashSet<TValue>>();
public IEnumerable<TValue> this[TKey key] {
get {
if(!_collection.ContainsKey(key)) return new List<TValue>();
return _collection[key];
}
}
<def tag="tabs">
<set-scoped tab-names="&[]" tab-contents="&{}">
<ul class="tabs" merge>
<do param="default" />
</ul>
<do repeat="&scope.tab_names">
<div id="#{this}">
<%= scope.tab_contents[this] %>
</div>
</do>