Skip to content

Instantly share code, notes, and snippets.

@arberg
arberg / MyActivity.Java
Created February 1, 2018 14:20
RxJava with AutoDispose: Provoke error after life cycle ends
package dk.bnr.androidbooking;
import android.arch.lifecycle.Lifecycle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.uber.autodispose.AutoDispose;
import com.uber.autodispose.AutoDisposePlugins;
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider;
@arberg
arberg / Get-TodoistBackup.ps1
Last active June 11, 2018 19:21 — forked from dansmith65/Get-TodoistBackup.ps1
Powershell script to download the latest backup from Todoist - With logging and win10 notifications on failure
# Get-TodoistBackup.ps1
# Created By: Daniel Smith dan@dansmith65.com
#
# Download the latest backup from Todoist
#
# https://gist.github.com/dansmith65/7a753ddb89c9db145d41b0c4b3c7fac0
# https://gist.github.com/arberg/5c905272dd3ba41d767e0907b46cd675
# Powershell Notifications: Install-Module -Name BurntToast
$useToast=(Get-Command New-BurntToastNotification -errorAction SilentlyContinue)
@arberg
arberg / Apache Tomcat 8 Start stop script init.d script
Last active October 17, 2018 18:12 — forked from miglen/Apache Tomcat 8 Start stop script init.d script
Apache Tomcat init script (or startup/controll script). Works fine for version 7/8. Read the comments for release history. Feel free to modify, copy and give suggestions. (c) GNU General Public License
#!/bin/bash
#
# description: Apache Tomcat init script
# processname: tomcat
# chkconfig: 234 20 80
#
#
# Copyright (C) 2014 Miglen Evlogiev
#
# This program is free software: you can redistribute it and/or modify it under
@arberg
arberg / WindowsHub4ComSerialRedirectToTcpPortWithTraceAndBaudRate.cmd
Last active November 25, 2018 10:17
In windows redirect RS232 Serial Port traffic (in+out) to TCP port. 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/
del log\*.log
rem Dependent on Hub4Com
rem Hub4Com Project page and download
rem https://sourceforge.net/projects/com0com/files/hub4com/
rem https://sourceforge.net/p/com0com/news/2012/06/hub4com-v2100-released/
rem Parent com0com project page (unused)
rem https://sourceforge.net/projects/com0com/
@arberg
arberg / linuxRedirectSerialPortToTcpWithLog.sh
Last active November 25, 2018 15:39
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
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 / 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
@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 / 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 / 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