Skip to content

Instantly share code, notes, and snippets.

View splatch's full-sized avatar

Łukasz Dywicki splatch

View GitHub Profile
@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
public class JacksonDataFormatSplitExpression extends ExpressionAdapter
{
private final JacksonDataFormat format;
private final FormatSchema schema;
public JacksonDataFormatSplitExpression(JacksonDataFormat format, FormatSchema schema)
{
this.format = format;
this.schema = schema;
@splatch
splatch / Migrator.java
Created October 28, 2013 18:14
Eclipse project migrator
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import org.eclipse.core.internal.localstore.SafeChunkyInputStream;
import org.eclipse.core.internal.localstore.SafeChunkyOutputStream;
public class Migrator {
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
public class InstrumentingThreadPoolExecutor extends ThreadPoolExecutor {