Skip to content

Instantly share code, notes, and snippets.

View pgcd's full-sized avatar

Paolo Dente pgcd

  • Berlin, Deutschland
View GitHub Profile
@pgcd
pgcd / mix_form_class.py
Last active May 6, 2025 10:16
Function to combine two modelform classes in Django
def mix_form_class(klass, new_klass):
# this way we can avoid repeating fields every time
meta = klass.Meta
if inject_meta := getattr(new_klass, 'Meta', None):
if (
(m1 := getattr(meta, 'model', None)) is not None and
(m2 := getattr(inject_meta, 'model', None)) is not None and
m1 != m2):
raise ValueError(f"Incompatible models in classes {meta} and {inject_meta}")
@pgcd
pgcd / autocompleteview.py
Last active April 4, 2025 06:23
Basic Django AutocompleteView
from abc import abstractmethod, ABCMeta
from django.views.generic import ListView
from django.http import JsonResponse
class AutocompleteView(ListView, metaclass=ABCMeta):
# Subclass and adjust to taste
GET_parameter_name = 's'
min_search_length = 3
@pgcd
pgcd / gist:c7ca959c464d3aeafce12f53e380f7f7
Last active May 14, 2023 16:29
Reset boot for a P2V Windows 11 disk
Copy disk (eg `disk2vhd` then `Vboxmanage clonemedium`)
- access VM commandline (eg. use a win11 installation disk and select "repair"
- in the VM use `diskpart` to list volumes, find system one and assign letter=Z
- format system volume (`format Z: /q`)
- use `bcdboot C:\Windows /s Z:`
- reboot VM
(https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/bcdboot-command-line-options-techref-di?view=windows-11)
@pgcd
pgcd / gist:34b18fea96b1a10bc582239d4b7b9f45
Last active December 18, 2022 20:35
functools.partialmethod behavior changes in python 3.11
### In Python 3.10 you can do this:
import functools
class A:
def whoami(self, obj):
print(self, obj)
class B:
pass
a = A()
setattr(B, "whoami", functools.partialmethod(a.whoami))
@pgcd
pgcd / .bashrc
Created March 8, 2022 10:45 — forked from strarsis/.bashrc
Vagrant on WSL (Bash on Windows)
# Vagrant
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
export PATH=$PATH:/mnt/c/Program\ Files/Oracle/VirtualBox
export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/c/Users/<Windows Username>"
@pgcd
pgcd / logging_setup.py
Created September 6, 2019 06:13
Django Logging setup to log directly to papertrail (syslog)
import socket
hostname = socket.gethostname()
PAPERTRAIL_HOST = 'logsN.papertrailapp.com'
PAPERTRAIL_PORT = 'XXXXX'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'SysLog': {
'level': 'INFO',

Keybase proof

I hereby claim:

  • I am pgcd on github.
  • I am pgcd (https://keybase.io/pgcd) on keybase.
  • I have a public key ASA-P78BVoVBnB5EQBsnisKQWoM18r_GOW43QGDkWwVBfwo

To claim this, I am signing this object:

@pgcd
pgcd / compressors.py
Created September 7, 2017 05:12
DeferredCSSCompressor for django-compressor
from compressor.css import CssCompressor
class DeferredCssCompressor(CssCompressor):
template_name_file = 'deferred_compressed_css.html'
@pgcd
pgcd / save_all_strms.py
Created June 18, 2017 16:06
Save STRM for all the videos in a gdrive directory
# usage: python save_all_strms.py gdrive:your_video_folder
import os
import sys
import re
from subprocess import Popen, PIPE
import logging
log = logging.getLogger('save_all_strms')
log.addHandler(logging.StreamHandler())
@pgcd
pgcd / __init__.py
Last active July 23, 2017 07:53
CouchPotato PostProcess Script to move to Google Drive and replace with a STRM for Kodi
from .main import PostProcess
def autoload():
return PostProcess()