Skip to content

Instantly share code, notes, and snippets.

@tynn
tynn / get.deps
Last active August 14, 2017 12:10
Download a dependency with `gradle -q -b get.deps -P dep='groupId:artifactId:revision'`
// 2017 CC0 http://creativecommons.org/publicdomain/zero/1.0/
repositories {
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://maven.google.com' }
}
configurations {
deps
}
@tynn
tynn / ObservableToggle.java
Last active December 29, 2016 11:00
Rx challenge
import org.junit.Before;
import org.junit.Test;
import rx.Observable;
import rx.observers.TestSubscriber;
import rx.subjects.PublishSubject;
import rx.subjects.ReplaySubject;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@tynn
tynn / dir2xpi
Last active August 29, 2015 14:02
Build Mozilla Add-on file from directory.
#!/bin/sh
# 2014 CC0 http://creativecommons.org/publicdomain/zero/1.0/
IFS="$(printf '\n\t')"
[ -f .xpi-include ] && I="-d $(cat .xpi-include)"
[ -f .xpi-exclude ] && X=-x@.xpi-exclude
ls $I | zip -r "$(basename $(pwd)).xpi" -@ -x"*.xpi" $X
@tynn
tynn / pdflatex+
Created May 7, 2014 16:21
Create pdf from tex files with the table of contents and other lists included, since pdflatex will be invoked twice. You'll only get the pdf, not any other output file.
#!/bin/sh
# 2014 CC0 http://creativecommons.org/publicdomain/zero/1.0/
# Create pdf from tex files.
[ $# -lt 1 ] && echo Usage: $0 tex-file && exit 1
OUT=/tmp/pdflatex+out
[ -d $OUT ] || mkdir $OUT
PL="pdflatex -file-line-error -halt-on-error -output-directory $OUT"
for file in "$@"
do [ -f "$file" ] && $PL -draftmode "$file" && $PL "$file"
done
@tynn
tynn / pause
Created March 31, 2014 12:34
The pause command suitable for a shell.
#!/bin/sh
# 2014 CC0 http://creativecommons.org/publicdomain/zero/1.0/
# A little implementation of pause.
[ -t 0 ] || exit
[ $# -ge 1 ] && msg="$@" || msg="Press any key ..."
read -p "$msg" -n 1 c
[ x"$c" = x"" ] || echo -e "\b "
@tynn
tynn / disttest.py
Last active August 29, 2015 13:57
This is a simple testing extension for distutils. The test class extends Command and can be used with the cmdclass argument. The setup function extends the default setup to accept a test_suite argument.
# Copyright (c) 2014 Christian Schmitz <tynn.dev@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@tynn
tynn / a_gtk_win.py
Last active January 1, 2016 14:49
Python Snippets
from gi.repository import Gtk
window = Gtk.Window()
window.connect('delete-event', Gtk.main_quit)
window.show()
Gtk.main()
@tynn
tynn / transbtadd.py
Last active January 1, 2016 13:09
Add a torrent to Transmission with the download directory set to the torrents parent directory. This might not work as intended if Transmission already keeps track of the torrent to be added or for any other reason.
#!/usr/bin/env python
# 2013 CC0 http://creativecommons.org/publicdomain/zero/1.0/
import os.path, sys, transmissionrpc
tc = transmissionrpc.Client()
for torrent in map(os.path.abspath, sys.argv[1:]) :
try : tc.add_torrent(torrent, download_dir = os.path.dirname(torrent))
except : print ("Failed adding {0:s}".format(torrent))
@tynn
tynn / tsw.py
Created December 26, 2013 21:36
Just stop with Ctrl-C.
#!/usr/bin/env python
# 2013 CC0 http://creativecommons.org/publicdomain/zero/1.0/
if __name__ == '__main__' :
from time import sleep, time
start = time()
print ("Terminal Stop Watch")
try :
while True : sleep(.0001)
except : print ("\r{:f}".format(time() - start))
@tynn
tynn / update.torrents.sh
Last active January 1, 2016 11:29
Script to maintain a list of torrents from webpages using data-bt attributes to link to those.
#!/bin/sh
# 2013 CC0 http://creativecommons.org/publicdomain/zero/1.0/
# Got a little annoyed by searching for game updates on HB webpage ...
[ $# -lt 2 ] && echo Usage: $(basename "$0") input-file output-dir && exit 1
[ ! -f "$1" ] && ([ -t 0 ] || [ "$1" != - ]) && echo Invalid input-file \'$1\' && exit 1
[ ! -d "$2" ] && ! mkdir -p "$2" && echo Invalid output-dir \'$2\' && exit 1 || out="$2"
bt=$(date +"%Y%m%d%H%M%S") && mkdir "$out/$bt" && bt="$bt/bt"
grep -m 1 'data-bt="' "$1" > /dev/null && S=\" || S=\'
grep -o "data-bt=$S.*://.*$S" "$1" | sed "s/^data-bt=\|$S//g" | sort | uniq > "$out/$bt"
[ x"$S" = x\" ] && sed -i "s/&amp;/\&/g" "$out/$bt"