Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / 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 / 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 / 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 / Measure-TMCommand.ps1
Last active December 1, 2019 10:16
Maynards Powershell Measure-TMCommand with small extensions https://gallery.technet.microsoft.com/Measure-Command-with-52158178
Function Measure-TMCommand {
<#
.SYNOPSIS
Continually measure a command (or commands) and/or a script (or scripts) up to a user-defined number of repetitions.
.DESCRIPTION
Continually measure a command (or commands) and/or a script (or scripts) up to a user-defined number of repetitions. As well, the advanced function will calculate averages, can include limited hardware specs about the computer that is performing the measurements, and can even display the output of the commands and/or scripts being measured.
.PARAMETER Command
@arberg
arberg / logger.ps1
Created September 19, 2019 14:39 — forked from barsv/logger.ps1
Logging in powershell with log rotation
# all logging settins are here on top
$logFile = "log-$(gc env:computername).log"
$logLevel = "DEBUG" # ("DEBUG","INFO","WARN","ERROR","FATAL")
$logSize = 1mb # 30kb
$logCount = 10
# end of settings
function Write-Log-Line ($line) {
Add-Content $logFile -Value $Line
Write-Host $Line
@arberg
arberg / logger.ps1
Created September 19, 2019 14:39 — forked from barsv/logger.ps1
Logging in powershell with log rotation
# all logging settins are here on top
$logFile = "log-$(gc env:computername).log"
$logLevel = "DEBUG" # ("DEBUG","INFO","WARN","ERROR","FATAL")
$logSize = 1mb # 30kb
$logCount = 10
# end of settings
function Write-Log-Line ($line) {
Add-Content $logFile -Value $Line
Write-Host $Line
@arberg
arberg / downloadWith-YoutubeDl.sc
Created December 7, 2018 12:40
Download from youtubeDl with my custom video quality preference and downnload subtitles and convert vtt to srt with ffmpeg. Written in scala ammonite, so needs Ammonite to run it.
import ammonite.ops._
import ujson.Js.Value
import upickle.default.{macroRW, ReadWriter => RW}
//import scala.math.Ordering.Implicits._
//https://transform.now.sh/json-to-scala-case-class
case class SubLanguage(ext: String, url: String)
object SubLanguage { // uPickle 0.7.1 needs these to parse the objects. Really ugly, maybe gson is better?
implicit val rw: RW[SubLanguage] = macroRW
@arberg
arberg / downloadWith-YoutubeDl.sc
Created December 7, 2018 12:09
Download from youtubeDl with my custom video quality preference and downnload subtitles and convert vtt to srt with ffmpeg.
import ammonite.ops._
import ujson.Js.Value
import upickle.default.{macroRW, ReadWriter => RW}
//import scala.math.Ordering.Implicits._
//https://transform.now.sh/json-to-scala-case-class
case class Da(ext: String, url: String)
object Da { // uPickle 0.7.1 needs these to parse the objects. Really ugly, maybe gson is better?
implicit val rw: RW[Da] = macroRW