Skip to content

Instantly share code, notes, and snippets.

View panzi's full-sized avatar

Mathias Panzenböck panzi

View GitHub Profile
@panzi
panzi / mkplaylist.py
Last active December 29, 2015 20:19
Find music files in a filesystem hierarchy and put them all numerically sorted into a playlist.
#!/usr/bin/env python
import os
import re
import sys
import argparse
from os.path import abspath, join as pathjoin, splitext
from stat import S_ISREG, S_ISDIR
@panzi
panzi / dirdiff.py
Last active January 24, 2016 22:17
A very simple script to compare two folders, only based on file names (and not file content).
#!/usr/bin/env python
#
# A very simple script to compare two folders, only based on file names (and
# not file content).
# I'm sure there are lots of programs that do just this but given how short it
# is it was faster for me to write this than to search for a tool that does
# exactly what I want.
from __future__ import print_function
@panzi
panzi / absurl.js
Created February 18, 2012 04:11
Build an absolute url from an relative url and an absolute base url.
/**
* Build an absolute url using an base url.
* The provided base url has to be a valid absolute url. It will not be validated!
* If no base url is given the document location is used.
* Schemes that behave other than http might not work.
* It tries to support file:-urls, but might fail in some cases.
* email:-urls aren't supported at all (don't make sense anyway).
*
* NOTE: Internet Explorer does not support the baseURI property, but it does
* support the base tag, which results in wrong url. You might want to
@panzi
panzi / rabbit-autoscroll.user.js
Created October 5, 2016 00:58
Automaticall scroll the chat on rabb.it to the bottom. You need to install the Greasemonkey Browser add-on.
// ==UserScript==
// @name Auto-scroll in rabb.it chat
// @namespace http://panzi.github.io/
// @description Automaticall scroll the chat on rabb.it to the bottom.
// @include https://www.rabb.it/*
// @include http://www.rabb.it/*
// @include https://rabb.it/*
// @include http://rabb.it/*
// @version 1.0
// ==/UserScript==
@panzi
panzi / stop_tweetdeck_videos.user.js
Last active October 5, 2016 01:20
This stops auto-play of videos (vines, GIFs) on TweetDeck. You can still manually play videos by clicking them, though.
// ==UserScript==
// @name Auto-scroll in rabb.it chat
// @namespace http://panzi.github.io/
// @description Automaticall scroll the chat on rabb.it to the bottom.
// @include https://www.rabb.it/*
// @include http://www.rabb.it/*
// @include https://rabb.it/*
// @include http://rabb.it/*
// @version 1.0
// ==/UserScript==
@panzi
panzi / prefix.py
Last active December 17, 2016 22:36
Find common prefix of a list of strings.
#!/usr/bin/env python3
def find_prefix(words):
it = iter(words)
try:
first = next(it)
except StopIteration:
return ''
if not first:
@panzi
panzi / new_google_maps_zoom.js
Last active February 15, 2017 13:59
The new Google Maps seems to use a diameter instead of a zoom value. You can use this function to get the old zoom value from the diameter. I tested it with the given list of values.
function diameterToZoom (diameter) {
var zoom = Math.floor(19 - Math.log(diameter / 1000) / Math.LN2);
return zoom < 0 ? 0 : zoom > 20 ? 20 : zoom;
}
// tested with these values:
// diameter = zoom
// 758 = 19
// 1515 = 18
// 3031 = 17
@panzi
panzi / .bashrc
Last active March 26, 2017 10:25 — forked from henrik/.bashrc
No color and only show basename of current working directory.
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine dir [master]$ # clean working directory
# username@Machine dir [master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ [\1$(parse_git_dirty)]/"

Create a new bookmark in your bookmar toolbar, call it download and use this as the URL:

javascript:(function() { var els = document.querySelectorAll('audio, video'); var links = []; for (var i = 0; i < els.length; ++ i) { var el = els[i]; var l = document.createElement('a'); l.href = el.currentSrc; l.download = ''; l.style.visibility = 'hidden'; l.style.position = 'absolute'; l.style.bottom = '0'; l.style.right = '0'; document.body.appendChild(l); l.click(); links.push(l); } for (var i = 0; i < links.length; ++ i) { document.body.removeChild(links[i]); } })();void(0)

This doesn't work in all cases. Some webpages uses that special streaming video format or DRM.

@panzi
panzi / mediaspeed.md
Last active May 24, 2017 10:59
Change media speed.

Create a new bookmark and set the URL to the javascript:-URL of the speed you want. Click that link when you want to set a video's (or audio's) speed. In principle it works with Twitch VODs when using the HTML5 player, but Twitch seems to send data to slow for 2x. 1.5x seems to work for me.

Speed URL
0.5x javascript:document.querySelectorAll("audio,video").forEach(e=>e.playbackRate=0.5);void(0)
1x javascript:document.querySelectorAll("audio,video").forEach(e=>e.playbackRate=1);void(0)
1.25x javascript:document.querySelectorAll("audio,video").forEach(e=&gt;e.playbackRate=1.25);void(0)