Skip to content

Instantly share code, notes, and snippets.

View Paebbels's full-sized avatar

Patrick Lehmann Paebbels

View GitHub Profile
@Paebbels
Paebbels / Reproducer.py
Created June 13, 2023 20:52
Python __new__ and __init__ with meta-classes
class AbstractClassError(Exception):
pass
class M(type):
# staticmethod
def __new__(cls, className, baseClasses, members, abstract):
newClass = type.__new__(cls, className, baseClasses, members)
if abstract:
def newnew(cls, *_, **__):
@Paebbels
Paebbels / BindingDecorator.py
Created January 13, 2021 12:00
Bind Python Functions via ctype to Shared Libraries
class __Environment():
"""
Create a Python root environment with local and global symbols and a builtins
namespace
"""
globals: Dict #: global symbols
locals: Dict #: local symbols
builtins: Dict #: builtins namespace (``__builtins__``)
@Paebbels
Paebbels / Add-and-Remove-from-PATH.ps1
Created January 12, 2021 14:12
PowerShell Snippets
# GitHub user: https://github.com/mkropat
# Gist account at GitHub: https://gist.github.com/mkropat
# Gist snippet URL: https://gist.github.com/mkropat/c1226e0cc2ca941b23a9
function Add-EnvPath
{ param(
[Parameter(Mandatory=$true)]
[string] $Path,
[ValidateSet("Machine", "User", "Session")]
[string] $Container = "Session"
@Paebbels
Paebbels / inspect_objects.py
Created January 5, 2021 01:00 — forked from acsr/inspect_objects.py
patch sphinx.ext.intersphinx output tweaking the main function to using almost csv compatible tab separators instead of columns adjusted by spaces
#!./bin/python
# -*- coding: utf-8 -*-
"""
inspect_objects
based on and requiring sphinx.ext.intersphinx
~~~~~~~~~~~~~~~~~~~~~~
List links to objects documented in as build Sphinx documentation.
@Paebbels
Paebbels / pyUnittest_Testcase.py
Created December 28, 2020 11:05
Abort following tests if one failed.
class SomeTestcases(TestCase):
_continueTesting = True
def setUp(self) -> None:
"""Check for every test, if tests should continue."""
if not self.__class__._continueTesting:
self.skipTest("No reason to go on.")
def fail(self, msg: Any = ...) -> NoReturn:
self.__class__._continueTesting = False
@Paebbels
Paebbels / gist:3a111f070f3151383d5021e0eec46f52
Created August 7, 2020 06:29 — forked from cdown/gist:1163649
Bash urlencode and urldecode
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
@Paebbels
Paebbels / ssh-tar
Created November 21, 2018 21:07 — forked from purplefish32/ssh-tar
Compress and copy via SSH using TAR
#Compress and copy via SSH using SCP and TAR
tar -czf - /some/file | ssh joebloggs@otherserver.com tar -xzf - -C /destination
#Switch -c for tar creates an archive and -f which tells tar to send the new archive to stdout.
#The second tar command uses the -C switch which changes directory on the target host. It takes the input from stdin. The -x switch extracts the archive.
#The second way of doing the transfer over a network is with the -z option, which compresses the stream, decreasing time it will take to transfer over the network.
#Some people may ask why tar is used, this is great for large file trees, as it is just streaming the data from one host to another and not having to do intense operations with file trees.
#If using the -v (verbose) switch, be sure only to include it on the second tar command, otherwise you will see double output.
#Using tar and piping can also be a great way to transfer files locally to be sure that file permissions are kept correctly
@Paebbels
Paebbels / README.md
Created September 21, 2017 06:19 — forked from JamesMessinger/README.md
VSCode GitHub Markdown Theme

GitHub Markdown Theme for Visual Studio Code

This CSS stylesheet allows you to preview markdown files in VSCode using GitHub's mardown theme. This CSS was taken directly from the official GitHub Markdown repo. I replaced their top-level .markdown-body class with the body tag so it would work in VSCode, and added styling for the html tag to match GitHub's fixed-width container.

Instructions

  1. Copy the CSS file to your computer
    Copy the github-markdown.css file below to your computer. You can put it anywhere you want, but I chose to put it in the same folder as my VSCode settings file.

  2. Edit your VSCode settings
    If you want to use this theme for all of your projects, then edit your User Settings file. If you just want to use this them

@Paebbels
Paebbels / FromXML.py
Created October 26, 2016 14:13
Read and validate a XML file with lxml in Python.
class foo:
@classmethod
def FromFile(cls, filePath):
if (not filePath.exists()):
raise PyIpxactException("File '{0!s}' not found.".format(filePath))
from FileNotFoundError(str(filePath))
try:
with filePath.open(encoding="utf-8") as fileHandle:
content = fileHandle.read()
@Paebbels
Paebbels / iCLA test
Created April 29, 2016 00:09
Individual Contributor License Agreement (iCLA)
The PoC-Library is licensed under the [Apache License 2.0][al20].
Due to the modular structure of the PoC-Library, contributions can come in two distinct forms:
- **(1)** modifications of the core code (i.e., the code under the copyright of the
Chair for VLSI Design, Diagnostics and Architecture, Faculty of Computer Science,
Technische Universität Dresden, including extensions in the core repository) as well as
- **(2)** **third party extensions**, translations and similar additions.
Essentially, the difference between the two is that type **(1)** contributions cannot be