Skip to content

Instantly share code, notes, and snippets.

View PoisonousJohn's full-sized avatar

Ivan Fateev PoisonousJohn

View GitHub Profile
@PoisonousJohn
PoisonousJohn / headset-switcher.service
Last active December 16, 2020 10:28
Headset switcher service. Detects when Zoom is running and switches headset profile for the call, then switches it back, when the meeting is ended
[Unit]
Description=Music Player Daemon
[Service]
ExecStart=/home/jp/.config/systemd/user/headset-switcher.sh
[Install]
WantedBy=default.target
@PoisonousJohn
PoisonousJohn / check.kt
Created June 18, 2020 15:29
Kotlin data class, Check fields equality by reflection
var fields = originalInvoice::class.memberProperties
var string = ""
for (field in fields) {
if (field.getter.call(originalInvoice) != field.getter.call(this)) string += "${field.name}\n"
}
string
Reason:
java.lang.LinkageError: loader constraint violation: when resolving interface method "groovy.text.Template.make(Ljava/util/Map;)Lgroovy/lang/Writable;" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, com/kms/katalon/core/util/StrSubstitutor, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for the method's defining class, groovy/text/Template, have different Class objects for the type groovy/lang/Writable used in the signature
at com.kms.katalon.core.util.StrSubstitutor.replace(StrSubstitutor.java:44)
at com.kms.katalon.core.testobject.ObjectRepository.lambda$0(ObjectRepository.java:261)
at com.kms.katalon.core.testobject.ObjectRepository.findWebUIObject(ObjectRepository.java:258)
at com.kms.katalon.core.testobject.ObjectRepository.readTestObjectFile(ObjectRepository.java:206)
at com.kms.katalon.core.testobject.ObjectRepository.findTestObject(ObjectRepository.java:174)
at com.kms.katalon.core.testobject.ObjectRepository.findTestObject(
@PoisonousJohn
PoisonousJohn / touchpad-sleep.service
Created October 4, 2019 13:39
Restore touchpad for Lenovo X1 gen 6
# from: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1791427
# /etc/systemd/system/touchpad-sleep.service
# restore touchpad on suspend
[Unit]
Description=Restore Touchpad on suspend
Before=sleep.target
StopWhenUnneeded=yes
[Service]
@PoisonousJohn
PoisonousJohn / prepare-commit-msg
Last active September 23, 2019 15:56
Prepend commit message with ticket number in case your branch is of format 'branch#123` where 123 is a number.
# based on https://medium.com/@nicklee1/prepending-your-git-commit-messages-with-user-story-ids-3bfea00eab5a
# Include any branches for which you wish to disable this script
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop staging test)
fi
# Get the current branch name and check if it is excluded
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
@PoisonousJohn
PoisonousJohn / dict_utils.py
Created May 15, 2019 16:46
deep update for python dicts
import copy
import itertools
def update_list_by_dict(target: list, value: dict):
"""
Updates a list using keys from dictionary
May be helpful if you want a fuzzy update of a list
If key greater than list size, list will be extended
If list value is dict, it's deep updated
@PoisonousJohn
PoisonousJohn / crop.sh
Last active February 1, 2019 22:06
ImageMagick crop image to square adding stripes on the sides, same names
#!/bin/bash
mkdir -p out
convert *.JPG -background white -resize "1500x1500" -gravity Center -extent 1500x1500 -rotate 90 -set filename:f '%t' out/'%[filename:f].png'
@PoisonousJohn
PoisonousJohn / tasks.json
Created January 18, 2019 14:03
vscode pylint problem matcher
{
"problemMatcher": {
"owner": "python",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(W|E).+:\\s+(.*)$",
"file": 1,
@PoisonousJohn
PoisonousJohn / log.log
Created October 8, 2018 20:45
Motion log with rtsp
[alarm@alarmpi records]$ motion
[37881728:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[37881728:motion] [NTC] [ALL] motion_startup: Motion 4.1.1 Started
[37881728:motion] [NTC] [ALL] motion_startup: Logging to syslog
[37881728:motion] [NTC] [ALL] motion_startup: Using log type (ALL) log level (DBG)
[37881728:motion] [INF] [ALL] conf_output_parms: Writing configuration parameters from all files (1):
[37881728:motion] [INF] [ALL] Thread 0 - Config file: /etc/motion/motion.conf
[37881728:motion] [INF] [ALL] daemon off
[37881728:motion] [INF] [ALL] process_id_file /var/run/motion/motion.pid
[37881728:motion] [INF] [ALL] setup_mode off
@PoisonousJohn
PoisonousJohn / copy.ps1
Last active March 30, 2018 15:24
Copy Azure managed image to a different region. Source: https://michaelcollier.wordpress.com/2017/05/03/copy-managed-images/
az account set --subscription $SubscriptionID
snapshotId=$(az snapshot show -g $ResourceGroupName -n $snapshotName --query "id" -o tsv )
# Get the SAS for the snapshotId
snapshotSasUrl=$(az snapshot grant-access -g $ResourceGroupName -n $snapshotName --duration-in-seconds 3600 -o tsv)
# Setup the target storage account in another region
targetStorageAccountKey=$(az storage account keys list -g $ResourceGroupName --account-name $targetStorageAccountName --query "[:1].value" -o tsv)
storageSasToken=$(az storage account generate-sas --expiry 2017-05-02'T'12:00'Z' --permissions aclrpuw --resource-types sco --services b --https-only --account-name $targetStorageAccountName --account-key $targetStorageAccountKey -o tsv)