Skip to content

Instantly share code, notes, and snippets.

View Cellebyte's full-sized avatar

Marcel Fest Cellebyte

  • Deutsche Telekom Technik GmbH
  • Düsseldorf, Germany
View GitHub Profile
@Cellebyte
Cellebyte / sharelatex_dump.py
Created March 28, 2018 18:05
Simple sharelatex to git repo dumper in python ugly but usefull
#!/usr/bin/env python3
'''
Simple Python Module to dump sharelatex onto gitlab
apt install git
apt install python3
apt install python3-requests
'''
import sys
import os
import shutil
@Cellebyte
Cellebyte / backup.py
Last active December 16, 2019 17:38
Grafana Backup with requests and prometheus_client
from __future__ import annotations
import logging
from datetime import datetime
from enum import Enum
from typing import List
from urllib.parse import urlparse
from prometheus_client import REGISTRY, CollectorRegistry, Gauge, Info
@Cellebyte
Cellebyte / wsgi.py
Created January 7, 2020 16:19
Initialization for serving a WSGI app.
try:
from cheroot.wsgi import Server as WSGIServer, PathInfoDispatcher
except ImportError:
from cherrypy.wsgiserver import CherryPyWSGIServer as WSGIServer, WSGIPathInfoDispatcher as PathInfoDispatcher
from .your_module import app
d = PathInfoDispatcher({'/': app})
server = WSGIServer(('0.0.0.0', 5000), d)
@Cellebyte
Cellebyte / lvm_expand_on_boot.sh
Last active April 30, 2020 14:41
This script can expand an lvm on bootup.
#!/usr/bin/env bash
declare -A ratios
declare -A freespace
declare -A units
declare -r DRY_RUN="${1}"
declare HIDDEN_PARTITION="${2}"
declare LVM_PARTITION="${3}"
grow_partitions=("${HIDDEN_PARTITION:=/dev/sda2}" "${LVM_PARTITION:=/dev/sda5}")
@Cellebyte
Cellebyte / netstat.py
Last active March 17, 2022 11:36
If you are in a airgapped environment without net-tools but python3 is installed.
import pwd
import os
import re
import glob
import ipaddress
import socket
import struct
import codecs
@Cellebyte
Cellebyte / dict_flatten.py
Last active October 28, 2020 14:56
Flatten a dict with comprehensions and a generator.
from typing import Any, Tuple, Generator
SEPARATOR = '.'
def dict_flatten(
d: dict, parent_key: str = "", sep: str = SEPARATOR
) -> Generator[Tuple[str, Any], None, None]:
for key, value in d.items():
if isinstance(value, dict):
yield from dict_flatten(value, parent_key=f"{parent_key}{key}{sep}")
@Cellebyte
Cellebyte / list_flatten.py
Created October 28, 2020 14:56
Flatten a list with comprehensions and a generator.
from typing import Generator, Any
def list_flatten(l: list) -> Generator[Any,None,None]:
for item in l:
if isinstance(item, list):
yield from list_flatten(item)
else:
yield item
if __name__ == '__main__':
@Cellebyte
Cellebyte / values-yaml-doc.py
Created October 28, 2020 15:01
Try to autogenerate Markdown Tables based on the comments from yaml.
import argparse
import io
import itertools
import sys
from typing import Any, Generator, Tuple, Union
import ruamel
from pytablewriter import MarkdownTableWriter
from ruamel.yaml import YAML
@Cellebyte
Cellebyte / rename.py
Created January 5, 2021 20:27
A simple script which allows to rename file by pattern and substitution.
import glob
import argparse
import re
import os
parser = argparse.ArgumentParser(description='Rename some files.')
parser.add_argument('--pattern', type=str, default='')
parser.add_argument('--substitution', type=str, default='')
args = parser.parse_args()
@Cellebyte
Cellebyte / create-uefi-iso.sh
Created April 1, 2021 11:49
Building UEFI bootable mini image for ipa.
#!/usr/bin/env bash
declare -r TEMP_MOUNT="$(mktemp -d)"
declare -r TITLE="Python Ironic Agent"
declare -r DESTINATION="${1:-out.iso}"
declare -r KERNEL="${2:-kernel}"
declare -r INITRAMFS="${3:-initramfs}"
echo "TEMP_MOUNT = ${TEMP_MOUNT}"
dd if=/dev/zero of=${DESTINATION} bs=1M count=514