Skip to content

Instantly share code, notes, and snippets.

@scorpp
scorpp / put resources off java code
Last active December 16, 2015 00:09
Move all resource file from src/main/java to src/main/resources Needed sort files that way while migrating existing java projects to maven build system
find ./*/src/main/java/ -type f ! -name *.java | xargs -n 1 -P 1 -I{} bash -c "newdir=\$(echo \"\$(dirname {})\" | sed 's/src\/main\/java/src\/main\/resources/'); mkdir -p \$newdir; git mv {} \$newdir"
@scorpp
scorpp / git merge a subdirectory
Last active December 19, 2015 09:39
GIT merge a subdirectory from another repo\branch
# http://stackoverflow.com/a/12048161/679052
$ git remote add Bar /path/to/bar
$ git merge -s ours --no-commit Bar/master
$ git read-tree --prefix=public/bar -u Bar/master:www/tools/
@scorpp
scorpp / gist:9207503
Last active August 29, 2015 13:56
Find all java files in current directory and move them in maven-correct directory with git
find . -type f -name '*.java' | \
while read f; do \
target=$(grep '^package ' $f | sed -e 's/package \+//' -e 's/;$//' -e 's/\./\//g'); \
newf="src/main/java/${target}/$(basename $f)"; \
mkdir -p $(dirname $newf); \
git mv $f $newf; \
chmod 644 $newf; \
done
@scorpp
scorpp / skype-search.pl
Created December 31, 2014 14:16
Skype: focus main win and prepare it for typing in contact name
#!/usr/bin/perl
use strict;
use warnings;
use Net::DBus;
my $session = Net::DBus->session;
my $service = $session->get_service('com.Skype.API');
@scorpp
scorpp / skype-mute.py
Created December 31, 2014 14:18
Skype: mute\unmute current call
#!/usr/bin/python2
import sys
import traceback
import re
import dbus
import dbus.service
#for event loop
import gobject
from dbus.mainloop.glib import DBusGMainLoop
@scorpp
scorpp / skype-toggle.py
Created December 31, 2014 14:19
Skype: show\hide main window
#!/usr/bin/python2
import dbus
import os
remote_bus = dbus.SessionBus()
out_connection = remote_bus.get_object('com.Skype.API', '/com/Skype')
out_connection.Invoke('NAME SkypeToggler')
out_connection.Invoke('PROTOCOL 5')
@scorpp
scorpp / proxmox-backup-hook.sh
Last active December 29, 2020 13:40
Hetzner backup hook to mount Hetzner backup space
#!/bin/bash
# vzdump hook script that handles mounting of [Hetzner] backup space
# [over SFTP] and then mounting an FS image stored there.
# After backup is done backup image is remounted to ensure data synced.
# Relies on /etc/fstab entries for backup mount points and pub key auth
# for SFTP.
#
# Corresponding fstab enties:
# [email protected]: /mnt/backup-space fuse.sshfs defaults,noauto,allow_root,_netdev 0 0
# /mnt/backup-space/image /mnt/backup ext4 noauto,defaults,loop 0 0
@scorpp
scorpp / docker-pulse-server.sh
Last active July 16, 2019 14:33
Run pulseaudio server in docker container
docker run --rm -ti \
--device=/dev/snd/controlC0 --device=/dev/snd/pcmC0D0p --device=/dev/sndpcmC0D1p --device=/dev/snd/timer \
-p 4713:4713 \
rpi-deb-pulse \
/bin/bash -c "groupadd --gid $(ls -l /dev/snd/controlC0 | cut -d' ' -f4 | xargs getent group | cut -d: -f3) alsadev \
&& gpasswd -a pulse alsadev \
&& pulseaudio --system --high-priority --no-cpu-limit -v \
-L 'module-alsa-sink device=hw:0,0' \
-L 'module-native-protocol-tcp auth-ip-acl=10.2.0.0/24'"
@scorpp
scorpp / rancher-update-service.sh
Created November 11, 2016 17:39
Jenkins script to upgrade a service on Rancher
test -f JSON.sh || curl -O https://raw.githubusercontent.com/dominictarr/JSON.sh/master/JSON.sh
eval $(sed 's/^/MY_/' build.info)
ORIG_LAUNCH_CONFIG=$(cat my-app-service.json | bash ./JSON.sh | grep -F '["launchConfig"]' | sed -e 's/[^{]*//')
NEW_LAUNGH_CONFIG=$(echo $ORIG_LAUNCH_CONFIG |\
sed "s/\(\"imageUuid\"\):\"[^\"]*\"/\1:\"docker:my-image:${MY_BUILD_NUMBER}\"/")
echo $NEW_LAUNGH_CONFIG |\
xargs -d\\n -i_-_ curl -v -u "RANCHER_KEY:RANCHER_SECRET" \
-X POST -H 'Content-Type: application/json' \
-d '{"inServiceStrategy":{"launchConfig": _-_ }}' \
@scorpp
scorpp / capture-audio.sh
Created March 16, 2018 11:07
Capture audio from desktop + mic with pulseaudio
#!/bin/bash
#
# Usage:
#
# capture-audio.sh [ffmpeg args]
#
function get_default_sink_or_source() {
SINK_OR_SOURCE=$1