Skip to content

Instantly share code, notes, and snippets.

View lene's full-sized avatar

Lene Preuss lene

View GitHub Profile
@lene
lene / socat_socks_proxy.sh
Last active October 7, 2023 07:52
Using tor as SOCKS proxy with SOCAT
socat TCP-LISTEN:<localport> SOCKS4A:localhost:<host>:<remoteport>,socksport=9050
# for example, to ssh into secret.shell.server.org via tor, do:
$ socat TCP-LISTEN:22222 SOCKS4A:localhost:secret.shell.server.org:22,socksport=9050 &
$ ssh localhost -p 22222
@lene
lene / assertThrows.scala
Last active September 16, 2023 19:17
Scala: assertThrows in Junit5 and hand-rolled
def throwingFunction(): Unit = throw RuntimeError()
// own implementation of assertThrows
def assertThrows[E](f: => Unit)(implicit eType:ClassTag[E]): Unit =
try f
catch
case _: E => return
case e: Any => Assertions.fail(s"Expected ${eType.runtimeClass.getName} got ${e.getClass}")
Assertions.fail(s"Expected ${eType.runtimeClass.getName}")
@lene
lene / attributes.scala
Last active October 3, 2022 18:26
Scala: print names and types of all attributes of an unknown object
UNKNOWN_OBJECT.getClass.getDeclaredFields.foreach(v => println(s"${v.getName}: $v"))
@lene
lene / sync.fish
Last active September 8, 2022 22:05
Sync Music dir to Google Drive
sudo apt install google-drive-ocamlfuse # to mount google drive as a pseudo fs
sudo apt install athena-jot # for generating the list of {A..Z} in fish shell on the fly
sudo apt install parallel # to control running jobs in parallel
# set up google drive, see https://github.com/astrada/google-drive-ocamlfuse/wiki/Authorization
google-drive-ocamlfuse
# mount google drive
set DRIVE_DIR GoogleDrive
google-drive-ocamlfuse ~/$DRIVE_DIR/
@lene
lene / tox265.fish
Last active August 30, 2022 11:38
re-encode videos to H.265, specifying source and target container format (fish shell)
set FROM_EXT mp4
set TO_EXT mkv
set ABR 128k
set CRF 22
for i in *.$FROM_EXT
set BASENAME (basename $i .$FROM_EXT)
set DIRNAME (dirname $i)
nice -n 19 time ffmpeg -i "$DIRNAME/$BASENAME.$FROM_EXT" -vcodec libx265 -crf $CRF -ac 2 -c:a libmp3lame -b:a $ABR output.$TO_EXT; and \
mv output.$TO_EXT "$DIRNAME/$BASENAME.$TO_EXT"; and \
rm "$i"
@lene
lene / subparser.py
Last active July 13, 2020 10:43
argparse subparser easy use
def command(args):
pass
parser = argparse.ArgumentParser()
subparser = parser.add_subparsers(title="subcommands")
command_parser = subparser.add_parser("command")
command_parser.set_defaults(func=command)
command_parser.add_argument("--dummy", help="some arg to the subcommand")
args = parser.parse_args()
@lene
lene / decorator_args.py
Last active December 21, 2018 09:20
Python decorator with argument(s)
from functools import wraps
def decorator_with_argument(argument=None):
def actual_decorator(func):
@wraps(func)
def func_wrapper(*args, **kwargs):
return do_stuff(func(*args, **kwargs), argument)
@lene
lene / PnR.json
Last active March 20, 2018 14:29
{
"Res": {
"Connections": {
"Connection": [
{
"@duration": "PT2H3M33S",
"@transfers": "2",
"Dep": {
"@time": "2018-03-20T07:47:27",
"Addr": {
@lene
lene / request.sh
Last active March 20, 2018 14:28
Anatomy of a request to the HERE Intermodal Routing API
http://mobility.api.here.com/v1/route
?app_id={YOUR_APP_ID}
&app_code={YOUR_APP_CODE}
&profile=parkandride
&dep={YOUR_START_POINT}
&arr=41.884238,-87.638862
&time=2018-03-20T07:30:00
@lene
lene / response.json
Last active March 20, 2018 14:27
HERE Intermodal Routing API response (shortened example)
{
"Res": {
"Connections": {
"Connection": [
{
"@duration": "PT2H3M33S",
"@transfers": "2",
"Sections": {
"Sec": [
{