Skip to content

Instantly share code, notes, and snippets.

View splatch's full-sized avatar

Łukasz Dywicki splatch

View GitHub Profile
// I don't know it makes any sense at all, it's just a random rant in code.
import org.slf4j.Logger;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
class FunctionalLogger {
Cache<String, Integer> cache = getCache(CACHE_ID); // wrapper around Hazelcast Map
cache.put("one", 1);
cache.put("two", 2);
cache.put("three", 3);
Map<String, Integer> map = cache.asMap(); // map representation of cache
assertThat(map).hasSize(3).containsOnly(
entry("one", 1),
entry("two", 2),
I am using Cassandra since few years now and I went into few troubles till now which simply
pushed me away from even trying to become part of "open source" Cassandra community.
Since I worked with Apache projects ealier on I was looking forward to modernize way how
cassandra was built. Project uses ant script and it's not problem that it was not modern
enough, but it simply caused some troubles which hit me. I invested fair amount of time
in collecting project dependencies and separating source roots (server/client etc), but
project team simply refused this direction. Whole discussion started here:
http://mail-archives.apache.org/mod_mbox/cassandra-dev/201503.mbox/%3C287F5EBC-3C2E-44FE-B652-D0A267646ABF@code-house.org%3E
People who worked on project were rather defensing any changes in this area despite of
@Override
public void bridgeHandlerInitialized(ThingHandler thingHandler, Bridge bridge) {
if (thingHandler instanceof BacNetBridgeHandler) {
this.client = ((BacNetBridgeHandler) thingHandler).getClient();
BacNetDeviceConfiguration configuration = getConfigAs(BacNetDeviceConfiguration.class);
// hardcode network number temporary to 0
this.device = new Device(configuration.id, configuration.ip, configuration.port, 0);
final List<Property> deviceProperties = client.getDeviceProperties(device);
@splatch
splatch / exec.java
Last active June 29, 2016 15:38
Capturing output of executed command with piped streams.
final PipedInputStream stream = new PipedInputStream();
final Process start = Runtime.getRuntime().exec(this.command);
new Thread(new Runnable() {
@Override
public void run() {
try {
InputStream inputStream = start.getInputStream();
PipedOutputStream output = new PipedOutputStream(stream);
IOUtils.copy(inputStream, output);
[[inputs.win_perf_counters]]
[[inputs.win_perf_counters.object]]
ObjectName = "Processor"
Instances = ["*"]
Counters = ["% Idle Time", "% Interrupt Time", "% Privileged Time", "% User Time", "% Processor Time"]
Measurement = "win_cpu"
[[inputs.win_perf_counters.object]]
ObjectName = "PhysicalDisk"
Instances = ["*"]
@splatch
splatch / bacnet4j.java
Created June 23, 2016 21:14
This is example of bacnet4j 3.2.4 api usage to interact with Komfovent C4/Ping module to read present values og gauges and also set mode.
import com.serotonin.bacnet4j.event.DeviceEventAdapter;
import com.serotonin.bacnet4j.exception.BACnetException;
import com.serotonin.bacnet4j.exception.ErrorAPDUException;
import com.serotonin.bacnet4j.npdu.ip.IpNetwork;
import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;
import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyMultipleAck;
import com.serotonin.bacnet4j.service.confirmed.*;
import com.serotonin.bacnet4j.service.unconfirmed.WhoIsRequest;
import com.serotonin.bacnet4j.transport.DefaultTransport;
@splatch
splatch / timer.java
Created July 17, 2015 12:28
Gather metrics using codahale stuff
Counter failCounter = new Counter();
Counter successCounter = new Counter();
Timer timer = new Timer();
@Override
public Y transform(X x) {
Timer.Context time = timer.time();
try {
Y transform = delegate.transform(x);
@splatch
splatch / MapMatcher.java
Created June 30, 2015 08:41
Simple hamcrest map matcher which ensures that argument contains given keys and values.
import org.hamcrest.Description;
import org.mockito.ArgumentMatcher;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class MapMatcher extends ArgumentMatcher<Map> {
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Austrian Association for Software Tool Integration (AASTI)
under one or more contributor license agreements. See the NOTICE file
distributed with this work for additional information regarding copyright
ownership. The AASTI licenses this file to you 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