Skip to content

Instantly share code, notes, and snippets.

@arberg
arberg / OnResultCallback.kt
Created Jul 15, 2021
Kotlin Coroutine Callback for result/error/cancel
View OnResultCallback.kt
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 Jul 15, 2021
Kotlin Coroutine Callback
View OnCompleteCallback.kt
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 Jul 7, 2020
Android Sms AutoRetrieval hash-generator in Kotlin
View AppSignatureSmsVerificationHelper.kt
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
View Measure-TMCommand.ps1
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 Sep 19, 2019 — forked from barsv/logger.ps1
Logging in powershell with log rotation
View logger.ps1
# 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 Sep 19, 2019 — forked from barsv/logger.ps1
Logging in powershell with log rotation
View logger.ps1
# 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 Dec 7, 2018
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.
View downloadWith-YoutubeDl.sc
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 Dec 7, 2018
Download from youtubeDl with my custom video quality preference and downnload subtitles and convert vtt to srt with ffmpeg.
View downloadWith-YoutubeDl.sc
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
@arberg
arberg / linuxRedirectSerialPortToTcpWithLog.sh
Last active Nov 25, 2018
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/
View linuxRedirectSerialPortToTcpWithLog.sh
#!/bin/bash
pid=$$
pgid=$(ps -o pgid= $$ | awk '{$1=$1;print}')
# 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 -echo
@arberg
arberg / linuxRedirectSerialPortToTcpWithLog.sh
Created Nov 25, 2018
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/
View linuxRedirectSerialPortToTcpWithLog.sh
#!/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() {