Skip to content

Instantly share code, notes, and snippets.

@arberg
arberg / linuxRedirectSerialPortToTcpWithLog.sh
Created November 25, 2018 10:23
In linux redirect RS232 Serial Port traffic (in+out) to TCP port. Log all input + output to files. Its possible to connect with telnet to tcp-port. Short circuit COM pin 2+3 (in+out) to do loop-back test of connection without device attached, see http://www.ni.com/tutorial/3450/en/
#!/bin/bash
# netcat -l 7000 </dev/ttyUSB0 >/dev/ttyUSB0 &
cat /dev/ttyUSB0 | tee /var/log/lyngdorfSerial.ComToTcp.log | netcat -l 7000 | tee /var/log/lyngdorfSerial.TcpToCom.log > /dev/ttyUSB0 &
# Linux resets state when netcat closes com-port, so we need to se this after opening netcat
stty -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb
killtree() {
@arberg
arberg / OnCompleteCallback.kt
Created July 15, 2021 20:34
Kotlin Coroutine Callback
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
interface OnCompleteCallback {
fun complete()
/**
@arberg
arberg / OnResultCallback.kt
Created July 15, 2021 20:36
Kotlin Coroutine Callback for result/error/cancel
import dk.bnr.androidbooking.managers.model.AppInternalSilentException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
interface OnResultCallback<T> {
fun onNext(value: T)
fun onError(throwable: Exception)
@arberg
arberg / gw-simple.ps1
Last active May 7, 2022 02:46
Wrapping the gradle wrapper with Powershell
#Finds the first gradle in the list below
#Runs gradle with the arguments to this script in current dir
$gradlePaths = @("./gradlew","../gradlew", "gradle")
$currentGradlePaths = ( $gradlePaths | ?{ gcm $_ -erroraction 'silentlycontinue' } )
if ($currentGradlePaths.Length -gt 0) {
if ($currentGradlePaths -is [array]) {
$gradle = $currentGradlePaths[0]
} else {
@arberg
arberg / AppSignatureSmsVerificationHelper.kt
Created July 7, 2020 17:24
Android Sms AutoRetrieval hash-generator in Kotlin
package sms
import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.util.Base64
import android.util.Log
import java.nio.charset.StandardCharsets
import java.security.MessageDigest
@arberg
arberg / EnumIgnoreUnknownSerializer.kt
Last active June 23, 2023 00:44
Kotlin Enum Serializer which ignores unknown values (kotlinx)
import android.annotation.SuppressLint
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
@arberg
arberg / MessagingSerialVersionUidTest.java
Created September 25, 2023 16:45
Junit5 test: Verify all classes have serialVersionUID, and when one is missing generate a TestCase which verifies the current value, so we can add the serialVersionUID and verify its correct with previous value
package dk.messaging;
import com.google.common.truth.Truth;
import com.openpojo.reflection.PojoClass;
import com.openpojo.reflection.impl.PojoClassFactory;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;