Skip to content

Instantly share code, notes, and snippets.

View kevinherron's full-sized avatar

Kevin Herron kevinherron

View GitHub Profile
import kotlinx.coroutines.*
fun main(args: Array<String>) {
val job = SupervisorJob()
val scope = CoroutineScope(job + Dispatchers.Default)
val deferred = GlobalScope.async(Dispatchers.Default, start = CoroutineStart.LAZY) {
delay(5000)
throw Exception("boom")
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.delay
import java.time.Duration
import java.util.concurrent.TimeUnit
fun <T> ReceiveChannel<T>.debounce(timeout: Long, scope: CoroutineScope) =
this.debounce(Duration.ofMillis(timeout), scope)
fun <T> ReceiveChannel<T>.debounce(
/*
* Copyright (c) 2017 Kevin Herron
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
### Keybase proof
I hereby claim:
* I am kevinherron on github.
* I am kevinherron (https://keybase.io/kevinherron) on keybase.
* I have a public key ASCm4aAA4vH81LGpEb1rJ-D99hl0sVWFBH27o9KmFxeV7Ao
To claim this, I am signing this object:
@kevinherron
kevinherron / HistoryReadExample.java
Created July 28, 2017 14:45
HistoryReadExample
package org.eclipse.milo.examples.client;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
import org.eclipse.milo.opcua.stack.client.UaTcpStackClient;
public class BrowseExample implements ClientExample {
public static void main(String[] args) throws Exception {
BrowseExample example = new BrowseExample();
new ClientExampleRunner(example).run();
}
private final Logger logger = LoggerFactory.getLogger(getClass());
@kevinherron
kevinherron / Aes256GcmTest.java
Last active April 5, 2017 15:11
Aes256GcmTest
package org.eclipse.milo.opcua.stack;
import java.security.SecureRandom;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.eclipse.milo.opcua.stack.core.util.CryptoRestrictions;
import org.testng.annotations.Test;
package org.eclipse.milo.opcua.stack;
import java.security.SecureRandom;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.eclipse.milo.opcua.stack.core.util.CryptoRestrictions;
import org.testng.annotations.Test;
@kevinherron
kevinherron / LongAccumulatorCounter.java
Last active March 23, 2017 16:17
LongAdderCounter and LongAccumulatorCounter
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.LongAccumulator;
public class LongAccumulatorCounter extends ServerCounter {
private final AtomicReference<LongAccumulator> accumulator = new AtomicReference<>(
new LongAccumulator(
(left, right) -> left + right,
0L
)
@kevinherron
kevinherron / LoggerExtensions.kt
Last active May 22, 2017 13:12
Kotlin extensions to SLF4J Logger with MDC support
import org.slf4j.Logger
import org.slf4j.MDC
import org.slf4j.Marker
import org.slf4j.helpers.MessageFormatter
typealias LazyPair = () -> Pair<String, String>
// <editor-fold desc="Logger.trace Extensions">
inline fun Logger.trace(msg: () -> Any?) {
this.trace(msg.invoke().toString())