It's all fluff, all the way down ...

Posts

All the things.

Helloworld

First test of Hugo

Autohotkey, mouse button different action, click vs hold

; This is the "back" button ...
; Keywait waits max 210ms for key release. 
; IF: (keywait < 200ms) -> send the actual button, IF: (keywait > 200ms (or timeout)) -> send key PageUp.
XButton1::
    x:=A_TickCount
    Keywait XButton1, T0.21
    d:=(A_TickCount-x)
    If (d<200)
        Send {XButton1}
    Else
        Send {PgUp}
Return

; This is the "forward"-button ...
; Keywait waits max 210ms for key release.
; IF: (keywait < 200ms) -> send the actual button, IF: (keywait > 200ms (or timeout)) -> press the 1-button down, repeat.
XButton2::
    x:=A_TickCount
    Keywait XButton2, T0.21
    d:=(A_TickCount-x)
    If (d<200)
        Send {Xbutton2}
    Else
        Send {1 Down}
Return

; When "forward" is released, the 1-button is released ...
XButton2 Up::
    Send {1 Up}
Return

"Keep WiFi on during sleep" from adb

adb shell settings put global wifi_sleep_policy 2

* Always = 2
* Only When Plugged In = 1
* Never = 0

Backup running VirtualBox machine (with only a tiny interupt)!

There is a lot to be said about backups. I won’t even try to cover all bases. I’ll just show you what I’m using, that works for me. Yes.

In a nutshel this is what happens

Input is name of VM-machine and index of backup.
Output is a backup of your machine … who’da thunk it.

Create random Spotify playlist with bash, curl and the Spotify API

Untinkered with this script will

You need a access-token with enough permissions (scopes) to modify playlists. I created one with AAAALL the scopes for my personal use so I’m not entirely sure which ones are really needed.

Kodi addon, run script on playback action

Addon version of a kodi-script I never published here … so yeah.

Run scripts when you start playing a video in kodi. In my case I turn off some HUE-lights on play and turn them on, in red, on pause.

2021-03-14: Made this a bit less shit, maybe. Added some debug-logging. Also in a sort of “auto-like” for youtube-videos, very hacky.

addon.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.playback.actions" 
  name="Playback Actions Service" 
  version="0.0.1" 
  provider-name="me/you/whoever">
 <requires>
  <import addon="xbmc.python" version="2.14.0"/>
 </requires>
 <!-- <extension point="xbmc.python.script" library="addon.py">
  <provides>executable</provides>
 </extension> -->
 <extension point="xbmc.service" library="service.py" start="login" />
 <extension point="xbmc.addon.metadata">
  <platform>all</platform>
  <summary lang="en">Does stuff on playback actions</summary>
  <description lang="en">Fancy that eh?</description>
  <license>GNU General Public License, v2</license>
  <language></language>
 </extension>
</addon>

service.py

Home "automation" in Linux with netcat/socat

I realize that this post i lacking in instructions. I might flesh this out at a later date but no guaranties. It’s not really that difficult once you figure out my madness ;)

I’m using tasker and udp sender to send udp packets with commands to a listening socat.

So if I send, for example (trailing blank line is intentional):

hue_on
kodi_on
 

… my Hue lights and HTPC will turn on. Tasker is then set up to send these commands when my phone connects to my home network. Simple and effective.

Monitor/screen standby on Raspberry Pi 2

These instructions are kind of hastily thrown together so you might want to research this on your own a bit more and not simply copy-paste this.

We will use xscreensaver (from the repos) and tvservice - which is (apparently) preinstalled in /opt/vc/bin/tvservice - to control the video output and turn the connected monitor on and off.

Turning the monitor off is very straight forward. Just append the -o switch to the tvservice-command above and your monitor will turn off. This will however get you stuck with the monitor off and with no way of turning it back on.

Automatic VirtualBox extpack upgrade on Linux host

Can’t be arsed to write something here …

#!/bin/bash
version=$(vboxmanage -v)
echo Version: $version
var1=$(echo $version | cut -d 'r' -f 1)
echo Main   : $var1
var2=$(echo $version | cut -d 'r' -f 2)
echo Build  : $var2
file="Oracle_VM_VirtualBox_Extension_Pack-$var1-$var2.vbox-extpack"
echo Extpack: $file
wget http://download.virtualbox.org/virtualbox/$var1/$file -O /tmp/$file
VBoxManage extpack install /tmp/$file --replace

XBMC - auto login, auto start, auto restart - systemd edition

These instructions are stupid, you should totally use this now. :)

Right up front I want to admit that I am not well versed in the inner workings of systemd and there are probably ways to get this done without resorting to “hax” as well. But I like easy, easy is simple by definition and I also like simple. Fancy that.

This is basically a refresh of an old post from 2012 that covers auto login and auto (re)start of xbmc under ubuntu/upstart. This time it is Arch Linux and, more specifically, systemd that is the obstacle. An obstacle which is not insurmountable, or at least not unworkaroundable as it were.

Activate specific window on mouse over

I use three monitors with two of them used for the host (Win7) and one for linux (fullscreened VM). I grew tired of having to click inside the VM window to be able to send input to it so I chopped together this AutoHotkey script that will activate it on mouse over. This mimics how a separate PC setup with its own monitor and Synergy works and feels a lot more… correct/intuitive/good/blargh than having to click.

Clear files from directory by age

Looping through all directories and files in a directory.

Directories are checked for video files. If found these are moved to the base directory and the directory, and any other files inside is then removed.

Files in base directory are checked for age and removed if older than 90 days.

Update 2014-06-20:

#!/bin/bash

datNow=`date "+%s"`
me=`basename $0`

# check if we got a directory, exit if not
if (( $# != 1 ))
then
  echo "Usage: $me "
  exit 1
fi

# change to directory passed to script, exit if fail
cd $1 || exit 1

for fluff in ./* ; do
  # age in seconds
  datFluff=`date -r "$fluff" "+%s"`

  if [ -d "$fluff" ]; then # fluff is directory
      # diff in minutes
      diff=$((($datNow-$datFluff)/60))

      if [ $diff -gt 60 ]; then
        echo "Moving files: $fluff"
        # yes the escaping in find is kinda silly but it is correct
        find "./$fluff/" -type f -regex ".*\.\(mp4\|avi\|mkv\)$" -exec mv {} ./ \;
        echo "Removing    : $fluff"
        rm -r "$fluff"
      fi
  elif [ -f "$fluff" ]; then # fluff is file
    # diff in days
    diff=$((($datNow-$datFluff/86400\*86400)/60/60/24)) # diff in days, rounded down 24h.

    if [ $diff -gt 90 ]; then
      echo "Removing      : $fluff // Age: $diff"
      rm "$fluff"
    fi
  fi
done 

Auto Loot in Guild Wars 2 with AutoHotkey

This really simple AutoHotkey script will send simulated presses of F12 to Guild Wars 2 every 250ms. That is it. The range on the AOE-loot does seem to be longer than the standard loot so you should not miss anything. If you still do, lower the number on the SetTimer-row below. I have not tested it below 250 (that is 4 times every second) but it is probably fine down to 100ms or so.

Add random songs to MPD playlist

The first part puts currently playing song in a text-file for use in other programs. The second part adds random songs while there is less than 3 songs in the playlist. This probably isn’t optimized or even good, to be frank, but it works. ^^

Update 1: As I have more than one mpd server running I figured it’d be more efficient catching the hostname as well as minimum tracks from stdin.
Update 2: Checks if we actually got a song to add as mpc add "" adds ALL the songs in your library.
Update 3: Cleaned up the code. Added NEXT_ON_ERROR to keep going if MPD stops while trying to play a song.
Update 4: Now backgrounds itself automagically. Also, functions are neat.
Update 5: Comments and exit 0.

XBMC - auto login, auto start, auto restart

This info is old and probably not very useful to anyone anymore.

This is a quick and dirty way of getting Ubuntu server to auto login the user xbmc and have that user start XBMC on boot and restart it if it crashes. There is no login-manager, no WM/DE, no nothing, just XBMC. And for me, that is enough.

Update 1: Checking if logged in at tty1 before starting the xbmc-neverending-loop. This as not to interfere with ssh-logins and/or logins on other ttys with the xbmc user.
Update 2: I think you could trim the startx line in the loop-script to only “startx /usr/bin/xbmc” but I’m not on Ubuntu anymore so I’ll leave it as is for now seeing as I can’t test it.

"Unblock" files recursively with Streams from Sysinternals

If you’re moving files (i.e. a asp.net website) from another computer to a server running Windows 2008 Server (or similarly new version) you’ll risk having to unblock all the files one-by-one as they are deemed “not safe”. I’m guessing this can be rectified by the network/domain/whatever-admins by defining what parts of the network is considered safe to copy files from.

But if they aren’t doing it you can use Streams to recursively unblock an entire directory and it’s very easy to use.

tmux - Resize pane to specific width and height

Quick post on how to resize a tmux-pane to a specific width and height.
I’m presuming you only have one session and that you’ve changed base-index to 1 and your prefix key combo to ctrl+a (ctrl+b is silly).

.tmux.conf

# 1 is easier to reach than 0  
set -g base-index 1  
# make tmux behave more screen-like  
unbind C-b  
set -g prefix C-a  
bind-key C-a last-window  
# run nested multiplexers and send prefix with ctrl+a a as in screen  
bind-key a send-prefix  
# make pane right size  
bind-key k run-shell "/path/to/the/script/below.sh"

I use this to set my irssi-pane to the correct width and height when I resize my client. I have a 3-pane setup with one pane to the left and two panes to the right split vertically so I really only need to resize this one pane and the other two will follow along.

CRON - cause I always forget

The cron format.

# .---------------- minute (0 - 59)
# |    .------------- hour (0 - 23)
# |    |    .---------- day of month (1 - 31)
# |    |    |    .------- month (1 - 12) OR jan,feb,mar,apr ...
# |    |    |    |    .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat
# |    |    |    |    |
# *    *    *    *    *    [command to be executed\]

I addition to the above syntax you can use the following, more easily remembered, special words.