Skip to content

Instantly share code, notes, and snippets.

View wolkenarchitekt's full-sized avatar

Ingo Weinmann wolkenarchitekt

View GitHub Profile
@wolkenarchitekt
wolkenarchitekt / ipythonhist.py
Last active August 22, 2023 10:00
Access complete IPython history
#!/usr/bin/env python
"""Extract a session from the IPython input history.
"""
import sys
import codecs
from IPython.core.history import HistoryAccessor
class MyHistoryAccessor(HistoryAccessor):
""" Modified HistoryAccessor to fetch the whole ipython history across all sessions """
@wolkenarchitekt
wolkenarchitekt / ipythonsync.sh
Last active December 23, 2015 00:19
Monitor IPython SQLite history; save into plain textfile on every update
#!/usr/bin/env bash
# Saves todays ipython history to textfile.
# Needs inotify-tools, sqlite3
HISTORY_SQLITE="${HOME}/.config/ipython/profile_default/history.sqlite"
HISTORY_FILE="${HOME}/.config/ipython/profile_default/history.py"
if [ ! -f "${HISTORY_FILE}" ]; then
touch "${HISTORY_FILE}"
fi
@wolkenarchitekt
wolkenarchitekt / argparselibs.md
Last active February 22, 2016 09:45
Command line argument parsing libraries

argcomplete

https://github.com/kislyuk/argcomplete

argcomplete - Bash tab completion for argparse Tab complete all the things!

Argcomplete provides easy, extensible command line tab completion of arguments for your Python script.

It makes two assumptions:

@wolkenarchitekt
wolkenarchitekt / parse_icinga_object_cache.py
Created August 9, 2017 14:30
Parse Icinga object cache file using Python and regex
#!/usr/bin/env python
# Parse Icinga object cache file into proper data structure
import re
import logging
logger = logging.getLogger(__name__)
def parse_config(cache_file):
"""
@wolkenarchitekt
wolkenarchitekt / ssh_tunnel.py
Last active December 8, 2017 13:11
Establish SSH forwarding tunnel in background
import subprocess
logger = logging.getLogger(__name__)
def ssh_tunnel(jumphost, remote_server, local_port, remote_port,
control_socket='/tmp/ssh_socket'):
"""
Establish SSH tunnel
:param jumphost: jump host
@wolkenarchitekt
wolkenarchitekt / git_url.py
Last active December 8, 2017 12:05
Get git url of file (works for Github and Gitlab)
#!/usr/bin/env python
#
# Show URL of file in git, optionally open URL in browser.
# In contrast to 'hub' this works to Github *and* Gitlab.
#
# Requirements: GitPython, click
import logging
import os
import sys
import webbrowser
@wolkenarchitekt
wolkenarchitekt / ndict.py
Last active March 15, 2022 14:24
A defaultdict like dictionary that allows accessing nested keys without getting KeyErrors or TypeErrors
# Required: boltons, nested_dict
from boltons.iterutils import remap
from nested_dict import nested_dict
def ndict(data):
"""
Create a defaultdict-like dictionary that allows accessing nested keys without getting
KeyErrors or TypeErrors.
Regular dict:
@wolkenarchitekt
wolkenarchitekt / traktor_rating.py
Last active June 29, 2020 06:58
Get/set popularimeter rating ID3 tag for Traktor
# Gets or sets popularimeter ID3 rating tag for Traktor.
# Needs mutagen for ID3 tag manipulation:
# pip install mutagen
import logging
import os
import sys
import click
import mutagen
import mutagen.id3
@wolkenarchitekt
wolkenarchitekt / Dockerfile
Created March 4, 2018 13:23
Dockerfile for wav2png
FROM ubuntu:latest
RUN apt-get update --fix-missing
RUN apt-get install -y git make g++ libsndfile1-dev libpng++-dev libpng12-dev libboost-program-options-dev
RUN apt-get install -y libxvidcore4 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad gstreamer1.0-alsa gstreamer1.0-fluendo-mp3 gstreamer1.0-libav
RUN git clone https://github.com/beschulz/wav2png
WORKDIR /wav2png/build
RUN make all
RUN ln -s /wav2png/bin/Linux/wav2png /usr/bin/wav2png
#
# Fetches latest MYSQL dump from radio-browser.info, converts it to SQLite.
# Usage:
# docker build -t radiobrowser-converter .
# docker run -v $PWD:/temp -it --rm radiobrowser-converter
#
FROM mysql:latest
RUN apt-get update
RUN apt-get install -y rubygems ruby-mysql2 wget build-essential libmysqlclient-dev ruby2*-dev sqlite3 libsqlite3-dev
RUN gem install sequel mysql2 sqlite3